diff --git a/src/utils/CommunicatorManager.hpp b/src/utils/CommunicatorManager.hpp index df0ea8dba61b7ab51f9dd5819a9a20c9eca684ec..a03620a6001e09b61a716b4c558df9884ed8c652 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 c3a25aec9b243afb7e5bd9b951286f322606099b..5de31be8502855954d5bb7d9e037d6bb6dd30ae1 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 0000000000000000000000000000000000000000..56b76b2610a49dc84800bb777af29293e751eec4 --- /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 +}