$treeview $search $mathjax
00001 00005 // ////////////////////////////////////////////////////////////////////// 00006 // Import section 00007 // ////////////////////////////////////////////////////////////////////// 00008 // STL 00009 #include <sstream> 00010 #include <fstream> 00011 #include <string> 00012 // Boost Unit Test Framework (UTF) 00013 #define BOOST_TEST_DYN_LINK 00014 #define BOOST_TEST_MAIN 00015 #define BOOST_TEST_MODULE YieldTestSuite 00016 #include <boost/test/unit_test.hpp> 00017 // StdAir 00018 #include <stdair/basic/BasLogParams.hpp> 00019 #include <stdair/basic/BasDBParams.hpp> 00020 #include <stdair/basic/BasFileMgr.hpp> 00021 #include <stdair/bom/TravelSolutionStruct.hpp> 00022 #include <stdair/service/Logger.hpp> 00023 // Airrac 00024 #include <airrac/AIRRAC_Service.hpp> 00025 #include <airrac/config/airrac-paths.hpp> 00026 00027 namespace boost_utf = boost::unit_test; 00028 00029 // (Boost) Unit Test XML Report 00030 std::ofstream utfReportStream ("YieldTestSuite_utfresults.xml"); 00031 00035 struct UnitTestConfig { 00037 UnitTestConfig() { 00038 boost_utf::unit_test_log.set_stream (utfReportStream); 00039 boost_utf::unit_test_log.set_format (boost_utf::XML); 00040 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units); 00041 //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests); 00042 } 00043 00045 ~UnitTestConfig() { 00046 } 00047 }; 00048 00049 // ////////////////////////////////////////////////////////////////////// 00050 00054 void testYieldQuoterHelper (const unsigned short iTestFlag, 00055 const stdair::Filename_T iYieldInputFilename, 00056 const bool isBuiltin) { 00057 00058 // Output log File 00059 std::ostringstream oStr; 00060 oStr << "FQTTestSuite_" << iTestFlag << ".log"; 00061 const stdair::Filename_T lLogFilename (oStr.str()); 00062 00063 // Set the log parameters 00064 std::ofstream logOutputFile; 00065 // Open and clean the log outputfile 00066 logOutputFile.open (lLogFilename.c_str()); 00067 logOutputFile.clear(); 00068 00069 // Initialise the AirRAC service object 00070 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, 00071 logOutputFile); 00072 00073 // Initialise the AirRAC service object 00074 AIRRAC::AIRRAC_Service airracService (lLogParams); 00075 00076 // Build a sample list of travel solutions 00077 stdair::TravelSolutionList_T lTravelSolutionList; 00078 airracService.buildSampleTravelSolutions (lTravelSolutionList); 00079 00080 // Check whether or not a (CSV) input file should be read 00081 if (isBuiltin == true) { 00082 00083 // Build the default sample BOM tree (filled with yields) for AirRAC 00084 airracService.buildSampleBom(); 00085 00086 } else { 00087 00088 // Build the BOM tree from parsing the yield input file 00089 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename); 00090 airracService.parseAndLoad (lYieldFilePath); 00091 } 00092 00093 // Calculate the yields for the given travel solution 00094 airracService.calculateYields (lTravelSolutionList); 00095 00096 // Close the log file 00097 logOutputFile.close(); 00098 00099 } 00100 00101 00102 // /////////////// Main: Unit Test Suite ////////////// 00103 00104 // Set the UTF configuration (re-direct the output to a specific file) 00105 BOOST_GLOBAL_FIXTURE (UnitTestConfig); 00106 00107 // Start the test suite 00108 BOOST_AUTO_TEST_SUITE (master_test_suite) 00109 00110 00113 BOOST_AUTO_TEST_CASE (airrac_simple_yield) { 00114 00115 // Input file name 00116 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstore01.csv"); 00117 00118 // State whether the BOM tree should be built-in or parsed from an input file 00119 const bool isBuiltin = false; 00120 00121 // Try to yieldQuote the sample default list of travel solutions 00122 BOOST_CHECK_NO_THROW (testYieldQuoterHelper (0, lYieldInputFilename, isBuiltin)); 00123 00124 } 00125 00130 BOOST_AUTO_TEST_CASE (airrac_error_parsing_input_file) { 00131 00132 // Input file name 00133 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/yieldstoreError01.csv"); 00134 00135 // State whether the BOM tree should be built-in or parsed from an input file 00136 const bool isBuiltin = false; 00137 00138 // Try to yield quote the sample default list of travel solutions 00139 BOOST_CHECK_THROW (testYieldQuoterHelper (1, lYieldInputFilename, isBuiltin), 00140 AIRRAC::YieldFileParsingFailedException); 00141 } 00142 00147 BOOST_AUTO_TEST_CASE (airrac_error_missing_input_file) { 00148 00149 // Input file name 00150 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv"); 00151 00152 // State whether the BOM tree should be built-in or parsed from an input file 00153 const bool isBuiltin = false; 00154 00155 // Try to yield quote the sample default list of travel solutions 00156 BOOST_CHECK_THROW (testYieldQuoterHelper (2, lYieldInputFilename, isBuiltin), 00157 AIRRAC::YieldInputFileNotFoundException); 00158 } 00159 00163 BOOST_AUTO_TEST_CASE (airrac_simple_yield_built_in) { 00164 00165 // State whether the BOM tree should be built-in or parsed from an input file 00166 const bool isBuiltin = true; 00167 00168 // Try to yield quote the sample default list of travel solutions 00169 BOOST_CHECK_NO_THROW (testYieldQuoterHelper (3, " ", isBuiltin)); 00170 00171 } 00172 00173 // End the test suite 00174 BOOST_AUTO_TEST_SUITE_END() 00175 00176