OpenTREP Logo  0.07.1
C++ Open Travel Request Parsing Library
SearchingTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE SearchingTestSuite
16 #include <boost/test/unit_test.hpp>
17 // OpenTrep
20 #include <opentrep/Location.hpp>
21 #include <opentrep/CityDetails.hpp>
22 
23 namespace boost_utf = boost::unit_test;
24 
25 // (Boost) Unit Test XML Report
26 std::ofstream utfReportStream ("SearchingTestSuite_utfresults.xml");
27 
31 struct UnitTestConfig {
33  UnitTestConfig() {
34  boost_utf::unit_test_log.set_stream (utfReportStream);
35 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
36  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
37 #else // BOOST_VERSION
38  boost_utf::unit_test_log.set_format (boost_utf::XML);
39 #endif // BOOST_VERSION
40  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
41  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
42  }
43 
45  ~UnitTestConfig() {
46  }
47 };
48 
49 
50 // //////////// Constants for the tests ///////////////
54 const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
55 
59 const std::string X_SQL_DB_STR ("");
60 
61 
62 // /////////////// Main: Unit Test Suite //////////////
63 
64 // Set the UTF configuration (re-direct the output to a specific file)
66 
67 // Start the test suite
68 BOOST_AUTO_TEST_SUITE (master_test_suite)
69 
70 
73 BOOST_AUTO_TEST_CASE (opentrep_simple_search) {
74 
75  // Output log File
76  std::string lLogFilename ("SearchingTestSuite.log");
77 
78  // Travel query
79  std::string lTravelQuery ("nce");
80 
81  // Deployment number/version
82  OPENTREP::DeploymentNumber_T lDeploymentNumber (0);
83 
84  // Set the log parameters
85  std::ofstream logOutputFile;
86  // Open and clean the log outputfile
87  logOutputFile.open (lLogFilename.c_str());
88  logOutputFile.clear();
89 
90  // Initialise the context
91  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
93  const OPENTREP::SQLDBConnectionString_T lSQLDBConnStr (X_SQL_DB_STR);
94  OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lTravelDBFilePath,
95  lDBType, lSQLDBConnStr,
96  lDeploymentNumber);
97 
98  // Query the Xapian database (index)
99  OPENTREP::WordList_T lNonMatchedWordList;
100  OPENTREP::LocationList_T lLocationList;
101  const OPENTREP::NbOfMatches_T nbOfMatches =
102  opentrepService.interpretTravelRequest (lTravelQuery, lLocationList,
103  lNonMatchedWordList);
104  BOOST_CHECK_MESSAGE (nbOfMatches == 1,
105  "The travel query ('" << lTravelQuery
106  << "') matches with " << nbOfMatches
107  << " key-words, whereas 1 is expected.");
108 
109  // Close the Log outputFile
110  logOutputFile.close();
111 }
112 
113 // End the test suite
114 BOOST_AUTO_TEST_SUITE_END()
115 
116 
unsigned short NbOfMatches_T
const std::string X_SQL_DB_STR("")
const std::string X_XAPIAN_DB_FP(OPENTREP::DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH)
Interface for the OPENTREP Services.
std::list< Word_T > WordList_T
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
Enumeration of database types.
Definition: DBType.hpp:17
BOOST_AUTO_TEST_CASE(partition_small_string)
std::list< Location > LocationList_T
std::ofstream utfReportStream("PartitionTestSuite_utfresults.xml")
unsigned short DeploymentNumber_T