|
@@ -101,16 +101,20 @@ public:
|
|
using LibraryManager::closeLibrary;
|
|
using LibraryManager::closeLibrary;
|
|
using LibraryManager::checkVersion;
|
|
using LibraryManager::checkVersion;
|
|
using LibraryManager::registerStandardCallouts;
|
|
using LibraryManager::registerStandardCallouts;
|
|
|
|
+ using LibraryManager::runLoad;
|
|
};
|
|
};
|
|
|
|
|
|
// Names of the libraries used in these tests. These libraries are built using
|
|
// Names of the libraries used in these tests. These libraries are built using
|
|
// libtool, so we need to look in the hidden ".libs" directory to locate the
|
|
// libtool, so we need to look in the hidden ".libs" directory to locate the
|
|
// .so file. Note that we access the .so file - libtool creates this as a
|
|
// .so file. Note that we access the .so file - libtool creates this as a
|
|
// like to the real shared library.
|
|
// like to the real shared library.
|
|
|
|
+static const char* BASIC_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libbcl.so";
|
|
|
|
+static const char* INCORRECT_VERSION_LIBRARY = "@abs_builddir@/.libs/libivl.so";
|
|
|
|
+static const char* LOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/liblcl.so";
|
|
|
|
+static const char* LOAD_ERROR_CALLOUT_LIBRARY =
|
|
|
|
+ "@abs_builddir@/.libs/liblecl.so";
|
|
static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere.so";
|
|
static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere.so";
|
|
-static const char* NO_VERSION_LIBRARY = "@abs_builddir@/.libs/libnv.so";
|
|
|
|
-static const char* INCORRECT_VERSION_LIBRARY = "@abs_builddir@/.libs/libiv.so";
|
|
|
|
-static const char* BASIC_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libbco.so";
|
|
|
|
|
|
+static const char* NO_VERSION_LIBRARY = "@abs_builddir@/.libs/libnvl.so";
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
@@ -213,13 +217,13 @@ TEST_F(LibraryManagerTest, RegisterStandardCallouts) {
|
|
callout_handle_->getArgument("result", result);
|
|
callout_handle_->getArgument("result", result);
|
|
EXPECT_EQ(15, result);
|
|
EXPECT_EQ(15, result);
|
|
|
|
|
|
- // Second callout multiples the context value by 7
|
|
|
|
|
|
+ // Second callout multiples the running total by 7
|
|
callout_handle_->setArgument("data_2", static_cast<int>(7));
|
|
callout_handle_->setArgument("data_2", static_cast<int>(7));
|
|
callout_manager_->callCallouts(lm_two_index_, *callout_handle_);
|
|
callout_manager_->callCallouts(lm_two_index_, *callout_handle_);
|
|
callout_handle_->getArgument("result", result);
|
|
callout_handle_->getArgument("result", result);
|
|
EXPECT_EQ(105, result);
|
|
EXPECT_EQ(105, result);
|
|
|
|
|
|
- // Third callout subtracts 17.
|
|
|
|
|
|
+ // Third callout subtracts 17 from the running total.
|
|
callout_handle_->setArgument("data_3", static_cast<int>(17));
|
|
callout_handle_->setArgument("data_3", static_cast<int>(17));
|
|
callout_manager_->callCallouts(lm_three_index_, *callout_handle_);
|
|
callout_manager_->callCallouts(lm_three_index_, *callout_handle_);
|
|
callout_handle_->getArgument("result", result);
|
|
callout_handle_->getArgument("result", result);
|
|
@@ -233,4 +237,94 @@ TEST_F(LibraryManagerTest, RegisterStandardCallouts) {
|
|
EXPECT_TRUE(lib_manager.closeLibrary());
|
|
EXPECT_TRUE(lib_manager.closeLibrary());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Test that the "load" function is called correctly.
|
|
|
|
+
|
|
|
|
+TEST_F(LibraryManagerTest, CheckLoadCalled) {
|
|
|
|
+
|
|
|
|
+ // Load the only library, specifying the index of 0 as it's the only
|
|
|
|
+ // library. This should load all callouts.
|
|
|
|
+ PublicLibraryManager lib_manager(std::string(LOAD_CALLOUT_LIBRARY),
|
|
|
|
+ 0, callout_manager_);
|
|
|
|
+ EXPECT_TRUE(lib_manager.openLibrary());
|
|
|
|
+
|
|
|
|
+ // Check the version of the library.
|
|
|
|
+ EXPECT_TRUE(lib_manager.checkVersion());
|
|
|
|
+
|
|
|
|
+ // Load the standard callouts
|
|
|
|
+ EXPECT_NO_THROW(lib_manager.registerStandardCallouts());
|
|
|
|
+
|
|
|
|
+ int result = 0;
|
|
|
|
+
|
|
|
|
+ // Check that only context_create and lm_one have callouts registered.
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(
|
|
|
|
+ ServerHooks::CONTEXT_CREATE));
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(lm_one_index_));
|
|
|
|
+ EXPECT_FALSE(callout_manager_->calloutsPresent(lm_two_index_));
|
|
|
|
+ EXPECT_FALSE(callout_manager_->calloutsPresent(lm_three_index_));
|
|
|
|
+ EXPECT_FALSE(callout_manager_->calloutsPresent(
|
|
|
|
+ ServerHooks::CONTEXT_DESTROY));
|
|
|
|
+
|
|
|
|
+ // Call the runLoad() method to run the load() function.
|
|
|
|
+ EXPECT_TRUE(lib_manager.runLoad());
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(
|
|
|
|
+ ServerHooks::CONTEXT_CREATE));
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(lm_one_index_));
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(lm_two_index_));
|
|
|
|
+ EXPECT_TRUE(callout_manager_->calloutsPresent(lm_three_index_));
|
|
|
|
+ EXPECT_FALSE(callout_manager_->calloutsPresent(
|
|
|
|
+ ServerHooks::CONTEXT_DESTROY));
|
|
|
|
+
|
|
|
|
+ // Now execute the callouts in the order expected.
|
|
|
|
+ // only the first callout should be executed and the
|
|
|
|
+ // always comes first. This sets the context value to 10.
|
|
|
|
+ callout_manager_->callCallouts(ServerHooks::CONTEXT_CREATE,
|
|
|
|
+ *callout_handle_);
|
|
|
|
+
|
|
|
|
+ // First callout multiplies the passed data by 5.
|
|
|
|
+ callout_handle_->setArgument("data_1", static_cast<int>(5));
|
|
|
|
+ callout_manager_->callCallouts(lm_one_index_, *callout_handle_);
|
|
|
|
+ callout_handle_->getArgument("result", result);
|
|
|
|
+ EXPECT_EQ(25, result);
|
|
|
|
+
|
|
|
|
+ // Second callout adds 7 to the stored data.
|
|
|
|
+ callout_handle_->setArgument("data_2", static_cast<int>(7));
|
|
|
|
+ callout_manager_->callCallouts(lm_two_index_, *callout_handle_);
|
|
|
|
+ callout_handle_->getArgument("result", result);
|
|
|
|
+ EXPECT_EQ(32, result);
|
|
|
|
+
|
|
|
|
+ // Third callout multiplies the running total by 10
|
|
|
|
+ callout_handle_->setArgument("data_3", static_cast<int>(10));
|
|
|
|
+ callout_manager_->callCallouts(lm_three_index_, *callout_handle_);
|
|
|
|
+ callout_handle_->getArgument("result", result);
|
|
|
|
+ EXPECT_EQ(320, result);
|
|
|
|
+
|
|
|
|
+ // Explicitly clear the callout_handle_ so that we can delete the library.
|
|
|
|
+ // This is the only object to contain memory allocated by it.
|
|
|
|
+ callout_handle_.reset();
|
|
|
|
+
|
|
|
|
+ // Tidy up
|
|
|
|
+ EXPECT_TRUE(lib_manager.closeLibrary());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Check handling of a "load" function that returns an error.
|
|
|
|
+
|
|
|
|
+TEST_F(LibraryManagerTest, CheckLoadError) {
|
|
|
|
+
|
|
|
|
+ // Load the only library, specifying the index of 0 as it's the only
|
|
|
|
+ // library. This should load all callouts.
|
|
|
|
+ PublicLibraryManager lib_manager(std::string(LOAD_ERROR_CALLOUT_LIBRARY),
|
|
|
|
+ 0, callout_manager_);
|
|
|
|
+ EXPECT_TRUE(lib_manager.openLibrary());
|
|
|
|
+
|
|
|
|
+ // Check that we catch a load error
|
|
|
|
+ EXPECT_FALSE(lib_manager.runLoad());
|
|
|
|
+
|
|
|
|
+ // Explicitly clear the callout_handle_ so that we can delete the library.
|
|
|
|
+ // This is the only object to contain memory allocated by it.
|
|
|
|
+ callout_handle_.reset();
|
|
|
|
+
|
|
|
|
+ // Tidy up
|
|
|
|
+ EXPECT_TRUE(lib_manager.closeLibrary());
|
|
|
|
+}
|
|
|
|
+
|
|
} // Anonymous namespace
|
|
} // Anonymous namespace
|