SEvMgr Logo  1.00.3
C++ Simulation-Oriented Discrete Event Management Library
EventQueueManagementTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <map>
12 #include <cmath>
13 // Boost Unit Test Framework (UTF)
14 #define BOOST_TEST_DYN_LINK
15 #define BOOST_TEST_MAIN
16 #define BOOST_TEST_MODULE EventQueueManagementTest
17 #include <boost/test/unit_test.hpp>
18 #include <boost/shared_ptr.hpp>
19 // StdAir
20 #include <stdair/stdair_basic_types.hpp>
21 #include <stdair/stdair_date_time_types.hpp>
22 #include <stdair/basic/BasLogParams.hpp>
23 #include <stdair/basic/BasDBParams.hpp>
24 #include <stdair/basic/BasFileMgr.hpp>
25 #include <stdair/basic/ProgressStatusSet.hpp>
26 #include <stdair/bom/EventStruct.hpp>
27 #include <stdair/bom/BookingRequestStruct.hpp>
28 #include <stdair/bom/BookingRequestTypes.hpp>
29 #include <stdair/service/Logger.hpp>
30 // SEvMgr
33 
34 namespace boost_utf = boost::unit_test;
35 
36 // (Boost) Unit Test XML Report
37 std::ofstream utfReportStream ("EventQueueManagementTestSuite_utfresults.xml");
38 
42 struct UnitTestConfig {
44  UnitTestConfig() {
45  boost_utf::unit_test_log.set_stream (utfReportStream);
46 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
47  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
48 #else // BOOST_VERSION
49  boost_utf::unit_test_log.set_format (boost_utf::XML);
50 #endif // BOOST_VERSION
51  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
52  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
53  }
54 
56  ~UnitTestConfig() {
57  }
58 };
59 
60 // Specific type definitions
61 typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
62 typedef std::map<const stdair::DemandStreamKeyStr_T,
63  NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
64 
65 
66 // /////////////// Main: Unit Test Suite //////////////
67 
68 // Set the UTF configuration (re-direct the output to a specific file)
69 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
70 
71 // Start the test suite
72 BOOST_AUTO_TEST_SUITE (master_test_suite)
73 
74 
77 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
78 
79  // Output log File
80  const stdair::Filename_T lLogFilename ("EventQueueManagementTestSuite.log");
81 
82  // Set the log parameters
83  std::ofstream logOutputFile;
84  // open and clean the log outputfile
85  logOutputFile.open (lLogFilename.c_str());
86  logOutputFile.clear();
87 
88  // Initialise the Sevmgr service object
89  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
90  SEVMGR::SEVMGR_Service sevmgrService (lLogParams);
91 
93  const bool isQueueDone = sevmgrService.isQueueDone();
94  BOOST_REQUIRE_MESSAGE (isQueueDone == true,
95  "The event queue should be empty at this step. No "
96  << "insertion done.");
97 
101  sevmgrService.buildSampleQueue ();
102 
106  stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
107 
109  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == false,
110  "The event queue should not be empty at this step. "
111  << "Two insertions done.");
112 
119  stdair::Count_T idx = 1;
120  while (sevmgrService.isQueueDone() == false) {
121 
122  // Pop the next event out of the event queue
123  stdair::EventStruct lEventStruct;
124  const stdair::ProgressStatusSet lPPS =
125  sevmgrService.popEvent (lEventStruct);
126 
127  // DEBUG
128  STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '"
129  << lEventStruct.describe() << "'.");
130  STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe());
131  STDAIR_LOG_DEBUG ("Poped event: '"
132  << lEventStruct.describe() << "'.");
133 
134  // Iterate
135  ++idx;
136  }
137 
138  // Compensate for the last iteration
139  --idx;
140  // Compared the actual number of popped events with the expected one.
141  BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
142  "Actual number of requests in the queue: "
143  << idx << ". Expected value: " << lNbOfEvents);
144 
146  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
147  "The event queue should be empty at this step: "
148  "the two events have been popped.");
149 
150  STDAIR_LOG_DEBUG ("Re-added the events into the queue");
151 
152  // Add again the four events into the queue thanks to
153  // sevmgrService.buildSampleQueue().
154  // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
155  // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
156  sevmgrService.buildSampleQueue ();
157 
158  // Pop the next event out of the event queue
159  stdair::EventStruct lFirstEventStruct;
160  const stdair::ProgressStatusSet lFirstPS =
161  sevmgrService.popEvent (lFirstEventStruct);
162 
163  // Extract the corresponding date
164  const stdair::DateTime_T& lFirstEventDateTime =
165  lFirstEventStruct.getEventTime ();
166  const stdair::Date_T& lFirstRequestDate =
167  lFirstEventDateTime.date();
168 
170  const stdair::Date_T lExpectedDate (2010, boost::gregorian::Jan, 21);
171  BOOST_REQUIRE_MESSAGE (lFirstRequestDate == lExpectedDate,
172  "Date of the first event popped from the queue: "
173  << lFirstRequestDate << ". Should be: "
174  << lExpectedDate << " which is earlier in time.");
175 
178  STDAIR_LOG_DEBUG ("Reset the queue");
179  sevmgrService.reset();
180 
182  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
183  "The event queue has been reset: it should be empty "
184  << "at this step.");
185 
186  STDAIR_LOG_DEBUG ("Re-added the events into the queue one more time");
187 
188  // Add again the four events into the queue thanks to
189  // sevmgrService.buildSampleQueue().
190  // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
191  // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
192  sevmgrService.buildSampleQueue ();
193 
196  stdair::EventStruct lBreakPointStruct;
197  sevmgrService.run(lBreakPointStruct);
198  stdair::EventType::EN_EventType lBreakPointType =
199  lBreakPointStruct.getEventType();
200 
202  BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
203  "The last event poppped from the queue should be a "
204  << "break point.");
205 
206  sevmgrService.run(lBreakPointStruct);
207  lBreakPointType = lBreakPointStruct.getEventType();
208 
210  BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
211  "The last event poppped from the queue should be a "
212  << "break point.");
213 
214  // Extract the corresponding date
215  const stdair::DateTime_T& lBPDateTime =
216  lBreakPointStruct.getEventTime ();
217  const stdair::Date_T& lBPDate =
218  lBPDateTime.date();
219 
221  const stdair::Date_T lExpectedBPDate (2011, boost::gregorian::May, 14);
222  BOOST_REQUIRE_MESSAGE (lBPDate == lExpectedBPDate,
223  "Date of the second break point popped from the queue: "
224  << lBPDate << ". Should be: "
225  << lExpectedBPDate << ".");
226 
227  // DEBUG
228  STDAIR_LOG_DEBUG ("End of the simulation");
229 
230  // Close the log file
231  logOutputFile.close();
232 }
233 
234 // End the test suite
235 BOOST_AUTO_TEST_SUITE_END()
236 
237 
class holding the services related to Travel Demand Generation.