*/
#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>
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);
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) {
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,
BOOST_ERROR ("The two types mut be equal, but are not");
}
if (boost::is_same<boost::mpl::at_c<types, 1>::type,
BOOST_ERROR ("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();
stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
const std::string& lBomRootKeyStr = lPersistentBomRoot.
describeKey();
const std::string lBomRootString (" -- ROOT -- ");
<< "'. 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 ();
logOutputFile.close();
}
BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {
myprovider::Inventory& 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");
myprovider::Inventory& 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");
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();
stdairService.buildSampleBom();
stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
const std::string& lCSVDump = stdairService.csvDisplay ();
stdairService.clonePersistentBom ();
const std::string lBAInvKeyStr ("BA");
<< 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 << lPersistentBomRoot;
}
{
std::ifstream ifs (lBackupFilename.c_str());
boost::archive::text_iarchive ia(ifs);
ia >> lRestoredBomRoot;
}
const std::string& lRestoredCSVDump =
stdairService.csvDisplay(lRestoredBomRoot);
const std::string& lBomRootKeyStr = lRestoredBomRoot.
describeKey();
const std::string lBomRootString (" -- ROOT -- ");
<< "'. 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.");
<< lBAInvKeyStr << "' key in the restored BOM root.");
BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,
"An Inventory object should exist with the key, '"
<< lBAInvKeyStr << "' in the restored BOM root.");
logOutputFile.close();
}
BOOST_AUTO_TEST_CASE (bom_structure_clone_test) {
const std::string lLogFilename ("StandardAirlineITTestSuite_clone.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
stdairService.buildSampleBom();
stdairService.getPersistentBomRoot();
const std::string& lCSVDump = stdairService.csvDisplay ();
stdairService.clonePersistentBom ();
const std::string& lAfterCloneCSVDump =
stdairService.csvDisplay(lCloneBomRoot);
const std::string& lCloneBomRootKeyStr = lCloneBomRoot.
describeKey();
const std::string& lPersistentBomRootKeyStr =
<< "'. It should be equal to '"
<< lPersistentBomRootKeyStr << "'");
BOOST_CHECK_EQUAL (lCloneBomRootKeyStr, lPersistentBomRootKeyStr);
BOOST_CHECK_MESSAGE (lCloneBomRootKeyStr == lPersistentBomRootKeyStr,
"The clone BOM root key, '" << lCloneBomRootKeyStr
<< "', should be equal to '" << lPersistentBomRootKeyStr
<< "', but is not.");
const std::string lBAInvKeyStr ("BA");
<< lBAInvKeyStr << "' key in the clone BOM root.");
BOOST_CHECK_MESSAGE (lCloneBAInv_ptr != NULL,
"An Inventory object should exist with the key, '"
<< lBAInvKeyStr << "' in the clone BOM root.");
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