///
/// @param hooks Collection of known hook names.
/// @param num_libraries Number of loaded libraries.
+ ///
+ /// @throw isc::BadValue if the number of libraries is less than or equal
+ /// to 0, or if the pointer to the server hooks object is empty.
CalloutManager(const boost::shared_ptr<ServerHooks>& hooks,
int num_libraries)
: current_library_(-1), hooks_(hooks), hook_vector_(hooks->getCount()),
library_handle_(this), num_libraries_(num_libraries)
- {}
+ {
+ if (!hooks) {
+ isc_throw(isc::BadValue, "must pass a pointer to a valid server "
+ "hooks object to the CalloutManager");
+ } else if (num_libraries <= 0) {
+ isc_throw(isc::BadValue, "number of libraries passed to the "
+ "CalloutManager must be >= 0");
+ }
+ }
/// @brief Register a callout on a hook
///
/// @return Status return.
int callCallouts(int hook_index, CalloutHandle& callout_handle);
+ /// @brief Get number of libraries
+ ///
+ /// Returns the number of libraries that this CalloutManager is expected
+ /// to serve. This is the number passed to its constructor.
+ ///
+ /// @return Number of libraries server by this CalloutManager.
+ int getNumLibraries() const {
+ return (num_libraries_);
+ }
+
/// @brief Get current library index
///
/// Returns the index of the "current" library. This the index associated
#include <util/hooks/library_handle.h>
#include <util/hooks/server_hooks.h>
+#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
#include <algorithm>
return (callout_manager_);
}
+ boost::shared_ptr<ServerHooks> getServerHooks() {
+ return (hooks_);
+ }
+
/// Static variable used for accumulating information
static int callout_value_;
int delta_index_;
private:
+ /// Callout handle used in calls
+ boost::shared_ptr<CalloutHandle> callout_handle_;
+
/// Callout manager used for the test
boost::shared_ptr<CalloutManager> callout_manager_;
/// Server hooks
boost::shared_ptr<ServerHooks> hooks_;
-
- /// Callout handle used in calls
- boost::shared_ptr<CalloutHandle> callout_handle_;
-
-
};
// Definition of the static variable.
}; // extern "C"
+// Constructor - check that we trap bad parameters.
+
+TEST_F(CalloutManagerTest, BadConstructorParameters) {
+ boost::scoped_ptr<CalloutManager> cm;
+
+ // Invalid number of libraries
+ EXPECT_THROW(cm.reset(new CalloutManager(getServerHooks(), 0)), BadValue);
+ EXPECT_THROW(cm.reset(new CalloutManager(getServerHooks(), -1)), BadValue);
+
+ // Invalid server hooks pointer.
+ boost::shared_ptr<ServerHooks> sh;
+ EXPECT_THROW(cm.reset(new CalloutManager(sh, 4)), BadValue);
+}
+
+// Check the number of libraries is reported successfully.
+
+TEST_F(CalloutManagerTest, GetNumLibraries) {
+ boost::scoped_ptr<CalloutManager> cm;
+
+ // Check two valid values of number of libraries to ensure that the
+ // GetNumLibraries() returns the value set.
+ EXPECT_NO_THROW(cm.reset(new CalloutManager(getServerHooks(), 4)));
+ EXPECT_EQ(4, cm->getNumLibraries());
+
+ EXPECT_NO_THROW(cm.reset(new CalloutManager(getServerHooks(), 42)));
+ EXPECT_EQ(42, cm->getNumLibraries());
+}
+
// Check that we can only set the current library index to the correct values.
TEST_F(CalloutManagerTest, CheckLibraryIndex) {