$treeview $search $mathjax
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/basic/PassengerChoiceModel.hpp> 00022 #include <stdair/bom/TravelSolutionStruct.hpp> 00023 #include <stdair/bom/BookingRequestStruct.hpp> 00024 #include <stdair/service/Logger.hpp> 00025 // TravelCCM 00026 #include <travelccm/TRAVELCCM_Service.hpp> 00027 #include <travelccm/config/travelccm-paths.hpp> 00028 00029 namespace boost_utf = boost::unit_test; 00030 00031 // (Boost) Unit Test XML Report 00032 std::ofstream utfReportStream ("TravelChoiceTestSuite_utfresults.xml"); 00033 00037 struct UnitTestConfig { 00039 UnitTestConfig() { 00040 boost_utf::unit_test_log.set_stream (utfReportStream); 00041 boost_utf::unit_test_log.set_format (boost_utf::XML); 00042 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units); 00043 //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests); 00044 } 00046 ~UnitTestConfig() { 00047 } 00048 }; 00049 00050 // ////////////////////////////////////////////////////////////////////// 00054 void testTravelCCMHelper (const unsigned short iTestFlag, 00055 const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel, 00056 const unsigned int iExpectedPrice) { 00057 00058 // Output log File 00059 std::ostringstream oStr; 00060 oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log"; 00061 const stdair::Filename_T lLogFilename (oStr.str()); 00062 00063 // Set the log parameters 00064 std::ofstream logOutputFile; 00065 // Open and clean the log outputfile 00066 logOutputFile.open (lLogFilename.c_str()); 00067 logOutputFile.clear(); 00068 00069 // Initialise the service context 00070 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); 00071 00072 // Build the BOM tree 00073 TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams); 00074 travelccmService.buildSampleBom (); 00075 00076 // DEBUG 00077 STDAIR_LOG_DEBUG ("Welcome to TravelCCM"); 00078 00079 // Build a list of travel solutions 00080 const stdair::BookingRequestStruct& lBookingRequest = 00081 travelccmService.buildSampleBookingRequest(); 00082 00083 // DEBUG 00084 STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display()); 00085 00086 // Build the sample BOM tree 00087 stdair::TravelSolutionList_T lTSList; 00088 travelccmService.buildSampleTravelSolutions (lTSList); 00089 00090 // DEBUG: Display the list of travel solutions 00091 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList); 00092 STDAIR_LOG_DEBUG (lCSVDump); 00093 00094 // Choose a travel solution 00095 const stdair::TravelSolutionStruct* lTS_ptr = 00096 travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel); 00097 00098 // Check that a solution has been found 00099 BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL, 00100 "No travel solution can be found for " 00101 << lBookingRequest.display() 00102 << " within the following list of travel solutions. " 00103 << lCSVDump); 00104 00105 STDAIR_LOG_DEBUG (lTS_ptr->describe()); 00106 00107 // Retrieve the chosen fare option 00108 stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption(); 00109 00110 // DEBUG 00111 std::ostringstream oMessageExpectedPrice; 00112 oMessageExpectedPrice << "The price chosen by the passenger is: " 00113 << lFareOption.getFare() << " Euros. It is expected to be " 00114 << iExpectedPrice << " Euros."; 00115 STDAIR_LOG_DEBUG (oMessageExpectedPrice.str()); 00116 00117 // Check that the price corresponds to the expected one 00118 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice); 00119 00120 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5) 00121 == iExpectedPrice, oMessageExpectedPrice.str()); 00122 00123 // Close the log file 00124 logOutputFile.close(); 00125 00126 } 00127 00128 00129 // /////////////// Main: Unit Test Suite ////////////// 00130 00131 // Set the UTF configuration (re-direct the output to a specific file) 00132 BOOST_GLOBAL_FIXTURE (UnitTestConfig); 00133 00134 // Start the test suite 00135 BOOST_AUTO_TEST_SUITE (master_test_suite) 00136 00137 00140 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) { 00141 00146 const unsigned int lExpectedPrice = 1000; 00147 00148 BOOST_CHECK_NO_THROW (testTravelCCMHelper 00149 (0, 00150 stdair::PassengerChoiceModel::HARD_RESTRICTION, 00151 lExpectedPrice)); 00152 } 00153 00157 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) { 00158 00163 const unsigned int lExpectedPrice = 900; 00164 00165 BOOST_CHECK_NO_THROW (testTravelCCMHelper 00166 (1, 00167 stdair::PassengerChoiceModel::PRICE_ORIENTED, 00168 lExpectedPrice)); 00169 } 00170 00174 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) { 00175 00180 const unsigned int lExpectedPrice = 920; 00181 00182 BOOST_CHECK_NO_THROW (testTravelCCMHelper 00183 (2, 00184 stdair::PassengerChoiceModel::HYBRID, 00185 lExpectedPrice)); 00186 } 00187 00188 // End the test suite 00189 BOOST_AUTO_TEST_SUITE_END() 00190 00191