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>
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& iYieldInputFilename,
62 const bool isForSchedule) {
65 std::ostringstream oStr;
66 oStr <<
"InventoryTestSuite_" << iTestFlag <<
".log";
67 const stdair::Filename_T lLogFilename (oStr.str());
70 std::ofstream logOutputFile;
72 logOutputFile.open (lLogFilename.c_str());
73 logOutputFile.clear();
76 const bool lForceMultipleInit =
true;
77 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 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
104 airinvService.parseAndLoad (iScheduleInputFilename, iODInputFilename,
108 lSegmentDateKey =
"SQ,11,2010-01-15,SIN,BKK";
114 airinvService.parseAndLoad (iInventoryInputFilename);
118 lSegmentDateKey =
"SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
125 const bool hasSaleBeenSuccessful =
126 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
129 const std::string& lCSVDump = airinvService.csvDisplay();
130 STDAIR_LOG_DEBUG (lCSVDump);
133 logOutputFile.close();
135 if (hasSaleBeenSuccessful ==
false) {
136 STDAIR_LOG_DEBUG (
"No sale can be made for '" << lSegmentDateKey
140 return hasSaleBeenSuccessful;
147 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
150 BOOST_AUTO_TEST_SUITE (master_test_suite)
155 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
162 const bool isBuiltin =
false;
164 const bool isForSchedule =
false;
167 bool hasTestBeenSuccessful =
false;
168 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
169 testInventoryHelper (0, lInventoryInputFilename,
170 " ",
" ",
" ", isBuiltin, isForSchedule));
171 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
178 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
181 const bool isBuiltin =
true;
183 const bool isForSchedule =
false;
186 bool hasTestBeenSuccessful =
false;
187 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
188 testInventoryHelper (1,
" ",
" ",
" ",
" ",
189 isBuiltin, isForSchedule));
190 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
197 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
205 "/yieldstore01.csv");
208 const bool isBuiltin =
false;
210 const bool isForSchedule =
true;
213 bool hasTestBeenSuccessful =
false;
214 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
215 testInventoryHelper (2,
" ",
216 lScheduleInputFilename,
219 isBuiltin, isForSchedule));
220 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
228 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
235 const bool isBuiltin =
false;
237 const bool isForSchedule =
false;
240 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
241 " ",
" ",
" ", isBuiltin, isForSchedule),
250 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
257 const bool isBuiltin =
false;
259 const bool isForSchedule =
true;
262 BOOST_CHECK_THROW (testInventoryHelper (4,
" ", lMissingScheduleFilename,
263 " ",
" ", isBuiltin, isForSchedule),
272 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
283 const bool isBuiltin =
false;
285 const bool isForSchedule =
true;
288 BOOST_CHECK_THROW (testInventoryHelper (5,
" ",
289 lScheduleInputFilename,
292 isBuiltin, isForSchedule),
293 AIRRAC::YieldInputFileNotFoundException);
301 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
305 "/scheduleError01.csv");
312 const bool isBuiltin =
false;
314 const bool isForSchedule =
true;
317 BOOST_CHECK_THROW (testInventoryHelper (6,
" ",
318 lScheduleInputFilename,
321 isBuiltin, isForSchedule),
330 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
334 "/scheduleError02.csv");
338 "/yieldstore01.csv");
341 const bool isBuiltin =
false;
343 const bool isForSchedule =
true;
346 BOOST_CHECK_THROW (testInventoryHelper (7,
" ",
347 lScheduleInputFilename,
350 isBuiltin, isForSchedule),
356 BOOST_AUTO_TEST_SUITE_END()