OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
22 namespace boost_utf = boost::unit_test;
23 
24 // (Boost) Unit Test XML Report
25 std::ofstream utfReportStream ("SearchingTestSuite_utfresults.xml");
26 
30 struct UnitTestConfig {
32  UnitTestConfig() {
33  boost_utf::unit_test_log.set_stream (utfReportStream);
34  boost_utf::unit_test_log.set_format (boost_utf::XML);
35  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
36  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
37  }
38 
40  ~UnitTestConfig() {
41  }
42 };
43 
44 
45 // //////////// Constants for the tests ///////////////
49 const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
50 
54 const std::string X_SQLITE_DB_FP ("/tmp/opentrep/test_traveldb/ori_por_public.csv");
55 
56 
57 // /////////////// Main: Unit Test Suite //////////////
58 
59 // Set the UTF configuration (re-direct the output to a specific file)
61 
62 // Start the test suite
63 BOOST_AUTO_TEST_SUITE (master_test_suite)
64 
65 
68 BOOST_AUTO_TEST_CASE (opentrep_simple_search) {
69 
70  // Output log File
71  std::string lLogFilename ("SearchingTestSuite.log");
72 
73  // Travel query
74  std::string lTravelQuery ("nce");
75 
76  // Set the log parameters
77  std::ofstream logOutputFile;
78  // Open and clean the log outputfile
79  logOutputFile.open (lLogFilename.c_str());
80  logOutputFile.clear();
81 
82  // Initialise the context
83  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
84  const OPENTREP::SQLiteDBFilePath_T lSQLiteDBFilePath (X_SQLITE_DB_FP);
85  OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lTravelDBFilePath,
86  lSQLiteDBFilePath);
87 
88  // Query the Xapian database (index)
89  OPENTREP::WordList_T lNonMatchedWordList;
90  OPENTREP::LocationList_T lLocationList;
91  const OPENTREP::NbOfMatches_T nbOfMatches =
92  opentrepService.interpretTravelRequest (lTravelQuery, lLocationList,
93  lNonMatchedWordList);
94  BOOST_CHECK_MESSAGE (nbOfMatches == 1,
95  "The travel query ('" << lTravelQuery
96  << "') matches with " << nbOfMatches
97  << " key-words, whereas 1 is expected.");
98 
99  // Close the Log outputFile
100  logOutputFile.close();
101 }
102 
103 // End the test suite
104 BOOST_AUTO_TEST_SUITE_END()
105 
106 
unsigned short NbOfMatches_T
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)
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)