gtest/include/gtest/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 
40 namespace testing
41 {
42 
43 // This helper class can be used to mock out Google Test failure reporting
44 // so that we can test Google Test or code that builds on Google Test.
45 //
46 // An object of this class appends a TestPartResult object to the
47 // TestPartResultArray object given in the constructor whenever a Google Test
48 // failure is reported. It can either intercept only failures that are
49 // generated in the same thread that created this object or it can intercept
50 // all generated failures. The scope of this mock object can be controlled with
51 // the second argument to the two arguments constructor.
52 class GTEST_API_ ScopedFakeTestPartResultReporter
53  : public TestPartResultReporterInterface
54 {
55 public:
56  // The two possible mocking modes of this object.
58  {
59  INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
60  INTERCEPT_ALL_THREADS // Intercepts all failures.
61  };
62 
63  // The c'tor sets this object as the test part result reporter used
64  // by Google Test. The 'result' parameter specifies where to report the
65  // results. This reporter will only catch failures generated in the current
66  // thread. DEPRECATED
68 
69  // Same as above, but you can choose the interception scope of this object.
71  TestPartResultArray * result);
72 
73  // The d'tor restores the previous test part result reporter.
75 
76  // Appends the TestPartResult object to the TestPartResultArray
77  // received in the constructor.
78  //
79  // This method is from the TestPartResultReporterInterface
80  // interface.
81  virtual void ReportTestPartResult(const TestPartResult & result);
82 private:
83  void Init();
84 
85  const InterceptMode intercept_mode_;
86  TestPartResultReporterInterface * old_reporter_;
87  TestPartResultArray * const result_;
88 
90 };
91 
92 namespace internal
93 {
94 
95 // A helper class for implementing EXPECT_FATAL_FAILURE() and
96 // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
97 // TestPartResultArray contains exactly one failure that has the given
98 // type and contains the given substring. If that's not the case, a
99 // non-fatal failure will be generated.
100 class GTEST_API_ SingleFailureChecker
101 {
102 public:
103  // The constructor remembers the arguments.
104  SingleFailureChecker(const TestPartResultArray * results,
106  const string & substr);
107  ~SingleFailureChecker();
108 private:
109  const TestPartResultArray * const results_;
111  const string substr_;
112 
113  GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
114 };
115 
116 } // namespace internal
117 
118 } // namespace testing
119 
120 // A set of macros for testing Google Test assertions or code that's expected
121 // to generate Google Test fatal failures. It verifies that the given
122 // statement will cause exactly one fatal Google Test failure with 'substr'
123 // being part of the failure message.
124 //
125 // There are two different versions of this macro. EXPECT_FATAL_FAILURE only
126 // affects and considers failures generated in the current thread and
127 // EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
128 //
129 // The verification of the assertion is done correctly even when the statement
130 // throws an exception or aborts the current function.
131 //
132 // Known restrictions:
133 // - 'statement' cannot reference local non-static variables or
134 // non-static members of the current object.
135 // - 'statement' cannot return a value.
136 // - You cannot stream a failure message to this macro.
137 //
138 // Note that even though the implementations of the following two
139 // macros are much alike, we cannot refactor them to use a common
140 // helper macro, due to some peculiarity in how the preprocessor
141 // works. The AcceptsMacroThatExpandsToUnprotectedComma test in
142 // gtest_unittest.cc will fail to compile if we do that.
143 #define EXPECT_FATAL_FAILURE(statement, substr) \
144  do { \
145  class GTestExpectFatalFailureHelper {\
146  public:\
147  static void Execute() { statement; }\
148  };\
149  ::testing::TestPartResultArray gtest_failures;\
150  ::testing::internal::SingleFailureChecker gtest_checker(\
151  &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
152  {\
153  ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
154  ::testing::ScopedFakeTestPartResultReporter:: \
155  INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
156  GTestExpectFatalFailureHelper::Execute();\
157  }\
158  } while (::testing::internal::AlwaysFalse())
159 
160 #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
161  do { \
162  class GTestExpectFatalFailureHelper {\
163  public:\
164  static void Execute() { statement; }\
165  };\
166  ::testing::TestPartResultArray gtest_failures;\
167  ::testing::internal::SingleFailureChecker gtest_checker(\
168  &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
169  {\
170  ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
171  ::testing::ScopedFakeTestPartResultReporter:: \
172  INTERCEPT_ALL_THREADS, &gtest_failures);\
173  GTestExpectFatalFailureHelper::Execute();\
174  }\
175  } while (::testing::internal::AlwaysFalse())
176 
177 // A macro for testing Google Test assertions or code that's expected to
178 // generate Google Test non-fatal failures. It asserts that the given
179 // statement will cause exactly one non-fatal Google Test failure with 'substr'
180 // being part of the failure message.
181 //
182 // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
183 // affects and considers failures generated in the current thread and
184 // EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
185 //
186 // 'statement' is allowed to reference local variables and members of
187 // the current object.
188 //
189 // The verification of the assertion is done correctly even when the statement
190 // throws an exception or aborts the current function.
191 //
192 // Known restrictions:
193 // - You cannot stream a failure message to this macro.
194 //
195 // Note that even though the implementations of the following two
196 // macros are much alike, we cannot refactor them to use a common
197 // helper macro, due to some peculiarity in how the preprocessor
198 // works. If we do that, the code won't compile when the user gives
199 // EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
200 // expands to code containing an unprotected comma. The
201 // AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
202 // catches that.
203 //
204 // For the same reason, we have to write
205 // if (::testing::internal::AlwaysTrue()) { statement; }
206 // instead of
207 // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
208 // to avoid an MSVC warning on unreachable code.
209 #define EXPECT_NONFATAL_FAILURE(statement, substr) \
210  do {\
211  ::testing::TestPartResultArray gtest_failures;\
212  ::testing::internal::SingleFailureChecker gtest_checker(\
213  &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
214  (substr));\
215  {\
216  ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
217  ::testing::ScopedFakeTestPartResultReporter:: \
218  INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
219  if (::testing::internal::AlwaysTrue()) { statement; }\
220  }\
221  } while (::testing::internal::AlwaysFalse())
222 
223 #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
224  do {\
225  ::testing::TestPartResultArray gtest_failures;\
226  ::testing::internal::SingleFailureChecker gtest_checker(\
227  &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
228  (substr));\
229  {\
230  ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
231  ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
232  &gtest_failures);\
233  if (::testing::internal::AlwaysTrue()) { statement; }\
234  }\
235  } while (::testing::internal::AlwaysFalse())
236 
237 #endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define GTEST_API_
wchar_t type_
Definition: format.cc:302


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:21