AirRAC Logo  1.00.3
C++ Simulated Revenue Accounting (RAC) System Library
YieldTestSuite.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 YieldTestSuite
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/service/Logger.hpp>
23 // Airrac
26 
27 namespace boost_utf = boost::unit_test;
28 
29 // (Boost) Unit Test XML Report
30 std::ofstream utfReportStream ("YieldTestSuite_utfresults.xml");
31 
35 struct UnitTestConfig {
37  UnitTestConfig() {
38  boost_utf::unit_test_log.set_stream (utfReportStream);
39 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
40  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
41 #else // BOOST_VERSION
42  boost_utf::unit_test_log.set_format (boost_utf::XML);
43 #endif // BOOST_VERSION
44  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
45  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
46  }
47 
49  ~UnitTestConfig() {
50  }
51 };
52 
53 // //////////////////////////////////////////////////////////////////////
54 
58 void testYieldQuoterHelper (const unsigned short iTestFlag,
59  const stdair::Filename_T iYieldInputFilename,
60  const bool isBuiltin) {
61 
62  // Output log File
63  std::ostringstream oStr;
64  oStr << "FQTTestSuite_" << iTestFlag << ".log";
65  const stdair::Filename_T lLogFilename (oStr.str());
66 
67  // Set the log parameters
68  std::ofstream logOutputFile;
69  // Open and clean the log outputfile
70  logOutputFile.open (lLogFilename.c_str());
71  logOutputFile.clear();
72 
73  // Initialise the AirRAC service object
74  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
75  logOutputFile);
76 
77  // Initialise the AirRAC service object
78  AIRRAC::AIRRAC_Service airracService (lLogParams);
79 
80  // Build a sample list of travel solutions
81  stdair::TravelSolutionList_T lTravelSolutionList;
82  airracService.buildSampleTravelSolutions (lTravelSolutionList);
83 
84  // Check whether or not a (CSV) input file should be read
85  if (isBuiltin == true) {
86 
87  // Build the default sample BOM tree (filled with yields) for AirRAC
88  airracService.buildSampleBom();
89 
90  } else {
91 
92  // Build the BOM tree from parsing the yield input file
93  AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
94  airracService.parseAndLoad (lYieldFilePath);
95  }
96 
97  // Calculate the yields for the given travel solution
98  airracService.calculateYields (lTravelSolutionList);
99 
100  // Close the log file
101  logOutputFile.close();
102 
103 }
104 
105 
106 // /////////////// Main: Unit Test Suite //////////////
107 
108 // Set the UTF configuration (re-direct the output to a specific file)
109 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
110 
111 // Start the test suite
112 BOOST_AUTO_TEST_SUITE (master_test_suite)
113 
114 
117 BOOST_AUTO_TEST_CASE (airrac_simple_yield) {
118 
119  // Input file name
120  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstore01.csv");
121 
122  // State whether the BOM tree should be built-in or parsed from an input file
123  const bool isBuiltin = false;
124 
125  // Try to yieldQuote the sample default list of travel solutions
126  BOOST_CHECK_NO_THROW (testYieldQuoterHelper (0, lYieldInputFilename, isBuiltin));
127 
128 }
129 
134 BOOST_AUTO_TEST_CASE (airrac_error_parsing_input_file) {
135 
136  // Input file name
137  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstoreError01.csv");
138 
139  // State whether the BOM tree should be built-in or parsed from an input file
140  const bool isBuiltin = false;
141 
142  // Try to yield quote the sample default list of travel solutions
143  BOOST_CHECK_THROW (testYieldQuoterHelper (1, lYieldInputFilename, isBuiltin),
145 }
146 
151 BOOST_AUTO_TEST_CASE (airrac_error_missing_input_file) {
152 
153  // Input file name
154  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv");
155 
156  // State whether the BOM tree should be built-in or parsed from an input file
157  const bool isBuiltin = false;
158 
159  // Try to yield quote the sample default list of travel solutions
160  BOOST_CHECK_THROW (testYieldQuoterHelper (2, lYieldInputFilename, isBuiltin),
162 }
163 
167 BOOST_AUTO_TEST_CASE (airrac_simple_yield_built_in) {
168 
169  // State whether the BOM tree should be built-in or parsed from an input file
170  const bool isBuiltin = true;
171 
172  // Try to yield quote the sample default list of travel solutions
173  BOOST_CHECK_NO_THROW (testYieldQuoterHelper (3, " ", isBuiltin));
174 
175 }
176 
177 // End the test suite
178 BOOST_AUTO_TEST_SUITE_END()
179 
180 
AIRRAC::YieldInputFileNotFoundException
Definition: AIRRAC_Types.hpp:61
AIRRAC::AIRRAC_Service
Interface for the AIRRAC Services.
Definition: AIRRAC_Service.hpp:30
AIRRAC::YieldFileParsingFailedException
Definition: AIRRAC_Types.hpp:68
AIRRAC_Service.hpp
AIRRAC::YieldFilePath
Definition: AIRRAC_Types.hpp:82
airrac-paths.hpp
STDAIR_SAMPLE_DIR
#define STDAIR_SAMPLE_DIR
Definition: airrac-paths.hpp:22