Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gtest-spi.h
Go to the documentation of this file.
1// Copyright 2007, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Author: wan@google.com (Zhanyong Wan)
31//
32// Utilities for testing Google Test itself and code that uses Google Test
33// (e.g. frameworks built on top of Google Test).
34
35#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
36#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
37
38#include "gtest/gtest.h"
39
40namespace testing {
41
42// This helper class can be used to mock out Google Test failure reporting
43// so that we can test Google Test or code that builds on Google Test.
44//
45// An object of this class appends a TestPartResult object to the
46// TestPartResultArray object given in the constructor whenever a Google Test
47// failure is reported. It can either intercept only failures that are
48// generated in the same thread that created this object or it can intercept
49// all generated failures. The scope of this mock object can be controlled with
50// the second argument to the two arguments constructor.
53 public:
54 // The two possible mocking modes of this object.
56 INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
57 INTERCEPT_ALL_THREADS // Intercepts all failures.
58 };
59
60 // The c'tor sets this object as the test part result reporter used
61 // by Google Test. The 'result' parameter specifies where to report the
62 // results. This reporter will only catch failures generated in the current
63 // thread. DEPRECATED
65
66 // Same as above, but you can choose the interception scope of this object.
67 ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
68 TestPartResultArray* result);
69
70 // The d'tor restores the previous test part result reporter.
72
73 // Appends the TestPartResult object to the TestPartResultArray
74 // received in the constructor.
75 //
76 // This method is from the TestPartResultReporterInterface
77 // interface.
78 virtual void ReportTestPartResult(const TestPartResult& result);
79 private:
80 void Init();
81
82 const InterceptMode intercept_mode_;
84 TestPartResultArray* const result_;
85
87};
88
89namespace internal {
90
91// A helper class for implementing EXPECT_FATAL_FAILURE() and
92// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
93// TestPartResultArray contains exactly one failure that has the given
94// type and contains the given substring. If that's not the case, a
95// non-fatal failure will be generated.
97 public:
98 // The constructor remembers the arguments.
100 TestPartResult::Type type, const std::string& substr);
102 private:
103 const TestPartResultArray* const results_;
104 const TestPartResult::Type type_;
105 const std::string substr_;
106
108};
109
110} // namespace internal
111
112} // namespace testing
113
114// A set of macros for testing Google Test assertions or code that's expected
115// to generate Google Test fatal failures. It verifies that the given
116// statement will cause exactly one fatal Google Test failure with 'substr'
117// being part of the failure message.
118//
119// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
120// affects and considers failures generated in the current thread and
121// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
122//
123// The verification of the assertion is done correctly even when the statement
124// throws an exception or aborts the current function.
125//
126// Known restrictions:
127// - 'statement' cannot reference local non-static variables or
128// non-static members of the current object.
129// - 'statement' cannot return a value.
130// - You cannot stream a failure message to this macro.
131//
132// Note that even though the implementations of the following two
133// macros are much alike, we cannot refactor them to use a common
134// helper macro, due to some peculiarity in how the preprocessor
135// works. The AcceptsMacroThatExpandsToUnprotectedComma test in
136// gtest_unittest.cc will fail to compile if we do that.
137#define EXPECT_FATAL_FAILURE(statement, substr) \
138 do { \
139 class GTestExpectFatalFailureHelper {\
140 public:\
141 static void Execute() { statement; }\
142 };\
143 ::testing::TestPartResultArray gtest_failures;\
144 ::testing::internal::SingleFailureChecker gtest_checker(\
145 &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
146 {\
147 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
148 ::testing::ScopedFakeTestPartResultReporter:: \
149 INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
150 GTestExpectFatalFailureHelper::Execute();\
151 }\
152 } while (::testing::internal::AlwaysFalse())
153
154#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
155 do { \
156 class GTestExpectFatalFailureHelper {\
157 public:\
158 static void Execute() { statement; }\
159 };\
160 ::testing::TestPartResultArray gtest_failures;\
161 ::testing::internal::SingleFailureChecker gtest_checker(\
162 &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
163 {\
164 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
165 ::testing::ScopedFakeTestPartResultReporter:: \
166 INTERCEPT_ALL_THREADS, &gtest_failures);\
167 GTestExpectFatalFailureHelper::Execute();\
168 }\
169 } while (::testing::internal::AlwaysFalse())
170
171// A macro for testing Google Test assertions or code that's expected to
172// generate Google Test non-fatal failures. It asserts that the given
173// statement will cause exactly one non-fatal Google Test failure with 'substr'
174// being part of the failure message.
175//
176// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
177// affects and considers failures generated in the current thread and
178// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
179//
180// 'statement' is allowed to reference local variables and members of
181// the current object.
182//
183// The verification of the assertion is done correctly even when the statement
184// throws an exception or aborts the current function.
185//
186// Known restrictions:
187// - You cannot stream a failure message to this macro.
188//
189// Note that even though the implementations of the following two
190// macros are much alike, we cannot refactor them to use a common
191// helper macro, due to some peculiarity in how the preprocessor
192// works. If we do that, the code won't compile when the user gives
193// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
194// expands to code containing an unprotected comma. The
195// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
196// catches that.
197//
198// For the same reason, we have to write
199// if (::testing::internal::AlwaysTrue()) { statement; }
200// instead of
201// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
202// to avoid an MSVC warning on unreachable code.
203#define EXPECT_NONFATAL_FAILURE(statement, substr) \
204 do {\
205 ::testing::TestPartResultArray gtest_failures;\
206 ::testing::internal::SingleFailureChecker gtest_checker(\
207 &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
208 (substr));\
209 {\
210 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
211 ::testing::ScopedFakeTestPartResultReporter:: \
212 INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
213 if (::testing::internal::AlwaysTrue()) { statement; }\
214 }\
215 } while (::testing::internal::AlwaysFalse())
216
217#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
218 do {\
219 ::testing::TestPartResultArray gtest_failures;\
220 ::testing::internal::SingleFailureChecker gtest_checker(\
221 &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
222 (substr));\
223 {\
224 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
225 ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
226 &gtest_failures);\
227 if (::testing::internal::AlwaysTrue()) { statement; }\
228 }\
229 } while (::testing::internal::AlwaysFalse())
230
231#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#define GTEST_API_
Definition gtest-port.h:984
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:917
Definition lib.h:54
account_query_db::get_accounts_by_authorizers_result results