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