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>
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>
32 #include <sevmgr/config/sevmgr-paths.hpp>
34 namespace boost_utf = boost::unit_test;
37 std::ofstream utfReportStream (
"EventQueueManagementTestSuite_utfresults.xml");
42 struct 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);
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;
65 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
68 BOOST_AUTO_TEST_SUITE (master_test_suite)
73 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
76 const stdair::Filename_T lLogFilename (
"EventQueueManagementTestSuite.log");
79 std::ofstream logOutputFile;
81 logOutputFile.open (lLogFilename.c_str());
82 logOutputFile.clear();
85 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
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.");
97 sevmgrService.buildSampleQueue ();
102 stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
105 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
false,
106 "The event queue should not be empty at this step. "
107 <<
"Two insertions done.");
115 stdair::Count_T idx = 1;
116 while (sevmgrService.isQueueDone() ==
false) {
119 stdair::EventStruct lEventStruct;
120 const stdair::ProgressStatusSet lPPS =
121 sevmgrService.popEvent (lEventStruct);
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() <<
"'.");
137 BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
138 "Actual number of requests in the queue: "
139 << idx <<
". Expected value: " << lNbOfEvents);
142 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
143 "The event queue should be empty at this step: "
144 "the two events have been popped.");
146 STDAIR_LOG_DEBUG (
"Re-added the events into the queue");
152 sevmgrService.buildSampleQueue ();
155 stdair::EventStruct lFirstEventStruct;
156 const stdair::ProgressStatusSet lFirstPS =
157 sevmgrService.popEvent (lFirstEventStruct);
160 const stdair::DateTime_T& lFirstEventDateTime =
161 lFirstEventStruct.getEventTime ();
162 const stdair::Date_T& lFirstRequestDate =
163 lFirstEventDateTime.date();
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.");
174 STDAIR_LOG_DEBUG (
"Reset the queue");
175 sevmgrService.reset();
178 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
179 "The event queue has been reset: it should be empty "
182 STDAIR_LOG_DEBUG (
"Re-added the events into the queue one more time");
188 sevmgrService.buildSampleQueue ();
192 stdair::EventStruct lBreakPointStruct;
193 sevmgrService.run(lBreakPointStruct);
194 stdair::EventType::EN_EventType lBreakPointType =
195 lBreakPointStruct.getEventType();
198 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
199 "The last event poppped from the queue should be a "
202 sevmgrService.run(lBreakPointStruct);
203 lBreakPointType = lBreakPointStruct.getEventType();
206 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
207 "The last event poppped from the queue should be a "
211 const stdair::DateTime_T& lBPDateTime =
212 lBreakPointStruct.getEventTime ();
213 const stdair::Date_T& lBPDate =
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 <<
".");
224 STDAIR_LOG_DEBUG (
"End of the simulation");
227 logOutputFile.close();
231 BOOST_AUTO_TEST_SUITE_END()