<!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 Test the Travel CCM Project</title> <link rel="shortcut icon" href="favicon.ico"> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="travelccm.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-25250378-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://travel-ccm.sourceforge.net"><img height="45px" alt="TravelCCM Logo" src="travelccm_logo.png"></a>  <span id="projectnumber">1.00.1</span> </div> <div id="projectbrief">C++ Travel Customer Choice Model Library</div> </td> <!-- begin SOURCEFORGE_CUSTOM--> <td> <div id="sflogo"><a href="http://travel-ccm.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('TravelChoiceTestSuite_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 Test the Travel CCM Project </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 <string></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 TravelCCMTest</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="comment">// StdAir</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/PassengerChoiceModel.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/bom/TravelSolutionStruct.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/bom/BookingRequestStruct.hpp></span></div> <div class="line"><span class="preprocessor">#include <stdair/service/Logger.hpp></span></div> <div class="line"><span class="comment">// TravelCCM</span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="TRAVELCCM__Service_8hpp.html">travelccm/TRAVELCCM_Service.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="travelccm-paths_8hpp.html">travelccm/config/travelccm-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">"TravelChoiceTestSuite_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"> ~UnitTestConfig() {</div> <div class="line"> }</div> <div class="line">};</div> <div class="line"></div> <div class="line"><span class="comment">// //////////////////////////////////////////////////////////////////////</span></div> <div class="line"><span class="comment"></span><span class="keywordtype">void</span> testTravelCCMHelper (<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> iTestFlag,</div> <div class="line"> <span class="keyword">const</span> stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,</div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iExpectedPrice) {</div> <div class="line"></div> <div class="line"> <span class="comment">// Output log File</span></div> <div class="line"> std::ostringstream oStr;</div> <div class="line"> oStr << <span class="stringliteral">"TravelChoiceTestSuite_"</span> << iTestFlag << <span class="stringliteral">".log"</span>;</div> <div class="line"> <span class="keyword">const</span> stdair::Filename_T lLogFilename (oStr.str());</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 service context</span></div> <div class="line"> <span class="keyword">const</span> stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);</div> <div class="line"> </div> <div class="line"> <span class="comment">// Build the BOM tree</span></div> <div class="line"> <a class="code" href="classTRAVELCCM_1_1TRAVELCCM__Service.html">TRAVELCCM::TRAVELCCM_Service</a> travelccmService (lLogParams);</div> <div class="line"> travelccmService.buildSampleBom ();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Welcome to TravelCCM"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Build a list of travel solutions</span></div> <div class="line"> <span class="keyword">const</span> stdair::BookingRequestStruct& lBookingRequest =</div> <div class="line"> travelccmService.buildSampleBookingRequest();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> STDAIR_LOG_DEBUG (<span class="stringliteral">"Booking request: "</span> << lBookingRequest.display());</div> <div class="line"></div> <div class="line"> <span class="comment">// Build the sample BOM tree</span></div> <div class="line"> stdair::TravelSolutionList_T lTSList;</div> <div class="line"> travelccmService.buildSampleTravelSolutions (lTSList);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG: Display the list of travel solutions</span></div> <div class="line"> <span class="keyword">const</span> std::string& lCSVDump = travelccmService.csvDisplay (lTSList);</div> <div class="line"> STDAIR_LOG_DEBUG (lCSVDump);</div> <div class="line"> </div> <div class="line"> <span class="comment">// Choose a travel solution</span></div> <div class="line"> <span class="keyword">const</span> stdair::TravelSolutionStruct* lTS_ptr =</div> <div class="line"> travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);</div> <div class="line"></div> <div class="line"> <span class="comment">// Check that a solution has been found</span></div> <div class="line"> BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,</div> <div class="line"> <span class="stringliteral">"No travel solution can be found for "</span></div> <div class="line"> << lBookingRequest.display()</div> <div class="line"> << <span class="stringliteral">" within the following list of travel solutions. "</span></div> <div class="line"> << lCSVDump);</div> <div class="line"></div> <div class="line"> STDAIR_LOG_DEBUG (lTS_ptr->describe());</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the chosen fare option</span></div> <div class="line"> stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> std::ostringstream oMessageExpectedPrice;</div> <div class="line"> oMessageExpectedPrice << <span class="stringliteral">"The price chosen by the passenger is: "</span></div> <div class="line"> << lFareOption.getFare() << <span class="stringliteral">" Euros. It is expected to be "</span></div> <div class="line"> << iExpectedPrice << <span class="stringliteral">" Euros."</span>;</div> <div class="line"> STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());</div> <div class="line"></div> <div class="line"> <span class="comment">// Check that the price corresponds to the expected one</span></div> <div class="line"> BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)</div> <div class="line"> == iExpectedPrice, oMessageExpectedPrice.str());</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"></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 (simple_hard_restriction_model_test) {</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> lExpectedPrice = 1000;</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_NO_THROW (testTravelCCMHelper</div> <div class="line"> (0,</div> <div class="line"> stdair::PassengerChoiceModel::HARD_RESTRICTION,</div> <div class="line"> lExpectedPrice));</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> lExpectedPrice = 900;</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_NO_THROW (testTravelCCMHelper</div> <div class="line"> (1,</div> <div class="line"> stdair::PassengerChoiceModel::PRICE_ORIENTED,</div> <div class="line"> lExpectedPrice));</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {</div> <div class="line"></div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> lExpectedPrice = 920;</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_NO_THROW (testTravelCCMHelper</div> <div class="line"> (2,</div> <div class="line"> stdair::PassengerChoiceModel::HYBRID,</div> <div class="line"> lExpectedPrice));</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:19:40 for TravelCCM 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/travel-ccm"><img class="footer" src="http://sflogo.sourceforge.net/sflogo.php?group_id=261639&type=12&format=.png" alt="SourceForge Logo"></a> </li> </ul> </div> </body> </html>