Browse Source

[2974] Added missing test to LibraryHandle unit tests

Stephen Morris 12 years ago
parent
commit
d219feca60
2 changed files with 22 additions and 5 deletions
  1. 4 5
      src/lib/util/hooks/library_handle.h
  2. 18 0
      src/lib/util/tests/library_handle_unittest.cc

+ 4 - 5
src/lib/util/hooks/library_handle.h

@@ -56,15 +56,14 @@ extern "C" {
 };
 
 
-/// @brief Global Callout Handle
-/// @todo Change name to Library Handle?
+/// @brief Library handle
 ///
 /// This class is used to manage a loaded library.  It is used by the user
 /// library to register callouts and by the HookManager to call them.  The
 /// class also contains storage for library-specific context.
 ///
-/// Although there is an argument for the class to load unload the user
-/// library, that is handled by the HookManager to prevent the user library
+/// Although there is a persuasive argument for the class to load unload the
+/// user library, that is handled by the HookManager to prevent the user library
 /// from accessing those functions.
 
 class LibraryHandle {
@@ -167,7 +166,7 @@ public:
     ///
     /// @return true if callouts are present, false if not.
     ///
-    /// @throw NoSuchHook Thrown if the indesx is not valid.
+    /// @throw NoSuchHook Thrown if the index is not valid.
     bool calloutsPresent(int index) const;
 
     /// @brief Calls the callouts for a given hook

+ 18 - 0
src/lib/util/tests/library_handle_unittest.cc

@@ -444,5 +444,23 @@ TEST_F(LibraryHandleTest, DeregisterAll) {
     EXPECT_FALSE(handle.calloutsPresent(getServerHooks()->getIndex("alpha")));
 }
 
+// Add checks that invalid names etc. all throw.  With the base hooks added
+// by the constructor, there are five valid hooks, with valid indexes 0 to 4.
+
+TEST_F(LibraryHandleTest, InvalidNameAndIndex) {
+    LibraryHandle handle(getServerHooks(), 1);
+
+    EXPECT_THROW(handle.registerCallout("omega", one), NoSuchHook);
+    EXPECT_THROW(handle.deregisterCallout("omega", one), NoSuchHook);
+    EXPECT_THROW(handle.deregisterAll("omega"), NoSuchHook);
+
+    EXPECT_THROW(static_cast<void>(handle.calloutsPresent(-1)), NoSuchHook);
+    EXPECT_THROW(static_cast<void>(handle.calloutsPresent(5)), NoSuchHook);
+
+    CalloutHandle dummy;
+    EXPECT_THROW(static_cast<void>(handle.callCallouts(-1, dummy)), NoSuchHook);
+    EXPECT_THROW(static_cast<void>(handle.callCallouts(10, dummy)), NoSuchHook);
+}
+
 
 } // Anonymous namespace