AirSched Logo  0.1.4
C++ Simulated Airline Schedule Manager 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 // StdAir
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/bom/TravelSolutionStruct.hpp>
22 #include <stdair/bom/BookingRequestStruct.hpp>
23 #include <stdair/service/Logger.hpp>
24 // AirSched
27 
28 namespace boost_utf = boost::unit_test;
29 
30 // (Boost) Unit Test XML Report
31 std::ofstream utfReportStream ("AirlineScheduleTestSuite_utfresults.xml");
32 
36 struct UnitTestConfig {
38  UnitTestConfig() {
39  boost_utf::unit_test_log.set_stream (utfReportStream);
40  boost_utf::unit_test_log.set_format (boost_utf::XML);
41  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
42  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
43  }
44 
46  ~UnitTestConfig() {
47  }
48 };
49 
50 
51 // /////////////// Main: Unit Test Suite //////////////
52 
53 // Set the UTF configuration (re-direct the output to a specific file)
54 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
55 
56 // Start the test suite
57 BOOST_AUTO_TEST_SUITE (master_test_suite)
58 
59 
62 BOOST_AUTO_TEST_CASE (airsched_simple_inventory_sell) {
63 
64  // Input file name
65  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
66  "/schedule03.csv");
67 
68  // Output log File
69  const stdair::Filename_T lLogFilename ("AirlineScheduleTestSuite.log");
70 
71  // Check that the file path given as input corresponds to an actual file
72  bool doesExistAndIsReadable =
73  stdair::BasFileMgr::doesExistAndIsReadable (lScheduleInputFilename);
74  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
75  "The '" << lScheduleInputFilename
76  << "' input file can not be open and read");
77 
78  // Set the log parameters
79  std::ofstream logOutputFile;
80  // Open and clean the log outputfile
81  logOutputFile.open (lLogFilename.c_str());
82  logOutputFile.clear();
83 
84  // Instantiate the AirSched service
85  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
86  AIRSCHED::AIRSCHED_Service airschedService (lLogParams);
87 
88  // Build the BOM tree from parsing input files
89  airschedService.parseAndLoad (lScheduleInputFilename);
90 
91  // Create an empty booking request structure
92  // \todo: fill the booking request structure from the input parameters
93  const stdair::AirportCode_T lOrigin ("NCE");
94  const stdair::AirportCode_T lDestination ("BKK");
95  const stdair::AirportCode_T lPOS ("NCE");
96  const stdair::Date_T lPreferredDepartureDate(2007, boost::gregorian::Apr, 21);
97  const stdair::Date_T lRequestDate (2007, boost::gregorian::Mar, 21);
98  const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
99  const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
100  const stdair::CabinCode_T lPreferredCabin ("Bus");
101  const stdair::PartySize_T lPartySize (3);
102  const stdair::ChannelLabel_T lChannel ("DF");
103  const stdair::TripType_T lTripType ("RO");
104  const stdair::DayDuration_T lStayDuration (5);
105  const stdair::FrequentFlyer_T lFrequentFlyerType ("NONE");
106  const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
107  const stdair::WTP_T lWTP (2000.0);
108  const stdair::PriceValue_T lValueOfTime (20.0);
109  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
110  lPOS,
111  lPreferredDepartureDate,
112  lRequestDateTime,
113  lPreferredCabin,
114  lPartySize, lChannel,
115  lTripType, lStayDuration,
116  lFrequentFlyerType,
117  lPreferredDepartureTime,
118  lWTP, lValueOfTime);
119 
120  //
121  stdair::TravelSolutionList_T lTravelSolutionList;
122  airschedService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
123  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
124 
125  // \todo: change the expected number of travel solutions to the actual number
126  const unsigned int lExpectedNbOfTravelSolutions = 4;
127 
128  // DEBUG
129  STDAIR_LOG_DEBUG ("Number of travel solutions for the booking request '"
130  << lBookingRequest.describe() << "': "
131  << lNbOfTravelSolutions << ". It is expected to be "
132  << lExpectedNbOfTravelSolutions << ".");
133 
134  BOOST_CHECK_EQUAL (lNbOfTravelSolutions, lExpectedNbOfTravelSolutions);
135 
136  BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
137  "The number of travel solutions for the booking request '"
138  << lBookingRequest.describe() << "' is equal to "
139  << lNbOfTravelSolutions << ", but it should be equal to "
140  << lExpectedNbOfTravelSolutions);
141 
142  // Close the Log outputFile
143  logOutputFile.close();
144 }
145 
146 // End the test suite
147 BOOST_AUTO_TEST_SUITE_END()
148 
149