File: assert_debug_test.cpp

package info (click to toggle)
cryfs 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,404 kB
  • sloc: cpp: 150,188; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (62 lines) | stat: -rw-r--r-- 1,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <gtest/gtest.h>
#include <gmock/gmock.h>

#ifdef NDEBUG
#define REAL_NDEBUG_
#endif

//Include the ASSERT macro for a debug build
#undef NDEBUG
#include "cpp-utils/assert/assert.h"


TEST(AssertTest_DebugBuild, DoesntDieIfTrue) {
    ASSERT(true, "bla");
}

TEST(AssertTest_DebugBuild, DiesIfFalse) {
    testing::FLAGS_gtest_death_test_style = "threadsafe";
    EXPECT_DEATH(
      ASSERT(false, "bla"),
      ""
    );
}

TEST(AssertTest_DebugBuild, whenDisablingAbort_thenThrowsIfFalse) {
    const cpputils::_assert::DisableAbortOnFailedAssertionRAII _disableAbort;
    EXPECT_THROW(
        ASSERT(false, "bla"),
        cpputils::AssertFailed
    );
}

TEST(AssertTest_DebugBuild, AssertMessage) {
    testing::FLAGS_gtest_death_test_style = "threadsafe";
#if defined(_MSC_VER)
    constexpr const char* EXPECTED = R"(Assertion \[2==5\] failed in .*assert_debug_test.cpp:\d+: my message)";
#else
    constexpr const char* EXPECTED = R"(Assertion \[2==5\] failed in .*assert_debug_test.cpp:[0-9]+: my message)";
#endif
    EXPECT_DEATH(
      ASSERT(2==5, "my message"),
		EXPECTED
    );
}

#if !(defined(_MSC_VER) && defined(REAL_NDEBUG_))
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
    testing::FLAGS_gtest_death_test_style = "threadsafe";
    EXPECT_DEATH(
        ASSERT(2==5, "my message"),
        "cpputils::"
    );
}
#else
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
    testing::FLAGS_gtest_death_test_style = "threadsafe";
    EXPECT_DEATH(
        ASSERT(2==5, "my message"),
        "#1"
    );
}
#endif