From 94de7d3da08b336beaacf9817c403200ec0a581c Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Thu, 19 May 2022 12:58:31 +0300 Subject: [PATCH] [#562] add LibLoadTest fixture --- src/lib/testutils/Makefile.am | 1 + src/lib/testutils/lib_load_test_fixture.h | 68 +++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/lib/testutils/lib_load_test_fixture.h diff --git a/src/lib/testutils/Makefile.am b/src/lib/testutils/Makefile.am index 30332da548..03d78fbab1 100644 --- a/src/lib/testutils/Makefile.am +++ b/src/lib/testutils/Makefile.am @@ -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 index 0000000000..3fe73ae20f --- /dev/null +++ b/src/lib/testutils/lib_load_test_fixture.h @@ -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 + +#include + +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 -- 2.47.3