13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE TravelCCMTest
16 #include <boost/test/unit_test.hpp>
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/basic/PassengerChoiceModel.hpp>
22 #include <stdair/bom/TravelSolutionStruct.hpp>
23 #include <stdair/bom/BookingRequestStruct.hpp>
24 #include <stdair/service/Logger.hpp>
27 #include <travelccm/config/travelccm-paths.hpp>
29 namespace boost_utf = boost::unit_test;
32 std::ofstream utfReportStream (
"TravelChoiceTestSuite_utfresults.xml");
37 struct UnitTestConfig {
40 boost_utf::unit_test_log.set_stream (utfReportStream);
41 boost_utf::unit_test_log.set_format (boost_utf::XML);
42 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
54 void testTravelCCMHelper (
const unsigned short iTestFlag,
55 const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
56 const unsigned int iExpectedPrice) {
59 std::ostringstream oStr;
60 oStr <<
"TravelChoiceTestSuite_" << iTestFlag <<
".log";
61 const stdair::Filename_T lLogFilename (oStr.str());
64 std::ofstream logOutputFile;
66 logOutputFile.open (lLogFilename.c_str());
67 logOutputFile.clear();
70 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
74 travelccmService.buildSampleBom ();
77 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
80 const stdair::BookingRequestStruct& lBookingRequest =
81 travelccmService.buildSampleBookingRequest();
84 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
87 stdair::TravelSolutionList_T lTSList;
88 travelccmService.buildSampleTravelSolutions (lTSList);
91 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
92 STDAIR_LOG_DEBUG (lCSVDump);
95 const stdair::TravelSolutionStruct* lTS_ptr =
96 travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
99 BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
100 "No travel solution can be found for "
101 << lBookingRequest.display()
102 <<
" within the following list of travel solutions. "
105 STDAIR_LOG_DEBUG (lTS_ptr->describe());
108 stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
111 std::ostringstream oMessageExpectedPrice;
112 oMessageExpectedPrice <<
"The price chosen by the passenger is: "
113 << lFareOption.getFare() <<
" Euros. It is expected to be "
114 << iExpectedPrice <<
" Euros.";
115 STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());
118 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
120 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
121 == iExpectedPrice, oMessageExpectedPrice.str());
124 logOutputFile.close();
132 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
135 BOOST_AUTO_TEST_SUITE (master_test_suite)
140 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
146 const unsigned int lExpectedPrice = 1000;
148 BOOST_CHECK_NO_THROW (testTravelCCMHelper
150 stdair::PassengerChoiceModel::HARD_RESTRICTION,
157 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
163 const unsigned int lExpectedPrice = 900;
165 BOOST_CHECK_NO_THROW (testTravelCCMHelper
167 stdair::PassengerChoiceModel::PRICE_ORIENTED,
174 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
180 const unsigned int lExpectedPrice = 920;
182 BOOST_CHECK_NO_THROW (testTravelCCMHelper
184 stdair::PassengerChoiceModel::HYBRID,
189 BOOST_AUTO_TEST_SUITE_END()