TravelCCM Logo  0.5.3
C++ Travel Customer Choice Model Library
TravelChoiceTestSuite.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 TravelCCMTest
00016 #include <boost/test/unit_test.hpp>
00017 // StdAir
00018 #include <stdair/basic/BasLogParams.hpp>
00019 #include <stdair/basic/BasDBParams.hpp>
00020 #include <stdair/basic/BasFileMgr.hpp>
00021 #include <stdair/bom/TravelSolutionStruct.hpp>
00022 #include <stdair/bom/BookingRequestStruct.hpp>
00023 #include <stdair/service/Logger.hpp>
00024 // TravelCCM
00025 #include <travelccm/TRAVELCCM_Service.hpp>
00026 #include <travelccm/config/travelccm-paths.hpp>
00027 
00028 namespace boost_utf = boost::unit_test;
00029 
00030 // (Boost) Unit Test XML Report
00031 std::ofstream utfReportStream ("TravelChoiceTestSuite_utfresults.xml");
00032 
00036 struct UnitTestConfig {
00038   UnitTestConfig() {
00039     boost_utf::unit_test_log.set_stream (utfReportStream);
00040     boost_utf::unit_test_log.set_format (boost_utf::XML);
00041     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00042     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00043   }
00045   ~UnitTestConfig() {
00046   }
00047 };
00048 
00049 
00050 // /////////////// Main: Unit Test Suite //////////////
00051 
00052 // Set the UTF configuration (re-direct the output to a specific file)
00053 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00054 
00055 // Start the test suite
00056 BOOST_AUTO_TEST_SUITE (master_test_suite)
00057 
00058 
00061 BOOST_AUTO_TEST_CASE (simple_simulation_test) {
00062 
00063   // Input file name
00064   /*
00065     const stdair::Filename_T inputFileName (STDAIR_SAMPLE_DIR "/ccm_02.csv");
00066   
00067   // Check that the file path given as input corresponds to an actual file
00068   const bool doesExistAndIsReadable =
00069     stdair::BasFileMgr::doesExistAndIsReadable (lInputFilename);
00070   BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
00071                        "The '" << lInputFilename
00072                        << "' input file can not be open and read");
00073   */
00074   
00075   // Output log File
00076   const stdair::Filename_T lLogFilename ("TravelChoiceTestSuite.log");
00077     
00078   // Set the log parameters
00079   std::ofstream logOutputFile;
00080   // Open and clean the log outputfile
00081   logOutputFile.open (lLogFilename.c_str());
00082   logOutputFile.clear();
00083   
00084   // Initialise the service context
00085   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00086   
00087   // Build the BOM tree
00088   TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
00089 
00090   // DEBUG
00091   STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
00092 
00093   // Build a list of travel solutions
00094   const stdair::BookingRequestStruct& lBookingRequest =
00095     travelccmService.buildSampleBookingRequest();
00096 
00097   // DEBUG
00098   STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
00099 
00100   // Build the sample BOM tree
00101   stdair::TravelSolutionList_T lTSList;
00102   travelccmService.buildSampleTravelSolutions (lTSList);
00103 
00104   // DEBUG: Display the list of travel solutions
00105   const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
00106   STDAIR_LOG_DEBUG (lCSVDump);
00107   
00108   // Choose a travel solution
00109   const stdair::TravelSolutionStruct* lTS_ptr =
00110     travelccmService.chooseTravelSolution (lTSList, lBookingRequest);
00111 
00112   // Check that a solution has been found
00113   BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
00114                          "No travel solution can be found for "
00115                          << lBookingRequest.display()
00116                          << " within the following list of travel solutions. "
00117                          << lCSVDump);
00118 
00119   // Close the log file
00120   logOutputFile.close();
00121 }
00122 
00123 // End the test suite
00124 BOOST_AUTO_TEST_SUITE_END()
00125 
00126