SEvMgr Logo  1.00.0
C++ Simulation-Oriented Discrete Event Management Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
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
32 #include <sevmgr/config/sevmgr-paths.hpp>
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  boost_utf::unit_test_log.set_format (boost_utf::XML);
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 // Specific type definitions
57 typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
58 typedef std::map<const stdair::DemandStreamKeyStr_T,
59  NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
60 
61 
62 // /////////////// Main: Unit Test Suite //////////////
63 
64 // Set the UTF configuration (re-direct the output to a specific file)
65 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
66 
67 // Start the test suite
68 BOOST_AUTO_TEST_SUITE (master_test_suite)
69 
70 
73 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
74 
75  // Output log File
76  const stdair::Filename_T lLogFilename ("EventQueueManagementTestSuite.log");
77 
78  // Set the log parameters
79  std::ofstream logOutputFile;
80  // open and clean the log outputfile
81  logOutputFile.open (lLogFilename.c_str());
82  logOutputFile.clear();
83 
84  // Initialise the Sevmgr service object
85  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
86  SEVMGR::SEVMGR_Service sevmgrService (lLogParams);
87 
89  const bool isQueueDone = sevmgrService.isQueueDone();
90  BOOST_REQUIRE_MESSAGE (isQueueDone == true,
91  "The event queue should be empty at this step. No "
92  << "insertion done.");
93 
97  sevmgrService.buildSampleQueue ();
98 
102  stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
103 
105  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == false,
106  "The event queue should not be empty at this step. "
107  << "Two insertions done.");
108 
115  stdair::Count_T idx = 1;
116  while (sevmgrService.isQueueDone() == false) {
117 
118  // Pop the next event out of the event queue
119  stdair::EventStruct lEventStruct;
120  const stdair::ProgressStatusSet lPPS =
121  sevmgrService.popEvent (lEventStruct);
122 
123  // DEBUG
124  STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '"
125  << lEventStruct.describe() << "'.");
126  STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe());
127  STDAIR_LOG_DEBUG ("Poped event: '"
128  << lEventStruct.describe() << "'.");
129 
130  // Iterate
131  ++idx;
132  }
133 
134  // Compensate for the last iteration
135  --idx;
136  // Compared the actual number of popped events with the expected one.
137  BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
138  "Actual number of requests in the queue: "
139  << idx << ". Expected value: " << lNbOfEvents);
140 
142  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
143  "The event queue should be empty at this step: "
144  "the two events have been popped.");
145 
146  STDAIR_LOG_DEBUG ("Re-added the events into the queue");
147 
148  // Add again the four events into the queue thanks to
149  // sevmgrService.buildSampleQueue().
150  // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
151  // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
152  sevmgrService.buildSampleQueue ();
153 
154  // Pop the next event out of the event queue
155  stdair::EventStruct lFirstEventStruct;
156  const stdair::ProgressStatusSet lFirstPS =
157  sevmgrService.popEvent (lFirstEventStruct);
158 
159  // Extract the corresponding date
160  const stdair::DateTime_T& lFirstEventDateTime =
161  lFirstEventStruct.getEventTime ();
162  const stdair::Date_T& lFirstRequestDate =
163  lFirstEventDateTime.date();
164 
166  const stdair::Date_T lExpectedDate (2010, boost::gregorian::Jan, 21);
167  BOOST_REQUIRE_MESSAGE (lFirstRequestDate == lExpectedDate,
168  "Date of the first event popped from the queue: "
169  << lFirstRequestDate << ". Should be: "
170  << lExpectedDate << " which is earlier in time.");
171 
174  STDAIR_LOG_DEBUG ("Reset the queue");
175  sevmgrService.reset();
176 
178  BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
179  "The event queue has been reset: it should be empty "
180  << "at this step.");
181 
182  STDAIR_LOG_DEBUG ("Re-added the events into the queue one more time");
183 
184  // Add again the four events into the queue thanks to
185  // sevmgrService.buildSampleQueue().
186  // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
187  // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
188  sevmgrService.buildSampleQueue ();
189 
192  stdair::EventStruct lBreakPointStruct;
193  sevmgrService.run(lBreakPointStruct);
194  stdair::EventType::EN_EventType lBreakPointType =
195  lBreakPointStruct.getEventType();
196 
198  BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
199  "The last event poppped from the queue should be a "
200  << "break point.");
201 
202  sevmgrService.run(lBreakPointStruct);
203  lBreakPointType = lBreakPointStruct.getEventType();
204 
206  BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
207  "The last event poppped from the queue should be a "
208  << "break point.");
209 
210  // Extract the corresponding date
211  const stdair::DateTime_T& lBPDateTime =
212  lBreakPointStruct.getEventTime ();
213  const stdair::Date_T& lBPDate =
214  lBPDateTime.date();
215 
217  const stdair::Date_T lExpectedBPDate (2011, boost::gregorian::May, 14);
218  BOOST_REQUIRE_MESSAGE (lBPDate == lExpectedBPDate,
219  "Date of the second break point popped from the queue: "
220  << lBPDate << ". Should be: "
221  << lExpectedBPDate << ".");
222 
223  // DEBUG
224  STDAIR_LOG_DEBUG ("End of the simulation");
225 
226  // Close the log file
227  logOutputFile.close();
228 }
229 
230 // End the test suite
231 BOOST_AUTO_TEST_SUITE_END()
232 
233