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