*/
#include <sstream>
#include <fstream>
#include <map>
#include <cmath>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE EventQueueManagementTest
#include <boost/test/unit_test.hpp>
#include <boost/shared_ptr.hpp>
#include <stdair/stdair_basic_types.hpp>
#include <stdair/stdair_date_time_types.hpp>
#include <stdair/basic/BasLogParams.hpp>
#include <stdair/basic/BasDBParams.hpp>
#include <stdair/basic/BasFileMgr.hpp>
#include <stdair/basic/ProgressStatusSet.hpp>
#include <stdair/bom/EventStruct.hpp>
#include <stdair/bom/BookingRequestStruct.hpp>
#include <stdair/bom/BookingRequestTypes.hpp>
#include <stdair/service/Logger.hpp>
#include <sevmgr/config/sevmgr-paths.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("EventQueueManagementTestSuite_utfresults.xml");
struct UnitTestConfig {
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
~UnitTestConfig() {
}
};
typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
typedef std::map<const stdair::DemandStreamKeyStr_T,
NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
const stdair::Filename_T lLogFilename ("EventQueueManagementTestSuite.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
const bool isQueueDone = sevmgrService.isQueueDone();
BOOST_REQUIRE_MESSAGE (isQueueDone == true,
"The event queue should be empty at this step. No "
<< "insertion done.");
sevmgrService.buildSampleQueue ();
stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == false,
"The event queue should not be empty at this step. "
<< "Two insertions done.");
stdair::Count_T idx = 1;
while (sevmgrService.isQueueDone() == false) {
stdair::EventStruct lEventStruct;
const stdair::ProgressStatusSet lPPS =
sevmgrService.popEvent (lEventStruct);
STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '"
<< lEventStruct.describe() << "'.");
STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe());
STDAIR_LOG_DEBUG ("Poped event: '"
<< lEventStruct.describe() << "'.");
++idx;
}
--idx;
BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
"Actual number of requests in the queue: "
<< idx << ". Expected value: " << lNbOfEvents);
BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
"The event queue should be empty at this step: "
"the two events have been popped.");
STDAIR_LOG_DEBUG ("Re-added the events into the queue");
sevmgrService.buildSampleQueue ();
stdair::EventStruct lFirstEventStruct;
const stdair::ProgressStatusSet lFirstPS =
sevmgrService.popEvent (lFirstEventStruct);
const stdair::DateTime_T& lFirstEventDateTime =
lFirstEventStruct.getEventTime ();
const stdair::Date_T& lFirstRequestDate =
lFirstEventDateTime.date();
const stdair::Date_T lExpectedDate (2010, boost::gregorian::Jan, 21);
BOOST_REQUIRE_MESSAGE (lFirstRequestDate == lExpectedDate,
"Date of the first event popped from the queue: "
<< lFirstRequestDate << ". Should be: "
<< lExpectedDate << " which is earlier in time.");
STDAIR_LOG_DEBUG ("Reset the queue");
sevmgrService.reset();
BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
"The event queue has been reset: it should be empty "
<< "at this step.");
STDAIR_LOG_DEBUG ("Re-added the events into the queue one more time");
sevmgrService.buildSampleQueue ();
stdair::EventStruct lBreakPointStruct;
sevmgrService.run(lBreakPointStruct);
stdair::EventType::EN_EventType lBreakPointType =
lBreakPointStruct.getEventType();
BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
"The last event poppped from the queue should be a "
<< "break point.");
sevmgrService.run(lBreakPointStruct);
lBreakPointType = lBreakPointStruct.getEventType();
BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
"The last event poppped from the queue should be a "
<< "break point.");
const stdair::DateTime_T& lBPDateTime =
lBreakPointStruct.getEventTime ();
const stdair::Date_T& lBPDate =
lBPDateTime.date();
const stdair::Date_T lExpectedBPDate (2011, boost::gregorian::May, 14);
BOOST_REQUIRE_MESSAGE (lBPDate == lExpectedBPDate,
"Date of the second break point popped from the queue: "
<< lBPDate << ". Should be: "
<< lExpectedBPDate << ".");
STDAIR_LOG_DEBUG ("End of the simulation");
logOutputFile.close();
}
BOOST_AUTO_TEST_SUITE_END()