OpenTREP Logo  0.07.7
C++ Open Travel Request Parsing Library
SliceTestSuite.cpp
Go to the documentation of this file.
1 // /////////////////////////////////////////////////////////////////////////
2 //
3 // Query slice algorithm
4 //
5 // Author: Denis Arnaud
6 // Date: October 2012
7 //
8 // /////////////////////////////////////////////////////////////////////////
9 // STL
10 #include <sstream>
11 #include <fstream>
12 #include <string>
13 #include <list>
14 // Boost
15 #include <boost/filesystem.hpp>
16 // Boost Unit Test Framework (UTF)
17 #define BOOST_TEST_DYN_LINK
18 #define BOOST_TEST_MAIN
19 #define BOOST_TEST_MODULE SliceTestSuite
20 #include <boost/test/unit_test.hpp>
21 // OpenTrep
27 
28 namespace boost_utf = boost::unit_test;
29 
30 // (Boost) Unit Test XML Report
31 std::ofstream utfReportStream ("SliceTestSuite_utfresults.xml");
32 
36 struct UnitTestConfig {
39  boost_utf::unit_test_log.set_stream (utfReportStream);
40 #if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
41  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
42 #else // BOOST_VERSION
43  boost_utf::unit_test_log.set_format (boost_utf::XML);
44 #endif // BOOST_VERSION
45  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
46  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
47  }
48 
51  }
52 };
53 
54 // //////////// Constants for the tests ///////////////
58 const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
59 
63 const std::string X_SQL_DB_STR ("");
64 
65 /*
66  * Deployment number/version.
67  */
69 
70 // /////////////// Main: Unit Test Suite //////////////
71 
72 // Set the UTF configuration (re-direct the output to a specific file)
74 
75 // Start the test suite
76 BOOST_AUTO_TEST_SUITE (master_test_suite)
77 
78 
81 BOOST_AUTO_TEST_CASE (slice_small_string) {
82 
83  // Output log File
84  const std::string lLogFilename ("SliceTestSuite.log");
85 
86  // Set the log parameters
87  std::ofstream logOutputFile;
88  // Open and clean the log outputfile
89  logOutputFile.open (lLogFilename.c_str());
90  logOutputFile.clear();
91 
92  // Initialise the context
93  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
95  const OPENTREP::SQLDBConnectionString_T lSQLDBConnStr (X_SQL_DB_STR);
96  const OPENTREP::DeploymentNumber_T lDeploymentNumber (X_DEPLOYMENT_NUMBER);
97  OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lTravelDBFilePath,
98  lDBType, lSQLDBConnStr,
99  lDeploymentNumber);
100 
101  // A few sample strings
102  const std::string lLax1Str = "los angeles";
103  const std::string lLax2Str = "lso angeles";
104  const std::string lRio1Str = "rio de janeiro";
105  const std::string lRio2Str = "rio de janero";
106  const std::string lRek1Str = "reikjavik";
107  const std::string lRek2Str = "rekyavik";
108  const std::string lLwoIevHrk1Str = "lviv kiev kharkov";
109  const std::string lSfoRio1Str = "san francisco rio de janeiro";
110  const std::string lSfoRio2Str = "san francicso rio de janero";
111  const std::string lSfoRio3Str = "sna francicso rio de janero";
112  const std::string lChelseaStr = "chelsea municipal airport";
113 
118  // Open the Xapian database (the deployment number/version is added to the
119  // file-path
120  std::ostringstream oStr;
121  oStr << lTravelDBFilePath << lDeploymentNumber;
122  Xapian::Database lXapianDatabase (oStr.str());
123 
124  // Create a Unicode transliterator
125  const OPENTREP::OTransliterator lTransliterator;
126 
127  // Create the query slices
128  OPENTREP::QuerySlices lQuerySlices (lXapianDatabase, lLwoIevHrk1Str,
129  lTransliterator);
130 
131  // DEBUG
132  OPENTREP_LOG_DEBUG (lQuerySlices.size() << " slices: "
133  << lQuerySlices.describe());
134 
135  //
136  BOOST_CHECK_MESSAGE (lQuerySlices.size() == 3,
137  "The query ('" << lLwoIevHrk1Str
138  << "') should contain 3 slices."
139  << " However, its size is " << lQuerySlices.size()
140  << ".");
141 
142  // Create other query slices
143  OPENTREP::QuerySlices lAnotherQuerySlices (lXapianDatabase, lChelseaStr,
144  lTransliterator);
145 
146  // DEBUG
147  OPENTREP_LOG_DEBUG (lAnotherQuerySlices.size() << " slices: "
148  << lAnotherQuerySlices.describe());
149 
150  //
151  BOOST_CHECK_MESSAGE (lAnotherQuerySlices.size() == 3,
152  "The query ('" << lChelseaStr
153  << "') should contain 1 slice."
154  << " However, its size is " << lAnotherQuerySlices.size()
155  << ".");
156 
157  // Close the Log outputFile
158  logOutputFile.close();
159 }
160 
161 // End the test suite
162 BOOST_AUTO_TEST_SUITE_END()
163 
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition: Logger.hpp:33
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
const std::string X_SQL_DB_STR("")
const std::string X_XAPIAN_DB_FP("/tmp/opentrep/test_traveldb")
Interface for the OPENTREP Services.
BOOST_AUTO_TEST_CASE(slice_small_string)
Enumeration of database types.
Definition: DBType.hpp:17
const OPENTREP::DeploymentNumber_T X_DEPLOYMENT_NUMBER(0)
size_t size() const
Definition: QuerySlices.cpp:39
std::ofstream utfReportStream("SliceTestSuite_utfresults.xml")
std::string describe() const
Definition: QuerySlices.cpp:61
unsigned short DeploymentNumber_T