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);
92441d0579e8de9ef4ff178fc499104