1fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Copyright 2005, Google Inc.
2fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// All rights reserved.
3fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
4fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Redistribution and use in source and binary forms, with or without
5fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// modification, are permitted provided that the following conditions are
6fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// met:
7fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
8fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Redistributions of source code must retain the above copyright
9fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// notice, this list of conditions and the following disclaimer.
10fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Redistributions in binary form must reproduce the above
11fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// copyright notice, this list of conditions and the following disclaimer
12fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// in the documentation and/or other materials provided with the
13fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// distribution.
14fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Neither the name of Google Inc. nor the names of its
15fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// contributors may be used to endorse or promote products derived from
16fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// this software without specific prior written permission.
17fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
18fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
30fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Author: wan@google.com (Zhanyong Wan)
31fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
32fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The Google C++ Testing Framework (Google Test)
33fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
34fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This header file defines the public API for Google Test.  It should be
35fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// included by any test program that uses Google Test.
36fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
37fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
38fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// leave some internal implementation details in this header file.
39fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// They are clearly marked by comments like this:
40fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
41fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
42fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
43fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Such code is NOT meant to be used by a user directly, and is subject
44fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
45fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// program!
46fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
47fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Acknowledgment: Google Test borrowed the idea of automatic test
48fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
49fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// easyUnit framework.
50fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
51fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
52fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#define GTEST_INCLUDE_GTEST_GTEST_H_
53fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
54fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <limits>
55fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/internal/gtest-internal.h>
56fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/internal/gtest-string.h>
57fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest-death-test.h>
58fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest-message.h>
59fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest-param-test.h>
60fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest_prod.h>
61fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest-test-part.h>
62fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest-typed-test.h>
63fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
64fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Depending on the platform, different string classes are available.
65fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// On Windows, ::std::string compiles only when exceptions are
66fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// enabled.  On Linux, in addition to ::std::string, Google also makes
67fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// use of class ::string, which has the same interface as
68fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// ::std::string, but has a different implementation.
69fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
70fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The user can tell us whether ::std::string is available in his
71fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// environment by defining the macro GTEST_HAS_STD_STRING to either 1
72fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// or 0 on the compiler command line.  He can also define
73fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// GTEST_HAS_GLOBAL_STRING to 1 to indicate that ::string is available
74fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// AND is a distinct type to ::std::string, or define it to 0 to
75fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// indicate otherwise.
76fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
77fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// If the user's ::std::string and ::string are the same class due to
78fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// aliasing, he should define GTEST_HAS_STD_STRING to 1 and
79fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// GTEST_HAS_GLOBAL_STRING to 0.
80fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
81fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// If the user doesn't define GTEST_HAS_STD_STRING and/or
82fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// GTEST_HAS_GLOBAL_STRING, they are defined heuristically.
83fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
84fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillenamespace testing {
85fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
86fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Declares the flags.
87fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
88fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag temporary enables the disabled tests.
89fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(also_run_disabled_tests);
90fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
91fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag brings the debugger on an assertion failure.
92fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(break_on_failure);
93fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
94fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag controls whether Google Test catches all test-thrown exceptions
95fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// and logs them as failures.
96fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(catch_exceptions);
97fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
98fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag enables using colors in terminal output. Available values are
99fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
100fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// to let Google Test decide.
101fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_string_(color);
102fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
103fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag sets up the filter to select by name using a glob pattern
104fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// the tests to run. If the filter is not given all tests are executed.
105fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_string_(filter);
106fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
107fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag causes the Google Test to list tests. None of the tests listed
108fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// are actually run if the flag is provided.
109fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(list_tests);
110fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
111fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag controls whether Google Test emits a detailed XML report to a file
112fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// in addition to its normal textual output.
113fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_string_(output);
114fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
115fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flags control whether Google Test prints the elapsed time for each
116fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// test.
117fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(print_time);
118fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
119fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag specifies the random number seed.
120fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_int32_(random_seed);
121fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
122fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag sets how many times the tests are repeated. The default value
123fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// is 1. If the value is -1 the tests are repeating forever.
124fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_int32_(repeat);
125fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
126fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag controls whether Google Test includes Google Test internal
127fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// stack frames in failure stack traces.
128fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(show_internal_stack_frames);
129fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
130d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// When this flag is specified, tests' order is randomized on every iteration.
131fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(shuffle);
132fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
133fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This flag specifies the maximum number of stack frames to be
134fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// printed in a failure message.
135fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_int32_(stack_trace_depth);
136fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
137fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// When this flag is specified, a failed assertion will throw an
138fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// exception if exceptions are enabled, or exit the program with a
139fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// non-zero code otherwise.
140fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleGTEST_DECLARE_bool_(throw_on_failure);
141fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
142fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The upper limit for valid stack trace depths.
143fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleconst int kMaxStackTraceDepth = 100;
144fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
145fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillenamespace internal {
146fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
147fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass AssertHelper;
148fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass DefaultGlobalTestPartResultReporter;
149fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass ExecDeathTest;
150d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass NoExecDeathTest;
151fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass FinalSuccessChecker;
152fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass GTestFlagSaver;
153fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestInfoImpl;
154fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestResultAccessor;
155d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass TestEventListenersAccessor;
156d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass TestEventRepeater;
157fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass WindowsDeathTest;
158fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass UnitTestImpl* GetUnitTestImpl();
159d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savillevoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
160fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville                                    const String& message);
161d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass PrettyUnitTestResultPrinter;
162d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass XmlUnitTestResultPrinter;
163fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
164fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Converts a streamable value to a String.  A NULL pointer is
165fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// converted to "(null)".  When the input value is a ::string,
166fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// ::std::string, ::wstring, or ::std::wstring object, each NUL
167fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// character in it is replaced with "\\0".
168fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Declared in gtest-internal.h but defined here, so that it has access
169fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// to the definition of the Message class, required by the ARM
170fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// compiler.
171fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilletemplate <typename T>
172fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleString StreamableToString(const T& streamable) {
173fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  return (Message() << streamable).GetString();
174fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville}
175fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
176fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville}  // namespace internal
177fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
178fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A class for indicating whether an assertion was successful.  When
179fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// the assertion wasn't successful, the AssertionResult object
180fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// remembers a non-empty message that described how it failed.
181fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
182fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This class is useful for defining predicate-format functions to be
183fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
184fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
185fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The constructor of AssertionResult is private.  To create an
186fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// instance of this class, use one of the factory functions
187fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// (AssertionSuccess() and AssertionFailure()).
188fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
189fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// For example, in order to be able to write:
190fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
191fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   // Verifies that Foo() returns an even number.
192fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   EXPECT_PRED_FORMAT1(IsEven, Foo());
193fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
194fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// you just need to define:
195fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
196fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   testing::AssertionResult IsEven(const char* expr, int n) {
197fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     if ((n % 2) == 0) return testing::AssertionSuccess();
198fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
199fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     Message msg;
200fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     msg << "Expected: " << expr << " is even\n"
201fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//         << "  Actual: it's " << n;
202fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     return testing::AssertionFailure(msg);
203fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   }
204fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
205fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// If Foo() returns 5, you will see the following message:
206fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
207fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   Expected: Foo() is even
208fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     Actual: it's 5
209fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass AssertionResult {
210fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
211fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Declares factory functions for making successful and failed
212fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // assertion results as friends.
213fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend AssertionResult AssertionSuccess();
214fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend AssertionResult AssertionFailure(const Message&);
215fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
216fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the assertion succeeded.
217fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  operator bool() const { return failure_message_.c_str() == NULL; }  // NOLINT
218fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
219fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the assertion's failure message.
220fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* failure_message() const { return failure_message_.c_str(); }
221fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
222fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
223fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The default constructor.  It is used when the assertion succeeded.
224fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  AssertionResult() {}
225fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
226fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The constructor used when the assertion failed.
227fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  explicit AssertionResult(const internal::String& failure_message);
228fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
229fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Stores the assertion's failure message.
230fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::String failure_message_;
231fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
232fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
233fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Makes a successful assertion result.
234fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleAssertionResult AssertionSuccess();
235fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
236fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Makes a failed assertion result with the given failure message.
237fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleAssertionResult AssertionFailure(const Message& msg);
238fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
239fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The abstract class that all tests inherit from.
240fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
241fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// In Google Test, a unit test program contains one or many TestCases, and
242fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// each TestCase contains one or many Tests.
243fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
244fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// When you define a test using the TEST macro, you don't need to
245fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// explicitly derive from Test - the TEST macro automatically does
246fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// this for you.
247fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
248fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The only time you derive from Test is when defining a test fixture
249fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// to be used a TEST_F.  For example:
250fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
251fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   class FooTest : public testing::Test {
252fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//    protected:
253fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     virtual void SetUp() { ... }
254fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     virtual void TearDown() { ... }
255fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     ...
256fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   };
257fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
258fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   TEST_F(FooTest, Bar) { ... }
259fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   TEST_F(FooTest, Baz) { ... }
260fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
261fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Test is not copyable.
262fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass Test {
263fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
264fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::TestInfoImpl;
265fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
266fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Defines types for pointers to functions that set up and tear down
267fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // a test case.
268fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
269fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
270fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
271fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The d'tor is virtual as we intend to inherit from Test.
272fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual ~Test();
273fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
274fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets up the stuff shared by all tests in this test case.
275fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
276fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Google Test will call Foo::SetUpTestCase() before running the first
277fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // test in test case Foo.  Hence a sub-class can define its own
278fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // SetUpTestCase() method to shadow the one defined in the super
279fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // class.
280fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static void SetUpTestCase() {}
281fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
282fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Tears down the stuff shared by all tests in this test case.
283fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
284fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Google Test will call Foo::TearDownTestCase() after running the last
285fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // test in test case Foo.  Hence a sub-class can define its own
286fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // TearDownTestCase() method to shadow the one defined in the super
287fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // class.
288fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static void TearDownTestCase() {}
289fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
290fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the current test has a fatal failure.
291fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool HasFatalFailure();
292fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
293fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the current test has a non-fatal failure.
294fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool HasNonfatalFailure();
295fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
296fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the current test has a (either fatal or
297fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // non-fatal) failure.
298fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
299fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
300fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Logs a property for the current test.  Only the last value for a given
301fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // key is remembered.
302fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // These are public static so they can be called from utility functions
303fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // that are not members of the test fixture.
304fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The arguments are const char* instead strings, as Google Test is used
305fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // on platforms where string doesn't compile.
306fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
307fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Note that a driving consideration for these RecordProperty methods
308fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // was to produce xml output suited to the Greenspan charting utility,
309fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // which at present will only chart values that fit in a 32-bit int. It
310fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // is the user's responsibility to restrict their values to 32-bit ints
311fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // if they intend them to be used with Greenspan.
312fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static void RecordProperty(const char* key, const char* value);
313fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static void RecordProperty(const char* key, int value);
314fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
315fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville protected:
316fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Creates a Test object.
317fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  Test();
318fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
319fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets up the test fixture.
320fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual void SetUp();
321fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
322fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Tears down the test fixture.
323fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual void TearDown();
324fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
325fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
326fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the current test has the same fixture class as
327fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // the first test in the current test case.
328fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool HasSameFixtureClass();
329fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
330fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Runs the test after the test fixture has been set up.
331fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
332fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // A sub-class must implement this to define the test logic.
333fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
334fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
335fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Instead, use the TEST or TEST_F macro.
336fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual void TestBody() = 0;
337fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
338fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets up, executes, and tears down the test.
339fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void Run();
340fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
341fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Uses a GTestFlagSaver to save and restore all Google Test flags.
342fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const internal::GTestFlagSaver* const gtest_flag_saver_;
343fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
344fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Often a user mis-spells SetUp() as Setup() and spends a long time
345fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // wondering why it is never called by Google Test.  The declaration of
346fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // the following method is solely for catching such an error at
347fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // compile time:
348fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
349fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   - The return type is deliberately chosen to be not void, so it
350fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   will be a conflict if a user declares void Setup() in his test
351fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   fixture.
352fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
353fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   - This method is private, so it will be another compiler error
354fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   if a user calls it from his test fixture.
355fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
356fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // DO NOT OVERRIDE THIS FUNCTION.
357fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
358fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // If you see an error about overriding the following function or
359fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // about it being private, you have mis-spelled SetUp() as Setup().
360fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  struct Setup_should_be_spelled_SetUp {};
361fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
362fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
363fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // We disallow copying Tests.
364fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
365fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
366fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
367fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilletypedef internal::TimeInMillis TimeInMillis;
368fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
369fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A copyable object representing a user specified test property which can be
370fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// output as a key/value string pair.
371fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
372fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Don't inherit from TestProperty as its destructor is not virtual.
373fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestProperty {
374fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
375fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // C'tor.  TestProperty does NOT have a default constructor.
376fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Always use this constructor (with parameters) to create a
377fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // TestProperty object.
378fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TestProperty(const char* key, const char* value) :
379fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    key_(key), value_(value) {
380fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
381fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
382fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the user supplied key.
383fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* key() const {
384fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    return key_.c_str();
385fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
386fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
387fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the user supplied value.
388fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* value() const {
389fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    return value_.c_str();
390fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
391fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
392fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets a new value, overriding the one supplied in the constructor.
393fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void SetValue(const char* new_value) {
394fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    value_ = new_value;
395fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
396fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
397fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
398fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The key supplied by the user.
399fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::String key_;
400fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The value supplied by the user.
401fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::String value_;
402fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
403fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
404fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The result of a single Test.  This includes a list of
405fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// TestPartResults, a list of TestProperties, a count of how many
406fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// death tests there are in the Test, and how much time it took to run
407fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// the Test.
408fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
409fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// TestResult is not copyable.
410fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestResult {
411fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
412fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Creates an empty TestResult.
413fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TestResult();
414fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
415fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // D'tor.  Do not inherit from TestResult.
416fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  ~TestResult();
417fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
418fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the number of all test parts.  This is the sum of the number
419fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // of successful test parts and the number of failed test parts.
420fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int total_part_count() const;
421fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
422fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the number of the test properties.
423fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int test_property_count() const;
424fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
425fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test passed (i.e. no test part failed).
426fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool Passed() const { return !Failed(); }
427fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
428fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test failed.
429fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool Failed() const;
430fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
431fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test fatally failed.
432fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool HasFatalFailure() const;
433fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
434fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test has a non-fatal failure.
435fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool HasNonfatalFailure() const;
436fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
437fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the elapsed time, in milliseconds.
438fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TimeInMillis elapsed_time() const { return elapsed_time_; }
439fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
440fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the i-th test part result among all the results. i can range
441fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // from 0 to test_property_count() - 1. If i is not in that range, aborts
442fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // the program.
443fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const TestPartResult& GetTestPartResult(int i) const;
444fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
445fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the i-th test property. i can range from 0 to
446fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // test_property_count() - 1. If i is not in that range, aborts the
447fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // program.
448fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const TestProperty& GetTestProperty(int i) const;
449fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
450fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
451d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class TestInfo;
452d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class UnitTest;
453fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::DefaultGlobalTestPartResultReporter;
454fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::ExecDeathTest;
455fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::TestInfoImpl;
456fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::TestResultAccessor;
457fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::UnitTestImpl;
458fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::WindowsDeathTest;
459fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
460fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the vector of TestPartResults.
461fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const internal::Vector<TestPartResult>& test_part_results() const {
462fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    return *test_part_results_;
463fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
464fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
465fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the vector of TestProperties.
466fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const internal::Vector<TestProperty>& test_properties() const {
467fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    return *test_properties_;
468fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
469fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
470fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets the elapsed time.
471fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
472fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
473fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Adds a test property to the list. The property is validated and may add
474fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
475fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // key names). If a property is already recorded for the same key, the
476fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // value will be updated, rather than storing multiple values for the same
477fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // key.
478fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void RecordProperty(const TestProperty& test_property);
479fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
480fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Adds a failure if the key is a reserved attribute of Google Test
481fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // testcase tags.  Returns true if the property is valid.
482fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // TODO(russr): Validate attribute names are legal and human readable.
483fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool ValidateTestProperty(const TestProperty& test_property);
484fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
485fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Adds a test part result to the list.
486fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void AddTestPartResult(const TestPartResult& test_part_result);
487fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
488fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the death test count.
489fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int death_test_count() const { return death_test_count_; }
490fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
491fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Increments the death test count, returning the new count.
492fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int increment_death_test_count() { return ++death_test_count_; }
493fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
494fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Clears the test part results.
495fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void ClearTestPartResults();
496fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
497fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Clears the object.
498fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void Clear();
499fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
500fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Protects mutable state of the property vector and of owned
501fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // properties, whose values may be updated.
502fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::Mutex test_properites_mutex_;
503fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
504fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The vector of TestPartResults
505fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::scoped_ptr<internal::Vector<TestPartResult> > test_part_results_;
506fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The vector of TestProperties
507fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::scoped_ptr<internal::Vector<TestProperty> > test_properties_;
508fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Running count of death tests.
509fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int death_test_count_;
510fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The elapsed time, in milliseconds.
511fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TimeInMillis elapsed_time_;
512fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
513fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // We disallow copying TestResult.
514fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
515fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};  // class TestResult
516fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
517fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A TestInfo object stores the following information about a test:
518fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
519fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   Test case name
520fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   Test name
521fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   Whether the test should be run
522fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   A function pointer that creates the test object when invoked
523fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   Test result
524fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
525fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// The constructor of TestInfo registers itself with the UnitTest
526fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// singleton such that the RUN_ALL_TESTS() macro knows which tests to
527fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// run.
528fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestInfo {
529fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
530fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Destructs a TestInfo object.  This function is not virtual, so
531fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // don't inherit from TestInfo.
532fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  ~TestInfo();
533fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
534fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the test case name.
535fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* test_case_name() const;
536fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
537fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the test name.
538fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* name() const;
539fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
540fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the test case comment.
541fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* test_case_comment() const;
542fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
543fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the test comment.
544fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* comment() const;
545fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
546fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true if this test should run, that is if the test is not disabled
547fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // (or it is disabled but the also_run_disabled_tests flag has been specified)
548fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // and its full name matches the user-specified filter.
549fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
550fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Google Test allows the user to filter the tests by their full names.
551fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The full name of a test Bar in test case Foo is defined as
552fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // "Foo.Bar".  Only the tests that match the filter will run.
553fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
554fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // A filter is a colon-separated list of glob (not regex) patterns,
555fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // optionally followed by a '-' and a colon-separated list of
556fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // negative patterns (tests to exclude).  A test is run if it
557fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // matches one of the positive patterns and does not match any of
558fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // the negative patterns.
559fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
560fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // For example, *A*:Foo.* is a filter that matches any string that
561fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // contains the character 'A' or starts with "Foo.".
562fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool should_run() const;
563fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
564fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the result of the test.
565d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  const TestResult* result() const;
566fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
567fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
568fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#if GTEST_HAS_DEATH_TEST
569fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::DefaultDeathTestFactory;
570fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#endif  // GTEST_HAS_DEATH_TEST
571d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class Test;
572d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class TestCase;
573fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::TestInfoImpl;
574fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::UnitTestImpl;
575fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend TestInfo* internal::MakeAndRegisterTestInfo(
576fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      const char* test_case_name, const char* name,
577fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      const char* test_case_comment, const char* comment,
578fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      internal::TypeId fixture_class_id,
579fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      Test::SetUpTestCaseFunc set_up_tc,
580fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      Test::TearDownTestCaseFunc tear_down_tc,
581fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville      internal::TestFactoryBase* factory);
582fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
583fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true if this test matches the user-specified filter.
584fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool matches_filter() const;
585fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
586fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Increments the number of death tests encountered in this test so
587fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // far.
588fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int increment_death_test_count();
589fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
590fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Accessors for the implementation object.
591fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::TestInfoImpl* impl() { return impl_; }
592fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const internal::TestInfoImpl* impl() const { return impl_; }
593fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
594fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Constructs a TestInfo object. The newly constructed instance assumes
595fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // ownership of the factory object.
596fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TestInfo(const char* test_case_name, const char* name,
597fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville           const char* test_case_comment, const char* comment,
598fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville           internal::TypeId fixture_class_id,
599fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville           internal::TestFactoryBase* factory);
600fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
601fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // An opaque implementation object.
602fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::TestInfoImpl* impl_;
603fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
604fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
605fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
606fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
607fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A test case, which consists of a vector of TestInfos.
608fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
609fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// TestCase is not copyable.
610fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass TestCase {
611fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
612fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Creates a TestCase with the given name.
613fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
614fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // TestCase does NOT have a default constructor.  Always use this
615fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // constructor to create a TestCase object.
616fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
617fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Arguments:
618fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //
619fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   name:         name of the test case
620fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   set_up_tc:    pointer to the function that sets up the test case
621fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  //   tear_down_tc: pointer to the function that tears down the test case
622fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TestCase(const char* name, const char* comment,
623fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville           Test::SetUpTestCaseFunc set_up_tc,
624fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville           Test::TearDownTestCaseFunc tear_down_tc);
625fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
626fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Destructor of TestCase.
627fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual ~TestCase();
628fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
629fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the name of the TestCase.
630fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* name() const { return name_.c_str(); }
631fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
632fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the test case comment.
633fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const char* comment() const { return comment_.c_str(); }
634fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
635fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true if any test in this test case should run.
636fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool should_run() const { return should_run_; }
637fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
638fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the number of successful tests in this test case.
639fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int successful_test_count() const;
640fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
641fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the number of failed tests in this test case.
642fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int failed_test_count() const;
643fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
644fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the number of disabled tests in this test case.
645fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int disabled_test_count() const;
646fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
647fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Get the number of tests in this test case that should run.
648fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int test_to_run_count() const;
649fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
650fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the number of all tests in this test case.
651fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  int total_test_count() const;
652fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
653fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test case passed.
654fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool Passed() const { return !Failed(); }
655fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
656fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff the test case failed.
657fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool Failed() const { return failed_test_count() > 0; }
658fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
659fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the elapsed time, in milliseconds.
660fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TimeInMillis elapsed_time() const { return elapsed_time_; }
661fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
662fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns the i-th test among all the tests. i can range from 0 to
663fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // total_test_count() - 1. If i is not in that range, returns NULL.
664fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const TestInfo* GetTestInfo(int i) const;
665fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
666fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
667d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class Test;
668fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  friend class internal::UnitTestImpl;
669fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
670fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the (mutable) vector of TestInfos in this TestCase.
671fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::Vector<TestInfo*>& test_info_list() { return *test_info_list_; }
672fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
673fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Gets the (immutable) vector of TestInfos in this TestCase.
674fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  const internal::Vector<TestInfo *> & test_info_list() const {
675fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    return *test_info_list_;
676fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
677fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
678d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Returns the i-th test among all the tests. i can range from 0 to
679d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // total_test_count() - 1. If i is not in that range, returns NULL.
680d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestInfo* GetMutableTestInfo(int i);
681d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
682fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Sets the should_run member.
683fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void set_should_run(bool should) { should_run_ = should; }
684fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
685fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
686fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // destruction of the TestCase object.
687fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void AddTestInfo(TestInfo * test_info);
688fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
689fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Clears the results of all tests in this test case.
690fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void ClearResult();
691fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
692fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Clears the results of all tests in the given test case.
693fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static void ClearTestCaseResult(TestCase* test_case) {
694fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville    test_case->ClearResult();
695fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  }
696fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
697fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Runs every test in this TestCase.
698fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void Run();
699fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
700fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff test passed.
701fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool TestPassed(const TestInfo * test_info);
702fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
703fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff test failed.
704fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool TestFailed(const TestInfo * test_info);
705fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
706fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true iff test is disabled.
707fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool TestDisabled(const TestInfo * test_info);
708fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
709fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Returns true if the given test should run.
710fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  static bool ShouldRunTest(const TestInfo *test_info);
711fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
712d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Shuffles the tests in this test case.
713d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  void ShuffleTests(internal::Random* random);
714d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
715d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Restores the test order to before the first shuffle.
716d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  void UnshuffleTests();
717d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
718fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Name of the test case.
719fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::String name_;
720fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Comment on the test case.
721fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  internal::String comment_;
722d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // The vector of TestInfos in their original order.  It owns the
723d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // elements in the vector.
724d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  const internal::scoped_ptr<internal::Vector<TestInfo*> > test_info_list_;
725d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Provides a level of indirection for the test list to allow easy
726d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // shuffling and restoring the test order.  The i-th element in this
727d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // vector is the index of the i-th test in the shuffled test list.
728d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  const internal::scoped_ptr<internal::Vector<int> > test_indices_;
729fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Pointer to the function that sets up the test case.
730fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  Test::SetUpTestCaseFunc set_up_tc_;
731fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Pointer to the function that tears down the test case.
732fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  Test::TearDownTestCaseFunc tear_down_tc_;
733fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // True iff any test in this test case should run.
734fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  bool should_run_;
735fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Elapsed time, in milliseconds.
736fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  TimeInMillis elapsed_time_;
737fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
738fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // We disallow copying TestCases.
739fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
740fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
741fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
742fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// An Environment object is capable of setting up and tearing down an
743fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// environment.  The user should subclass this to define his own
744fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// environment(s).
745fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
746fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// An Environment object does the set-up and tear-down in virtual
747fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// methods SetUp() and TearDown() instead of the constructor and the
748fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// destructor, as:
749fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
750fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   1. You cannot safely throw from a destructor.  This is a problem
751fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//      as in some cases Google Test is used where exceptions are enabled, and
752fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//      we may want to implement ASSERT_* using exceptions where they are
753fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//      available.
754fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   2. You cannot use ASSERT_* directly in a constructor or
755fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//      destructor.
756fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass Environment {
757fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public:
758fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // The d'tor is virtual as we need to subclass Environment.
759fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual ~Environment() {}
760fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
761fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Override this to define how to set up the environment.
762fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual void SetUp() {}
763fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
764fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // Override this to define how to tear down the environment.
765fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual void TearDown() {}
766fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private:
767fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // If you see an error about overriding the following function or
768fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // about it being private, you have mis-spelled SetUp() as Setup().
769fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  struct Setup_should_be_spelled_SetUp {};
770fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
771fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville};
772fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
773d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// The interface for tracing execution of tests. The methods are organized in
774d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// the order the corresponding events are fired.
775d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass TestEventListener {
776d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville public:
777d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual ~TestEventListener() {}
778d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
779d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before any test activity starts.
780d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
781d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
782d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before each iteration of tests starts.  There may be more than
783d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
784d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // index, starting from 0.
785d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestIterationStart(const UnitTest& unit_test,
786d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville                                    int iteration) = 0;
787d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
788d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before environment set-up for each iteration of tests starts.
789d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
790d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
791d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after environment set-up for each iteration of tests ends.
792d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
793d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
794d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before the test case starts.
795d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
796d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
797d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before the test starts.
798d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestStart(const TestInfo& test_info) = 0;
799d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
800d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after a failed assertion or a SUCCESS().
801d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
802d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
803d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after the test ends.
804d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestEnd(const TestInfo& test_info) = 0;
805d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
806d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after the test case ends.
807d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
808d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
809d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired before environment tear-down for each iteration of tests starts.
810d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
811d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
812d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after environment tear-down for each iteration of tests ends.
813d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
814d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
815d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after each iteration of tests finishes.
816d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestIterationEnd(const UnitTest& unit_test,
817d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville                                  int iteration) = 0;
818d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
819d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Fired after all test activities have ended.
820d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
821d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville};
822d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
823d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// The convenience class for users who need to override just one or two
824d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// methods and are not concerned that a possible change to a signature of
825d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// the methods they override will not be caught during the build.  For
826d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// comments about each method please see the definition of TestEventListener
827d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// above.
828d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass EmptyTestEventListener : public TestEventListener {
829d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville public:
830d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
831d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
832d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville                                    int /*iteration*/) {}
833d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
834d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
835d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
836d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
837d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
838d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
839d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
840d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
841d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
842d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
843d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville                                  int /*iteration*/) {}
844d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
845d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville};
846d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
847d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville// TestEventListeners lets users add listeners to track events in Google Test.
848d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Savilleclass TestEventListeners {
849d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville public:
850d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestEventListeners();
851d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  ~TestEventListeners();
852d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
853d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Appends an event listener to the end of the list. Google Test assumes
854d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // the ownership of the listener (i.e. it will delete the listener when
855d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // the test program finishes).
856d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  void Append(TestEventListener* listener);
857d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
858d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Removes the given event listener from the list and returns it.  It then
859d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // becomes the caller's responsibility to delete the listener. Returns
860d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // NULL if the listener is not found in the list.
861d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestEventListener* Release(TestEventListener* listener);
862d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
863d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Returns the standard listener responsible for the default console
864d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // output.  Can be removed from the listeners list to shut down default
865d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // console output.  Note that removing this object from the listener list
866d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // with Release transfers its ownership to the caller and makes this
867d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // function return NULL the next time.
868d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestEventListener* default_result_printer() const {
869d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville    return default_result_printer_;
870d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  }
871d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
872d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Returns the standard listener responsible for the default XML output
873d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // controlled by the --gtest_output=xml flag.  Can be removed from the
874d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // listeners list by users who want to shut down the default XML output
875d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // controlled by this flag and substitute it with custom one.  Note that
876d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // removing this object from the listener list with Release transfers its
877d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // ownership to the caller and makes this function return NULL the next
878d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // time.
879d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestEventListener* default_xml_generator() const {
880d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville    return default_xml_generator_;
881d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  }
882d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
883d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville private:
884d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class TestCase;
885d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class internal::DefaultGlobalTestPartResultReporter;
886d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class internal::NoExecDeathTest;
887d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class internal::TestEventListenersAccessor;
888d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class internal::TestInfoImpl;
889d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  friend class internal::UnitTestImpl;
890d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
891d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Returns repeater that broadcasts the TestEventListener events to all
892d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // subscribers.
893d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  TestEventListener* repeater();
894d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
895d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Sets the default_result_printer attribute to the provided listener.
896d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // The listener is also added to the listener list and previous
897d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // default_result_printer is removed from it and deleted. The listener can
898d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // also be NULL in which case it will not be added to the list. Does
899d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // nothing if the previous and the current listener objects are the same.
900d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  void SetDefaultResultPrinter(TestEventListener* listener);
901d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
902d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // Sets the default_xml_generator attribute to the provided listener.  The
903d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // listener is also added to the listener list and previous
904d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // default_xml_generator is removed from it and deleted. The listener can
905d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // also be NULL in which case it will not be added to the list. Does
906d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  // nothing if the previous and the current listener objects are the same.
907d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville  void SetDefaultXmlGenerator(TestEventListener* listener);
908d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville
909d0