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>
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 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
45 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
46 #else // BOOST_VERSION
47 boost_utf::unit_test_log.set_format (boost_utf::XML);
48 #endif // BOOST_VERSION
49 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
62 const unsigned int testScheduleHelper (
const unsigned short iTestFlag,
63 const stdair::Filename_T& iScheduleInputFilename,
64 const stdair::Filename_T& iODInputFilename,
66 const bool isWithOnD) {
69 std::ostringstream oStr;
70 oStr <<
"AirlineScheduleTestSuite_" << iTestFlag <<
".log";
71 const stdair::Filename_T lLogFilename (oStr.str());
74 std::ofstream logOutputFile;
76 logOutputFile.open (lLogFilename.c_str());
77 logOutputFile.clear();
80 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
83 stdair::AirportCode_T lOrigin;
84 stdair::AirportCode_T lDestination;
85 stdair::AirportCode_T lPOS;
86 stdair::Date_T lPreferredDepartureDate;;
87 stdair::Date_T lRequestDate;
90 if (isBuiltin ==
true) {
93 airtspService.buildSampleBom();
98 lPreferredDepartureDate = boost::gregorian::from_string (
"2010/02/08");
99 lRequestDate = boost::gregorian::from_string (
"2010/01/21");
103 if (isWithOnD ==
false) {
106 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
107 airtspService.parseAndLoad (lScheduleFilePath);
110 lDestination =
"BKK";
112 lPreferredDepartureDate = boost::gregorian::from_string (
"2007/04/21");
113 lRequestDate = boost::gregorian::from_string (
"2007/03/21");
118 const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
119 const stdair::ODFilePath lODFilePath (iODInputFilename);
120 airtspService.parseAndLoad (lScheduleFilePath,
124 lDestination =
"BKK";
126 lPreferredDepartureDate = boost::gregorian::from_string (
"2012/06/04");
127 lRequestDate = boost::gregorian::from_string (
"2012/01/01");
133 const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
134 const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
135 const stdair::CabinCode_T lPreferredCabin (
"Bus");
136 const stdair::PartySize_T lPartySize (3);
137 const stdair::ChannelLabel_T lChannel (
"DF");
138 const stdair::TripType_T lTripType (
"RO");
139 const stdair::DayDuration_T lStayDuration (5);
140 const stdair::FrequentFlyer_T lFrequentFlyerType (
"NONE");
141 const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
142 const stdair::WTP_T lWTP (2000.0);
143 const stdair::PriceValue_T lValueOfTime (20.0);
144 const stdair::ChangeFees_T lChangeFees (
true);
145 const stdair::Disutility_T lChangeFeeDisutility (50);
146 const stdair::NonRefundable_T lNonRefundable (
true);
147 const stdair::Disutility_T lNonRefundableDisutility (50);
149 const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
151 lPreferredDepartureDate,
154 lPartySize, lChannel,
155 lTripType, lStayDuration,
157 lPreferredDepartureTime,
160 lChangeFeeDisutility,
162 lNonRefundableDisutility);
165 stdair::TravelSolutionList_T lTravelSolutionList;
166 airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
167 const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
169 STDAIR_LOG_DEBUG (
"The number of travel solutions for the booking request '"
170 << lBookingRequest.describe() <<
"' is equal to "
171 << lNbOfTravelSolutions <<
".");
174 logOutputFile.close();
176 return lNbOfTravelSolutions;
183 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
186 BOOST_AUTO_TEST_SUITE (master_test_suite)
191 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
194 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
198 const bool isBuiltin =
false;
199 const bool isWithOnD =
false;
202 unsigned int lNbOfTravelSolutions = 0;
203 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
204 testScheduleHelper (0, lScheduleInputFilename,
" ",
205 isBuiltin, isWithOnD));
208 const unsigned int lExpectedNbOfTravelSolutions = 4;
209 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
210 "The number of travel solutions is "
211 << lNbOfTravelSolutions <<
", but it should be equal to "
212 << lExpectedNbOfTravelSolutions);
219 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
222 const bool isBuiltin =
true;
223 const bool isWithOnD =
false;
226 unsigned int lNbOfTravelSolutions = 0;
227 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
228 testScheduleHelper (1,
" ",
" ", isBuiltin, isWithOnD));
231 const unsigned int lExpectedNbOfTravelSolutions = 1;
232 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
233 "The number of travel solutions is "
234 << lNbOfTravelSolutions <<
", but it should be equal to "
235 << lExpectedNbOfTravelSolutions);
242 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
245 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
246 "/rds01/schedule05.csv");
247 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
251 const bool isBuiltin =
false;
252 const bool isWithOnD =
true;
255 unsigned int lNbOfTravelSolutions = 0;
256 BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
257 testScheduleHelper (2, lScheduleInputFilename,
259 isBuiltin, isWithOnD));
262 const unsigned int lExpectedNbOfTravelSolutions = 1;
263 BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
264 "The number of travel solutions is "
265 << lNbOfTravelSolutions <<
", but it should be equal to "
266 << lExpectedNbOfTravelSolutions);
272 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
275 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
277 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
278 "/missingFiles.csv");
281 const bool isBuiltin =
false;
282 const bool isWithOnD =
true;
285 BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
287 isBuiltin, isWithOnD),
294 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
297 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
298 "/missingFiles.csv");
301 const bool isBuiltin =
false;
302 const bool isWithOnD =
false;
305 BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename,
" ",
306 isBuiltin, isWithOnD),
314 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
317 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
318 "/scheduleError03.csv");
321 const bool isBuiltin =
false;
322 const bool isWithOnD =
false;
325 BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
327 isBuiltin, isWithOnD),
335 BOOST_AUTO_TEST_SUITE_END()