*/
#include <sstream>
#include <fstream>
#include <string>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE StdAirTest
#if BOOST_VERSION >= 103900
#include <boost/test/unit_test.hpp>
#else // BOOST_VERSION >= 103900
#include <boost/test/test_tools.hpp>
#include <boost/test/results_reporter.hpp>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/output_test_stream.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/framework.hpp>
#include <boost/test/detail/unit_test_parameters.hpp>
#endif // BOOST_VERSION >= 103900
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <stdair/stdair_inventory_types.hpp>
#include <stdair/service/Logger.hpp>
#include <stdair/STDAIR_Service.hpp>
#include <stdair/basic/float_utils.hpp>
#include <stdair/bom/BomDisplay.hpp>
#include <stdair/bom/BomRoot.hpp>
#include <stdair/bom/BomManager.hpp>
#include <stdair/factory/FacBom.hpp>
#include <stdair/factory/FacBomManager.hpp>
#include <test/stdair/StdairTestLib.hpp>
#include <test/stdair/MPInventory.hpp>
namespace boost_utf = boost::unit_test;
#if BOOST_VERSION >= 103900
std::ofstream utfReportStream ("StandardAirlineITTestSuite_utfresults.xml");
struct UnitTestConfig {
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
~UnitTestConfig() {
}
};
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (float_comparison_test) {
float a = 0.2f;
a = 5*a;
const float b = 1.0f;
BOOST_CHECK_MESSAGE (a == b, "The two floats (" << a << " and " << b
<< ") should be equal, but are not");
BOOST_CHECK_CLOSE (a, b, 0.0001);
const FloatingPoint<float> lhs (a), rhs (b);
BOOST_CHECK_MESSAGE (lhs.AlmostEquals (rhs),
"The two floats (" << a << " and " << b
<< ") should be equal, but are not");
}
BOOST_AUTO_TEST_CASE (mpl_structure_test) {
const stdair::ClassCode_T lBookingClassCodeA ("A");
const stdair_test::BookingClass lA (lBookingClassCodeA);
const stdair_test::Cabin lCabin (lA);
BOOST_CHECK_EQUAL (lCabin.toString(), lBookingClassCodeA);
BOOST_CHECK_MESSAGE (lCabin.toString() == lBookingClassCodeA,
"The cabin key, '" << lCabin.toString()
<< "' is not equal to '" << lBookingClassCodeA << "'");
typedef boost::mpl::vector<stdair_test::BookingClass> MPL_BookingClass;
typedef boost::mpl::push_back<MPL_BookingClass,
stdair_test::Cabin>::type types;
if (boost::is_same<stdair_test::BookingClass,
stdair_test::Cabin::child>::value == false) {
BOOST_REQUIRE ("The two types mut be equal, but are not");
}
if (boost::is_same<boost::mpl::at_c<types, 1>::type,
stdair_test::Cabin>::value == false) {
BOOST_REQUIRE ("The type must be stdair_test::Cabin, but is not");
}
}
BOOST_AUTO_TEST_CASE (stdair_service_initialisation_test) {
const std::string lLogFilename ("StandardAirlineITTestSuite_init.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
stdair::STDAIR_Service stdairService (lLogParams);
stdair::BomRoot& lBomRoot = stdairService.getBomRoot();
const std::string& lBomRootKeyStr = lBomRoot.describeKey();
const std::string lBomRootString (" -- ROOT -- ");
STDAIR_LOG_DEBUG ("The BOM root key is '" << lBomRootKeyStr
<< "'. It should be equal to '" << lBomRootString << "'");
BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
"The BOM root key, '" << lBomRootKeyStr
<< "', should be equal to '" << lBomRootString
<< "', but is not.");
stdairService.buildSampleBom();
const std::string& lCSVDump = stdairService.csvDisplay();
STDAIR_LOG_DEBUG (lCSVDump);
logOutputFile.close();
}
BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {
stdair::BomRoot& lBomRoot =
stdair::FacBom<stdair::BomRoot>::instance().create();
const stdair::AirlineCode_T lBAAirlineCode ("BA");
const stdair::InventoryKey lBAKey (lBAAirlineCode);
myprovider::Inventory& lBAInv =
stdair::FacBom<myprovider::Inventory>::instance().create (lBAKey);
stdair::FacBomManager::addToList (lBomRoot, lBAInv);
BOOST_CHECK_EQUAL (lBAInv.describeKey(), lBAAirlineCode);
BOOST_CHECK_MESSAGE (lBAInv.describeKey() == lBAAirlineCode,
"The inventory key, '" << lBAInv.describeKey()
<< "', should be equal to '" << lBAAirlineCode
<< "', but is not");
const stdair::AirlineCode_T lAFAirlineCode ("AF");
const stdair::InventoryKey lAFKey (lAFAirlineCode);
myprovider::Inventory& lAFInv =
stdair::FacBom<myprovider::Inventory>::instance().create (lAFKey);
stdair::FacBomManager::addToList (lBomRoot, lAFInv);
BOOST_CHECK_EQUAL (lAFInv.describeKey(), lAFAirlineCode);
BOOST_CHECK_MESSAGE (lAFInv.describeKey() == lAFAirlineCode,
"The inventory key, '" << lAFInv.describeKey()
<< "', should be equal to '" << lAFAirlineCode
<< "', but is not");
const myprovider::InventoryList_T& lInventoryList =
stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);
const std::string lInventoryKeyArray[2] = {lBAAirlineCode, lAFAirlineCode};
short idx = 0;
for (myprovider::InventoryList_T::const_iterator itInv =
lInventoryList.begin(); itInv != lInventoryList.end();
++itInv, ++idx) {
const myprovider::Inventory* lInv_ptr = *itInv;
BOOST_REQUIRE (lInv_ptr != NULL);
BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());
BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),
"They inventory key, '" << lInventoryKeyArray[idx]
<< "', does not match that of the Inventory object: '"
<< lInv_ptr->describeKey() << "'");
}
}
BOOST_AUTO_TEST_CASE (bom_structure_serialisation_test) {
const std::string lBackupFilename = "StandardAirlineITTestSuite_serial.txt";
const std::string lLogFilename ("StandardAirlineITTestSuite_serial.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
stdair::STDAIR_Service stdairService (lLogParams);
stdairService.buildSampleBom();
const std::string& lCSVDump = stdairService.csvDisplay();
STDAIR_LOG_DEBUG (lCSVDump);
stdair::BomRoot& lBomRoot = stdairService.getBomRoot();
const std::string lBAInvKeyStr ("BA");
stdair::Inventory* lBAInv_ptr = lBomRoot.getInventory (lBAInvKeyStr);
STDAIR_LOG_DEBUG ("There should be an Inventory object corresponding to the '"
<< lBAInvKeyStr << "' key.");
BOOST_REQUIRE_MESSAGE (lBAInv_ptr != NULL,
"An Inventory object should exist with the key, '"
<< lBAInvKeyStr << "'.");
std::ofstream ofs (lBackupFilename.c_str());
{
boost::archive::text_oarchive oa (ofs);
oa << lBomRoot;
}
stdair::BomRoot& lRestoredBomRoot =
stdair::FacBom<stdair::BomRoot>::instance().create();
{
std::ifstream ifs (lBackupFilename.c_str());
boost::archive::text_iarchive ia(ifs);
ia >> lRestoredBomRoot;
}
std::ostringstream oRestoredCSVDumpStr;
stdair::BomDisplay::csvDisplay (oRestoredCSVDumpStr, lRestoredBomRoot);
STDAIR_LOG_DEBUG (oRestoredCSVDumpStr.str());
const std::string& lBomRootKeyStr = lRestoredBomRoot.describeKey();
const std::string lBomRootString (" -- ROOT -- ");
STDAIR_LOG_DEBUG ("The BOM root key is '" << lBomRootKeyStr
<< "'. It should be equal to '" << lBomRootString << "'");
BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
"The BOM root key, '" << lBomRootKeyStr
<< "', should be equal to '" << lBomRootString
<< "', but is not.");
stdair::Inventory* lRestoredBAInv_ptr =
lRestoredBomRoot.getInventory (lBAInvKeyStr);
STDAIR_LOG_DEBUG ("There should be an Inventory object corresponding to the '"
<< lBAInvKeyStr << "' key.");
BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,
"An Inventory object should exist with the key, '"
<< lBAInvKeyStr << "'.");
logOutputFile.close();
}
BOOST_AUTO_TEST_SUITE_END()
#else // BOOST_VERSION >= 103900
boost_utf::test_suite* init_unit_test_suite (int, char* []) {
boost_utf::test_suite* test = BOOST_TEST_SUITE ("Unit test example 1");
return test;
}
#endif // BOOST_VERSION >= 103900