17ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Copyright 2005, Google Inc.
27ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// All rights reserved.
37ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
47ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Redistribution and use in source and binary forms, with or without
57ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// modification, are permitted provided that the following conditions are
67ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// met:
77ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
87ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Redistributions of source code must retain the above copyright
97ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// notice, this list of conditions and the following disclaimer.
107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Redistributions in binary form must reproduce the above
117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// copyright notice, this list of conditions and the following disclaimer
127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// in the documentation and/or other materials provided with the
137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// distribution.
147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     * Neither the name of Google Inc. nor the names of its
157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// contributors may be used to endorse or promote products derived from
167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// this software without specific prior written permission.
177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Author: wan@google.com (Zhanyong Wan)
317ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The Google C++ Testing Framework (Google Test)
337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// This header file defines the public API for Google Test.  It should be
357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// included by any test program that uses Google Test.
367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// leave some internal implementation details in this header file.
397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// They are clearly marked by comments like this:
407ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Such code is NOT meant to be used by a user directly, and is subject
447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
457ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// program!
467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Acknowledgment: Google Test borrowed the idea of automatic test
487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// easyUnit framework.
507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#define GTEST_INCLUDE_GTEST_GTEST_H_
537ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
547ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#include <limits>
5557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer#include <vector>
5657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
57b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/internal/gtest-internal.h"
58b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/internal/gtest-string.h"
59b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-death-test.h"
60b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-message.h"
61b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-param-test.h"
62b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-printers.h"
63b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest_prod.h"
64b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-test-part.h"
65b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad#include "gtest/gtest-typed-test.h"
667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Depending on the platform, different string classes are available.
6857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// On Linux, in addition to ::std::string, Google also makes use of
6957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// class ::string, which has the same interface as ::std::string, but
7057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// has a different implementation.
7157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
7257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
7357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// ::string is available AND is a distinct type to ::std::string, or
7457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// define it to 0 to indicate otherwise.
757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
767ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// If the user's ::std::string and ::string are the same class due to
7757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
787ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
7957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
8057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// heuristically.
817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmannamespace testing {
837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
84e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// Declares the flags.
857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
86e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag temporary enables the disabled tests.
87e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(also_run_disabled_tests);
88e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
89e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag brings the debugger on an assertion failure.
90e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(break_on_failure);
91e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
92e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag controls whether Google Test catches all test-thrown exceptions
93e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// and logs them as failures.
94e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(catch_exceptions);
95e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
96e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag enables using colors in terminal output. Available values are
97e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
98e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// to let Google Test decide.
99e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_string_(color);
100e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
101e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag sets up the filter to select by name using a glob pattern
102e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// the tests to run. If the filter is not given all tests are executed.
103e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_string_(filter);
104e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
105e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag causes the Google Test to list tests. None of the tests listed
106e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// are actually run if the flag is provided.
107e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(list_tests);
108e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
109e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag controls whether Google Test emits a detailed XML report to a file
110e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// in addition to its normal textual output.
111e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_string_(output);
112e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
113e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flags control whether Google Test prints the elapsed time for each
114e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// test.
115e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(print_time);
116e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
117190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// This flag specifies the random number seed.
118190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin KramerGTEST_DECLARE_int32_(random_seed);
119190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
120e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag sets how many times the tests are repeated. The default value
121e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// is 1. If the value is -1 the tests are repeating forever.
122e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_int32_(repeat);
1237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
1247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// This flag controls whether Google Test includes Google Test internal
1257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// stack frames in failure stack traces.
1267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha BrukmanGTEST_DECLARE_bool_(show_internal_stack_frames);
1277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
128190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// When this flag is specified, tests' order is randomized on every iteration.
129190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin KramerGTEST_DECLARE_bool_(shuffle);
130190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
131e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// This flag specifies the maximum number of stack frames to be
132e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// printed in a failure message.
133e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_int32_(stack_trace_depth);
134e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
135e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// When this flag is specified, a failed assertion will throw an
136e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// exception if exceptions are enabled, or exit the program with a
137e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// non-zero code otherwise.
138e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin KramerGTEST_DECLARE_bool_(throw_on_failure);
139e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
140b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// When this flag is set with a "host:port" string, on supported
141b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// platforms test results are streamed to the specified port on
142b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// the specified host machine.
143b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay FoadGTEST_DECLARE_string_(stream_result_to);
144b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
145e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer// The upper limit for valid stack trace depths.
146e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramerconst int kMaxStackTraceDepth = 100;
147e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer
1487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmannamespace internal {
1497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
150190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass AssertHelper;
151190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass DefaultGlobalTestPartResultReporter;
152190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass ExecDeathTest;
153190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass NoExecDeathTest;
154190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass FinalSuccessChecker;
1557ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanclass GTestFlagSaver;
156190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass TestResultAccessor;
157190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass TestEventListenersAccessor;
158190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass TestEventRepeater;
159190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass WindowsDeathTest;
160190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass UnitTestImpl* GetUnitTestImpl();
161190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramervoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
162190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                    const String& message);
1637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
1647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Converts a streamable value to a String.  A NULL pointer is
1657ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// converted to "(null)".  When the input value is a ::string,
1667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// ::std::string, ::wstring, or ::std::wstring object, each NUL
1677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// character in it is replaced with "\\0".
1687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Declared in gtest-internal.h but defined here, so that it has access
1697ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to the definition of the Message class, required by the ARM
1707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// compiler.
1717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmantemplate <typename T>
1727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha BrukmanString StreamableToString(const T& streamable) {
1737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  return (Message() << streamable).GetString();
1747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman}
1757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
1767ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman}  // namespace internal
1777ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
178b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// The friend relationship of some of these classes is cyclic.
179b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// If we don't forward declare them the compiler might confuse the classes
180b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad// in friendship clauses with same named classes on the scope.
181b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadclass Test;
182b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadclass TestCase;
183b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadclass TestInfo;
184b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foadclass UnitTest;
185b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
1867ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// A class for indicating whether an assertion was successful.  When
1877ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// the assertion wasn't successful, the AssertionResult object
18857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// remembers a non-empty message that describes how it failed.
1897ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
19057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// To create an instance of this class, use one of the factory functions
1917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// (AssertionSuccess() and AssertionFailure()).
1927ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
19357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// This class is useful for two purposes:
19457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   1. Defining predicate functions to be used with Boolean test assertions
19557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
19657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   2. Defining predicate-format functions to be
19757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
19857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
19957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// For example, if you define IsEven predicate:
20057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
20157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   testing::AssertionResult IsEven(int n) {
20257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     if ((n % 2) == 0)
20357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionSuccess();
20457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     else
20557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionFailure() << n << " is odd";
20657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   }
20757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
20857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
20957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// will print the message
21057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
21157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Value of: IsEven(Fib(5))
21257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     Actual: false (5 is odd)
21357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Expected: true
21457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
21557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// instead of a more opaque
21657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
21757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Value of: IsEven(Fib(5))
21857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     Actual: false
21957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Expected: true
22057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
22157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// in case IsEven is a simple Boolean predicate.
22257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
22357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// If you expect your predicate to be reused and want to support informative
22457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
22557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// about half as often as positive ones in our tests), supply messages for
22657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// both success and failure cases:
22757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
22857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   testing::AssertionResult IsEven(int n) {
22957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     if ((n % 2) == 0)
23057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionSuccess() << n << " is even";
23157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     else
23257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionFailure() << n << " is odd";
23357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   }
23457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
23557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
23657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
23757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Value of: IsEven(Fib(6))
23857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     Actual: true (8 is even)
23957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//   Expected: false
24057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
24157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// NB: Predicates that support negative Boolean assertions have reduced
24257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// performance in positive ones so be careful not to use them in tests
24357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// that have lots (tens of thousands) of positive Boolean assertions.
24457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
24557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// To use this class with EXPECT_PRED_FORMAT assertions such as:
2467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
2477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   // Verifies that Foo() returns an even number.
2487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   EXPECT_PRED_FORMAT1(IsEven, Foo());
2497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
25057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// you need to define:
2517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
2527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   testing::AssertionResult IsEven(const char* expr, int n) {
25357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     if ((n % 2) == 0)
25457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionSuccess();
25557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//     else
25657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//       return testing::AssertionFailure()
25757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
2587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   }
2597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
2607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// If Foo() returns 5, you will see the following message:
2617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
2627ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Expected: Foo() is even
2637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     Actual: it's 5
26457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer//
26557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ AssertionResult {
2667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
26757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Copy constructor.
26857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Used in EXPECT_TRUE/FALSE(assertion_result).
26957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  AssertionResult(const AssertionResult& other);
27057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Used in the EXPECT_TRUE/FALSE(bool_expression).
27157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  explicit AssertionResult(bool success) : success_(success) {}
2727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
27394c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the assertion succeeded.
27457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  operator bool() const { return success_; }  // NOLINT
27557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
27657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
27757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  AssertionResult operator!() const;
27857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
27957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Returns the text streamed into this AssertionResult. Test assertions
28057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // use it when they fail (i.e., the predicate's outcome doesn't match the
28157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // assertion's expectation). When nothing has been streamed into the
28257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // object, returns an empty string.
28357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  const char* message() const {
284b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return message_.get() != NULL ?  message_->c_str() : "";
28557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  }
28657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // TODO(vladl@google.com): Remove this after making sure no clients use it.
28757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Deprecated; please use message() instead.
28857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  const char* failure_message() const { return message(); }
2897ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
29057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Streams a custom failure message into this object.
291b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  template <typename T> AssertionResult& operator<<(const T& value) {
292b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    AppendMessage(Message() << value);
293b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return *this;
294b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
295b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
296b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Allows streaming basic output manipulators such as endl or flush into
297b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // this object.
298b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  AssertionResult& operator<<(
299b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
300b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    AppendMessage(Message() << basic_manipulator);
301b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return *this;
302b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
3037ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
305b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Appends the contents of message to message_.
306b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  void AppendMessage(const Message& a_message) {
307b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    if (message_.get() == NULL)
308b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      message_.reset(new ::std::string);
309b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    message_->append(a_message.GetString().c_str());
310b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
31157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
31257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Stores result of the assertion predicate.
31357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  bool success_;
31457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Stores the message describing the condition in case the expectation
31557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // construct is not satisfied with the predicate's outcome.
31657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // Referenced via a pointer to avoid taking too much stack frame space
31757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  // with test assertions.
318b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  internal::scoped_ptr< ::std::string> message_;
31957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
320b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  GTEST_DISALLOW_ASSIGN_(AssertionResult);
321b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad};
3227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Makes a successful assertion result.
32457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin KramerGTEST_API_ AssertionResult AssertionSuccess();
32557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer
32657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Makes a failed assertion result.
32757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin KramerGTEST_API_ AssertionResult AssertionFailure();
3287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Makes a failed assertion result with the given failure message.
33057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer// Deprecated; use AssertionFailure() << msg.
33157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin KramerGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
3327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The abstract class that all tests inherit from.
3347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// In Google Test, a unit test program contains one or many TestCases, and
3367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// each TestCase contains one or many Tests.
3377ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3387ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// When you define a test using the TEST macro, you don't need to
3397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// explicitly derive from Test - the TEST macro automatically does
3407ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// this for you.
3417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The only time you derive from Test is when defining a test fixture
3437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// to be used a TEST_F.  For example:
3447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3457ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   class FooTest : public testing::Test {
3467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//    protected:
3477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     virtual void SetUp() { ... }
3487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     virtual void TearDown() { ... }
3497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//     ...
3507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   };
3517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   TEST_F(FooTest, Bar) { ... }
3537ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   TEST_F(FooTest, Baz) { ... }
3547ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
3557ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// Test is not copyable.
35657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ Test {
3577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
358b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  friend class TestInfo;
3597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Defines types for pointers to functions that set up and tear down
3617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // a test case.
3627ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
3637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
3647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3657ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // The d'tor is virtual as we intend to inherit from Test.
3667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual ~Test();
3677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Sets up the stuff shared by all tests in this test case.
3697ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
3707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Google Test will call Foo::SetUpTestCase() before running the first
3717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // test in test case Foo.  Hence a sub-class can define its own
3727ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // SetUpTestCase() method to shadow the one defined in the super
3737ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // class.
3747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static void SetUpTestCase() {}
3757ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
3767ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Tears down the stuff shared by all tests in this test case.
3777ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
3787ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Google Test will call Foo::TearDownTestCase() after running the last
3797ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // test in test case Foo.  Hence a sub-class can define its own
3807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // TearDownTestCase() method to shadow the one defined in the super
3817ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // class.
3827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static void TearDownTestCase() {}
3837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
38494c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the current test has a fatal failure.
3857ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool HasFatalFailure();
3867ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
38794c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the current test has a non-fatal failure.
388190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  static bool HasNonfatalFailure();
389190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
39094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the current test has a (either fatal or
391190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // non-fatal) failure.
392190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
393190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
3947ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Logs a property for the current test.  Only the last value for a given
3957ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // key is remembered.
3967ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // These are public static so they can be called from utility functions
3977ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // that are not members of the test fixture.
3987ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // The arguments are const char* instead strings, as Google Test is used
3997ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // on platforms where string doesn't compile.
4007ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4017ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Note that a driving consideration for these RecordProperty methods
4027ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // was to produce xml output suited to the Greenspan charting utility,
4037ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // which at present will only chart values that fit in a 32-bit int. It
4047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // is the user's responsibility to restrict their values to 32-bit ints
4057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // if they intend them to be used with Greenspan.
4067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static void RecordProperty(const char* key, const char* value);
4077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static void RecordProperty(const char* key, int value);
4087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman protected:
4107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Creates a Test object.
4117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  Test();
4127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Sets up the test fixture.
4147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual void SetUp();
4157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Tears down the test fixture.
4177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual void TearDown();
4187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
42094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the current test has the same fixture class as
4217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // the first test in the current test case.
4227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  static bool HasSameFixtureClass();
4237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Runs the test after the test fixture has been set up.
4257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // A sub-class must implement this to define the test logic.
4277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
4297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Instead, use the TEST or TEST_F macro.
4307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual void TestBody() = 0;
4317ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4327ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Sets up, executes, and tears down the test.
4337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  void Run();
4347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
435b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Deletes self.  We deliberately pick an unusual name for this
436b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // internal method to avoid clashing with names used in user TESTs.
437b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  void DeleteSelf_() { delete this; }
438b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
4397ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Uses a GTestFlagSaver to save and restore all Google Test flags.
4407ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  const internal::GTestFlagSaver* const gtest_flag_saver_;
4417ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4427ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Often a user mis-spells SetUp() as Setup() and spends a long time
4437ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // wondering why it is never called by Google Test.  The declaration of
4447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // the following method is solely for catching such an error at
4457ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // compile time:
4467ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4477ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //   - The return type is deliberately chosen to be not void, so it
4487ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //   will be a conflict if a user declares void Setup() in his test
4497ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //   fixture.
4507ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4517ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //   - This method is private, so it will be another compiler error
4527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //   if a user calls it from his test fixture.
4537ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4547ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // DO NOT OVERRIDE THIS FUNCTION.
4557ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
4567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // If you see an error about overriding the following function or
4577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // about it being private, you have mis-spelled SetUp() as Setup().
4587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  struct Setup_should_be_spelled_SetUp {};
4597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
4607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
4617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // We disallow copying Tests.
4627ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
4637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman};
4647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
465190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramertypedef internal::TimeInMillis TimeInMillis;
466190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
467190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// A copyable object representing a user specified test property which can be
468190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// output as a key/value string pair.
469190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//
470190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// Don't inherit from TestProperty as its destructor is not virtual.
471190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass TestProperty {
472190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
473190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // C'tor.  TestProperty does NOT have a default constructor.
474190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Always use this constructor (with parameters) to create a
475190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // TestProperty object.
47657240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  TestProperty(const char* a_key, const char* a_value) :
47757240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    key_(a_key), value_(a_value) {
478190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
479190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
480190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the user supplied key.
481190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const char* key() const {
482190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    return key_.c_str();
483190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
484190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
485190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the user supplied value.
486190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const char* value() const {
487190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    return value_.c_str();
488190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
489190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
490190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Sets a new value, overriding the one supplied in the constructor.
491190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void SetValue(const char* new_value) {
492190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    value_ = new_value;
493190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
494190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
495190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer private:
496190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The key supplied by the user.
497190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  internal::String key_;
498190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The value supplied by the user.
499190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  internal::String value_;
500190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};
501190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
502190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// The result of a single Test.  This includes a list of
503190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// TestPartResults, a list of TestProperties, a count of how many
504190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// death tests there are in the Test, and how much time it took to run
505190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// the Test.
506190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//
507190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// TestResult is not copyable.
50857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ TestResult {
509190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
510190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Creates an empty TestResult.
511190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestResult();
512190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
513190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // D'tor.  Do not inherit from TestResult.
514190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  ~TestResult();
515190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
516190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the number of all test parts.  This is the sum of the number
517190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // of successful test parts and the number of failed test parts.
518190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int total_part_count() const;
519190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
520190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the number of the test properties.
521190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int test_property_count() const;
522190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
52394c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test passed (i.e. no test part failed).
524190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool Passed() const { return !Failed(); }
525190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
52694c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test failed.
527190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool Failed() const;
528190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
52994c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test fatally failed.
530190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool HasFatalFailure() const;
531190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
53294c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test has a non-fatal failure.
533190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool HasNonfatalFailure() const;
534190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
535190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the elapsed time, in milliseconds.
536190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TimeInMillis elapsed_time() const { return elapsed_time_; }
537190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
538190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the i-th test part result among all the results. i can range
539190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // from 0 to test_property_count() - 1. If i is not in that range, aborts
540190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // the program.
541190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const TestPartResult& GetTestPartResult(int i) const;
542190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
543190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the i-th test property. i can range from 0 to
544190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // test_property_count() - 1. If i is not in that range, aborts the
545190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // program.
546190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const TestProperty& GetTestProperty(int i) const;
547190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
548190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer private:
549190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class TestInfo;
550190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class UnitTest;
551190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::DefaultGlobalTestPartResultReporter;
552190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::ExecDeathTest;
553190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::TestResultAccessor;
554190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::UnitTestImpl;
555190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::WindowsDeathTest;
556190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
557190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the vector of TestPartResults.
55857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  const std::vector<TestPartResult>& test_part_results() const {
55957240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    return test_part_results_;
560190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
561190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
562190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the vector of TestProperties.
56357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  const std::vector<TestProperty>& test_properties() const {
56457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    return test_properties_;
565190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
566190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
567190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Sets the elapsed time.
568190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
569190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
570190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Adds a test property to the list. The property is validated and may add
571190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
572190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // key names). If a property is already recorded for the same key, the
573190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // value will be updated, rather than storing multiple values for the same
574190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // key.
575190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void RecordProperty(const TestProperty& test_property);
576190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
577190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Adds a failure if the key is a reserved attribute of Google Test
578190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // testcase tags.  Returns true if the property is valid.
579190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // TODO(russr): Validate attribute names are legal and human readable.
580190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  static bool ValidateTestProperty(const TestProperty& test_property);
581190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
582190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Adds a test part result to the list.
583190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void AddTestPartResult(const TestPartResult& test_part_result);
584190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
585190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the death test count.
586190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int death_test_count() const { return death_test_count_; }
587190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
588190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Increments the death test count, returning the new count.
589190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int increment_death_test_count() { return ++death_test_count_; }
590190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
591190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Clears the test part results.
592190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void ClearTestPartResults();
593190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
594190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Clears the object.
595190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void Clear();
596190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
597190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Protects mutable state of the property vector and of owned
598190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // properties, whose values may be updated.
599190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  internal::Mutex test_properites_mutex_;
600190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
601190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The vector of TestPartResults
60257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  std::vector<TestPartResult> test_part_results_;
603190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The vector of TestProperties
60457240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  std::vector<TestProperty> test_properties_;
605190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Running count of death tests.
606190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int death_test_count_;
607190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The elapsed time, in milliseconds.
608190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TimeInMillis elapsed_time_;
609190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
610190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // We disallow copying TestResult.
611190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
612190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};  // class TestResult
6137ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// A TestInfo object stores the following information about a test:
6157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
6167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Test case name
6177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Test name
6187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Whether the test should be run
6197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   A function pointer that creates the test object when invoked
6207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   Test result
6217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
6227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// The constructor of TestInfo registers itself with the UnitTest
6237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// singleton such that the RUN_ALL_TESTS() macro knows which tests to
6247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// run.
62557240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ TestInfo {
6267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
6277ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Destructs a TestInfo object.  This function is not virtual, so
6287ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // don't inherit from TestInfo.
6297ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  ~TestInfo();
6307ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6317ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Returns the test case name.
632b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const char* test_case_name() const { return test_case_name_.c_str(); }
6337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Returns the test name.
635b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const char* name() const { return name_.c_str(); }
6367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
637b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Returns the name of the parameter type, or NULL if this is not a typed
638b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // or a type-parameterized test.
639b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const char* type_param() const {
640b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    if (type_param_.get() != NULL)
641b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      return type_param_->c_str();
642b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return NULL;
643b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
6447ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
645b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Returns the text representation of the value parameter, or NULL if this
646b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // is not a value-parameterized test.
647b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const char* value_param() const {
648b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    if (value_param_.get() != NULL)
649b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      return value_param_->c_str();
650b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return NULL;
651b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
6527ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
653190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns true if this test should run, that is if the test is not disabled
654190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // (or it is disabled but the also_run_disabled_tests flag has been specified)
655190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // and its full name matches the user-specified filter.
6567ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
6577ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Google Test allows the user to filter the tests by their full names.
6587ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // The full name of a test Bar in test case Foo is defined as
6597ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // "Foo.Bar".  Only the tests that match the filter will run.
6607ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
6617ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // A filter is a colon-separated list of glob (not regex) patterns,
6627ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // optionally followed by a '-' and a colon-separated list of
6637ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // negative patterns (tests to exclude).  A test is run if it
6647ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // matches one of the positive patterns and does not match any of
6657ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // the negative patterns.
6667ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  //
6677ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // For example, *A*:Foo.* is a filter that matches any string that
6687ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // contains the character 'A' or starts with "Foo.".
669b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  bool should_run() const { return should_run_; }
6707ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6717ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Returns the result of the test.
672b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const TestResult* result() const { return &result_; }
673190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
6747ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
675b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
676e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0Benjamin Kramer#if GTEST_HAS_DEATH_TEST
6777ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  friend class internal::DefaultDeathTestFactory;
6787ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman#endif  // GTEST_HAS_DEATH_TEST
6797ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  friend class Test;
6807ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  friend class TestCase;
681190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::UnitTestImpl;
6827ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  friend TestInfo* internal::MakeAndRegisterTestInfo(
6837ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      const char* test_case_name, const char* name,
684b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      const char* type_param,
685b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      const char* value_param,
6867ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      internal::TypeId fixture_class_id,
6877ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      Test::SetUpTestCaseFunc set_up_tc,
6887ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      Test::TearDownTestCaseFunc tear_down_tc,
6897ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman      internal::TestFactoryBase* factory);
6907ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
6917ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Constructs a TestInfo object. The newly constructed instance assumes
6927ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // ownership of the factory object.
6937ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  TestInfo(const char* test_case_name, const char* name,
694b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad           const char* a_type_param,
695b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad           const char* a_value_param,
6967ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman           internal::TypeId fixture_class_id,
6977ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman           internal::TestFactoryBase* factory);
6987ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
699b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Increments the number of death tests encountered in this test so
700b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // far.
701b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  int increment_death_test_count() {
702b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return result_.increment_death_test_count();
703b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
704b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
705b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Creates the test object, runs it, records its result, and then
706b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // deletes it.
707b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  void Run();
708b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
709b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  static void ClearTestResult(TestInfo* test_info) {
710b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    test_info->result_.Clear();
711b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
712b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
713b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // These fields are immutable properties of the test.
714b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const std::string test_case_name_;     // Test case name
715b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const std::string name_;               // Test name
716b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Name of the parameter type, or NULL if this is not a typed or a
717b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // type-parameterized test.
718b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const internal::scoped_ptr<const ::std::string> type_param_;
719b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Text representation of the value parameter, or NULL if this is not a
720b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // value-parameterized test.
721b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const internal::scoped_ptr<const ::std::string> value_param_;
722b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
72394c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  bool should_run_;                 // True iff this test should run
72494c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  bool is_disabled_;                // True iff this test is disabled
725b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  bool matches_filter_;             // True if this test matches the
726b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad                                    // user-specified filter.
727b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  internal::TestFactoryBase* const factory_;  // The factory that creates
728b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad                                              // the test object
729b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
730b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // This field is mutable and needs to be reset before running the
731b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // test for the second time.
732b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  TestResult result_;
7337ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
7347ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
7357ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman};
7367ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
737190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// A test case, which consists of a vector of TestInfos.
738190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer//
739190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// TestCase is not copyable.
74057240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ TestCase {
741190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
742190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Creates a TestCase with the given name.
743190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //
744190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // TestCase does NOT have a default constructor.  Always use this
745190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // constructor to create a TestCase object.
746190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //
747190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Arguments:
748190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //
749190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //   name:         name of the test case
750b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  //   a_type_param: the name of the test's type parameter, or NULL if
751b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  //                 this is not a type-parameterized test.
752190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //   set_up_tc:    pointer to the function that sets up the test case
753190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  //   tear_down_tc: pointer to the function that tears down the test case
754b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  TestCase(const char* name, const char* a_type_param,
755190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer           Test::SetUpTestCaseFunc set_up_tc,
756190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer           Test::TearDownTestCaseFunc tear_down_tc);
757190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
758190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Destructor of TestCase.
759190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual ~TestCase();
760190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
761190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the name of the TestCase.
762190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const char* name() const { return name_.c_str(); }
763190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
764b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Returns the name of the parameter type, or NULL if this is not a
765b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // type-parameterized test case.
766b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const char* type_param() const {
767b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    if (type_param_.get() != NULL)
768b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad      return type_param_->c_str();
769b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return NULL;
770b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
771190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
772190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns true if any test in this test case should run.
773190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool should_run() const { return should_run_; }
774190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
775190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the number of successful tests in this test case.
776190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int successful_test_count() const;
777190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
778190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the number of failed tests in this test case.
779190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int failed_test_count() const;
780190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
781190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the number of disabled tests in this test case.
782190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int disabled_test_count() const;
783190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
784190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Get the number of tests in this test case that should run.
785190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int test_to_run_count() const;
786190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
787190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the number of all tests in this test case.
788190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  int total_test_count() const;
789190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
79094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test case passed.
791190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool Passed() const { return !Failed(); }
792190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
79394c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff the test case failed.
794190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool Failed() const { return failed_test_count() > 0; }
795190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
796190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the elapsed time, in milliseconds.
797190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TimeInMillis elapsed_time() const { return elapsed_time_; }
798190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
799190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the i-th test among all the tests. i can range from 0 to
800190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // total_test_count() - 1. If i is not in that range, returns NULL.
801190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  const TestInfo* GetTestInfo(int i) const;
802190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
803190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer private:
804190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class Test;
805190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::UnitTestImpl;
806190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
807190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the (mutable) vector of TestInfos in this TestCase.
80857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
809190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
810190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Gets the (immutable) vector of TestInfos in this TestCase.
81157240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  const std::vector<TestInfo*>& test_info_list() const {
81257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer    return test_info_list_;
813190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
814190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
815190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the i-th test among all the tests. i can range from 0 to
816190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // total_test_count() - 1. If i is not in that range, returns NULL.
817190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestInfo* GetMutableTestInfo(int i);
818190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
819190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Sets the should_run member.
820190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void set_should_run(bool should) { should_run_ = should; }
821190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
822190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
823190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // destruction of the TestCase object.
824190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void AddTestInfo(TestInfo * test_info);
825190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
826190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Clears the results of all tests in this test case.
827190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void ClearResult();
828190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
829190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Clears the results of all tests in the given test case.
830190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  static void ClearTestCaseResult(TestCase* test_case) {
831190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    test_case->ClearResult();
832190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
833190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
834190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Runs every test in this TestCase.
835190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void Run();
836190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
837b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
838b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // for catching exceptions thrown from SetUpTestCase().
839b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  void RunSetUpTestCase() { (*set_up_tc_)(); }
840b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
841b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Runs TearDownTestCase() for this TestCase.  This wrapper is
842b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // needed for catching exceptions thrown from TearDownTestCase().
843b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  void RunTearDownTestCase() { (*tear_down_tc_)(); }
844b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad
84594c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff test passed.
846b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  static bool TestPassed(const TestInfo* test_info) {
847b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return test_info->should_run() && test_info->result()->Passed();
848b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
849190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
85094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff test failed.
851b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  static bool TestFailed(const TestInfo* test_info) {
852b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return test_info->should_run() && test_info->result()->Failed();
853b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
854190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
85594c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // Returns true iff test is disabled.
856b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  static bool TestDisabled(const TestInfo* test_info) {
857b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return test_info->is_disabled_;
858b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
859190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
860190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns true if the given test should run.
861b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  static bool ShouldRunTest(const TestInfo* test_info) {
862b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad    return test_info->should_run();
863b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  }
864190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
865190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Shuffles the tests in this test case.
866190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void ShuffleTests(internal::Random* random);
867190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
868190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Restores the test order to before the first shuffle.
869190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void UnshuffleTests();
870190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
871190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Name of the test case.
872190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  internal::String name_;
873b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Name of the parameter type, or NULL if this is not a typed or a
874b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // type-parameterized test.
875b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  const internal::scoped_ptr<const ::std::string> type_param_;
876190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // The vector of TestInfos in their original order.  It owns the
877190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // elements in the vector.
87857240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  std::vector<TestInfo*> test_info_list_;
879190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Provides a level of indirection for the test list to allow easy
880190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // shuffling and restoring the test order.  The i-th element in this
881190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // vector is the index of the i-th test in the shuffled test list.
88257240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramer  std::vector<int> test_indices_;
883190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Pointer to the function that sets up the test case.
884190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  Test::SetUpTestCaseFunc set_up_tc_;
885190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Pointer to the function that tears down the test case.
886190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  Test::TearDownTestCaseFunc tear_down_tc_;
88794c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru  // True iff any test in this test case should run.
888190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  bool should_run_;
889190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Elapsed time, in milliseconds.
890190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TimeInMillis elapsed_time_;
891190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
892190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // We disallow copying TestCases.
893190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
894190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};
895190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
8967ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// An Environment object is capable of setting up and tearing down an
8977ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// environment.  The user should subclass this to define his own
8987ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// environment(s).
8997ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
9007ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// An Environment object does the set-up and tear-down in virtual
9017ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// methods SetUp() and TearDown() instead of the constructor and the
9027ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman// destructor, as:
9037ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//
9047ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   1. You cannot safely throw from a destructor.  This is a problem
9057ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//      as in some cases Google Test is used where exceptions are enabled, and
9067ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//      we may want to implement ASSERT_* using exceptions where they are
9077ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//      available.
9087ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//   2. You cannot use ASSERT_* directly in a constructor or
9097ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman//      destructor.
9107ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukmanclass Environment {
9117ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman public:
9127ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // The d'tor is virtual as we need to subclass Environment.
913354362524a72b3fa43a6c09380b7ae3b2380cbbaJuergen Ributzka  virtual ~Environment();
9147ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
9157ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Override this to define how to set up the environment.
9167ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual void SetUp() {}
9177ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
9187ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // Override this to define how to tear down the environment.
9197ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual void TearDown() {}
9207ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman private:
9217ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // If you see an error about overriding the following function or
9227ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  // about it being private, you have mis-spelled SetUp() as Setup().
9237ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  struct Setup_should_be_spelled_SetUp {};
9247ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
9257ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman};
9267ae6ff442a26212a0cc4c1929b8b0a105dc988e4Misha Brukman
927190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// The interface for tracing execution of tests. The methods are organized in
928190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// the order the corresponding events are fired.
929190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass TestEventListener {
930190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
931354362524a72b3fa43a6c09380b7ae3b2380cbbaJuergen Ributzka  virtual ~TestEventListener();
932190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
933190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before any test activity starts.
934190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
935190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
936190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before each iteration of tests starts.  There may be more than
937190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
938190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // index, starting from 0.
939190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestIterationStart(const UnitTest& unit_test,
940190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                    int iteration) = 0;
941190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
942190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before environment set-up for each iteration of tests starts.
943190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
944190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
945190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after environment set-up for each iteration of tests ends.
946190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
947190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
948190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before the test case starts.
949190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
950190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
951190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before the test starts.
952190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestStart(const TestInfo& test_info) = 0;
953190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
954b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  // Fired after a failed assertion or a SUCCEED() invocation.
955190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
956190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
957190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after the test ends.
958190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestEnd(const TestInfo& test_info) = 0;
959190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
960190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after the test case ends.
961190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
962190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
963190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired before environment tear-down for each iteration of tests starts.
964190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
965190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
966190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after environment tear-down for each iteration of tests ends.
967190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
968190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
969190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after each iteration of tests finishes.
970190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestIterationEnd(const UnitTest& unit_test,
971190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                  int iteration) = 0;
972190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
973190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Fired after all test activities have ended.
974190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
975190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};
976190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
977190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// The convenience class for users who need to override just one or two
978190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// methods and are not concerned that a possible change to a signature of
979190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// the methods they override will not be caught during the build.  For
980190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// comments about each method please see the definition of TestEventListener
981190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// above.
982190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramerclass EmptyTestEventListener : public TestEventListener {
983354362524a72b3fa43a6c09380b7ae3b2380cbbaJuergen Ributzka  virtual void anchor();
984190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
985190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
986190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
987190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                    int /*iteration*/) {}
988190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
989190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
990190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
991190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
992190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
993190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
994190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
995190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
996190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
997190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
998190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer                                  int /*iteration*/) {}
999190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
1000190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer};
1001190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1002190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer// TestEventListeners lets users add listeners to track events in Google Test.
100357240ff6e2252f8986f6e47e4010bc52fbae25d1Benjamin Kramerclass GTEST_API_ TestEventListeners {
1004190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer public:
1005190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestEventListeners();
1006190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  ~TestEventListeners();
1007190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1008190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Appends an event listener to the end of the list. Google Test assumes
1009190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // the ownership of the listener (i.e. it will delete the listener when
1010190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // the test program finishes).
1011190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  void Append(TestEventListener* listener);
1012190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1013190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Removes the given event listener from the list and returns it.  It then
1014190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // becomes the caller's responsibility to delete the listener. Returns
1015190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // NULL if the listener is not found in the list.
1016190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestEventListener* Release(TestEventListener* listener);
1017190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1018190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the standard listener responsible for the default console
1019190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // output.  Can be removed from the listeners list to shut down default
1020190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // console output.  Note that removing this object from the listener list
1021190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // with Release transfers its ownership to the caller and makes this
1022190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // function return NULL the next time.
1023190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestEventListener* default_result_printer() const {
1024190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    return default_result_printer_;
1025190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
1026190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1027190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // Returns the standard listener responsible for the default XML output
1028190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // controlled by the --gtest_output=xml flag.  Can be removed from the
1029190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // listeners list by users who want to shut down the default XML output
1030190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // controlled by this flag and substitute it with custom one.  Note that
1031190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // removing this object from the listener list with Release transfers its
1032190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // ownership to the caller and makes this function return NULL the next
1033190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  // time.
1034190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  TestEventListener* default_xml_generator() const {
1035190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer    return default_xml_generator_;
1036190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  }
1037190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer
1038190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer private:
1039190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class TestCase;
1040b33f8e3e55932d0e15a686ef0c598da8dbc37acdJay Foad  friend class TestInfo;
1041190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::DefaultGlobalTestPartResultReporter;
1042190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::NoExecDeathTest;
1043190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::TestEventListenersAccessor;
1044190f8ee25a6977ac6eb71b816498df42f17ad9a7Benjamin Kramer  friend class internal::UnitTestImpl;