<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta name="robots" content="index,follow"/> <title>Command-Line Test to Demonstrate How To Use Sevmgr elements</title> <link rel="shortcut icon" href="favicon.ico"> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="sevmgr.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript"> $(document).ready(initResizable); $(window).load(resizeHeight); </script> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/search.js"></script> <script type="text/javascript"> $(document).ready(function() { searchBox.OnSelectItem(0); }); </script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-28344140-1']); _gaq.push(['_setDomainName', 'none']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table width="100%"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname"><a href="http://sevmgr.sourceforge.net"><img height="45px" alt="SEvMgr Logo" src="sevmgr_logo.png"></a>  <span id="projectnumber">1.00.0</span> </div> <div id="projectbrief">C++ Simulation-Oriented Discrete Event Management Library</div> </td> <!-- begin SOURCEFORGE_CUSTOM--> <td> <div id="sflogo"><a href="http://sevmgr.sourceforge.net"><img height="45px" alt="SourceForge Logo" src="sfx_logo.png"></a></div> </td> <!-- end SOURCEFORGE_CUSTOM--> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.8.3.1 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <span class="left"> <img id="MSearchSelect" src="search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> </span><span class="right"> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </span> </div> </li> </ul> </div> </div><!-- top --> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> <div id="nav-sync" class="sync"></div> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> $(document).ready(function(){initNavTree('EventQueueManagementTestSuite_cpp.html','');}); </script> <div id="doc-content"> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Pages</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <div class="header"> <div class="headertitle"> <div class="title">Command-Line Test to Demonstrate How To Use Sevmgr elements </div> </div> </div><!--header--> <div class="contents"> <div class="textblock"><div class="fragment"><div class="line"> */</div> <div class="line"><span class="comment">// //////////////////////////////////////////////////////////////////////</span></div> <div class="line"><span class="comment">// Import section</span></div> <div class="line"><span class="comment">// //////////////////////////////////////////////////////////////////////</span></div> <div class="line"><span class="comment">// STL</span></div> <div class="line"><span class="preprocessor">#include <sstream></span></div> <div class="line"><span class="preprocessor">#include <fstream></span></div> <div class="line"><span class="preprocessor">#include <map></span></div> <div class="line"><span class="preprocessor">#include <cmath></span></div> <div class="line"><span class="comment">// Boost Unit Test Framework (UTF)</span></div> <div class="line"><span class="preprocessor">#define BOOST_TEST_DYN_LINK</span></div> <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define BOOST_TEST_MAIN</span></div> <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define BOOST_TEST_MODULE EventQueueManagementTest</span></div> <div class="line"><span class="preprocessor"></span><span class="preprocessor">#include <boost/test/unit_test.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/shared_ptr.hpp></span></div> <div class="line"><span class="comment">// StdAir</span></div> <div class="line"><span class="preprocessor">#include <stdair/stdair_basic_types.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/stdair_date_time_types.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/basic/BasLogParams.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/basic/BasDBParams.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/basic/BasFileMgr.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/basic/ProgressStatusSet.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/bom/EventStruct.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/bom/BookingRequestStruct.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/bom/BookingRequestTypes.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/service/Logger.hpp></span></div> <div class="line"><span class="comment">// SEvMgr</span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="SEVMGR__Service_8hpp.html">sevmgr/SEVMGR_Service.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="sevmgr-paths_8hpp.html">sevmgr/config/sevmgr-paths.hpp</a>></span></div> <div class="line"></div> <div class="line"><span class="keyword">namespace </span>boost_utf = boost::unit_test;</div> <div class="line"></div> <div class="line"><span class="comment">// (Boost) Unit Test XML Report</span></div> <div class="line">std::ofstream utfReportStream (<span class="stringliteral">"EventQueueManagementTestSuite_utfresults.xml"</span>);</div> <div class="line"></div> <div class="line"><span class="keyword">struct </span>UnitTestConfig {</div> <div class="line"> UnitTestConfig() {</div> <div class="line"> boost_utf::unit_test_log.set_stream (utfReportStream);</div> <div class="line"> boost_utf::unit_test_log.set_format (boost_utf::XML);</div> <div class="line"> boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);</div> <div class="line"> <span class="comment">//boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);</span></div> <div class="line"> }</div> <div class="line"> </div> <div class="line"> ~UnitTestConfig() {</div> <div class="line"> }</div> <div class="line">};</div> <div class="line"></div> <div class="line"><span class="comment">// Specific type definitions</span></div> <div class="line"><span class="keyword">typedef</span> std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;</div> <div class="line"><span class="keyword">typedef</span> std::map<<span class="keyword">const</span> stdair::DemandStreamKeyStr_T,</div> <div class="line"> NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;</div> <div class="line"></div> <div class="line"></div> <div class="line"><span class="comment">// /////////////// Main: Unit Test Suite //////////////</span></div> <div class="line"></div> <div class="line"><span class="comment">// Set the UTF configuration (re-direct the output to a specific file)</span></div> <div class="line">BOOST_GLOBAL_FIXTURE (UnitTestConfig);</div> <div class="line"></div> <div class="line"><span class="comment">// Start the test suite</span></div> <div class="line">BOOST_AUTO_TEST_SUITE (master_test_suite)</div> <div class="line"></div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (sevmgr_simple_simulation_test) {</div> <div class="line"> </div> <div class="line"> <span class="comment">// Output log File</span></div> <div class="line"> <span class="keyword">const</span> stdair::Filename_T lLogFilename (<span class="stringliteral">"EventQueueManagementTestSuite.log"</span>);</div> <div class="line"> </div> <div class="line"> <span class="comment">// Set the log parameters</span></div> <div class="line"> std::ofstream logOutputFile;</div> <div class="line"> <span class="comment">// open and clean the log outputfile</span></div> <div class="line"> logOutputFile.open (lLogFilename.c_str());</div> <div class="line"> logOutputFile.clear();</div> <div class="line"> </div> <div class="line"> <span class="comment">// Initialise the Sevmgr service object</span></div> <div class="line"> <span class="keyword">const</span> stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);</div> <div class="line"> <a class="code" href="classSEVMGR_1_1SEVMGR__Service.html" title="class holding the services related to Travel Demand Generation.">SEVMGR::SEVMGR_Service</a> sevmgrService (lLogParams);</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">bool</span> isQueueDone = sevmgrService.isQueueDone();</div> <div class="line"> BOOST_REQUIRE_MESSAGE (isQueueDone == <span class="keyword">true</span>,</div> <div class="line"> <span class="stringliteral">"The event queue should be empty at this step. No "</span></div> <div class="line"> << <span class="stringliteral">"insertion done."</span>); </div> <div class="line"></div> <div class="line"> sevmgrService.buildSampleQueue (); </div> <div class="line"></div> <div class="line"> stdair::Count_T lNbOfEvents (sevmgrService.getQueueSize());</div> <div class="line"></div> <div class="line"> BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == <span class="keyword">false</span>,</div> <div class="line"> <span class="stringliteral">"The event queue should not be empty at this step. "</span></div> <div class="line"> << <span class="stringliteral">"Two insertions done."</span>);</div> <div class="line"></div> <div class="line"> stdair::Count_T idx = 1;</div> <div class="line"> <span class="keywordflow">while</span> (sevmgrService.isQueueDone() == <span class="keyword">false</span>) {</div> <div class="line"> </div> <div class="line"> <span class="comment">// Pop the next event out of the event queue</span></div> <div class="line"> stdair::EventStruct lEventStruct;</div> <div class="line"> <span class="keyword">const</span> stdair::ProgressStatusSet lPPS =</div> <div class="line"> sevmgrService.popEvent (lEventStruct);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Poped event "</span><< idx << <span class="stringliteral">": '"</span></div> <div class="line"> << lEventStruct.describe() << <span class="stringliteral">"'."</span>);</div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Progresss status: "</span> << lPPS.describe());</div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Poped event: '"</span></div> <div class="line"> << lEventStruct.describe() << <span class="stringliteral">"'."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Iterate</span></div> <div class="line"> ++idx;</div> <div class="line"> }</div> <div class="line"> </div> <div class="line"> <span class="comment">// Compensate for the last iteration</span></div> <div class="line"> --idx;</div> <div class="line"> <span class="comment">// Compared the actual number of popped events with the expected one. </span></div> <div class="line"> BOOST_REQUIRE_MESSAGE (idx == lNbOfEvents,</div> <div class="line"> <span class="stringliteral">"Actual number of requests in the queue: "</span></div> <div class="line"> << idx << <span class="stringliteral">". Expected value: "</span> << lNbOfEvents);</div> <div class="line"></div> <div class="line"> BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == <span class="keyword">true</span>,</div> <div class="line"> <span class="stringliteral">"The event queue should be empty at this step: "</span></div> <div class="line"> <span class="stringliteral">"the two events have been popped."</span>);</div> <div class="line"></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Re-added the events into the queue"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Add again the four events into the queue thanks to </span></div> <div class="line"> <span class="comment">// sevmgrService.buildSampleQueue(). </span></div> <div class="line"> <span class="comment">// Dates of the break points: 21-JAN-2010 and 14-MAY-2011.</span></div> <div class="line"> <span class="comment">// Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.</span></div> <div class="line"> sevmgrService.buildSampleQueue ();</div> <div class="line"></div> <div class="line"> <span class="comment">// Pop the next event out of the event queue</span></div> <div class="line"> stdair::EventStruct lFirstEventStruct;</div> <div class="line"> <span class="keyword">const</span> stdair::ProgressStatusSet lFirstPS =</div> <div class="line"> sevmgrService.popEvent (lFirstEventStruct);</div> <div class="line"> </div> <div class="line"> <span class="comment">// Extract the corresponding date</span></div> <div class="line"> <span class="keyword">const</span> stdair::DateTime_T& lFirstEventDateTime =</div> <div class="line"> lFirstEventStruct.getEventTime ();</div> <div class="line"> <span class="keyword">const</span> stdair::Date_T& lFirstRequestDate =</div> <div class="line"> lFirstEventDateTime.date();</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> stdair::Date_T lExpectedDate (2010, boost::gregorian::Jan, 21);</div> <div class="line"> BOOST_REQUIRE_MESSAGE (lFirstRequestDate == lExpectedDate,</div> <div class="line"> <span class="stringliteral">"Date of the first event popped from the queue: "</span></div> <div class="line"> << lFirstRequestDate << <span class="stringliteral">". Should be: "</span></div> <div class="line"> << lExpectedDate << <span class="stringliteral">" which is earlier in time."</span>);</div> <div class="line"> </div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Reset the queue"</span>);</div> <div class="line"> sevmgrService.reset();</div> <div class="line"></div> <div class="line"> BOOST_REQUIRE_MESSAGE (sevmgrService.isQueueDone() == <span class="keyword">true</span>,</div> <div class="line"> <span class="stringliteral">"The event queue has been reset: it should be empty "</span></div> <div class="line"> << <span class="stringliteral">"at this step."</span>);</div> <div class="line"></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Re-added the events into the queue one more time"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Add again the four events into the queue thanks to </span></div> <div class="line"> <span class="comment">// sevmgrService.buildSampleQueue(). </span></div> <div class="line"> <span class="comment">// Dates of the break points: 21-JAN-2010 and 14-MAY-2011.</span></div> <div class="line"> <span class="comment">// Dates of the booking requests: 22-JAN-2010 and 15-MAY-2011.</span></div> <div class="line"> sevmgrService.buildSampleQueue ();</div> <div class="line"></div> <div class="line"> stdair::EventStruct lBreakPointStruct;</div> <div class="line"> sevmgrService.run(lBreakPointStruct);</div> <div class="line"> stdair::EventType::EN_EventType lBreakPointType =</div> <div class="line"> lBreakPointStruct.getEventType();</div> <div class="line"></div> <div class="line"> BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,</div> <div class="line"> <span class="stringliteral">"The last event poppped from the queue should be a "</span></div> <div class="line"> << <span class="stringliteral">"break point."</span>);</div> <div class="line"></div> <div class="line"> sevmgrService.run(lBreakPointStruct);</div> <div class="line"> lBreakPointType = lBreakPointStruct.getEventType();</div> <div class="line"> </div> <div class="line"> BOOST_REQUIRE_MESSAGE (lBreakPointType == stdair::EventType::BRK_PT,</div> <div class="line"> <span class="stringliteral">"The last event poppped from the queue should be a "</span></div> <div class="line"> << <span class="stringliteral">"break point."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Extract the corresponding date</span></div> <div class="line"> <span class="keyword">const</span> stdair::DateTime_T& lBPDateTime =</div> <div class="line"> lBreakPointStruct.getEventTime ();</div> <div class="line"> <span class="keyword">const</span> stdair::Date_T& lBPDate =</div> <div class="line"> lBPDateTime.date();</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> stdair::Date_T lExpectedBPDate (2011, boost::gregorian::May, 14);</div> <div class="line"> BOOST_REQUIRE_MESSAGE (lBPDate == lExpectedBPDate,</div> <div class="line"> <span class="stringliteral">"Date of the second break point popped from the queue: "</span></div> <div class="line"> << lBPDate << <span class="stringliteral">". Should be: "</span></div> <div class="line"> << lExpectedBPDate << <span class="stringliteral">"."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"End of the simulation"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Close the log file</span></div> <div class="line"> logOutputFile.close();</div> <div class="line">}</div> <div class="line"></div> <div class="line"><span class="comment">// End the test suite</span></div> <div class="line">BOOST_AUTO_TEST_SUITE_END()</div> <div class="line"></div> <div class="line"><span class="comment">/*!</span></div> </div><!-- fragment --> </div></div><!-- contents --> </div><!-- doc-content --> <li class="footer">Generated on Wed May 22 2013 21:15:38 for SEvMgr by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li> <li class="footer"> <a href="http://sourceforge.net/projects/sevmgr"><img class="footer" src="http://sflogo.sourceforge.net/sflogo.php?group_id=537815&type=12&format=.png" alt="SourceForge Logo"></a> </li> </ul> </div> </body> </html>