/
#include <algorithm>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE IndexBuildingTestSuite
#include <boost/test/unit_test.hpp>
#include <opentrep/config/opentrep-paths.hpp>
namespace boost_utf = boost::unit_test;
#if defined(BOOST_VERSION) && BOOST_VERSION >= 105900
boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
#else
boost_utf::unit_test_log.set_format (boost_utf::XML);
#endif
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
}
};
const std::string K_POR_FILEPATH (OPENTREP_POR_DATA_DIR
"/csv/test-optd-por-public.csv");
const std::string K_POR_FILEPATH_QSW (OPENTREP_POR_DATA_DIR
"/csv/test-optd-por-qsw-as-suwayda.csv");
BOOST_AUTO_TEST_SUITE (master_test_suite)
std::string lLogFilename ("IndexBuildingTestSuite.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
lTravelDBFilePath,
lDBType, lSQLDBConnStr,
lDeploymentNumber,
lShouldIndexNonIATAPOR,
lShouldIndexPORInXapian,
lShouldAddPORInSQLDB);
opentrepService.insertIntoDBAndXapian();
BOOST_CHECK_MESSAGE (nbOfEntries == 9,
"The Xapian index ('" << lTravelDBFilePath
<< "') contains " << nbOfEntries
<< " entries, where as 9 are expected.");
logOutputFile.close();
}
BOOST_REQUIRE (lDefaultParams.find ("dbname") != lDefaultParams.end());
BOOST_REQUIRE (lDefaultParams.find ("host") != lDefaultParams.end());
BOOST_CHECK_EQUAL (lDefaultParams.find ("dbname")->second, "trep");
BOOST_CHECK_EQUAL (lDefaultParams.find ("host")->second, "localhost");
BOOST_REQUIRE (lDeploymentParams.find ("dbname") != lDeploymentParams.end());
BOOST_REQUIRE (lDeploymentParams.find ("host") != lDeploymentParams.end());
BOOST_CHECK_EQUAL (lDeploymentParams.find ("dbname")->second, "trep0");
BOOST_CHECK_EQUAL (lDeploymentParams.find ("host")->second, "localhost");
}
std::ifstream lPORFile (K_POR_FILEPATH.c_str());
BOOST_REQUIRE (lPORFile.good());
std::string lHeader;
std::string lPORRecord;
std::getline (lPORFile, lHeader);
std::getline (lPORFile, lPORRecord);
const std::string lOriginalAltName ("ja|ケプラヴィーク国際空港|");
const std::string lAltNameWithEquals ("ja|ケプラ=ヴィーク国際空港|");
const std::string::size_type lAltNamePos =
lPORRecord.find (lOriginalAltName);
BOOST_REQUIRE (lAltNamePos != std::string::npos);
lPORRecord.replace (lAltNamePos, lOriginalAltName.size(),
lAltNameWithEquals);
}
std::ifstream lPORFile (K_POR_FILEPATH_QSW.c_str());
BOOST_REQUIRE (lPORFile.good());
std::string lHeader;
std::string lPORRecord;
std::getline (lPORFile, lHeader);
std::getline (lPORFile, lPORRecord);
BOOST_REQUIRE (lPORRecord.find ("ja|アス=スワイダ|") != std::string::npos);
lJapaneseNames));
BOOST_CHECK (std::find (lJapaneseNames.begin(), lJapaneseNames.end(),
"アス=スワイダ") != lJapaneseNames.end());
lJavaneseNames));
BOOST_CHECK (std::find (lJavaneseNames.begin(), lJavaneseNames.end(),
"As-Suwayda") != lJavaneseNames.end());
}
std::ifstream lPORFile (K_POR_FILEPATH.c_str());
BOOST_REQUIRE (lPORFile.good());
std::string lHeader;
std::string lPORRecord;
std::getline (lPORFile, lHeader);
std::getline (lPORFile, lPORRecord);
std::vector<std::string> lFields;
std::stringstream lRecordStream (lPORRecord);
std::string lField;
while (std::getline (lRecordStream, lField, '^')) {
lFields.push_back (lField);
}
BOOST_REQUIRE (lFields.size() == 51);
lFields[43] = "";
lFields[47] = "AUBWS|=AUWW3|";
std::ostringstream lModifiedRecord;
for (std::vector<std::string>::const_iterator itField = lFields.begin();
itField != lFields.end(); ++itField) {
if (itField != lFields.begin()) {
lModifiedRecord << '^';
}
lModifiedRecord << *itField;
}
}
std::ifstream lPORFile (K_POR_FILEPATH.c_str());
BOOST_REQUIRE (lPORFile.good());
std::string lHeader;
std::string lPORRecord;
std::getline (lPORFile, lHeader);
std::getline (lPORFile, lPORRecord);
const std::string lOriginalAltName ("ja|ケプラヴィーク国際空港|");
const std::string lLongAltName ("ja|" + std::string (300, 'a') + "|");
const std::string::size_type lAltNamePos =
lPORRecord.find (lOriginalAltName);
BOOST_REQUIRE (lAltNamePos != std::string::npos);
lPORRecord.replace (lAltNamePos, lOriginalAltName.size(), lLongAltName);
const std::string lPORFilepath ("/tmp/opentrep-long-spelling-term.csv");
std::ofstream lModifiedPORFile (lPORFilepath.c_str());
BOOST_REQUIRE (lModifiedPORFile.good());
lModifiedPORFile << lHeader << '\n' << lPORRecord << '\n';
lModifiedPORFile.close();
std::ofstream lLogFile ("/tmp/opentrep-long-spelling-term.log");
BOOST_CHECK_EQUAL (lService.insertIntoDBAndXapian(), 1);
}
BOOST_AUTO_TEST_SUITE_END()