OpenTREP Logo  0.07.11
C++ Open Travel Request Parsing Library
IndexBuildingTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <cassert>
10 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <string>
14 // Boost Unit Test Framework (UTF)
15 #define BOOST_TEST_DYN_LINK
16 #define BOOST_TEST_MAIN
17 #define BOOST_TEST_MODULE IndexBuildingTestSuite
18 #include <boost/test/unit_test.hpp>
19 // OpenTrep
22 #include <opentrep/Location.hpp>
23 #include <opentrep/CityDetails.hpp>
25 
26 namespace boost_utf = boost::unit_test;
27 
28 // (Boost) Unit Test XML Report
29 std::ofstream utfReportStream ("IndexBuildingTestSuite_utfresults.xml");
30 
34 struct UnitTestConfig {
36  UnitTestConfig() {
37  boost_utf::unit_test_log.set_stream (utfReportStream);
38 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
39  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
40 #else // BOOST_VERSION
41  boost_utf::unit_test_log.set_format (boost_utf::XML);
42 #endif // BOOST_VERSION
43  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
44  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
45  }
46 
48  ~UnitTestConfig() {
49  }
50 };
51 
52 
53 // //////////// Constants for the tests ///////////////
57 const std::string K_POR_FILEPATH (OPENTREP_POR_DATA_DIR
58  "/test_optd_por_public.csv");
59 
63 const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
64 
68 const std::string X_SQL_DB_STR ("");
69 
74 
78 const OPENTREP::shouldIndexNonIATAPOR_T K_ALL_POR = false;
79 
83 const OPENTREP::shouldIndexPORInXapian_T K_XAPIAN_IDX = true;
84 
88 const OPENTREP::shouldAddPORInSQLDB_T K_SQLDB_ADD = false;
89 
90 
91 // /////////////// Main: Unit Test Suite //////////////
92 
93 // Set the UTF configuration (re-direct the output to a specific file)
95 
96 // Start the test suite
97 BOOST_AUTO_TEST_SUITE (master_test_suite)
98 
99 
102 BOOST_AUTO_TEST_CASE (opentrep_simple_index) {
103 
104  // Output log File
105  std::string lLogFilename ("IndexBuildingTestSuite.log");
106 
107  // Set the log parameters
108  std::ofstream logOutputFile;
109  // Open and clean the log outputfile
110  logOutputFile.open (lLogFilename.c_str());
111  logOutputFile.clear();
112 
113  // Initialise the context
114  const OPENTREP::PORFilePath_T lPORFilePath (K_POR_FILEPATH);
115  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
117  const OPENTREP::SQLDBConnectionString_T lSQLDBConnStr (X_SQL_DB_STR);
118  const OPENTREP::DeploymentNumber_T lDeploymentNumber (X_DEPLOYMENT_NUMBER);
119  const OPENTREP::shouldIndexNonIATAPOR_T lShouldIndexNonIATAPOR (K_ALL_POR);
120  const OPENTREP::shouldIndexPORInXapian_T lShouldIndexPORInXapian(K_XAPIAN_IDX);
121  const OPENTREP::shouldAddPORInSQLDB_T lShouldAddPORInSQLDB (K_SQLDB_ADD);
122  OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lPORFilePath,
123  lTravelDBFilePath,
124  lDBType, lSQLDBConnStr,
125  lDeploymentNumber,
126  lShouldIndexNonIATAPOR,
127  lShouldIndexPORInXapian,
128  lShouldAddPORInSQLDB);
129 
130  // Query the Xapian database (index)
131  OPENTREP::WordList_T lNonMatchedWordList;
132  OPENTREP::LocationList_T lLocationList;
133  // Launch the indexation
134  const OPENTREP::NbOfDBEntries_T nbOfEntries =
135  opentrepService.insertIntoDBAndXapian();
136 
137  BOOST_CHECK_MESSAGE (nbOfEntries == 9,
138  "The Xapian index ('" << lTravelDBFilePath
139  << "') contains " << nbOfEntries
140  << " entries, where as 9 are expected.");
141 
142  // Close the Log outputFile
143  logOutputFile.close();
144 }
145 
146 // End the test suite
147 BOOST_AUTO_TEST_SUITE_END()
148 
149 
const std::string X_SQL_DB_STR("")
const std::string X_XAPIAN_DB_FP("/tmp/opentrep/test_traveldb")
bool shouldIndexNonIATAPOR_T
unsigned int NbOfDBEntries_T
Interface for the OPENTREP Services.
std::list< Word_T > WordList_T
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
#define OPENTREP_POR_DATA_DIR
Enumeration of database types.
Definition: DBType.hpp:17
BOOST_AUTO_TEST_CASE(partition_small_string)
std::list< Location > LocationList_T
const OPENTREP::DeploymentNumber_T X_DEPLOYMENT_NUMBER(0)
bool shouldAddPORInSQLDB_T
bool shouldIndexPORInXapian_T
std::ofstream utfReportStream("PartitionTestSuite_utfresults.xml")
unsigned short DeploymentNumber_T