From 2fbcc0a55d2e593207081e3bcad70abc0cc3bfa4 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 1 Nov 2024 14:01:21 +0100 Subject: [PATCH] Add tests for CommunicatorManager --- src/utils/CommunicatorManager.hpp | 2 ++ tests/CMakeLists.txt | 1 + tests/test_CommunicatorManager.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/test_CommunicatorManager.cpp diff --git a/src/utils/CommunicatorManager.hpp b/src/utils/CommunicatorManager.hpp index df0ea8dba..a03620a60 100644 --- a/src/utils/CommunicatorManager.hpp +++ b/src/utils/CommunicatorManager.hpp @@ -8,6 +8,8 @@ class CommunicatorManager private: static std::optional<int> s_split_color; + friend void resetCommunicationManagerForTests(); + public: static bool hasSplitColor(); static int splitColor(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c3a25aec9..5de31be85 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,6 +61,7 @@ add_executable (unit_tests test_CastArray.cpp test_CellIntegrator.cpp test_CellType.cpp + test_CommunicatorManager.cpp test_ConsoleManager.cpp test_CG.cpp test_ConcatExpressionProcessor.cpp diff --git a/tests/test_CommunicatorManager.cpp b/tests/test_CommunicatorManager.cpp new file mode 100644 index 000000000..56b76b261 --- /dev/null +++ b/tests/test_CommunicatorManager.cpp @@ -0,0 +1,29 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <utils/CommunicatorManager.hpp> + +// clazy:excludeall=non-pod-global-static + +inline void +resetCommunicationManagerForTests() +{ + CommunicatorManager::s_split_color.reset(); +} + +TEST_CASE("CommunicatorManager", "[utils]") +{ + resetCommunicationManagerForTests(); + + REQUIRE(not CommunicatorManager::hasSplitColor()); +#ifndef NDEBUG + REQUIRE_THROWS_WITH(CommunicatorManager::splitColor(), "split color has not been defined"); +#endif // NDEBUG + + REQUIRE_NOTHROW(CommunicatorManager::setSplitColor(2)); + REQUIRE(CommunicatorManager::splitColor() == 2); + +#ifndef NDEBUG + REQUIRE_THROWS_WITH(CommunicatorManager::setSplitColor(2), "split color has already been defined"); +#endif // NDEBUG +} -- GitLab