|
@@ -14,6 +14,7 @@
|
|
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
+#include <datasrc/datasrc_config.h>
|
|
|
#include <datasrc/factory.h>
|
|
|
#include <datasrc/data_source.h>
|
|
|
#include <datasrc/sqlite3_accessor.h>
|
|
@@ -30,6 +31,70 @@ std::string SQLITE_DBFILE_EXAMPLE_ORG = TEST_DATA_DIR "/example.org.sqlite3";
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
+// note this helper only checks the error that is received up to the length
|
|
|
+// of the expected string. It will always pass if you give it an empty
|
|
|
+// expected_error
|
|
|
+void
|
|
|
+pathtestHelper(const std::string& file, const std::string& expected_error) {
|
|
|
+ std::string error;
|
|
|
+ try {
|
|
|
+ DataSourceClientContainer(file, ElementPtr());
|
|
|
+ } catch (const DataSourceLibraryError& dsle) {
|
|
|
+ error = dsle.what();
|
|
|
+ }
|
|
|
+ ASSERT_LT(expected_error.size(), error.size());
|
|
|
+ EXPECT_EQ(expected_error, error.substr(0, expected_error.size()));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(FactoryTest, paths) {
|
|
|
+ // Test whether the paths are made absolute if they are not,
|
|
|
+ // by inspecting the error that is raised when they are wrong
|
|
|
+ const std::string error("dlopen failed for ");
|
|
|
+ // With the current implementation, we can safely assume this has
|
|
|
+ // been set for this test (as the loader would otherwise also fail
|
|
|
+ // unless the loadable backend library happens to be installed)
|
|
|
+ const std::string builddir(getenv("B10_FROM_BUILD"));
|
|
|
+
|
|
|
+ // Absolute and ending with .so should have no change
|
|
|
+ pathtestHelper("/no_such_file.so", error + "/no_such_file.so");
|
|
|
+
|
|
|
+ // If no ending in .so, it should get _ds.so
|
|
|
+ pathtestHelper("/no_such_file", error + "/no_such_file_ds.so");
|
|
|
+
|
|
|
+ // If not starting with /, path should be added. For this test that
|
|
|
+ // means the build directory as set in B10_FROM_BUILD
|
|
|
+ pathtestHelper("no_such_file.so", error + builddir +
|
|
|
+ "/src/lib/datasrc/.libs/no_such_file.so");
|
|
|
+ pathtestHelper("no_such_file", error + builddir +
|
|
|
+ "/src/lib/datasrc/.libs/no_such_file_ds.so");
|
|
|
+
|
|
|
+ // Some tests with '.so' in the name itself
|
|
|
+ pathtestHelper("no_such_file.so.something", error + builddir +
|
|
|
+ "/src/lib/datasrc/.libs/no_such_file.so.something_ds.so");
|
|
|
+ pathtestHelper("/no_such_file.so.something", error +
|
|
|
+ "/no_such_file.so.something_ds.so");
|
|
|
+ pathtestHelper("/no_such_file.so.something.so", error +
|
|
|
+ "/no_such_file.so.something.so");
|
|
|
+ pathtestHelper("/no_such_file.so.so", error +
|
|
|
+ "/no_such_file.so.so");
|
|
|
+ pathtestHelper("no_such_file.so.something", error + builddir +
|
|
|
+ "/src/lib/datasrc/.libs/no_such_file.so.something_ds.so");
|
|
|
+
|
|
|
+ // Temporarily unset B10_FROM_BUILD to see that BACKEND_LIBRARY_PATH
|
|
|
+ // is used
|
|
|
+ unsetenv("B10_FROM_BUILD");
|
|
|
+ pathtestHelper("no_such_file.so", error + BACKEND_LIBRARY_PATH +
|
|
|
+ "no_such_file.so");
|
|
|
+ // Put it back just in case
|
|
|
+ setenv("B10_FROM_BUILD", builddir.c_str(), 1);
|
|
|
+
|
|
|
+ // Test some bad input values
|
|
|
+ ASSERT_THROW(DataSourceClientContainer("", ElementPtr()),
|
|
|
+ DataSourceLibraryError);
|
|
|
+ ASSERT_THROW(DataSourceClientContainer(".so", ElementPtr()),
|
|
|
+ DataSourceLibraryError);
|
|
|
+}
|
|
|
+
|
|
|
TEST(FactoryTest, sqlite3ClientBadConfig) {
|
|
|
// We start out by building the configuration data bit by bit,
|
|
|
// testing each form of 'bad config', until we have a good one.
|