AirTSP Logo  1.01.3
C++ Simulated Airline Travel Solution Provider (TSP) Library
AirlineScheduleTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
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 // Boost Date-Time
18 #include <boost/date_time/gregorian/gregorian.hpp>
19 // StdAir
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>
27 // AirTSP
28 #include <airtsp/AIRTSP_Types.hpp>
30 #include <airtsp/config/airtsp-paths.hpp>
31 
32 namespace boost_utf = boost::unit_test;
33 
34 // (Boost) Unit Test XML Report
35 std::ofstream utfReportStream ("AirlineScheduleTestSuite_utfresults.xml");
36 
40 struct UnitTestConfig {
42  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);
50  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
51  }
52 
54  ~UnitTestConfig() {
55  }
56 };
57 
58 // //////////////////////////////////////////////////////////////////////
62  const unsigned int testScheduleHelper (const unsigned short iTestFlag,
63  const stdair::Filename_T& iScheduleInputFilename,
64  const stdair::Filename_T& iODInputFilename,
65  const bool isBuiltin,
66  const bool isWithOnD) {
67 
68  // Output log File
69  std::ostringstream oStr;
70  oStr << "AirlineScheduleTestSuite_" << iTestFlag << ".log";
71  const stdair::Filename_T lLogFilename (oStr.str());
72 
73  // Set the log parameters
74  std::ofstream logOutputFile;
75  // Open and clean the log outputfile
76  logOutputFile.open (lLogFilename.c_str());
77  logOutputFile.clear();
78 
79  // Instantiate the AirTSP service
80  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
81  AIRTSP::AIRTSP_Service airtspService (lLogParams);
82 
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;
88 
89  // Check wether or not a (CSV) input file should be read
90  if (isBuiltin == true) {
91 
92  // Build the default sample BOM tree (filled with schedules)
93  airtspService.buildSampleBom();
94 
95  lOrigin = "SIN";
96  lDestination = "BKK";
97  lPOS = "SIN";
98  lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
99  lRequestDate = boost::gregorian::from_string ("2010/01/21");
100 
101  } else {
102 
103  if (isWithOnD == false) {
104 
105  // Build the BOM tree from parsing input files
106  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
107  airtspService.parseAndLoad (lScheduleFilePath);
108 
109  lOrigin = "NCE";
110  lDestination = "BKK";
111  lPOS = "NCE";
112  lPreferredDepartureDate = boost::gregorian::from_string ("2007/04/21");
113  lRequestDate = boost::gregorian::from_string ("2007/03/21");
114 
115  } else {
116 
117  // Build the BOM tree from parsing input files
118  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
119  const stdair::ODFilePath lODFilePath (iODInputFilename);
120  airtspService.parseAndLoad (lScheduleFilePath,
121  lODFilePath);
122 
123  lOrigin = "SIN";
124  lDestination = "BKK";
125  lPOS = "SIN";
126  lPreferredDepartureDate = boost::gregorian::from_string ("2012/06/04");
127  lRequestDate = boost::gregorian::from_string ("2012/01/01");
128  }
129 
130  }
131 
132  // Create a booking request structure
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);
148 
149  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
150  lPOS,
151  lPreferredDepartureDate,
152  lRequestDateTime,
153  lPreferredCabin,
154  lPartySize, lChannel,
155  lTripType, lStayDuration,
156  lFrequentFlyerType,
157  lPreferredDepartureTime,
158  lWTP, lValueOfTime,
159  lChangeFees,
160  lChangeFeeDisutility,
161  lNonRefundable,
162  lNonRefundableDisutility);
163 
164  // Build the segment path list
165  stdair::TravelSolutionList_T lTravelSolutionList;
166  airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
167  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
168 
169  STDAIR_LOG_DEBUG ("The number of travel solutions for the booking request '"
170  << lBookingRequest.describe() << "' is equal to "
171  << lNbOfTravelSolutions << ".");
172 
173  // Close the Log outputFile
174  logOutputFile.close();
175 
176  return lNbOfTravelSolutions;
177 }
178 
179 
180 // /////////////// Main: Unit Test Suite //////////////
181 
182 // Set the UTF configuration (re-direct the output to a specific file)
183 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
184 
185 // Start the test suite
186 BOOST_AUTO_TEST_SUITE (master_test_suite)
187 
188 
191 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
192 
193  // Input file name
194  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
195  "/schedule03.csv");
196 
197  // State whether the BOM tree should be built-in or parsed from input files
198  const bool isBuiltin = false;
199  const bool isWithOnD = false;
200 
201  // Try to build a travel solution list
202  unsigned int lNbOfTravelSolutions = 0;
203  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
204  testScheduleHelper (0, lScheduleInputFilename, " ",
205  isBuiltin, isWithOnD));
206 
207  // Check the size of the travel solution list
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);
213 
214 }
215 
219 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
220 
221  // State whether the BOM tree should be built-in or parsed from input files
222  const bool isBuiltin = true;
223  const bool isWithOnD = false;
224 
225  // Try to build a travel solution list
226  unsigned int lNbOfTravelSolutions = 0;
227  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
228  testScheduleHelper (1, " ", " ", isBuiltin, isWithOnD));
229 
230  // Check the size of the travel solution list
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);
236 
237 }
238 
242 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
243 
244  // Input file names
245  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
246  "/rds01/schedule05.csv");
247  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
248  "/ond01.csv");
249 
250  // State whether the BOM tree should be built-in or parsed from input files
251  const bool isBuiltin = false;
252  const bool isWithOnD = true;
253 
254  // Try to build a travel solution list
255  unsigned int lNbOfTravelSolutions = 0;
256  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
257  testScheduleHelper (2, lScheduleInputFilename,
258  lODInputFilename,
259  isBuiltin, isWithOnD));
260 
261  // Check the size of the travel solution list
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);
267 }
268 
272 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
273 
274  // Input file names
275  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
276  "/schedule03.csv");
277  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
278  "/missingFiles.csv");
279 
280  // State whether the BOM tree should be built-in or parsed from input files
281  const bool isBuiltin = false;
282  const bool isWithOnD = true;
283 
284  // Try to build a travel solution list
285  BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
286  lODInputFilename,
287  isBuiltin, isWithOnD),
289 }
290 
294 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
295 
296  // Input file name
297  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
298  "/missingFiles.csv");
299 
300  // State whether the BOM tree should be built-in or parsed from input files
301  const bool isBuiltin = false;
302  const bool isWithOnD = false;
303 
304  // Try to build a travel solution list
305  BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename, " ",
306  isBuiltin, isWithOnD),
308 
309 }
310 
314 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
315 
316  // Input file name
317  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
318  "/scheduleError03.csv");
319 
320  // State whether the BOM tree should be built-in or parsed from input files
321  const bool isBuiltin = false;
322  const bool isWithOnD = false;
323 
324  // Try to build a travel solution list
325  BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
326  " " ,
327  isBuiltin, isWithOnD),
329 
330 
331 }
332 
333 
334 // End the test suite
335 BOOST_AUTO_TEST_SUITE_END()
336 
337 
Interface for the Airtsp Services.