OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
25 
26 namespace boost_utf = boost::unit_test;
27 
28 // (Boost) Unit Test XML Report
29 std::ofstream utfReportStream ("SliceTestSuite_utfresults.xml");
30 
34 struct UnitTestConfig {
37  boost_utf::unit_test_log.set_stream (utfReportStream);
38  boost_utf::unit_test_log.set_format (boost_utf::XML);
39  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
40  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
41  }
42 
45  }
46 };
47 
48 // //////////// Constants for the tests ///////////////
53 
58 
59 
60 // /////////////// Main: Unit Test Suite //////////////
61 
62 // Set the UTF configuration (re-direct the output to a specific file)
64 
65 // Start the test suite
66 BOOST_AUTO_TEST_SUITE (master_test_suite)
67 
68 
71 BOOST_AUTO_TEST_CASE (slice_small_string) {
72 
73  // Output log File
74  const std::string lLogFilename ("SliceTestSuite.log");
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  // A few sample strings
89  const std::string lLax1Str = "los angeles";
90  const std::string lLax2Str = "lso angeles";
91  const std::string lRio1Str = "rio de janeiro";
92  const std::string lRio2Str = "rio de janero";
93  const std::string lRek1Str = "reikjavik";
94  const std::string lRek2Str = "rekyavik";
95  const std::string lSfoRio1Str = "san francisco rio de janeiro";
96  const std::string lSfoRio2Str = "san francicso rio de janero";
97  const std::string lSfoRio3Str = "sna francicso rio de janero";
98  const std::string lChelseaStr = "chelsea municipal airport";
99 
104  // Open the Xapian database
105  Xapian::Database lXapianDatabase (lTravelDBFilePath);
106 
107  // Create the query slices
108  OPENTREP::QuerySlices lQuerySlices (lXapianDatabase, lSfoRio1Str);
109 
110  //
111  BOOST_CHECK_MESSAGE (lQuerySlices.size() == 5,
112  "The query ('" << lSfoRio1Str
113  << "') should contain 5 slices."
114  << " However, its size is " << lQuerySlices.size()
115  << ".");
116 
117  // Create other query slices
118  OPENTREP::QuerySlices lAnotherQuerySlices (lXapianDatabase, lChelseaStr);
119 
120  //
121  BOOST_CHECK_MESSAGE (lAnotherQuerySlices.size() == 3,
122  "The query ('" << lChelseaStr
123  << "') should contain 3 slices."
124  << " However, its size is " << lAnotherQuerySlices.size()
125  << ".");
126 
127  // Close the Log outputFile
128  logOutputFile.close();
129 }
130 
131 // End the test suite
132 BOOST_AUTO_TEST_SUITE_END()
133 
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
size_t size() const
Definition: QuerySlices.cpp:37
const std::string X_XAPIAN_DB_FP(OPENTREP::DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH)
const std::string DEFAULT_OPENTREP_SQLITE_DB_FILEPATH
Interface for the OPENTREP Services.
BOOST_AUTO_TEST_CASE(slice_small_string)
const std::string DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH
const std::string X_SQLITE_DB_FP(OPENTREP::DEFAULT_OPENTREP_SQLITE_DB_FILEPATH)
std::ofstream utfReportStream("SliceTestSuite_utfresults.xml")