AirRAC Logo  1.00.0
C++ Simulated Revenue Accounting (RAC) System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
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
25 #include <airrac/config/airrac-paths.hpp>
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  boost_utf::unit_test_log.set_format (boost_utf::XML);
40  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
41  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
42  }
43 
45  ~UnitTestConfig() {
46  }
47 };
48 
49 // //////////////////////////////////////////////////////////////////////
50 
54 void testYieldQuoterHelper (const unsigned short iTestFlag,
55  const stdair::Filename_T iYieldInputFilename,
56  const bool isBuiltin) {
57 
58  // Output log File
59  std::ostringstream oStr;
60  oStr << "FQTTestSuite_" << iTestFlag << ".log";
61  const stdair::Filename_T lLogFilename (oStr.str());
62 
63  // Set the log parameters
64  std::ofstream logOutputFile;
65  // Open and clean the log outputfile
66  logOutputFile.open (lLogFilename.c_str());
67  logOutputFile.clear();
68 
69  // Initialise the AirRAC service object
70  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
71  logOutputFile);
72 
73  // Initialise the AirRAC service object
74  AIRRAC::AIRRAC_Service airracService (lLogParams);
75 
76  // Build a sample list of travel solutions
77  stdair::TravelSolutionList_T lTravelSolutionList;
78  airracService.buildSampleTravelSolutions (lTravelSolutionList);
79 
80  // Check whether or not a (CSV) input file should be read
81  if (isBuiltin == true) {
82 
83  // Build the default sample BOM tree (filled with yields) for AirRAC
84  airracService.buildSampleBom();
85 
86  } else {
87 
88  // Build the BOM tree from parsing the yield input file
89  AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
90  airracService.parseAndLoad (lYieldFilePath);
91  }
92 
93  // Calculate the yields for the given travel solution
94  airracService.calculateYields (lTravelSolutionList);
95 
96  // Close the log file
97  logOutputFile.close();
98 
99 }
100 
101 
102 // /////////////// Main: Unit Test Suite //////////////
103 
104 // Set the UTF configuration (re-direct the output to a specific file)
105 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
106 
107 // Start the test suite
108 BOOST_AUTO_TEST_SUITE (master_test_suite)
109 
110 
113 BOOST_AUTO_TEST_CASE (airrac_simple_yield) {
114 
115  // Input file name
116  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstore01.csv");
117 
118  // State whether the BOM tree should be built-in or parsed from an input file
119  const bool isBuiltin = false;
120 
121  // Try to yieldQuote the sample default list of travel solutions
122  BOOST_CHECK_NO_THROW (testYieldQuoterHelper (0, lYieldInputFilename, isBuiltin));
123 
124 }
125 
130 BOOST_AUTO_TEST_CASE (airrac_error_parsing_input_file) {
131 
132  // Input file name
133  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstoreError01.csv");
134 
135  // State whether the BOM tree should be built-in or parsed from an input file
136  const bool isBuiltin = false;
137 
138  // Try to yield quote the sample default list of travel solutions
139  BOOST_CHECK_THROW (testYieldQuoterHelper (1, lYieldInputFilename, isBuiltin),
141 }
142 
147 BOOST_AUTO_TEST_CASE (airrac_error_missing_input_file) {
148 
149  // Input file name
150  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv");
151 
152  // State whether the BOM tree should be built-in or parsed from an input file
153  const bool isBuiltin = false;
154 
155  // Try to yield quote the sample default list of travel solutions
156  BOOST_CHECK_THROW (testYieldQuoterHelper (2, lYieldInputFilename, isBuiltin),
158 }
159 
163 BOOST_AUTO_TEST_CASE (airrac_simple_yield_built_in) {
164 
165  // State whether the BOM tree should be built-in or parsed from an input file
166  const bool isBuiltin = true;
167 
168  // Try to yield quote the sample default list of travel solutions
169  BOOST_CHECK_NO_THROW (testYieldQuoterHelper (3, " ", isBuiltin));
170 
171 }
172 
173 // End the test suite
174 BOOST_AUTO_TEST_SUITE_END()
175 
176