1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright 2005, Google Inc.
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// All rights reserved.
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Redistribution and use in source and binary forms, with or without
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// modification, are permitted provided that the following conditions are
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// met:
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Redistributions of source code must retain the above copyright
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// notice, this list of conditions and the following disclaimer.
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Redistributions in binary form must reproduce the above
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// copyright notice, this list of conditions and the following disclaimer
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in the documentation and/or other materials provided with the
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// distribution.
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     * Neither the name of Google Inc. nor the names of its
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// contributors may be used to endorse or promote products derived from
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// this software without specific prior written permission.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Author: wan@google.com (Zhanyong Wan)
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The Google C++ Testing Framework (Google Test)
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This header file defines the public API for Google Test.  It should be
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// included by any test program that uses Google Test.
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// leave some internal implementation details in this header file.
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// They are clearly marked by comments like this:
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Such code is NOT meant to be used by a user directly, and is subject
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// program!
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Acknowledgment: Google Test borrowed the idea of automatic test
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// easyUnit framework.
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_INCLUDE_GTEST_GTEST_H_
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <limits>
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <vector>
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/internal/gtest-internal.h"
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/internal/gtest-string.h"
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-death-test.h"
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-message.h"
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-param-test.h"
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-printers.h"
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest_prod.h"
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-test-part.h"
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest-typed-test.h"
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Depending on the platform, different string classes are available.
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// On Linux, in addition to ::std::string, Google also makes use of
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// class ::string, which has the same interface as ::std::string, but
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// has a different implementation.
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ::string is available AND is a distinct type to ::std::string, or
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// define it to 0 to indicate otherwise.
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If the user's ::std::string and ::string are the same class due to
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// heuristically.
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace testing {
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Declares the flags.
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag temporary enables the disabled tests.
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(also_run_disabled_tests);
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag brings the debugger on an assertion failure.
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(break_on_failure);
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag controls whether Google Test catches all test-thrown exceptions
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and logs them as failures.
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(catch_exceptions);
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag enables using colors in terminal output. Available values are
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to let Google Test decide.
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_string_(color);
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag sets up the filter to select by name using a glob pattern
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the tests to run. If the filter is not given all tests are executed.
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_string_(filter);
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag causes the Google Test to list tests. None of the tests listed
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// are actually run if the flag is provided.
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(list_tests);
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag controls whether Google Test emits a detailed XML report to a file
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in addition to its normal textual output.
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_string_(output);
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flags control whether Google Test prints the elapsed time for each
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// test.
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(print_time);
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag specifies the random number seed.
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_int32_(random_seed);
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag sets how many times the tests are repeated. The default value
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is 1. If the value is -1 the tests are repeating forever.
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_int32_(repeat);
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag controls whether Google Test includes Google Test internal
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// stack frames in failure stack traces.
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(show_internal_stack_frames);
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When this flag is specified, tests' order is randomized on every iteration.
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(shuffle);
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This flag specifies the maximum number of stack frames to be
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// printed in a failure message.
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_int32_(stack_trace_depth);
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When this flag is specified, a failed assertion will throw an
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// exception if exceptions are enabled, or exit the program with a
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// non-zero code otherwise.
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_bool_(throw_on_failure);
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When this flag is set with a "host:port" string, on supported
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// platforms test results are streamed to the specified port on
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the specified host machine.
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_DECLARE_string_(stream_result_to);
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The upper limit for valid stack trace depths.
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst int kMaxStackTraceDepth = 100;
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace internal {
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass AssertHelper;
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass DefaultGlobalTestPartResultReporter;
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass ExecDeathTest;
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass NoExecDeathTest;
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass FinalSuccessChecker;
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTestFlagSaver;
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestResultAccessor;
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestEventListenersAccessor;
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestEventRepeater;
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass WindowsDeathTest;
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass UnitTestImpl* GetUnitTestImpl();
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    const String& message);
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Converts a streamable value to a String.  A NULL pointer is
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// converted to "(null)".  When the input value is a ::string,
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ::std::string, ::wstring, or ::std::wstring object, each NUL
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// character in it is replaced with "\\0".
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Declared in gtest-internal.h but defined here, so that it has access
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to the definition of the Message class, required by the ARM
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// compiler.
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgString StreamableToString(const T& streamable) {
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return (Message() << streamable).GetString();
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace internal
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The friend relationship of some of these classes is cyclic.
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If we don't forward declare them the compiler might confuse the classes
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in friendship clauses with same named classes on the scope.
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Test;
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestCase;
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestInfo;
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass UnitTest;
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A class for indicating whether an assertion was successful.  When
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the assertion wasn't successful, the AssertionResult object
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// remembers a non-empty message that describes how it failed.
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To create an instance of this class, use one of the factory functions
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// (AssertionSuccess() and AssertionFailure()).
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This class is useful for two purposes:
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   1. Defining predicate functions to be used with Boolean test assertions
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   2. Defining predicate-format functions to be
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For example, if you define IsEven predicate:
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   testing::AssertionResult IsEven(int n) {
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     if ((n % 2) == 0)
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionSuccess();
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     else
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionFailure() << n << " is odd";
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// will print the message
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Value of: IsEven(Fib(5))
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Actual: false (5 is odd)
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Expected: true
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// instead of a more opaque
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Value of: IsEven(Fib(5))
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Actual: false
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Expected: true
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in case IsEven is a simple Boolean predicate.
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If you expect your predicate to be reused and want to support informative
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// about half as often as positive ones in our tests), supply messages for
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// both success and failure cases:
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   testing::AssertionResult IsEven(int n) {
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     if ((n % 2) == 0)
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionSuccess() << n << " is even";
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     else
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionFailure() << n << " is odd";
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Value of: IsEven(Fib(6))
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Actual: true (8 is even)
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Expected: false
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// NB: Predicates that support negative Boolean assertions have reduced
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// performance in positive ones so be careful not to use them in tests
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// that have lots (tens of thousands) of positive Boolean assertions.
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// To use this class with EXPECT_PRED_FORMAT assertions such as:
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // Verifies that Foo() returns an even number.
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_PRED_FORMAT1(IsEven, Foo());
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// you need to define:
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   testing::AssertionResult IsEven(const char* expr, int n) {
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     if ((n % 2) == 0)
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionSuccess();
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     else
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       return testing::AssertionFailure()
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// If Foo() returns 5, you will see the following message:
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Expected: Foo() is even
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Actual: it's 5
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ AssertionResult {
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Copy constructor.
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Used in EXPECT_TRUE/FALSE(assertion_result).
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  AssertionResult(const AssertionResult& other);
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Used in the EXPECT_TRUE/FALSE(bool_expression).
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  explicit AssertionResult(bool success) : success_(success) {}
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the assertion succeeded.
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  operator bool() const { return success_; }  // NOLINT
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  AssertionResult operator!() const;
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the text streamed into this AssertionResult. Test assertions
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // use it when they fail (i.e., the predicate's outcome doesn't match the
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // assertion's expectation). When nothing has been streamed into the
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // object, returns an empty string.
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* message() const {
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return message_.get() != NULL ?  message_->c_str() : "";
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TODO(vladl@google.com): Remove this after making sure no clients use it.
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Deprecated; please use message() instead.
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* failure_message() const { return message(); }
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Streams a custom failure message into this object.
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  template <typename T> AssertionResult& operator<<(const T& value) {
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    AppendMessage(Message() << value);
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return *this;
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Allows streaming basic output manipulators such as endl or flush into
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // this object.
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  AssertionResult& operator<<(
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    AppendMessage(Message() << basic_manipulator);
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return *this;
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Appends the contents of message to message_.
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AppendMessage(const Message& a_message) {
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (message_.get() == NULL)
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      message_.reset(new ::std::string);
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    message_->append(a_message.GetString().c_str());
310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Stores result of the assertion predicate.
313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool success_;
314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Stores the message describing the condition in case the expectation
315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // construct is not satisfied with the predicate's outcome.
316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Referenced via a pointer to avoid taking too much stack frame space
317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // with test assertions.
318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::scoped_ptr< ::std::string> message_;
319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_ASSIGN_(AssertionResult);
321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Makes a successful assertion result.
324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult AssertionSuccess();
325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Makes a failed assertion result.
327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult AssertionFailure();
328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Makes a failed assertion result with the given failure message.
330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Deprecated; use AssertionFailure() << msg.
331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The abstract class that all tests inherit from.
334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// In Google Test, a unit test program contains one or many TestCases, and
336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// each TestCase contains one or many Tests.
337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When you define a test using the TEST macro, you don't need to
339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// explicitly derive from Test - the TEST macro automatically does
340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// this for you.
341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The only time you derive from Test is when defining a test fixture
343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to be used a TEST_F.  For example:
344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   class FooTest : public testing::Test {
346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    protected:
347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     virtual void SetUp() { ... }
348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     virtual void TearDown() { ... }
349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     ...
350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   };
351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TEST_F(FooTest, Bar) { ... }
353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TEST_F(FooTest, Baz) { ... }
354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Test is not copyable.
356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ Test {
357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class TestInfo;
359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Defines types for pointers to functions that set up and tear down
361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // a test case.
362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The d'tor is virtual as we intend to inherit from Test.
366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~Test();
367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets up the stuff shared by all tests in this test case.
369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Google Test will call Foo::SetUpTestCase() before running the first
371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // test in test case Foo.  Hence a sub-class can define its own
372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // SetUpTestCase() method to shadow the one defined in the super
373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // class.
374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void SetUpTestCase() {}
375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Tears down the stuff shared by all tests in this test case.
377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Google Test will call Foo::TearDownTestCase() after running the last
379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // test in test case Foo.  Hence a sub-class can define its own
380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TearDownTestCase() method to shadow the one defined in the super
381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // class.
382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void TearDownTestCase() {}
383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the current test has a fatal failure.
385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool HasFatalFailure();
386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the current test has a non-fatal failure.
388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool HasNonfatalFailure();
389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the current test has a (either fatal or
391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // non-fatal) failure.
392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Logs a property for the current test.  Only the last value for a given
395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // key is remembered.
396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // These are public static so they can be called from utility functions
397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // that are not members of the test fixture.
398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The arguments are const char* instead strings, as Google Test is used
399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // on platforms where string doesn't compile.
400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Note that a driving consideration for these RecordProperty methods
402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // was to produce xml output suited to the Greenspan charting utility,
403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // which at present will only chart values that fit in a 32-bit int. It
404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // is the user's responsibility to restrict their values to 32-bit ints
405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // if they intend them to be used with Greenspan.
406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void RecordProperty(const char* key, const char* value);
407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void RecordProperty(const char* key, int value);
408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org protected:
410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Creates a Test object.
411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Test();
412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets up the test fixture.
414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void SetUp();
415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Tears down the test fixture.
417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void TearDown();
418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the current test has the same fixture class as
421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the first test in the current test case.
422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool HasSameFixtureClass();
423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Runs the test after the test fixture has been set up.
425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // A sub-class must implement this to define the test logic.
427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Instead, use the TEST or TEST_F macro.
430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void TestBody() = 0;
431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets up, executes, and tears down the test.
433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Run();
434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Deletes self.  We deliberately pick an unusual name for this
436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // internal method to avoid clashing with names used in user TESTs.
437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void DeleteSelf_() { delete this; }
438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Uses a GTestFlagSaver to save and restore all Google Test flags.
440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::GTestFlagSaver* const gtest_flag_saver_;
441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Often a user mis-spells SetUp() as Setup() and spends a long time
443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // wondering why it is never called by Google Test.  The declaration of
444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the following method is solely for catching such an error at
445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // compile time:
446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   - The return type is deliberately chosen to be not void, so it
448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   will be a conflict if a user declares void Setup() in his test
449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   fixture.
450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   - This method is private, so it will be another compiler error
452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   if a user calls it from his test fixture.
453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // DO NOT OVERRIDE THIS FUNCTION.
455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // If you see an error about overriding the following function or
457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // about it being private, you have mis-spelled SetUp() as Setup().
458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  struct Setup_should_be_spelled_SetUp {};
459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We disallow copying Tests.
462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef internal::TimeInMillis TimeInMillis;
466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A copyable object representing a user specified test property which can be
468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// output as a key/value string pair.
469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Don't inherit from TestProperty as its destructor is not virtual.
471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestProperty {
472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // C'tor.  TestProperty does NOT have a default constructor.
474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Always use this constructor (with parameters) to create a
475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TestProperty object.
476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestProperty(const char* a_key, const char* a_value) :
477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    key_(a_key), value_(a_value) {
478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the user supplied key.
481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* key() const {
482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return key_.c_str();
483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the user supplied value.
486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* value() const {
487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return value_.c_str();
488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets a new value, overriding the one supplied in the constructor.
491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void SetValue(const char* new_value) {
492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    value_ = new_value;
493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The key supplied by the user.
497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::String key_;
498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The value supplied by the user.
499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::String value_;
500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The result of a single Test.  This includes a list of
503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TestPartResults, a list of TestProperties, a count of how many
504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// death tests there are in the Test, and how much time it took to run
505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the Test.
506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TestResult is not copyable.
508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ TestResult {
509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Creates an empty TestResult.
511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestResult();
512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // D'tor.  Do not inherit from TestResult.
514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~TestResult();
515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of all test parts.  This is the sum of the number
517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // of successful test parts and the number of failed test parts.
518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int total_part_count() const;
519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the number of the test properties.
521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int test_property_count() const;
522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test passed (i.e. no test part failed).
524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Passed() const { return !Failed(); }
525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test failed.
527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Failed() const;
528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test fatally failed.
530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool HasFatalFailure() const;
531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test has a non-fatal failure.
533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool HasNonfatalFailure() const;
534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the elapsed time, in milliseconds.
536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TimeInMillis elapsed_time() const { return elapsed_time_; }
537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the i-th test part result among all the results. i can range
539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // from 0 to test_property_count() - 1. If i is not in that range, aborts
540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the program.
541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestPartResult& GetTestPartResult(int i) const;
542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the i-th test property. i can range from 0 to
544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // test_property_count() - 1. If i is not in that range, aborts the
545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // program.
546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestProperty& GetTestProperty(int i) const;
547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class TestInfo;
550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class UnitTest;
551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::DefaultGlobalTestPartResultReporter;
552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::ExecDeathTest;
553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::TestResultAccessor;
554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::UnitTestImpl;
555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::WindowsDeathTest;
556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the vector of TestPartResults.
558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const std::vector<TestPartResult>& test_part_results() const {
559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_part_results_;
560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the vector of TestProperties.
563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const std::vector<TestProperty>& test_properties() const {
564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_properties_;
565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets the elapsed time.
568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a test property to the list. The property is validated and may add
571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // key names). If a property is already recorded for the same key, the
573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // value will be updated, rather than storing multiple values for the same
574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // key.
575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void RecordProperty(const TestProperty& test_property);
576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a failure if the key is a reserved attribute of Google Test
578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // testcase tags.  Returns true if the property is valid.
579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TODO(russr): Validate attribute names are legal and human readable.
580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool ValidateTestProperty(const TestProperty& test_property);
581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a test part result to the list.
583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AddTestPartResult(const TestPartResult& test_part_result);
584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the death test count.
586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int death_test_count() const { return death_test_count_; }
587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Increments the death test count, returning the new count.
589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int increment_death_test_count() { return ++death_test_count_; }
590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Clears the test part results.
592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void ClearTestPartResults();
593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Clears the object.
595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Clear();
596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Protects mutable state of the property vector and of owned
598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // properties, whose values may be updated.
599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::Mutex test_properites_mutex_;
600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The vector of TestPartResults
602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  std::vector<TestPartResult> test_part_results_;
603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The vector of TestProperties
604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  std::vector<TestProperty> test_properties_;
605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Running count of death tests.
606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int death_test_count_;
607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The elapsed time, in milliseconds.
608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TimeInMillis elapsed_time_;
609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We disallow copying TestResult.
611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};  // class TestResult
613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A TestInfo object stores the following information about a test:
615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Test case name
617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Test name
618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Whether the test should be run
619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   A function pointer that creates the test object when invoked
620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Test result
621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The constructor of TestInfo registers itself with the UnitTest
623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// singleton such that the RUN_ALL_TESTS() macro knows which tests to
624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// run.
625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ TestInfo {
626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Destructs a TestInfo object.  This function is not virtual, so
628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // don't inherit from TestInfo.
629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~TestInfo();
630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the test case name.
632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* test_case_name() const { return test_case_name_.c_str(); }
633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the test name.
635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* name() const { return name_.c_str(); }
636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the name of the parameter type, or NULL if this is not a typed
638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // or a type-parameterized test.
639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* type_param() const {
640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (type_param_.get() != NULL)
641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return type_param_->c_str();
642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return NULL;
643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the text representation of the value parameter, or NULL if this
646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // is not a value-parameterized test.
647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* value_param() const {
648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (value_param_.get() != NULL)
649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return value_param_->c_str();
650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return NULL;
651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true if this test should run, that is if the test is not disabled
654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // (or it is disabled but the also_run_disabled_tests flag has been specified)
655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // and its full name matches the user-specified filter.
656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Google Test allows the user to filter the tests by their full names.
658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The full name of a test Bar in test case Foo is defined as
659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // "Foo.Bar".  Only the tests that match the filter will run.
660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // A filter is a colon-separated list of glob (not regex) patterns,
662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // optionally followed by a '-' and a colon-separated list of
663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // negative patterns (tests to exclude).  A test is run if it
664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // matches one of the positive patterns and does not match any of
665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the negative patterns.
666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // For example, *A*:Foo.* is a filter that matches any string that
668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // contains the character 'A' or starts with "Foo.".
669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool should_run() const { return should_run_; }
670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the result of the test.
672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestResult* result() const { return &result_; }
673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_DEATH_TEST
677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::DefaultDeathTestFactory;
678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_DEATH_TEST
679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class Test;
680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class TestCase;
681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::UnitTestImpl;
682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend TestInfo* internal::MakeAndRegisterTestInfo(
683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* test_case_name, const char* name,
684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* type_param,
685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* value_param,
686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      internal::TypeId fixture_class_id,
687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      Test::SetUpTestCaseFunc set_up_tc,
688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      Test::TearDownTestCaseFunc tear_down_tc,
689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      internal::TestFactoryBase* factory);
690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Constructs a TestInfo object. The newly constructed instance assumes
692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // ownership of the factory object.
693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestInfo(const char* test_case_name, const char* name,
694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           const char* a_type_param,
695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           const char* a_value_param,
696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           internal::TypeId fixture_class_id,
697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           internal::TestFactoryBase* factory);
698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Increments the number of death tests encountered in this test so
700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // far.
701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int increment_death_test_count() {
702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return result_.increment_death_test_count();
703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Creates the test object, runs it, records its result, and then
706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // deletes it.
707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Run();
708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void ClearTestResult(TestInfo* test_info) {
710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    test_info->result_.Clear();
711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // These fields are immutable properties of the test.
714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const std::string test_case_name_;     // Test case name
715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const std::string name_;               // Test name
716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Name of the parameter type, or NULL if this is not a typed or a
717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // type-parameterized test.
718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::scoped_ptr<const ::std::string> type_param_;
719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Text representation of the value parameter, or NULL if this is not a
720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // value-parameterized test.
721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::scoped_ptr<const ::std::string> value_param_;
722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool should_run_;                 // True iff this test should run
724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool is_disabled_;                // True iff this test is disabled
725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool matches_filter_;             // True if this test matches the
726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    // user-specified filter.
727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::TestFactoryBase* const factory_;  // The factory that creates
728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              // the test object
729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This field is mutable and needs to be reset before running the
731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // test for the second time.
732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestResult result_;
733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A test case, which consists of a vector of TestInfos.
738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TestCase is not copyable.
740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ TestCase {
741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Creates a TestCase with the given name.
743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TestCase does NOT have a default constructor.  Always use this
745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // constructor to create a TestCase object.
746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Arguments:
748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   name:         name of the test case
750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   a_type_param: the name of the test's type parameter, or NULL if
751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //                 this is not a type-parameterized test.
752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   set_up_tc:    pointer to the function that sets up the test case
753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //   tear_down_tc: pointer to the function that tears down the test case
754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestCase(const char* name, const char* a_type_param,
755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           Test::SetUpTestCaseFunc set_up_tc,
756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           Test::TearDownTestCaseFunc tear_down_tc);
757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Destructor of TestCase.
759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~TestCase();
760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the name of the TestCase.
762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* name() const { return name_.c_str(); }
763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the name of the parameter type, or NULL if this is not a
765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // type-parameterized test case.
766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* type_param() const {
767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (type_param_.get() != NULL)
768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return type_param_->c_str();
769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return NULL;
770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true if any test in this test case should run.
773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool should_run() const { return should_run_; }
774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of successful tests in this test case.
776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int successful_test_count() const;
777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of failed tests in this test case.
779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int failed_test_count() const;
780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of disabled tests in this test case.
782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int disabled_test_count() const;
783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Get the number of tests in this test case that should run.
785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int test_to_run_count() const;
786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of all tests in this test case.
788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int total_test_count() const;
789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test case passed.
791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Passed() const { return !Failed(); }
792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the test case failed.
794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Failed() const { return failed_test_count() > 0; }
795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the elapsed time, in milliseconds.
797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TimeInMillis elapsed_time() const { return elapsed_time_; }
798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the i-th test among all the tests. i can range from 0 to
800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // total_test_count() - 1. If i is not in that range, returns NULL.
801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestInfo* GetTestInfo(int i) const;
802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class Test;
805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::UnitTestImpl;
806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the (mutable) vector of TestInfos in this TestCase.
808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the (immutable) vector of TestInfos in this TestCase.
811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const std::vector<TestInfo*>& test_info_list() const {
812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_info_list_;
813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the i-th test among all the tests. i can range from 0 to
816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // total_test_count() - 1. If i is not in that range, returns NULL.
817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestInfo* GetMutableTestInfo(int i);
818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets the should_run member.
820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void set_should_run(bool should) { should_run_ = should; }
821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // destruction of the TestCase object.
824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AddTestInfo(TestInfo * test_info);
825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Clears the results of all tests in this test case.
827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void ClearResult();
828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Clears the results of all tests in the given test case.
830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void ClearTestCaseResult(TestCase* test_case) {
831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    test_case->ClearResult();
832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Runs every test in this TestCase.
835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Run();
836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // for catching exceptions thrown from SetUpTestCase().
839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void RunSetUpTestCase() { (*set_up_tc_)(); }
840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Runs TearDownTestCase() for this TestCase.  This wrapper is
842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // needed for catching exceptions thrown from TearDownTestCase().
843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void RunTearDownTestCase() { (*tear_down_tc_)(); }
844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff test passed.
846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool TestPassed(const TestInfo* test_info) {
847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_info->should_run() && test_info->result()->Passed();
848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff test failed.
851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool TestFailed(const TestInfo* test_info) {
852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_info->should_run() && test_info->result()->Failed();
853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff test is disabled.
856f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool TestDisabled(const TestInfo* test_info) {
857f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_info->is_disabled_;
858f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
859f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
860f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true if the given test should run.
861f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static bool ShouldRunTest(const TestInfo* test_info) {
862f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return test_info->should_run();
863f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
864f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
865f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Shuffles the tests in this test case.
866f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void ShuffleTests(internal::Random* random);
867f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
868f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Restores the test order to before the first shuffle.
869f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void UnshuffleTests();
870f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
871f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Name of the test case.
872f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::String name_;
873f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Name of the parameter type, or NULL if this is not a typed or a
874f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // type-parameterized test.
875f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::scoped_ptr<const ::std::string> type_param_;
876f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The vector of TestInfos in their original order.  It owns the
877f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // elements in the vector.
878f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  std::vector<TestInfo*> test_info_list_;
879f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Provides a level of indirection for the test list to allow easy
880f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // shuffling and restoring the test order.  The i-th element in this
881f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // vector is the index of the i-th test in the shuffled test list.
882f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  std::vector<int> test_indices_;
883f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Pointer to the function that sets up the test case.
884f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Test::SetUpTestCaseFunc set_up_tc_;
885f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Pointer to the function that tears down the test case.
886f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Test::TearDownTestCaseFunc tear_down_tc_;
887f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // True iff any test in this test case should run.
888f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool should_run_;
889f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Elapsed time, in milliseconds.
890f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TimeInMillis elapsed_time_;
891f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
892f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We disallow copying TestCases.
893f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
894f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
895f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
896f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// An Environment object is capable of setting up and tearing down an
897f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// environment.  The user should subclass this to define his own
898f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// environment(s).
899f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
900f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// An Environment object does the set-up and tear-down in virtual
901f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// methods SetUp() and TearDown() instead of the constructor and the
902f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// destructor, as:
903f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
904f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   1. You cannot safely throw from a destructor.  This is a problem
905f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      as in some cases Google Test is used where exceptions are enabled, and
906f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      we may want to implement ASSERT_* using exceptions where they are
907f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      available.
908f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   2. You cannot use ASSERT_* directly in a constructor or
909f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//      destructor.
910f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Environment {
911f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
912f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The d'tor is virtual as we need to subclass Environment.
913f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~Environment() {}
914f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
915f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Override this to define how to set up the environment.
916f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void SetUp() {}
917f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
918f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Override this to define how to tear down the environment.
919f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void TearDown() {}
920f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
921f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // If you see an error about overriding the following function or
922f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // about it being private, you have mis-spelled SetUp() as Setup().
923f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  struct Setup_should_be_spelled_SetUp {};
924f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
925f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
926f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
927f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The interface for tracing execution of tests. The methods are organized in
928f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the order the corresponding events are fired.
929f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestEventListener {
930f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
931f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~TestEventListener() {}
932f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
933f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before any test activity starts.
934f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
935f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
936f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before each iteration of tests starts.  There may be more than
937f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
938f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // index, starting from 0.
939f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestIterationStart(const UnitTest& unit_test,
940f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    int iteration) = 0;
941f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
942f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before environment set-up for each iteration of tests starts.
943f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
944f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
945f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after environment set-up for each iteration of tests ends.
946f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
947f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
948f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before the test case starts.
949f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
950f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
951f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before the test starts.
952f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestStart(const TestInfo& test_info) = 0;
953f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
954f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after a failed assertion or a SUCCEED() invocation.
955f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
956f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
957f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after the test ends.
958f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestEnd(const TestInfo& test_info) = 0;
959f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
960f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after the test case ends.
961f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
962f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
963f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired before environment tear-down for each iteration of tests starts.
964f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
965f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
966f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after environment tear-down for each iteration of tests ends.
967f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
968f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
969f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after each iteration of tests finishes.
970f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestIterationEnd(const UnitTest& unit_test,
971f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  int iteration) = 0;
972f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
973f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Fired after all test activities have ended.
974f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
975f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
976f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
977f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The convenience class for users who need to override just one or two
978f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// methods and are not concerned that a possible change to a signature of
979f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the methods they override will not be caught during the build.  For
980f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// comments about each method please see the definition of TestEventListener
981f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// above.
982f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass EmptyTestEventListener : public TestEventListener {
983f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
984f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
985f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
986f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    int /*iteration*/) {}
987f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
988f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
989f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
990f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
991f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
992f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
993f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
994f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
995f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
996f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
997f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  int /*iteration*/) {}
998f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
999f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1000f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1001f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TestEventListeners lets users add listeners to track events in Google Test.
1002f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ TestEventListeners {
1003f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1004f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListeners();
1005f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~TestEventListeners();
1006f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1007f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Appends an event listener to the end of the list. Google Test assumes
1008f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the ownership of the listener (i.e. it will delete the listener when
1009f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the test program finishes).
1010f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void Append(TestEventListener* listener);
1011f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1012f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Removes the given event listener from the list and returns it.  It then
1013f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // becomes the caller's responsibility to delete the listener. Returns
1014f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // NULL if the listener is not found in the list.
1015f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* Release(TestEventListener* listener);
1016f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1017f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the standard listener responsible for the default console
1018f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // output.  Can be removed from the listeners list to shut down default
1019f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // console output.  Note that removing this object from the listener list
1020f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // with Release transfers its ownership to the caller and makes this
1021f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // function return NULL the next time.
1022f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* default_result_printer() const {
1023f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return default_result_printer_;
1024f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1025f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1026f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the standard listener responsible for the default XML output
1027f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // controlled by the --gtest_output=xml flag.  Can be removed from the
1028f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // listeners list by users who want to shut down the default XML output
1029f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // controlled by this flag and substitute it with custom one.  Note that
1030f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // removing this object from the listener list with Release transfers its
1031f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // ownership to the caller and makes this function return NULL the next
1032f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // time.
1033f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* default_xml_generator() const {
1034f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return default_xml_generator_;
1035f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1036f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1037f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1038f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class TestCase;
1039f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class TestInfo;
1040f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::DefaultGlobalTestPartResultReporter;
1041f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::NoExecDeathTest;
1042f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::TestEventListenersAccessor;
1043f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::UnitTestImpl;
1044f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1045f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns repeater that broadcasts the TestEventListener events to all
1046f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // subscribers.
1047f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* repeater();
1048f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1049f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets the default_result_printer attribute to the provided listener.
1050f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The listener is also added to the listener list and previous
1051f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // default_result_printer is removed from it and deleted. The listener can
1052f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // also be NULL in which case it will not be added to the list. Does
1053f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // nothing if the previous and the current listener objects are the same.
1054f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void SetDefaultResultPrinter(TestEventListener* listener);
1055f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1056f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets the default_xml_generator attribute to the provided listener.  The
1057f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // listener is also added to the listener list and previous
1058f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // default_xml_generator is removed from it and deleted. The listener can
1059f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // also be NULL in which case it will not be added to the list. Does
1060f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // nothing if the previous and the current listener objects are the same.
1061f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void SetDefaultXmlGenerator(TestEventListener* listener);
1062f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1063f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Controls whether events will be forwarded by the repeater to the
1064f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // listeners in the list.
1065f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool EventForwardingEnabled() const;
1066f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void SuppressEventForwarding();
1067f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1068f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The actual list of listeners.
1069f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::TestEventRepeater* repeater_;
1070f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Listener responsible for the standard result output.
1071f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* default_result_printer_;
1072f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Listener responsible for the creation of the XML output file.
1073f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListener* default_xml_generator_;
1074f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1075f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We disallow copying TestEventListeners.
1076f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
1077f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1078f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1079f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A UnitTest consists of a vector of TestCases.
1080f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1081f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This is a singleton class.  The only instance of UnitTest is
1082f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// created when UnitTest::GetInstance() is first called.  This
1083f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// instance is never deleted.
1084f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1085f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// UnitTest is not copyable.
1086f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1087f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This class is thread-safe as long as the methods are called
1088f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// according to their specification.
1089f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ UnitTest {
1090f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1091f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the singleton UnitTest object.  The first time this method
1092f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // is called, a UnitTest object is constructed and returned.
1093f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Consecutive calls will return the same object.
1094f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static UnitTest* GetInstance();
1095f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1096f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Runs all tests in this UnitTest object and prints the result.
1097f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns 0 if successful, or 1 otherwise.
1098f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1099f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This method can only be called from the main thread.
1100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int Run() GTEST_MUST_USE_RESULT_;
1103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the working directory when the first TEST() or TEST_F()
1105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // was executed.  The UnitTest object owns the string.
1106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const char* original_working_dir() const;
1107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the TestCase object for the test that's currently running,
1109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // or NULL if no test is running.
1110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestCase* current_test_case() const;
1111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the TestInfo object for the test that's currently running,
1113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // or NULL if no test is running.
1114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestInfo* current_test_info() const;
1115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the random seed used at the start of the current test run.
1117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int random_seed() const;
1118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_PARAM_TEST
1120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the ParameterizedTestCaseRegistry object used to keep track of
1121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // value-parameterized tests and instantiate and register them.
1122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::ParameterizedTestCaseRegistry& parameterized_test_registry();
1125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_PARAM_TEST
1126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of successful test cases.
1128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int successful_test_case_count() const;
1129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of failed test cases.
1131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int failed_test_case_count() const;
1132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of all test cases.
1134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int total_test_case_count() const;
1135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of all test cases that contain at least one test
1137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // that should run.
1138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int test_case_to_run_count() const;
1139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of successful tests.
1141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int successful_test_count() const;
1142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of failed tests.
1144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int failed_test_count() const;
1145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of disabled tests.
1147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int disabled_test_count() const;
1148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of all tests.
1150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int total_test_count() const;
1151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the number of tests that should run.
1153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int test_to_run_count() const;
1154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the elapsed time, in milliseconds.
1156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TimeInMillis elapsed_time() const;
1157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the unit test passed (i.e. all test cases passed).
1159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Passed() const;
1160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns true iff the unit test failed (i.e. some test case failed
1162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // or something outside of all tests failed).
1163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  bool Failed() const;
1164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the i-th test case among all the test cases. i can range from 0 to
1166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const TestCase* GetTestCase(int i) const;
1168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Returns the list of event listeners that can be used to track events
1170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // inside Google Test.
1171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestEventListeners& listeners();
1172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Registers and returns a global test environment.  When a test
1175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // program is run, all global test environments will be set-up in
1176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the order they were registered.  After all tests in the program
1177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // have finished, all global test environments will be torn-down in
1178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the *reverse* order they were registered.
1179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The UnitTest object takes ownership of the given environment.
1181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This method can only be called from the main thread.
1183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  Environment* AddEnvironment(Environment* env);
1184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a TestPartResult to the current TestResult object.  All
1186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // eventually call this to report their results.  The user code
1188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // should use the assertion macros instead of calling this directly.
1189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void AddTestPartResult(TestPartResult::Type result_type,
1190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         const char* file_name,
1191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         int line_number,
1192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         const internal::String& message,
1193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         const internal::String& os_stack_trace);
1194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Adds a TestProperty to the current TestResult object. If the result already
1196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // contains a property with the same key, the value will be updated.
1197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void RecordPropertyForCurrentTest(const char* key, const char* value);
1198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Gets the i-th test case among all the test cases. i can range from 0 to
1200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  TestCase* GetMutableTestCase(int i);
1202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Accessors for the implementation object.
1204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::UnitTestImpl* impl() { return impl_; }
1205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const internal::UnitTestImpl* impl() const { return impl_; }
1206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // These classes and funcions are friends as they need to access private
1208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // members of UnitTest.
1209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class Test;
1210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::AssertHelper;
1211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend class internal::ScopedTrace;
1212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend Environment* AddGlobalTestEnvironment(Environment* env);
1213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend internal::UnitTestImpl* internal::GetUnitTestImpl();
1214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  friend void internal::ReportFailureInUnknownLocation(
1215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      TestPartResult::Type result_type,
1216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const internal::String& message);
1217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Creates an empty UnitTest.
1219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  UnitTest();
1220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // D'tor
1222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~UnitTest();
1223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
1225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Google Test trace stack.
1226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void PushGTestTrace(const internal::TraceInfo& trace);
1227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Pops a trace from the per-thread Google Test trace stack.
1229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void PopGTestTrace();
1230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Protects mutable state in *impl_.  This is mutable as some const
1232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // methods need to lock it too.
1233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  mutable internal::Mutex mutex_;
1234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Opaque implementation object.  This field is never changed once
1236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // the object is constructed.  We don't mark it as const here, as
1237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // doing so will cause a warning in the constructor of UnitTest.
1238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Mutable state in *impl_ is protected by mutex_.
1239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  internal::UnitTestImpl* impl_;
1240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We disallow copying UnitTest.
1242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
1243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A convenient wrapper for adding an environment for the test
1246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// program.
1247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// You should call this before RUN_ALL_TESTS() is called, probably in
1249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// main().  If you use gtest_main, you need to call this before main()
1250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// starts for it to take effect.  For example, you can define a global
1251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// variable like this:
1252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   testing::Environment* const foo_env =
1254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       testing::AddGlobalTestEnvironment(new FooEnvironment);
1255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// However, we strongly recommend you to write your own main() and
1257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// call AddGlobalTestEnvironment() there, as relying on initialization
1258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// of global variables makes the code harder to read and may cause
1259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// problems when you register multiple environments from different
1260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// translation units and the environments have dependencies among them
1261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// (remember that the compiler doesn't guarantee the order in which
1262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// global variables from different translation units are initialized).
1263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline Environment* AddGlobalTestEnvironment(Environment* env) {
1264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return UnitTest::GetInstance()->AddEnvironment(env);
1265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Initializes Google Test.  This must be called before calling
1268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// RUN_ALL_TESTS().  In particular, it parses a command line for the
1269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// flags that Google Test recognizes.  Whenever a Google Test flag is
1270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// seen, it is removed from argv, and *argc is decremented.
1271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// No value is returned.  Instead, the Google Test flag variables are
1273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// updated.
1274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Calling the function for the second time has no user-visible effect.
1276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ void InitGoogleTest(int* argc, char** argv);
1277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This overloaded version can be used in Windows programs compiled in
1279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// UNICODE mode.
1280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
1281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace internal {
1283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
1285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// operand to be used in a failure message.  The type (but not value)
1286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// of the other operand may affect the format.  This allows us to
1287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// print a char* as a raw pointer when it is compared against another
1288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// char*, and print it as a C string when it is compared against an
1289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// std::string object, for example.
1290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The default implementation ignores the type of the other operand.
1292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Some specialized versions are used to handle formatting wide or
1293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// narrow C strings.
1294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T1, typename T2>
1297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgString FormatForComparisonFailureMessage(const T1& value,
1298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                         const T2& /* other_operand */) {
1299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // C++Builder compiles this incorrectly if the namespace isn't explicitly
1300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // given.
1301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return ::testing::PrintToString(value);
1302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper function for {ASSERT|EXPECT}_EQ.
1305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T1, typename T2>
1306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgAssertionResult CmpHelperEQ(const char* expected_expression,
1307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const char* actual_expression,
1308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const T1& expected,
1309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const T2& actual) {
1310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER
1311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(push)          // Saves the current warning state.
1312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(disable:4389)  // Temporarily disables warning on
1313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                               // signed/unsigned mismatch.
1314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (expected == actual) {
1317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return AssertionSuccess();
1318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER
1321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# pragma warning(pop)          // Restores the warning state.
1322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return EqFailure(expected_expression,
1325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   actual_expression,
1326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   FormatForComparisonFailureMessage(expected, actual),
1327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   FormatForComparisonFailureMessage(actual, expected),
1328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   false);
1329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// With this overloaded version, we allow anonymous enums to be used
1332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
1333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// can be implicitly cast to BiggestInt.
1334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
1335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       const char* actual_expression,
1336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       BiggestInt expected,
1337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       BiggestInt actual);
1338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper class for {ASSERT|EXPECT}_EQ.  The template argument
1340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
1341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is a null pointer literal.  The following default implementation is
1342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// for lhs_is_null_literal being false.
1343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <bool lhs_is_null_literal>
1344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass EqHelper {
1345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This templatized version is for the general case.
1347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  template <typename T1, typename T2>
1348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static AssertionResult Compare(const char* expected_expression,
1349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 const char* actual_expression,
1350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 const T1& expected,
1351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 const T2& actual) {
1352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return CmpHelperEQ(expected_expression, actual_expression, expected,
1353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       actual);
1354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // With this overloaded version, we allow anonymous enums to be used
1357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
1358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // enums can be implicitly cast to BiggestInt.
1359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  //
1360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Even though its body looks the same as the above version, we
1361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // cannot merge the two, as it will make anonymous enums unhappy.
1362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static AssertionResult Compare(const char* expected_expression,
1363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 const char* actual_expression,
1364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 BiggestInt expected,
1365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 BiggestInt actual) {
1366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return CmpHelperEQ(expected_expression, actual_expression, expected,
1367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       actual);
1368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This specialization is used when the first argument to ASSERT_EQ()
1372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is a null pointer literal, like NULL, false, or 0.
1373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass EqHelper<true> {
1375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We define two overloaded versions of Compare().  The first
1377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // version will be picked when the second argument to ASSERT_EQ() is
1378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
1379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // EXPECT_EQ(false, a_bool).
1380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  template <typename T1, typename T2>
1381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static AssertionResult Compare(
1382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* expected_expression,
1383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* actual_expression,
1384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const T1& expected,
1385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const T2& actual,
1386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // The following line prevents this overload from being considered if T2
1387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
1388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // expands to Compare("", "", NULL, my_ptr), which requires a conversion
1389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // to match the Secret* in the other overload, which would otherwise make
1390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // this template match better.
1391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
1392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return CmpHelperEQ(expected_expression, actual_expression, expected,
1393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       actual);
1394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // This version will be picked when the second argument to ASSERT_EQ() is a
1397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
1398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  template <typename T>
1399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static AssertionResult Compare(
1400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* expected_expression,
1401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const char* actual_expression,
1402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // We used to have a second template parameter instead of Secret*.  That
1403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // template parameter would deduce to 'long', making this a better match
1404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // than the first overload even without the first overload's EnableIf.
1405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
1406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // non-pointer argument" (even a deduced integral argument), so the old
1407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      // implementation caused warnings in user code.
1408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      Secret* /* expected (NULL) */,
1409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      T* actual) {
1410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // We already know that 'expected' is a null pointer.
1411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return CmpHelperEQ(expected_expression, actual_expression,
1412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       static_cast<T*>(NULL), actual);
1413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A macro for implementing the helper functions needed to implement
1417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
1418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// of similar code.
1419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For each templatized helper function, we also define an overloaded
1421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// version for BiggestInt in order to reduce code bloat and allow
1422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
1423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// with gcc 4.
1424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T1, typename T2>\
1428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   const T1& val1, const T2& val2) {\
1430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (val1 op val2) {\
1431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return AssertionSuccess();\
1432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  } else {\
1433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return AssertionFailure() \
1434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        << "Expected: (" << expr1 << ") " #op " (" << expr2\
1435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }\
1438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}\
1439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelper##op_name(\
1440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
1441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements the helper function for {ASSERT|EXPECT}_NE
1445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_IMPL_CMP_HELPER_(NE, !=);
1446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements the helper function for {ASSERT|EXPECT}_LE
1447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_IMPL_CMP_HELPER_(LE, <=);
1448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements the helper function for {ASSERT|EXPECT}_LT
1449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_IMPL_CMP_HELPER_(LT, < );
1450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements the helper function for {ASSERT|EXPECT}_GE
1451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_IMPL_CMP_HELPER_(GE, >=);
1452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Implements the helper function for {ASSERT|EXPECT}_GT
1453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_IMPL_CMP_HELPER_(GT, > );
1454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#undef GTEST_IMPL_CMP_HELPER_
1456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper function for {ASSERT|EXPECT}_STREQ.
1458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* actual_expression,
1462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* expected,
1463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* actual);
1464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
1469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* actual_expression,
1470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* expected,
1471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* actual);
1472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper function for {ASSERT|EXPECT}_STRNE.
1474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* s2_expression,
1478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* s1,
1479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* s2);
1480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The helper function for {ASSERT|EXPECT}_STRCASENE.
1482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* s2_expression,
1486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* s1,
1487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                              const char* s2);
1488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helper function for *_STREQ on wide strings.
1491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* actual_expression,
1495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const wchar_t* expected,
1496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const wchar_t* actual);
1497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helper function for *_STRNE on wide strings.
1499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const char* s2_expression,
1503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const wchar_t* s1,
1504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                          const wchar_t* s2);
1505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace internal
1507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// IsSubstring() and IsNotSubstring() are intended to be used as the
1509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
1510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// themselves.  They check whether needle is a substring of haystack
1511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// (NULL is considered a substring of itself only), and return an
1512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// appropriate error message when they fail.
1513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The {needle,haystack}_expr arguments are the stringified
1515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// expressions that generated the two real arguments.
1516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsSubstring(
1517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle, const char* haystack);
1519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsSubstring(
1520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const wchar_t* needle, const wchar_t* haystack);
1522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsNotSubstring(
1523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle, const char* haystack);
1525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsNotSubstring(
1526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const wchar_t* needle, const wchar_t* haystack);
1528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsSubstring(
1529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const ::std::string& needle, const ::std::string& haystack);
1531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsNotSubstring(
1532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const ::std::string& needle, const ::std::string& haystack);
1534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_STD_WSTRING
1536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsSubstring(
1537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const ::std::wstring& needle, const ::std::wstring& haystack);
1539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult IsNotSubstring(
1540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char* needle_expr, const char* haystack_expr,
1541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const ::std::wstring& needle, const ::std::wstring& haystack);
1542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_STD_WSTRING
1543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace internal {
1545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helper template function for comparing floating-points.
1547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Template parameter:
1549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   RawType: the raw floating-point type (either float or double)
1551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename RawType>
1554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgAssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
1555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                         const char* actual_expression,
1556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                         RawType expected,
1557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                         RawType actual) {
1558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const FloatingPoint<RawType> lhs(expected), rhs(actual);
1559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (lhs.AlmostEquals(rhs)) {
1561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return AssertionSuccess();
1562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ::std::stringstream expected_ss;
1565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org              << expected;
1567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ::std::stringstream actual_ss;
1569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            << actual;
1571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return EqFailure(expected_expression,
1573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   actual_expression,
1574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   StringStreamToString(&expected_ss),
1575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   StringStreamToString(&actual_ss),
1576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   false);
1577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Helper function for implementing ASSERT_NEAR.
1580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
1583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                const char* expr2,
1584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                const char* abs_error_expr,
1585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                double val1,
1586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                double val2,
1587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                                double abs_error);
1588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A class that enables one to stream messages to assertion macros
1591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass GTEST_API_ AssertHelper {
1592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Constructor.
1594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  AssertHelper(TestPartResult::Type type,
1595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               const char* file,
1596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               int line,
1597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               const char* message);
1598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ~AssertHelper();
1599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Message assignment is a semantic trick to enable assertion
1601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // streaming; see the GTEST_MESSAGE_ macro below.
1602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  void operator=(const Message& message) const;
1603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // We put our data in a struct so that the size of the AssertHelper class can
1606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // be as small as possible.  This is important because gcc is incapable of
1607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // re-using stack space even for temporary variables, so every EXPECT_EQ
1608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // reserves stack space for another AssertHelper.
1609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  struct AssertHelperData {
1610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    AssertHelperData(TestPartResult::Type t,
1611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                     const char* srcfile,
1612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                     int line_num,
1613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                     const char* msg)
1614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        : type(t), file(srcfile), line(line_num), message(msg) { }
1615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    TestPartResult::Type const type;
1617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char*        const file;
1618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    int                const line;
1619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    String             const message;
1620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   private:
1622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
1623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  };
1624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  AssertHelperData* const data_;
1626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
1628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace internal
1631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_HAS_PARAM_TEST
1633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The pure interface class that all value-parameterized tests inherit from.
1634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A value-parameterized class must inherit from both ::testing::Test and
1635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ::testing::WithParamInterface. In most cases that just means inheriting
1636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// from ::testing::TestWithParam, but more complicated test hierarchies
1637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// may need to inherit from Test and WithParamInterface at different levels.
1638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// This interface has support for accessing the test parameter value via
1640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the GetParam() method.
1641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use it with one of the parameter generator defining functions, like Range(),
1643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Values(), ValuesIn(), Bool(), and Combine().
1644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// class FooTest : public ::testing::TestWithParam<int> {
1646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//  protected:
1647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   FooTest() {
1648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     // Can use GetParam() here.
1649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
1650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   virtual ~FooTest() {
1651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     // Can use GetParam() here.
1652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
1653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   virtual void SetUp() {
1654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     // Can use GetParam() here.
1655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
1656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   virtual void TearDown {
1657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     // Can use GetParam() here.
1658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
1659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// };
1660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// TEST_P(FooTest, DoesBar) {
1661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   // Can use GetParam() method here.
1662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Foo foo;
1663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ASSERT_TRUE(foo.DoesBar(GetParam()));
1664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// }
1665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass WithParamInterface {
1669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public:
1670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  typedef T ParamType;
1671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  virtual ~WithParamInterface() {}
1672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The current parameter value. Is also available in the test fixture's
1674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // constructor. This member function is non-static, even though it only
1675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // references static data, to reduce the opportunity for incorrect uses
1676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
1677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // uses a fixture whose parameter type is int.
1678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  const ParamType& GetParam() const { return *parameter_; }
1679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org private:
1681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Sets parameter value. The caller is responsible for making sure the value
1682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // remains alive and unchanged throughout the current test.
1683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static void SetParam(const ParamType* parameter) {
1684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    parameter_ = parameter;
1685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
1686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // Static value used for accessing parameter during a test lifetime.
1688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  static const ParamType* parameter_;
1689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // TestClass must be a subclass of WithParamInterface<T> and Test.
1691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  template <class TestClass> friend class internal::ParameterizedTestFactory;
1692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst T* WithParamInterface<T>::parameter_ = NULL;
1696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Most value-parameterized classes can ignore the existence of
1698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// WithParamInterface, and can just inherit from ::testing::TestWithParam.
1699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass TestWithParam : public Test, public WithParamInterface<T> {
1702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_HAS_PARAM_TEST
1705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for indicating success/failure in test code.
1707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ADD_FAILURE unconditionally adds a failure to the current test.
1709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// SUCCEED generates a success - it doesn't automatically make the
1710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// current test successful, as a test is only successful when it has
1711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// no failure.
1712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// EXPECT_* verifies that a certain condition is satisfied.  If not,
1714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// it behaves like ADD_FAILURE.  In particular:
1715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_TRUE  verifies that a Boolean condition is true.
1717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_FALSE verifies that a Boolean condition is false.
1718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
1720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// that they will also abort the current function on failure.  People
1721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
1722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// writing data-driven tests often find themselves using ADD_FAILURE
1723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// and EXPECT_* more.
1724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Examples:
1726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_TRUE(server.StatusIsOK());
1728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ASSERT_FALSE(server.HasPendingRequest(port))
1729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//       << "There are still pending requests " << "on port " << port;
1730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Generates a nonfatal failure with a generic message.
1732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
1733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Generates a nonfatal failure at the given source file location with
1735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// a generic message.
1736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ADD_FAILURE_AT(file, line) \
1737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_MESSAGE_AT_(file, line, "Failed", \
1738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                    ::testing::TestPartResult::kNonFatalFailure)
1739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Generates a fatal failure with a generic message.
1741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
1742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Define this macro to 1 to omit the definition of FAIL(), which is a
1744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// generic name and clashes with some other libraries.
1745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_FAIL
1746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define FAIL() GTEST_FAIL()
1747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Generates a success with a generic message.
1750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
1751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Define this macro to 1 to omit the definition of SUCCEED(), which
1753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is a generic name and clashes with some other libraries.
1754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_SUCCEED
1755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define SUCCEED() GTEST_SUCCEED()
1756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for testing exceptions.
1759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
1761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that the statement throws the expected exception.
1762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_NO_THROW(statement):
1763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that the statement doesn't throw any exception.
1764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_ANY_THROW(statement):
1765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that the statement throws an exception.
1766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_THROW(statement, expected_exception) \
1768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
1769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_NO_THROW(statement) \
1770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_ANY_THROW(statement) \
1772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_THROW(statement, expected_exception) \
1774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
1775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_NO_THROW(statement) \
1776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
1777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_ANY_THROW(statement) \
1778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
1779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Boolean assertions. Condition can be either a Boolean expression or an
1781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// AssertionResult. For more information on how to use AssertionResult with
1782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// these macros see comments on that class.
1783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_TRUE(condition) \
1784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      GTEST_NONFATAL_FAILURE_)
1786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_FALSE(condition) \
1787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      GTEST_NONFATAL_FAILURE_)
1789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_TRUE(condition) \
1790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      GTEST_FATAL_FAILURE_)
1792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_FALSE(condition) \
1793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      GTEST_FATAL_FAILURE_)
1795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Includes the auto-generated header that implements a family of
1797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// generic predicate assertion macros.
1798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gtest/gtest_pred_impl.h"
1799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for testing equalities and inequalities.
1801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
1803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_NE(v1, v2):           Tests that v1 != v2
1804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_LT(v1, v2):           Tests that v1 < v2
1805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_LE(v1, v2):           Tests that v1 <= v2
1806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_GT(v1, v2):           Tests that v1 > v2
1807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_GE(v1, v2):           Tests that v1 >= v2
1808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When they are not, Google Test prints both the tested expressions and
1810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// their actual values.  The values must be compatible built-in types,
1811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// or you will get a compiler error.  By "compatible" we mean that the
1812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// values can be compared by the respective operator.
1813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Note:
1815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   1. It is possible to make a user-defined type work with
1817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   {ASSERT|EXPECT}_??(), but that requires overloading the
1818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   comparison operators and is thus discouraged by the Google C++
1819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   Usage Guide.  Therefore, you are advised to use the
1820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
1821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   equal.
1822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
1824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   pointers (in particular, C strings).  Therefore, if you use it
1825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   with two C strings, you are testing how their locations in memory
1826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   are related, not how their content is related.  To compare two C
1827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   strings by content, use {ASSERT|EXPECT}_STR*().
1828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
1830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
1831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   what the actual value is when it fails, and similarly for the
1832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   other comparisons.
1833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
1835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   evaluate their arguments, which is undefined.
1836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   5. These macros evaluate their arguments exactly once.
1838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Examples:
1840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_NE(5, Foo());
1842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_EQ(NULL, a_pointer);
1843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ASSERT_LT(i, array_size);
1844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ASSERT_GT(records.size(), 0) << "There is no record left.";
1845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_EQ(expected, actual) \
1847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal:: \
1848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
1849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_NE(expected, actual) \
1851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
1852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_LE(val1, val2) \
1853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_LT(val1, val2) \
1855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
1856f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_GE(val1, val2) \
1857f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
1858f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_GT(val1, val2) \
1859f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
1860f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1861f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_EQ(expected, actual) \
1862f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal:: \
1863f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
1864f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1865f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_NE(val1, val2) \
1866f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
1867f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_LE(val1, val2) \
1868f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1869f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_LT(val1, val2) \
1870f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
1871f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_GE(val1, val2) \
1872f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
1873f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_ASSERT_GT(val1, val2) \
1874f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
1875f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1876f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
1877f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ASSERT_XY(), which clashes with some users' own code.
1878f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1879f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_EQ
1880f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
1881f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1882f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1883f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_NE
1884f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
1885f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1886f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1887f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_LE
1888f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
1889f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1890f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1891f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_LT
1892f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
1893f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1894f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1895f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_GE
1896f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
1897f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1898f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1899f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_ASSERT_GT
1900f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
1901f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1902f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1903f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// C String Comparisons.  All tests treat NULL and any non-NULL string
1904f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// as different.  Two NULLs are equal.
1905f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1906f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
1907f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
1908f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
1909f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
1910f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1911f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// For wide or narrow string objects, you can use the
1912f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// {ASSERT|EXPECT}_??() macros.
1913f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1914f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Don't depend on the order in which the arguments are evaluated,
1915f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// which is undefined.
1916f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1917f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// These macros evaluate their arguments exactly once.
1918f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1919f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_STREQ(expected, actual) \
1920f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
1921f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_STRNE(s1, s2) \
1922f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
1923f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_STRCASEEQ(expected, actual) \
1924f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
1925f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_STRCASENE(s1, s2)\
1926f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
1927f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1928f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_STREQ(expected, actual) \
1929f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
1930f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_STRNE(s1, s2) \
1931f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
1932f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_STRCASEEQ(expected, actual) \
1933f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
1934f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_STRCASENE(s1, s2)\
1935f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
1936f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1937f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros for comparing floating-point numbers.
1938f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1939f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
1940f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that two float values are almost equal.
1941f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
1942f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that two double values are almost equal.
1943f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
1944f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//         Tests that v1 and v2 are within the given distance to each other.
1945f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1946f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Google Test uses ULP-based comparison to automatically pick a default
1947f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// error bound that is appropriate for the operands.  See the
1948f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// FloatingPoint template class in gtest-internal.h if you are
1949f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// interested in the implementation details.
1950f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1951f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_FLOAT_EQ(expected, actual)\
1952f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
1953f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1954f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1955f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_DOUBLE_EQ(expected, actual)\
1956f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
1957f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1958f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1959f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_FLOAT_EQ(expected, actual)\
1960f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
1961f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1962f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1963f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_DOUBLE_EQ(expected, actual)\
1964f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
1965f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      expected, actual)
1966f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1967f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_NEAR(val1, val2, abs_error)\
1968f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
1969f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      val1, val2, abs_error)
1970f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1971f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_NEAR(val1, val2, abs_error)\
1972f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
1973f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      val1, val2, abs_error)
1974f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1975f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// These predicate format functions work on floating-point values, and
1976f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
1977f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1978f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
1979f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1980f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Asserts that val1 is less than, or almost equal to, val2.  Fails
1981f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// otherwise.  In particular, it fails if either val1 or val2 is NaN.
1982f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
1983f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   float val1, float val2);
1984f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
1985f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    double val1, double val2);
1986f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1987f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1988f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if GTEST_OS_WINDOWS
1989f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1990f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros that test for HRESULT failure and success, these are only useful
1991f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// on Windows, and rely on Windows SDK macros and APIs to compile.
1992f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1993f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
1994f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
1995f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When expr unexpectedly fails or succeeds, Google Test prints the
1996f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// expected result and the actual result with both a human-readable
1997f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// string representation of the error, if available, as well as the
1998f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// hex result code.
1999f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define EXPECT_HRESULT_SUCCEEDED(expr) \
2000f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2001f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2002f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_HRESULT_SUCCEEDED(expr) \
2003f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2004f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2005f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define EXPECT_HRESULT_FAILED(expr) \
2006f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2007f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2008f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ASSERT_HRESULT_FAILED(expr) \
2009f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2010f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2011f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_OS_WINDOWS
2012f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2013f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Macros that execute statement and check that it doesn't generate new fatal
2014f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// failures in the current thread.
2015f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2016f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2017f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2018f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Examples:
2019f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2020f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   EXPECT_NO_FATAL_FAILURE(Process());
2021f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2022f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2023f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define ASSERT_NO_FATAL_FAILURE(statement) \
2024f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
2025f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EXPECT_NO_FATAL_FAILURE(statement) \
2026f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
2027f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2028f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Causes a trace (including the source file path, the current line
2029f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// number, and the given message) to be included in every test failure
2030f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// message generated by code in the current scope.  The effect is
2031f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// undone when the control leaves the current scope.
2032f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2033f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The message argument can be anything streamable to std::ostream.
2034f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2035f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// In the implementation, we include the current line number as part
2036f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
2037f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to appear in the same block - as long as they are on different
2038f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// lines.
2039f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define SCOPED_TRACE(message) \
2040f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
2041f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    __FILE__, __LINE__, ::testing::Message() << (message))
2042f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2043f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Compile-time assertion for type equality.
2044f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
2045f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the same type.  The value it returns is not interesting.
2046f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2047f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Instead of making StaticAssertTypeEq a class template, we make it a
2048f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// function template that invokes a helper class template.  This
2049f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
2050f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// defining objects of that type.
2051f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2052f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// CAVEAT:
2053f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2054f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// When used inside a method of a class template,
2055f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
2056f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// instantiated.  For example, given:
2057f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2058f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   template <typename T> class Foo {
2059f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    public:
2060f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
2061f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   };
2062f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2063f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the code:
2064f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2065f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   void Test1() { Foo<bool> foo; }
2066f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2067f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// will NOT generate a compiler error, as Foo<bool>::Bar() is never
2068f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// actually instantiated.  Instead, you need:
2069f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2070f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   void Test2() { Foo<bool> foo; foo.Bar(); }
2071f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2072f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// to cause a compiler error.
2073f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T1, typename T2>
2074f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgbool StaticAssertTypeEq() {
2075f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  (void)internal::StaticAssertTypeEqHelper<T1, T2>();
2076f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return true;
2077f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
2078f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2079f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines a test.
2080f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2081f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The first parameter is the name of the test case, and the second
2082f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// parameter is the name of the test within the test case.
2083f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2084f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The convention is to end the test case name with "Test".  For
2085f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// example, a test case for the Foo class can be named FooTest.
2086f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2087f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The user should put his test code between braces after using this
2088f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// macro.  Example:
2089f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2090f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TEST(FooTest, InitializesCorrectly) {
2091f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Foo foo;
2092f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     EXPECT_TRUE(foo.StatusIsOK());
2093f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
2094f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2095f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Note that we call GetTestTypeId() instead of GetTypeId<
2096f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ::testing::Test>() here to get the type ID of testing::Test.  This
2097f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is to work around a suspected linker bug when using Google Test as
2098f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// a framework on Mac OS X.  The bug causes GetTypeId<
2099f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// ::testing::Test>() to return different values depending on whether
2100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// the call is from the Google Test framework itself or from user test
2101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// code.  GetTestTypeId() is guaranteed to always return the same
2102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// value, as it always calls GetTypeId<>() from the Google Test
2103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// framework.
2104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GTEST_TEST(test_case_name, test_name)\
2105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_(test_case_name, test_name, \
2106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org              ::testing::Test, ::testing::internal::GetTestTypeId())
2107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Define this macro to 1 to omit the definition of TEST(), which
2109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// is a generic name and clashes with some other libraries.
2110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !GTEST_DONT_DEFINE_TEST
2111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
2112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
2113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Defines a test that uses a test fixture.
2115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// The first parameter is the name of the test fixture class, which
2117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// also doubles as the test case name.  The second parameter is the
2118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// name of the test within the test case.
2119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// A test fixture class must be declared earlier.  The user should put
2121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// his test code between braces after using this macro.  Example:
2122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   class FooTest : public testing::Test {
2124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//    protected:
2125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     virtual void SetUp() { b_.AddElement(3); }
2126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Foo a_;
2128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     Foo b_;
2129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   };
2130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TEST_F(FooTest, InitializesCorrectly) {
2132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     EXPECT_TRUE(a_.StatusIsOK());
2133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
2134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   TEST_F(FooTest, ReturnsElementCountCorrectly) {
2136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     EXPECT_EQ(0, a_.size());
2137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//     EXPECT_EQ(1, b_.size());
2138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//   }
2139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define TEST_F(test_fixture, test_name)\
2141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  GTEST_TEST_(test_fixture, test_name, test_fixture, \
2142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org              ::testing::internal::GetTypeId<test_fixture>())
2143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use this macro in main() to run all tests.  It returns 0 if all
2145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// tests are successful, or 1 otherwise.
2146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
2147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// RUN_ALL_TESTS() should be invoked after the command line has been
2148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// parsed by InitGoogleTest().
2149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RUN_ALL_TESTS()\
2151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  (::testing::UnitTest::GetInstance()->Run())
2152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}  // namespace testing
2154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif  // GTEST_INCLUDE_GTEST_GTEST_H_
2156