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 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900 43 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
44 #else // BOOST_VERSION 45 boost_utf::unit_test_log.set_format (boost_utf::XML);
46 #endif // BOOST_VERSION 47 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
60 bool testInventoryHelper (
const unsigned short iTestFlag,
61 const stdair::Filename_T& iInventoryInputFilename,
62 const stdair::Filename_T& iScheduleInputFilename,
63 const stdair::Filename_T& iODInputFilename,
64 const stdair::Filename_T& iFRAT5InputFilename,
65 const stdair::Filename_T& iFFDisutilityInputFilename,
66 const stdair::Filename_T& iYieldInputFilename,
68 const bool isForSchedule) {
71 std::ostringstream oStr;
72 oStr <<
"InventoryTestSuite_" << iTestFlag <<
".log";
73 const stdair::Filename_T lLogFilename (oStr.str());
76 std::ofstream logOutputFile;
78 logOutputFile.open (lLogFilename.c_str());
79 logOutputFile.clear();
82 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
89 std::string lSegmentDateKey;
90 stdair::ClassCode_T lClassCode;
91 const stdair::PartySize_T lPartySize (2);
94 if (isBuiltin ==
true) {
97 airinvService.buildSampleBom();
100 lSegmentDateKey =
"BA,9,2011-06-10,LHR,SYD";
105 if (isForSchedule ==
true) {
107 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
108 stdair::ODFilePath lODFilePath (iODInputFilename);
109 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
110 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
111 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
112 airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
113 lFRAT5FilePath, lFFDisutilityFilePath,
117 lSegmentDateKey =
"SQ,11,2010-01-15,SIN,BKK";
124 airinvService.parseAndLoad (lInventoryFilePath);
128 lSegmentDateKey =
"SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
135 const bool hasSaleBeenSuccessful =
136 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
139 const std::string& lCSVDump = airinvService.csvDisplay();
140 STDAIR_LOG_DEBUG (lCSVDump);
143 logOutputFile.close();
145 if (hasSaleBeenSuccessful ==
false) {
146 STDAIR_LOG_DEBUG (
"No sale can be made for '" << lSegmentDateKey
150 return hasSaleBeenSuccessful;
157 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
160 BOOST_AUTO_TEST_SUITE (master_test_suite)
165 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
172 const bool isBuiltin =
false;
174 const bool isForSchedule =
false;
177 bool hasTestBeenSuccessful =
false;
178 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
179 testInventoryHelper (0, lInventoryInputFilename,
180 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule));
181 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
188 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
191 const bool isBuiltin =
true;
193 const bool isForSchedule =
false;
196 bool hasTestBeenSuccessful =
false;
197 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
198 testInventoryHelper (1,
" ",
" ",
" ",
" ",
" ",
" ",
199 isBuiltin, isForSchedule));
200 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
207 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
217 "/ffDisutility.csv");
219 "/yieldstore01.csv");
222 const bool isBuiltin =
false;
224 const bool isForSchedule =
true;
227 bool hasTestBeenSuccessful =
false;
228 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
229 testInventoryHelper (2,
" ",
230 lScheduleInputFilename,
233 lFFDisutilityInputFilename,
235 isBuiltin, isForSchedule));
236 BOOST_CHECK_EQUAL (hasTestBeenSuccessful,
true);
244 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
251 const bool isBuiltin =
false;
253 const bool isForSchedule =
false;
256 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
257 " ",
" ",
" ",
" ",
" ", isBuiltin, isForSchedule),
266 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
274 "/ffDisutility.csv");
277 const bool isBuiltin =
false;
279 const bool isForSchedule =
true;
282 BOOST_CHECK_THROW (testInventoryHelper (4,
" ", lMissingScheduleFilename,
283 " ", lFRAT5InputFilename,
284 lFFDisutilityInputFilename,
" ",
285 isBuiltin, isForSchedule),
294 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
304 "/ffDisutility.csv");
309 const bool isBuiltin =
false;
311 const bool isForSchedule =
true;
314 BOOST_CHECK_THROW (testInventoryHelper (5,
" ",
315 lScheduleInputFilename,
318 lFFDisutilityInputFilename,
320 isBuiltin, isForSchedule),
321 AIRRAC::YieldInputFileNotFoundException);
329 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
333 "/scheduleError01.csv");
339 "/ffDisutility.csv");
344 const bool isBuiltin =
false;
346 const bool isForSchedule =
true;
349 BOOST_CHECK_THROW (testInventoryHelper (6,
" ",
350 lScheduleInputFilename,
353 lFFDisutilityInputFilename,
355 isBuiltin, isForSchedule),
364 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
368 "/scheduleError02.csv");
374 "/ffDisutility.csv");
376 "/yieldstore01.csv");
379 const bool isBuiltin =
false;
381 const bool isForSchedule =
true;
384 BOOST_CHECK_THROW (testInventoryHelper (7,
" ",
385 lScheduleInputFilename,
388 lFFDisutilityInputFilename,
390 isBuiltin, isForSchedule),
396 BOOST_AUTO_TEST_SUITE_END()
#define STDAIR_SAMPLE_DIR
Interface for the AIRINV Services.