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> 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> 35 namespace boost_utf = boost::unit_test;
38 std::ofstream utfReportStream (
"EventQueueManagementTestSuite_utfresults.xml");
43 struct 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);
50 boost_utf::unit_test_log.set_format (boost_utf::XML);
52 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
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;
70 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
73 BOOST_AUTO_TEST_SUITE (master_test_suite)
78 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
81 const stdair::Filename_T lLogFilename (
"EventQueueManagementTestSuite.log");
84 std::ofstream logOutputFile;
86 logOutputFile.open (lLogFilename.c_str());
87 logOutputFile.clear();
90 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
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.");
102 sevmgrService.buildSampleQueue ();
107 stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
110 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
false,
111 "The event queue should not be empty at this step. " 112 <<
"Two insertions done.");
120 stdair::Count_T idx = 1;
121 while (sevmgrService.isQueueDone() ==
false) {
124 stdair::EventStruct lEventStruct;
125 const stdair::ProgressStatusSet lPPS =
126 sevmgrService.popEvent (lEventStruct);
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() <<
"'.");
142 BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
143 "Actual number of requests in the queue: " 144 << idx <<
". Expected value: " << lNbOfEvents);
147 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
148 "The event queue should be empty at this step: " 149 "the two events have been popped.");
151 STDAIR_LOG_DEBUG (
"Re-added the events into the queue");
157 sevmgrService.buildSampleQueue ();
160 stdair::EventStruct lFirstEventStruct;
161 const stdair::ProgressStatusSet lFirstPS =
162 sevmgrService.popEvent (lFirstEventStruct);
165 const stdair::DateTime_T& lFirstEventDateTime =
166 lFirstEventStruct.getEventTime ();
167 const stdair::Date_T& lFirstRequestDate =
168 lFirstEventDateTime.date();
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.");
179 STDAIR_LOG_DEBUG (
"Reset the queue");
180 sevmgrService.reset();
183 BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() ==
true,
184 "The event queue has been reset: it should be empty " 187 STDAIR_LOG_DEBUG (
"Re-added the events into the queue one more time");
193 sevmgrService.buildSampleQueue ();
197 stdair::EventStruct lBreakPointStruct;
198 sevmgrService.run(lBreakPointStruct);
199 stdair::EventType::EN_EventType lBreakPointType =
200 lBreakPointStruct.getEventType();
203 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
204 "The last event poppped from the queue should be a " 207 sevmgrService.run(lBreakPointStruct);
208 lBreakPointType = lBreakPointStruct.getEventType();
211 BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
212 "The last event poppped from the queue should be a " 216 const stdair::DateTime_T& lBPDateTime =
217 lBreakPointStruct.getEventTime ();
218 const stdair::Date_T& lBPDate =
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 <<
".");
229 STDAIR_LOG_DEBUG (
"End of the simulation");
232 logOutputFile.close();
236 BOOST_AUTO_TEST_SUITE_END()
class holding the services related to Travel Demand Generation.