13 #include <boost/mpl/push_back.hpp>
14 #include <boost/mpl/vector.hpp>
15 #include <boost/mpl/at.hpp>
16 #include <boost/mpl/assert.hpp>
17 #include <boost/type_traits/is_same.hpp>
19 #define BOOST_TEST_DYN_LINK
20 #define BOOST_TEST_MAIN
21 #define BOOST_TEST_MODULE StdAirTest
22 #if BOOST_VERSION >= 103900
23 #include <boost/test/unit_test.hpp>
24 #else // BOOST_VERSION >= 103900
25 #include <boost/test/test_tools.hpp>
26 #include <boost/test/results_reporter.hpp>
27 #include <boost/test/unit_test_suite.hpp>
28 #include <boost/test/output_test_stream.hpp>
29 #include <boost/test/unit_test_log.hpp>
30 #include <boost/test/framework.hpp>
31 #include <boost/test/detail/unit_test_parameters.hpp>
32 #endif // BOOST_VERSION >= 103900
34 #include <boost/archive/text_oarchive.hpp>
35 #include <boost/archive/text_iarchive.hpp>
50 namespace boost_utf = boost::unit_test;
52 #if BOOST_VERSION >= 103900
55 std::ofstream utfReportStream (
"StandardAirlineITTestSuite_utfresults.xml");
60 struct UnitTestConfig {
63 boost_utf::unit_test_log.set_stream (utfReportStream);
64 boost_utf::unit_test_log.set_format (boost_utf::XML);
65 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
78 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
81 BOOST_AUTO_TEST_SUITE (master_test_suite)
87 BOOST_AUTO_TEST_CASE (float_comparison_test) {
93 BOOST_CHECK_MESSAGE (a == b,
"The two floats (" << a <<
" and " << b
94 <<
") should be equal, but are not");
95 BOOST_CHECK_CLOSE (a, b, 0.0001);
99 BOOST_CHECK_MESSAGE (lhs.AlmostEquals (rhs),
100 "The two floats (" << a <<
" and " << b
101 <<
") should be equal, but are not");
108 BOOST_AUTO_TEST_CASE (mpl_structure_test) {
113 BOOST_CHECK_EQUAL (lCabin.toString(), lBookingClassCodeA);
114 BOOST_CHECK_MESSAGE (lCabin.toString() == lBookingClassCodeA,
115 "The cabin key, '" << lCabin.toString()
116 <<
"' is not equal to '" << lBookingClassCodeA <<
"'");
119 typedef boost::mpl::vector<stdair_test::BookingClass> MPL_BookingClass;
120 typedef boost::mpl::push_back<MPL_BookingClass,
125 BOOST_ERROR (
"The two types mut be equal, but are not");
128 if (boost::is_same<boost::mpl::at_c<types, 1>::type,
130 BOOST_ERROR (
"The type must be stdair_test::Cabin, but is not");
137 BOOST_AUTO_TEST_CASE (stdair_service_initialisation_test) {
139 const std::string lLogFilename (
"StandardAirlineITTestSuite_init.log");
142 std::ofstream logOutputFile;
145 logOutputFile.open (lLogFilename.c_str());
146 logOutputFile.clear();
153 stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
156 const std::string& lBomRootKeyStr = lPersistentBomRoot.
describeKey();
157 const std::string lBomRootString (
" -- ROOT -- ");
161 <<
"'. It should be equal to '" << lBomRootString <<
"'");
163 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
164 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
165 "The BOM root key, '" << lBomRootKeyStr
166 <<
"', should be equal to '" << lBomRootString
167 <<
"', but is not.");
170 stdairService.buildSampleBom();
173 const std::string& lCSVDump = stdairService.csvDisplay ();
177 logOutputFile.close();
183 BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {
193 myprovider::Inventory& lBAInv =
197 BOOST_CHECK_EQUAL (lBAInv.describeKey(), lBAAirlineCode);
198 BOOST_CHECK_MESSAGE (lBAInv.describeKey() == lBAAirlineCode,
199 "The inventory key, '" << lBAInv.describeKey()
200 <<
"', should be equal to '" << lBAAirlineCode
206 myprovider::Inventory& lAFInv =
210 BOOST_CHECK_EQUAL (lAFInv.describeKey(), lAFAirlineCode);
211 BOOST_CHECK_MESSAGE (lAFInv.describeKey() == lAFAirlineCode,
212 "The inventory key, '" << lAFInv.describeKey()
213 <<
"', should be equal to '" << lAFAirlineCode
218 stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);
219 const std::string lInventoryKeyArray[2] = {lBAAirlineCode, lAFAirlineCode};
221 for (myprovider::InventoryList_T::const_iterator itInv =
222 lInventoryList.begin(); itInv != lInventoryList.end();
224 const myprovider::Inventory* lInv_ptr = *itInv;
225 BOOST_REQUIRE (lInv_ptr != NULL);
227 BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());
228 BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),
229 "They inventory key, '" << lInventoryKeyArray[idx]
230 <<
"', does not match that of the Inventory object: '"
231 << lInv_ptr->describeKey() <<
"'");
238 BOOST_AUTO_TEST_CASE (bom_structure_serialisation_test) {
241 const std::string lBackupFilename =
"StandardAirlineITTestSuite_serial.txt";
244 const std::string lLogFilename (
"StandardAirlineITTestSuite_serial.log");
247 std::ofstream logOutputFile;
250 logOutputFile.open (lLogFilename.c_str());
251 logOutputFile.clear();
258 stdairService.buildSampleBom();
261 stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
264 const std::string& lCSVDump = stdairService.csvDisplay ();
268 stdairService.clonePersistentBom ();
271 const std::string lBAInvKeyStr (
"BA");
276 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
277 << lBAInvKeyStr <<
"' key.");
279 BOOST_REQUIRE_MESSAGE (lBAInv_ptr != NULL,
280 "An Inventory object should exist with the key, '"
281 << lBAInvKeyStr <<
"'.");
284 std::ofstream ofs (lBackupFilename.c_str());
288 boost::archive::text_oarchive oa (ofs);
290 oa << lPersistentBomRoot;
299 std::ifstream ifs (lBackupFilename.c_str());
300 boost::archive::text_iarchive ia(ifs);
302 ia >> lRestoredBomRoot;
307 const std::string& lRestoredCSVDump =
308 stdairService.csvDisplay(lRestoredBomRoot);
312 const std::string& lBomRootKeyStr = lRestoredBomRoot.
describeKey();
313 const std::string lBomRootString (
" -- ROOT -- ");
317 <<
"'. It should be equal to '" << lBomRootString <<
"'");
319 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
320 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
321 "The BOM root key, '" << lBomRootKeyStr
322 <<
"', should be equal to '" << lBomRootString
323 <<
"', but is not.");
330 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
331 << lBAInvKeyStr <<
"' key in the restored BOM root.");
333 BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,
334 "An Inventory object should exist with the key, '"
335 << lBAInvKeyStr <<
"' in the restored BOM root.");
338 logOutputFile.close();
344 BOOST_AUTO_TEST_CASE (bom_structure_clone_test) {
347 const std::string lLogFilename (
"StandardAirlineITTestSuite_clone.log");
350 std::ofstream logOutputFile;
353 logOutputFile.open (lLogFilename.c_str());
354 logOutputFile.clear();
361 stdairService.buildSampleBom();
365 stdairService.getPersistentBomRoot();
368 const std::string& lCSVDump = stdairService.csvDisplay ();
373 stdairService.clonePersistentBom ();
379 const std::string& lAfterCloneCSVDump =
380 stdairService.csvDisplay(lCloneBomRoot);
386 const std::string& lCloneBomRootKeyStr = lCloneBomRoot.
describeKey();
387 const std::string& lPersistentBomRootKeyStr =
392 <<
"'. It should be equal to '"
393 << lPersistentBomRootKeyStr <<
"'");
395 BOOST_CHECK_EQUAL (lCloneBomRootKeyStr, lPersistentBomRootKeyStr);
396 BOOST_CHECK_MESSAGE (lCloneBomRootKeyStr == lPersistentBomRootKeyStr,
397 "The clone BOM root key, '" << lCloneBomRootKeyStr
398 <<
"', should be equal to '" << lPersistentBomRootKeyStr
399 <<
"', but is not.");
402 const std::string lBAInvKeyStr (
"BA");
407 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
408 << lBAInvKeyStr <<
"' key in the clone BOM root.");
410 BOOST_CHECK_MESSAGE (lCloneBAInv_ptr != NULL,
411 "An Inventory object should exist with the key, '"
412 << lBAInvKeyStr <<
"' in the clone BOM root.");
415 logOutputFile.close();
419 BOOST_AUTO_TEST_SUITE_END()
421 #else // BOOST_VERSION >= 103900
422 boost_utf::test_suite* init_unit_test_suite (
int,
char* []) {
423 boost_utf::test_suite* test = BOOST_TEST_SUITE (
"Unit test example 1");
426 #endif // BOOST_VERSION >= 103900
static FacBom & instance()
std::string AirlineCode_T
Key of a given inventory, made of the airline code.
Structure holding parameters for logging.
Class representing the actual attributes for an airline inventory.
static void addToList(OBJECT1 &, OBJECT2 &)
Inventory * getInventory(const std::string &iInventoryKeyStr) const
Class representing the actual attributes for the Bom root.
std::list< Inventory * > InventoryList_T
const std::string describeKey() const
Interface for the STDAIR Services.
#define STDAIR_LOG_DEBUG(iToBeLogged)