gtest.h revision fc2de66453b0669c09eaca643b07d34443858b6f
11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Copyright 2005, Google Inc.
21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// All rights reserved.
31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Redistribution and use in source and binary forms, with or without
51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// modification, are permitted provided that the following conditions are
61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// met:
71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Redistributions of source code must retain the above copyright
91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// notice, this list of conditions and the following disclaimer.
101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Redistributions in binary form must reproduce the above
111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copyright notice, this list of conditions and the following disclaimer
121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in the documentation and/or other materials provided with the
131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// distribution.
141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Neither the name of Google Inc. nor the names of its
151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// contributors may be used to endorse or promote products derived from
161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this software without specific prior written permission.
171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Author: wan@google.com (Zhanyong Wan)
311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The Google C++ Testing Framework (Google Test)
331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This header file defines the public API for Google Test.  It should be
351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// included by any test program that uses Google Test.
361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// leave some internal implementation details in this header file.
391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// They are clearly marked by comments like this:
401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Such code is NOT meant to be used by a user directly, and is subject
441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// program!
461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Acknowledgment: Google Test borrowed the idea of automatic test
481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// easyUnit framework.
501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define GTEST_INCLUDE_GTEST_GTEST_H_
531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include <limits>
55fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#include <ostream>
5641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include <vector>
5741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
5841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/internal/gtest-internal.h"
5941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/internal/gtest-string.h"
6041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-death-test.h"
6141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-message.h"
6241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-param-test.h"
6341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-printers.h"
6441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest_prod.h"
6541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-test-part.h"
6641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-typed-test.h"
671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Depending on the platform, different string classes are available.
6941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// On Linux, in addition to ::std::string, Google also makes use of
7041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// class ::string, which has the same interface as ::std::string, but
7141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// has a different implementation.
7241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
7341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
7441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// ::string is available AND is a distinct type to ::std::string, or
7541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// define it to 0 to indicate otherwise.
761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// If the user's ::std::string and ::string are the same class due to
7841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
8041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
8141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// heuristically.
821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace testing {
841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Declares the flags.
861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag temporary enables the disabled tests.
881be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(also_run_disabled_tests);
891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag brings the debugger on an assertion failure.
911be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(break_on_failure);
921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag controls whether Google Test catches all test-thrown exceptions
941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// and logs them as failures.
951be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(catch_exceptions);
961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag enables using colors in terminal output. Available values are
981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// to let Google Test decide.
1001be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_string_(color);
1011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag sets up the filter to select by name using a glob pattern
1031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the tests to run. If the filter is not given all tests are executed.
1041be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_string_(filter);
1051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag causes the Google Test to list tests. None of the tests listed
1071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// are actually run if the flag is provided.
1081be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(list_tests);
1091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag controls whether Google Test emits a detailed XML report to a file
1111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in addition to its normal textual output.
1121be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_string_(output);
1131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flags control whether Google Test prints the elapsed time for each
1151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// test.
1161be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(print_time);
1171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
11841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// This flag specifies the random number seed.
11941d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_DECLARE_int32_(random_seed);
12041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag sets how many times the tests are repeated. The default value
1221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// is 1. If the value is -1 the tests are repeating forever.
1231be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_int32_(repeat);
1241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag controls whether Google Test includes Google Test internal
1261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// stack frames in failure stack traces.
1271be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(show_internal_stack_frames);
1281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// When this flag is specified, tests' order is randomized on every iteration.
13041d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_DECLARE_bool_(shuffle);
13141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This flag specifies the maximum number of stack frames to be
1331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// printed in a failure message.
1341be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_int32_(stack_trace_depth);
1351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// When this flag is specified, a failed assertion will throw an
1371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// exception if exceptions are enabled, or exit the program with a
1381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// non-zero code otherwise.
1391be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_bool_(throw_on_failure);
1401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// When this flag is set with a "host:port" string, on supported
14241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// platforms test results are streamed to the specified port on
14341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the specified host machine.
14441d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_DECLARE_string_(stream_result_to);
14541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The upper limit for valid stack trace depths.
1471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaconst int kMaxStackTraceDepth = 100;
1481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace internal {
1501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass AssertHelper;
15241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass DefaultGlobalTestPartResultReporter;
15341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass ExecDeathTest;
15441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass NoExecDeathTest;
15541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass FinalSuccessChecker;
1561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass GTestFlagSaver;
157fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesclass StreamingListenerTest;
15841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestResultAccessor;
15941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestEventListenersAccessor;
16041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestEventRepeater;
161fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesclass UnitTestRecordPropertyTestHelper;
16241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass WindowsDeathTest;
16341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass UnitTestImpl* GetUnitTestImpl();
16441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
165fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                                    const std::string& message);
1661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}  // namespace internal
1681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The friend relationship of some of these classes is cyclic.
17041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// If we don't forward declare them the compiler might confuse the classes
17141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// in friendship clauses with same named classes on the scope.
17241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass Test;
17341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestCase;
17441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestInfo;
17541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass UnitTest;
17641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A class for indicating whether an assertion was successful.  When
1781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the assertion wasn't successful, the AssertionResult object
17941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// remembers a non-empty message that describes how it failed.
1801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// To create an instance of this class, use one of the factory functions
1821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (AssertionSuccess() and AssertionFailure()).
1831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// This class is useful for two purposes:
18541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   1. Defining predicate functions to be used with Boolean test assertions
18641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
18741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   2. Defining predicate-format functions to be
18841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
18941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
19041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// For example, if you define IsEven predicate:
19141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
19241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   testing::AssertionResult IsEven(int n) {
19341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     if ((n % 2) == 0)
19441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionSuccess();
19541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     else
19641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionFailure() << n << " is odd";
19741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   }
19841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
19941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
20041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// will print the message
20141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
20241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Value of: IsEven(Fib(5))
20341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     Actual: false (5 is odd)
20441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Expected: true
20541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
20641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// instead of a more opaque
20741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
20841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Value of: IsEven(Fib(5))
20941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     Actual: false
21041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Expected: true
21141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
21241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// in case IsEven is a simple Boolean predicate.
21341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
21441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// If you expect your predicate to be reused and want to support informative
21541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
21641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// about half as often as positive ones in our tests), supply messages for
21741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// both success and failure cases:
21841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
21941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   testing::AssertionResult IsEven(int n) {
22041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     if ((n % 2) == 0)
22141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionSuccess() << n << " is even";
22241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     else
22341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionFailure() << n << " is odd";
22441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   }
22541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
22641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
22741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
22841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Value of: IsEven(Fib(6))
22941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     Actual: true (8 is even)
23041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//   Expected: false
23141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
23241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// NB: Predicates that support negative Boolean assertions have reduced
23341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// performance in positive ones so be careful not to use them in tests
23441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// that have lots (tens of thousands) of positive Boolean assertions.
23541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
23641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// To use this class with EXPECT_PRED_FORMAT assertions such as:
2371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
2381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   // Verifies that Foo() returns an even number.
2391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_PRED_FORMAT1(IsEven, Foo());
2401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
24141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// you need to define:
2421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
2431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   testing::AssertionResult IsEven(const char* expr, int n) {
24441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     if ((n % 2) == 0)
24541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionSuccess();
24641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//     else
24741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//       return testing::AssertionFailure()
24841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
2491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
2501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
2511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// If Foo() returns 5, you will see the following message:
2521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
2531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Expected: Foo() is even
2541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     Actual: it's 5
25541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
25641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ AssertionResult {
2571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
25841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Copy constructor.
25941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Used in EXPECT_TRUE/FALSE(assertion_result).
26041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  AssertionResult(const AssertionResult& other);
26141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Used in the EXPECT_TRUE/FALSE(bool_expression).
26241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  explicit AssertionResult(bool success) : success_(success) {}
2631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns true iff the assertion succeeded.
26541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  operator bool() const { return success_; }  // NOLINT
2661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
26741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
26841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  AssertionResult operator!() const;
26941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
27041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the text streamed into this AssertionResult. Test assertions
27141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // use it when they fail (i.e., the predicate's outcome doesn't match the
27241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // assertion's expectation). When nothing has been streamed into the
27341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // object, returns an empty string.
27441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* message() const {
27541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return message_.get() != NULL ?  message_->c_str() : "";
27641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
27741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // TODO(vladl@google.com): Remove this after making sure no clients use it.
27841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Deprecated; please use message() instead.
27941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* failure_message() const { return message(); }
28041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
28141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Streams a custom failure message into this object.
28241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  template <typename T> AssertionResult& operator<<(const T& value) {
28341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    AppendMessage(Message() << value);
28441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return *this;
28541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
28641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
28741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Allows streaming basic output manipulators such as endl or flush into
28841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // this object.
28941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  AssertionResult& operator<<(
29041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
29141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    AppendMessage(Message() << basic_manipulator);
29241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return *this;
29341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
2941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
29641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Appends the contents of message to message_.
29741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void AppendMessage(const Message& a_message) {
29841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if (message_.get() == NULL)
29941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      message_.reset(new ::std::string);
30041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    message_->append(a_message.GetString().c_str());
30141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
3021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
30341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Stores result of the assertion predicate.
30441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool success_;
30541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Stores the message describing the condition in case the expectation
30641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // construct is not satisfied with the predicate's outcome.
30741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Referenced via a pointer to avoid taking too much stack frame space
30841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // with test assertions.
30941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  internal::scoped_ptr< ::std::string> message_;
3101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
31141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  GTEST_DISALLOW_ASSIGN_(AssertionResult);
3121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
3131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Makes a successful assertion result.
31541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult AssertionSuccess();
31641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
31741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Makes a failed assertion result.
31841d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult AssertionFailure();
3191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Makes a failed assertion result with the given failure message.
32141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Deprecated; use AssertionFailure() << msg.
32241d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
3231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The abstract class that all tests inherit from.
3251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// In Google Test, a unit test program contains one or many TestCases, and
3271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// each TestCase contains one or many Tests.
3281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// When you define a test using the TEST macro, you don't need to
3301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// explicitly derive from Test - the TEST macro automatically does
3311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this for you.
3321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The only time you derive from Test is when defining a test fixture
3341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// to be used a TEST_F.  For example:
3351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   class FooTest : public testing::Test {
3371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    protected:
3381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     virtual void SetUp() { ... }
3391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     virtual void TearDown() { ... }
3401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     ...
3411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   };
3421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   TEST_F(FooTest, Bar) { ... }
3441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   TEST_F(FooTest, Baz) { ... }
3451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
3461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Test is not copyable.
34741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ Test {
3481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
34941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class TestInfo;
3501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Defines types for pointers to functions that set up and tear down
3521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // a test case.
3531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
3541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
3551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // The d'tor is virtual as we intend to inherit from Test.
3571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual ~Test();
3581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Sets up the stuff shared by all tests in this test case.
3601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
3611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Google Test will call Foo::SetUpTestCase() before running the first
3621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // test in test case Foo.  Hence a sub-class can define its own
3631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // SetUpTestCase() method to shadow the one defined in the super
3641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // class.
3651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static void SetUpTestCase() {}
3661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Tears down the stuff shared by all tests in this test case.
3681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
3691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Google Test will call Foo::TearDownTestCase() after running the last
3701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // test in test case Foo.  Hence a sub-class can define its own
3711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // TearDownTestCase() method to shadow the one defined in the super
3721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // class.
3731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static void TearDownTestCase() {}
3741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
3751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns true iff the current test has a fatal failure.
3761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static bool HasFatalFailure();
3771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
37841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the current test has a non-fatal failure.
37941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool HasNonfatalFailure();
38041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
38141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the current test has a (either fatal or
38241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // non-fatal) failure.
38341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
38441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
385fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Logs a property for the current test, test case, or for the entire
386fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // invocation of the test program when used outside of the context of a
387fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // test case.  Only the last value for a given key is remembered.  These
388fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // are public static so they can be called from utility functions that are
389fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // not members of the test fixture.  Calls to RecordProperty made during
390fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // lifespan of the test (from the moment its constructor starts to the
391fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // moment its destructor finishes) will be output in XML as attributes of
392fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // the <testcase> element.  Properties recorded from fixture's
393fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // SetUpTestCase or TearDownTestCase are logged as attributes of the
394fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // corresponding <testsuite> element.  Calls to RecordProperty made in the
395fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // global context (before or after invocation of RUN_ALL_TESTS and from
396fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // SetUp/TearDown method of Environment objects registered with Google
397fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Test) will be output as attributes of the <testsuites> element.
398fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static void RecordProperty(const std::string& key, const std::string& value);
399fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static void RecordProperty(const std::string& key, int value);
4001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania protected:
4021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Creates a Test object.
4031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  Test();
4041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Sets up the test fixture.
4061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void SetUp();
4071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Tears down the test fixture.
4091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void TearDown();
4101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
4121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns true iff the current test has the same fixture class as
4131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // the first test in the current test case.
4141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static bool HasSameFixtureClass();
4151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Runs the test after the test fixture has been set up.
4171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // A sub-class must implement this to define the test logic.
4191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
4211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Instead, use the TEST or TEST_F macro.
4221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void TestBody() = 0;
4231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Sets up, executes, and tears down the test.
4251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  void Run();
4261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
42741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Deletes self.  We deliberately pick an unusual name for this
42841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // internal method to avoid clashing with names used in user TESTs.
42941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void DeleteSelf_() { delete this; }
43041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
4311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Uses a GTestFlagSaver to save and restore all Google Test flags.
4321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  const internal::GTestFlagSaver* const gtest_flag_saver_;
4331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Often a user mis-spells SetUp() as Setup() and spends a long time
4351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // wondering why it is never called by Google Test.  The declaration of
4361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // the following method is solely for catching such an error at
4371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // compile time:
4381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //   - The return type is deliberately chosen to be not void, so it
4401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //   will be a conflict if a user declares void Setup() in his test
4411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //   fixture.
4421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //   - This method is private, so it will be another compiler error
4441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //   if a user calls it from his test fixture.
4451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // DO NOT OVERRIDE THIS FUNCTION.
4471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
4481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // If you see an error about overriding the following function or
4491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // about it being private, you have mis-spelled SetUp() as Setup().
4501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  struct Setup_should_be_spelled_SetUp {};
4511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
4521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // We disallow copying Tests.
4541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
4551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
4561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
45741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottypedef internal::TimeInMillis TimeInMillis;
45841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
45941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// A copyable object representing a user specified test property which can be
46041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// output as a key/value string pair.
46141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
46241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Don't inherit from TestProperty as its destructor is not virtual.
46341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestProperty {
46441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
46541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // C'tor.  TestProperty does NOT have a default constructor.
46641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Always use this constructor (with parameters) to create a
46741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // TestProperty object.
468fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  TestProperty(const std::string& a_key, const std::string& a_value) :
46941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    key_(a_key), value_(a_value) {
47041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
47141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
47241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the user supplied key.
47341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* key() const {
47441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return key_.c_str();
47541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
47641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
47741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the user supplied value.
47841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* value() const {
47941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return value_.c_str();
48041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
48141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
48241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Sets a new value, overriding the one supplied in the constructor.
483fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  void SetValue(const std::string& new_value) {
48441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    value_ = new_value;
48541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
48641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
48741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private:
48841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The key supplied by the user.
489fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  std::string key_;
49041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The value supplied by the user.
491fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  std::string value_;
49241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
49341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
49441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The result of a single Test.  This includes a list of
49541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// TestPartResults, a list of TestProperties, a count of how many
49641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// death tests there are in the Test, and how much time it took to run
49741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the Test.
49841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
49941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// TestResult is not copyable.
50041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ TestResult {
50141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
50241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Creates an empty TestResult.
50341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestResult();
50441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
50541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // D'tor.  Do not inherit from TestResult.
50641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  ~TestResult();
50741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
50841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of all test parts.  This is the sum of the number
50941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // of successful test parts and the number of failed test parts.
51041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int total_part_count() const;
51141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
51241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the number of the test properties.
51341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int test_property_count() const;
51441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
51541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test passed (i.e. no test part failed).
51641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Passed() const { return !Failed(); }
51741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
51841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test failed.
51941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Failed() const;
52041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
52141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test fatally failed.
52241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool HasFatalFailure() const;
52341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
52441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test has a non-fatal failure.
52541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool HasNonfatalFailure() const;
52641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
52741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the elapsed time, in milliseconds.
52841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TimeInMillis elapsed_time() const { return elapsed_time_; }
52941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
53041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the i-th test part result among all the results. i can range
53141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // from 0 to test_property_count() - 1. If i is not in that range, aborts
53241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // the program.
53341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const TestPartResult& GetTestPartResult(int i) const;
53441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
53541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the i-th test property. i can range from 0 to
53641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // test_property_count() - 1. If i is not in that range, aborts the
53741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // program.
53841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const TestProperty& GetTestProperty(int i) const;
53941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
54041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private:
54141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class TestInfo;
542fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  friend class TestCase;
54341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class UnitTest;
54441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::DefaultGlobalTestPartResultReporter;
54541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::ExecDeathTest;
54641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::TestResultAccessor;
54741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::UnitTestImpl;
54841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::WindowsDeathTest;
54941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
55041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the vector of TestPartResults.
55141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const std::vector<TestPartResult>& test_part_results() const {
55241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_part_results_;
55341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
55441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
55541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the vector of TestProperties.
55641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const std::vector<TestProperty>& test_properties() const {
55741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_properties_;
55841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
55941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
56041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Sets the elapsed time.
56141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
56241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
56341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Adds a test property to the list. The property is validated and may add
56441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
56541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // key names). If a property is already recorded for the same key, the
56641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // value will be updated, rather than storing multiple values for the same
567fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // key.  xml_element specifies the element for which the property is being
568fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // recorded and is used for validation.
569fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  void RecordProperty(const std::string& xml_element,
570fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                      const TestProperty& test_property);
57141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
57241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Adds a failure if the key is a reserved attribute of Google Test
57341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // testcase tags.  Returns true if the property is valid.
57441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // TODO(russr): Validate attribute names are legal and human readable.
575fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static bool ValidateTestProperty(const std::string& xml_element,
576fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                                   const TestProperty& test_property);
57741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
57841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Adds a test part result to the list.
57941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void AddTestPartResult(const TestPartResult& test_part_result);
58041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
58141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the death test count.
58241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int death_test_count() const { return death_test_count_; }
58341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
58441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Increments the death test count, returning the new count.
58541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int increment_death_test_count() { return ++death_test_count_; }
58641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
58741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Clears the test part results.
58841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void ClearTestPartResults();
58941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
59041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Clears the object.
59141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void Clear();
59241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
59341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Protects mutable state of the property vector and of owned
59441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // properties, whose values may be updated.
59541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  internal::Mutex test_properites_mutex_;
59641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
59741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The vector of TestPartResults
59841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  std::vector<TestPartResult> test_part_results_;
59941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The vector of TestProperties
60041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  std::vector<TestProperty> test_properties_;
60141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Running count of death tests.
60241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int death_test_count_;
60341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The elapsed time, in milliseconds.
60441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TimeInMillis elapsed_time_;
60541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
60641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // We disallow copying TestResult.
60741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
60841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};  // class TestResult
6091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
6101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A TestInfo object stores the following information about a test:
6111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
6121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Test case name
6131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Test name
6141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Whether the test should be run
6151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   A function pointer that creates the test object when invoked
6161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Test result
6171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
6181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The constructor of TestInfo registers itself with the UnitTest
6191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// singleton such that the RUN_ALL_TESTS() macro knows which tests to
6201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// run.
62141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ TestInfo {
6221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
6231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Destructs a TestInfo object.  This function is not virtual, so
6241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // don't inherit from TestInfo.
6251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ~TestInfo();
6261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
6271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the test case name.
62841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* test_case_name() const { return test_case_name_.c_str(); }
6291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
6301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the test name.
63141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* name() const { return name_.c_str(); }
63241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
63341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the name of the parameter type, or NULL if this is not a typed
63441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // or a type-parameterized test.
63541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* type_param() const {
63641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if (type_param_.get() != NULL)
63741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      return type_param_->c_str();
63841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return NULL;
63941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
6401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
64141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the text representation of the value parameter, or NULL if this
64241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // is not a value-parameterized test.
64341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* value_param() const {
64441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if (value_param_.get() != NULL)
64541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      return value_param_->c_str();
64641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return NULL;
64741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
6481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
649fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns true if this test should run, that is if the test is not
650fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // disabled (or it is disabled but the also_run_disabled_tests flag has
651fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // been specified) and its full name matches the user-specified filter.
6521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
6531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Google Test allows the user to filter the tests by their full names.
6541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // The full name of a test Bar in test case Foo is defined as
6551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // "Foo.Bar".  Only the tests that match the filter will run.
6561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
6571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // A filter is a colon-separated list of glob (not regex) patterns,
6581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // optionally followed by a '-' and a colon-separated list of
6591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // negative patterns (tests to exclude).  A test is run if it
6601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // matches one of the positive patterns and does not match any of
6611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // the negative patterns.
6621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
6631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // For example, *A*:Foo.* is a filter that matches any string that
6641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // contains the character 'A' or starts with "Foo.".
66541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool should_run() const { return should_run_; }
6661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
667fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns true iff this test will appear in the XML report.
668fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  bool is_reportable() const {
669fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    // For now, the XML report includes all tests matching the filter.
670fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    // In the future, we may trim tests that are excluded because of
671fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    // sharding.
672fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return matches_filter_;
673fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
674fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
6751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the result of the test.
67641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const TestResult* result() const { return &result_; }
67741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
6781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
6791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_DEATH_TEST
6801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  friend class internal::DefaultDeathTestFactory;
6811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_DEATH_TEST
6821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  friend class Test;
6831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  friend class TestCase;
68441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::UnitTestImpl;
685fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  friend class internal::StreamingListenerTest;
6861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  friend TestInfo* internal::MakeAndRegisterTestInfo(
687fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      const char* test_case_name,
688fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      const char* name,
68941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* type_param,
69041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* value_param,
6911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      internal::TypeId fixture_class_id,
6921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      Test::SetUpTestCaseFunc set_up_tc,
6931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      Test::TearDownTestCaseFunc tear_down_tc,
6941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      internal::TestFactoryBase* factory);
6951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
6961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Constructs a TestInfo object. The newly constructed instance assumes
6971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // ownership of the factory object.
698fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  TestInfo(const std::string& test_case_name,
699fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes           const std::string& name,
700fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes           const char* a_type_param,   // NULL if not a type-parameterized test
701fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes           const char* a_value_param,  // NULL if not a value-parameterized test
7021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania           internal::TypeId fixture_class_id,
7031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania           internal::TestFactoryBase* factory);
7041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
70541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Increments the number of death tests encountered in this test so
70641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // far.
70741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int increment_death_test_count() {
70841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return result_.increment_death_test_count();
70941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
71041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
71141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Creates the test object, runs it, records its result, and then
71241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // deletes it.
71341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void Run();
71441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
71541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static void ClearTestResult(TestInfo* test_info) {
71641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    test_info->result_.Clear();
71741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
71841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
71941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // These fields are immutable properties of the test.
72041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const std::string test_case_name_;     // Test case name
72141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const std::string name_;               // Test name
72241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Name of the parameter type, or NULL if this is not a typed or a
72341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // type-parameterized test.
72441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const internal::scoped_ptr<const ::std::string> type_param_;
72541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Text representation of the value parameter, or NULL if this is not a
72641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // value-parameterized test.
72741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const internal::scoped_ptr<const ::std::string> value_param_;
72841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
72941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool should_run_;                 // True iff this test should run
73041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool is_disabled_;                // True iff this test is disabled
73141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool matches_filter_;             // True if this test matches the
73241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                    // user-specified filter.
73341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  internal::TestFactoryBase* const factory_;  // The factory that creates
73441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              // the test object
73541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
73641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // This field is mutable and needs to be reset before running the
73741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // test for the second time.
73841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestResult result_;
7391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
7401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
7411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
7421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
74341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// A test case, which consists of a vector of TestInfos.
74441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot//
74541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// TestCase is not copyable.
74641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ TestCase {
74741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
74841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Creates a TestCase with the given name.
74941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
75041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // TestCase does NOT have a default constructor.  Always use this
75141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // constructor to create a TestCase object.
75241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
75341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Arguments:
75441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
75541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //   name:         name of the test case
75641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //   a_type_param: the name of the test's type parameter, or NULL if
75741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //                 this is not a type-parameterized test.
75841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //   set_up_tc:    pointer to the function that sets up the test case
75941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //   tear_down_tc: pointer to the function that tears down the test case
76041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestCase(const char* name, const char* a_type_param,
76141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot           Test::SetUpTestCaseFunc set_up_tc,
76241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot           Test::TearDownTestCaseFunc tear_down_tc);
76341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
76441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Destructor of TestCase.
76541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual ~TestCase();
76641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
76741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the name of the TestCase.
76841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* name() const { return name_.c_str(); }
76941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
77041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the name of the parameter type, or NULL if this is not a
77141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // type-parameterized test case.
77241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const char* type_param() const {
77341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if (type_param_.get() != NULL)
77441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      return type_param_->c_str();
77541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return NULL;
77641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
77741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
77841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true if any test in this test case should run.
77941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool should_run() const { return should_run_; }
78041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
78141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of successful tests in this test case.
78241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int successful_test_count() const;
78341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
78441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of failed tests in this test case.
78541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int failed_test_count() const;
78641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
787fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Gets the number of disabled tests that will be reported in the XML report.
788fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  int reportable_disabled_test_count() const;
789fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
79041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of disabled tests in this test case.
79141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int disabled_test_count() const;
79241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
793fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Gets the number of tests to be printed in the XML report.
794fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  int reportable_test_count() const;
795fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
79641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Get the number of tests in this test case that should run.
79741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int test_to_run_count() const;
79841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
79941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of all tests in this test case.
80041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int total_test_count() const;
80141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
80241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test case passed.
80341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Passed() const { return !Failed(); }
80441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
80541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the test case failed.
80641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Failed() const { return failed_test_count() > 0; }
80741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
80841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the elapsed time, in milliseconds.
80941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TimeInMillis elapsed_time() const { return elapsed_time_; }
81041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
81141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the i-th test among all the tests. i can range from 0 to
81241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // total_test_count() - 1. If i is not in that range, returns NULL.
81341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const TestInfo* GetTestInfo(int i) const;
81441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
815fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns the TestResult that holds test properties recorded during
816fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // execution of SetUpTestCase and TearDownTestCase.
817fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
818fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
81941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private:
82041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class Test;
82141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::UnitTestImpl;
82241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
82341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the (mutable) vector of TestInfos in this TestCase.
82441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
82541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
82641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the (immutable) vector of TestInfos in this TestCase.
82741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const std::vector<TestInfo*>& test_info_list() const {
82841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_info_list_;
82941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
83041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
83141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the i-th test among all the tests. i can range from 0 to
83241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // total_test_count() - 1. If i is not in that range, returns NULL.
83341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestInfo* GetMutableTestInfo(int i);
83441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
83541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Sets the should_run member.
83641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void set_should_run(bool should) { should_run_ = should; }
83741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
83841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
83941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // destruction of the TestCase object.
84041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void AddTestInfo(TestInfo * test_info);
84141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
84241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Clears the results of all tests in this test case.
84341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void ClearResult();
84441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
84541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Clears the results of all tests in the given test case.
84641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static void ClearTestCaseResult(TestCase* test_case) {
84741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    test_case->ClearResult();
84841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
84941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
85041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Runs every test in this TestCase.
85141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void Run();
85241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
85341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
85441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // for catching exceptions thrown from SetUpTestCase().
85541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void RunSetUpTestCase() { (*set_up_tc_)(); }
85641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
85741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Runs TearDownTestCase() for this TestCase.  This wrapper is
85841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // needed for catching exceptions thrown from TearDownTestCase().
85941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void RunTearDownTestCase() { (*tear_down_tc_)(); }
86041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
86141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff test passed.
86241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool TestPassed(const TestInfo* test_info) {
86341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_info->should_run() && test_info->result()->Passed();
86441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
86541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
86641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff test failed.
86741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool TestFailed(const TestInfo* test_info) {
86841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_info->should_run() && test_info->result()->Failed();
86941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
87041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
871fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns true iff the test is disabled and will be reported in the XML
872fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // report.
873fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static bool TestReportableDisabled(const TestInfo* test_info) {
874fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return test_info->is_reportable() && test_info->is_disabled_;
875fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
876fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
87741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff test is disabled.
87841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool TestDisabled(const TestInfo* test_info) {
87941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_info->is_disabled_;
88041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
88141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
882fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns true iff this test will appear in the XML report.
883fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static bool TestReportable(const TestInfo* test_info) {
884fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return test_info->is_reportable();
885fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
886fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
88741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true if the given test should run.
88841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static bool ShouldRunTest(const TestInfo* test_info) {
88941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return test_info->should_run();
89041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
89141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
89241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Shuffles the tests in this test case.
89341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void ShuffleTests(internal::Random* random);
89441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
89541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Restores the test order to before the first shuffle.
89641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void UnshuffleTests();
89741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
89841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Name of the test case.
899fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  std::string name_;
90041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Name of the parameter type, or NULL if this is not a typed or a
90141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // type-parameterized test.
90241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const internal::scoped_ptr<const ::std::string> type_param_;
90341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The vector of TestInfos in their original order.  It owns the
90441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // elements in the vector.
90541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  std::vector<TestInfo*> test_info_list_;
90641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Provides a level of indirection for the test list to allow easy
90741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // shuffling and restoring the test order.  The i-th element in this
90841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // vector is the index of the i-th test in the shuffled test list.
90941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  std::vector<int> test_indices_;
91041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Pointer to the function that sets up the test case.
91141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  Test::SetUpTestCaseFunc set_up_tc_;
91241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Pointer to the function that tears down the test case.
91341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  Test::TearDownTestCaseFunc tear_down_tc_;
91441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // True iff any test in this test case should run.
91541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool should_run_;
91641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Elapsed time, in milliseconds.
91741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TimeInMillis elapsed_time_;
918fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Holds test properties recorded during execution of SetUpTestCase and
919fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // TearDownTestCase.
920fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  TestResult ad_hoc_test_result_;
92141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
92241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // We disallow copying TestCases.
92341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
92441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
92541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
9261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// An Environment object is capable of setting up and tearing down an
9271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// environment.  The user should subclass this to define his own
9281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// environment(s).
9291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
9301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// An Environment object does the set-up and tear-down in virtual
9311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// methods SetUp() and TearDown() instead of the constructor and the
9321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// destructor, as:
9331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
9341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   1. You cannot safely throw from a destructor.  This is a problem
9351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//      as in some cases Google Test is used where exceptions are enabled, and
9361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//      we may want to implement ASSERT_* using exceptions where they are
9371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//      available.
9381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   2. You cannot use ASSERT_* directly in a constructor or
9391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//      destructor.
9401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass Environment {
9411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
9421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // The d'tor is virtual as we need to subclass Environment.
9431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual ~Environment() {}
9441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
9451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Override this to define how to set up the environment.
9461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void SetUp() {}
9471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
9481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Override this to define how to tear down the environment.
9491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void TearDown() {}
9501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
9511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // If you see an error about overriding the following function or
9521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // about it being private, you have mis-spelled SetUp() as Setup().
9531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  struct Setup_should_be_spelled_SetUp {};
9541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
9551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
9561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
95741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The interface for tracing execution of tests. The methods are organized in
95841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the order the corresponding events are fired.
95941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestEventListener {
96041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
96141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual ~TestEventListener() {}
96241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
96341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before any test activity starts.
96441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
96541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
96641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before each iteration of tests starts.  There may be more than
96741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
96841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // index, starting from 0.
96941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestIterationStart(const UnitTest& unit_test,
97041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                    int iteration) = 0;
97141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
97241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before environment set-up for each iteration of tests starts.
97341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
97441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
97541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after environment set-up for each iteration of tests ends.
97641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
97741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
97841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before the test case starts.
97941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
98041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
98141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before the test starts.
98241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestStart(const TestInfo& test_info) = 0;
98341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
98441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after a failed assertion or a SUCCEED() invocation.
98541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
98641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
98741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after the test ends.
98841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestEnd(const TestInfo& test_info) = 0;
98941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
99041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after the test case ends.
99141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
99241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
99341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired before environment tear-down for each iteration of tests starts.
99441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
99541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
99641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after environment tear-down for each iteration of tests ends.
99741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
99841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
99941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after each iteration of tests finishes.
100041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestIterationEnd(const UnitTest& unit_test,
100141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                  int iteration) = 0;
100241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
100341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Fired after all test activities have ended.
100441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
100541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
100641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
100741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The convenience class for users who need to override just one or two
100841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// methods and are not concerned that a possible change to a signature of
100941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the methods they override will not be caught during the build.  For
101041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// comments about each method please see the definition of TestEventListener
101141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// above.
101241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass EmptyTestEventListener : public TestEventListener {
101341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
101441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
101541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
101641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                    int /*iteration*/) {}
101741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
101841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
101941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
102041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
102141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
102241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
102341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
102441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
102541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
102641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
102741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                  int /*iteration*/) {}
102841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
102941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
103041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
103141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// TestEventListeners lets users add listeners to track events in Google Test.
103241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ TestEventListeners {
103341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public:
103441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListeners();
103541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  ~TestEventListeners();
103641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
103741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Appends an event listener to the end of the list. Google Test assumes
103841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // the ownership of the listener (i.e. it will delete the listener when
103941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // the test program finishes).
104041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void Append(TestEventListener* listener);
104141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
104241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Removes the given event listener from the list and returns it.  It then
104341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // becomes the caller's responsibility to delete the listener. Returns
104441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // NULL if the listener is not found in the list.
104541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* Release(TestEventListener* listener);
104641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
104741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the standard listener responsible for the default console
104841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // output.  Can be removed from the listeners list to shut down default
104941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // console output.  Note that removing this object from the listener list
105041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // with Release transfers its ownership to the caller and makes this
105141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // function return NULL the next time.
105241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* default_result_printer() const {
105341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return default_result_printer_;
105441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
105541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
105641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the standard listener responsible for the default XML output
105741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // controlled by the --gtest_output=xml flag.  Can be removed from the
105841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // listeners list by users who want to shut down the default XML output
105941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // controlled by this flag and substitute it with custom one.  Note that
106041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // removing this object from the listener list with Release transfers its
106141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // ownership to the caller and makes this function return NULL the next
106241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // time.
106341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* default_xml_generator() const {
106441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return default_xml_generator_;
106541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  }
106641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
106741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private:
106841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class TestCase;
106941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class TestInfo;
107041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::DefaultGlobalTestPartResultReporter;
107141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::NoExecDeathTest;
107241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::TestEventListenersAccessor;
107341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::UnitTestImpl;
107441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
107541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns repeater that broadcasts the TestEventListener events to all
107641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // subscribers.
107741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* repeater();
107841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
107941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Sets the default_result_printer attribute to the provided listener.
108041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The listener is also added to the listener list and previous
108141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // default_result_printer is removed from it and deleted. The listener can
108241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // also be NULL in which case it will not be added to the list. Does
108341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // nothing if the previous and the current listener objects are the same.
108441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void SetDefaultResultPrinter(TestEventListener* listener);
108541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
108641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Sets the default_xml_generator attribute to the provided listener.  The
108741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // listener is also added to the listener list and previous
108841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // default_xml_generator is removed from it and deleted. The listener can
108941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // also be NULL in which case it will not be added to the list. Does
109041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // nothing if the previous and the current listener objects are the same.
109141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void SetDefaultXmlGenerator(TestEventListener* listener);
109241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
109341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Controls whether events will be forwarded by the repeater to the
109441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // listeners in the list.
109541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool EventForwardingEnabled() const;
109641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void SuppressEventForwarding();
109741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
109841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The actual list of listeners.
109941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  internal::TestEventRepeater* repeater_;
110041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Listener responsible for the standard result output.
110141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* default_result_printer_;
110241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Listener responsible for the creation of the XML output file.
110341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListener* default_xml_generator_;
110441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
110541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // We disallow copying TestEventListeners.
110641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
110741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
110841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
110941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// A UnitTest consists of a vector of TestCases.
11101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
11111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This is a singleton class.  The only instance of UnitTest is
11121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// created when UnitTest::GetInstance() is first called.  This
11131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// instance is never deleted.
11141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
11151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// UnitTest is not copyable.
11161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
11171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This class is thread-safe as long as the methods are called
11181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// according to their specification.
111941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ UnitTest {
11201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
11211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Gets the singleton UnitTest object.  The first time this method
11221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // is called, a UnitTest object is constructed and returned.
11231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Consecutive calls will return the same object.
11241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static UnitTest* GetInstance();
11251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
11261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Runs all tests in this UnitTest object and prints the result.
11271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns 0 if successful, or 1 otherwise.
11281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
11291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // This method can only be called from the main thread.
11301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
11311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
11321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  int Run() GTEST_MUST_USE_RESULT_;
11331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
11341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the working directory when the first TEST() or TEST_F()
11351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // was executed.  The UnitTest object owns the string.
11361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  const char* original_working_dir() const;
11371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
11381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the TestCase object for the test that's currently running,
11391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // or NULL if no test is running.
1140fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  const TestCase* current_test_case() const
1141fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
11421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
11431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the TestInfo object for the test that's currently running,
11441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // or NULL if no test is running.
1145fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  const TestInfo* current_test_info() const
1146fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
11471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
114841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the random seed used at the start of the current test run.
114941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int random_seed() const;
115041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
11511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
11521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Returns the ParameterizedTestCaseRegistry object used to keep track of
11531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // value-parameterized tests and instantiate and register them.
115441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
115541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1156fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
1157fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
11581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
11591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
116041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of successful test cases.
116141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int successful_test_case_count() const;
116241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
116341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of failed test cases.
116441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int failed_test_case_count() const;
116541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
116641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of all test cases.
116741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int total_test_case_count() const;
116841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
116941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of all test cases that contain at least one test
117041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // that should run.
117141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int test_case_to_run_count() const;
117241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
117341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of successful tests.
117441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int successful_test_count() const;
117541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
117641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of failed tests.
117741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int failed_test_count() const;
117841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1179fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Gets the number of disabled tests that will be reported in the XML report.
1180fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  int reportable_disabled_test_count() const;
1181fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
118241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of disabled tests.
118341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int disabled_test_count() const;
118441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1185fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Gets the number of tests to be printed in the XML report.
1186fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  int reportable_test_count() const;
1187fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
118841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of all tests.
118941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int total_test_count() const;
119041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
119141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the number of tests that should run.
119241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  int test_to_run_count() const;
119341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1194fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Gets the time of the test program start, in ms from the start of the
1195fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // UNIX epoch.
1196fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  TimeInMillis start_timestamp() const;
1197fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
119841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the elapsed time, in milliseconds.
119941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TimeInMillis elapsed_time() const;
120041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
120141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the unit test passed (i.e. all test cases passed).
120241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Passed() const;
120341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
120441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns true iff the unit test failed (i.e. some test case failed
120541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // or something outside of all tests failed).
120641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  bool Failed() const;
120741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
120841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the i-th test case among all the test cases. i can range from 0 to
120941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // total_test_case_count() - 1. If i is not in that range, returns NULL.
121041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  const TestCase* GetTestCase(int i) const;
121141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1212fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Returns the TestResult containing information on test failures and
1213fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // properties logged outside of individual test cases.
1214fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  const TestResult& ad_hoc_test_result() const;
1215fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
121641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Returns the list of event listeners that can be used to track events
121741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // inside Google Test.
121841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestEventListeners& listeners();
121941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
122041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private:
122141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Registers and returns a global test environment.  When a test
122241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // program is run, all global test environments will be set-up in
122341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // the order they were registered.  After all tests in the program
122441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // have finished, all global test environments will be torn-down in
122541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // the *reverse* order they were registered.
122641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
122741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // The UnitTest object takes ownership of the given environment.
122841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  //
122941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // This method can only be called from the main thread.
123041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  Environment* AddEnvironment(Environment* env);
123141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
123241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Adds a TestPartResult to the current TestResult object.  All
123341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
123441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // eventually call this to report their results.  The user code
123541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // should use the assertion macros instead of calling this directly.
123641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  void AddTestPartResult(TestPartResult::Type result_type,
123741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                         const char* file_name,
123841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                         int line_number,
1239fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                         const std::string& message,
1240fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                         const std::string& os_stack_trace)
1241fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
124241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
1243fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // Adds a TestProperty to the current TestResult object when invoked from
1244fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
1245fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // from SetUpTestCase or TearDownTestCase, or to the global property set
1246fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // when invoked elsewhere.  If the result already contains a property with
1247fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  // the same key, the value will be updated.
1248fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  void RecordProperty(const std::string& key, const std::string& value);
124941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
125041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // Gets the i-th test case among all the test cases. i can range from 0 to
125141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // total_test_case_count() - 1. If i is not in that range, returns NULL.
125241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  TestCase* GetMutableTestCase(int i);
125341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
12541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Accessors for the implementation object.
12551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  internal::UnitTestImpl* impl() { return impl_; }
12561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  const internal::UnitTestImpl* impl() const { return impl_; }
125741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
125841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // These classes and funcions are friends as they need to access private
125941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // members of UnitTest.
126041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class Test;
126141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend class internal::AssertHelper;
12621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  friend class internal::ScopedTrace;
1263fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  friend class internal::StreamingListenerTest;
1264fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  friend class internal::UnitTestRecordPropertyTestHelper;
126541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend Environment* AddGlobalTestEnvironment(Environment* env);
126641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend internal::UnitTestImpl* internal::GetUnitTestImpl();
126741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  friend void internal::ReportFailureInUnknownLocation(
126841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      TestPartResult::Type result_type,
1269fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      const std::string& message);
12701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Creates an empty UnitTest.
12721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  UnitTest();
12731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // D'tor
12751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual ~UnitTest();
12761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
12781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Google Test trace stack.
1279fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  void PushGTestTrace(const internal::TraceInfo& trace)
1280fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
12811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Pops a trace from the per-thread Google Test trace stack.
1283fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  void PopGTestTrace()
1284fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      GTEST_LOCK_EXCLUDED_(mutex_);
12851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Protects mutable state in *impl_.  This is mutable as some const
12871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // methods need to lock it too.
12881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  mutable internal::Mutex mutex_;
12891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Opaque implementation object.  This field is never changed once
12911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // the object is constructed.  We don't mark it as const here, as
12921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // doing so will cause a warning in the constructor of UnitTest.
12931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Mutable state in *impl_ is protected by mutex_.
12941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  internal::UnitTestImpl* impl_;
12951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
12961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // We disallow copying UnitTest.
12971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
12981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
12991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
13001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A convenient wrapper for adding an environment for the test
13011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// program.
13021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
13031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// You should call this before RUN_ALL_TESTS() is called, probably in
13041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// main().  If you use gtest_main, you need to call this before main()
13051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// starts for it to take effect.  For example, you can define a global
13061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// variable like this:
13071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
13081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   testing::Environment* const foo_env =
13091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//       testing::AddGlobalTestEnvironment(new FooEnvironment);
13101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
13111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// However, we strongly recommend you to write your own main() and
13121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// call AddGlobalTestEnvironment() there, as relying on initialization
13131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// of global variables makes the code harder to read and may cause
13141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// problems when you register multiple environments from different
13151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// translation units and the environments have dependencies among them
13161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (remember that the compiler doesn't guarantee the order in which
13171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// global variables from different translation units are initialized).
13181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniainline Environment* AddGlobalTestEnvironment(Environment* env) {
13191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  return UnitTest::GetInstance()->AddEnvironment(env);
13201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
13211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
13221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Initializes Google Test.  This must be called before calling
13231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// RUN_ALL_TESTS().  In particular, it parses a command line for the
13241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// flags that Google Test recognizes.  Whenever a Google Test flag is
13251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// seen, it is removed from argv, and *argc is decremented.
13261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
13271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// No value is returned.  Instead, the Google Test flag variables are
13281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// updated.
13291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
13301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Calling the function for the second time has no user-visible effect.
133141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ void InitGoogleTest(int* argc, char** argv);
13321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
13331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This overloaded version can be used in Windows programs compiled in
13341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// UNICODE mode.
133541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
13361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
13371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace internal {
13381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1339fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
1340fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// value of type ToPrint that is an operand of a comparison assertion
1341fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// (e.g. ASSERT_EQ).  OtherOperand is the type of the other operand in
1342fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// the comparison, and is used to help determine the best way to
1343fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// format the value.  In particular, when the value is a C string
1344fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// (char pointer) and the other operand is an STL string object, we
1345fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// want to format the C string as a string, since we know it is
1346fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// compared by value with the string object.  If the value is a char
1347fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// pointer but the other operand is not an STL string object, we don't
1348fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// know whether the pointer is supposed to point to a NUL-terminated
1349fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// string, and thus want to print it as a pointer to be safe.
1350fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes//
1351fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1352fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1353fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// The default case.
1354fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughestemplate <typename ToPrint, typename OtherOperand>
1355fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesclass FormatForComparison {
1356fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes public:
1357fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static ::std::string Format(const ToPrint& value) {
1358fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return ::testing::PrintToString(value);
1359fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
1360fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes};
1361fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1362fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// Array.
1363fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughestemplate <typename ToPrint, size_t N, typename OtherOperand>
1364fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesclass FormatForComparison<ToPrint[N], OtherOperand> {
1365fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes public:
1366fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  static ::std::string Format(const ToPrint* value) {
1367fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
1368fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
1369fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes};
1370fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1371fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// By default, print C string as pointers to be safe, as we don't know
1372fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// whether they actually point to a NUL-terminated string.
1373fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1374fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType)                \
1375fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  template <typename OtherOperand>                                      \
1376fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  class FormatForComparison<CharType*, OtherOperand> {                  \
1377fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes   public:                                                              \
1378fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    static ::std::string Format(CharType* value) {                      \
1379fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      return ::testing::PrintToString(static_cast<const void*>(value)); \
1380fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    }                                                                   \
1381fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
1382fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1383fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
1384fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
1385fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
1386fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
1387fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1388fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
1389fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1390fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// If a C string is compared with an STL string object, we know it's meant
1391fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// to point to a NUL-terminated string, and thus can print it as a string.
1392fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1393fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
1394fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  template <>                                                           \
1395fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  class FormatForComparison<CharType*, OtherStringType> {               \
1396fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes   public:                                                              \
1397fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    static ::std::string Format(CharType* value) {                      \
1398fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes      return ::testing::PrintToString(value);                           \
1399fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    }                                                                   \
1400fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
1401fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1402fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
1403fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
1404fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1405fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#if GTEST_HAS_GLOBAL_STRING
1406fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
1407fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
1408fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#endif
1409fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1410fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#if GTEST_HAS_GLOBAL_WSTRING
1411fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
1412fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
1413fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#endif
1414fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1415fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#if GTEST_HAS_STD_WSTRING
1416fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
1417fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
1418fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#endif
1419fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
1420fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
1421fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
14221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
14231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// operand to be used in a failure message.  The type (but not value)
14241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// of the other operand may affect the format.  This allows us to
14251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// print a char* as a raw pointer when it is compared against another
1426fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// char* or void*, and print it as a C string when it is compared
1427fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// against an std::string object, for example.
14281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
14291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
14301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T1, typename T2>
1431fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesstd::string FormatForComparisonFailureMessage(
1432fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    const T1& value, const T2& /* other_operand */) {
1433fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  return FormatForComparison<T1, T2>::Format(value);
14341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
14351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper function for {ASSERT|EXPECT}_EQ.
14371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T1, typename T2>
14381be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaAssertionResult CmpHelperEQ(const char* expected_expression,
14391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                            const char* actual_expression,
14401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                            const T1& expected,
14411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                            const T2& actual) {
14421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#ifdef _MSC_VER
144341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# pragma warning(push)          // Saves the current warning state.
144441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# pragma warning(disable:4389)  // Temporarily disables warning on
1445fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes                                // signed/unsigned mismatch.
14461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif
14471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  if (expected == actual) {
14491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return AssertionSuccess();
14501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
14511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#ifdef _MSC_VER
145341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# pragma warning(pop)          // Restores the warning state.
14541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif
14551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  return EqFailure(expected_expression,
14571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   actual_expression,
14581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   FormatForComparisonFailureMessage(expected, actual),
14591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   FormatForComparisonFailureMessage(actual, expected),
14601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   false);
14611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
14621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// With this overloaded version, we allow anonymous enums to be used
14641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
14651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// can be implicitly cast to BiggestInt.
146641d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
146741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                       const char* actual_expression,
146841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                       BiggestInt expected,
146941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                       BiggestInt actual);
14701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper class for {ASSERT|EXPECT}_EQ.  The template argument
14721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
14731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// is a null pointer literal.  The following default implementation is
14741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// for lhs_is_null_literal being false.
14751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <bool lhs_is_null_literal>
14761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass EqHelper {
14771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
14781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // This templatized version is for the general case.
14791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  template <typename T1, typename T2>
14801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static AssertionResult Compare(const char* expected_expression,
14811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 const char* actual_expression,
14821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 const T1& expected,
14831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 const T2& actual) {
14841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return CmpHelperEQ(expected_expression, actual_expression, expected,
14851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                       actual);
14861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
14871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
14881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // With this overloaded version, we allow anonymous enums to be used
14891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
14901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // enums can be implicitly cast to BiggestInt.
14911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //
14921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Even though its body looks the same as the above version, we
14931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // cannot merge the two, as it will make anonymous enums unhappy.
14941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static AssertionResult Compare(const char* expected_expression,
14951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 const char* actual_expression,
14961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 BiggestInt expected,
14971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                 BiggestInt actual) {
14981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return CmpHelperEQ(expected_expression, actual_expression, expected,
14991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                       actual);
15001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
15011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
15021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This specialization is used when the first argument to ASSERT_EQ()
150441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// is a null pointer literal, like NULL, false, or 0.
15051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <>
15061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass EqHelper<true> {
15071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
15081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // We define two overloaded versions of Compare().  The first
15091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // version will be picked when the second argument to ASSERT_EQ() is
15101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
15111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // EXPECT_EQ(false, a_bool).
15121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  template <typename T1, typename T2>
151341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static AssertionResult Compare(
151441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* expected_expression,
151541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* actual_expression,
151641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const T1& expected,
151741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const T2& actual,
151841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // The following line prevents this overload from being considered if T2
151941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
152041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // expands to Compare("", "", NULL, my_ptr), which requires a conversion
152141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // to match the Secret* in the other overload, which would otherwise make
152241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // this template match better.
152341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
15241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return CmpHelperEQ(expected_expression, actual_expression, expected,
15251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                       actual);
15261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
15271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
152841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // This version will be picked when the second argument to ASSERT_EQ() is a
152941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
153041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  template <typename T>
153141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  static AssertionResult Compare(
153241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* expected_expression,
153341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      const char* actual_expression,
153441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // We used to have a second template parameter instead of Secret*.  That
153541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // template parameter would deduce to 'long', making this a better match
153641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // than the first overload even without the first overload's EnableIf.
153741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
153841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // non-pointer argument" (even a deduced integral argument), so the old
153941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      // implementation caused warnings in user code.
154041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      Secret* /* expected (NULL) */,
154141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      T* actual) {
15421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    // We already know that 'expected' is a null pointer.
15431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return CmpHelperEQ(expected_expression, actual_expression,
154441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                       static_cast<T*>(NULL), actual);
15451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
15461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
15471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A macro for implementing the helper functions needed to implement
15491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
15501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// of similar code.
15511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
15521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// For each templatized helper function, we also define an overloaded
15531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// version for BiggestInt in order to reduce code bloat and allow
15541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
15551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// with gcc 4.
15561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
15571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
15591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T1, typename T2>\
15601be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
15611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                   const T1& val1, const T2& val2) {\
15621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  if (val1 op val2) {\
15631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return AssertionSuccess();\
15641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  } else {\
156541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    return AssertionFailure() \
156641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot        << "Expected: (" << expr1 << ") " #op " (" << expr2\
15671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania        << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
15681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania        << " vs " << FormatForComparisonFailureMessage(val2, val1);\
15691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }\
15701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}\
157141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelper##op_name(\
157241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
15731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Implements the helper function for {ASSERT|EXPECT}_NE
157741d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_IMPL_CMP_HELPER_(NE, !=);
15781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Implements the helper function for {ASSERT|EXPECT}_LE
157941d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_IMPL_CMP_HELPER_(LE, <=);
15801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Implements the helper function for {ASSERT|EXPECT}_LT
1581fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_CMP_HELPER_(LT, <);
15821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Implements the helper function for {ASSERT|EXPECT}_GE
158341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_IMPL_CMP_HELPER_(GE, >=);
15841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Implements the helper function for {ASSERT|EXPECT}_GT
1585fc2de66453b0669c09eaca643b07d34443858b6fElliott HughesGTEST_IMPL_CMP_HELPER_(GT, >);
15861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#undef GTEST_IMPL_CMP_HELPER_
15881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper function for {ASSERT|EXPECT}_STREQ.
15901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
15911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
159241d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
159341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* actual_expression,
159441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* expected,
159541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* actual);
15961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
15971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
15981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
15991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
160041d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
160141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* actual_expression,
160241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* expected,
160341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* actual);
16041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper function for {ASSERT|EXPECT}_STRNE.
16061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
160841d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
160941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* s2_expression,
161041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* s1,
161141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* s2);
16121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The helper function for {ASSERT|EXPECT}_STRCASENE.
16141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
161641d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
161741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* s2_expression,
161841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* s1,
161941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                              const char* s2);
16201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Helper function for *_STREQ on wide strings.
16231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
162541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
162641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* actual_expression,
162741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const wchar_t* expected,
162841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const wchar_t* actual);
16291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Helper function for *_STRNE on wide strings.
16311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
163341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
163441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const char* s2_expression,
163541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const wchar_t* s1,
163641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                          const wchar_t* s2);
16371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}  // namespace internal
16391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// IsSubstring() and IsNotSubstring() are intended to be used as the
16411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
16421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// themselves.  They check whether needle is a substring of haystack
16431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (NULL is considered a substring of itself only), and return an
16441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// appropriate error message when they fail.
16451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The {needle,haystack}_expr arguments are the stringified
16471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// expressions that generated the two real arguments.
164841d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsSubstring(
16491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle, const char* haystack);
165141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsSubstring(
16521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const wchar_t* needle, const wchar_t* haystack);
165441d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsNotSubstring(
16551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle, const char* haystack);
165741d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsNotSubstring(
16581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const wchar_t* needle, const wchar_t* haystack);
166041d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsSubstring(
16611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const ::std::string& needle, const ::std::string& haystack);
166341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsNotSubstring(
16641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const ::std::string& needle, const ::std::string& haystack);
16661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_STD_WSTRING
166841d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsSubstring(
16691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const ::std::wstring& needle, const ::std::wstring& haystack);
167141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult IsNotSubstring(
16721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const char* needle_expr, const char* haystack_expr,
16731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const ::std::wstring& needle, const ::std::wstring& haystack);
16741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_STD_WSTRING
16751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace internal {
16771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Helper template function for comparing floating-points.
16791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Template parameter:
16811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   RawType: the raw floating-point type (either float or double)
16831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
16841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
16851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename RawType>
16861be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaAssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
16871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                         const char* actual_expression,
16881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                         RawType expected,
16891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                                         RawType actual) {
16901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  const FloatingPoint<RawType> lhs(expected), rhs(actual);
16911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
16921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  if (lhs.AlmostEquals(rhs)) {
16931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    return AssertionSuccess();
16941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
16951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
169641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  ::std::stringstream expected_ss;
16971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
16981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania              << expected;
16991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
170041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  ::std::stringstream actual_ss;
17011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
17021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania            << actual;
17031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  return EqFailure(expected_expression,
17051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   actual_expression,
170641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                   StringStreamToString(&expected_ss),
170741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                   StringStreamToString(&actual_ss),
17081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   false);
17091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
17101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Helper function for implementing ASSERT_NEAR.
17121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
17131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
171441d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
171541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                                const char* expr2,
171641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                                const char* abs_error_expr,
171741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                                double val1,
171841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                                double val2,
171941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                                double abs_error);
17201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
17221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A class that enables one to stream messages to assertion macros
172341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass GTEST_API_ AssertHelper {
17241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
17251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Constructor.
172641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  AssertHelper(TestPartResult::Type type,
172741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot               const char* file,
172841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot               int line,
17291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania               const char* message);
173041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  ~AssertHelper();
173141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
17321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Message assignment is a semantic trick to enable assertion
17331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // streaming; see the GTEST_MESSAGE_ macro below.
17341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  void operator=(const Message& message) const;
173541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
17361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
173741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // We put our data in a struct so that the size of the AssertHelper class can
173841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // be as small as possible.  This is important because gcc is incapable of
173941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // re-using stack space even for temporary variables, so every EXPECT_EQ
174041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // reserves stack space for another AssertHelper.
174141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  struct AssertHelperData {
174241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    AssertHelperData(TestPartResult::Type t,
174341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                     const char* srcfile,
174441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                     int line_num,
174541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                     const char* msg)
174641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot        : type(t), file(srcfile), line(line_num), message(msg) { }
174741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
174841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    TestPartResult::Type const type;
1749fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    const char* const file;
1750fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    int const line;
1751fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    std::string const message;
175241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
175341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot   private:
175441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
175541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  };
175641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
175741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  AssertHelperData* const data_;
17581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
17601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
17611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}  // namespace internal
17631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
176541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// The pure interface class that all value-parameterized tests inherit from.
176641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// A value-parameterized class must inherit from both ::testing::Test and
176741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// ::testing::WithParamInterface. In most cases that just means inheriting
176841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// from ::testing::TestWithParam, but more complicated test hierarchies
176941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// may need to inherit from Test and WithParamInterface at different levels.
17701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
177141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// This interface has support for accessing the test parameter value via
17721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the GetParam() method.
17731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
17741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Use it with one of the parameter generator defining functions, like Range(),
17751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Values(), ValuesIn(), Bool(), and Combine().
17761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
17771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// class FooTest : public ::testing::TestWithParam<int> {
17781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//  protected:
17791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   FooTest() {
17801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     // Can use GetParam() here.
17811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
17821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   virtual ~FooTest() {
17831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     // Can use GetParam() here.
17841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
17851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   virtual void SetUp() {
17861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     // Can use GetParam() here.
17871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
17881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   virtual void TearDown {
17891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     // Can use GetParam() here.
17901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
17911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// };
17921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// TEST_P(FooTest, DoesBar) {
17931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   // Can use GetParam() method here.
17941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Foo foo;
17951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   ASSERT_TRUE(foo.DoesBar(GetParam()));
17961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// }
17971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
17981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T>
180041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass WithParamInterface {
18011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
18021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  typedef T ParamType;
180341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  virtual ~WithParamInterface() {}
18041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // The current parameter value. Is also available in the test fixture's
180641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // constructor. This member function is non-static, even though it only
180741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // references static data, to reduce the opportunity for incorrect uses
180841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
180941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // uses a fixture whose parameter type is int.
1810fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  const ParamType& GetParam() const {
1811fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    GTEST_CHECK_(parameter_ != NULL)
1812fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes        << "GetParam() can only be called inside a value-parameterized test "
1813fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes        << "-- did you intend to write TEST_P instead of TEST_F?";
1814fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes    return *parameter_;
1815fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  }
18161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private:
18181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Sets parameter value. The caller is responsible for making sure the value
18191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // remains alive and unchanged throughout the current test.
18201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static void SetParam(const ParamType* parameter) {
18211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    parameter_ = parameter;
18221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  }
18231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // Static value used for accessing parameter during a test lifetime.
18251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  static const ParamType* parameter_;
18261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
182741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  // TestClass must be a subclass of WithParamInterface<T> and Test.
18281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  template <class TestClass> friend class internal::ParameterizedTestFactory;
18291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
18301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T>
183241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotconst T* WithParamInterface<T>::parameter_ = NULL;
183341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
183441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Most value-parameterized classes can ignore the existence of
183541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// WithParamInterface, and can just inherit from ::testing::TestWithParam.
183641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
183741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottemplate <typename T>
183841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass TestWithParam : public Test, public WithParamInterface<T> {
183941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot};
18401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
18421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros for indicating success/failure in test code.
18441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// ADD_FAILURE unconditionally adds a failure to the current test.
18461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SUCCEED generates a success - it doesn't automatically make the
18471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// current test successful, as a test is only successful when it has
18481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// no failure.
18491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// EXPECT_* verifies that a certain condition is satisfied.  If not,
18511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// it behaves like ADD_FAILURE.  In particular:
18521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_TRUE  verifies that a Boolean condition is true.
18541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_FALSE verifies that a Boolean condition is false.
18551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
18571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// that they will also abort the current function on failure.  People
18581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
18591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// writing data-driven tests often find themselves using ADD_FAILURE
18601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// and EXPECT_* more.
18611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Generates a nonfatal failure with a generic message.
18631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
18641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
186541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Generates a nonfatal failure at the given source file location with
186641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// a generic message.
186741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define ADD_FAILURE_AT(file, line) \
186841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  GTEST_MESSAGE_AT_(file, line, "Failed", \
186941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                    ::testing::TestPartResult::kNonFatalFailure)
187041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
18711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Generates a fatal failure with a generic message.
187241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
187341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
187441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Define this macro to 1 to omit the definition of FAIL(), which is a
187541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// generic name and clashes with some other libraries.
187641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_FAIL
187741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define FAIL() GTEST_FAIL()
187841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
18791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Generates a success with a generic message.
188141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
188241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
188341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Define this macro to 1 to omit the definition of SUCCEED(), which
188441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// is a generic name and clashes with some other libraries.
188541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_SUCCEED
188641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define SUCCEED() GTEST_SUCCEED()
188741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
18881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros for testing exceptions.
18901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
18911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
18921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that the statement throws the expected exception.
18931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_NO_THROW(statement):
18941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that the statement doesn't throw any exception.
18951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_ANY_THROW(statement):
18961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that the statement throws an exception.
18971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
18981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_THROW(statement, expected_exception) \
18991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
19001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_NO_THROW(statement) \
19011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
19021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_ANY_THROW(statement) \
19031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
19041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_THROW(statement, expected_exception) \
19051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
19061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_NO_THROW(statement) \
19071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
19081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_ANY_THROW(statement) \
19091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
19101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
191141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Boolean assertions. Condition can be either a Boolean expression or an
191241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// AssertionResult. For more information on how to use AssertionResult with
191341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// these macros see comments on that class.
19141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_TRUE(condition) \
19151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
19161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      GTEST_NONFATAL_FAILURE_)
19171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_FALSE(condition) \
19181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
19191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      GTEST_NONFATAL_FAILURE_)
19201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_TRUE(condition) \
19211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
19221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      GTEST_FATAL_FAILURE_)
19231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_FALSE(condition) \
19241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
19251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      GTEST_FATAL_FAILURE_)
19261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
19271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Includes the auto-generated header that implements a family of
19281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// generic predicate assertion macros.
192941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest_pred_impl.h"
19301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
19311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros for testing equalities and inequalities.
19321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
19341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_NE(v1, v2):           Tests that v1 != v2
19351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_LT(v1, v2):           Tests that v1 < v2
19361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_LE(v1, v2):           Tests that v1 <= v2
19371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_GT(v1, v2):           Tests that v1 > v2
19381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_GE(v1, v2):           Tests that v1 >= v2
19391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// When they are not, Google Test prints both the tested expressions and
19411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// their actual values.  The values must be compatible built-in types,
19421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// or you will get a compiler error.  By "compatible" we mean that the
19431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// values can be compared by the respective operator.
19441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Note:
19461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   1. It is possible to make a user-defined type work with
19481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   {ASSERT|EXPECT}_??(), but that requires overloading the
19491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   comparison operators and is thus discouraged by the Google C++
19501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   Usage Guide.  Therefore, you are advised to use the
19511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
19521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   equal.
19531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
19551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   pointers (in particular, C strings).  Therefore, if you use it
19561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   with two C strings, you are testing how their locations in memory
19571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   are related, not how their content is related.  To compare two C
19581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   strings by content, use {ASSERT|EXPECT}_STR*().
19591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
19611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
19621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   what the actual value is when it fails, and similarly for the
19631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   other comparisons.
19641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
19661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   evaluate their arguments, which is undefined.
19671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   5. These macros evaluate their arguments exactly once.
19691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Examples:
19711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
19721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_NE(5, Foo());
19731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_EQ(NULL, a_pointer);
19741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   ASSERT_LT(i, array_size);
19751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   ASSERT_GT(records.size(), 0) << "There is no record left.";
19761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
19771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_EQ(expected, actual) \
19781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal:: \
19791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
19801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
19811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_NE(expected, actual) \
19821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
19831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_LE(val1, val2) \
19841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
19851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_LT(val1, val2) \
19861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
19871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_GE(val1, val2) \
19881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
19891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_GT(val1, val2) \
19901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
19911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
199241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_EQ(expected, actual) \
19931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal:: \
19941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
19951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
199641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_NE(val1, val2) \
19971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
199841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_LE(val1, val2) \
19991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
200041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_LT(val1, val2) \
20011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
200241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_GE(val1, val2) \
20031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
200441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_ASSERT_GT(val1, val2) \
20051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
20061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
200741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
200841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// ASSERT_XY(), which clashes with some users' own code.
200941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
201041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_EQ
201141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
201241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
201341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
201441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_NE
201541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
201641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
201741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
201841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_LE
201941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
202041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
202141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
202241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_LT
202341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
202441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
202541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
202641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_GE
202741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
202841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
202941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
203041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_ASSERT_GT
203141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
203241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
203341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
2034fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// C-string Comparisons.  All tests treat NULL and any non-NULL string
20351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// as different.  Two NULLs are equal.
20361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
20381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
20391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
20401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
20411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// For wide or narrow string objects, you can use the
20431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// {ASSERT|EXPECT}_??() macros.
20441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Don't depend on the order in which the arguments are evaluated,
20461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// which is undefined.
20471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// These macros evaluate their arguments exactly once.
20491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_STREQ(expected, actual) \
20511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
20521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_STRNE(s1, s2) \
20531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
20541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_STRCASEEQ(expected, actual) \
20551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
20561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_STRCASENE(s1, s2)\
20571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_STREQ(expected, actual) \
20601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
20611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_STRNE(s1, s2) \
20621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
20631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_STRCASEEQ(expected, actual) \
20641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
20651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_STRCASENE(s1, s2)\
20661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros for comparing floating-point numbers.
20691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
20711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that two float values are almost equal.
20721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
20731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that two double values are almost equal.
20741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
20751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//         Tests that v1 and v2 are within the given distance to each other.
20761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
20771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Google Test uses ULP-based comparison to automatically pick a default
20781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// error bound that is appropriate for the operands.  See the
20791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// FloatingPoint template class in gtest-internal.h if you are
20801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// interested in the implementation details.
20811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_FLOAT_EQ(expected, actual)\
20831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
20841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
20851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_DOUBLE_EQ(expected, actual)\
20871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
20881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
20891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_FLOAT_EQ(expected, actual)\
20911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
20921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
20931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_DOUBLE_EQ(expected, actual)\
20951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
20961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      expected, actual)
20971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
20981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_NEAR(val1, val2, abs_error)\
20991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
21001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      val1, val2, abs_error)
21011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_NEAR(val1, val2, abs_error)\
21031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
21041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                      val1, val2, abs_error)
21051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// These predicate format functions work on floating-point values, and
21071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
21081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
21101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Asserts that val1 is less than, or almost equal to, val2.  Fails
21121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// otherwise.  In particular, it fails if either val1 or val2 is NaN.
211341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
211441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                   float val1, float val2);
211541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
211641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                                    double val1, double val2);
21171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_OS_WINDOWS
21201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros that test for HRESULT failure and success, these are only useful
21221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// on Windows, and rely on Windows SDK macros and APIs to compile.
21231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
21251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// When expr unexpectedly fails or succeeds, Google Test prints the
21271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// expected result and the actual result with both a human-readable
21281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// string representation of the error, if available, as well as the
21291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// hex result code.
213041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define EXPECT_HRESULT_SUCCEEDED(expr) \
21311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
21321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
213341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_HRESULT_SUCCEEDED(expr) \
21341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
21351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
213641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define EXPECT_HRESULT_FAILED(expr) \
21371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
21381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
213941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define ASSERT_HRESULT_FAILED(expr) \
21401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
21411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_OS_WINDOWS
21431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Macros that execute statement and check that it doesn't generate new fatal
21451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// failures in the current thread.
21461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
21481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Examples:
21501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   EXPECT_NO_FATAL_FAILURE(Process());
21521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
21531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define ASSERT_NO_FATAL_FAILURE(statement) \
21551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
21561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define EXPECT_NO_FATAL_FAILURE(statement) \
21571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
21581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Causes a trace (including the source file path, the current line
21601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// number, and the given message) to be included in every test failure
21611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// message generated by code in the current scope.  The effect is
21621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// undone when the control leaves the current scope.
21631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The message argument can be anything streamable to std::ostream.
21651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// In the implementation, we include the current line number as part
21671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
21681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// to appear in the same block - as long as they are on different
21691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// lines.
21701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define SCOPED_TRACE(message) \
21711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
21721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    __FILE__, __LINE__, ::testing::Message() << (message))
21731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
21741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Compile-time assertion for type equality.
21751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
21761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the same type.  The value it returns is not interesting.
21771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Instead of making StaticAssertTypeEq a class template, we make it a
21791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// function template that invokes a helper class template.  This
21801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
21811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// defining objects of that type.
21821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// CAVEAT:
21841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// When used inside a method of a class template,
21861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
21871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// instantiated.  For example, given:
21881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   template <typename T> class Foo {
21901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    public:
21911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
21921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   };
21931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the code:
21951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   void Test1() { Foo<bool> foo; }
21971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
21981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// will NOT generate a compiler error, as Foo<bool>::Bar() is never
21991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// actually instantiated.  Instead, you need:
22001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   void Test2() { Foo<bool> foo; foo.Bar(); }
22021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// to cause a compiler error.
22041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T1, typename T2>
22051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniabool StaticAssertTypeEq() {
220641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  (void)internal::StaticAssertTypeEqHelper<T1, T2>();
22071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  return true;
22081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
22091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
22101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Defines a test.
22111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The first parameter is the name of the test case, and the second
22131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// parameter is the name of the test within the test case.
22141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The convention is to end the test case name with "Test".  For
22161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// example, a test case for the Foo class can be named FooTest.
22171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The user should put his test code between braces after using this
22191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// macro.  Example:
22201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   TEST(FooTest, InitializesCorrectly) {
22221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     Foo foo;
22231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     EXPECT_TRUE(foo.StatusIsOK());
22241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
22251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
22261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Note that we call GetTestTypeId() instead of GetTypeId<
22271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// ::testing::Test>() here to get the type ID of testing::Test.  This
22281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// is to work around a suspected linker bug when using Google Test as
22291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// a framework on Mac OS X.  The bug causes GetTypeId<
22301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// ::testing::Test>() to return different values depending on whether
22311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the call is from the Google Test framework itself or from user test
22321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// code.  GetTestTypeId() is guaranteed to always return the same
22331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// value, as it always calls GetTypeId<>() from the Google Test
22341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// framework.
223541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#define GTEST_TEST(test_case_name, test_name)\
22361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_(test_case_name, test_name, \
22371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania              ::testing::Test, ::testing::internal::GetTestTypeId())
22381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
223941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Define this macro to 1 to omit the definition of TEST(), which
224041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// is a generic name and clashes with some other libraries.
224141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if !GTEST_DONT_DEFINE_TEST
224241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
224341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif
22441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
22451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Defines a test that uses a test fixture.
22461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The first parameter is the name of the test fixture class, which
22481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// also doubles as the test case name.  The second parameter is the
22491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// name of the test within the test case.
22501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A test fixture class must be declared earlier.  The user should put
22521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// his test code between braces after using this macro.  Example:
22531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   class FooTest : public testing::Test {
22551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//    protected:
22561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     virtual void SetUp() { b_.AddElement(3); }
22571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     Foo a_;
22591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     Foo b_;
22601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   };
22611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   TEST_F(FooTest, InitializesCorrectly) {
22631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     EXPECT_TRUE(a_.StatusIsOK());
22641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
22651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   TEST_F(FooTest, ReturnsElementCountCorrectly) {
22671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     EXPECT_EQ(0, a_.size());
22681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     EXPECT_EQ(1, b_.size());
22691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//   }
22701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
22711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define TEST_F(test_fixture, test_name)\
22721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_TEST_(test_fixture, test_name, test_fixture, \
22731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania              ::testing::internal::GetTypeId<test_fixture>())
22741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2275fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes}  // namespace testing
2276fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes
2277fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// Use this function in main() to run all tests.  It returns 0 if all
22781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// tests are successful, or 1 otherwise.
22791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
22801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// RUN_ALL_TESTS() should be invoked after the command line has been
22811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// parsed by InitGoogleTest().
2282fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes//
2283fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// This function was formerly a macro; thus, it is in the global
2284fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes// namespace and has an all-caps name.
2285fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesint RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
22861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2287fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughesinline int RUN_ALL_TESTS() {
2288fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  return ::testing::UnitTest::GetInstance()->Run();
2289fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes}
22901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
22911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_INCLUDE_GTEST_GTEST_H_
2292