13 #define BOOST_TEST_DYN_LINK 14 #define BOOST_TEST_MAIN 15 #define BOOST_TEST_MODULE InventoryTestSuite 16 #include <boost/test/unit_test.hpp> 17 #include <boost/version.hpp> 19 #include <stdair/basic/BasLogParams.hpp> 20 #include <stdair/basic/BasDBParams.hpp> 21 #include <stdair/basic/BasFileMgr.hpp> 22 #include <stdair/bom/TravelSolutionStruct.hpp> 23 #include <stdair/bom/BookingRequestStruct.hpp> 24 #include <stdair/service/Logger.hpp> 25 #include <stdair/stdair_exceptions.hpp> 31 namespace boost_utf = boost::unit_test;
34 std::ofstream utfReportStream (
"InventoryTestSuite_utfresults.xml");
39 struct UnitTestConfig {
42 boost_utf::unit_test_log.set_stream (utfReportStream);
43 #if BOOST_VERSION >= 105900 44 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
46 boost_utf::unit_test_log.set_format (boost_utf::XML);
48 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
61 bool testInventoryHelper (
const unsigned short iTestFlag,
62 const stdair::Filename_T& iInventoryInputFilename,
63 const stdair::Filename_T& iScheduleInputFilename,
64 const stdair::Filename_T& iODInputFilename,
65 const stdair::Filename_T& iFRAT5InputFilename,
66 const stdair::Filename_T& iFFDisutilityInputFilename,
67 const stdair::Filename_T& iYieldInputFilename,
69 const bool isForSchedule) {
72 std::ostringstream oStr;
73 oStr <<
"InventoryTestSuite_" << iTestFlag <<
".log";
74 const stdair::Filename_T lLogFilename (oStr.str());
77 std::ofstream logOutputFile;
79 logOutputFile.open (lLogFilename.c_str());
80 logOutputFile.clear();
83 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
90 std::string lSegmentDateKey;
91 stdair::ClassCode_T lClassCode;
92 const stdair::PartySize_T lPartySize (2);
95 if (isBuiltin ==
true) {
98 airinvService.buildSampleBom();
101 lSegmentDateKey =
"BA,9,2011-06-10,LHR,SYD";
106 if (isForSchedule ==
true) {
108 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
109 stdair::ODFilePath lODFilePath (iODInputFilename);
110 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
111 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
112 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
113 airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
114 lFRAT5FilePath, lFFDisutilityFilePath,
118 lSegmentDateKey =
"SQ,11,2010-01-15,SIN,BKK";
125 airinvService.parseAndLoad (lInventoryFilePath);
129 lSegmentDateKey =
"SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
136 const bool hasSaleBeenSuccessful =
137 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
140 const std::string& lCSVDump = airinvService.csvDisplay();
141 STDAIR_LOG_DEBUG (lCSVDump);
144 logOutputFile.close();
146 if (hasSaleBeenSuccessful ==
false) {
147 STDAIR_LOG_DEBUG (
"No sale can be made for '" << lSegmentDateKey
151 return hasSaleBeenSuccessful;
158 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
161 BOOST_AUTO_TEST_SUITE (master_test_suite)
166 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
173 const bool isBuiltin =
false;
175 const bool isForSchedule =
false;
178 bool hasTestBeenSuccessful =
false;
179 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
180 testInventoryHelper (0, lInventoryInputFilename,
181 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule));
182 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
189 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
192 const bool isBuiltin =
true;
194 const bool isForSchedule =
false;
197 bool hasTestBeenSuccessful =
false;
198 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
199 testInventoryHelper (1,
" ",
" ",
" ",
" ",
" ",
" ",
200 isBuiltin, isForSchedule));
201 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
208 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
218 "/ffDisutility.csv");
220 "/yieldstore01.csv");
223 const bool isBuiltin =
false;
225 const bool isForSchedule =
true;
228 bool hasTestBeenSuccessful =
false;
229 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
230 testInventoryHelper (2,
" ",
231 lScheduleInputFilename,
234 lFFDisutilityInputFilename,
236 isBuiltin, isForSchedule));
237 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
245 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
252 const bool isBuiltin =
false;
254 const bool isForSchedule =
false;
257 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
258 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule),
267 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
275 "/ffDisutility.csv");
278 const bool isBuiltin =
false;
280 const bool isForSchedule =
true;
283 BOOST_CHECK_THROW (testInventoryHelper (4,
" ", lMissingScheduleFilename,
284 " ", lFRAT5InputFilename,
285 lFFDisutilityInputFilename,
" ",
286 isBuiltin, isForSchedule),
295 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
305 "/ffDisutility.csv");
310 const bool isBuiltin =
false;
312 const bool isForSchedule =
true;
315 BOOST_CHECK_THROW (testInventoryHelper (5,
" ",
316 lScheduleInputFilename,
319 lFFDisutilityInputFilename,
321 isBuiltin, isForSchedule),
322 AIRRAC::YieldInputFileNotFoundException);
330 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
334 "/scheduleError01.csv");
340 "/ffDisutility.csv");
345 const bool isBuiltin =
false;
347 const bool isForSchedule =
true;
350 BOOST_CHECK_THROW (testInventoryHelper (6,
" ",
351 lScheduleInputFilename,
354 lFFDisutilityInputFilename,
356 isBuiltin, isForSchedule),
365 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
369 "/scheduleError02.csv");
375 "/ffDisutility.csv");
377 "/yieldstore01.csv");
380 const bool isBuiltin =
false;
382 const bool isForSchedule =
true;
385 BOOST_CHECK_THROW (testInventoryHelper (7,
" ",
386 lScheduleInputFilename,
389 lFFDisutilityInputFilename,
391 isBuiltin, isForSchedule),
397 BOOST_AUTO_TEST_SUITE_END()
#define STDAIR_SAMPLE_DIR
Interface for the AIRINV Services.