OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Command-Line Test to Demonstrate How To Test the OpenTREP Project
/
// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
// Boost Unit Test Framework (UTF)
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE IndexBuildingTestSuite
#include <boost/test/unit_test.hpp>
// OpenTrep
#include <opentrep/config/opentrep-paths.hpp>
namespace boost_utf = boost::unit_test;
// (Boost) Unit Test XML Report
std::ofstream utfReportStream ("IndexBuildingTestSuite_utfresults.xml");
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
//boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
}
}
};
// //////////// Constants for the tests ///////////////
const std::string K_POR_FILEPATH (OPENTREP_POR_DATA_DIR
"/test_ori_por_public.csv");
const std::string X_XAPIAN_DB_FP ("/tmp/opentrep/test_traveldb");
const std::string X_SQLITE_DB_FP ("/tmp/opentrep/test_traveldb/ori_por_public.csv");
// /////////////// Main: Unit Test Suite //////////////
// Set the UTF configuration (re-direct the output to a specific file)
// Start the test suite
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (opentrep_simple_index) {
// Output log File
std::string lLogFilename ("IndexBuildingTestSuite.log");
// Set the log parameters
std::ofstream logOutputFile;
// Open and clean the log outputfile
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
// Initialise the context
const OPENTREP::PORFilePath_T lPORFilePath (K_POR_FILEPATH);
const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (X_XAPIAN_DB_FP);
const OPENTREP::SQLiteDBFilePath_T lSQLiteDBFilePath (X_SQLITE_DB_FP);
OPENTREP::OPENTREP_Service opentrepService (logOutputFile, lPORFilePath,
lTravelDBFilePath,
lSQLiteDBFilePath);
// Query the Xapian database (index)
OPENTREP::WordList_T lNonMatchedWordList;
OPENTREP::LocationList_T lLocationList;
// Launch the indexation
const OPENTREP::NbOfDBEntries_T nbOfEntries =
opentrepService.buildSearchIndex();
BOOST_CHECK_MESSAGE (nbOfEntries == 9,
"The Xapian index ('" << lTravelDBFilePath
<< "') contains " << nbOfEntries
<< " entries, where as 9 are expected.");
// Close the Log outputFile
logOutputFile.close();
}
// End the test suite
BOOST_AUTO_TEST_SUITE_END()