16#define BOOST_TEST_DYN_LINK
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_MODULE IndexBuildingTestSuite
19#include <boost/test/unit_test.hpp>
27#include <opentrep/config/opentrep-paths.hpp>
29namespace boost_utf = boost::unit_test;
41#if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
42 boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
44 boost_utf::unit_test_log.set_format (boost_utf::XML);
46 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
60const std::string K_POR_FILEPATH (OPENTREP_POR_DATA_DIR
61 "/csv/test-optd-por-public.csv");
69const std::string K_POR_FILEPATH_QSW (OPENTREP_POR_DATA_DIR
70 "/csv/test-optd-por-qsw-as-suwayda.csv");
109BOOST_AUTO_TEST_SUITE (master_test_suite)
117 std::string lLogFilename (
"IndexBuildingTestSuite.log");
120 std::ofstream logOutputFile;
122 logOutputFile.open (lLogFilename.c_str());
123 logOutputFile.clear();
136 lDBType, lSQLDBConnStr,
138 lShouldIndexNonIATAPOR,
139 lShouldIndexPORInXapian,
140 lShouldAddPORInSQLDB);
147 opentrepService.insertIntoDBAndXapian();
149 BOOST_CHECK_MESSAGE (nbOfEntries == 9,
150 "The Xapian index ('" << lTravelDBFilePath
151 <<
"') contains " << nbOfEntries
152 <<
" entries, where as 9 are expected.");
155 logOutputFile.close();
168 BOOST_REQUIRE (lDefaultParams.find (
"dbname") != lDefaultParams.end());
169 BOOST_REQUIRE (lDefaultParams.find (
"host") != lDefaultParams.end());
170 BOOST_CHECK_EQUAL (lDefaultParams.find (
"dbname")->second,
"trep");
171 BOOST_CHECK_EQUAL (lDefaultParams.find (
"host")->second,
"localhost");
178 BOOST_REQUIRE (lDeploymentParams.find (
"dbname") != lDeploymentParams.end());
179 BOOST_REQUIRE (lDeploymentParams.find (
"host") != lDeploymentParams.end());
180 BOOST_CHECK_EQUAL (lDeploymentParams.find (
"dbname")->second,
"trep0");
181 BOOST_CHECK_EQUAL (lDeploymentParams.find (
"host")->second,
"localhost");
189 std::ifstream lPORFile (K_POR_FILEPATH.c_str());
190 BOOST_REQUIRE (lPORFile.good());
193 std::string lPORRecord;
194 std::getline (lPORFile, lHeader);
195 std::getline (lPORFile, lPORRecord);
197 const std::string lOriginalAltName (
"ja|ケプラヴィーク国際空港|");
198 const std::string lAltNameWithEquals (
"ja|ケプラ=ヴィーク国際空港|");
199 const std::string::size_type lAltNamePos =
200 lPORRecord.find (lOriginalAltName);
201 BOOST_REQUIRE (lAltNamePos != std::string::npos);
202 lPORRecord.replace (lAltNamePos, lOriginalAltName.size(),
207 BOOST_CHECK_EQUAL (lLocation.
getIataCode(),
"KEF");
218 std::ifstream lPORFile (K_POR_FILEPATH_QSW.c_str());
219 BOOST_REQUIRE (lPORFile.good());
222 std::string lPORRecord;
223 std::getline (lPORFile, lHeader);
224 std::getline (lPORFile, lPORRecord);
225 BOOST_REQUIRE (lPORRecord.find (
"ja|アス=スワイダ|") != std::string::npos);
229 BOOST_CHECK_EQUAL (lLocation.
getIataCode(),
"QSW");
234 BOOST_CHECK (std::find (lJapaneseNames.begin(), lJapaneseNames.end(),
235 "アス=スワイダ") != lJapaneseNames.end());
240 BOOST_CHECK (std::find (lJavaneseNames.begin(), lJavaneseNames.end(),
241 "As-Suwayda") != lJavaneseNames.end());
249 std::ifstream lPORFile (K_POR_FILEPATH.c_str());
250 BOOST_REQUIRE (lPORFile.good());
253 std::string lPORRecord;
254 std::getline (lPORFile, lHeader);
255 std::getline (lPORFile, lPORRecord);
257 std::vector<std::string> lFields;
258 std::stringstream lRecordStream (lPORRecord);
260 while (std::getline (lRecordStream, lField,
'^')) {
261 lFields.push_back (lField);
263 BOOST_REQUIRE (lFields.size() == 51);
265 lFields[47] =
"AUBWS|=AUWW3|";
267 std::ostringstream lModifiedRecord;
268 for (std::vector<std::string>::const_iterator itField = lFields.begin();
269 itField != lFields.end(); ++itField) {
270 if (itField != lFields.begin()) {
271 lModifiedRecord <<
'^';
273 lModifiedRecord << *itField;
278 BOOST_CHECK_EQUAL (lLocation.
getIataCode(),
"KEF");
286 std::ifstream lPORFile (K_POR_FILEPATH.c_str());
287 BOOST_REQUIRE (lPORFile.good());
290 std::string lPORRecord;
291 std::getline (lPORFile, lHeader);
292 std::getline (lPORFile, lPORRecord);
294 const std::string lOriginalAltName (
"ja|ケプラヴィーク国際空港|");
295 const std::string lLongAltName (
"ja|" + std::string (300,
'a') +
"|");
296 const std::string::size_type lAltNamePos =
297 lPORRecord.find (lOriginalAltName);
298 BOOST_REQUIRE (lAltNamePos != std::string::npos);
299 lPORRecord.replace (lAltNamePos, lOriginalAltName.size(), lLongAltName);
301 const std::string lPORFilepath (
"/tmp/opentrep-long-spelling-term.csv");
302 std::ofstream lModifiedPORFile (lPORFilepath.c_str());
303 BOOST_REQUIRE (lModifiedPORFile.good());
304 lModifiedPORFile << lHeader <<
'\n' << lPORRecord <<
'\n';
305 lModifiedPORFile.close();
307 std::ofstream lLogFile (
"/tmp/opentrep-long-spelling-term.log");
314 BOOST_CHECK_EQUAL (lService.insertIntoDBAndXapian(), 1);
318BOOST_AUTO_TEST_SUITE_END()
std::ofstream utfReportStream("PartitionTestSuite_utfresults.xml")
BOOST_AUTO_TEST_CASE(partition_small_string)
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
const std::string X_XAPIAN_DB_FP("/tmp/opentrep/test_traveldb")
const std::string X_SQL_DB_STR("")
const OPENTREP::DeploymentNumber_T X_DEPLOYMENT_NUMBER(0)
std::ofstream utfReportStream("UnicodeTestSuite_utfresults.xml")
Interface for the OPENTREP Services.
std::list< Word_T > WordList_T
const std::string DEFAULT_OPENTREP_PG_CONN_STRING
bool shouldAddPORInSQLDB_T
unsigned int NbOfDBEntries_T
SQLDBConnectionString_T buildPGConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
std::list< std::string > NameList_T
std::list< Location > LocationList_T
bool shouldIndexPORInXapian_T
unsigned short DeploymentNumber_T
StringMap_T parsePGConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
bool shouldIndexNonIATAPOR_T
std::map< const std::string, std::string > StringMap_T
Enumeration of database types.
Structure modelling a (geographical) location.
const IATACode_T & getIataCode() const
bool getNameList(const LanguageCode_T &iLanguageCode, NameList_T &ioNameList) const