SimFQT Logo  0.1.3
C++ Simulated Fare Quote System Library
FQTTestSuite.cpp
Go to the documentation of this file.
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 FQTTestSuite
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/service/Logger.hpp>
00022 #include <stdair/bom/TravelSolutionStruct.hpp>
00023 #include <stdair/bom/BookingRequestStruct.hpp>
00024 // SimFQT
00025 #include <simfqt/SIMFQT_Service.hpp>
00026 #include <simfqt/config/simfqt-paths.hpp>
00027 
00028 namespace boost_utf = boost::unit_test;
00029 
00033 struct UnitTestConfig {
00035   UnitTestConfig() {
00036     static std::ofstream _test_log ("FQTTestSuite_utfresults.xml");
00037     boost_utf::unit_test_log.set_stream (_test_log);
00038     boost_utf::unit_test_log.set_format (boost_utf::XML);
00039     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00040     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00041   }
00042 
00044   ~UnitTestConfig() {
00045   }
00046 };
00047 
00048 // //////////////////////////////////////////////////////////////////////
00052 void testFareQuoterHelper (const unsigned short iTestFlag,
00053                            const stdair::Filename_T iFareInputFilename,
00054                            const bool isBuiltin) {
00055 
00056   // Output log File
00057   std::ostringstream oStr;
00058   oStr << "FQTTestSuite_" << iTestFlag << ".log";
00059   const stdair::Filename_T lLogFilename (oStr.str());
00060 
00061   // Set the log parameters
00062   std::ofstream logOutputFile;
00063   // Open and clean the log outputfile
00064   logOutputFile.open (lLogFilename.c_str());
00065   logOutputFile.clear();
00066     
00067   // Initialise the SimFQT service object
00068   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
00069                                          logOutputFile);
00070   
00071   // Initialise the Simfqt service object
00072   SIMFQT::SIMFQT_Service simfqtService (lLogParams);
00073 
00074   // Check wether or not a (CSV) input file should be read
00075   if (isBuiltin == true) {
00076 
00077     // Build the default sample BOM tree (filled with fares) for Simfqt
00078     simfqtService.buildSampleBom();
00079 
00080   } else {
00081 
00082     // Build the BOM tree from parsing the fare input file    
00083     SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
00084     simfqtService.parseAndLoad (lFareFilePath);
00085   }
00086 
00087   // Build a sample list of travel solutions and a booking request.
00088   stdair::TravelSolutionList_T lTravelSolutionList;
00089   simfqtService.buildSampleTravelSolutions (lTravelSolutionList);
00090   stdair::BookingRequestStruct lBookingRequest =
00091     simfqtService.buildBookingRequest();
00092 
00093   // Try to fareQuote the sample list of travel solutions
00094   simfqtService.quotePrices (lBookingRequest, lTravelSolutionList);
00095 
00096   // Close the log file
00097   logOutputFile.close();
00098 
00099 }
00100 
00101 // /////////////// Main: Unit Test Suite //////////////
00102 
00103 // Set the UTF configuration (re-direct the output to a specific file)
00104 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00105 
00106 // Start the test suite
00107 BOOST_AUTO_TEST_SUITE (master_test_suite)
00108 
00109 
00112 BOOST_AUTO_TEST_CASE (simfqt_simple_pricing_test) {
00113 
00114   // Input file name
00115   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fare01.csv");
00116 
00117   // State whether the BOM tree should be built-in or parsed from an input file
00118   const bool isBuiltin = false;
00119 
00120   // Try to fareQuote the sample default list of travel solutions
00121   BOOST_CHECK_NO_THROW (testFareQuoterHelper (0, lFareInputFilename, isBuiltin));
00122  
00123 }
00124 
00129 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_01) {
00130 
00131   // Input file name
00132   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError01.csv");
00133 
00134   // State whether the BOM tree should be built-in or parsed from an input file
00135   const bool isBuiltin = false;
00136 
00137   // Try to fareQuote the sample default list of travel solutions
00138   BOOST_CHECK_THROW (testFareQuoterHelper (1, lFareInputFilename, isBuiltin),
00139                      SIMFQT::AirportPairNotFoundException);
00140 }
00141 
00146 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_02) {
00147 
00148   // Input file name
00149   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError02.csv");
00150 
00151   // State whether the BOM tree should be built-in or parsed from an input file
00152   const bool isBuiltin = false;
00153 
00154   // Try to fareQuote the sample default list of travel solutions
00155   BOOST_CHECK_THROW (testFareQuoterHelper (2, lFareInputFilename, isBuiltin),
00156                      SIMFQT::PosOrChannelNotFoundException);
00157 }
00158 
00163 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_03) {
00164 
00165   // Input file name
00166   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError03.csv");
00167 
00168   // State whether the BOM tree should be built-in or parsed from an input file
00169   const bool isBuiltin = false;
00170 
00171   // Try to fareQuote the sample default list of travel solutions
00172   BOOST_CHECK_THROW (testFareQuoterHelper (3, lFareInputFilename, isBuiltin),
00173                      SIMFQT::FlightDateNotFoundException);
00174 }
00175 
00180 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_04) {
00181 
00182   // Input file name
00183   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError04.csv");
00184 
00185   // State whether the BOM tree should be built-in or parsed from an input file
00186   const bool isBuiltin = false;
00187   
00188   // Try to fareQuote the sample default list of travel solutions
00189   BOOST_CHECK_THROW (testFareQuoterHelper (4, lFareInputFilename, isBuiltin),
00190                      SIMFQT::FlightTimeNotFoundException);
00191 }
00192 
00197 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_05) {
00198 
00199   // Input file name
00200   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError05.csv");
00201 
00202   // State whether the BOM tree should be built-in or parsed from an input file
00203   const bool isBuiltin = false;
00204 
00205   // Try to fareQuote the sample default list of travel solutions
00206   BOOST_CHECK_THROW (testFareQuoterHelper (5, lFareInputFilename, isBuiltin),
00207                      SIMFQT::FeaturesNotFoundException);
00208 }
00209 
00214 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_06) {
00215 
00216   // Input file name
00217   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError06.csv");
00218 
00219   // State whether the BOM tree should be built-in or parsed from an input file
00220   const bool isBuiltin = false;
00221     
00222   // Try to fareQuote the sample default list of travel solutions
00223   BOOST_CHECK_THROW (testFareQuoterHelper (6, lFareInputFilename, isBuiltin),
00224                      SIMFQT::AirlineNotFoundException);
00225 }
00226 
00231 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_07) {
00232 
00233   // Input file name
00234   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/fareError07.csv");
00235 
00236   // State whether the BOM tree should be built-in or parsed from an input file
00237   const bool isBuiltin = false;
00238     
00239   // Try to fareQuote the sample default list of travel solutions
00240   BOOST_CHECK_THROW (testFareQuoterHelper (7, lFareInputFilename, isBuiltin),
00241                      SIMFQT::FareFileParsingFailedException);
00242 }
00243 
00248 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_08) {
00249 
00250   // Input file name
00251   const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR "/missingFile.csv");
00252 
00253   // State whether the BOM tree should be built-in or parsed from an input file
00254   const bool isBuiltin = false;
00255     
00256   // Try to fareQuote the sample default list of travel solutions
00257   BOOST_CHECK_THROW (testFareQuoterHelper (8, lFareInputFilename, isBuiltin),
00258                      SIMFQT::FareInputFileNotFoundException);
00259 }
00260 
00265 BOOST_AUTO_TEST_CASE (simfqt_error_pricing_test_09) {
00266 
00267   // Input file name
00268   const stdair::Filename_T lEmptyInputFilename (STDAIR_SAMPLE_DIR "/ ");
00269 
00270   // State whether the BOM tree should be built-in or parsed from an input file
00271   const bool isBuiltin = true;
00272     
00273   // Try to fareQuote the sample default list of travel solutions
00274   BOOST_CHECK_NO_THROW(testFareQuoterHelper (9, lEmptyInputFilename, isBuiltin));
00275 }
00276 
00277 
00278 // End the test suite
00279 BOOST_AUTO_TEST_SUITE_END()
00280 
00281