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 <boost/date_time/gregorian/gregorian.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/basic/BasLogParams.hpp>
22 #include <stdair/basic/BasDBParams.hpp>
23 #include <stdair/basic/BasFileMgr.hpp>
24 #include <stdair/bom/TravelSolutionStruct.hpp>
25 #include <stdair/bom/BookingRequestStruct.hpp>
26 #include <stdair/service/Logger.hpp>
30 #include <airtsp/config/airtsp-paths.hpp>
32 namespace boost_utf = boost::unit_test;
35 std::ofstream utfReportStream (
"AirlineScheduleTestSuite_utfresults.xml");
40 struct UnitTestConfig {
43 boost_utf::unit_test_log.set_stream (utfReportStream);
44 boost_utf::unit_test_log.set_format (boost_utf::XML);
45 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
58 const unsigned int testScheduleHelper (
const unsigned short iTestFlag,
59 const stdair::Filename_T& iScheduleInputFilename,
60 const stdair::Filename_T& iODInputFilename,
62 const bool isWithOnD) {
65 std::ostringstream oStr;
66 oStr <<
"AirlineScheduleTestSuite_" << 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 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
79 stdair::AirportCode_T lOrigin;
80 stdair::AirportCode_T lDestination;
81 stdair::AirportCode_T lPOS;
82 stdair::Date_T lPreferredDepartureDate;;
83 stdair::Date_T lRequestDate;
86 if (isBuiltin ==
true) {
89 airtspService.buildSampleBom();
94 lPreferredDepartureDate = boost::gregorian::from_string (
"2010/02/08");
95 lRequestDate = boost::gregorian::from_string (
"2010/01/21");
99 if (isWithOnD ==
false) {
102 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
103 airtspService.parseAndLoad (lScheduleFilePath);
106 lDestination =
"BKK";
108 lPreferredDepartureDate = boost::gregorian::from_string (
"2007/04/21");
109 lRequestDate = boost::gregorian::from_string (
"2007/03/21");
114 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
115 const stdair::ODFilePath lODFilePath (iODInputFilename);
116 airtspService.parseAndLoad (lScheduleFilePath,
120 lDestination =
"BKK";
122 lPreferredDepartureDate = boost::gregorian::from_string (
"2012/06/04");
123 lRequestDate = boost::gregorian::from_string (
"2012/01/01");
129 const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
130 const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
131 const stdair::CabinCode_T lPreferredCabin (
"Bus");
132 const stdair::PartySize_T lPartySize (3);
133 const stdair::ChannelLabel_T lChannel (
"DF");
134 const stdair::TripType_T lTripType (
"RO");
135 const stdair::DayDuration_T lStayDuration (5);
136 const stdair::FrequentFlyer_T lFrequentFlyerType (
"NONE");
137 const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
138 const stdair::WTP_T lWTP (2000.0);
139 const stdair::PriceValue_T lValueOfTime (20.0);
140 const stdair::ChangeFees_T lChangeFees (
true);
141 const stdair::Disutility_T lChangeFeeDisutility (50);
142 const stdair::NonRefundable_T lNonRefundable (
true);
143 const stdair::Disutility_T lNonRefundableDisutility (50);
145 const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
147 lPreferredDepartureDate,
150 lPartySize, lChannel,
151 lTripType, lStayDuration,
153 lPreferredDepartureTime,
156 lChangeFeeDisutility,
158 lNonRefundableDisutility);
161 stdair::TravelSolutionList_T lTravelSolutionList;
162 airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
163 const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
165 STDAIR_LOG_DEBUG (
"The number of travel solutions for the booking request '"
166 << lBookingRequest.describe() <<
"' is equal to "
167 << lNbOfTravelSolutions <<
".");
170 logOutputFile.close();
172 return lNbOfTravelSolutions;
179 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
182 BOOST_AUTO_TEST_SUITE (master_test_suite)
187 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
190 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
194 const bool isBuiltin =
false;
195 const bool isWithOnD =
false;
198 unsigned int lNbOfTravelSolutions = 0;
199 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
200 testScheduleHelper (0, lScheduleInputFilename,
" ",
201 isBuiltin, isWithOnD));
204 const unsigned int lExpectedNbOfTravelSolutions = 4;
205 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
206 "The number of travel solutions is "
207 << lNbOfTravelSolutions <<
", but it should be equal to "
208 << lExpectedNbOfTravelSolutions);
215 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
218 const bool isBuiltin =
true;
219 const bool isWithOnD =
false;
222 unsigned int lNbOfTravelSolutions = 0;
223 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
224 testScheduleHelper (1,
" ",
" ", isBuiltin, isWithOnD));
227 const unsigned int lExpectedNbOfTravelSolutions = 1;
228 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
229 "The number of travel solutions is "
230 << lNbOfTravelSolutions <<
", but it should be equal to "
231 << lExpectedNbOfTravelSolutions);
238 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
241 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
242 "/rds01/schedule05.csv");
243 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
247 const bool isBuiltin =
false;
248 const bool isWithOnD =
true;
251 unsigned int lNbOfTravelSolutions = 0;
252 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
253 testScheduleHelper (2, lScheduleInputFilename,
255 isBuiltin, isWithOnD));
258 const unsigned int lExpectedNbOfTravelSolutions = 1;
259 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
260 "The number of travel solutions is "
261 << lNbOfTravelSolutions <<
", but it should be equal to "
262 << lExpectedNbOfTravelSolutions);
268 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
271 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
273 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
274 "/missingFiles.csv");
277 const bool isBuiltin =
false;
278 const bool isWithOnD =
true;
281 BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
283 isBuiltin, isWithOnD),
290 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
293 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
294 "/missingFiles.csv");
297 const bool isBuiltin =
false;
298 const bool isWithOnD =
false;
301 BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename,
" ",
302 isBuiltin, isWithOnD),
310 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
313 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
314 "/scheduleError03.csv");
317 const bool isBuiltin =
false;
318 const bool isWithOnD =
false;
321 BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
323 isBuiltin, isWithOnD),
331 BOOST_AUTO_TEST_SUITE_END()