13d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Copyright 2007, Google Inc. 23d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// All rights reserved. 33d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 43d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Redistribution and use in source and binary forms, with or without 53d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// modification, are permitted provided that the following conditions are 63d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// met: 73d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 83d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Redistributions of source code must retain the above copyright 93d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// notice, this list of conditions and the following disclaimer. 103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Redistributions in binary form must reproduce the above 113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// copyright notice, this list of conditions and the following disclaimer 123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in the documentation and/or other materials provided with the 133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// distribution. 143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Neither the name of Google Inc. nor the names of its 153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// contributors may be used to endorse or promote products derived from 163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this software without specific prior written permission. 173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Author: wan@google.com (Zhanyong Wan) 313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Utilities for testing Google Test itself and code that uses Google Test 333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (e.g. frameworks built on top of Google Test). 343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest.h" 393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace testing { 413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This helper class can be used to mock out Google Test failure reporting 433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// so that we can test Google Test or code that builds on Google Test. 443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// An object of this class appends a TestPartResult object to the 463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TestPartResultArray object given in the constructor whenever a Google Test 473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// failure is reported. It can either intercept only failures that are 483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// generated in the same thread that created this object or it can intercept 493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// all generated failures. The scope of this mock object can be controlled with 503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the second argument to the two arguments constructor. 513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ ScopedFakeTestPartResultReporter 523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick : public TestPartResultReporterInterface { 533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The two possible mocking modes of this object. 553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick enum InterceptMode { 563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures. 573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick INTERCEPT_ALL_THREADS // Intercepts all failures. 583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }; 593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The c'tor sets this object as the test part result reporter used 613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // by Google Test. The 'result' parameter specifies where to report the 623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // results. This reporter will only catch failures generated in the current 633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // thread. DEPRECATED 643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result); 653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Same as above, but you can choose the interception scope of this object. 673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, 683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestPartResultArray* result); 693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The d'tor restores the previous test part result reporter. 713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual ~ScopedFakeTestPartResultReporter(); 723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Appends the TestPartResult object to the TestPartResultArray 743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // received in the constructor. 753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // This method is from the TestPartResultReporterInterface 773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // interface. 783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual void ReportTestPartResult(const TestPartResult& result); 793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick void Init(); 813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const InterceptMode intercept_mode_; 833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestPartResultReporterInterface* old_reporter_; 843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestPartResultArray* const result_; 853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); 873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace internal { 903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A helper class for implementing EXPECT_FATAL_FAILURE() and 923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given 933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TestPartResultArray contains exactly one failure that has the given 943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// type and contains the given substring. If that's not the case, a 953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// non-fatal failure will be generated. 963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ SingleFailureChecker { 973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The constructor remembers the arguments. 993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick SingleFailureChecker(const TestPartResultArray* results, 1003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestPartResult::Type type, 1013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const string& substr); 1023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ~SingleFailureChecker(); 1033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 1043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const TestPartResultArray* const results_; 1053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const TestPartResult::Type type_; 1063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const string substr_; 1073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); 1093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 1103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} // namespace internal 1123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} // namespace testing 1143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A set of macros for testing Google Test assertions or code that's expected 1163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to generate Google Test fatal failures. It verifies that the given 1173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// statement will cause exactly one fatal Google Test failure with 'substr' 1183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// being part of the failure message. 1193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// There are two different versions of this macro. EXPECT_FATAL_FAILURE only 1213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// affects and considers failures generated in the current thread and 1223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 1233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The verification of the assertion is done correctly even when the statement 1253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// throws an exception or aborts the current function. 1263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Known restrictions: 1283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - 'statement' cannot reference local non-static variables or 1293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// non-static members of the current object. 1303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - 'statement' cannot return a value. 1313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - You cannot stream a failure message to this macro. 1323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Note that even though the implementations of the following two 1343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// macros are much alike, we cannot refactor them to use a common 1353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// helper macro, due to some peculiarity in how the preprocessor 1363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// works. The AcceptsMacroThatExpandsToUnprotectedComma test in 1373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// gtest_unittest.cc will fail to compile if we do that. 1383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define EXPECT_FATAL_FAILURE(statement, substr) \ 1393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick do { \ 1403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick class GTestExpectFatalFailureHelper {\ 1413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:\ 1423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static void Execute() { statement; }\ 1433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick };\ 1443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::TestPartResultArray gtest_failures;\ 1453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::SingleFailureChecker gtest_checker(\ 1463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 1473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick {\ 1483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 1493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter:: \ 1503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 1513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTestExpectFatalFailureHelper::Execute();\ 1523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }\ 1533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } while (::testing::internal::AlwaysFalse()) 1543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 1563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick do { \ 1573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick class GTestExpectFatalFailureHelper {\ 1583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:\ 1593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static void Execute() { statement; }\ 1603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick };\ 1613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::TestPartResultArray gtest_failures;\ 1623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::SingleFailureChecker gtest_checker(\ 1633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 1643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick {\ 1653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 1663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter:: \ 1673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick INTERCEPT_ALL_THREADS, >est_failures);\ 1683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTestExpectFatalFailureHelper::Execute();\ 1693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }\ 1703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } while (::testing::internal::AlwaysFalse()) 1713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A macro for testing Google Test assertions or code that's expected to 1733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// generate Google Test non-fatal failures. It asserts that the given 1743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// statement will cause exactly one non-fatal Google Test failure with 'substr' 1753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// being part of the failure message. 1763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only 1783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// affects and considers failures generated in the current thread and 1793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 1803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 'statement' is allowed to reference local variables and members of 1823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the current object. 1833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The verification of the assertion is done correctly even when the statement 1853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// throws an exception or aborts the current function. 1863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Known restrictions: 1883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// - You cannot stream a failure message to this macro. 1893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Note that even though the implementations of the following two 1913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// macros are much alike, we cannot refactor them to use a common 1923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// helper macro, due to some peculiarity in how the preprocessor 1933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// works. If we do that, the code won't compile when the user gives 1943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that 1953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// expands to code containing an unprotected comma. The 1963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc 1973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// catches that. 1983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For the same reason, we have to write 2003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// if (::testing::internal::AlwaysTrue()) { statement; } 2013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// instead of 2023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 2033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to avoid an MSVC warning on unreachable code. 2043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define EXPECT_NONFATAL_FAILURE(statement, substr) \ 2053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick do {\ 2063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::TestPartResultArray gtest_failures;\ 2073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::SingleFailureChecker gtest_checker(\ 2083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 2093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick (substr));\ 2103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick {\ 2113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter:: \ 2133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 2143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { statement; }\ 2153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }\ 2163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } while (::testing::internal::AlwaysFalse()) 2173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 2193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick do {\ 2203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::TestPartResultArray gtest_failures;\ 2213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::SingleFailureChecker gtest_checker(\ 2223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 2233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick (substr));\ 2243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick {\ 2253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\ 2273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick >est_failures);\ 2283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { statement; }\ 2293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }\ 2303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } while (::testing::internal::AlwaysFalse()) 2313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 233