SimFQT Logo  1.00.1
C++ Simulated Fare Quote System Library
FQTTestSuite.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 FQTTestSuite
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/service/Logger.hpp>
23 #include <stdair/bom/TravelSolutionStruct.hpp>
24 #include <stdair/bom/BookingRequestStruct.hpp>
25 // SimFQT
28 
29 namespace boost_utf = boost::unit_test;
30 
34 struct UnitTestConfig {
36  UnitTestConfig() {
37  static std::ofstream _test_log ("FQTTestSuite_utfresults.xml");
38  boost_utf::unit_test_log.set_stream (_test_log);
39 #if BOOST_VERSION >= 105900
40  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
41 #else
42  boost_utf::unit_test_log.set_format (boost_utf::XML);
43 #endif
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 // //////////////////////////////////////////////////////////////////////
57 void testFareQuoterHelper (const unsigned short iTestFlag,
58  const stdair::Filename_T iFareInputFilename,
59  const bool isBuiltin) {
60 
61  // Output log File
62  std::ostringstream oStr;
63  oStr << "FQTTestSuite_" << iTestFlag << ".log";
64  const stdair::Filename_T lLogFilename (oStr.str());
65 
66  // Set the log parameters
67  std::ofstream logOutputFile;
68  // Open and clean the log outputfile
69  logOutputFile.open (lLogFilename.c_str());
70  logOutputFile.clear();
71 
72  // Initialise the SimFQT service object
73  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
74  logOutputFile);
75 
76  // Initialise the Simfqt service object
77  SIMFQT::SIMFQT_Service simfqtService (lLogParams);
78 
79  // Check wether or not a (CSV) input file should be read
80  if (isBuiltin == true) {
81 
82  // Build the default sample BOM tree (filled with fares) for Simfqt
83  simfqtService.buildSampleBom();
84 
85  } else {
86 
87  // Build the BOM tree from parsing the fare input file
88  SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
89  simfqtService.parseAndLoad (lFareFilePath);
90  }
91 
92  // Build a sample list of travel solutions and a booking request.
93  stdair::TravelSolutionList_T lTravelSolutionList;
94  simfqtService.buildSampleTravelSolutions (lTravelSolutionList);
95  stdair::BookingRequestStruct lBookingRequest =
96  simfqtService.buildBookingRequest();
97 
98  // Try to fareQuote the sample list of travel solutions
99  simfqtService.quotePrices (lBookingRequest, lTravelSolutionList);
100 
101  // Close the log file
102  logOutputFile.close();
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 (simfqt_simple_pricing_test) {
118 
119  // Input file name
120  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fare01.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 fareQuote the sample default list of travel solutions
126  BOOST_CHECK_NO_THROW (testFareQuoterHelper (0, lFareInputFilename, isBuiltin));
127 
128 }
129 
134 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_01) {
135 
136  // Input file name
137  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError01.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 fareQuote the sample default list of travel solutions
143  BOOST_CHECK_THROW (testFareQuoterHelper (1, lFareInputFilename, isBuiltin),
145 }
146 
151 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_02) {
152 
153  // Input file name
154  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError02.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 fareQuote the sample default list of travel solutions
160  BOOST_CHECK_THROW (testFareQuoterHelper (2, lFareInputFilename, isBuiltin),
162 }
163 
168 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_03) {
169 
170  // Input file name
171  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError03.csv");
172 
173  // State whether the BOM tree should be built-in or parsed from an input file
174  const bool isBuiltin = false;
175 
176  // Try to fareQuote the sample default list of travel solutions
177  BOOST_CHECK_THROW (testFareQuoterHelper (3, lFareInputFilename, isBuiltin),
179 }
180 
185 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_04) {
186 
187  // Input file name
188  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError04.csv");
189 
190  // State whether the BOM tree should be built-in or parsed from an input file
191  const bool isBuiltin = false;
192 
193  // Try to fareQuote the sample default list of travel solutions
194  BOOST_CHECK_THROW (testFareQuoterHelper (4, lFareInputFilename, isBuiltin),
196 }
197 
202 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_05) {
203 
204  // Input file name
205  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError05.csv");
206 
207  // State whether the BOM tree should be built-in or parsed from an input file
208  const bool isBuiltin = false;
209 
210  // Try to fareQuote the sample default list of travel solutions
211  BOOST_CHECK_THROW (testFareQuoterHelper (5, lFareInputFilename, isBuiltin),
213 }
214 
219 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_06) {
220 
221  // Input file name
222  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError06.csv");
223 
224  // State whether the BOM tree should be built-in or parsed from an input file
225  const bool isBuiltin = false;
226 
227  // Try to fareQuote the sample default list of travel solutions
228  BOOST_CHECK_THROW (testFareQuoterHelper (6, lFareInputFilename, isBuiltin),
230 }
231 
236 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_07) {
237 
238  // Input file name
239  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError07.csv");
240 
241  // State whether the BOM tree should be built-in or parsed from an input file
242  const bool isBuiltin = false;
243 
244  // Try to fareQuote the sample default list of travel solutions
245  BOOST_CHECK_THROW (testFareQuoterHelper (7, lFareInputFilename, isBuiltin),
247 }
248 
253 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_08) {
254 
255  // Input file name
256  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv");
257 
258  // State whether the BOM tree should be built-in or parsed from an input file
259  const bool isBuiltin = false;
260 
261  // Try to fareQuote the sample default list of travel solutions
262  BOOST_CHECK_THROW (testFareQuoterHelper (8, lFareInputFilename, isBuiltin),
264 }
265 
270 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_09) {
271 
272  // Input file name
273  const stdair::Filename_T lEmptyInputFilename (STDAIR_SAMPLE_DIR "/ ");
274 
275  // State whether the BOM tree should be built-in or parsed from an input file
276  const bool isBuiltin = true;
277 
278  // Try to fareQuote the sample default list of travel solutions
279  BOOST_CHECK_NO_THROW(testFareQuoterHelper (9, lEmptyInputFilename, isBuiltin));
280 }
281 
282 
283 // End the test suite
284 BOOST_AUTO_TEST_SUITE_END()
285 
286 
#define STDAIR_SAMPLE_DIR
Interface for the SIMFQT Services.