$treeview $search $mathjax
SEvMgr Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

EventQueueManagementTestSuite.cpp

Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <sstream>
00010 #include <fstream>
00011 #include <map>
00012 #include <cmath>
00013 // Boost Unit Test Framework (UTF)
00014 #define BOOST_TEST_DYN_LINK
00015 #define BOOST_TEST_MAIN
00016 #define BOOST_TEST_MODULE EventQueueManagementTest
00017 #include <boost/test/unit_test.hpp>
00018 #include <boost/shared_ptr.hpp>
00019 // StdAir
00020 #include <stdair/stdair_basic_types.hpp>
00021 #include <stdair/stdair_date_time_types.hpp>
00022 #include <stdair/basic/BasLogParams.hpp>
00023 #include <stdair/basic/BasDBParams.hpp>
00024 #include <stdair/basic/BasFileMgr.hpp>
00025 #include <stdair/basic/ProgressStatusSet.hpp>
00026 #include <stdair/bom/EventStruct.hpp>
00027 #include <stdair/bom/BookingRequestStruct.hpp>
00028 #include <stdair/bom/BookingRequestTypes.hpp>
00029 #include <stdair/service/Logger.hpp>
00030 // SEvMgr
00031 #include <sevmgr/SEVMGR_Service.hpp>
00032 #include <sevmgr/config/sevmgr-paths.hpp>
00033 
00034 namespace boost_utf = boost::unit_test;
00035 
00036 // (Boost) Unit Test XML Report
00037 std::ofstream utfReportStream ("EventQueueManagementTestSuite_utfresults.xml");
00038 
00042 struct UnitTestConfig {
00044   UnitTestConfig() {
00045     boost_utf::unit_test_log.set_stream (utfReportStream);
00046     boost_utf::unit_test_log.set_format (boost_utf::XML);
00047     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00048     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00049   }
00050   
00052   ~UnitTestConfig() {
00053   }
00054 };
00055 
00056 // Specific type definitions
00057 typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
00058 typedef std::map<const stdair::DemandStreamKeyStr_T,
00059                  NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
00060 
00061 
00062 // /////////////// Main: Unit Test Suite //////////////
00063 
00064 // Set the UTF configuration (re-direct the output to a specific file)
00065 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00066 
00067 // Start the test suite
00068 BOOST_AUTO_TEST_SUITE (master_test_suite)
00069 
00070 
00073 BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {
00074   
00075   // Output log File
00076   const stdair::Filename_T lLogFilename ("EventQueueManagementTestSuite.log");
00077   
00078   // Set the log parameters
00079   std::ofstream logOutputFile;
00080   // open and clean the log outputfile
00081   logOutputFile.open (lLogFilename.c_str());
00082   logOutputFile.clear();
00083   
00084   // Initialise the Sevmgr service object
00085   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00086   SEVMGR::SEVMGR_Service sevmgrService (lLogParams);
00087 
00089   const bool isQueueDone = sevmgrService.isQueueDone();
00090   BOOST_REQUIRE_MESSAGE (isQueueDone == true,
00091                          "The event queue should be empty at this step. No "
00092                          << "insertion done.");  
00093 
00097   sevmgrService.buildSampleQueue (); 
00098 
00102   stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());
00103 
00105   BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == false,
00106                          "The event queue should not be empty at this step. "
00107                          << "Two insertions done.");
00108 
00115   stdair::Count_T idx = 1;
00116   while (sevmgrService.isQueueDone() == false) {
00117     
00118     // Pop the next event out of the event queue
00119     stdair::EventStruct lEventStruct;
00120     const stdair::ProgressStatusSet lPPS =
00121       sevmgrService.popEvent (lEventStruct);
00122 
00123     // DEBUG
00124     STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '"
00125                       << lEventStruct.describe() << "'.");
00126     STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe());
00127     STDAIR_LOG_DEBUG ("Poped event: '"
00128                       << lEventStruct.describe() << "'.");
00129 
00130     // Iterate
00131     ++idx;
00132   }
00133   
00134   // Compensate for the last iteration
00135   --idx;
00136   // Compared the actual number of popped events with the expected one. 
00137   BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,
00138                          "Actual number of requests in the queue: "
00139                          << idx << ". Expected value: " << lNbOfEvents);
00140 
00142   BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
00143                          "The event queue should be empty at this step: "
00144                          "the two events have been popped.");
00145 
00146   STDAIR_LOG_DEBUG ("Re-added the events into the queue");
00147 
00148   // Add again the four events into the queue thanks to 
00149   // sevmgrService.buildSampleQueue(). 
00150   // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
00151   // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
00152   sevmgrService.buildSampleQueue ();
00153 
00154   // Pop the next event out of the event queue
00155   stdair::EventStruct lFirstEventStruct;
00156   const stdair::ProgressStatusSet lFirstPS =
00157     sevmgrService.popEvent (lFirstEventStruct);
00158   
00159   // Extract the corresponding date
00160   const stdair::DateTime_T& lFirstEventDateTime =
00161     lFirstEventStruct.getEventTime ();
00162   const stdair::Date_T& lFirstRequestDate =
00163     lFirstEventDateTime.date();
00164 
00166   const stdair::Date_T lExpectedDate (2010, boost::gregorian::Jan, 21);
00167   BOOST_REQUIRE_MESSAGE (lFirstRequestDate == lExpectedDate,
00168                          "Date of the first event popped from the queue: "
00169                          << lFirstRequestDate << ". Should be: "
00170                          << lExpectedDate << " which is earlier in time.");
00171                 
00174   STDAIR_LOG_DEBUG ("Reset the queue");
00175   sevmgrService.reset();
00176 
00178   BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == true,
00179                          "The event queue has been reset: it should be empty "
00180                          << "at this step.");
00181 
00182   STDAIR_LOG_DEBUG ("Re-added the events into the queue one more time");
00183 
00184   // Add again the four events into the queue thanks to 
00185   // sevmgrService.buildSampleQueue(). 
00186   // Dates of the break points: 21-JAN-2010 and 14-MAY-2011.
00187   // Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.
00188   sevmgrService.buildSampleQueue ();
00189 
00192   stdair::EventStruct lBreakPointStruct;
00193   sevmgrService.run(lBreakPointStruct);
00194   stdair::EventType::EN_EventType lBreakPointType =
00195     lBreakPointStruct.getEventType();
00196 
00198   BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
00199                          "The last event poppped from the queue should be a "
00200                          << "break point.");
00201 
00202   sevmgrService.run(lBreakPointStruct);
00203   lBreakPointType = lBreakPointStruct.getEventType();
00204   
00206   BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,
00207                          "The last event poppped from the queue should be a "
00208                          << "break point.");
00209 
00210   // Extract the corresponding date
00211   const stdair::DateTime_T& lBPDateTime =
00212     lBreakPointStruct.getEventTime ();
00213   const stdair::Date_T& lBPDate =
00214     lBPDateTime.date();
00215 
00217   const stdair::Date_T lExpectedBPDate (2011, boost::gregorian::May, 14);
00218   BOOST_REQUIRE_MESSAGE (lBPDate == lExpectedBPDate,
00219                          "Date of the second break point popped from the queue: "
00220                          << lBPDate << ". Should be: "
00221                          << lExpectedBPDate << ".");
00222 
00223   // DEBUG
00224   STDAIR_LOG_DEBUG ("End of the simulation");
00225 
00226   // Close the log file
00227   logOutputFile.close();
00228 }
00229 
00230 // End the test suite
00231 BOOST_AUTO_TEST_SUITE_END()
00232 
00233