SimFQT Logo  1.00.0
C++ Simulated Fare Quote System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
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 // StdAir
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/service/Logger.hpp>
22 #include <stdair/bom/TravelSolutionStruct.hpp>
23 #include <stdair/bom/BookingRequestStruct.hpp>
24 // SimFQT
26 #include <simfqt/config/simfqt-paths.hpp>
27 
28 namespace boost_utf = boost::unit_test;
29 
33 struct UnitTestConfig {
35  UnitTestConfig() {
36  static std::ofstream _test_log ("FQTTestSuite_utfresults.xml");
37  boost_utf::unit_test_log.set_stream (_test_log);
38  boost_utf::unit_test_log.set_format (boost_utf::XML);
39  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
40  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
41  }
42 
44  ~UnitTestConfig() {
45  }
46 };
47 
48 // //////////////////////////////////////////////////////////////////////
52 void testFareQuoterHelper (const unsigned short iTestFlag,
53  const stdair::Filename_T iFareInputFilename,
54  const bool isBuiltin) {
55 
56  // Output log File
57  std::ostringstream oStr;
58  oStr << "FQTTestSuite_" << iTestFlag << ".log";
59  const stdair::Filename_T lLogFilename (oStr.str());
60 
61  // Set the log parameters
62  std::ofstream logOutputFile;
63  // Open and clean the log outputfile
64  logOutputFile.open (lLogFilename.c_str());
65  logOutputFile.clear();
66 
67  // Initialise the SimFQT service object
68  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
69  logOutputFile);
70 
71  // Initialise the Simfqt service object
72  SIMFQT::SIMFQT_Service simfqtService (lLogParams);
73 
74  // Check wether or not a (CSV) input file should be read
75  if (isBuiltin == true) {
76 
77  // Build the default sample BOM tree (filled with fares) for Simfqt
78  simfqtService.buildSampleBom();
79 
80  } else {
81 
82  // Build the BOM tree from parsing the fare input file
83  SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
84  simfqtService.parseAndLoad (lFareFilePath);
85  }
86 
87  // Build a sample list of travel solutions and a booking request.
88  stdair::TravelSolutionList_T lTravelSolutionList;
89  simfqtService.buildSampleTravelSolutions (lTravelSolutionList);
90  stdair::BookingRequestStruct lBookingRequest =
91  simfqtService.buildBookingRequest();
92 
93  // Try to fareQuote the sample list of travel solutions
94  simfqtService.quotePrices (lBookingRequest, lTravelSolutionList);
95 
96  // Close the log file
97  logOutputFile.close();
98 
99 }
100 
101 // /////////////// Main: Unit Test Suite //////////////
102 
103 // Set the UTF configuration (re-direct the output to a specific file)
104 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
105 
106 // Start the test suite
107 BOOST_AUTO_TEST_SUITE (master_test_suite)
108 
109 
112 BOOST_AUTO_TEST_CASE (simfqt_simple_pricing_test) {
113 
114  // Input file name
115  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fare01.csv");
116 
117  // State whether the BOM tree should be built-in or parsed from an input file
118  const bool isBuiltin = false;
119 
120  // Try to fareQuote the sample default list of travel solutions
121  BOOST_CHECK_NO_THROW (testFareQuoterHelper (0, lFareInputFilename, isBuiltin));
122 
123 }
124 
129 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_01) {
130 
131  // Input file name
132  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError01.csv");
133 
134  // State whether the BOM tree should be built-in or parsed from an input file
135  const bool isBuiltin = false;
136 
137  // Try to fareQuote the sample default list of travel solutions
138  BOOST_CHECK_THROW (testFareQuoterHelper (1, lFareInputFilename, isBuiltin),
140 }
141 
146 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_02) {
147 
148  // Input file name
149  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError02.csv");
150 
151  // State whether the BOM tree should be built-in or parsed from an input file
152  const bool isBuiltin = false;
153 
154  // Try to fareQuote the sample default list of travel solutions
155  BOOST_CHECK_THROW (testFareQuoterHelper (2, lFareInputFilename, isBuiltin),
157 }
158 
163 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_03) {
164 
165  // Input file name
166  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError03.csv");
167 
168  // State whether the BOM tree should be built-in or parsed from an input file
169  const bool isBuiltin = false;
170 
171  // Try to fareQuote the sample default list of travel solutions
172  BOOST_CHECK_THROW (testFareQuoterHelper (3, lFareInputFilename, isBuiltin),
174 }
175 
180 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_04) {
181 
182  // Input file name
183  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError04.csv");
184 
185  // State whether the BOM tree should be built-in or parsed from an input file
186  const bool isBuiltin = false;
187 
188  // Try to fareQuote the sample default list of travel solutions
189  BOOST_CHECK_THROW (testFareQuoterHelper (4, lFareInputFilename, isBuiltin),
191 }
192 
197 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_05) {
198 
199  // Input file name
200  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError05.csv");
201 
202  // State whether the BOM tree should be built-in or parsed from an input file
203  const bool isBuiltin = false;
204 
205  // Try to fareQuote the sample default list of travel solutions
206  BOOST_CHECK_THROW (testFareQuoterHelper (5, lFareInputFilename, isBuiltin),
208 }
209 
214 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_06) {
215 
216  // Input file name
217  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError06.csv");
218 
219  // State whether the BOM tree should be built-in or parsed from an input file
220  const bool isBuiltin = false;
221 
222  // Try to fareQuote the sample default list of travel solutions
223  BOOST_CHECK_THROW (testFareQuoterHelper (6, lFareInputFilename, isBuiltin),
225 }
226 
231 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_07) {
232 
233  // Input file name
234  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError07.csv");
235 
236  // State whether the BOM tree should be built-in or parsed from an input file
237  const bool isBuiltin = false;
238 
239  // Try to fareQuote the sample default list of travel solutions
240  BOOST_CHECK_THROW (testFareQuoterHelper (7, lFareInputFilename, isBuiltin),
242 }
243 
248 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_08) {
249 
250  // Input file name
251  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv");
252 
253  // State whether the BOM tree should be built-in or parsed from an input file
254  const bool isBuiltin = false;
255 
256  // Try to fareQuote the sample default list of travel solutions
257  BOOST_CHECK_THROW (testFareQuoterHelper (8, lFareInputFilename, isBuiltin),
259 }
260 
265 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_09) {
266 
267  // Input file name
268  const stdair::Filename_T lEmptyInputFilename (STDAIR_SAMPLE_DIR "/ ");
269 
270  // State whether the BOM tree should be built-in or parsed from an input file
271  const bool isBuiltin = true;
272 
273  // Try to fareQuote the sample default list of travel solutions
274  BOOST_CHECK_NO_THROW(testFareQuoterHelper (9, lEmptyInputFilename, isBuiltin));
275 }
276 
277 
278 // End the test suite
279 BOOST_AUTO_TEST_SUITE_END()
280 
281