<!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 Extend StdAir BOM</title> <link rel="shortcut icon" href="favicon.ico"> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="stdair.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-24867310-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://stdair.sourceforge.net"><img height="45px" alt="StdAir Logo" src="stdair_logo.png"></a>  <span id="projectnumber">1.00.1</span> </div> <div id="projectbrief">C++ Standard Airline IT Object Library</div> </td> <!-- begin SOURCEFORGE_CUSTOM--> <td> <div id="sflogo"><a href="http://stdair.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('a00025.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>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(11)"><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 Extend StdAir BOM </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 MPL</span></div> <div class="line"><span class="preprocessor">#include <boost/mpl/push_back.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/mpl/vector.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/mpl/at.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/mpl/assert.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/type_traits/is_same.hpp></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 StdAirTest</span></div> <div class="line"><span class="preprocessor"></span><span class="preprocessor">#if BOOST_VERSION >= 103900</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">#else // BOOST_VERSION >= 103900</span></div> <div class="line"><span class="preprocessor"></span><span class="preprocessor">#include <boost/test/test_tools.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/results_reporter.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/unit_test_suite.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/output_test_stream.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/unit_test_log.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/framework.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/test/detail/unit_test_parameters.hpp></span></div> <div class="line"><span class="preprocessor">#endif // BOOST_VERSION >= 103900</span></div> <div class="line"><span class="preprocessor"></span><span class="comment">// Boost Serialisation</span></div> <div class="line"><span class="preprocessor">#include <boost/archive/text_oarchive.hpp></span></div> <div class="line"><span class="preprocessor">#include <boost/archive/text_iarchive.hpp></span></div> <div class="line"><span class="comment">// StdAir</span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00513.html">stdair/stdair_inventory_types.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00499.html">stdair/service/Logger.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00518.html">stdair/STDAIR_Service.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00241.html">stdair/basic/float_utils.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00293.html">stdair/bom/BomDisplay.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00311.html">stdair/bom/BomRoot.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00307.html">stdair/bom/BomManager.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00486.html">stdair/factory/FacBom.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00488.html">stdair/factory/FacBomManager.hpp</a>></span></div> <div class="line"><span class="comment">// StdAir Test Suite</span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00528.html">test/stdair/StdairTestLib.hpp</a>></span></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="a00526.html">test/stdair/MPInventory.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="preprocessor">#if BOOST_VERSION >= 103900</span></div> <div class="line"><span class="preprocessor"></span></div> <div class="line"><span class="comment">// (Boost) Unit Test XML Report</span></div> <div class="line">std::ofstream utfReportStream (<span class="stringliteral">"StandardAirlineITTestSuite_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"></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 (float_comparison_test) {</div> <div class="line"> <span class="keywordtype">float</span> a = 0.2f;</div> <div class="line"> a = 5*a;</div> <div class="line"> <span class="keyword">const</span> <span class="keywordtype">float</span> b = 1.0f;</div> <div class="line"></div> <div class="line"> <span class="comment">// Test the Boost way</span></div> <div class="line"> BOOST_CHECK_MESSAGE (a == b, <span class="stringliteral">"The two floats ("</span> << a << <span class="stringliteral">" and "</span> << b</div> <div class="line"> << <span class="stringliteral">") should be equal, but are not"</span>);</div> <div class="line"> BOOST_CHECK_CLOSE (a, b, 0.0001);</div> <div class="line"></div> <div class="line"> <span class="comment">// Test the Google way</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00107.html">FloatingPoint<float></a> lhs (a), rhs (b);</div> <div class="line"> BOOST_CHECK_MESSAGE (lhs.AlmostEquals (rhs),</div> <div class="line"> <span class="stringliteral">"The two floats ("</span> << a << <span class="stringliteral">" and "</span> << b</div> <div class="line"> << <span class="stringliteral">") should be equal, but are not"</span>);</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (mpl_structure_test) {</div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00535.html#a2333a1276804180fe52c77f099005054">stdair::ClassCode_T</a> lBookingClassCodeA (<span class="stringliteral">"A"</span>);</div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00051.html">stdair_test::BookingClass</a> lA (lBookingClassCodeA);</div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00059.html">stdair_test::Cabin</a> lCabin (lA);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_EQUAL (lCabin.toString(), lBookingClassCodeA);</div> <div class="line"> BOOST_CHECK_MESSAGE (lCabin.toString() == lBookingClassCodeA,</div> <div class="line"> <span class="stringliteral">"The cabin key, '"</span> << lCabin.toString()</div> <div class="line"> << <span class="stringliteral">"' is not equal to '"</span> << lBookingClassCodeA << <span class="stringliteral">"'"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// MPL</span></div> <div class="line"> <span class="keyword">typedef</span> boost::mpl::vector<stdair_test::BookingClass> MPL_BookingClass;</div> <div class="line"> <span class="keyword">typedef</span> boost::mpl::push_back<MPL_BookingClass,</div> <div class="line"> <a class="code" href="a00059.html">stdair_test::Cabin</a>>::type types;</div> <div class="line"> </div> <div class="line"> <span class="keywordflow">if</span> (boost::is_same<<a class="code" href="a00051.html">stdair_test::BookingClass</a>,</div> <div class="line"> <a class="code" href="a00051.html">stdair_test::Cabin::child</a>>::value == <span class="keyword">false</span>) {</div> <div class="line"> BOOST_ERROR (<span class="stringliteral">"The two types mut be equal, but are not"</span>);</div> <div class="line"> }</div> <div class="line"> </div> <div class="line"> <span class="keywordflow">if</span> (boost::is_same<boost::mpl::at_c<types, 1>::type,</div> <div class="line"> <a class="code" href="a00059.html">stdair_test::Cabin</a>>::value == <span class="keyword">false</span>) {</div> <div class="line"> BOOST_ERROR (<span class="stringliteral">"The type must be stdair_test::Cabin, but is not"</span>);</div> <div class="line"> }</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (stdair_service_initialisation_test) {</div> <div class="line"> <span class="comment">// Output log File</span></div> <div class="line"> <span class="keyword">const</span> std::string lLogFilename (<span class="stringliteral">"StandardAirlineITTestSuite_init.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"> </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 stdair BOM</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00036.html" title="Structure holding parameters for logging.">stdair::BasLogParams</a> lLogParams (<a class="code" href="a00536.html#a0e942800c20ab8c1dc913408f555112daf8480a95ba3662dd03cd956546bf951b">stdair::LOG::DEBUG</a>, logOutputFile);</div> <div class="line"> <a class="code" href="a00179.html" title="Interface for the STDAIR Services.">stdair::STDAIR_Service</a> stdairService (lLogParams);</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve (a reference on) the top of the persistent BOM tree</span></div> <div class="line"> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lPersistentBomRoot = stdairService.getPersistentBomRoot();</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the BomRoot key, and compare it to the expected one</span></div> <div class="line"> <span class="keyword">const</span> std::string& lBomRootKeyStr = lPersistentBomRoot.<a class="code" href="a00049.html#a2e5ffe8887b014acb18c858e44c6d21c">describeKey</a>();</div> <div class="line"> <span class="keyword">const</span> std::string lBomRootString (<span class="stringliteral">" -- ROOT -- "</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"The BOM root key is '"</span> << lBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"'. It should be equal to '"</span> << lBomRootString << <span class="stringliteral">"'"</span>);</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);</div> <div class="line"> BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,</div> <div class="line"> <span class="stringliteral">"The BOM root key, '"</span> << lBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"', should be equal to '"</span> << lBomRootString</div> <div class="line"> << <span class="stringliteral">"', but is not."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Build a sample BOM tree</span></div> <div class="line"> stdairService.buildSampleBom();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG: Display the whole BOM tree</span></div> <div class="line"> <span class="keyword">const</span> std::string& lCSVDump = stdairService.csvDisplay ();</div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (lCSVDump);</div> <div class="line"></div> <div class="line"> <span class="comment">// Close the Log outputFile</span></div> <div class="line"> logOutputFile.close();</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {</div> <div class="line"> <span class="comment">// Step 0.0: initialisation</span></div> <div class="line"> <span class="comment">// Create the root of a Bom tree (i.e., a BomRoot object)</span></div> <div class="line"> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lBomRoot =</div> <div class="line"> <a class="code" href="a00089.html#af10a87fcdeb32af553c6994ba724016a">stdair::FacBom<stdair::BomRoot>::instance</a>().<a class="code" href="a00089.html#af06dd266824e0ec2ea9a15994f56fd75">create</a>();</div> <div class="line"> </div> <div class="line"> <span class="comment">// Step 0.1: Inventory level</span></div> <div class="line"> <span class="comment">// Create an Inventory (BA)</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00535.html#ac0ab9f765621de3140cc27d6472f5581">stdair::AirlineCode_T</a> lBAAirlineCode (<span class="stringliteral">"BA"</span>);</div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00113.html" title="Key of a given inventory, made of the airline code.">stdair::InventoryKey</a> lBAKey (lBAAirlineCode);</div> <div class="line"> myprovider::Inventory& lBAInv =</div> <div class="line"> <a class="code" href="a00089.html#af10a87fcdeb32af553c6994ba724016a">stdair::FacBom<myprovider::Inventory>::instance</a>().<a class="code" href="a00089.html#af06dd266824e0ec2ea9a15994f56fd75">create</a> (lBAKey);</div> <div class="line"> <a class="code" href="a00090.html#a732e7152a1bcb27b2b7e88e38f9fa535">stdair::FacBomManager::addToList</a> (lBomRoot, lBAInv);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_EQUAL (lBAInv.describeKey(), lBAAirlineCode);</div> <div class="line"> BOOST_CHECK_MESSAGE (lBAInv.describeKey() == lBAAirlineCode,</div> <div class="line"> <span class="stringliteral">"The inventory key, '"</span> << lBAInv.describeKey()</div> <div class="line"> << <span class="stringliteral">"', should be equal to '"</span> << lBAAirlineCode</div> <div class="line"> << <span class="stringliteral">"', but is not"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Create an Inventory for AF</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00535.html#ac0ab9f765621de3140cc27d6472f5581">stdair::AirlineCode_T</a> lAFAirlineCode (<span class="stringliteral">"AF"</span>);</div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00113.html" title="Key of a given inventory, made of the airline code.">stdair::InventoryKey</a> lAFKey (lAFAirlineCode);</div> <div class="line"> myprovider::Inventory& lAFInv =</div> <div class="line"> <a class="code" href="a00089.html#af10a87fcdeb32af553c6994ba724016a">stdair::FacBom<myprovider::Inventory>::instance</a>().<a class="code" href="a00089.html#af06dd266824e0ec2ea9a15994f56fd75">create</a> (lAFKey);</div> <div class="line"> <a class="code" href="a00090.html#a732e7152a1bcb27b2b7e88e38f9fa535">stdair::FacBomManager::addToList</a> (lBomRoot, lAFInv);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_EQUAL (lAFInv.describeKey(), lAFAirlineCode);</div> <div class="line"> BOOST_CHECK_MESSAGE (lAFInv.describeKey() == lAFAirlineCode,</div> <div class="line"> <span class="stringliteral">"The inventory key, '"</span> << lAFInv.describeKey()</div> <div class="line"> << <span class="stringliteral">"', should be equal to '"</span> << lAFAirlineCode</div> <div class="line"> << <span class="stringliteral">"', but is not"</span>);</div> <div class="line"> </div> <div class="line"> <span class="comment">// Browse the inventories</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00535.html#aa2443c204cfcb7ce31e90308b9a63d71">myprovider::InventoryList_T</a>& lInventoryList =</div> <div class="line"> stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);</div> <div class="line"> <span class="keyword">const</span> std::string lInventoryKeyArray[2] = {lBAAirlineCode, lAFAirlineCode};</div> <div class="line"> <span class="keywordtype">short</span> idx = 0;</div> <div class="line"> <span class="keywordflow">for</span> (myprovider::InventoryList_T::const_iterator itInv =</div> <div class="line"> lInventoryList.begin(); itInv != lInventoryList.end();</div> <div class="line"> ++itInv, ++idx) {</div> <div class="line"> <span class="keyword">const</span> myprovider::Inventory* lInv_ptr = *itInv;</div> <div class="line"> BOOST_REQUIRE (lInv_ptr != NULL);</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());</div> <div class="line"> BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),</div> <div class="line"> <span class="stringliteral">"They inventory key, '"</span> << lInventoryKeyArray[idx]</div> <div class="line"> << <span class="stringliteral">"', does not match that of the Inventory object: '"</span></div> <div class="line"> << lInv_ptr->describeKey() << <span class="stringliteral">"'"</span>);</div> <div class="line"> }</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (bom_structure_serialisation_test) {</div> <div class="line"></div> <div class="line"> <span class="comment">// Backup (thanks to Boost.Serialisation) file</span></div> <div class="line"> <span class="keyword">const</span> std::string lBackupFilename = <span class="stringliteral">"StandardAirlineITTestSuite_serial.txt"</span>;</div> <div class="line"></div> <div class="line"> <span class="comment">// Output log File</span></div> <div class="line"> <span class="keyword">const</span> std::string lLogFilename (<span class="stringliteral">"StandardAirlineITTestSuite_serial.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"> </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 stdair BOM</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00036.html" title="Structure holding parameters for logging.">stdair::BasLogParams</a> lLogParams (<a class="code" href="a00536.html#a0e942800c20ab8c1dc913408f555112daf8480a95ba3662dd03cd956546bf951b">stdair::LOG::DEBUG</a>, logOutputFile);</div> <div class="line"> <a class="code" href="a00179.html" title="Interface for the STDAIR Services.">stdair::STDAIR_Service</a> stdairService (lLogParams);</div> <div class="line"></div> <div class="line"> <span class="comment">// Build a sample BOM tree</span></div> <div class="line"> stdairService.buildSampleBom();</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve (a reference on) the top of the persistent BOM tree</span></div> <div class="line"> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lPersistentBomRoot = stdairService.getPersistentBomRoot();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG: Display the whole BOM tree</span></div> <div class="line"> <span class="keyword">const</span> std::string& lCSVDump = stdairService.csvDisplay ();</div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (lCSVDump);</div> <div class="line"></div> <div class="line"> <span class="comment">// Clone the persistent BOM</span></div> <div class="line"> stdairService.clonePersistentBom ();</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the BomRoot key, and compare it to the expected one</span></div> <div class="line"> <span class="keyword">const</span> std::string lBAInvKeyStr (<span class="stringliteral">"BA"</span>);</div> <div class="line"> <a class="code" href="a00112.html" title="Class representing the actual attributes for an airline inventory.">stdair::Inventory</a>* lBAInv_ptr = </div> <div class="line"> lPersistentBomRoot.<a class="code" href="a00049.html#a73c84237e4a7308bd009bc436d498a18">getInventory</a> (lBAInvKeyStr);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"There should be an Inventory object corresponding to the '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"' key."</span>);</div> <div class="line"></div> <div class="line"> BOOST_REQUIRE_MESSAGE (lBAInv_ptr != NULL,</div> <div class="line"> <span class="stringliteral">"An Inventory object should exist with the key, '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"'."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// create and open a character archive for output</span></div> <div class="line"> std::ofstream ofs (lBackupFilename.c_str());</div> <div class="line"></div> <div class="line"> <span class="comment">// save data to archive</span></div> <div class="line"> {</div> <div class="line"> boost::archive::text_oarchive oa (ofs);</div> <div class="line"> <span class="comment">// write class instance to archive</span></div> <div class="line"> oa << lPersistentBomRoot;</div> <div class="line"> <span class="comment">// archive and stream closed when destructors are called</span></div> <div class="line"> }</div> <div class="line"></div> <div class="line"> <span class="comment">// ... some time later restore the class instance to its orginal state</span></div> <div class="line"> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lRestoredBomRoot =</div> <div class="line"> <a class="code" href="a00089.html#af10a87fcdeb32af553c6994ba724016a">stdair::FacBom<stdair::BomRoot>::instance</a>().<a class="code" href="a00089.html#af06dd266824e0ec2ea9a15994f56fd75">create</a>();</div> <div class="line"> {</div> <div class="line"> <span class="comment">// create and open an archive for input</span></div> <div class="line"> std::ifstream ifs (lBackupFilename.c_str());</div> <div class="line"> boost::archive::text_iarchive ia(ifs);</div> <div class="line"> <span class="comment">// read class state from archive</span></div> <div class="line"> ia >> lRestoredBomRoot;</div> <div class="line"> <span class="comment">// archive and stream closed when destructors are called</span></div> <div class="line"> }</div> <div class="line"> </div> <div class="line"> <span class="comment">// DEBUG: Display the whole restored BOM tree</span></div> <div class="line"> <span class="keyword">const</span> std::string& lRestoredCSVDump = </div> <div class="line"> stdairService.csvDisplay(lRestoredBomRoot);</div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (lRestoredCSVDump);</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the BomRoot key, and compare it to the expected one</span></div> <div class="line"> <span class="keyword">const</span> std::string& lBomRootKeyStr = lRestoredBomRoot.<a class="code" href="a00049.html#a2e5ffe8887b014acb18c858e44c6d21c">describeKey</a>();</div> <div class="line"> <span class="keyword">const</span> std::string lBomRootString (<span class="stringliteral">" -- ROOT -- "</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"The BOM root key is '"</span> << lBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"'. It should be equal to '"</span> << lBomRootString << <span class="stringliteral">"'"</span>);</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);</div> <div class="line"> BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,</div> <div class="line"> <span class="stringliteral">"The BOM root key, '"</span> << lBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"', should be equal to '"</span> << lBomRootString</div> <div class="line"> << <span class="stringliteral">"', but is not."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the Inventory</span></div> <div class="line"> <a class="code" href="a00112.html" title="Class representing the actual attributes for an airline inventory.">stdair::Inventory</a>* lRestoredBAInv_ptr =</div> <div class="line"> lRestoredBomRoot.<a class="code" href="a00049.html#a73c84237e4a7308bd009bc436d498a18">getInventory</a> (lBAInvKeyStr);</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"There should be an Inventory object corresponding to the '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"' key in the restored BOM root."</span>);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,</div> <div class="line"> <span class="stringliteral">"An Inventory object should exist with the key, '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"' in the restored BOM root."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Close the Log outputFile</span></div> <div class="line"> logOutputFile.close();</div> <div class="line">}</div> <div class="line"></div> <div class="line">BOOST_AUTO_TEST_CASE (bom_structure_clone_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> std::string lLogFilename (<span class="stringliteral">"StandardAirlineITTestSuite_clone.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"> </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 stdair BOM</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00036.html" title="Structure holding parameters for logging.">stdair::BasLogParams</a> lLogParams (<a class="code" href="a00536.html#a0e942800c20ab8c1dc913408f555112daf8480a95ba3662dd03cd956546bf951b">stdair::LOG::DEBUG</a>, logOutputFile);</div> <div class="line"> <a class="code" href="a00179.html" title="Interface for the STDAIR Services.">stdair::STDAIR_Service</a> stdairService (lLogParams);</div> <div class="line"></div> <div class="line"> <span class="comment">// Build a sample BOM tree</span></div> <div class="line"> stdairService.buildSampleBom();</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve (a constant reference on) the top of the persistent BOM tree</span></div> <div class="line"> <span class="keyword">const</span> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lPersistentBomRoot =</div> <div class="line"> stdairService.getPersistentBomRoot(); </div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG: Display the whole persistent BOM tree</span></div> <div class="line"> <span class="keyword">const</span> std::string& lCSVDump = stdairService.csvDisplay (); </div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"Display the persistent BOM tree."</span>);</div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (lCSVDump); </div> <div class="line"></div> <div class="line"> <span class="comment">// Clone the persistent BOM</span></div> <div class="line"> stdairService.clonePersistentBom (); </div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve (a reference on) the top of the clone BOM tree</span></div> <div class="line"> <a class="code" href="a00049.html" title="Class representing the actual attributes for the Bom root.">stdair::BomRoot</a>& lCloneBomRoot = stdairService.getBomRoot(); </div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG: Display the clone BOM tree after the clone process.</span></div> <div class="line"> <span class="keyword">const</span> std::string& lAfterCloneCSVDump = </div> <div class="line"> stdairService.csvDisplay(lCloneBomRoot); </div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"Display the clone BOM tree after the clone process."</span>);</div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (lAfterCloneCSVDump);</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the clone BomRoot key, and compare it to the persistent BomRoot </span></div> <div class="line"> <span class="comment">// key.</span></div> <div class="line"> <span class="keyword">const</span> std::string& lCloneBomRootKeyStr = lCloneBomRoot.<a class="code" href="a00049.html#a2e5ffe8887b014acb18c858e44c6d21c">describeKey</a>();</div> <div class="line"> <span class="keyword">const</span> std::string& lPersistentBomRootKeyStr = </div> <div class="line"> lPersistentBomRoot.<a class="code" href="a00049.html#a2e5ffe8887b014acb18c858e44c6d21c">describeKey</a>();</div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"The clone BOM root key is '"</span> << lCloneBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"'. It should be equal to '"</span> </div> <div class="line"> << lPersistentBomRootKeyStr << <span class="stringliteral">"'"</span>);</div> <div class="line"> </div> <div class="line"> BOOST_CHECK_EQUAL (lCloneBomRootKeyStr, lPersistentBomRootKeyStr);</div> <div class="line"> BOOST_CHECK_MESSAGE (lCloneBomRootKeyStr == lPersistentBomRootKeyStr,</div> <div class="line"> <span class="stringliteral">"The clone BOM root key, '"</span> << lCloneBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"', should be equal to '"</span> << lPersistentBomRootKeyStr</div> <div class="line"> << <span class="stringliteral">"', but is not."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Retrieve the BA inventory in the clone BOM root</span></div> <div class="line"> <span class="keyword">const</span> std::string lBAInvKeyStr (<span class="stringliteral">"BA"</span>);</div> <div class="line"> <a class="code" href="a00112.html" title="Class representing the actual attributes for an airline inventory.">stdair::Inventory</a>* lCloneBAInv_ptr =</div> <div class="line"> lCloneBomRoot.<a class="code" href="a00049.html#a73c84237e4a7308bd009bc436d498a18">getInventory</a> (lBAInvKeyStr); </div> <div class="line"></div> <div class="line"> <span class="comment">// DEBUG</span></div> <div class="line"> <a class="code" href="a00499.html#a24f87ac1961418818b267ed4d02ff487">STDAIR_LOG_DEBUG</a> (<span class="stringliteral">"There should be an Inventory object corresponding to the '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"' key in the clone BOM root."</span>);</div> <div class="line"></div> <div class="line"> BOOST_CHECK_MESSAGE (lCloneBAInv_ptr != NULL,</div> <div class="line"> <span class="stringliteral">"An Inventory object should exist with the key, '"</span></div> <div class="line"> << lBAInvKeyStr << <span class="stringliteral">"' in the clone BOM root."</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Close the Log outputFile</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="preprocessor">#else // BOOST_VERSION >= 103900</span></div> <div class="line"><span class="preprocessor"></span>boost_utf::test_suite* init_unit_test_suite (<span class="keywordtype">int</span>, <span class="keywordtype">char</span>* []) {</div> <div class="line"> boost_utf::test_suite* test = BOOST_TEST_SUITE (<span class="stringliteral">"Unit test example 1"</span>);</div> <div class="line"> <span class="keywordflow">return</span> test;</div> <div class="line">}</div> <div class="line"><span class="preprocessor">#endif // BOOST_VERSION >= 103900</span></div> <div class="line"><span class="preprocessor"></span></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 10:52:00 for StdAir 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/stdair"><img class="footer" src="http://sflogo.sourceforge.net/sflogo.php?group_id=267760&type=12&format=.png" alt="SourceForge Logo"></a> </li> </ul> </div> </body> </html>