00001
00005
00006
00007
00008
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012
00013 #include <boost/mpl/push_back.hpp>
00014 #include <boost/mpl/vector.hpp>
00015 #include <boost/mpl/at.hpp>
00016 #include <boost/mpl/assert.hpp>
00017 #include <boost/type_traits/is_same.hpp>
00018
00019 #define BOOST_TEST_DYN_LINK
00020 #define BOOST_TEST_MAIN
00021 #define BOOST_TEST_MODULE StdAirTest
00022 #if BOOST_VERSION >= 103900
00023 #include <boost/test/unit_test.hpp>
00024 #else // BOOST_VERSION >= 103900
00025 #include <boost/test/test_tools.hpp>
00026 #include <boost/test/results_reporter.hpp>
00027 #include <boost/test/unit_test_suite.hpp>
00028 #include <boost/test/output_test_stream.hpp>
00029 #include <boost/test/unit_test_log.hpp>
00030 #include <boost/test/framework.hpp>
00031 #include <boost/test/detail/unit_test_parameters.hpp>
00032 #endif // BOOST_VERSION >= 103900
00033
00034 #include <boost/archive/text_oarchive.hpp>
00035 #include <boost/archive/text_iarchive.hpp>
00036
00037 #include <stdair/stdair_inventory_types.hpp>
00038 #include <stdair/service/Logger.hpp>
00039 #include <stdair/STDAIR_Service.hpp>
00040 #include <stdair/basic/float_utils.hpp>
00041 #include <stdair/bom/BomDisplay.hpp>
00042 #include <stdair/bom/BomRoot.hpp>
00043 #include <stdair/bom/BomManager.hpp>
00044 #include <stdair/factory/FacBom.hpp>
00045 #include <stdair/factory/FacBomManager.hpp>
00046
00047 #include <test/stdair/StdairTestLib.hpp>
00048 #include <test/stdair/MPInventory.hpp>
00049
00050 namespace boost_utf = boost::unit_test;
00051
00052 #if BOOST_VERSION >= 103900
00053
00054
00055 std::ofstream utfReportStream ("StandardAirlineITTestSuite_utfresults.xml");
00056
00060 struct UnitTestConfig {
00062 UnitTestConfig() {
00063 boost_utf::unit_test_log.set_stream (utfReportStream);
00064 boost_utf::unit_test_log.set_format (boost_utf::XML);
00065 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00066
00067 }
00068
00070 ~UnitTestConfig() {
00071 }
00072 };
00073
00074
00075
00076
00077
00078 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00079
00080
00081 BOOST_AUTO_TEST_SUITE (master_test_suite)
00082
00083
00087 BOOST_AUTO_TEST_CASE (float_comparison_test) {
00088 float a = 0.2f;
00089 a = 5*a;
00090 const float b = 1.0f;
00091
00092
00093 BOOST_CHECK_MESSAGE (a == b, "The two floats (" << a << " and " << b
00094 << ") should be equal, but are not");
00095 BOOST_CHECK_CLOSE (a, b, 0.0001);
00096
00097
00098 const FloatingPoint<float> lhs (a), rhs (b);
00099 BOOST_CHECK_MESSAGE (lhs.AlmostEquals (rhs),
00100 "The two floats (" << a << " and " << b
00101 << ") should be equal, but are not");
00102 }
00103
00108 BOOST_AUTO_TEST_CASE (mpl_structure_test) {
00109 const stdair::ClassCode_T lBookingClassCodeA ("A");
00110 const stdair_test::BookingClass lA (lBookingClassCodeA);
00111 const stdair_test::Cabin lCabin (lA);
00112
00113 BOOST_CHECK_EQUAL (lCabin.toString(), lBookingClassCodeA);
00114 BOOST_CHECK_MESSAGE (lCabin.toString() == lBookingClassCodeA,
00115 "The cabin key, '" << lCabin.toString()
00116 << "' is not equal to '" << lBookingClassCodeA << "'");
00117
00118
00119 typedef boost::mpl::vector<stdair_test::BookingClass> MPL_BookingClass;
00120 typedef boost::mpl::push_back<MPL_BookingClass,
00121 stdair_test::Cabin>::type types;
00122
00123 if (boost::is_same<stdair_test::BookingClass,
00124 stdair_test::Cabin::child>::value == false) {
00125 BOOST_REQUIRE ("The two types mut be equal, but are not");
00126 }
00127
00128 if (boost::is_same<boost::mpl::at_c<types, 1>::type,
00129 stdair_test::Cabin>::value == false) {
00130 BOOST_REQUIRE ("The type must be stdair_test::Cabin, but is not");
00131 }
00132 }
00133
00137 BOOST_AUTO_TEST_CASE (stdair_service_initialisation_test) {
00138
00139 const std::string lLogFilename ("StandardAirlineITTestSuite_init.log");
00140
00141
00142 std::ofstream logOutputFile;
00143
00144
00145 logOutputFile.open (lLogFilename.c_str());
00146 logOutputFile.clear();
00147
00148
00149 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00150 stdair::STDAIR_Service stdairService (lLogParams);
00151
00152
00153 stdair::BomRoot& lBomRoot = stdairService.getBomRoot();
00154
00155
00156 const std::string& lBomRootKeyStr = lBomRoot.describeKey();
00157 const std::string lBomRootString (" -- ROOT -- ");
00158
00159
00160 STDAIR_LOG_DEBUG ("The BOM root key is '" << lBomRootKeyStr
00161 << "'. It should be equal to '" << lBomRootString << "'");
00162
00163 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
00164 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
00165 "The BOM root key, '" << lBomRootKeyStr
00166 << "', should be equal to '" << lBomRootString
00167 << "', but is not.");
00168
00169
00170 stdairService.buildSampleBom();
00171
00172
00173 const std::string& lCSVDump = stdairService.csvDisplay();
00174 STDAIR_LOG_DEBUG (lCSVDump);
00175
00176
00177 logOutputFile.close();
00178 }
00179
00183 BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {
00184
00185
00186 stdair::BomRoot& lBomRoot =
00187 stdair::FacBom<stdair::BomRoot>::instance().create();
00188
00189
00190
00191 const stdair::AirlineCode_T lBAAirlineCode ("BA");
00192 const stdair::InventoryKey lBAKey (lBAAirlineCode);
00193 myprovider::Inventory& lBAInv =
00194 stdair::FacBom<myprovider::Inventory>::instance().create (lBAKey);
00195 stdair::FacBomManager::addToList (lBomRoot, lBAInv);
00196
00197 BOOST_CHECK_EQUAL (lBAInv.describeKey(), lBAAirlineCode);
00198 BOOST_CHECK_MESSAGE (lBAInv.describeKey() == lBAAirlineCode,
00199 "The inventory key, '" << lBAInv.describeKey()
00200 << "', should be equal to '" << lBAAirlineCode
00201 << "', but is not");
00202
00203
00204 const stdair::AirlineCode_T lAFAirlineCode ("AF");
00205 const stdair::InventoryKey lAFKey (lAFAirlineCode);
00206 myprovider::Inventory& lAFInv =
00207 stdair::FacBom<myprovider::Inventory>::instance().create (lAFKey);
00208 stdair::FacBomManager::addToList (lBomRoot, lAFInv);
00209
00210 BOOST_CHECK_EQUAL (lAFInv.describeKey(), lAFAirlineCode);
00211 BOOST_CHECK_MESSAGE (lAFInv.describeKey() == lAFAirlineCode,
00212 "The inventory key, '" << lAFInv.describeKey()
00213 << "', should be equal to '" << lAFAirlineCode
00214 << "', but is not");
00215
00216
00217 const myprovider::InventoryList_T& lInventoryList =
00218 stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);
00219 const std::string lInventoryKeyArray[2] = {lBAAirlineCode, lAFAirlineCode};
00220 short idx = 0;
00221 for (myprovider::InventoryList_T::const_iterator itInv =
00222 lInventoryList.begin(); itInv != lInventoryList.end();
00223 ++itInv, ++idx) {
00224 const myprovider::Inventory* lInv_ptr = *itInv;
00225 BOOST_REQUIRE (lInv_ptr != NULL);
00226
00227 BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());
00228 BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),
00229 "They inventory key, '" << lInventoryKeyArray[idx]
00230 << "', does not match that of the Inventory object: '"
00231 << lInv_ptr->describeKey() << "'");
00232 }
00233 }
00234
00238 BOOST_AUTO_TEST_CASE (bom_structure_serialisation_test) {
00239
00240
00241 const std::string lBackupFilename = "StandardAirlineITTestSuite_serial.txt";
00242
00243
00244 const std::string lLogFilename ("StandardAirlineITTestSuite_serial.log");
00245
00246
00247 std::ofstream logOutputFile;
00248
00249
00250 logOutputFile.open (lLogFilename.c_str());
00251 logOutputFile.clear();
00252
00253
00254 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00255 stdair::STDAIR_Service stdairService (lLogParams);
00256
00257
00258 stdairService.buildSampleBom();
00259
00260
00261 const std::string& lCSVDump = stdairService.csvDisplay();
00262 STDAIR_LOG_DEBUG (lCSVDump);
00263
00264
00265 stdair::BomRoot& lBomRoot = stdairService.getBomRoot();
00266
00267
00268 const std::string lBAInvKeyStr ("BA");
00269 stdair::Inventory* lBAInv_ptr = lBomRoot.getInventory (lBAInvKeyStr);
00270
00271
00272 STDAIR_LOG_DEBUG ("There should be an Inventory object corresponding to the '"
00273 << lBAInvKeyStr << "' key.");
00274
00275 BOOST_REQUIRE_MESSAGE (lBAInv_ptr != NULL,
00276 "An Inventory object should exist with the key, '"
00277 << lBAInvKeyStr << "'.");
00278
00279
00280 std::ofstream ofs (lBackupFilename.c_str());
00281
00282
00283 {
00284 boost::archive::text_oarchive oa (ofs);
00285
00286 oa << lBomRoot;
00287
00288 }
00289
00290
00291 stdair::BomRoot& lRestoredBomRoot =
00292 stdair::FacBom<stdair::BomRoot>::instance().create();
00293 {
00294
00295 std::ifstream ifs (lBackupFilename.c_str());
00296 boost::archive::text_iarchive ia(ifs);
00297
00298 ia >> lRestoredBomRoot;
00299
00300 }
00301
00302
00303 std::ostringstream oRestoredCSVDumpStr;
00304 stdair::BomDisplay::csvDisplay (oRestoredCSVDumpStr, lRestoredBomRoot);
00305 STDAIR_LOG_DEBUG (oRestoredCSVDumpStr.str());
00306
00307
00308 const std::string& lBomRootKeyStr = lRestoredBomRoot.describeKey();
00309 const std::string lBomRootString (" -- ROOT -- ");
00310
00311
00312 STDAIR_LOG_DEBUG ("The BOM root key is '" << lBomRootKeyStr
00313 << "'. It should be equal to '" << lBomRootString << "'");
00314
00315 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
00316 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
00317 "The BOM root key, '" << lBomRootKeyStr
00318 << "', should be equal to '" << lBomRootString
00319 << "', but is not.");
00320
00321
00322 stdair::Inventory* lRestoredBAInv_ptr =
00323 lRestoredBomRoot.getInventory (lBAInvKeyStr);
00324
00325
00326 STDAIR_LOG_DEBUG ("There should be an Inventory object corresponding to the '"
00327 << lBAInvKeyStr << "' key.");
00328
00329 BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,
00330 "An Inventory object should exist with the key, '"
00331 << lBAInvKeyStr << "'.");
00332
00333
00334 logOutputFile.close();
00335 }
00336
00337
00338 BOOST_AUTO_TEST_SUITE_END()
00339
00340 #else // BOOST_VERSION >= 103900
00341 boost_utf::test_suite* init_unit_test_suite (int, char* []) {
00342 boost_utf::test_suite* test = BOOST_TEST_SUITE ("Unit test example 1");
00343 return test;
00344 }
00345 #endif // BOOST_VERSION >= 103900
00346