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> 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 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900 42 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
43 #else // BOOST_VERSION 44 boost_utf::unit_test_log.set_format (boost_utf::XML);
45 #endif // BOOST_VERSION 46 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
58 void testTravelCCMHelper (
const unsigned short iTestFlag,
59 const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
60 const unsigned int iExpectedPrice) {
63 std::ostringstream oStr;
64 oStr <<
"TravelChoiceTestSuite_" << iTestFlag <<
".log";
65 const stdair::Filename_T lLogFilename (oStr.str());
68 std::ofstream logOutputFile;
70 logOutputFile.open (lLogFilename.c_str());
71 logOutputFile.clear();
74 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
78 travelccmService.buildSampleBom ();
81 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
84 const stdair::BookingRequestStruct& lBookingRequest =
85 travelccmService.buildSampleBookingRequest();
88 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
91 stdair::TravelSolutionList_T lTSList;
92 travelccmService.buildSampleTravelSolutions (lTSList);
95 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
96 STDAIR_LOG_DEBUG (lCSVDump);
99 const stdair::TravelSolutionStruct* lTS_ptr =
100 travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
103 BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
104 "No travel solution can be found for " 105 << lBookingRequest.display()
106 <<
" within the following list of travel solutions. " 109 STDAIR_LOG_DEBUG (lTS_ptr->describe());
112 stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
115 std::ostringstream oMessageExpectedPrice;
116 oMessageExpectedPrice <<
"The price chosen by the passenger is: " 117 << lFareOption.getFare() <<
" Euros. It is expected to be " 118 << iExpectedPrice <<
" Euros.";
119 STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());
122 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
124 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
125 == iExpectedPrice, oMessageExpectedPrice.str());
128 logOutputFile.close();
135 void testAllTravelCCMHelper (
const unsigned short iTestFlag) {
138 std::ostringstream oStr;
139 oStr <<
"TravelChoiceTestSuite_" << iTestFlag <<
".log";
140 const stdair::Filename_T lLogFilename (oStr.str());
143 std::ofstream logOutputFile;
145 logOutputFile.open (lLogFilename.c_str());
146 logOutputFile.clear();
149 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
153 travelccmService.buildSampleBom ();
156 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
159 const stdair::BookingRequestStruct& lBookingRequest =
160 travelccmService.buildSampleBookingRequest();
163 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
166 stdair::TravelSolutionList_T lTSList;
167 travelccmService.buildSampleTravelSolutions (lTSList);
170 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
171 STDAIR_LOG_DEBUG (lCSVDump);
174 const stdair::TravelSolutionStruct* lTS_HardRestriction_ptr =
175 travelccmService.chooseTravelSolution
176 (lTSList, lBookingRequest,
177 stdair::PassengerChoiceModel::HARD_RESTRICTION);
179 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Hard Restriction model: " 180 + lTS_HardRestriction_ptr->describe());
183 const stdair::TravelSolutionStruct* lTS_Price_Oriented_ptr =
184 travelccmService.chooseTravelSolution
185 (lTSList, lBookingRequest,
186 stdair::PassengerChoiceModel::PRICE_ORIENTED);
188 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Price Oriented model: " 189 + lTS_Price_Oriented_ptr->describe());
192 const stdair::TravelSolutionStruct* lTS_Hybrid_ptr =
193 travelccmService.chooseTravelSolution
194 (lTSList, lBookingRequest,
195 stdair::PassengerChoiceModel::HYBRID);
197 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Hybrid model: " +
198 lTS_Hybrid_ptr->describe());
201 logOutputFile.close();
209 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
212 BOOST_AUTO_TEST_SUITE (master_test_suite)
217 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
223 const unsigned int lExpectedPrice = 1000;
225 BOOST_CHECK_NO_THROW (testTravelCCMHelper
227 stdair::PassengerChoiceModel::HARD_RESTRICTION,
234 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
240 const unsigned int lExpectedPrice = 900;
242 BOOST_CHECK_NO_THROW (testTravelCCMHelper
244 stdair::PassengerChoiceModel::PRICE_ORIENTED,
251 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
257 const unsigned int lExpectedPrice = 920;
259 BOOST_CHECK_NO_THROW (testTravelCCMHelper
261 stdair::PassengerChoiceModel::HYBRID,
268 BOOST_AUTO_TEST_CASE (all_models_test) {
270 BOOST_CHECK_NO_THROW (testAllTravelCCMHelper(3));
274 BOOST_AUTO_TEST_SUITE_END()