Kea  1.9.9-git
gtest_utils.h
Go to the documentation of this file.
1 // Copyright (C) 2019 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 
12 namespace isc {
13 namespace 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 #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 #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 #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 }; // end of isc::test namespace
90 }; // end of isc namespace
91 
92 #endif // GTEST_UTILS_H
Defines the logger used by the top-level component of kea-dhcp-ddns.