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