$treeview $search $mathjax
AirSched Logo  1.00.0
$projectbrief
$projectbrief
$searchbox

AirlineScheduleTestSuite.cpp

Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012 // Boost Unit Test Framework (UTF)
00013 #define BOOST_TEST_DYN_LINK
00014 #define BOOST_TEST_MAIN
00015 #define BOOST_TEST_MODULE InventoryTestSuite
00016 #include <boost/test/unit_test.hpp>
00017 // Boost Date-Time
00018 #include <boost/date_time/gregorian/gregorian.hpp>
00019 // StdAir
00020 #include <stdair/basic/BasFileMgr.hpp>
00021 #include <stdair/basic/BasLogParams.hpp>
00022 #include <stdair/basic/BasDBParams.hpp>
00023 #include <stdair/basic/BasFileMgr.hpp>
00024 #include <stdair/bom/TravelSolutionStruct.hpp>
00025 #include <stdair/bom/BookingRequestStruct.hpp>
00026 #include <stdair/service/Logger.hpp>
00027 // AirSched
00028 #include <airsched/AIRSCHED_Types.hpp>
00029 #include <airsched/AIRSCHED_Service.hpp>
00030 #include <airsched/config/airsched-paths.hpp>
00031 
00032 namespace boost_utf = boost::unit_test;
00033 
00034 // (Boost) Unit Test XML Report
00035 std::ofstream utfReportStream ("AirlineScheduleTestSuite_utfresults.xml");
00036 
00040 struct UnitTestConfig {
00042   UnitTestConfig() {
00043     boost_utf::unit_test_log.set_stream (utfReportStream);
00044     boost_utf::unit_test_log.set_format (boost_utf::XML);
00045     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00046     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00047   }
00048 
00050   ~UnitTestConfig() {
00051   }
00052 };
00053 
00054 // //////////////////////////////////////////////////////////////////////
00058  const unsigned int testScheduleHelper (const unsigned short iTestFlag,
00059                                         const stdair::Filename_T& iScheduleInputFilename,
00060                                         const stdair::Filename_T& iODInputFilename,
00061                                         const bool isBuiltin,
00062                                         const bool isWithOnD) {
00063   
00064   // Output log File
00065   std::ostringstream oStr;
00066   oStr << "AirlineScheduleTestSuite_" << iTestFlag << ".log";
00067   const stdair::Filename_T lLogFilename (oStr.str());
00068 
00069   // Set the log parameters
00070   std::ofstream logOutputFile;
00071   // Open and clean the log outputfile
00072   logOutputFile.open (lLogFilename.c_str());
00073   logOutputFile.clear();
00074 
00075   // Instantiate the AirSched service
00076   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00077   AIRSCHED::AIRSCHED_Service airschedService (lLogParams);
00078 
00079   stdair::AirportCode_T lOrigin;
00080   stdair::AirportCode_T lDestination;
00081   stdair::AirportCode_T lPOS;
00082   stdair::Date_T lPreferredDepartureDate;;
00083   stdair::Date_T lRequestDate;
00084 
00085   // Check wether or not a (CSV) input file should be read
00086   if (isBuiltin == true) {
00087 
00088     // Build the default sample BOM tree (filled with schedules)
00089     airschedService.buildSampleBom();
00090 
00091     lOrigin = "SIN";
00092     lDestination = "BKK";
00093     lPOS = "SIN";
00094     lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
00095     lRequestDate = boost::gregorian::from_string ("2010/01/21");
00096 
00097   } else {
00098 
00099     if (isWithOnD == false) {
00100 
00101       // Build the BOM tree from parsing input files
00102       const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
00103       airschedService.parseAndLoad (lScheduleFilePath);
00104 
00105       lOrigin = "NCE";
00106       lDestination = "BKK";
00107       lPOS = "NCE";
00108       lPreferredDepartureDate = boost::gregorian::from_string ("2007/04/21");
00109       lRequestDate = boost::gregorian::from_string ("2007/03/21");
00110     
00111     } else {
00112 
00113       // Build the BOM tree from parsing input files
00114       const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
00115       const stdair::ODFilePath lODFilePath (iODInputFilename);
00116       airschedService.parseAndLoad (lScheduleFilePath,
00117                                     lODFilePath);
00118 
00119       lOrigin = "SIN";
00120       lDestination = "BKK";
00121       lPOS = "SIN";
00122       lPreferredDepartureDate = boost::gregorian::from_string ("2009/02/02");
00123       lRequestDate = boost::gregorian::from_string ("2009/01/01");
00124     }
00125     
00126   }
00127 
00128   // Create a booking request structure
00129   const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
00130   const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
00131   const stdair::CabinCode_T lPreferredCabin ("Bus");
00132   const stdair::PartySize_T lPartySize (3);
00133   const stdair::ChannelLabel_T lChannel ("DF");
00134   const stdair::TripType_T lTripType ("RO");
00135   const stdair::DayDuration_T lStayDuration (5);
00136   const stdair::FrequentFlyer_T lFrequentFlyerType ("NONE");
00137   const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
00138   const stdair::WTP_T lWTP (2000.0);
00139   const stdair::PriceValue_T lValueOfTime (20.0);
00140   const stdair::ChangeFees_T lChangeFees (true);
00141   const stdair::Disutility_T lChangeFeeDisutility (50);
00142   const stdair::NonRefundable_T lNonRefundable (true);
00143   const stdair::Disutility_T lNonRefundableDisutility (50);
00144       
00145   const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
00146                                                       lPOS,
00147                                                       lPreferredDepartureDate,
00148                                                       lRequestDateTime,
00149                                                       lPreferredCabin,
00150                                                       lPartySize, lChannel,
00151                                                       lTripType, lStayDuration,
00152                                                       lFrequentFlyerType,
00153                                                       lPreferredDepartureTime,
00154                                                       lWTP, lValueOfTime,
00155                                                       lChangeFees,
00156                                                       lChangeFeeDisutility,
00157                                                       lNonRefundable,
00158                                                       lNonRefundableDisutility);
00159     
00160   // Build the segment path list
00161   stdair::TravelSolutionList_T lTravelSolutionList;
00162   airschedService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
00163   const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
00164 
00165   STDAIR_LOG_DEBUG ("The number of travel solutions for the booking request '"
00166                     << lBookingRequest.describe() << "' is equal to "
00167                     << lNbOfTravelSolutions << ".");
00168 
00169   // Close the Log outputFile
00170   logOutputFile.close();
00171   
00172   return lNbOfTravelSolutions;
00173 }
00174 
00175 
00176 // /////////////// Main: Unit Test Suite //////////////
00177 
00178 // Set the UTF configuration (re-direct the output to a specific file)
00179 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00180 
00181 // Start the test suite
00182 BOOST_AUTO_TEST_SUITE (master_test_suite)
00183 
00184 
00187 BOOST_AUTO_TEST_CASE (airsched_simple_build) {
00188 
00189   // Input file name
00190   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00191                                                    "/schedule03.csv");
00192 
00193   // State whether the BOM tree should be built-in or parsed from input files
00194   const bool isBuiltin = false;
00195   const bool isWithOnD = false;
00196 
00197   // Try to build a travel solution list
00198   unsigned int lNbOfTravelSolutions = 0;
00199   BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
00200                         testScheduleHelper (0, lScheduleInputFilename, " ",
00201                                             isBuiltin, isWithOnD));
00202 
00203   // Check the size of the travel solution list
00204   const unsigned int lExpectedNbOfTravelSolutions = 4;    
00205   BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
00206                       "The number of travel solutions is "
00207                       << lNbOfTravelSolutions << ", but it should be equal to "
00208                       << lExpectedNbOfTravelSolutions);
00209   
00210 }
00211 
00215 BOOST_AUTO_TEST_CASE (airsched_default_bom_tree_simple_build) {
00216 
00217   // State whether the BOM tree should be built-in or parsed from input files
00218   const bool isBuiltin = true;
00219   const bool isWithOnD = false;
00220 
00221   // Try to build a travel solution list
00222   unsigned int lNbOfTravelSolutions = 0;
00223   BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
00224                         testScheduleHelper (1, " ", " ", isBuiltin, isWithOnD));
00225 
00226   // Check the size of the travel solution list
00227   const unsigned int lExpectedNbOfTravelSolutions = 1;    
00228   BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
00229                       "The number of travel solutions is "
00230                       << lNbOfTravelSolutions << ", but it should be equal to "
00231                       << lExpectedNbOfTravelSolutions);
00232   
00233 }
00234 
00238 BOOST_AUTO_TEST_CASE (airsched_OnD_input_file) {
00239 
00240   // Input file names
00241   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00242                                                    "/rds01/schedule05.csv");
00243   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00244                                              "/ond01.csv");
00245 
00246   // State whether the BOM tree should be built-in or parsed from input files
00247   const bool isBuiltin = false;
00248   const bool isWithOnD = true;
00249 
00250   // Try to build a travel solution list
00251   unsigned int lNbOfTravelSolutions = 0;   
00252   BOOST_CHECK_NO_THROW  (lNbOfTravelSolutions =
00253                          testScheduleHelper (2, lScheduleInputFilename,
00254                                              lODInputFilename,
00255                                              isBuiltin, isWithOnD));
00256   
00257   // Check the size of the travel solution list
00258   const unsigned int lExpectedNbOfTravelSolutions = 1;    
00259   BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
00260                       "The number of travel solutions is "
00261                       << lNbOfTravelSolutions << ", but it should be equal to "
00262                       << lExpectedNbOfTravelSolutions);
00263 }
00264 
00268 BOOST_AUTO_TEST_CASE (airsched_missing_OnD_input_file) {
00269 
00270   // Input file names
00271   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00272                                                    "/schedule03.csv");
00273   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00274                                              "/missingFiles.csv");
00275 
00276   // State whether the BOM tree should be built-in or parsed from input files
00277   const bool isBuiltin = false;
00278   const bool isWithOnD = true;
00279 
00280   // Try to build a travel solution list
00281   BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
00282                                          lODInputFilename,
00283                                          isBuiltin, isWithOnD),
00284                      AIRSCHED::OnDInputFileNotFoundException);
00285 }
00286 
00290 BOOST_AUTO_TEST_CASE (airsched_missing_schedule_input_file) {
00291 
00292   // Input file name
00293   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00294                                                    "/missingFiles.csv");
00295 
00296   // State whether the BOM tree should be built-in or parsed from input files
00297   const bool isBuiltin = false;
00298   const bool isWithOnD = false;
00299 
00300   // Try to build a travel solution list
00301   BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename, " ",
00302                                          isBuiltin, isWithOnD),
00303                      AIRSCHED::ScheduleInputFileNotFoundException);
00304 
00305 }
00306 
00310 BOOST_AUTO_TEST_CASE (airsched_segment_date_not_found) {
00311 
00312   // Input file name
00313   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00314                                                    "/scheduleError03.csv");
00315 
00316   // State whether the BOM tree should be built-in or parsed from input files
00317   const bool isBuiltin = false;
00318   const bool isWithOnD = false;
00319 
00320   // Try to build a travel solution list  
00321   BOOST_CHECK_THROW  (testScheduleHelper (5, lScheduleInputFilename,
00322                                           " " ,
00323                                           isBuiltin, isWithOnD),
00324                       AIRSCHED::SegmentDateNotFoundException);
00325   
00326 
00327 }
00328 
00329 
00330 // End the test suite
00331 BOOST_AUTO_TEST_SUITE_END()
00332 
00333