Kea: gtest_utils.h Source File

| Kea 3.2.0-git

gtest_utils.h
Go to the documentation of this file.
1// Copyright (C) 2019-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef GTEST_UTILS_H
8#define GTEST_UTILS_H
9
10#include <gtest/gtest.h>
11
12namespace isc {
13namespace test {
14
24#define EXPECT_THROW_MSG(statement,etype,emsg) \
25{ \
26 try { \
27 statement; \
28 ADD_FAILURE() << "no exception, expected: " << #etype; \
29 } catch (const etype& ex) { \
30 EXPECT_EQ(std::string(ex.what()), emsg); \
31 } catch (...) { \
32 ADD_FAILURE() << "wrong exception type thrown, expected: " << #etype; \
33 } \
34} \
35
36
45#define ASSERT_THROW_MSG(statement,etype,emsg) \
46{ \
47 try { \
48 statement; \
49 GTEST_FAIL() << "no exception, expected: " << #etype; \
50 } catch (const etype& ex) { \
51 ASSERT_EQ(std::string(ex.what()), emsg); \
52 } catch (...) { \
53 GTEST_FAIL() << "wrong exception type thrown, expected: " << #etype; \
54 } \
55} \
56
57
61#define EXPECT_NO_THROW_LOG(statement) \
62{ \
63 try { \
64 statement; \
65 } catch (const std::exception& ex) { \
66 ADD_FAILURE() << #statement << " threw type: " << typeid(ex).name() \
67 << ", what: " << ex.what(); \
68 } catch (...) { \
69 ADD_FAILURE() << #statement << "threw non-std::exception"; \
70 } \
71} \
72
73
77#define ASSERT_NO_THROW_LOG(statement) \
78{ \
79 try { \
80 statement; \
81 } catch (const std::exception& ex) { \
82 GTEST_FAIL() << #statement << " threw type: " << typeid(ex).name() \
83 << ", what: " << ex.what(); \
84 } catch (...) { \
85 GTEST_FAIL() << #statement << " threw non-std::exception"; \
86 } \
87} \
88
89
100#ifndef GTEST_SKIP
101#define SKIP_IF(expression) \
102{ \
103 if (expression) { \
104 auto const info = ::testing::UnitTest::GetInstance()->current_test_info(); \
105 std::cerr << "SKIPPING: " << info->test_case_name() << ":" << info->name() \
106 << ": '" << #expression << "' is true" << std::endl; \
107 return; \
108 } \
109}
110#else
111#define SKIP_IF(expression) \
112{ \
113 if (expression) { \
114 auto const info = ::testing::UnitTest::GetInstance()->current_test_info(); \
115 GTEST_SKIP() << "SKIPPING: " << info->test_case_name() << ":" << info->name() \
116 << ": '" << #expression << "' is true"; \
117 } \
118}
119#endif
120
121} // namespace test
122} // namespace isc
123
124#endif // GTEST_UTILS_H
isc::test
Definition env_var_wrapper.cc:14
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18