AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InventoryTestSuite.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 InventoryTestSuite
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/bom/BookingRequestStruct.hpp>
23 #include <stdair/service/Logger.hpp>
24 #include <stdair/stdair_exceptions.hpp>
25 // Airinv
26 #include <airinv/AIRINV_Types.hpp>
29 
30 namespace boost_utf = boost::unit_test;
31 
32 // (Boost) Unit Test XML Report
33 std::ofstream utfReportStream ("InventoryTestSuite_utfresults.xml");
34 
38 struct UnitTestConfig {
40  UnitTestConfig() {
41  boost_utf::unit_test_log.set_stream (utfReportStream);
42  boost_utf::unit_test_log.set_format (boost_utf::XML);
43  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
44  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
45  }
46 
48  ~UnitTestConfig() {
49  }
50 };
51 
52 // //////////////////////////////////////////////////////////////////////
56 bool testInventoryHelper (const unsigned short iTestFlag,
57  const stdair::Filename_T& iInventoryInputFilename,
58  const stdair::Filename_T& iScheduleInputFilename,
59  const stdair::Filename_T& iODInputFilename,
60  const stdair::Filename_T& iYieldInputFilename,
61  const bool isBuiltin,
62  const bool isForSchedule) {
63 
64  // Output log File
65  std::ostringstream oStr;
66  oStr << "InventoryTestSuite_" << iTestFlag << ".log";
67  const stdair::Filename_T lLogFilename (oStr.str());
68 
69  // Set the log parameters
70  std::ofstream logOutputFile;
71  // Open and clean the log outputfile
72  logOutputFile.open (lLogFilename.c_str());
73  logOutputFile.clear();
74 
75  // Initialise the AirInv service object
76  const bool lForceMultipleInit = true;
77  stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
78  logOutputFile,
79  lForceMultipleInit);
80 
81  // Initialise the inventory service
82  AIRINV::AIRINV_Master_Service airinvService (lLogParams);
83 
84  // Parameters for the sale
85  std::string lSegmentDateKey;
86  stdair::ClassCode_T lClassCode;
87  const stdair::PartySize_T lPartySize (2);
88 
89  // Check wether or not a (CSV) input file should be read
90  if (isBuiltin == true) {
91 
92  // Build the default sample BOM tree (filled with inventories) for AirInv
93  airinvService.buildSampleBom();
94 
95  // Define a specific segment-date key for the sample BOM tree
96  lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
97  lClassCode = "Q";
98 
99  } else {
100 
101  if (isForSchedule == true) {
102  // Build the BOM tree from parsing a schedule file (and O&D list)
103  AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
104  airinvService.parseAndLoad (iScheduleInputFilename, iODInputFilename,
105  lYieldFilePath);
106 
107  // Define a specific segment-date key for the schedule-based inventory
108  lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
109  lClassCode = "Y";
110 
111  } else {
112 
113  // Build the BOM tree from parsing an inventory dump file
114  airinvService.parseAndLoad (iInventoryInputFilename);
115 
116  // Define a specific segment-date key for the inventory parsed file
117  //const std::string lSegmentDateKey ("SV, 5, 2010-03-11, KBP, JFK, 08:00:00");
118  lSegmentDateKey = "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
119  lClassCode = "J";
120  }
121 
122  }
123 
124  // Make a booking
125  const bool hasSaleBeenSuccessful =
126  airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
127 
128  // DEBUG: Display the list of travel solutions
129  const std::string& lCSVDump = airinvService.csvDisplay();
130  STDAIR_LOG_DEBUG (lCSVDump);
131 
132  // Close the log file
133  logOutputFile.close();
134 
135  if (hasSaleBeenSuccessful == false) {
136  STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
137  << "'");
138  }
139 
140  return hasSaleBeenSuccessful;
141 
142 }
143 
144 // /////////////// Main: Unit Test Suite //////////////
145 
146 // Set the UTF configuration (re-direct the output to a specific file)
147 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
148 
149 // Start the test suite
150 BOOST_AUTO_TEST_SUITE (master_test_suite)
151 
152 
155 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
156 
157  // Input file name
158  const stdair::Filename_T lInventoryInputFilename (STDAIR_SAMPLE_DIR
159  "/invdump01.csv");
160 
161  // State whether the BOM tree should be built-in or parsed from an input file
162  const bool isBuiltin = false;
163  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
164  const bool isForSchedule = false;
165 
166  // Try sell a default segment.
167  bool hasTestBeenSuccessful = false;
168  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
169  testInventoryHelper (0, lInventoryInputFilename,
170  " ", " ", " ", isBuiltin, isForSchedule));
171  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
172 
173 }
174 
178 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
179 
180  // State whether the BOM tree should be built-in or parsed from an input file
181  const bool isBuiltin = true;
182  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
183  const bool isForSchedule = false;
184 
185  // Try sell a default segment.
186  bool hasTestBeenSuccessful = false;
187  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
188  testInventoryHelper (1, " ", " ", " ", " ",
189  isBuiltin, isForSchedule));
190  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
191 
192 }
193 
197 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
198 
199  // Input file names
200  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
201  "/schedule01.csv");
202  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
203  "/ond01.csv");
204  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
205  "/yieldstore01.csv");
206 
207  // State whether the BOM tree should be built-in or parsed from an input file
208  const bool isBuiltin = false;
209  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
210  const bool isForSchedule = true;
211 
212  // Try sell a default segment.
213  bool hasTestBeenSuccessful = false;
214  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
215  testInventoryHelper (2, " ",
216  lScheduleInputFilename,
217  lODInputFilename,
218  lYieldInputFilename,
219  isBuiltin, isForSchedule));
220  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
221 
222 }
223 
228 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
229 
230  // Inventory input file name
231  const stdair::Filename_T lMissingInventoryFilename (STDAIR_SAMPLE_DIR
232  "/missingFile.csv");
233 
234  // State whether the BOM tree should be built-in or parsed from an input file
235  const bool isBuiltin = false;
236  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
237  const bool isForSchedule = false;
238 
239  // Try sell a default segment.
240  BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
241  " ", " ", " ", isBuiltin, isForSchedule),
243 
244 }
245 
250 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
251 
252  // Schedule input file name
253  const stdair::Filename_T lMissingScheduleFilename (STDAIR_SAMPLE_DIR
254  "/missingFile.csv");
255 
256  // State whether the BOM tree should be built-in or parsed from an input file
257  const bool isBuiltin = false;
258  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
259  const bool isForSchedule = true;
260 
261  // Try sell a default segment.
262  BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
263  " ", " ", isBuiltin, isForSchedule),
265 
266 }
267 
272 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
273 
274  // Input file names
275  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
276  "/schedule01.csv");
277  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
278  "/ond01.csv");
279  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
280  "/missingFile.csv");
281 
282  // State whether the BOM tree should be built-in or parsed from an input file
283  const bool isBuiltin = false;
284  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
285  const bool isForSchedule = true;
286 
287  // Try sell a default segment.
288  BOOST_CHECK_THROW (testInventoryHelper (5, " ",
289  lScheduleInputFilename,
290  lODInputFilename,
291  lYieldInputFilename,
292  isBuiltin, isForSchedule),
293  AIRRAC::YieldInputFileNotFoundException);
294 
295 }
296 
301 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
302 
303  // Input file names
304  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
305  "/scheduleError01.csv");
306  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
307  "/ond01.csv");
308  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
309  "/missingFile.csv");
310 
311  // State whether the BOM tree should be built-in or parsed from an input file
312  const bool isBuiltin = false;
313  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
314  const bool isForSchedule = true;
315 
316  // Try sell a default segment.
317  BOOST_CHECK_THROW (testInventoryHelper (6, " ",
318  lScheduleInputFilename,
319  lODInputFilename,
320  lYieldInputFilename,
321  isBuiltin, isForSchedule),
323 
324 }
325 
330 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
331 
332  // Input file names
333  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
334  "/scheduleError02.csv");
335  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
336  "/ond01.csv");
337  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
338  "/yieldstore01.csv");
339 
340  // State whether the BOM tree should be built-in or parsed from an input file
341  const bool isBuiltin = false;
342  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
343  const bool isForSchedule = true;
344 
345  // Try sell a default segment.
346  BOOST_CHECK_THROW (testInventoryHelper (7, " ",
347  lScheduleInputFilename,
348  lODInputFilename,
349  lYieldInputFilename,
350  isBuiltin, isForSchedule),
352 
353 }
354 
355 // End the test suite
356 BOOST_AUTO_TEST_SUITE_END()
357 
358