13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE InventoryTestSuite
16 #include <boost/test/unit_test.hpp>
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/bom/TravelSolutionStruct.hpp>
22 #include <stdair/bom/BookingRequestStruct.hpp>
23 #include <stdair/service/Logger.hpp>
24 #include <stdair/stdair_exceptions.hpp>
28 #include <airinv/config/airinv-paths.hpp>
30 namespace boost_utf = boost::unit_test;
33 std::ofstream utfReportStream (
"InventoryTestSuite_utfresults.xml");
38 struct UnitTestConfig {
41 boost_utf::unit_test_log.set_stream (utfReportStream);
42 boost_utf::unit_test_log.set_format (boost_utf::XML);
43 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
56 bool testInventoryHelper (
const unsigned short iTestFlag,
57 const stdair::Filename_T& iInventoryInputFilename,
58 const stdair::Filename_T& iScheduleInputFilename,
59 const stdair::Filename_T& iODInputFilename,
60 const stdair::Filename_T& iFRAT5InputFilename,
61 const stdair::Filename_T& iFFDisutilityInputFilename,
62 const stdair::Filename_T& iYieldInputFilename,
64 const bool isForSchedule) {
67 std::ostringstream oStr;
68 oStr <<
"InventoryTestSuite_" << iTestFlag <<
".log";
69 const stdair::Filename_T lLogFilename (oStr.str());
72 std::ofstream logOutputFile;
74 logOutputFile.open (lLogFilename.c_str());
75 logOutputFile.clear();
78 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
85 std::string lSegmentDateKey;
86 stdair::ClassCode_T lClassCode;
87 const stdair::PartySize_T lPartySize (2);
90 if (isBuiltin ==
true) {
93 airinvService.buildSampleBom();
96 lSegmentDateKey =
"BA,9,2011-06-10,LHR,SYD";
101 if (isForSchedule ==
true) {
103 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
104 stdair::ODFilePath lODFilePath (iODInputFilename);
105 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
106 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
107 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
108 airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
109 lFRAT5FilePath, lFFDisutilityFilePath,
113 lSegmentDateKey =
"SQ,11,2010-01-15,SIN,BKK";
120 airinvService.parseAndLoad (lInventoryFilePath);
124 lSegmentDateKey =
"SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
131 const bool hasSaleBeenSuccessful =
132 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
135 const std::string& lCSVDump = airinvService.csvDisplay();
136 STDAIR_LOG_DEBUG (lCSVDump);
139 logOutputFile.close();
141 if (hasSaleBeenSuccessful ==
false) {
142 STDAIR_LOG_DEBUG (
"No sale can be made for '" << lSegmentDateKey
146 return hasSaleBeenSuccessful;
153 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
156 BOOST_AUTO_TEST_SUITE (master_test_suite)
161 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
168 const bool isBuiltin =
false;
170 const bool isForSchedule =
false;
173 bool hasTestBeenSuccessful =
false;
174 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
175 testInventoryHelper (0, lInventoryInputFilename,
176 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule));
177 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
184 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
187 const bool isBuiltin =
true;
189 const bool isForSchedule =
false;
192 bool hasTestBeenSuccessful =
false;
193 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
194 testInventoryHelper (1,
" ",
" ",
" ",
" ",
" ",
" ",
195 isBuiltin, isForSchedule));
196 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
203 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
213 "/ffDisutility.csv");
215 "/yieldstore01.csv");
218 const bool isBuiltin =
false;
220 const bool isForSchedule =
true;
223 bool hasTestBeenSuccessful =
false;
224 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
225 testInventoryHelper (2,
" ",
226 lScheduleInputFilename,
229 lFFDisutilityInputFilename,
231 isBuiltin, isForSchedule));
232 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
240 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
247 const bool isBuiltin =
false;
249 const bool isForSchedule =
false;
252 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
253 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule),
262 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
270 "/ffDisutility.csv");
273 const bool isBuiltin =
false;
275 const bool isForSchedule =
true;
278 BOOST_CHECK_THROW (testInventoryHelper (4,
" ", lMissingScheduleFilename,
279 " ", lFRAT5InputFilename,
280 lFFDisutilityInputFilename,
" ",
281 isBuiltin, isForSchedule),
290 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
300 "/ffDisutility.csv");
305 const bool isBuiltin =
false;
307 const bool isForSchedule =
true;
310 BOOST_CHECK_THROW (testInventoryHelper (5,
" ",
311 lScheduleInputFilename,
314 lFFDisutilityInputFilename,
316 isBuiltin, isForSchedule),
317 AIRRAC::YieldInputFileNotFoundException);
325 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
329 "/scheduleError01.csv");
335 "/ffDisutility.csv");
340 const bool isBuiltin =
false;
342 const bool isForSchedule =
true;
345 BOOST_CHECK_THROW (testInventoryHelper (6,
" ",
346 lScheduleInputFilename,
349 lFFDisutilityInputFilename,
351 isBuiltin, isForSchedule),
360 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
364 "/scheduleError02.csv");
370 "/ffDisutility.csv");
372 "/yieldstore01.csv");
375 const bool isBuiltin =
false;
377 const bool isForSchedule =
true;
380 BOOST_CHECK_THROW (testInventoryHelper (7,
" ",
381 lScheduleInputFilename,
384 lFFDisutilityInputFilename,
386 isBuiltin, isForSchedule),
392 BOOST_AUTO_TEST_SUITE_END()