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 <boost/date_time/gregorian/gregorian.hpp>
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/basic/BasLogParams.hpp>
23 #include <stdair/basic/BasDBParams.hpp>
24 #include <stdair/basic/BasFileMgr.hpp>
25 #include <stdair/bom/TravelSolutionStruct.hpp>
26 #include <stdair/bom/BookingRequestStruct.hpp>
27 #include <stdair/service/Logger.hpp>
31 #include <airtsp/config/airtsp-paths.hpp>
33 namespace boost_utf = boost::unit_test;
36 std::ofstream utfReportStream (
"AirlineScheduleTestSuite_utfresults.xml");
41 struct UnitTestConfig {
44 boost_utf::unit_test_log.set_stream (utfReportStream);
45 #if BOOST_VERSION >= 105900
46 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
48 boost_utf::unit_test_log.set_format (boost_utf::XML);
50 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
63 const unsigned int testScheduleHelper (
const unsigned short iTestFlag,
64 const stdair::Filename_T& iScheduleInputFilename,
65 const stdair::Filename_T& iODInputFilename,
67 const bool isWithOnD) {
70 std::ostringstream oStr;
71 oStr <<
"AirlineScheduleTestSuite_" << iTestFlag <<
".log";
72 const stdair::Filename_T lLogFilename (oStr.str());
75 std::ofstream logOutputFile;
77 logOutputFile.open (lLogFilename.c_str());
78 logOutputFile.clear();
81 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
84 stdair::AirportCode_T lOrigin;
85 stdair::AirportCode_T lDestination;
86 stdair::AirportCode_T lPOS;
87 stdair::Date_T lPreferredDepartureDate;;
88 stdair::Date_T lRequestDate;
91 if (isBuiltin ==
true) {
94 airtspService.buildSampleBom();
99 lPreferredDepartureDate = boost::gregorian::from_string (
"2010/02/08");
100 lRequestDate = boost::gregorian::from_string (
"2010/01/21");
104 if (isWithOnD ==
false) {
107 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
108 airtspService.parseAndLoad (lScheduleFilePath);
111 lDestination =
"BKK";
113 lPreferredDepartureDate = boost::gregorian::from_string (
"2007/04/21");
114 lRequestDate = boost::gregorian::from_string (
"2007/03/21");
119 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
120 const stdair::ODFilePath lODFilePath (iODInputFilename);
121 airtspService.parseAndLoad (lScheduleFilePath,
125 lDestination =
"BKK";
127 lPreferredDepartureDate = boost::gregorian::from_string (
"2012/06/04");
128 lRequestDate = boost::gregorian::from_string (
"2012/01/01");
134 const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
135 const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
136 const stdair::CabinCode_T lPreferredCabin (
"Bus");
137 const stdair::PartySize_T lPartySize (3);
138 const stdair::ChannelLabel_T lChannel (
"DF");
139 const stdair::TripType_T lTripType (
"RO");
140 const stdair::DayDuration_T lStayDuration (5);
141 const stdair::FrequentFlyer_T lFrequentFlyerType (
"NONE");
142 const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
143 const stdair::WTP_T lWTP (2000.0);
144 const stdair::PriceValue_T lValueOfTime (20.0);
145 const stdair::ChangeFees_T lChangeFees (
true);
146 const stdair::Disutility_T lChangeFeeDisutility (50);
147 const stdair::NonRefundable_T lNonRefundable (
true);
148 const stdair::Disutility_T lNonRefundableDisutility (50);
150 const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
152 lPreferredDepartureDate,
155 lPartySize, lChannel,
156 lTripType, lStayDuration,
158 lPreferredDepartureTime,
161 lChangeFeeDisutility,
163 lNonRefundableDisutility);
166 stdair::TravelSolutionList_T lTravelSolutionList;
167 airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
168 const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
170 STDAIR_LOG_DEBUG (
"The number of travel solutions for the booking request '"
171 << lBookingRequest.describe() <<
"' is equal to "
172 << lNbOfTravelSolutions <<
".");
175 logOutputFile.close();
177 return lNbOfTravelSolutions;
184 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
187 BOOST_AUTO_TEST_SUITE (master_test_suite)
192 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
195 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
199 const bool isBuiltin =
false;
200 const bool isWithOnD =
false;
203 unsigned int lNbOfTravelSolutions = 0;
204 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
205 testScheduleHelper (0, lScheduleInputFilename,
" ",
206 isBuiltin, isWithOnD));
209 const unsigned int lExpectedNbOfTravelSolutions = 4;
210 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
211 "The number of travel solutions is "
212 << lNbOfTravelSolutions <<
", but it should be equal to "
213 << lExpectedNbOfTravelSolutions);
220 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
223 const bool isBuiltin =
true;
224 const bool isWithOnD =
false;
227 unsigned int lNbOfTravelSolutions = 0;
228 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
229 testScheduleHelper (1,
" ",
" ", isBuiltin, isWithOnD));
232 const unsigned int lExpectedNbOfTravelSolutions = 1;
233 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
234 "The number of travel solutions is "
235 << lNbOfTravelSolutions <<
", but it should be equal to "
236 << lExpectedNbOfTravelSolutions);
243 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
246 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
247 "/rds01/schedule05.csv");
248 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
252 const bool isBuiltin =
false;
253 const bool isWithOnD =
true;
256 unsigned int lNbOfTravelSolutions = 0;
257 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
258 testScheduleHelper (2, lScheduleInputFilename,
260 isBuiltin, isWithOnD));
263 const unsigned int lExpectedNbOfTravelSolutions = 1;
264 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
265 "The number of travel solutions is "
266 << lNbOfTravelSolutions <<
", but it should be equal to "
267 << lExpectedNbOfTravelSolutions);
273 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
276 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
278 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
279 "/missingFiles.csv");
282 const bool isBuiltin =
false;
283 const bool isWithOnD =
true;
286 BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
288 isBuiltin, isWithOnD),
295 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
298 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
299 "/missingFiles.csv");
302 const bool isBuiltin =
false;
303 const bool isWithOnD =
false;
306 BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename,
" ",
307 isBuiltin, isWithOnD),
315 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
318 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
319 "/scheduleError03.csv");
322 const bool isBuiltin =
false;
323 const bool isWithOnD =
false;
326 BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
328 isBuiltin, isWithOnD),
336 BOOST_AUTO_TEST_SUITE_END()
Interface for the Airtsp Services.