From f95594d7a96e0802b06ed0dccd33a301ffbf568f Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Thu, 11 Feb 2021 16:11:48 +0100 Subject: [PATCH] iox-#542 call counter instead of bool Signed-off-by: Christian Eltzschig --- .../moduletests/test_cxx_generic_raii.cpp | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/iceoryx_utils/test/moduletests/test_cxx_generic_raii.cpp b/iceoryx_utils/test/moduletests/test_cxx_generic_raii.cpp index 129936db59..3909e7c6ce 100644 --- a/iceoryx_utils/test/moduletests/test_cxx_generic_raii.cpp +++ b/iceoryx_utils/test/moduletests/test_cxx_generic_raii.cpp @@ -34,101 +34,101 @@ class GenericRAII_test : public Test TEST_F(GenericRAII_test, InitFunctionIsCalledInCtorWhenSet) { - bool hasCalledInit = false; - GenericRAII sut([&] { hasCalledInit = true; }, std::function()); - EXPECT_TRUE(hasCalledInit); + int hasCalledInit = 0; + GenericRAII sut([&] { ++hasCalledInit; }, std::function()); + EXPECT_THAT(hasCalledInit, Eq(1)); } TEST_F(GenericRAII_test, InitFunctionIsCalledInCtorWhenSetWithCleanupFunction) { - bool hasCalledInit = false; - bool hasCalledCleanup = false; - GenericRAII sut([&] { hasCalledInit = true; }, [&] { hasCalledCleanup = true; }); - EXPECT_TRUE(hasCalledInit); + int hasCalledInit = 0; + int hasCalledCleanup = 0; + GenericRAII sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); + EXPECT_THAT(hasCalledInit, Eq(1)); } TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtor) { - bool hasCalledInit = false; - bool hasCalledCleanup = false; + int hasCalledInit = 0; + int hasCalledCleanup = 0; { - GenericRAII sut([&] { hasCalledInit = true; }, [&] { hasCalledCleanup = true; }); + GenericRAII sut([&] { ++hasCalledInit; }, [&] { ++hasCalledCleanup; }); } - EXPECT_TRUE(hasCalledInit); - EXPECT_TRUE(hasCalledCleanup); + EXPECT_THAT(hasCalledInit, Eq(1)); + EXPECT_THAT(hasCalledCleanup, Eq(1)); } TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtorWhenUsingCleanupOnlyCTor) { - bool hasCalledCleanup = false; + int hasCalledCleanup = 0; { GenericRAII sut([&] { hasCalledCleanup = true; }); } - EXPECT_TRUE(hasCalledCleanup); + EXPECT_THAT(hasCalledCleanup, Eq(1)); } TEST_F(GenericRAII_test, CleanupFunctionIsCalledInDtorWithEmptyInitFunction) { - bool hasCalledCleanup = false; + int hasCalledCleanup = 0; { - GenericRAII sut(std::function(), [&] { hasCalledCleanup = true; }); + GenericRAII sut(std::function(), [&] { ++hasCalledCleanup; }); } - EXPECT_TRUE(hasCalledCleanup); + EXPECT_THAT(hasCalledCleanup, Eq(1)); } TEST_F(GenericRAII_test, MoveCTorDoesNotCallCleanupFunctionOfOrigin) { - bool hasCalledCleanup = false; + int hasCalledCleanup = 0; - GenericRAII sut([&] { hasCalledCleanup = true; }); + GenericRAII sut([&] { ++hasCalledCleanup; }); GenericRAII sut2(std::move(sut)); - EXPECT_FALSE(hasCalledCleanup); + EXPECT_THAT(hasCalledCleanup, Eq(0)); } TEST_F(GenericRAII_test, MoveConstructedDoesCallCleanupFunctionWhenDestroyed) { - bool hasCalledCleanup = false; + int hasCalledCleanup = 0; { - GenericRAII sut([&] { hasCalledCleanup = true; }); + GenericRAII sut([&] { ++hasCalledCleanup; }); GenericRAII sut2(std::move(sut)); } - EXPECT_TRUE(hasCalledCleanup); + EXPECT_THAT(hasCalledCleanup, Eq(1)); } TEST_F(GenericRAII_test, MoveAssignmentCallsCleanup) { - bool hasCalledCleanup = false; - bool hasCalledCleanup2 = false; + int hasCalledCleanup = 0; + int hasCalledCleanup2 = 0; - GenericRAII sut([&] { hasCalledCleanup = true; }); - GenericRAII sut2([&] { hasCalledCleanup2 = true; }); + GenericRAII sut([&] { ++hasCalledCleanup; }); + GenericRAII sut2([&] { ++hasCalledCleanup2; }); sut = std::move(sut2); - EXPECT_TRUE(hasCalledCleanup); + EXPECT_THAT(hasCalledCleanup, Eq(1)); } TEST_F(GenericRAII_test, MoveAssignedCallsCleanupWhenOutOfScope) { - bool hasCalledCleanup = false; - bool hasCalledCleanup2 = false; + int hasCalledCleanup = 0; + int hasCalledCleanup2 = 0; { - GenericRAII sut([&] { hasCalledCleanup = true; }); - GenericRAII sut2([&] { hasCalledCleanup2 = true; }); + GenericRAII sut([&] { ++hasCalledCleanup; }); + GenericRAII sut2([&] { ++hasCalledCleanup2; }); sut = std::move(sut2); } - EXPECT_TRUE(hasCalledCleanup); - EXPECT_TRUE(hasCalledCleanup2); + EXPECT_THAT(hasCalledCleanup, Eq(1)); + EXPECT_THAT(hasCalledCleanup2, Eq(1)); }