TravelCCM Logo  0.5.3
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
TravelChoiceTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE TravelCCMTest
16 #include <boost/test/unit_test.hpp>
17 // StdAir
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/bom/TravelSolutionStruct.hpp>
22 #include <stdair/bom/BookingRequestStruct.hpp>
23 #include <stdair/service/Logger.hpp>
24 // TravelCCM
27 
28 namespace boost_utf = boost::unit_test;
29 
30 // (Boost) Unit Test XML Report
31 std::ofstream utfReportStream ("TravelChoiceTestSuite_utfresults.xml");
32 
36 struct UnitTestConfig {
38  UnitTestConfig() {
39  boost_utf::unit_test_log.set_stream (utfReportStream);
40  boost_utf::unit_test_log.set_format (boost_utf::XML);
41  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
42  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
43  }
45  ~UnitTestConfig() {
46  }
47 };
48 
49 
50 // /////////////// Main: Unit Test Suite //////////////
51 
52 // Set the UTF configuration (re-direct the output to a specific file)
53 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
54 
55 // Start the test suite
56 BOOST_AUTO_TEST_SUITE (master_test_suite)
57 
58 
61 BOOST_AUTO_TEST_CASE (simple_simulation_test) {
62 
63  // Input file name
64  /*
65  const stdair::Filename_T inputFileName (STDAIR_SAMPLE_DIR "/ccm_02.csv");
66 
67  // Check that the file path given as input corresponds to an actual file
68  const bool doesExistAndIsReadable =
69  stdair::BasFileMgr::doesExistAndIsReadable (lInputFilename);
70  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
71  "The '" << lInputFilename
72  << "' input file can not be open and read");
73  */
74 
75  // Output log File
76  const stdair::Filename_T lLogFilename ("TravelChoiceTestSuite.log");
77 
78  // Set the log parameters
79  std::ofstream logOutputFile;
80  // Open and clean the log outputfile
81  logOutputFile.open (lLogFilename.c_str());
82  logOutputFile.clear();
83 
84  // Initialise the service context
85  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
86 
87  // Build the BOM tree
88  TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
89 
90  // DEBUG
91  STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
92 
93  // Build a list of travel solutions
94  const stdair::BookingRequestStruct& lBookingRequest =
95  travelccmService.buildSampleBookingRequest();
96 
97  // DEBUG
98  STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
99 
100  // Build the sample BOM tree
101  stdair::TravelSolutionList_T lTSList;
102  travelccmService.buildSampleTravelSolutions (lTSList);
103 
104  // DEBUG: Display the list of travel solutions
105  const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
106  STDAIR_LOG_DEBUG (lCSVDump);
107 
108  // Choose a travel solution
109  const stdair::TravelSolutionStruct* lTS_ptr =
110  travelccmService.chooseTravelSolution (lTSList, lBookingRequest);
111 
112  // Check that a solution has been found
113  BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
114  "No travel solution can be found for "
115  << lBookingRequest.display()
116  << " within the following list of travel solutions. "
117  << lCSVDump);
118 
119  // Close the log file
120  logOutputFile.close();
121 }
122 
123 // End the test suite
124 BOOST_AUTO_TEST_SUITE_END()
125 
126