1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Copyright 2007, Google Inc.
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// All rights reserved.
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Redistribution and use in source and binary forms, with or without
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// modification, are permitted provided that the following conditions are
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// met:
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//     * Redistributions of source code must retain the above copyright
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// notice, this list of conditions and the following disclaimer.
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//     * Redistributions in binary form must reproduce the above
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// copyright notice, this list of conditions and the following disclaimer
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// in the documentation and/or other materials provided with the
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// distribution.
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//     * Neither the name of Google Inc. nor the names of its
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// contributors may be used to endorse or promote products derived from
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// this software without specific prior written permission.
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Author: wan@google.com (Zhanyong Wan)
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Utilities for testing Google Test itself and code that uses Google Test
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// (e.g. frameworks built on top of Google Test).
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "gtest/gtest.h"
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace testing {
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This helper class can be used to mock out Google Test failure reporting
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// so that we can test Google Test or code that builds on Google Test.
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// An object of this class appends a TestPartResult object to the
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// TestPartResultArray object given in the constructor whenever a Google Test
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// failure is reported. It can either intercept only failures that are
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// generated in the same thread that created this object or it can intercept
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// all generated failures. The scope of this mock object can be controlled with
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// the second argument to the two arguments constructor.
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass GTEST_API_ ScopedFakeTestPartResultReporter
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    : public TestPartResultReporterInterface {
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public:
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // The two possible mocking modes of this object.
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  enum InterceptMode {
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    INTERCEPT_ONLY_CURRENT_THREAD,  // Intercepts only thread local failures.
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    INTERCEPT_ALL_THREADS           // Intercepts all failures.
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // The c'tor sets this object as the test part result reporter used
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // by Google Test.  The 'result' parameter specifies where to report the
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // results. This reporter will only catch failures generated in the current
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // thread. DEPRECATED
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Same as above, but you can choose the interception scope of this object.
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   TestPartResultArray* result);
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // The d'tor restores the previous test part result reporter.
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual ~ScopedFakeTestPartResultReporter();
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Appends the TestPartResult object to the TestPartResultArray
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // received in the constructor.
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // This method is from the TestPartResultReporterInterface
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // interface.
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void ReportTestPartResult(const TestPartResult& result);
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman private:
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  void Init();
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const InterceptMode intercept_mode_;
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  TestPartResultReporterInterface* old_reporter_;
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  TestPartResultArray* const result_;
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace internal {
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// A helper class for implementing EXPECT_FATAL_FAILURE() and
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// EXPECT_NONFATAL_FAILURE().  Its destructor verifies that the given
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// TestPartResultArray contains exactly one failure that has the given
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// type and contains the given substring.  If that's not the case, a
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// non-fatal failure will be generated.
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass GTEST_API_ SingleFailureChecker {
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public:
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // The constructor remembers the arguments.
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  SingleFailureChecker(const TestPartResultArray* results,
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                       TestPartResult::Type type,
10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                       const string& substr);
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ~SingleFailureChecker();
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman private:
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const TestPartResultArray* const results_;
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const TestPartResult::Type type_;
10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  const string substr_;
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}  // namespace internal
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}  // namespace testing
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// A set of macros for testing Google Test assertions or code that's expected
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// to generate Google Test fatal failures.  It verifies that the given
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// statement will cause exactly one fatal Google Test failure with 'substr'
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// being part of the failure message.
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// affects and considers failures generated in the current thread and
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The verification of the assertion is done correctly even when the statement
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// throws an exception or aborts the current function.
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Known restrictions:
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   - 'statement' cannot reference local non-static variables or
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//     non-static members of the current object.
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   - 'statement' cannot return a value.
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   - You cannot stream a failure message to this macro.
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Note that even though the implementations of the following two
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// macros are much alike, we cannot refactor them to use a common
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// helper macro, due to some peculiarity in how the preprocessor
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// works.  The AcceptsMacroThatExpandsToUnprotectedComma test in
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// gtest_unittest.cc will fail to compile if we do that.
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define EXPECT_FATAL_FAILURE(statement, substr) \
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  do { \
140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    class GTestExpectFatalFailureHelper {\
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman     public:\
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      static void Execute() { statement; }\
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    };\
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::TestPartResultArray gtest_failures;\
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::internal::SingleFailureChecker gtest_checker(\
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    {\
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          ::testing::ScopedFakeTestPartResultReporter:: \
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      GTestExpectFatalFailureHelper::Execute();\
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }\
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  } while (::testing::internal::AlwaysFalse())
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  do { \
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    class GTestExpectFatalFailureHelper {\
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman     public:\
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      static void Execute() { statement; }\
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    };\
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::TestPartResultArray gtest_failures;\
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::internal::SingleFailureChecker gtest_checker(\
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    {\
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          ::testing::ScopedFakeTestPartResultReporter:: \
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          INTERCEPT_ALL_THREADS, &gtest_failures);\
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      GTestExpectFatalFailureHelper::Execute();\
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }\
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  } while (::testing::internal::AlwaysFalse())
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// A macro for testing Google Test assertions or code that's expected to
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// generate Google Test non-fatal failures.  It asserts that the given
174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// statement will cause exactly one non-fatal Google Test failure with 'substr'
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// being part of the failure message.
176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// affects and considers failures generated in the current thread and
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 'statement' is allowed to reference local variables and members of
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// the current object.
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The verification of the assertion is done correctly even when the statement
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// throws an exception or aborts the current function.
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Known restrictions:
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   - You cannot stream a failure message to this macro.
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Note that even though the implementations of the following two
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// macros are much alike, we cannot refactor them to use a common
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// helper macro, due to some peculiarity in how the preprocessor
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// works.  If we do that, the code won't compile when the user gives
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// expands to code containing an unprotected comma.  The
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// catches that.
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// For the same reason, we have to write
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   if (::testing::internal::AlwaysTrue()) { statement; }
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// instead of
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//   GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// to avoid an MSVC warning on unreachable code.
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define EXPECT_NONFATAL_FAILURE(statement, substr) \
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  do {\
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::TestPartResultArray gtest_failures;\
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::internal::SingleFailureChecker gtest_checker(\
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        (substr));\
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    {\
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          ::testing::ScopedFakeTestPartResultReporter:: \
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (::testing::internal::AlwaysTrue()) { statement; }\
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }\
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  } while (::testing::internal::AlwaysFalse())
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  do {\
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::TestPartResultArray gtest_failures;\
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    ::testing::internal::SingleFailureChecker gtest_checker(\
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        (substr));\
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    {\
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          &gtest_failures);\
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (::testing::internal::AlwaysTrue()) { statement; }\
229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }\
230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  } while (::testing::internal::AlwaysFalse())
231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif  // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
233