OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/config/opentrep-paths.hpp>
24 
25 namespace boost_utf = boost::unit_test;
26 
27 // (Boost) Unit Test XML Report
28 std::ofstream utfReportStream ("IndexBuildingTestSuite_utfresults.xml");
29 
33 struct UnitTestConfig {
35  UnitTestConfig() {
36  boost_utf::unit_test_log.set_stream (utfReportStream);
37  boost_utf::unit_test_log.set_format (boost_utf::XML);
38  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
39  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
40  }
41 
43  ~UnitTestConfig() {
44  }
45 };
46 
47 
48 // //////////// Constants for the tests ///////////////
52 const std::string K_POR_FILEPATH (OPENTREP_POR_DATA_DIR
53  "/test_ori_por_public.csv");
54 
58 const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
59 
63 const std::string X_SQLITE_DB_FP ("/tmp/opentrep/test_traveldb/ori_por_public.csv");
64 
65 
66 // /////////////// Main: Unit Test Suite //////////////
67 
68 // Set the UTF configuration (re-direct the output to a specific file)
70 
71 // Start the test suite
72 BOOST_AUTO_TEST_SUITE (master_test_suite)
73 
74 
77 BOOST_AUTO_TEST_CASE (opentrep_simple_index) {
78 
79  // Output log File
80  std::string lLogFilename ("IndexBuildingTestSuite.log");
81 
82  // Set the log parameters
83  std::ofstream logOutputFile;
84  // Open and clean the log outputfile
85  logOutputFile.open (lLogFilename.c_str());
86  logOutputFile.clear();
87 
88  // Initialise the context
89  const OPENTREP::PORFilePath_T lPORFilePath (K_POR_FILEPATH);
90  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
91  const OPENTREP::SQLiteDBFilePath_T lSQLiteDBFilePath (X_SQLITE_DB_FP);
92  OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lPORFilePath,
93  lTravelDBFilePath,
94  lSQLiteDBFilePath);
95 
96  // Query the Xapian database (index)
97  OPENTREP::WordList_T lNonMatchedWordList;
98  OPENTREP::LocationList_T lLocationList;
99  // Launch the indexation
100  const OPENTREP::NbOfDBEntries_T nbOfEntries =
101  opentrepService.buildSearchIndex();
102 
103  BOOST_CHECK_MESSAGE (nbOfEntries == 9,
104  "The Xapian index ('" << lTravelDBFilePath
105  << "') contains " << nbOfEntries
106  << " entries, where as 9 are expected.");
107 
108  // Close the Log outputFile
109  logOutputFile.close();
110 }
111 
112 // End the test suite
113 BOOST_AUTO_TEST_SUITE_END()
114 
115 
const std::string X_XAPIAN_DB_FP(OPENTREP::DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH)
unsigned int NbOfDBEntries_T
Interface for the OPENTREP Services.
std::list< Word_T > WordList_T
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
BOOST_AUTO_TEST_CASE(partition_small_string)
std::list< Location > LocationList_T
std::ofstream utfReportStream("PartitionTestSuite_utfresults.xml")
const std::string X_SQLITE_DB_FP(OPENTREP::DEFAULT_OPENTREP_SQLITE_DB_FILEPATH)