13d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Copyright 2005, Google Inc.
23d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// All rights reserved.
33d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
43d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Redistribution and use in source and binary forms, with or without
53d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// modification, are permitted provided that the following conditions are
63d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// met:
73d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
83d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Redistributions of source code must retain the above copyright
93d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// notice, this list of conditions and the following disclaimer.
103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Redistributions in binary form must reproduce the above
113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// copyright notice, this list of conditions and the following disclaimer
123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in the documentation and/or other materials provided with the
133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// distribution.
143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     * Neither the name of Google Inc. nor the names of its
153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// contributors may be used to endorse or promote products derived from
163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this software without specific prior written permission.
173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Author: wan@google.com (Zhanyong Wan)
313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The Google C++ Testing Framework (Google Test)
333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This header file defines the public API for Google Test.  It should be
353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// included by any test program that uses Google Test.
363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// leave some internal implementation details in this header file.
393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// They are clearly marked by comments like this:
403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Such code is NOT meant to be used by a user directly, and is subject
443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// program!
463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Acknowledgment: Google Test borrowed the idea of automatic test
483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// easyUnit framework.
503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_INCLUDE_GTEST_GTEST_H_
533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <limits>
553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <vector>
563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-internal.h"
583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-string.h"
593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-death-test.h"
603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-message.h"
613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-param-test.h"
623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-printers.h"
633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest_prod.h"
643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-test-part.h"
653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/gtest-typed-test.h"
663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Depending on the platform, different string classes are available.
683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// On Linux, in addition to ::std::string, Google also makes use of
693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// class ::string, which has the same interface as ::std::string, but
703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// has a different implementation.
713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ::string is available AND is a distinct type to ::std::string, or
743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// define it to 0 to indicate otherwise.
753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If the user's ::std::string and ::string are the same class due to
773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// heuristically.
813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace testing {
833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Declares the flags.
853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag temporary enables the disabled tests.
873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(also_run_disabled_tests);
883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag brings the debugger on an assertion failure.
903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(break_on_failure);
913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag controls whether Google Test catches all test-thrown exceptions
933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// and logs them as failures.
943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(catch_exceptions);
953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag enables using colors in terminal output. Available values are
973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to let Google Test decide.
993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_string_(color);
1003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag sets up the filter to select by name using a glob pattern
1023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the tests to run. If the filter is not given all tests are executed.
1033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_string_(filter);
1043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag causes the Google Test to list tests. None of the tests listed
1063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// are actually run if the flag is provided.
1073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(list_tests);
1083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag controls whether Google Test emits a detailed XML report to a file
1103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in addition to its normal textual output.
1113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_string_(output);
1123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flags control whether Google Test prints the elapsed time for each
1143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// test.
1153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(print_time);
1163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag specifies the random number seed.
1183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_int32_(random_seed);
1193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag sets how many times the tests are repeated. The default value
1213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// is 1. If the value is -1 the tests are repeating forever.
1223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_int32_(repeat);
1233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag controls whether Google Test includes Google Test internal
1253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// stack frames in failure stack traces.
1263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(show_internal_stack_frames);
1273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When this flag is specified, tests' order is randomized on every iteration.
1293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(shuffle);
1303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This flag specifies the maximum number of stack frames to be
1323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// printed in a failure message.
1333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_int32_(stack_trace_depth);
1343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When this flag is specified, a failed assertion will throw an
1363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// exception if exceptions are enabled, or exit the program with a
1373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// non-zero code otherwise.
1383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_bool_(throw_on_failure);
1393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When this flag is set with a "host:port" string, on supported
1413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// platforms test results are streamed to the specified port on
1423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the specified host machine.
1433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_DECLARE_string_(stream_result_to);
1443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The upper limit for valid stack trace depths.
1463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickconst int kMaxStackTraceDepth = 100;
1473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace internal {
1493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass AssertHelper;
1513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass DefaultGlobalTestPartResultReporter;
1523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass ExecDeathTest;
1533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass NoExecDeathTest;
1543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass FinalSuccessChecker;
1553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTestFlagSaver;
1563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestResultAccessor;
1573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestEventListenersAccessor;
1583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestEventRepeater;
1593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass WindowsDeathTest;
1603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass UnitTestImpl* GetUnitTestImpl();
1613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
1623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick                                    const String& message);
1633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Converts a streamable value to a String.  A NULL pointer is
1653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// converted to "(null)".  When the input value is a ::string,
1663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ::std::string, ::wstring, or ::std::wstring object, each NUL
1673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// character in it is replaced with "\\0".
1683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Declared in gtest-internal.h but defined here, so that it has access
1693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to the definition of the Message class, required by the ARM
1703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compiler.
1713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T>
1723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickString StreamableToString(const T& streamable) {
1733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  return (Message() << streamable).GetString();
1743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}
1753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}  // namespace internal
1773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The friend relationship of some of these classes is cyclic.
1793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If we don't forward declare them the compiler might confuse the classes
1803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in friendship clauses with same named classes on the scope.
1813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass Test;
1823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestCase;
1833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestInfo;
1843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass UnitTest;
1853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
1863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A class for indicating whether an assertion was successful.  When
1873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the assertion wasn't successful, the AssertionResult object
1883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// remembers a non-empty message that describes how it failed.
1893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// To create an instance of this class, use one of the factory functions
1913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (AssertionSuccess() and AssertionFailure()).
1923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This class is useful for two purposes:
1943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   1. Defining predicate functions to be used with Boolean test assertions
1953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
1963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   2. Defining predicate-format functions to be
1973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
1983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
1993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For example, if you define IsEven predicate:
2003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   testing::AssertionResult IsEven(int n) {
2023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     if ((n % 2) == 0)
2033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionSuccess();
2043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     else
2053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionFailure() << n << " is odd";
2063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   }
2073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
2093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// will print the message
2103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Value of: IsEven(Fib(5))
2123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     Actual: false (5 is odd)
2133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Expected: true
2143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// instead of a more opaque
2163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Value of: IsEven(Fib(5))
2183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     Actual: false
2193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Expected: true
2203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in case IsEven is a simple Boolean predicate.
2223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If you expect your predicate to be reused and want to support informative
2243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
2253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// about half as often as positive ones in our tests), supply messages for
2263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// both success and failure cases:
2273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   testing::AssertionResult IsEven(int n) {
2293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     if ((n % 2) == 0)
2303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionSuccess() << n << " is even";
2313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     else
2323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionFailure() << n << " is odd";
2333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   }
2343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
2363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Value of: IsEven(Fib(6))
2383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     Actual: true (8 is even)
2393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Expected: false
2403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// NB: Predicates that support negative Boolean assertions have reduced
2423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// performance in positive ones so be careful not to use them in tests
2433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// that have lots (tens of thousands) of positive Boolean assertions.
2443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// To use this class with EXPECT_PRED_FORMAT assertions such as:
2463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   // Verifies that Foo() returns an even number.
2483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   EXPECT_PRED_FORMAT1(IsEven, Foo());
2493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// you need to define:
2513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   testing::AssertionResult IsEven(const char* expr, int n) {
2533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     if ((n % 2) == 0)
2543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionSuccess();
2553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     else
2563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//       return testing::AssertionFailure()
2573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
2583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   }
2593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If Foo() returns 5, you will see the following message:
2613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Expected: Foo() is even
2633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     Actual: it's 5
2643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
2653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ AssertionResult {
2663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
2673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Copy constructor.
2683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Used in EXPECT_TRUE/FALSE(assertion_result).
2693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  AssertionResult(const AssertionResult& other);
2703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Used in the EXPECT_TRUE/FALSE(bool_expression).
2713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  explicit AssertionResult(bool success) : success_(success) {}
2723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the assertion succeeded.
2743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  operator bool() const { return success_; }  // NOLINT
2753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
2773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  AssertionResult operator!() const;
2783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the text streamed into this AssertionResult. Test assertions
2803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // use it when they fail (i.e., the predicate's outcome doesn't match the
2813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // assertion's expectation). When nothing has been streamed into the
2823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // object, returns an empty string.
2833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* message() const {
2843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return message_.get() != NULL ?  message_->c_str() : "";
2853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
2863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TODO(vladl@google.com): Remove this after making sure no clients use it.
2873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Deprecated; please use message() instead.
2883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* failure_message() const { return message(); }
2893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Streams a custom failure message into this object.
2913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  template <typename T> AssertionResult& operator<<(const T& value) {
2923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    AppendMessage(Message() << value);
2933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return *this;
2943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
2953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
2963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Allows streaming basic output manipulators such as endl or flush into
2973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // this object.
2983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  AssertionResult& operator<<(
2993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
3003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    AppendMessage(Message() << basic_manipulator);
3013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return *this;
3023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
3033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
3053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Appends the contents of message to message_.
3063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void AppendMessage(const Message& a_message) {
3073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    if (message_.get() == NULL)
3083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      message_.reset(new ::std::string);
3093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    message_->append(a_message.GetString().c_str());
3103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
3113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Stores result of the assertion predicate.
3133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool success_;
3143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Stores the message describing the condition in case the expectation
3153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // construct is not satisfied with the predicate's outcome.
3163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Referenced via a pointer to avoid taking too much stack frame space
3173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // with test assertions.
3183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::scoped_ptr< ::std::string> message_;
3193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_ASSIGN_(AssertionResult);
3213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
3223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Makes a successful assertion result.
3243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult AssertionSuccess();
3253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Makes a failed assertion result.
3273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult AssertionFailure();
3283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Makes a failed assertion result with the given failure message.
3303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Deprecated; use AssertionFailure() << msg.
3313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
3323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The abstract class that all tests inherit from.
3343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// In Google Test, a unit test program contains one or many TestCases, and
3363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// each TestCase contains one or many Tests.
3373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When you define a test using the TEST macro, you don't need to
3393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// explicitly derive from Test - the TEST macro automatically does
3403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this for you.
3413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The only time you derive from Test is when defining a test fixture
3433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to be used a TEST_F.  For example:
3443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   class FooTest : public testing::Test {
3463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//    protected:
3473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     virtual void SetUp() { ... }
3483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     virtual void TearDown() { ... }
3493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//     ...
3503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   };
3513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   TEST_F(FooTest, Bar) { ... }
3533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   TEST_F(FooTest, Baz) { ... }
3543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
3553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Test is not copyable.
3563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ Test {
3573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
3583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class TestInfo;
3593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Defines types for pointers to functions that set up and tear down
3613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // a test case.
3623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
3633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
3643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The d'tor is virtual as we intend to inherit from Test.
3663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual ~Test();
3673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets up the stuff shared by all tests in this test case.
3693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
3703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Google Test will call Foo::SetUpTestCase() before running the first
3713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // test in test case Foo.  Hence a sub-class can define its own
3723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // SetUpTestCase() method to shadow the one defined in the super
3733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // class.
3743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void SetUpTestCase() {}
3753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Tears down the stuff shared by all tests in this test case.
3773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
3783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Google Test will call Foo::TearDownTestCase() after running the last
3793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // test in test case Foo.  Hence a sub-class can define its own
3803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TearDownTestCase() method to shadow the one defined in the super
3813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // class.
3823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void TearDownTestCase() {}
3833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the current test has a fatal failure.
3853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool HasFatalFailure();
3863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the current test has a non-fatal failure.
3883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool HasNonfatalFailure();
3893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the current test has a (either fatal or
3913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // non-fatal) failure.
3923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
3933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
3943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Logs a property for the current test.  Only the last value for a given
3953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // key is remembered.
3963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // These are public static so they can be called from utility functions
3973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // that are not members of the test fixture.
3983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The arguments are const char* instead strings, as Google Test is used
3993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // on platforms where string doesn't compile.
4003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Note that a driving consideration for these RecordProperty methods
4023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // was to produce xml output suited to the Greenspan charting utility,
4033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // which at present will only chart values that fit in a 32-bit int. It
4043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // is the user's responsibility to restrict their values to 32-bit ints
4053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // if they intend them to be used with Greenspan.
4063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void RecordProperty(const char* key, const char* value);
4073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void RecordProperty(const char* key, int value);
4083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick protected:
4103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Creates a Test object.
4113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  Test();
4123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets up the test fixture.
4143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual void SetUp();
4153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Tears down the test fixture.
4173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual void TearDown();
4183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
4203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the current test has the same fixture class as
4213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // the first test in the current test case.
4223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool HasSameFixtureClass();
4233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Runs the test after the test fixture has been set up.
4253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // A sub-class must implement this to define the test logic.
4273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
4293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Instead, use the TEST or TEST_F macro.
4303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual void TestBody() = 0;
4313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets up, executes, and tears down the test.
4333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void Run();
4343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Deletes self.  We deliberately pick an unusual name for this
4363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // internal method to avoid clashing with names used in user TESTs.
4373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void DeleteSelf_() { delete this; }
4383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Uses a GTestFlagSaver to save and restore all Google Test flags.
4403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const internal::GTestFlagSaver* const gtest_flag_saver_;
4413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Often a user mis-spells SetUp() as Setup() and spends a long time
4433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // wondering why it is never called by Google Test.  The declaration of
4443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // the following method is solely for catching such an error at
4453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // compile time:
4463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   - The return type is deliberately chosen to be not void, so it
4483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   will be a conflict if a user declares void Setup() in his test
4493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   fixture.
4503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   - This method is private, so it will be another compiler error
4523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   if a user calls it from his test fixture.
4533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // DO NOT OVERRIDE THIS FUNCTION.
4553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
4563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // If you see an error about overriding the following function or
4573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // about it being private, you have mis-spelled SetUp() as Setup().
4583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  struct Setup_should_be_spelled_SetUp {};
4593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
4603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // We disallow copying Tests.
4623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
4633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
4643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef internal::TimeInMillis TimeInMillis;
4663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A copyable object representing a user specified test property which can be
4683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// output as a key/value string pair.
4693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
4703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Don't inherit from TestProperty as its destructor is not virtual.
4713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestProperty {
4723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
4733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // C'tor.  TestProperty does NOT have a default constructor.
4743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Always use this constructor (with parameters) to create a
4753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TestProperty object.
4763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestProperty(const char* a_key, const char* a_value) :
4773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    key_(a_key), value_(a_value) {
4783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
4793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the user supplied key.
4813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* key() const {
4823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return key_.c_str();
4833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
4843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the user supplied value.
4863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* value() const {
4873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return value_.c_str();
4883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
4893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets a new value, overriding the one supplied in the constructor.
4913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void SetValue(const char* new_value) {
4923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    value_ = new_value;
4933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
4943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
4953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
4963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The key supplied by the user.
4973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::String key_;
4983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The value supplied by the user.
4993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::String value_;
5003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
5013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The result of a single Test.  This includes a list of
5033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TestPartResults, a list of TestProperties, a count of how many
5043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// death tests there are in the Test, and how much time it took to run
5053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the Test.
5063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
5073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TestResult is not copyable.
5083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ TestResult {
5093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
5103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Creates an empty TestResult.
5113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestResult();
5123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // D'tor.  Do not inherit from TestResult.
5143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  ~TestResult();
5153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the number of all test parts.  This is the sum of the number
5173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // of successful test parts and the number of failed test parts.
5183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int total_part_count() const;
5193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the number of the test properties.
5213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int test_property_count() const;
5223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test passed (i.e. no test part failed).
5243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool Passed() const { return !Failed(); }
5253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test failed.
5273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool Failed() const;
5283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test fatally failed.
5303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool HasFatalFailure() const;
5313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test has a non-fatal failure.
5333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool HasNonfatalFailure() const;
5343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the elapsed time, in milliseconds.
5363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TimeInMillis elapsed_time() const { return elapsed_time_; }
5373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the i-th test part result among all the results. i can range
5393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // from 0 to test_property_count() - 1. If i is not in that range, aborts
5403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // the program.
5413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const TestPartResult& GetTestPartResult(int i) const;
5423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the i-th test property. i can range from 0 to
5443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // test_property_count() - 1. If i is not in that range, aborts the
5453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // program.
5463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const TestProperty& GetTestProperty(int i) const;
5473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
5493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class TestInfo;
5503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class UnitTest;
5513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::DefaultGlobalTestPartResultReporter;
5523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::ExecDeathTest;
5533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::TestResultAccessor;
5543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::UnitTestImpl;
5553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::WindowsDeathTest;
5563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the vector of TestPartResults.
5583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const std::vector<TestPartResult>& test_part_results() const {
5593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_part_results_;
5603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
5613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the vector of TestProperties.
5633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const std::vector<TestProperty>& test_properties() const {
5643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_properties_;
5653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
5663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets the elapsed time.
5683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
5693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Adds a test property to the list. The property is validated and may add
5713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
5723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // key names). If a property is already recorded for the same key, the
5733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // value will be updated, rather than storing multiple values for the same
5743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // key.
5753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void RecordProperty(const TestProperty& test_property);
5763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Adds a failure if the key is a reserved attribute of Google Test
5783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // testcase tags.  Returns true if the property is valid.
5793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TODO(russr): Validate attribute names are legal and human readable.
5803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool ValidateTestProperty(const TestProperty& test_property);
5813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Adds a test part result to the list.
5833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void AddTestPartResult(const TestPartResult& test_part_result);
5843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the death test count.
5863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int death_test_count() const { return death_test_count_; }
5873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Increments the death test count, returning the new count.
5893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int increment_death_test_count() { return ++death_test_count_; }
5903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Clears the test part results.
5923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void ClearTestPartResults();
5933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Clears the object.
5953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void Clear();
5963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
5973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Protects mutable state of the property vector and of owned
5983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // properties, whose values may be updated.
5993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::Mutex test_properites_mutex_;
6003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The vector of TestPartResults
6023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  std::vector<TestPartResult> test_part_results_;
6033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The vector of TestProperties
6043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  std::vector<TestProperty> test_properties_;
6053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Running count of death tests.
6063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int death_test_count_;
6073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The elapsed time, in milliseconds.
6083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TimeInMillis elapsed_time_;
6093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // We disallow copying TestResult.
6113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
6123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};  // class TestResult
6133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A TestInfo object stores the following information about a test:
6153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Test case name
6173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Test name
6183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Whether the test should be run
6193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   A function pointer that creates the test object when invoked
6203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//   Test result
6213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
6223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The constructor of TestInfo registers itself with the UnitTest
6233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// singleton such that the RUN_ALL_TESTS() macro knows which tests to
6243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// run.
6253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ TestInfo {
6263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
6273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Destructs a TestInfo object.  This function is not virtual, so
6283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // don't inherit from TestInfo.
6293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  ~TestInfo();
6303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the test case name.
6323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* test_case_name() const { return test_case_name_.c_str(); }
6333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the test name.
6353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* name() const { return name_.c_str(); }
6363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the name of the parameter type, or NULL if this is not a typed
6383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // or a type-parameterized test.
6393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* type_param() const {
6403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    if (type_param_.get() != NULL)
6413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      return type_param_->c_str();
6423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return NULL;
6433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
6443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the text representation of the value parameter, or NULL if this
6463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // is not a value-parameterized test.
6473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* value_param() const {
6483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    if (value_param_.get() != NULL)
6493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      return value_param_->c_str();
6503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return NULL;
6513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
6523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true if this test should run, that is if the test is not disabled
6543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // (or it is disabled but the also_run_disabled_tests flag has been specified)
6553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // and its full name matches the user-specified filter.
6563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
6573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Google Test allows the user to filter the tests by their full names.
6583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The full name of a test Bar in test case Foo is defined as
6593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // "Foo.Bar".  Only the tests that match the filter will run.
6603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
6613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // A filter is a colon-separated list of glob (not regex) patterns,
6623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // optionally followed by a '-' and a colon-separated list of
6633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // negative patterns (tests to exclude).  A test is run if it
6643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // matches one of the positive patterns and does not match any of
6653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // the negative patterns.
6663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
6673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // For example, *A*:Foo.* is a filter that matches any string that
6683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // contains the character 'A' or starts with "Foo.".
6693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool should_run() const { return should_run_; }
6703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the result of the test.
6723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const TestResult* result() const { return &result_; }
6733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
6753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_DEATH_TEST
6773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::DefaultDeathTestFactory;
6783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif  // GTEST_HAS_DEATH_TEST
6793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class Test;
6803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class TestCase;
6813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::UnitTestImpl;
6823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend TestInfo* internal::MakeAndRegisterTestInfo(
6833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      const char* test_case_name, const char* name,
6843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      const char* type_param,
6853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      const char* value_param,
6863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      internal::TypeId fixture_class_id,
6873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      Test::SetUpTestCaseFunc set_up_tc,
6883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      Test::TearDownTestCaseFunc tear_down_tc,
6893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      internal::TestFactoryBase* factory);
6903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Constructs a TestInfo object. The newly constructed instance assumes
6923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // ownership of the factory object.
6933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestInfo(const char* test_case_name, const char* name,
6943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           const char* a_type_param,
6953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           const char* a_value_param,
6963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           internal::TypeId fixture_class_id,
6973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           internal::TestFactoryBase* factory);
6983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
6993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Increments the number of death tests encountered in this test so
7003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // far.
7013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int increment_death_test_count() {
7023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return result_.increment_death_test_count();
7033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
7043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Creates the test object, runs it, records its result, and then
7063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // deletes it.
7073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void Run();
7083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void ClearTestResult(TestInfo* test_info) {
7103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    test_info->result_.Clear();
7113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
7123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // These fields are immutable properties of the test.
7143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const std::string test_case_name_;     // Test case name
7153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const std::string name_;               // Test name
7163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Name of the parameter type, or NULL if this is not a typed or a
7173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // type-parameterized test.
7183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const internal::scoped_ptr<const ::std::string> type_param_;
7193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Text representation of the value parameter, or NULL if this is not a
7203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // value-parameterized test.
7213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const internal::scoped_ptr<const ::std::string> value_param_;
7223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
7233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool should_run_;                 // True iff this test should run
7243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool is_disabled_;                // True iff this test is disabled
7253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool matches_filter_;             // True if this test matches the
7263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick                                    // user-specified filter.
7273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::TestFactoryBase* const factory_;  // The factory that creates
7283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick                                              // the test object
7293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // This field is mutable and needs to be reset before running the
7313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // test for the second time.
7323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestResult result_;
7333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
7353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};
7363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A test case, which consists of a vector of TestInfos.
7383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick//
7393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TestCase is not copyable.
7403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ TestCase {
7413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:
7423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Creates a TestCase with the given name.
7433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
7443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // TestCase does NOT have a default constructor.  Always use this
7453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // constructor to create a TestCase object.
7463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
7473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Arguments:
7483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //
7493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   name:         name of the test case
7503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   a_type_param: the name of the test's type parameter, or NULL if
7513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //                 this is not a type-parameterized test.
7523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   set_up_tc:    pointer to the function that sets up the test case
7533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  //   tear_down_tc: pointer to the function that tears down the test case
7543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestCase(const char* name, const char* a_type_param,
7553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           Test::SetUpTestCaseFunc set_up_tc,
7563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick           Test::TearDownTestCaseFunc tear_down_tc);
7573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Destructor of TestCase.
7593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  virtual ~TestCase();
7603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the name of the TestCase.
7623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* name() const { return name_.c_str(); }
7633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the name of the parameter type, or NULL if this is not a
7653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // type-parameterized test case.
7663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const char* type_param() const {
7673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    if (type_param_.get() != NULL)
7683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick      return type_param_->c_str();
7693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return NULL;
7703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
7713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true if any test in this test case should run.
7733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool should_run() const { return should_run_; }
7743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the number of successful tests in this test case.
7763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int successful_test_count() const;
7773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the number of failed tests in this test case.
7793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int failed_test_count() const;
7803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the number of disabled tests in this test case.
7823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int disabled_test_count() const;
7833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Get the number of tests in this test case that should run.
7853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int test_to_run_count() const;
7863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the number of all tests in this test case.
7883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  int total_test_count() const;
7893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test case passed.
7913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool Passed() const { return !Failed(); }
7923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff the test case failed.
7943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  bool Failed() const { return failed_test_count() > 0; }
7953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the elapsed time, in milliseconds.
7973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TimeInMillis elapsed_time() const { return elapsed_time_; }
7983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
7993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the i-th test among all the tests. i can range from 0 to
8003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // total_test_count() - 1. If i is not in that range, returns NULL.
8013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const TestInfo* GetTestInfo(int i) const;
8023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:
8043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class Test;
8053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  friend class internal::UnitTestImpl;
8063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the (mutable) vector of TestInfos in this TestCase.
8083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
8093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Gets the (immutable) vector of TestInfos in this TestCase.
8113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const std::vector<TestInfo*>& test_info_list() const {
8123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_info_list_;
8133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns the i-th test among all the tests. i can range from 0 to
8163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // total_test_count() - 1. If i is not in that range, returns NULL.
8173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  TestInfo* GetMutableTestInfo(int i);
8183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Sets the should_run member.
8203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void set_should_run(bool should) { should_run_ = should; }
8213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
8233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // destruction of the TestCase object.
8243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void AddTestInfo(TestInfo * test_info);
8253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Clears the results of all tests in this test case.
8273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void ClearResult();
8283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Clears the results of all tests in the given test case.
8303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static void ClearTestCaseResult(TestCase* test_case) {
8313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    test_case->ClearResult();
8323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Runs every test in this TestCase.
8353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void Run();
8363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
8383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // for catching exceptions thrown from SetUpTestCase().
8393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void RunSetUpTestCase() { (*set_up_tc_)(); }
8403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Runs TearDownTestCase() for this TestCase.  This wrapper is
8423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // needed for catching exceptions thrown from TearDownTestCase().
8433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void RunTearDownTestCase() { (*tear_down_tc_)(); }
8443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff test passed.
8463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool TestPassed(const TestInfo* test_info) {
8473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_info->should_run() && test_info->result()->Passed();
8483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff test failed.
8513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool TestFailed(const TestInfo* test_info) {
8523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_info->should_run() && test_info->result()->Failed();
8533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true iff test is disabled.
8563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool TestDisabled(const TestInfo* test_info) {
8573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_info->is_disabled_;
8583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Returns true if the given test should run.
8613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  static bool ShouldRunTest(const TestInfo* test_info) {
8623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick    return test_info->should_run();
8633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  }
8643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Shuffles the tests in this test case.
8663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void ShuffleTests(internal::Random* random);
8673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Restores the test order to before the first shuffle.
8693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  void UnshuffleTests();
8703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick
8713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Name of the test case.
8723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  internal::String name_;
8733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // Name of the parameter type, or NULL if this is not a typed or a
8743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // type-parameterized test.
8753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  const internal::scoped_ptr<const ::std::string> type_param_;
8763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // The vector of TestInfos in their original order.  It owns the
8773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  // elements in the vector.
8783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick  std::vector<TestInfo*> test_info_list_;
879