AirInv Logo  1.00.8
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
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
28#include <airinv/config/airinv-paths.hpp>
29
30namespace boost_utf = boost::unit_test;
31
32// (Boost) Unit Test XML Report
33std::ofstream utfReportStream ("InventoryTestSuite_utfresults.xml");
34
38struct UnitTestConfig {
40 UnitTestConfig() {
41 boost_utf::unit_test_log.set_stream (utfReportStream);
42#if BOOST_VERSION_MACRO >= 105900
43 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
44#else // BOOST_VERSION_MACRO
45 boost_utf::unit_test_log.set_format (boost_utf::XML);
46#endif // BOOST_VERSION_MACRO
47 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
48 //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
49 }
50
52 ~UnitTestConfig() {
53 }
54};
55
56// //////////////////////////////////////////////////////////////////////
60bool testInventoryHelper (const unsigned short iTestFlag,
61 const stdair::Filename_T& iInventoryInputFilename,
62 const stdair::Filename_T& iScheduleInputFilename,
63 const stdair::Filename_T& iODInputFilename,
64 const stdair::Filename_T& iFRAT5InputFilename,
65 const stdair::Filename_T& iFFDisutilityInputFilename,
66 const stdair::Filename_T& iYieldInputFilename,
67 const bool isBuiltin,
68 const bool isForSchedule) {
69
70 // Output log File
71 std::ostringstream oStr;
72 oStr << "InventoryTestSuite_" << iTestFlag << ".log";
73 const stdair::Filename_T lLogFilename (oStr.str());
74
75 // Set the log parameters
76 std::ofstream logOutputFile;
77 // Open and clean the log outputfile
78 logOutputFile.open (lLogFilename.c_str());
79 logOutputFile.clear();
80
81 // Initialise the AirInv service object
82 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
83 logOutputFile);
84
85 // Initialise the inventory service
86 AIRINV::AIRINV_Master_Service airinvService (lLogParams);
87
88 // Parameters for the sale
89 std::string lSegmentDateKey;
90 stdair::ClassCode_T lClassCode;
91 const stdair::PartySize_T lPartySize (2);
92
93 // Check wether or not a (CSV) input file should be read
94 if (isBuiltin == true) {
95
96 // Build the default sample BOM tree (filled with inventories) for AirInv
97 airinvService.buildSampleBom();
98
99 // Define a specific segment-date key for the sample BOM tree
100 lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
101 lClassCode = "Q";
102
103 } else {
104
105 if (isForSchedule == true) {
106 // Build the BOM tree from parsing a schedule file (and O&D list)
107 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
108 stdair::ODFilePath lODFilePath (iODInputFilename);
109 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
110 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
111 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
112 airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
113 lFRAT5FilePath, lFFDisutilityFilePath,
114 lYieldFilePath);
115
116 // Define a specific segment-date key for the schedule-based inventory
117 lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
118 lClassCode = "Y";
119
120 } else {
121
122 // Build the BOM tree from parsing an inventory dump file
123 AIRINV::InventoryFilePath lInventoryFilePath (iInventoryInputFilename);
124 airinvService.parseAndLoad (lInventoryFilePath);
125
126 // Define a specific segment-date key for the inventory parsed file
127 //const std::string lSegmentDateKey ("SV, 5, 2010-03-11, KBP, JFK, 08:00:00");
128 lSegmentDateKey = "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
129 lClassCode = "J";
130 }
131
132 }
133
134 // Make a booking
135 const bool hasSaleBeenSuccessful =
136 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
137
138 // DEBUG: Display the list of travel solutions
139 const std::string& lCSVDump = airinvService.csvDisplay();
140 STDAIR_LOG_DEBUG (lCSVDump);
141
142 // Close the log file
143 logOutputFile.close();
144
145 if (hasSaleBeenSuccessful == false) {
146 STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
147 << "'");
148 }
149
150 return hasSaleBeenSuccessful;
151
152}
153
154// /////////////// Main: Unit Test Suite //////////////
155
156// Set the UTF configuration (re-direct the output to a specific file)
157BOOST_GLOBAL_FIXTURE (UnitTestConfig);
158
159// Start the test suite
160BOOST_AUTO_TEST_SUITE (master_test_suite)
161
162
165BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
166
167 // Input file name
168 const stdair::Filename_T lInventoryInputFilename (STDAIR_SAMPLE_DIR
169 "/invdump01.csv");
170
171 // State whether the BOM tree should be built-in or parsed from an input file
172 const bool isBuiltin = false;
173 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
174 const bool isForSchedule = false;
175
176 // Try sell a default segment.
177 bool hasTestBeenSuccessful = false;
178 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
179 testInventoryHelper (0, lInventoryInputFilename,
180 " ", " ", " ", " ", " ", isBuiltin, isForSchedule));
181 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
182
183}
184
188BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
189
190 // State whether the BOM tree should be built-in or parsed from an input file
191 const bool isBuiltin = true;
192 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
193 const bool isForSchedule = false;
194
195 // Try sell a default segment.
196 bool hasTestBeenSuccessful = false;
197 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
198 testInventoryHelper (1, " ", " ", " ", " ", " ", " ",
199 isBuiltin, isForSchedule));
200 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
201
202}
203
207BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
208
209 // Input file names
210 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
211 "/schedule01.csv");
212 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
213 "/ond01.csv");
214 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
215 "/frat5.csv");
216 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
217 "/ffDisutility.csv");
218 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
219 "/yieldstore01.csv");
220
221 // State whether the BOM tree should be built-in or parsed from an input file
222 const bool isBuiltin = false;
223 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
224 const bool isForSchedule = true;
225
226 // Try sell a default segment.
227 bool hasTestBeenSuccessful = false;
228 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
229 testInventoryHelper (2, " ",
230 lScheduleInputFilename,
231 lODInputFilename,
232 lFRAT5InputFilename,
233 lFFDisutilityInputFilename,
234 lYieldInputFilename,
235 isBuiltin, isForSchedule));
236 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
237
238}
239
244BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
245
246 // Inventory input file name
247 const stdair::Filename_T lMissingInventoryFilename (STDAIR_SAMPLE_DIR
248 "/missingFile.csv");
249
250 // State whether the BOM tree should be built-in or parsed from an input file
251 const bool isBuiltin = false;
252 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
253 const bool isForSchedule = false;
254
255 // Try sell a default segment.
256 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
257 " ", " ", " ", " ", " ", isBuiltin, isForSchedule),
259
260}
261
266BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
267
268 // Schedule input file name
269 const stdair::Filename_T lMissingScheduleFilename (STDAIR_SAMPLE_DIR
270 "/missingFile.csv");
271 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
272 "/frat5.csv");
273 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
274 "/ffDisutility.csv");
275
276 // State whether the BOM tree should be built-in or parsed from an input file
277 const bool isBuiltin = false;
278 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
279 const bool isForSchedule = true;
280
281 // Try sell a default segment.
282 BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
283 " ", lFRAT5InputFilename,
284 lFFDisutilityInputFilename, " ",
285 isBuiltin, isForSchedule),
287
288}
289
294BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
295
296 // Input file names
297 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
298 "/schedule01.csv");
299 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
300 "/ond01.csv");
301 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
302 "/frat5.csv");
303 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
304 "/ffDisutility.csv");
305 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
306 "/missingFile.csv");
307
308 // State whether the BOM tree should be built-in or parsed from an input file
309 const bool isBuiltin = false;
310 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
311 const bool isForSchedule = true;
312
313 // Try sell a default segment.
314 BOOST_CHECK_THROW (testInventoryHelper (5, " ",
315 lScheduleInputFilename,
316 lODInputFilename,
317 lFRAT5InputFilename,
318 lFFDisutilityInputFilename,
319 lYieldInputFilename,
320 isBuiltin, isForSchedule),
321 AIRRAC::YieldInputFileNotFoundException);
322
323}
324
329BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
330
331 // Input file names
332 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
333 "/scheduleError01.csv");
334 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
335 "/ond01.csv");
336 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
337 "/frat5.csv");
338 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
339 "/ffDisutility.csv");
340 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
341 "/missingFile.csv");
342
343 // State whether the BOM tree should be built-in or parsed from an input file
344 const bool isBuiltin = false;
345 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
346 const bool isForSchedule = true;
347
348 // Try sell a default segment.
349 BOOST_CHECK_THROW (testInventoryHelper (6, " ",
350 lScheduleInputFilename,
351 lODInputFilename,
352 lFRAT5InputFilename,
353 lFFDisutilityInputFilename,
354 lYieldInputFilename,
355 isBuiltin, isForSchedule),
357
358}
359
364BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
365
366 // Input file names
367 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
368 "/scheduleError02.csv");
369 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
370 "/ond01.csv");
371 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
372 "/frat5.csv");
373 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
374 "/ffDisutility.csv");
375 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
376 "/yieldstore01.csv");
377
378 // State whether the BOM tree should be built-in or parsed from an input file
379 const bool isBuiltin = false;
380 // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
381 const bool isForSchedule = true;
382
383 // Try sell a default segment.
384 BOOST_CHECK_THROW (testInventoryHelper (7, " ",
385 lScheduleInputFilename,
386 lODInputFilename,
387 lFRAT5InputFilename,
388 lFFDisutilityInputFilename,
389 lYieldInputFilename,
390 isBuiltin, isForSchedule),
392
393}
394
395// End the test suite
396BOOST_AUTO_TEST_SUITE_END()
397
398
Interface for the AIRINV Services.