]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#562] add LibLoadTest fixture
authorAndrei Pavel <andrei@isc.org>
Thu, 19 May 2022 09:58:31 +0000 (12:58 +0300)
committerAndrei Pavel <andrei@isc.org>
Fri, 20 May 2022 17:40:46 +0000 (20:40 +0300)
src/lib/testutils/Makefile.am
src/lib/testutils/lib_load_test_fixture.h [new file with mode: 0644]

index 30332da54810bd7c83ec99291ba48c83605d7f9b..03d78fbab169f6d8c0aeaa471e32b6c49c07df42 100644 (file)
@@ -16,6 +16,7 @@ libkea_testutils_la_SOURCES += unix_control_client.cc unix_control_client.h
 libkea_testutils_la_SOURCES += user_context_utils.cc user_context_utils.h
 libkea_testutils_la_SOURCES += gtest_utils.h
 libkea_testutils_la_SOURCES += multi_threading_utils.h
+libkea_testutils_la_SOURCES += lib_load_test_fixture.h
 libkea_testutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 libkea_testutils_la_LIBADD  = $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
 libkea_testutils_la_LIBADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
diff --git a/src/lib/testutils/lib_load_test_fixture.h b/src/lib/testutils/lib_load_test_fixture.h
new file mode 100644 (file)
index 0000000..3fe73ae
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H
+#define ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H
+
+#include <cc/data.h>
+
+#include <gtest/gtest.h>
+
+namespace isc {
+namespace hooks {
+
+/// @brief Test fixture for testing loading and unloading of hook libraries.
+struct LibLoadTest : ::testing::Test {
+    /// @brief Constructor. Unloads any previously loaded libraries.
+    LibLoadTest() {
+        unloadLibraries();
+    }
+
+    /// @brief Destructor. Unloads any previously loaded libraries.
+    ~LibLoadTest() {
+        unloadLibraries();
+    }
+
+    /// @brief Adds a library along with its parameters to the list of libraries to be loaded.
+    ///
+    /// @param library the path to the library to be loaded
+    /// @param parameters the library's parameters in Element format
+    void addLibrary(const std::string& library, isc::data::ConstElementPtr parameters) {
+        libraries_.push_back({library, parameters});
+    }
+
+    void clearLibraries() {
+        libraries_.clear();
+    }
+
+    /// @brief Load all libraries.
+    ///
+    /// @return true if all libraries loaded succesfully, false if one or more
+    ///     libraries failed to load.
+    bool loadLibraries() {
+        bool result;
+        EXPECT_NO_THROW(result = HooksManager::loadLibraries(libraries_));
+        return result;
+    }
+
+    /// @brief Unloads all libraries.
+    ///
+    /// @return true if all libraries unloaded successfully, false if they
+    ///     are still in memory.
+    bool unloadLibraries() {
+        bool result;
+        EXPECT_NO_THROW(result = HooksManager::unloadLibraries());
+        return result;
+    }
+
+    /// @brief Libraries
+    HookLibsCollection libraries_;
+};
+
+}  // namespace hooks
+}  // namespace isc
+
+#endif  // ISC_TESTUTILS_LIB_LOAD_TEST_FIXTURE_H