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> 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 #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);
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;
69 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
72 BOOST_AUTO_TEST_SUITE (master_test_suite)
77 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
80 const stdair::Filename_T lLogFilename (
"EventQueueManagementTestSuite.log");
83 std::ofstream logOutputFile;
85 logOutputFile.open (lLogFilename.c_str());
86 logOutputFile.clear();
89 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
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.");
101 sevmgrService.buildSampleQueue ();
106 stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
109 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
false,
110 "The event queue should not be empty at this step. " 111 <<
"Two insertions done.");
119 stdair::Count_T idx = 1;
120 while (sevmgrService.isQueueDone() ==
false) {
123 stdair::EventStruct lEventStruct;
124 const stdair::ProgressStatusSet lPPS =
125 sevmgrService.popEvent (lEventStruct);
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() <<
"'.");
141 BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
142 "Actual number of requests in the queue: " 143 << idx <<
". Expected value: " << lNbOfEvents);
146 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
147 "The event queue should be empty at this step: " 148 "the two events have been popped.");
150 STDAIR_LOG_DEBUG (
"Re-added the events into the queue");
156 sevmgrService.buildSampleQueue ();
159 stdair::EventStruct lFirstEventStruct;
160 const stdair::ProgressStatusSet lFirstPS =
161 sevmgrService.popEvent (lFirstEventStruct);
164 const stdair::DateTime_T& lFirstEventDateTime =
165 lFirstEventStruct.getEventTime ();
166 const stdair::Date_T& lFirstRequestDate =
167 lFirstEventDateTime.date();
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.");
178 STDAIR_LOG_DEBUG (
"Reset the queue");
179 sevmgrService.reset();
182 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
183 "The event queue has been reset: it should be empty " 186 STDAIR_LOG_DEBUG (
"Re-added the events into the queue one more time");
192 sevmgrService.buildSampleQueue ();
196 stdair::EventStruct lBreakPointStruct;
197 sevmgrService.run(lBreakPointStruct);
198 stdair::EventType::EN_EventType lBreakPointType =
199 lBreakPointStruct.getEventType();
202 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
203 "The last event poppped from the queue should be a " 206 sevmgrService.run(lBreakPointStruct);
207 lBreakPointType = lBreakPointStruct.getEventType();
210 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
211 "The last event poppped from the queue should be a " 215 const stdair::DateTime_T& lBPDateTime =
216 lBreakPointStruct.getEventTime ();
217 const stdair::Date_T& lBPDate =
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 <<
".");
228 STDAIR_LOG_DEBUG (
"End of the simulation");
231 logOutputFile.close();
235 BOOST_AUTO_TEST_SUITE_END()
class holding the services related to Travel Demand Generation.