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_MACRO >= 103900
23 #include <boost/test/unit_test.hpp>
24 #else // BOOST_VERSION_MACRO >= 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_MACRO >= 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_MACRO >= 103900
55 std::ofstream utfReportStream (
"StandardAirlineITTestSuite_utfresults.xml");
60 struct UnitTestConfig {
63 boost_utf::unit_test_log.set_stream (utfReportStream);
64 #if BOOST_VERSION_MACRO >= 105900
65 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
67 boost_utf::unit_test_log.set_format (boost_utf::XML);
69 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
82 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
85 BOOST_AUTO_TEST_SUITE (master_test_suite)
91 BOOST_AUTO_TEST_CASE (float_comparison_test) {
97 BOOST_CHECK_MESSAGE (a == b,
"The two floats (" << a <<
" and " << b
98 <<
") should be equal, but are not");
99 BOOST_CHECK_CLOSE (a, b, 0.0001);
103 BOOST_CHECK_MESSAGE (lhs.AlmostEquals (rhs),
104 "The two floats (" << a <<
" and " << b
105 <<
") should be equal, but are not");
112 BOOST_AUTO_TEST_CASE (mpl_structure_test) {
117 BOOST_CHECK_EQUAL (lCabin.toString(), lBookingClassCodeA);
118 BOOST_CHECK_MESSAGE (lCabin.toString() == lBookingClassCodeA,
119 "The cabin key, '" << lCabin.toString()
120 <<
"' is not equal to '" << lBookingClassCodeA <<
"'");
123 typedef boost::mpl::vector<stdair_test::BookingClass> MPL_BookingClass;
124 typedef boost::mpl::push_back<MPL_BookingClass,
129 BOOST_ERROR (
"The two types mut be equal, but are not");
132 if (boost::is_same<boost::mpl::at_c<types, 1>::type,
134 BOOST_ERROR (
"The type must be stdair_test::Cabin, but is not");
141 BOOST_AUTO_TEST_CASE (stdair_service_initialisation_test) {
143 const std::string lLogFilename (
"StandardAirlineITTestSuite_init.log");
146 std::ofstream logOutputFile;
149 logOutputFile.open (lLogFilename.c_str());
150 logOutputFile.clear();
157 stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
160 const std::string& lBomRootKeyStr = lPersistentBomRoot.
describeKey();
161 const std::string lBomRootString (
" -- ROOT -- ");
165 <<
"'. It should be equal to '" << lBomRootString <<
"'");
167 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
168 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
169 "The BOM root key, '" << lBomRootKeyStr
170 <<
"', should be equal to '" << lBomRootString
171 <<
"', but is not.");
174 stdairService.buildSampleBom();
177 const std::string& lCSVDump = stdairService.csvDisplay ();
181 logOutputFile.close();
187 BOOST_AUTO_TEST_CASE (bom_structure_instantiation_test) {
197 myprovider::Inventory& lBAInv =
201 BOOST_CHECK_EQUAL (lBAInv.describeKey(), lBAAirlineCode);
202 BOOST_CHECK_MESSAGE (lBAInv.describeKey() == lBAAirlineCode,
203 "The inventory key, '" << lBAInv.describeKey()
204 <<
"', should be equal to '" << lBAAirlineCode
210 myprovider::Inventory& lAFInv =
214 BOOST_CHECK_EQUAL (lAFInv.describeKey(), lAFAirlineCode);
215 BOOST_CHECK_MESSAGE (lAFInv.describeKey() == lAFAirlineCode,
216 "The inventory key, '" << lAFInv.describeKey()
217 <<
"', should be equal to '" << lAFAirlineCode
222 stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);
223 const std::string lInventoryKeyArray[2] = {lBAAirlineCode, lAFAirlineCode};
225 for (myprovider::InventoryList_T::const_iterator itInv =
226 lInventoryList.begin(); itInv != lInventoryList.end();
228 const myprovider::Inventory* lInv_ptr = *itInv;
229 BOOST_REQUIRE (lInv_ptr != NULL);
231 BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());
232 BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),
233 "They inventory key, '" << lInventoryKeyArray[idx]
234 <<
"', does not match that of the Inventory object: '"
235 << lInv_ptr->describeKey() <<
"'");
242 BOOST_AUTO_TEST_CASE (bom_structure_serialisation_test) {
245 const std::string lBackupFilename =
"StandardAirlineITTestSuite_serial.txt";
248 const std::string lLogFilename (
"StandardAirlineITTestSuite_serial.log");
251 std::ofstream logOutputFile;
254 logOutputFile.open (lLogFilename.c_str());
255 logOutputFile.clear();
262 stdairService.buildSampleBom();
265 stdair::BomRoot& lPersistentBomRoot = stdairService.getPersistentBomRoot();
268 const std::string& lCSVDump = stdairService.csvDisplay ();
272 stdairService.clonePersistentBom ();
275 const std::string lBAInvKeyStr (
"BA");
280 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
281 << lBAInvKeyStr <<
"' key.");
283 BOOST_REQUIRE_MESSAGE (lBAInv_ptr != NULL,
284 "An Inventory object should exist with the key, '"
285 << lBAInvKeyStr <<
"'.");
288 std::ofstream ofs (lBackupFilename.c_str());
292 boost::archive::text_oarchive oa (ofs);
294 oa << lPersistentBomRoot;
303 std::ifstream ifs (lBackupFilename.c_str());
304 boost::archive::text_iarchive ia(ifs);
306 ia >> lRestoredBomRoot;
311 const std::string& lRestoredCSVDump =
312 stdairService.csvDisplay(lRestoredBomRoot);
316 const std::string& lBomRootKeyStr = lRestoredBomRoot.
describeKey();
317 const std::string lBomRootString (
" -- ROOT -- ");
321 <<
"'. It should be equal to '" << lBomRootString <<
"'");
323 BOOST_CHECK_EQUAL (lBomRootKeyStr, lBomRootString);
324 BOOST_CHECK_MESSAGE (lBomRootKeyStr == lBomRootString,
325 "The BOM root key, '" << lBomRootKeyStr
326 <<
"', should be equal to '" << lBomRootString
327 <<
"', but is not.");
334 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
335 << lBAInvKeyStr <<
"' key in the restored BOM root.");
337 BOOST_CHECK_MESSAGE (lRestoredBAInv_ptr != NULL,
338 "An Inventory object should exist with the key, '"
339 << lBAInvKeyStr <<
"' in the restored BOM root.");
342 logOutputFile.close();
348 BOOST_AUTO_TEST_CASE (bom_structure_clone_test) {
351 const std::string lLogFilename (
"StandardAirlineITTestSuite_clone.log");
354 std::ofstream logOutputFile;
357 logOutputFile.open (lLogFilename.c_str());
358 logOutputFile.clear();
365 stdairService.buildSampleBom();
369 stdairService.getPersistentBomRoot();
372 const std::string& lCSVDump = stdairService.csvDisplay ();
377 stdairService.clonePersistentBom ();
383 const std::string& lAfterCloneCSVDump =
384 stdairService.csvDisplay(lCloneBomRoot);
390 const std::string& lCloneBomRootKeyStr = lCloneBomRoot.
describeKey();
391 const std::string& lPersistentBomRootKeyStr =
396 <<
"'. It should be equal to '"
397 << lPersistentBomRootKeyStr <<
"'");
399 BOOST_CHECK_EQUAL (lCloneBomRootKeyStr, lPersistentBomRootKeyStr);
400 BOOST_CHECK_MESSAGE (lCloneBomRootKeyStr == lPersistentBomRootKeyStr,
401 "The clone BOM root key, '" << lCloneBomRootKeyStr
402 <<
"', should be equal to '" << lPersistentBomRootKeyStr
403 <<
"', but is not.");
406 const std::string lBAInvKeyStr (
"BA");
411 STDAIR_LOG_DEBUG (
"There should be an Inventory object corresponding to the '"
412 << lBAInvKeyStr <<
"' key in the clone BOM root.");
414 BOOST_CHECK_MESSAGE (lCloneBAInv_ptr != NULL,
415 "An Inventory object should exist with the key, '"
416 << lBAInvKeyStr <<
"' in the clone BOM root.");
419 logOutputFile.close();
423 BOOST_AUTO_TEST_SUITE_END()
425 #else // BOOST_VERSION_MACRO >= 103900
426 boost_utf::test_suite* init_unit_test_suite (
int,
char* []) {
427 boost_utf::test_suite* test = BOOST_TEST_SUITE (
"Unit test example 1");
430 #endif // BOOST_VERSION_MACRO >= 103900