AirTSP Logo  1.01.0
C++ Simulated Airline Travel Solution Provider Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  boost_utf::unit_test_log.set_format (boost_utf::XML);
45  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
46  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
47  }
48 
50  ~UnitTestConfig() {
51  }
52 };
53 
54 // //////////////////////////////////////////////////////////////////////
58  const unsigned int testScheduleHelper (const unsigned short iTestFlag,
59  const stdair::Filename_T& iScheduleInputFilename,
60  const stdair::Filename_T& iODInputFilename,
61  const bool isBuiltin,
62  const bool isWithOnD) {
63 
64  // Output log File
65  std::ostringstream oStr;
66  oStr << "AirlineScheduleTestSuite_" << iTestFlag << ".log";
67  const stdair::Filename_T lLogFilename (oStr.str());
68 
69  // Set the log parameters
70  std::ofstream logOutputFile;
71  // Open and clean the log outputfile
72  logOutputFile.open (lLogFilename.c_str());
73  logOutputFile.clear();
74 
75  // Instantiate the AirTSP service
76  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
77  AIRTSP::AIRTSP_Service airtspService (lLogParams);
78 
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;
84 
85  // Check wether or not a (CSV) input file should be read
86  if (isBuiltin == true) {
87 
88  // Build the default sample BOM tree (filled with schedules)
89  airtspService.buildSampleBom();
90 
91  lOrigin = "SIN";
92  lDestination = "BKK";
93  lPOS = "SIN";
94  lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
95  lRequestDate = boost::gregorian::from_string ("2010/01/21");
96 
97  } else {
98 
99  if (isWithOnD == false) {
100 
101  // Build the BOM tree from parsing input files
102  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
103  airtspService.parseAndLoad (lScheduleFilePath);
104 
105  lOrigin = "NCE";
106  lDestination = "BKK";
107  lPOS = "NCE";
108  lPreferredDepartureDate = boost::gregorian::from_string ("2007/04/21");
109  lRequestDate = boost::gregorian::from_string ("2007/03/21");
110 
111  } else {
112 
113  // Build the BOM tree from parsing input files
114  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
115  const stdair::ODFilePath lODFilePath (iODInputFilename);
116  airtspService.parseAndLoad (lScheduleFilePath,
117  lODFilePath);
118 
119  lOrigin = "SIN";
120  lDestination = "BKK";
121  lPOS = "SIN";
122  lPreferredDepartureDate = boost::gregorian::from_string ("2012/06/04");
123  lRequestDate = boost::gregorian::from_string ("2012/01/01");
124  }
125 
126  }
127 
128  // Create a booking request structure
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);
144 
145  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
146  lPOS,
147  lPreferredDepartureDate,
148  lRequestDateTime,
149  lPreferredCabin,
150  lPartySize, lChannel,
151  lTripType, lStayDuration,
152  lFrequentFlyerType,
153  lPreferredDepartureTime,
154  lWTP, lValueOfTime,
155  lChangeFees,
156  lChangeFeeDisutility,
157  lNonRefundable,
158  lNonRefundableDisutility);
159 
160  // Build the segment path list
161  stdair::TravelSolutionList_T lTravelSolutionList;
162  airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
163  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
164 
165  STDAIR_LOG_DEBUG ("The number of travel solutions for the booking request '"
166  << lBookingRequest.describe() << "' is equal to "
167  << lNbOfTravelSolutions << ".");
168 
169  // Close the Log outputFile
170  logOutputFile.close();
171 
172  return lNbOfTravelSolutions;
173 }
174 
175 
176 // /////////////// Main: Unit Test Suite //////////////
177 
178 // Set the UTF configuration (re-direct the output to a specific file)
179 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
180 
181 // Start the test suite
182 BOOST_AUTO_TEST_SUITE (master_test_suite)
183 
184 
187 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
188 
189  // Input file name
190  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
191  "/schedule03.csv");
192 
193  // State whether the BOM tree should be built-in or parsed from input files
194  const bool isBuiltin = false;
195  const bool isWithOnD = false;
196 
197  // Try to build a travel solution list
198  unsigned int lNbOfTravelSolutions = 0;
199  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
200  testScheduleHelper (0, lScheduleInputFilename, " ",
201  isBuiltin, isWithOnD));
202 
203  // Check the size of the travel solution list
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);
209 
210 }
211 
215 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
216 
217  // State whether the BOM tree should be built-in or parsed from input files
218  const bool isBuiltin = true;
219  const bool isWithOnD = false;
220 
221  // Try to build a travel solution list
222  unsigned int lNbOfTravelSolutions = 0;
223  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
224  testScheduleHelper (1, " ", " ", isBuiltin, isWithOnD));
225 
226  // Check the size of the travel solution list
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);
232 
233 }
234 
238 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
239 
240  // Input file names
241  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
242  "/rds01/schedule05.csv");
243  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
244  "/ond01.csv");
245 
246  // State whether the BOM tree should be built-in or parsed from input files
247  const bool isBuiltin = false;
248  const bool isWithOnD = true;
249 
250  // Try to build a travel solution list
251  unsigned int lNbOfTravelSolutions = 0;
252  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
253  testScheduleHelper (2, lScheduleInputFilename,
254  lODInputFilename,
255  isBuiltin, isWithOnD));
256 
257  // Check the size of the travel solution list
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);
263 }
264 
268 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
269 
270  // Input file names
271  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
272  "/schedule03.csv");
273  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
274  "/missingFiles.csv");
275 
276  // State whether the BOM tree should be built-in or parsed from input files
277  const bool isBuiltin = false;
278  const bool isWithOnD = true;
279 
280  // Try to build a travel solution list
281  BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
282  lODInputFilename,
283  isBuiltin, isWithOnD),
285 }
286 
290 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
291 
292  // Input file name
293  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
294  "/missingFiles.csv");
295 
296  // State whether the BOM tree should be built-in or parsed from input files
297  const bool isBuiltin = false;
298  const bool isWithOnD = false;
299 
300  // Try to build a travel solution list
301  BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename, " ",
302  isBuiltin, isWithOnD),
304 
305 }
306 
310 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
311 
312  // Input file name
313  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
314  "/scheduleError03.csv");
315 
316  // State whether the BOM tree should be built-in or parsed from input files
317  const bool isBuiltin = false;
318  const bool isWithOnD = false;
319 
320  // Try to build a travel solution list
321  BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
322  " " ,
323  isBuiltin, isWithOnD),
325 
326 
327 }
328 
329 
330 // End the test suite
331 BOOST_AUTO_TEST_SUITE_END()
332 
333