14b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Copyright 2005, Google Inc.
24b6829f0d28990dd645e16386eb226d0f10c8731shiqian// All rights reserved.
34b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
44b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Redistribution and use in source and binary forms, with or without
54b6829f0d28990dd645e16386eb226d0f10c8731shiqian// modification, are permitted provided that the following conditions are
64b6829f0d28990dd645e16386eb226d0f10c8731shiqian// met:
74b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
84b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     * Redistributions of source code must retain the above copyright
94b6829f0d28990dd645e16386eb226d0f10c8731shiqian// notice, this list of conditions and the following disclaimer.
104b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     * Redistributions in binary form must reproduce the above
114b6829f0d28990dd645e16386eb226d0f10c8731shiqian// copyright notice, this list of conditions and the following disclaimer
124b6829f0d28990dd645e16386eb226d0f10c8731shiqian// in the documentation and/or other materials provided with the
134b6829f0d28990dd645e16386eb226d0f10c8731shiqian// distribution.
144b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     * Neither the name of Google Inc. nor the names of its
154b6829f0d28990dd645e16386eb226d0f10c8731shiqian// contributors may be used to endorse or promote products derived from
164b6829f0d28990dd645e16386eb226d0f10c8731shiqian// this software without specific prior written permission.
174b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
184b6829f0d28990dd645e16386eb226d0f10c8731shiqian// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
194b6829f0d28990dd645e16386eb226d0f10c8731shiqian// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
204b6829f0d28990dd645e16386eb226d0f10c8731shiqian// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
214b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
224b6829f0d28990dd645e16386eb226d0f10c8731shiqian// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
234b6829f0d28990dd645e16386eb226d0f10c8731shiqian// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
244b6829f0d28990dd645e16386eb226d0f10c8731shiqian// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
254b6829f0d28990dd645e16386eb226d0f10c8731shiqian// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
264b6829f0d28990dd645e16386eb226d0f10c8731shiqian// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
274b6829f0d28990dd645e16386eb226d0f10c8731shiqian// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
284b6829f0d28990dd645e16386eb226d0f10c8731shiqian// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
294b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
304b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Author: wan@google.com (Zhanyong Wan)
314b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
324b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The Google C++ Testing Framework (Google Test)
334b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
344b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This header file defines the public API for Google Test.  It should be
354b6829f0d28990dd645e16386eb226d0f10c8731shiqian// included by any test program that uses Google Test.
364b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
374b6829f0d28990dd645e16386eb226d0f10c8731shiqian// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// leave some internal implementation details in this header file.
394b6829f0d28990dd645e16386eb226d0f10c8731shiqian// They are clearly marked by comments like this:
404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
414b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
424b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
434b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Such code is NOT meant to be used by a user directly, and is subject
444b6829f0d28990dd645e16386eb226d0f10c8731shiqian// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
454b6829f0d28990dd645e16386eb226d0f10c8731shiqian// program!
464b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
474b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Acknowledgment: Google Test borrowed the idea of automatic test
484b6829f0d28990dd645e16386eb226d0f10c8731shiqian// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
494b6829f0d28990dd645e16386eb226d0f10c8731shiqian// easyUnit framework.
504b6829f0d28990dd645e16386eb226d0f10c8731shiqian
514b6829f0d28990dd645e16386eb226d0f10c8731shiqian#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
524b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define GTEST_INCLUDE_GTEST_GTEST_H_
534b6829f0d28990dd645e16386eb226d0f10c8731shiqian
54e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian#include <limits>
5593fed47dbf8e6bc3d39d3f769cb5039551747257vladlosev#include <ostream>
5693d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan#include <vector>
5793d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan
582620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/internal/gtest-internal.h"
592620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/internal/gtest-string.h"
602620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-death-test.h"
612620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-message.h"
622620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-param-test.h"
632620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-printers.h"
642620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest_prod.h"
652620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-test-part.h"
662620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest-typed-test.h"
674b6829f0d28990dd645e16386eb226d0f10c8731shiqian
684b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Depending on the platform, different string classes are available.
6947ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// On Linux, in addition to ::std::string, Google also makes use of
7047ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// class ::string, which has the same interface as ::std::string, but
7147ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// has a different implementation.
7247ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan//
732f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
7447ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// ::string is available AND is a distinct type to ::std::string, or
7547ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// define it to 0 to indicate otherwise.
764b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
772f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// If ::std::string and ::string are the same class on your platform
782f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
794b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
802f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
8147ff745210c71ba79033fb69a7f832aa18b87977zhanyong.wan// heuristically.
824b6829f0d28990dd645e16386eb226d0f10c8731shiqian
834b6829f0d28990dd645e16386eb226d0f10c8731shiqiannamespace testing {
844b6829f0d28990dd645e16386eb226d0f10c8731shiqian
850ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// Declares the flags.
864b6829f0d28990dd645e16386eb226d0f10c8731shiqian
870ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// This flag temporary enables the disabled tests.
880ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_bool_(also_run_disabled_tests);
890ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
900ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// This flag brings the debugger on an assertion failure.
910ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_bool_(break_on_failure);
920ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
93b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flag controls whether Google Test catches all test-thrown exceptions
94b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// and logs them as failures.
950ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_bool_(catch_exceptions);
960ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
97b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flag enables using colors in terminal output. Available values are
98b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
990ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// to let Google Test decide.
1000ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_string_(color);
1010ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
102b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flag sets up the filter to select by name using a glob pattern
1030ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// the tests to run. If the filter is not given all tests are executed.
1040ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_string_(filter);
1050ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
106b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flag causes the Google Test to list tests. None of the tests listed
1070ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// are actually run if the flag is provided.
1080ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_bool_(list_tests);
1090ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
1100ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// This flag controls whether Google Test emits a detailed XML report to a file
1110ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// in addition to its normal textual output.
1120ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_string_(output);
1130ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
114b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flags control whether Google Test prints the elapsed time for each
1150ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// test.
1160ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_bool_(print_time);
1170ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
1189b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan// This flag specifies the random number seed.
1199b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wanGTEST_DECLARE_int32_(random_seed);
1209b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan
121b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// This flag sets how many times the tests are repeated. The default value
1220ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// is 1. If the value is -1 the tests are repeating forever.
1230ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_int32_(repeat);
1244b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1254b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This flag controls whether Google Test includes Google Test internal
1264b6829f0d28990dd645e16386eb226d0f10c8731shiqian// stack frames in failure stack traces.
127e44602ec83c65102035ce5304ae8de0cb16e9e56shiqianGTEST_DECLARE_bool_(show_internal_stack_frames);
1284b6829f0d28990dd645e16386eb226d0f10c8731shiqian
129f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan// When this flag is specified, tests' order is randomized on every iteration.
1309b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wanGTEST_DECLARE_bool_(shuffle);
1319b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan
1320ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// This flag specifies the maximum number of stack frames to be
1330ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// printed in a failure message.
1340ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanGTEST_DECLARE_int32_(stack_trace_depth);
1350ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
136b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// When this flag is specified, a failed assertion will throw an
137b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// exception if exceptions are enabled, or exit the program with a
138b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan// non-zero code otherwise.
139b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wanGTEST_DECLARE_bool_(throw_on_failure);
140b0fe69fcbfaa44ae05f6f2429d9c4bbb326b5ea5zhanyong.wan
141c95489ee7dd54fc6a2cd1d3e890c330718ead714zhanyong.wan// When this flag is set with a "host:port" string, on supported
142c95489ee7dd54fc6a2cd1d3e890c330718ead714zhanyong.wan// platforms test results are streamed to the specified port on
143c95489ee7dd54fc6a2cd1d3e890c330718ead714zhanyong.wan// the specified host machine.
144c95489ee7dd54fc6a2cd1d3e890c330718ead714zhanyong.wanGTEST_DECLARE_string_(stream_result_to);
145c95489ee7dd54fc6a2cd1d3e890c330718ead714zhanyong.wan
1460ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan// The upper limit for valid stack trace depths.
1470ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wanconst int kMaxStackTraceDepth = 100;
1480ebc16a68eea644a9f8a718fbdef95112a4a0ff2zhanyong.wan
1494b6829f0d28990dd645e16386eb226d0f10c8731shiqiannamespace internal {
1504b6829f0d28990dd645e16386eb226d0f10c8731shiqian
151a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wanclass AssertHelper;
152b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wanclass DefaultGlobalTestPartResultReporter;
153b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wanclass ExecDeathTest;
154f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wanclass NoExecDeathTest;
1551cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wanclass FinalSuccessChecker;
1564b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass GTestFlagSaver;
157a032cfff4091c87a137a8d24ce2eb97c740cf4c8kosak@google.comclass StreamingListenerTest;
1581cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wanclass TestResultAccessor;
159f6d087b78d230d875bf5d8281112662795044680zhanyong.wanclass TestEventListenersAccessor;
1607dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wanclass TestEventRepeater;
161dfbdf0bab51520595679a99710983daba6fc18ebvladlosevclass UnitTestRecordPropertyTestHelper;
1621cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wanclass WindowsDeathTest;
163a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wanclass UnitTestImpl* GetUnitTestImpl();
164334aaead71ccf797a18f2128c320f0304e724860zhanyong.wanvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
16503c314931649a999b0cf5deb0a434a1009157416jgm@google.com                                    const std::string& message);
1664b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1674b6829f0d28990dd645e16386eb226d0f10c8731shiqian}  // namespace internal
1684b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1695d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wan// The friend relationship of some of these classes is cyclic.
1705d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wan// If we don't forward declare them the compiler might confuse the classes
1715d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wan// in friendship clauses with same named classes on the scope.
1725d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wanclass Test;
1735d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wanclass TestCase;
1745d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wanclass TestInfo;
1755d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wanclass UnitTest;
1765d0c3dc09ece41c649deea59f975d0ff5548424azhanyong.wan
1774b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A class for indicating whether an assertion was successful.  When
1784b6829f0d28990dd645e16386eb226d0f10c8731shiqian// the assertion wasn't successful, the AssertionResult object
179fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// remembers a non-empty message that describes how it failed.
1804b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
181fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// To create an instance of this class, use one of the factory functions
1824b6829f0d28990dd645e16386eb226d0f10c8731shiqian// (AssertionSuccess() and AssertionFailure()).
1834b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
184fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// This class is useful for two purposes:
185fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   1. Defining predicate functions to be used with Boolean test assertions
186fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
187fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   2. Defining predicate-format functions to be
188fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
189fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
190fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// For example, if you define IsEven predicate:
191fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
192fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   testing::AssertionResult IsEven(int n) {
193fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     if ((n % 2) == 0)
194fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionSuccess();
195fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     else
196fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionFailure() << n << " is odd";
197fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   }
198fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
199fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
200fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// will print the message
201fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
202fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Value of: IsEven(Fib(5))
203fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     Actual: false (5 is odd)
204fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Expected: true
205fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
206fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// instead of a more opaque
207fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
208fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Value of: IsEven(Fib(5))
209fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     Actual: false
210fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Expected: true
211fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
212fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// in case IsEven is a simple Boolean predicate.
213fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
214fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// If you expect your predicate to be reused and want to support informative
215fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
216fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// about half as often as positive ones in our tests), supply messages for
217fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// both success and failure cases:
218fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
219fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   testing::AssertionResult IsEven(int n) {
220fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     if ((n % 2) == 0)
221fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionSuccess() << n << " is even";
222fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     else
223fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionFailure() << n << " is odd";
224fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   }
225fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
226fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
227fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
228fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Value of: IsEven(Fib(6))
229fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     Actual: true (8 is even)
230fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//   Expected: false
231fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
232fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// NB: Predicates that support negative Boolean assertions have reduced
233fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// performance in positive ones so be careful not to use them in tests
234fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// that have lots (tens of thousands) of positive Boolean assertions.
235fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
236fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// To use this class with EXPECT_PRED_FORMAT assertions such as:
2374b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
2384b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   // Verifies that Foo() returns an even number.
2394b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_PRED_FORMAT1(IsEven, Foo());
2404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
241fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// you need to define:
2424b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
2434b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   testing::AssertionResult IsEven(const char* expr, int n) {
244fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     if ((n % 2) == 0)
245fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionSuccess();
246fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//     else
247fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//       return testing::AssertionFailure()
248fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
2494b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   }
2504b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
2514b6829f0d28990dd645e16386eb226d0f10c8731shiqian// If Foo() returns 5, you will see the following message:
2524b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
2534b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Expected: Foo() is even
2544b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     Actual: it's 5
255fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev//
256e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ AssertionResult {
2574b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
258fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Copy constructor.
259fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Used in EXPECT_TRUE/FALSE(assertion_result).
260fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  AssertionResult(const AssertionResult& other);
261f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com
262f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
263f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com
264fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Used in the EXPECT_TRUE/FALSE(bool_expression).
265f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  //
266f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // T must be contextually convertible to bool.
267f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  //
268f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // The second parameter prevents this overload from being considered if
269f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // the argument is implicitly convertible to AssertionResult. In that case
270f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // we want AssertionResult's copy constructor to be used.
271f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  template <typename T>
272f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  explicit AssertionResult(
273f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com      const T& success,
274f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com      typename internal::EnableIf<
275f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com          !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
276f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com          /*enabler*/ = NULL)
277f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com      : success_(success) {}
278f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com
279f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  GTEST_DISABLE_MSC_WARNINGS_POP_()
280f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com
281f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // Assignment operator.
282f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  AssertionResult& operator=(AssertionResult other) {
283f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com    swap(other);
284f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com    return *this;
285f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  }
2864b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2874b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns true iff the assertion succeeded.
288fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  operator bool() const { return success_; }  // NOLINT
289fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev
290fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
291fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  AssertionResult operator!() const;
292fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev
293fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Returns the text streamed into this AssertionResult. Test assertions
294fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // use it when they fail (i.e., the predicate's outcome doesn't match the
295fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // assertion's expectation). When nothing has been streamed into the
296fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // object, returns an empty string.
297fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  const char* message() const {
2981287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    return message_.get() != NULL ?  message_->c_str() : "";
299fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  }
300fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // TODO(vladl@google.com): Remove this after making sure no clients use it.
301fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Deprecated; please use message() instead.
302fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  const char* failure_message() const { return message(); }
3034b6829f0d28990dd645e16386eb226d0f10c8731shiqian
304fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Streams a custom failure message into this object.
3051287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  template <typename T> AssertionResult& operator<<(const T& value) {
3061287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    AppendMessage(Message() << value);
3071287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    return *this;
3081287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  }
3091287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev
3101287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  // Allows streaming basic output manipulators such as endl or flush into
3111287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  // this object.
3121287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  AssertionResult& operator<<(
3131287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
3141287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    AppendMessage(Message() << basic_manipulator);
3151287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    return *this;
3161287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  }
3174b6829f0d28990dd645e16386eb226d0f10c8731shiqian
3184b6829f0d28990dd645e16386eb226d0f10c8731shiqian private:
3191287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  // Appends the contents of message to message_.
3201287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  void AppendMessage(const Message& a_message) {
3211287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    if (message_.get() == NULL)
3221287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev      message_.reset(new ::std::string);
3231287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev    message_->append(a_message.GetString().c_str());
3241287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  }
325fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev
326f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  // Swap the contents of this AssertionResult with other.
327f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com  void swap(AssertionResult& other);
328f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com
329fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Stores result of the assertion predicate.
330fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  bool success_;
331fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Stores the message describing the condition in case the expectation
332fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // construct is not satisfied with the predicate's outcome.
333fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // Referenced via a pointer to avoid taking too much stack frame space
334fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev  // with test assertions.
3351287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev  internal::scoped_ptr< ::std::string> message_;
3361287840af7b9efca823ad2fecb6d905f2c4a3acevladlosev};
3374b6829f0d28990dd645e16386eb226d0f10c8731shiqian
3384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Makes a successful assertion result.
339e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult AssertionSuccess();
3404b6829f0d28990dd645e16386eb226d0f10c8731shiqian
341fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// Makes a failed assertion result.
342e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult AssertionFailure();
343fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev
3444b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Makes a failed assertion result with the given failure message.
345fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// Deprecated; use AssertionFailure() << msg.
346e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
3474b6829f0d28990dd645e16386eb226d0f10c8731shiqian
3484b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The abstract class that all tests inherit from.
3494b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3504b6829f0d28990dd645e16386eb226d0f10c8731shiqian// In Google Test, a unit test program contains one or many TestCases, and
3514b6829f0d28990dd645e16386eb226d0f10c8731shiqian// each TestCase contains one or many Tests.
3524b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3534b6829f0d28990dd645e16386eb226d0f10c8731shiqian// When you define a test using the TEST macro, you don't need to
3544b6829f0d28990dd645e16386eb226d0f10c8731shiqian// explicitly derive from Test - the TEST macro automatically does
3554b6829f0d28990dd645e16386eb226d0f10c8731shiqian// this for you.
3564b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3574b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The only time you derive from Test is when defining a test fixture
3584b6829f0d28990dd645e16386eb226d0f10c8731shiqian// to be used a TEST_F.  For example:
3594b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3604b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   class FooTest : public testing::Test {
3614b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    protected:
3624b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     virtual void SetUp() { ... }
3634b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     virtual void TearDown() { ... }
3644b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     ...
3654b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   };
3664b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3674b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   TEST_F(FooTest, Bar) { ... }
3684b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   TEST_F(FooTest, Baz) { ... }
3694b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
3704b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Test is not copyable.
371e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ Test {
3724b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
373739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  friend class TestInfo;
3744b6829f0d28990dd645e16386eb226d0f10c8731shiqian
3754b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Defines types for pointers to functions that set up and tear down
3764b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // a test case.
377e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
378e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
3794b6829f0d28990dd645e16386eb226d0f10c8731shiqian
3804b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // The d'tor is virtual as we intend to inherit from Test.
3814b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual ~Test();
3824b6829f0d28990dd645e16386eb226d0f10c8731shiqian
383e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // Sets up the stuff shared by all tests in this test case.
384e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  //
385e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // Google Test will call Foo::SetUpTestCase() before running the first
386e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // test in test case Foo.  Hence a sub-class can define its own
387e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // SetUpTestCase() method to shadow the one defined in the super
388e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // class.
389e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  static void SetUpTestCase() {}
390e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
391e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // Tears down the stuff shared by all tests in this test case.
392e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  //
393e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // Google Test will call Foo::TearDownTestCase() after running the last
394e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // test in test case Foo.  Hence a sub-class can define its own
395e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // TearDownTestCase() method to shadow the one defined in the super
396e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  // class.
397e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  static void TearDownTestCase() {}
398e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
3994b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns true iff the current test has a fatal failure.
4004b6829f0d28990dd645e16386eb226d0f10c8731shiqian  static bool HasFatalFailure();
4014b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4021b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan  // Returns true iff the current test has a non-fatal failure.
4031b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan  static bool HasNonfatalFailure();
4041b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan
4051b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan  // Returns true iff the current test has a (either fatal or
4061b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan  // non-fatal) failure.
4071b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
4081b171100b3341c01fb377f8202d9eaccbeec1f55zhanyong.wan
409dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Logs a property for the current test, test case, or for the entire
410dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // invocation of the test program when used outside of the context of a
411dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // test case.  Only the last value for a given key is remembered.  These
412dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // are public static so they can be called from utility functions that are
413dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // not members of the test fixture.  Calls to RecordProperty made during
414dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // lifespan of the test (from the moment its constructor starts to the
415dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // moment its destructor finishes) will be output in XML as attributes of
416dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // the <testcase> element.  Properties recorded from fixture's
417dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // SetUpTestCase or TearDownTestCase are logged as attributes of the
418dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // corresponding <testsuite> element.  Calls to RecordProperty made in the
419dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // global context (before or after invocation of RUN_ALL_TESTS and from
420dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // SetUp/TearDown method of Environment objects registered with Google
421dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Test) will be output as attributes of the <testsuites> element.
422dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  static void RecordProperty(const std::string& key, const std::string& value);
423dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  static void RecordProperty(const std::string& key, int value);
4244b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4254b6829f0d28990dd645e16386eb226d0f10c8731shiqian protected:
4264b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Creates a Test object.
4274b6829f0d28990dd645e16386eb226d0f10c8731shiqian  Test();
4284b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4294b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Sets up the test fixture.
4304b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual void SetUp();
4314b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4324b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Tears down the test fixture.
4334b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual void TearDown();
4344b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4354b6829f0d28990dd645e16386eb226d0f10c8731shiqian private:
4364b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns true iff the current test has the same fixture class as
4374b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // the first test in the current test case.
4384b6829f0d28990dd645e16386eb226d0f10c8731shiqian  static bool HasSameFixtureClass();
4394b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4404b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Runs the test after the test fixture has been set up.
4414b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4424b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // A sub-class must implement this to define the test logic.
4434b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4444b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
4454b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Instead, use the TEST or TEST_F macro.
4464b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual void TestBody() = 0;
4474b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4484b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Sets up, executes, and tears down the test.
4494b6829f0d28990dd645e16386eb226d0f10c8731shiqian  void Run();
4504b6829f0d28990dd645e16386eb226d0f10c8731shiqian
451739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // Deletes self.  We deliberately pick an unusual name for this
452739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // internal method to avoid clashing with names used in user TESTs.
453739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  void DeleteSelf_() { delete this; }
454739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
4554b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Uses a GTestFlagSaver to save and restore all Google Test flags.
4564b6829f0d28990dd645e16386eb226d0f10c8731shiqian  const internal::GTestFlagSaver* const gtest_flag_saver_;
4574b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4582f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com  // Often a user misspells SetUp() as Setup() and spends a long time
4594b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // wondering why it is never called by Google Test.  The declaration of
4604b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // the following method is solely for catching such an error at
4614b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // compile time:
4624b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4634b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //   - The return type is deliberately chosen to be not void, so it
4642f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com  //   will be a conflict if void Setup() is declared in the user's
4652f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com  //   test fixture.
4664b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4674b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //   - This method is private, so it will be another compiler error
4682f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com  //   if the method is called from the user's test fixture.
4694b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4704b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // DO NOT OVERRIDE THIS FUNCTION.
4714b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
4724b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // If you see an error about overriding the following function or
4734b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // about it being private, you have mis-spelled SetUp() as Setup().
4744b6829f0d28990dd645e16386eb226d0f10c8731shiqian  struct Setup_should_be_spelled_SetUp {};
4754b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
4764b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4774b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // We disallow copying Tests.
478e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
4794b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
4804b6829f0d28990dd645e16386eb226d0f10c8731shiqian
4811cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wantypedef internal::TimeInMillis TimeInMillis;
4821cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan
4834e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan// A copyable object representing a user specified test property which can be
4844e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan// output as a key/value string pair.
4854e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan//
4864e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan// Don't inherit from TestProperty as its destructor is not virtual.
4874e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wanclass TestProperty {
4884e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan public:
4894e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // C'tor.  TestProperty does NOT have a default constructor.
4904e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // Always use this constructor (with parameters) to create a
4914e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // TestProperty object.
492dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  TestProperty(const std::string& a_key, const std::string& a_value) :
4937de3401f5f8c2a61476a3623e9802f973764fc27zhanyong.wan    key_(a_key), value_(a_value) {
4944e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  }
4954e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan
4964e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // Gets the user supplied key.
4974e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  const char* key() const {
4984e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan    return key_.c_str();
4994e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  }
5004e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan
5014e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // Gets the user supplied value.
5024e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  const char* value() const {
5034e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan    return value_.c_str();
5044e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  }
5054e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan
5064e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // Sets a new value, overriding the one supplied in the constructor.
507dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  void SetValue(const std::string& new_value) {
5084e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan    value_ = new_value;
5094e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  }
5104e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan
5114e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan private:
5124e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // The key supplied by the user.
51303c314931649a999b0cf5deb0a434a1009157416jgm@google.com  std::string key_;
5144e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan  // The value supplied by the user.
51503c314931649a999b0cf5deb0a434a1009157416jgm@google.com  std::string value_;
5164e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan};
5174e7e2fcd7ac837bf81d8f120a9a30785d83b3897zhanyong.wan
518535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan// The result of a single Test.  This includes a list of
519535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan// TestPartResults, a list of TestProperties, a count of how many
520535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan// death tests there are in the Test, and how much time it took to run
521535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan// the Test.
522535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan//
523535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan// TestResult is not copyable.
524e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ TestResult {
525535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan public:
526535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Creates an empty TestResult.
527535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  TestResult();
528535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
529535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // D'tor.  Do not inherit from TestResult.
530535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  ~TestResult();
531535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
532535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Gets the number of all test parts.  This is the sum of the number
533535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // of successful test parts and the number of failed test parts.
534535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  int total_part_count() const;
535535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
5369644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns the number of the test properties.
5379644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int test_property_count() const;
5389644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
539535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns true iff the test passed (i.e. no test part failed).
540535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  bool Passed() const { return !Failed(); }
541535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
542535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns true iff the test failed.
5431cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  bool Failed() const;
544535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
545535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns true iff the test fatally failed.
546535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  bool HasFatalFailure() const;
547535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
548535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns true iff the test has a non-fatal failure.
549535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  bool HasNonfatalFailure() const;
550535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
551535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns the elapsed time, in milliseconds.
552535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  TimeInMillis elapsed_time() const { return elapsed_time_; }
553535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
5549644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns the i-th test part result among all the results. i can range
555449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  // from 0 to test_property_count() - 1. If i is not in that range, aborts
556449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  // the program.
557449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  const TestPartResult& GetTestPartResult(int i) const;
5589644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
5599644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns the i-th test property. i can range from 0 to
560449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  // test_property_count() - 1. If i is not in that range, aborts the
561449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  // program.
562449f84de9b0c48289e20f63c6d08a39bcee2021bzhanyong.wan  const TestProperty& GetTestProperty(int i) const;
5639644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
564b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan private:
565fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class TestInfo;
566dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  friend class TestCase;
567fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class UnitTest;
5681cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::DefaultGlobalTestPartResultReporter;
5691cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::ExecDeathTest;
5701cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::TestResultAccessor;
5711cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::UnitTestImpl;
5721cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::WindowsDeathTest;
573b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
574a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // Gets the vector of TestPartResults.
57593d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  const std::vector<TestPartResult>& test_part_results() const {
57693d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan    return test_part_results_;
577b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  }
578b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
579a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // Gets the vector of TestProperties.
58093d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  const std::vector<TestProperty>& test_properties() const {
58193d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan    return test_properties_;
582b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  }
583b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
584b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  // Sets the elapsed time.
585b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
586535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
587535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Adds a test property to the list. The property is validated and may add
588535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
589535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // key names). If a property is already recorded for the same key, the
590535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // value will be updated, rather than storing multiple values for the same
591dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // key.  xml_element specifies the element for which the property is being
592dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // recorded and is used for validation.
593dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  void RecordProperty(const std::string& xml_element,
594dfbdf0bab51520595679a99710983daba6fc18ebvladlosev                      const TestProperty& test_property);
595535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
596535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Adds a failure if the key is a reserved attribute of Google Test
597535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // testcase tags.  Returns true if the property is valid.
598535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // TODO(russr): Validate attribute names are legal and human readable.
599dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  static bool ValidateTestProperty(const std::string& xml_element,
600dfbdf0bab51520595679a99710983daba6fc18ebvladlosev                                   const TestProperty& test_property);
601535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
602b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  // Adds a test part result to the list.
603b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  void AddTestPartResult(const TestPartResult& test_part_result);
604b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
605535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Returns the death test count.
606535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  int death_test_count() const { return death_test_count_; }
607535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
608535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Increments the death test count, returning the new count.
609535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  int increment_death_test_count() { return ++death_test_count_; }
610535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
611535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Clears the test part results.
612535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  void ClearTestPartResults();
613535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
614535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Clears the object.
615535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  void Clear();
616b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
617a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // Protects mutable state of the property vector and of owned
618a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // properties, whose values may be updated.
619535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  internal::Mutex test_properites_mutex_;
620535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
621a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // The vector of TestPartResults
62293d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  std::vector<TestPartResult> test_part_results_;
623a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // The vector of TestProperties
62493d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  std::vector<TestProperty> test_properties_;
625535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // Running count of death tests.
626535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  int death_test_count_;
627535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // The elapsed time, in milliseconds.
628535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  TimeInMillis elapsed_time_;
629535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
630535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  // We disallow copying TestResult.
631535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
632535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan};  // class TestResult
633535de1065311cc5e95e84811dc05f513393fa940zhanyong.wan
6344b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A TestInfo object stores the following information about a test:
6354b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
6364b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Test case name
6374b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Test name
6384b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Whether the test should be run
6394b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   A function pointer that creates the test object when invoked
6404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Test result
6414b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
6424b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The constructor of TestInfo registers itself with the UnitTest
6434b6829f0d28990dd645e16386eb226d0f10c8731shiqian// singleton such that the RUN_ALL_TESTS() macro knows which tests to
6444b6829f0d28990dd645e16386eb226d0f10c8731shiqian// run.
645e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ TestInfo {
6464b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
6474b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Destructs a TestInfo object.  This function is not virtual, so
6484b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // don't inherit from TestInfo.
6494b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ~TestInfo();
6504b6829f0d28990dd645e16386eb226d0f10c8731shiqian
6514b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns the test case name.
652739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const char* test_case_name() const { return test_case_name_.c_str(); }
6534b6829f0d28990dd645e16386eb226d0f10c8731shiqian
6544b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns the test name.
655739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const char* name() const { return name_.c_str(); }
6564b6829f0d28990dd645e16386eb226d0f10c8731shiqian
657a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Returns the name of the parameter type, or NULL if this is not a typed
658a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // or a type-parameterized test.
659a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const char* type_param() const {
660a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    if (type_param_.get() != NULL)
661a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan      return type_param_->c_str();
662a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    return NULL;
663a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  }
664e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
665a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Returns the text representation of the value parameter, or NULL if this
666a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // is not a value-parameterized test.
667a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const char* value_param() const {
668a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    if (value_param_.get() != NULL)
669a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan      return value_param_->c_str();
670a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    return NULL;
671a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  }
672e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
673c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Returns true if this test should run, that is if the test is not
674c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // disabled (or it is disabled but the also_run_disabled_tests flag has
675c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // been specified) and its full name matches the user-specified filter.
6764b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
6774b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Google Test allows the user to filter the tests by their full names.
6784b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // The full name of a test Bar in test case Foo is defined as
6794b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // "Foo.Bar".  Only the tests that match the filter will run.
6804b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
6814b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // A filter is a colon-separated list of glob (not regex) patterns,
6824b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // optionally followed by a '-' and a colon-separated list of
6834b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // negative patterns (tests to exclude).  A test is run if it
6844b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // matches one of the positive patterns and does not match any of
6854b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // the negative patterns.
6864b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
6874b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // For example, *A*:Foo.* is a filter that matches any string that
6884b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // contains the character 'A' or starts with "Foo.".
689739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  bool should_run() const { return should_run_; }
6904b6829f0d28990dd645e16386eb226d0f10c8731shiqian
691c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Returns true iff this test will appear in the XML report.
692c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  bool is_reportable() const {
693c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    // For now, the XML report includes all tests matching the filter.
694c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    // In the future, we may trim tests that are excluded because of
695c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    // sharding.
696c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    return matches_filter_;
697c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  }
698c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
6994b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns the result of the test.
700739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const TestResult* result() const { return &result_; }
701b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
7024b6829f0d28990dd645e16386eb226d0f10c8731shiqian private:
7034cd62602913a032a7aec091d4c8055ff9af95e37zhanyong.wan#if GTEST_HAS_DEATH_TEST
7044b6829f0d28990dd645e16386eb226d0f10c8731shiqian  friend class internal::DefaultDeathTestFactory;
7054b6829f0d28990dd645e16386eb226d0f10c8731shiqian#endif  // GTEST_HAS_DEATH_TEST
706fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class Test;
707fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class TestCase;
7084b6829f0d28990dd645e16386eb226d0f10c8731shiqian  friend class internal::UnitTestImpl;
709a032cfff4091c87a137a8d24ce2eb97c740cf4c8kosak@google.com  friend class internal::StreamingListenerTest;
710e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian  friend TestInfo* internal::MakeAndRegisterTestInfo(
7113b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com      const char* test_case_name,
7123b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com      const char* name,
713a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan      const char* type_param,
714a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan      const char* value_param,
715e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian      internal::TypeId fixture_class_id,
716e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian      Test::SetUpTestCaseFunc set_up_tc,
717e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian      Test::TearDownTestCaseFunc tear_down_tc,
718e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian      internal::TestFactoryBase* factory);
7194b6829f0d28990dd645e16386eb226d0f10c8731shiqian
7204834581321d60c17997d65a2360c7674f15f9bbcshiqian  // Constructs a TestInfo object. The newly constructed instance assumes
7214834581321d60c17997d65a2360c7674f15f9bbcshiqian  // ownership of the factory object.
7223b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com  TestInfo(const std::string& test_case_name,
7233b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com           const std::string& name,
7243b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com           const char* a_type_param,   // NULL if not a type-parameterized test
7253b8388d9490a64a47ed8cbdab2021935b1b2c76ckosak@google.com           const char* a_value_param,  // NULL if not a value-parameterized test
7264834581321d60c17997d65a2360c7674f15f9bbcshiqian           internal::TypeId fixture_class_id,
7274834581321d60c17997d65a2360c7674f15f9bbcshiqian           internal::TestFactoryBase* factory);
7284b6829f0d28990dd645e16386eb226d0f10c8731shiqian
729739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // Increments the number of death tests encountered in this test so
730739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // far.
731739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  int increment_death_test_count() {
732739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    return result_.increment_death_test_count();
733739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
734739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
735739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // Creates the test object, runs it, records its result, and then
736739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // deletes it.
737739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  void Run();
738739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
739739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  static void ClearTestResult(TestInfo* test_info) {
740739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    test_info->result_.Clear();
741739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
742739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
743739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // These fields are immutable properties of the test.
744739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const std::string test_case_name_;     // Test case name
745739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const std::string name_;               // Test name
746a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Name of the parameter type, or NULL if this is not a typed or a
747a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // type-parameterized test.
748a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const internal::scoped_ptr<const ::std::string> type_param_;
749a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Text representation of the value parameter, or NULL if this is not a
750a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // value-parameterized test.
751a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const internal::scoped_ptr<const ::std::string> value_param_;
752739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
753739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  bool should_run_;                 // True iff this test should run
754739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  bool is_disabled_;                // True iff this test is disabled
755739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  bool matches_filter_;             // True if this test matches the
756739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan                                    // user-specified filter.
757739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  internal::TestFactoryBase* const factory_;  // The factory that creates
758739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan                                              // the test object
759739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
760739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // This field is mutable and needs to be reset before running the
761739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // test for the second time.
762739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  TestResult result_;
7634b6829f0d28990dd645e16386eb226d0f10c8731shiqian
764e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
7654b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
7664b6829f0d28990dd645e16386eb226d0f10c8731shiqian
767a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan// A test case, which consists of a vector of TestInfos.
768b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan//
769b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan// TestCase is not copyable.
770e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ TestCase {
771b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan public:
772b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Creates a TestCase with the given name.
773b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //
774b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // TestCase does NOT have a default constructor.  Always use this
775b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // constructor to create a TestCase object.
776b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //
777b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Arguments:
778b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //
779b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //   name:         name of the test case
780a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  //   a_type_param: the name of the test's type parameter, or NULL if
781a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  //                 this is not a type-parameterized test.
782b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //   set_up_tc:    pointer to the function that sets up the test case
783b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  //   tear_down_tc: pointer to the function that tears down the test case
784a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  TestCase(const char* name, const char* a_type_param,
785b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan           Test::SetUpTestCaseFunc set_up_tc,
786b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan           Test::TearDownTestCaseFunc tear_down_tc);
787b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
788b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Destructor of TestCase.
789b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  virtual ~TestCase();
790b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
791b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Gets the name of the TestCase.
792b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  const char* name() const { return name_.c_str(); }
793b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
794a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Returns the name of the parameter type, or NULL if this is not a
795a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // type-parameterized test case.
796a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const char* type_param() const {
797a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    if (type_param_.get() != NULL)
798a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan      return type_param_->c_str();
799a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan    return NULL;
800a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  }
801b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
802b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true if any test in this test case should run.
803b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  bool should_run() const { return should_run_; }
804b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
805b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Gets the number of successful tests in this test case.
806b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  int successful_test_count() const;
807b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
808b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Gets the number of failed tests in this test case.
809b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  int failed_test_count() const;
810b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
811c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Gets the number of disabled tests that will be reported in the XML report.
812c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  int reportable_disabled_test_count() const;
813c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
814b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Gets the number of disabled tests in this test case.
815b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  int disabled_test_count() const;
816b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
817c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Gets the number of tests to be printed in the XML report.
818c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  int reportable_test_count() const;
819c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
820b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Get the number of tests in this test case that should run.
821b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  int test_to_run_count() const;
822b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
823b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Gets the number of all tests in this test case.
824b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  int total_test_count() const;
825b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
826b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true iff the test case passed.
827b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  bool Passed() const { return !Failed(); }
828b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
829b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true iff the test case failed.
830b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  bool Failed() const { return failed_test_count() > 0; }
831b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
832b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns the elapsed time, in milliseconds.
8331cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  TimeInMillis elapsed_time() const { return elapsed_time_; }
834b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
8359644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns the i-th test among all the tests. i can range from 0 to
8369644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // total_test_count() - 1. If i is not in that range, returns NULL.
8379644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  const TestInfo* GetTestInfo(int i) const;
8389644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
839dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Returns the TestResult that holds test properties recorded during
840dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // execution of SetUpTestCase and TearDownTestCase.
841dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
842dfbdf0bab51520595679a99710983daba6fc18ebvladlosev
843b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan private:
844fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class Test;
8451cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  friend class internal::UnitTestImpl;
846b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
847a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // Gets the (mutable) vector of TestInfos in this TestCase.
84893d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
849b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
850a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan  // Gets the (immutable) vector of TestInfos in this TestCase.
85193d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  const std::vector<TestInfo*>& test_info_list() const {
85293d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan    return test_info_list_;
853b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  }
854b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
855f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // Returns the i-th test among all the tests. i can range from 0 to
856f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // total_test_count() - 1. If i is not in that range, returns NULL.
857f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  TestInfo* GetMutableTestInfo(int i);
858f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan
859b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  // Sets the should_run member.
860b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan  void set_should_run(bool should) { should_run_ = should; }
861b7ec0f7b3b21338babc9a6ab5a593a40634a8062zhanyong.wan
862b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
863b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // destruction of the TestCase object.
864b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  void AddTestInfo(TestInfo * test_info);
865b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
866b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Clears the results of all tests in this test case.
867b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  void ClearResult();
868b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
869b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Clears the results of all tests in the given test case.
870b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  static void ClearTestCaseResult(TestCase* test_case) {
871b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan    test_case->ClearResult();
872b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  }
873b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
874b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Runs every test in this TestCase.
875b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  void Run();
876b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
877739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
878739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // for catching exceptions thrown from SetUpTestCase().
879739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  void RunSetUpTestCase() { (*set_up_tc_)(); }
880739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
881739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // Runs TearDownTestCase() for this TestCase.  This wrapper is
882739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  // needed for catching exceptions thrown from TearDownTestCase().
883739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  void RunTearDownTestCase() { (*tear_down_tc_)(); }
884739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan
885b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true iff test passed.
886739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  static bool TestPassed(const TestInfo* test_info) {
887739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    return test_info->should_run() && test_info->result()->Passed();
888739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
889b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
890b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true iff test failed.
891739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  static bool TestFailed(const TestInfo* test_info) {
892739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    return test_info->should_run() && test_info->result()->Failed();
893739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
894b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
895c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Returns true iff the test is disabled and will be reported in the XML
896c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // report.
897c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  static bool TestReportableDisabled(const TestInfo* test_info) {
898c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    return test_info->is_reportable() && test_info->is_disabled_;
899c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  }
900c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
901b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true iff test is disabled.
902739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  static bool TestDisabled(const TestInfo* test_info) {
903739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    return test_info->is_disabled_;
904739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
905b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
906c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Returns true iff this test will appear in the XML report.
907c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  static bool TestReportable(const TestInfo* test_info) {
908c567ac6c5431d9d2867ace1da1418f4575215516vladlosev    return test_info->is_reportable();
909c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  }
910c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
911b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Returns true if the given test should run.
912739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  static bool ShouldRunTest(const TestInfo* test_info) {
913739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan    return test_info->should_run();
914739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  }
915b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
916f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // Shuffles the tests in this test case.
917f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  void ShuffleTests(internal::Random* random);
918f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan
919f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // Restores the test order to before the first shuffle.
920f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  void UnshuffleTests();
921f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan
922b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Name of the test case.
92303c314931649a999b0cf5deb0a434a1009157416jgm@google.com  std::string name_;
924a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // Name of the parameter type, or NULL if this is not a typed or a
925a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  // type-parameterized test.
926a33163a3ddbb60a6c45340e436310f78044c1a7dzhanyong.wan  const internal::scoped_ptr<const ::std::string> type_param_;
927f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // The vector of TestInfos in their original order.  It owns the
928f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // elements in the vector.
92993d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  std::vector<TestInfo*> test_info_list_;
930f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // Provides a level of indirection for the test list to allow easy
931f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // shuffling and restoring the test order.  The i-th element in this
932f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // vector is the index of the i-th test in the shuffled test list.
93393d13a8bbcb70bfd80b0d7ae2bf9aedfc06bf0cczhanyong.wan  std::vector<int> test_indices_;
934b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Pointer to the function that sets up the test case.
935b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  Test::SetUpTestCaseFunc set_up_tc_;
936b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Pointer to the function that tears down the test case.
937b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  Test::TearDownTestCaseFunc tear_down_tc_;
938b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // True iff any test in this test case should run.
939b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  bool should_run_;
940b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // Elapsed time, in milliseconds.
9411cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  TimeInMillis elapsed_time_;
942dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Holds test properties recorded during execution of SetUpTestCase and
943dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // TearDownTestCase.
944dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  TestResult ad_hoc_test_result_;
945b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
946b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  // We disallow copying TestCases.
947b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
948b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan};
949b9a1628577f7ab2eb30a656aeff763909770c9c1zhanyong.wan
9504b6829f0d28990dd645e16386eb226d0f10c8731shiqian// An Environment object is capable of setting up and tearing down an
9512f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// environment.  You should subclass this to define your own
9524b6829f0d28990dd645e16386eb226d0f10c8731shiqian// environment(s).
9534b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
9544b6829f0d28990dd645e16386eb226d0f10c8731shiqian// An Environment object does the set-up and tear-down in virtual
9554b6829f0d28990dd645e16386eb226d0f10c8731shiqian// methods SetUp() and TearDown() instead of the constructor and the
9564b6829f0d28990dd645e16386eb226d0f10c8731shiqian// destructor, as:
9574b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
9584b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   1. You cannot safely throw from a destructor.  This is a problem
9594b6829f0d28990dd645e16386eb226d0f10c8731shiqian//      as in some cases Google Test is used where exceptions are enabled, and
9604b6829f0d28990dd645e16386eb226d0f10c8731shiqian//      we may want to implement ASSERT_* using exceptions where they are
9614b6829f0d28990dd645e16386eb226d0f10c8731shiqian//      available.
9624b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   2. You cannot use ASSERT_* directly in a constructor or
9634b6829f0d28990dd645e16386eb226d0f10c8731shiqian//      destructor.
9644b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass Environment {
9654b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
9664b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // The d'tor is virtual as we need to subclass Environment.
9674b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual ~Environment() {}
9684b6829f0d28990dd645e16386eb226d0f10c8731shiqian
9694b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Override this to define how to set up the environment.
9704b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual void SetUp() {}
9714b6829f0d28990dd645e16386eb226d0f10c8731shiqian
9724b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Override this to define how to tear down the environment.
9734b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual void TearDown() {}
9744b6829f0d28990dd645e16386eb226d0f10c8731shiqian private:
9754b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // If you see an error about overriding the following function or
9764b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // about it being private, you have mis-spelled SetUp() as Setup().
9774b6829f0d28990dd645e16386eb226d0f10c8731shiqian  struct Setup_should_be_spelled_SetUp {};
9784b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
9794b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
9804b6829f0d28990dd645e16386eb226d0f10c8731shiqian
981334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan// The interface for tracing execution of tests. The methods are organized in
982334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan// the order the corresponding events are fired.
983fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wanclass TestEventListener {
984f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan public:
985fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  virtual ~TestEventListener() {}
986f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
9877dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired before any test activity starts.
9887dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
989f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
9907dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired before each iteration of tests starts.  There may be more than
9917dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
9927dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // index, starting from 0.
9937dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestIterationStart(const UnitTest& unit_test,
9947dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan                                    int iteration) = 0;
9957dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan
9967dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired before environment set-up for each iteration of tests starts.
9977dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
998f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
9997dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired after environment set-up for each iteration of tests ends.
10007dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
1001f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
10027dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired before the test case starts.
10037dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
1004f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
10057dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired before the test starts.
1006f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  virtual void OnTestStart(const TestInfo& test_info) = 0;
1007f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1008e974309f2322ed19a0239e6247d806c156e00986vladlosev  // Fired after a failed assertion or a SUCCEED() invocation.
1009334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
1010334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan
10117dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  // Fired after the test ends.
1012f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  virtual void OnTestEnd(const TestInfo& test_info) = 0;
1013f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1014334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  // Fired after the test case ends.
1015334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
1016334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan
1017334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  // Fired before environment tear-down for each iteration of tests starts.
1018334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
1019334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan
1020334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  // Fired after environment tear-down for each iteration of tests ends.
1021334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
1022334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan
1023334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  // Fired after each iteration of tests finishes.
1024334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestIterationEnd(const UnitTest& unit_test,
1025334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan                                  int iteration) = 0;
1026334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan
1027334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  // Fired after all test activities have ended.
1028334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
1029f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan};
1030f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1031f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan// The convenience class for users who need to override just one or two
1032f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan// methods and are not concerned that a possible change to a signature of
1033fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan// the methods they override will not be caught during the build.  For
1034fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan// comments about each method please see the definition of TestEventListener
1035fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan// above.
1036fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wanclass EmptyTestEventListener : public TestEventListener {
1037f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan public:
10387dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
10397dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
10407dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan                                    int /*iteration*/) {}
10417dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
10427dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
1043f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
1044f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
10457dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
1046334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
1047334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
1048334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
1049334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
1050334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
1051334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan                                  int /*iteration*/) {}
1052334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
1053f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan};
1054f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1055f6d087b78d230d875bf5d8281112662795044680zhanyong.wan// TestEventListeners lets users add listeners to track events in Google Test.
1056e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ TestEventListeners {
1057f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan public:
1058f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  TestEventListeners();
1059f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  ~TestEventListeners();
1060f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1061f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Appends an event listener to the end of the list. Google Test assumes
1062f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // the ownership of the listener (i.e. it will delete the listener when
1063f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // the test program finishes).
1064fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  void Append(TestEventListener* listener);
1065f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1066f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Removes the given event listener from the list and returns it.  It then
1067f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // becomes the caller's responsibility to delete the listener. Returns
1068f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // NULL if the listener is not found in the list.
1069fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* Release(TestEventListener* listener);
1070f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1071f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Returns the standard listener responsible for the default console
1072f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // output.  Can be removed from the listeners list to shut down default
1073f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // console output.  Note that removing this object from the listener list
1074f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // with Release transfers its ownership to the caller and makes this
1075f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // function return NULL the next time.
1076fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* default_result_printer() const {
1077f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan    return default_result_printer_;
1078f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  }
1079f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1080f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Returns the standard listener responsible for the default XML output
1081f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // controlled by the --gtest_output=xml flag.  Can be removed from the
1082f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // listeners list by users who want to shut down the default XML output
1083f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // controlled by this flag and substitute it with custom one.  Note that
1084f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // removing this object from the listener list with Release transfers its
1085f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // ownership to the caller and makes this function return NULL the next
1086f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // time.
1087fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* default_xml_generator() const {
1088f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan    return default_xml_generator_;
1089f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  }
1090f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1091f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan private:
1092fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class TestCase;
1093739d30448cd8477c7c8802d41d4e0d969a9490dezhanyong.wan  friend class TestInfo;
1094f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  friend class internal::DefaultGlobalTestPartResultReporter;
1095f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  friend class internal::NoExecDeathTest;
1096f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  friend class internal::TestEventListenersAccessor;
1097f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  friend class internal::UnitTestImpl;
1098f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1099fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // Returns repeater that broadcasts the TestEventListener events to all
1100fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // subscribers.
1101fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* repeater();
1102f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1103f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Sets the default_result_printer attribute to the provided listener.
1104f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // The listener is also added to the listener list and previous
1105f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // default_result_printer is removed from it and deleted. The listener can
1106f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // also be NULL in which case it will not be added to the list. Does
1107f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // nothing if the previous and the current listener objects are the same.
1108fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  void SetDefaultResultPrinter(TestEventListener* listener);
1109f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1110f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Sets the default_xml_generator attribute to the provided listener.  The
1111f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // listener is also added to the listener list and previous
1112f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // default_xml_generator is removed from it and deleted. The listener can
1113f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // also be NULL in which case it will not be added to the list. Does
1114f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // nothing if the previous and the current listener objects are the same.
1115fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  void SetDefaultXmlGenerator(TestEventListener* listener);
1116f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1117f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Controls whether events will be forwarded by the repeater to the
1118f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // listeners in the list.
1119f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  bool EventForwardingEnabled() const;
1120f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  void SuppressEventForwarding();
1121f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1122f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // The actual list of listeners.
11237dcfb6b7375177814c5154e9770efc5406778ad0zhanyong.wan  internal::TestEventRepeater* repeater_;
1124f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Listener responsible for the standard result output.
1125fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* default_result_printer_;
1126f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Listener responsible for the creation of the XML output file.
1127fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  TestEventListener* default_xml_generator_;
1128f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1129f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  // We disallow copying TestEventListeners.
1130f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
1131f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan};
1132f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1133a8a582fb926a678d1c4303384bd4dc872f746de8zhanyong.wan// A UnitTest consists of a vector of TestCases.
11344b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
11354b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This is a singleton class.  The only instance of UnitTest is
11364b6829f0d28990dd645e16386eb226d0f10c8731shiqian// created when UnitTest::GetInstance() is first called.  This
11374b6829f0d28990dd645e16386eb226d0f10c8731shiqian// instance is never deleted.
11384b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
11394b6829f0d28990dd645e16386eb226d0f10c8731shiqian// UnitTest is not copyable.
11404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
11414b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This class is thread-safe as long as the methods are called
11424b6829f0d28990dd645e16386eb226d0f10c8731shiqian// according to their specification.
1143e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ UnitTest {
11444b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
11454b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Gets the singleton UnitTest object.  The first time this method
11464b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // is called, a UnitTest object is constructed and returned.
11474b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Consecutive calls will return the same object.
11484b6829f0d28990dd645e16386eb226d0f10c8731shiqian  static UnitTest* GetInstance();
11494b6829f0d28990dd645e16386eb226d0f10c8731shiqian
11504b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Runs all tests in this UnitTest object and prints the result.
11514b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns 0 if successful, or 1 otherwise.
11524b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
11534b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // This method can only be called from the main thread.
11544b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
11554b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1156e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  int Run() GTEST_MUST_USE_RESULT_;
11574b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1158c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian  // Returns the working directory when the first TEST() or TEST_F()
1159c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian  // was executed.  The UnitTest object owns the string.
1160c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian  const char* original_working_dir() const;
1161c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian
11624b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns the TestCase object for the test that's currently running,
11634b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // or NULL if no test is running.
1164ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev  const TestCase* current_test_case() const
1165ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
11664b6829f0d28990dd645e16386eb226d0f10c8731shiqian
11674b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Returns the TestInfo object for the test that's currently running,
11684b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // or NULL if no test is running.
1169ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev  const TestInfo* current_test_info() const
1170ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
11714b6829f0d28990dd645e16386eb226d0f10c8731shiqian
11729b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan  // Returns the random seed used at the start of the current test run.
11739b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan  int random_seed() const;
11749b9794ffb9cfafb94f5def851f76b9a104fcb891zhanyong.wan
11754cd62602913a032a7aec091d4c8055ff9af95e37zhanyong.wan#if GTEST_HAS_PARAM_TEST
1176f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // Returns the ParameterizedTestCaseRegistry object used to keep track of
1177f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // value-parameterized tests and instantiate and register them.
1178a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan  //
1179a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1180ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev  internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
1181ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
1182f904a612d9444ab36c07a8e619c113432e046f49vladlosev#endif  // GTEST_HAS_PARAM_TEST
1183f904a612d9444ab36c07a8e619c113432e046f49vladlosev
11849644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of successful test cases.
11859644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int successful_test_case_count() const;
11869644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
11879644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of failed test cases.
11889644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int failed_test_case_count() const;
11899644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
11909644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of all test cases.
11919644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int total_test_case_count() const;
11929644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
11939644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of all test cases that contain at least one test
11949644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // that should run.
11959644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int test_case_to_run_count() const;
11969644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
11979644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of successful tests.
11989644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int successful_test_count() const;
11999644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12009644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of failed tests.
12019644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int failed_test_count() const;
12029644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
1203c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Gets the number of disabled tests that will be reported in the XML report.
1204c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  int reportable_disabled_test_count() const;
1205c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
12069644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of disabled tests.
12079644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int disabled_test_count() const;
12089644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
1209c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  // Gets the number of tests to be printed in the XML report.
1210c567ac6c5431d9d2867ace1da1418f4575215516vladlosev  int reportable_test_count() const;
1211c567ac6c5431d9d2867ace1da1418f4575215516vladlosev
12129644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of all tests.
12139644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int total_test_count() const;
12149644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12159644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the number of tests that should run.
12169644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  int test_to_run_count() const;
12179644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12188883b42f2a78976dde09f31ca72806072e33bd5fvladlosev  // Gets the time of the test program start, in ms from the start of the
12198883b42f2a78976dde09f31ca72806072e33bd5fvladlosev  // UNIX epoch.
12208883b42f2a78976dde09f31ca72806072e33bd5fvladlosev  TimeInMillis start_timestamp() const;
12218883b42f2a78976dde09f31ca72806072e33bd5fvladlosev
12229644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the elapsed time, in milliseconds.
12231cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan  TimeInMillis elapsed_time() const;
12249644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12259644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns true iff the unit test passed (i.e. all test cases passed).
12269644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  bool Passed() const;
12279644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12289644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Returns true iff the unit test failed (i.e. some test case failed
12299644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // or something outside of all tests failed).
12309644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  bool Failed() const;
12319644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
12329644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // Gets the i-th test case among all the test cases. i can range from 0 to
12339644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1234fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  const TestCase* GetTestCase(int i) const;
12359644db857432db95bc64f5d6db5867b1c7cf1679zhanyong.wan
1236dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Returns the TestResult containing information on test failures and
1237dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // properties logged outside of individual test cases.
1238dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  const TestResult& ad_hoc_test_result() const;
1239dfbdf0bab51520595679a99710983daba6fc18ebvladlosev
1240f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // Returns the list of event listeners that can be used to track events
1241f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // inside Google Test.
1242f6d087b78d230d875bf5d8281112662795044680zhanyong.wan  TestEventListeners& listeners();
1243f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1244fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan private:
1245fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // Registers and returns a global test environment.  When a test
1246fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // program is run, all global test environments will be set-up in
1247fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // the order they were registered.  After all tests in the program
1248fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // have finished, all global test environments will be torn-down in
1249fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // the *reverse* order they were registered.
1250fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  //
1251fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // The UnitTest object takes ownership of the given environment.
1252fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  //
1253fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // This method can only be called from the main thread.
1254fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  Environment* AddEnvironment(Environment* env);
1255fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan
1256fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // Adds a TestPartResult to the current TestResult object.  All
1257fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1258fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // eventually call this to report their results.  The user code
1259fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // should use the assertion macros instead of calling this directly.
1260fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  void AddTestPartResult(TestPartResult::Type result_type,
1261fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan                         const char* file_name,
1262fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan                         int line_number,
126303c314931649a999b0cf5deb0a434a1009157416jgm@google.com                         const std::string& message,
126403c314931649a999b0cf5deb0a434a1009157416jgm@google.com                         const std::string& os_stack_trace)
1265ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
1266fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan
1267dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // Adds a TestProperty to the current TestResult object when invoked from
1268dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
1269dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // from SetUpTestCase or TearDownTestCase, or to the global property set
1270dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // when invoked elsewhere.  If the result already contains a property with
1271dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  // the same key, the value will be updated.
1272dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  void RecordProperty(const std::string& key, const std::string& value);
1273fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan
1274f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // Gets the i-th test case among all the test cases. i can range from 0 to
1275f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  // total_test_case_count() - 1. If i is not in that range, returns NULL.
1276f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan  TestCase* GetMutableTestCase(int i);
1277f19450f3ad156e1dea624b4d37e645bef067ab5czhanyong.wan
1278fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // Accessors for the implementation object.
1279fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  internal::UnitTestImpl* impl() { return impl_; }
1280fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  const internal::UnitTestImpl* impl() const { return impl_; }
1281fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan
1282fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // These classes and funcions are friends as they need to access private
1283fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  // members of UnitTest.
1284fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class Test;
1285fff033497b70e96a5dcadb6ba9570c12b5921d74zhanyong.wan  friend class internal::AssertHelper;
12864b6829f0d28990dd645e16386eb226d0f10c8731shiqian  friend class internal::ScopedTrace;
1287a032cfff4091c87a137a8d24ce2eb97c740cf4c8kosak@google.com  friend class internal::StreamingListenerTest;
1288dfbdf0bab51520595679a99710983daba6fc18ebvladlosev  friend class internal::UnitTestRecordPropertyTestHelper;
1289a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan  friend Environment* AddGlobalTestEnvironment(Environment* env);
1290a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan  friend internal::UnitTestImpl* internal::GetUnitTestImpl();
1291a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan  friend void internal::ReportFailureInUnknownLocation(
1292334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan      TestPartResult::Type result_type,
129303c314931649a999b0cf5deb0a434a1009157416jgm@google.com      const std::string& message);
12944b6829f0d28990dd645e16386eb226d0f10c8731shiqian
12954b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Creates an empty UnitTest.
12964b6829f0d28990dd645e16386eb226d0f10c8731shiqian  UnitTest();
12974b6829f0d28990dd645e16386eb226d0f10c8731shiqian
12984b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // D'tor
12994b6829f0d28990dd645e16386eb226d0f10c8731shiqian  virtual ~UnitTest();
13004b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13014b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
13024b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Google Test trace stack.
1303ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev  void PushGTestTrace(const internal::TraceInfo& trace)
1304ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
13054b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13064b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Pops a trace from the per-thread Google Test trace stack.
1307ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev  void PopGTestTrace()
1308ee89af8d5f0578d9da31c5295f59f2d2bdebec39vladlosev      GTEST_LOCK_EXCLUDED_(mutex_);
13094b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13104b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Protects mutable state in *impl_.  This is mutable as some const
13114b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // methods need to lock it too.
13124b6829f0d28990dd645e16386eb226d0f10c8731shiqian  mutable internal::Mutex mutex_;
13134b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13144b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Opaque implementation object.  This field is never changed once
13154b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // the object is constructed.  We don't mark it as const here, as
13164b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // doing so will cause a warning in the constructor of UnitTest.
13174b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Mutable state in *impl_ is protected by mutex_.
13184b6829f0d28990dd645e16386eb226d0f10c8731shiqian  internal::UnitTestImpl* impl_;
13194b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13204b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // We disallow copying UnitTest.
1321e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
13224b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
13234b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13244b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A convenient wrapper for adding an environment for the test
13254b6829f0d28990dd645e16386eb226d0f10c8731shiqian// program.
13264b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
13274b6829f0d28990dd645e16386eb226d0f10c8731shiqian// You should call this before RUN_ALL_TESTS() is called, probably in
13284b6829f0d28990dd645e16386eb226d0f10c8731shiqian// main().  If you use gtest_main, you need to call this before main()
13294b6829f0d28990dd645e16386eb226d0f10c8731shiqian// starts for it to take effect.  For example, you can define a global
13304b6829f0d28990dd645e16386eb226d0f10c8731shiqian// variable like this:
13314b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
13324b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   testing::Environment* const foo_env =
13334b6829f0d28990dd645e16386eb226d0f10c8731shiqian//       testing::AddGlobalTestEnvironment(new FooEnvironment);
13344b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
13354b6829f0d28990dd645e16386eb226d0f10c8731shiqian// However, we strongly recommend you to write your own main() and
13364b6829f0d28990dd645e16386eb226d0f10c8731shiqian// call AddGlobalTestEnvironment() there, as relying on initialization
13374b6829f0d28990dd645e16386eb226d0f10c8731shiqian// of global variables makes the code harder to read and may cause
13384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// problems when you register multiple environments from different
13394b6829f0d28990dd645e16386eb226d0f10c8731shiqian// translation units and the environments have dependencies among them
13404b6829f0d28990dd645e16386eb226d0f10c8731shiqian// (remember that the compiler doesn't guarantee the order in which
13414b6829f0d28990dd645e16386eb226d0f10c8731shiqian// global variables from different translation units are initialized).
13424b6829f0d28990dd645e16386eb226d0f10c8731shiqianinline Environment* AddGlobalTestEnvironment(Environment* env) {
13434b6829f0d28990dd645e16386eb226d0f10c8731shiqian  return UnitTest::GetInstance()->AddEnvironment(env);
13444b6829f0d28990dd645e16386eb226d0f10c8731shiqian}
13454b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13464b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Initializes Google Test.  This must be called before calling
13474b6829f0d28990dd645e16386eb226d0f10c8731shiqian// RUN_ALL_TESTS().  In particular, it parses a command line for the
13484b6829f0d28990dd645e16386eb226d0f10c8731shiqian// flags that Google Test recognizes.  Whenever a Google Test flag is
13494b6829f0d28990dd645e16386eb226d0f10c8731shiqian// seen, it is removed from argv, and *argc is decremented.
13504b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
13514b6829f0d28990dd645e16386eb226d0f10c8731shiqian// No value is returned.  Instead, the Google Test flag variables are
13524b6829f0d28990dd645e16386eb226d0f10c8731shiqian// updated.
1353f179f4ee7cc76e7103a726ebf666902b07f89659vladlosev//
1354f179f4ee7cc76e7103a726ebf666902b07f89659vladlosev// Calling the function for the second time has no user-visible effect.
1355e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ void InitGoogleTest(int* argc, char** argv);
13564b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13574b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This overloaded version can be used in Windows programs compiled in
13584b6829f0d28990dd645e16386eb226d0f10c8731shiqian// UNICODE mode.
1359e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
13604b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13614b6829f0d28990dd645e16386eb226d0f10c8731shiqiannamespace internal {
13624b6829f0d28990dd645e16386eb226d0f10c8731shiqian
13636b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
13646b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// value of type ToPrint that is an operand of a comparison assertion
13656b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// (e.g. ASSERT_EQ).  OtherOperand is the type of the other operand in
13666b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// the comparison, and is used to help determine the best way to
13676b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// format the value.  In particular, when the value is a C string
13686b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// (char pointer) and the other operand is an STL string object, we
13696b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// want to format the C string as a string, since we know it is
13706b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// compared by value with the string object.  If the value is a char
13716b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// pointer but the other operand is not an STL string object, we don't
13726b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// know whether the pointer is supposed to point to a NUL-terminated
13736b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// string, and thus want to print it as a pointer to be safe.
13746b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan//
13756b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
13766b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
13776b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// The default case.
13786b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wantemplate <typename ToPrint, typename OtherOperand>
13796b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanclass FormatForComparison {
13806b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan public:
13816b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  static ::std::string Format(const ToPrint& value) {
13826b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    return ::testing::PrintToString(value);
13836b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  }
13846b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan};
13856b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
13866b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// Array.
13876b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wantemplate <typename ToPrint, size_t N, typename OtherOperand>
13886b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanclass FormatForComparison<ToPrint[N], OtherOperand> {
13896b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan public:
13906b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  static ::std::string Format(const ToPrint* value) {
13916b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
13926b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  }
13936b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan};
13946b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
13956b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// By default, print C string as pointers to be safe, as we don't know
13966b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// whether they actually point to a NUL-terminated string.
13976b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
13986b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType)                \
13996b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  template <typename OtherOperand>                                      \
14006b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  class FormatForComparison<CharType*, OtherOperand> {                  \
14016b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan   public:                                                              \
14026b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    static ::std::string Format(CharType* value) {                      \
14036b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan      return ::testing::PrintToString(static_cast<const void*>(value)); \
14046b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    }                                                                   \
14056b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  }
14066b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14076b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
14086b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
14096b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
14106b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
14116b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14126b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
14136b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14146b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// If a C string is compared with an STL string object, we know it's meant
14156b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// to point to a NUL-terminated string, and thus can print it as a string.
14166b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14176b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
14186b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  template <>                                                           \
14196b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  class FormatForComparison<CharType*, OtherStringType> {               \
14206b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan   public:                                                              \
14216b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    static ::std::string Format(CharType* value) {                      \
14226b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan      return ::testing::PrintToString(value);                           \
14236b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan    }                                                                   \
14246b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  }
14256b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14266b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
14276b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
14286b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14296b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#if GTEST_HAS_GLOBAL_STRING
14306b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
14316b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
14326b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#endif
14336b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14346b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#if GTEST_HAS_GLOBAL_WSTRING
14356b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
14366b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
14376b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#endif
14386b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14396b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#if GTEST_HAS_STD_WSTRING
14406b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
14416b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wanGTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
14426b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#endif
14436b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14446b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
14456b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan
14464b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
14474b6829f0d28990dd645e16386eb226d0f10c8731shiqian// operand to be used in a failure message.  The type (but not value)
14484b6829f0d28990dd645e16386eb226d0f10c8731shiqian// of the other operand may affect the format.  This allows us to
14494b6829f0d28990dd645e16386eb226d0f10c8731shiqian// print a char* as a raw pointer when it is compared against another
14506b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// char* or void*, and print it as a C string when it is compared
14516b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan// against an std::string object, for example.
14524b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
14534b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
14544b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <typename T1, typename T2>
145503c314931649a999b0cf5deb0a434a1009157416jgm@google.comstd::string FormatForComparisonFailureMessage(
145603c314931649a999b0cf5deb0a434a1009157416jgm@google.com    const T1& value, const T2& /* other_operand */) {
14576b625a794e8a0e314f3ccc2f6a892f4a40a7e788zhanyong.wan  return FormatForComparison<T1, T2>::Format(value);
14584b6829f0d28990dd645e16386eb226d0f10c8731shiqian}
14594b6829f0d28990dd645e16386eb226d0f10c8731shiqian
14604b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper function for {ASSERT|EXPECT}_EQ.
14614b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <typename T1, typename T2>
14624b6829f0d28990dd645e16386eb226d0f10c8731shiqianAssertionResult CmpHelperEQ(const char* expected_expression,
14634b6829f0d28990dd645e16386eb226d0f10c8731shiqian                            const char* actual_expression,
14644b6829f0d28990dd645e16386eb226d0f10c8731shiqian                            const T1& expected,
14654b6829f0d28990dd645e16386eb226d0f10c8731shiqian                            const T2& actual) {
1466f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.comGTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
14674b6829f0d28990dd645e16386eb226d0f10c8731shiqian  if (expected == actual) {
14684b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return AssertionSuccess();
14694b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
1470f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.comGTEST_DISABLE_MSC_WARNINGS_POP_()
1471b0a12f719caf4e37894868334ce41b1864b0be53zhanyong.wan
14724b6829f0d28990dd645e16386eb226d0f10c8731shiqian  return EqFailure(expected_expression,
14734b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   actual_expression,
14744b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   FormatForComparisonFailureMessage(expected, actual),
14754b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   FormatForComparisonFailureMessage(actual, expected),
14764b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   false);
14774b6829f0d28990dd645e16386eb226d0f10c8731shiqian}
14784b6829f0d28990dd645e16386eb226d0f10c8731shiqian
14794b6829f0d28990dd645e16386eb226d0f10c8731shiqian// With this overloaded version, we allow anonymous enums to be used
14804b6829f0d28990dd645e16386eb226d0f10c8731shiqian// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
14814b6829f0d28990dd645e16386eb226d0f10c8731shiqian// can be implicitly cast to BiggestInt.
14821ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
14831ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wan                                       const char* actual_expression,
14841ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wan                                       BiggestInt expected,
14851ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wan                                       BiggestInt actual);
14864b6829f0d28990dd645e16386eb226d0f10c8731shiqian
14874b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper class for {ASSERT|EXPECT}_EQ.  The template argument
14884b6829f0d28990dd645e16386eb226d0f10c8731shiqian// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
14894b6829f0d28990dd645e16386eb226d0f10c8731shiqian// is a null pointer literal.  The following default implementation is
14904b6829f0d28990dd645e16386eb226d0f10c8731shiqian// for lhs_is_null_literal being false.
14914b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <bool lhs_is_null_literal>
14924b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass EqHelper {
14934b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
14944b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // This templatized version is for the general case.
14954b6829f0d28990dd645e16386eb226d0f10c8731shiqian  template <typename T1, typename T2>
14964b6829f0d28990dd645e16386eb226d0f10c8731shiqian  static AssertionResult Compare(const char* expected_expression,
14974b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 const char* actual_expression,
14984b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 const T1& expected,
14994b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 const T2& actual) {
15004b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return CmpHelperEQ(expected_expression, actual_expression, expected,
15014b6829f0d28990dd645e16386eb226d0f10c8731shiqian                       actual);
15024b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
15034b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15044b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // With this overloaded version, we allow anonymous enums to be used
15054b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
15064b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // enums can be implicitly cast to BiggestInt.
15074b6829f0d28990dd645e16386eb226d0f10c8731shiqian  //
15084b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Even though its body looks the same as the above version, we
15094b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // cannot merge the two, as it will make anonymous enums unhappy.
15104b6829f0d28990dd645e16386eb226d0f10c8731shiqian  static AssertionResult Compare(const char* expected_expression,
15114b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 const char* actual_expression,
15124b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 BiggestInt expected,
15134b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                 BiggestInt actual) {
15144b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return CmpHelperEQ(expected_expression, actual_expression, expected,
15154b6829f0d28990dd645e16386eb226d0f10c8731shiqian                       actual);
15164b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
15174b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
15184b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15194b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This specialization is used when the first argument to ASSERT_EQ()
15205e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan// is a null pointer literal, like NULL, false, or 0.
15214b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <>
15224b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass EqHelper<true> {
15234b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
15244b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // We define two overloaded versions of Compare().  The first
15254b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // version will be picked when the second argument to ASSERT_EQ() is
15264b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
15274b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // EXPECT_EQ(false, a_bool).
15284b6829f0d28990dd645e16386eb226d0f10c8731shiqian  template <typename T1, typename T2>
15295e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan  static AssertionResult Compare(
15305e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const char* expected_expression,
15315e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const char* actual_expression,
15325e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const T1& expected,
15335e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const T2& actual,
15345e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // The following line prevents this overload from being considered if T2
15355e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
15365e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // expands to Compare("", "", NULL, my_ptr), which requires a conversion
15375e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // to match the Secret* in the other overload, which would otherwise make
15385e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // this template match better.
15395e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
15404b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return CmpHelperEQ(expected_expression, actual_expression, expected,
15414b6829f0d28990dd645e16386eb226d0f10c8731shiqian                       actual);
15424b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
15434b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15445e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan  // This version will be picked when the second argument to ASSERT_EQ() is a
15455e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
15465e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan  template <typename T>
15475e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan  static AssertionResult Compare(
15485e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const char* expected_expression,
15495e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      const char* actual_expression,
15505e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // We used to have a second template parameter instead of Secret*.  That
15515e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // template parameter would deduce to 'long', making this a better match
15525e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // than the first overload even without the first overload's EnableIf.
15535e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
15545e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // non-pointer argument" (even a deduced integral argument), so the old
15555e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      // implementation caused warnings in user code.
15565e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      Secret* /* expected (NULL) */,
15575e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan      T* actual) {
15584b6829f0d28990dd645e16386eb226d0f10c8731shiqian    // We already know that 'expected' is a null pointer.
15594b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return CmpHelperEQ(expected_expression, actual_expression,
15605e255e0b6affbdc56718d81f0bb5d1b802a1c6c2zhanyong.wan                       static_cast<T*>(NULL), actual);
15614b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
15624b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
15634b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15644b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A macro for implementing the helper functions needed to implement
15654b6829f0d28990dd645e16386eb226d0f10c8731shiqian// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
15664b6829f0d28990dd645e16386eb226d0f10c8731shiqian// of similar code.
15674b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
15684b6829f0d28990dd645e16386eb226d0f10c8731shiqian// For each templatized helper function, we also define an overloaded
15694b6829f0d28990dd645e16386eb226d0f10c8731shiqian// version for BiggestInt in order to reduce code bloat and allow
15704b6829f0d28990dd645e16386eb226d0f10c8731shiqian// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
15714b6829f0d28990dd645e16386eb226d0f10c8731shiqian// with gcc 4.
15724b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
15734b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1574e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
15754b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <typename T1, typename T2>\
15764b6829f0d28990dd645e16386eb226d0f10c8731shiqianAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
15774b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                   const T1& val1, const T2& val2) {\
15784b6829f0d28990dd645e16386eb226d0f10c8731shiqian  if (val1 op val2) {\
15794b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return AssertionSuccess();\
15804b6829f0d28990dd645e16386eb226d0f10c8731shiqian  } else {\
15813928282cf0323a42e85e7885bddc54409021166fzhanyong.wan    return AssertionFailure() \
15823928282cf0323a42e85e7885bddc54409021166fzhanyong.wan        << "Expected: (" << expr1 << ") " #op " (" << expr2\
15834b6829f0d28990dd645e16386eb226d0f10c8731shiqian        << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
15844b6829f0d28990dd645e16386eb226d0f10c8731shiqian        << " vs " << FormatForComparisonFailureMessage(val2, val1);\
15854b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }\
15864b6829f0d28990dd645e16386eb226d0f10c8731shiqian}\
15871ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult CmpHelper##op_name(\
15881ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wan    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
15894b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15904b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15914b6829f0d28990dd645e16386eb226d0f10c8731shiqian
15924b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Implements the helper function for {ASSERT|EXPECT}_NE
15931ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_IMPL_CMP_HELPER_(NE, !=);
15944b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Implements the helper function for {ASSERT|EXPECT}_LE
15951ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_IMPL_CMP_HELPER_(LE, <=);
15964b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Implements the helper function for {ASSERT|EXPECT}_LT
159793fed47dbf8e6bc3d39d3f769cb5039551747257vladlosevGTEST_IMPL_CMP_HELPER_(LT, <);
15984b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Implements the helper function for {ASSERT|EXPECT}_GE
15991ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_IMPL_CMP_HELPER_(GE, >=);
16004b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Implements the helper function for {ASSERT|EXPECT}_GT
160193fed47dbf8e6bc3d39d3f769cb5039551747257vladlosevGTEST_IMPL_CMP_HELPER_(GT, >);
16024b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1603e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian#undef GTEST_IMPL_CMP_HELPER_
16044b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16054b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper function for {ASSERT|EXPECT}_STREQ.
16064b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16074b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1608e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1609e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* actual_expression,
1610e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* expected,
1611e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* actual);
16124b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16134b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
16144b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16154b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1616e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
1617e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* actual_expression,
1618e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* expected,
1619e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* actual);
16204b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16214b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper function for {ASSERT|EXPECT}_STRNE.
16224b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16234b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1624e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1625e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* s2_expression,
1626e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* s1,
1627e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* s2);
16284b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16294b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The helper function for {ASSERT|EXPECT}_STRCASENE.
16304b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16314b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1632e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1633e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* s2_expression,
1634e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* s1,
1635e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                              const char* s2);
16364b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16374b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Helper function for *_STREQ on wide strings.
16394b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16404b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1641e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1642e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* actual_expression,
1643e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const wchar_t* expected,
1644e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const wchar_t* actual);
16454b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16464b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Helper function for *_STRNE on wide strings.
16474b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16484b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1649e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1650e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const char* s2_expression,
1651e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const wchar_t* s1,
1652e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                          const wchar_t* s2);
16534b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16544b6829f0d28990dd645e16386eb226d0f10c8731shiqian}  // namespace internal
16554b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16564b6829f0d28990dd645e16386eb226d0f10c8731shiqian// IsSubstring() and IsNotSubstring() are intended to be used as the
16574b6829f0d28990dd645e16386eb226d0f10c8731shiqian// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
16584b6829f0d28990dd645e16386eb226d0f10c8731shiqian// themselves.  They check whether needle is a substring of haystack
16594b6829f0d28990dd645e16386eb226d0f10c8731shiqian// (NULL is considered a substring of itself only), and return an
16604b6829f0d28990dd645e16386eb226d0f10c8731shiqian// appropriate error message when they fail.
16614b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16624b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The {needle,haystack}_expr arguments are the stringified
16634b6829f0d28990dd645e16386eb226d0f10c8731shiqian// expressions that generated the two real arguments.
16641ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsSubstring(
16654b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16664b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle, const char* haystack);
16671ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsSubstring(
16684b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16694b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const wchar_t* needle, const wchar_t* haystack);
16701ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsNotSubstring(
16714b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16724b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle, const char* haystack);
16731ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsNotSubstring(
16744b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16754b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const wchar_t* needle, const wchar_t* haystack);
16761ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsSubstring(
16774b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16784b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const ::std::string& needle, const ::std::string& haystack);
16791ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsNotSubstring(
16804b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16814b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const ::std::string& needle, const ::std::string& haystack);
16824b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16834b6829f0d28990dd645e16386eb226d0f10c8731shiqian#if GTEST_HAS_STD_WSTRING
16841ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsSubstring(
16854b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16864b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const ::std::wstring& needle, const ::std::wstring& haystack);
16871ce454985edf37b17f2f266d499c2b7dec339002zhanyong.wanGTEST_API_ AssertionResult IsNotSubstring(
16884b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const char* needle_expr, const char* haystack_expr,
16894b6829f0d28990dd645e16386eb226d0f10c8731shiqian    const ::std::wstring& needle, const ::std::wstring& haystack);
16904b6829f0d28990dd645e16386eb226d0f10c8731shiqian#endif  // GTEST_HAS_STD_WSTRING
16914b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16924b6829f0d28990dd645e16386eb226d0f10c8731shiqiannamespace internal {
16934b6829f0d28990dd645e16386eb226d0f10c8731shiqian
16944b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Helper template function for comparing floating-points.
16954b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16964b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Template parameter:
16974b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
16984b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   RawType: the raw floating-point type (either float or double)
16994b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
17004b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
17014b6829f0d28990dd645e16386eb226d0f10c8731shiqiantemplate <typename RawType>
17024b6829f0d28990dd645e16386eb226d0f10c8731shiqianAssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
17034b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                         const char* actual_expression,
17044b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                         RawType expected,
17054b6829f0d28990dd645e16386eb226d0f10c8731shiqian                                         RawType actual) {
17064b6829f0d28990dd645e16386eb226d0f10c8731shiqian  const FloatingPoint<RawType> lhs(expected), rhs(actual);
17074b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17084b6829f0d28990dd645e16386eb226d0f10c8731shiqian  if (lhs.AlmostEquals(rhs)) {
17094b6829f0d28990dd645e16386eb226d0f10c8731shiqian    return AssertionSuccess();
17104b6829f0d28990dd645e16386eb226d0f10c8731shiqian  }
17114b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1712b15c73341d7a7abff7a04e1de18de59ba0f34009zhanyong.wan  ::std::stringstream expected_ss;
17134b6829f0d28990dd645e16386eb226d0f10c8731shiqian  expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
17144b6829f0d28990dd645e16386eb226d0f10c8731shiqian              << expected;
17154b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1716b15c73341d7a7abff7a04e1de18de59ba0f34009zhanyong.wan  ::std::stringstream actual_ss;
17174b6829f0d28990dd645e16386eb226d0f10c8731shiqian  actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
17184b6829f0d28990dd645e16386eb226d0f10c8731shiqian            << actual;
17194b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17204b6829f0d28990dd645e16386eb226d0f10c8731shiqian  return EqFailure(expected_expression,
17214b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   actual_expression,
1722b15c73341d7a7abff7a04e1de18de59ba0f34009zhanyong.wan                   StringStreamToString(&expected_ss),
1723b15c73341d7a7abff7a04e1de18de59ba0f34009zhanyong.wan                   StringStreamToString(&actual_ss),
17244b6829f0d28990dd645e16386eb226d0f10c8731shiqian                   false);
17254b6829f0d28990dd645e16386eb226d0f10c8731shiqian}
17264b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17274b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Helper function for implementing ASSERT_NEAR.
17284b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
17294b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1730e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
1731e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                                const char* expr2,
1732e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                                const char* abs_error_expr,
1733e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                                double val1,
1734e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                                double val2,
1735e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                                double abs_error);
17364b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17374b6829f0d28990dd645e16386eb226d0f10c8731shiqian// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
17384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A class that enables one to stream messages to assertion macros
1739e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanclass GTEST_API_ AssertHelper {
17404b6829f0d28990dd645e16386eb226d0f10c8731shiqian public:
17414b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Constructor.
1742334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan  AssertHelper(TestPartResult::Type type,
1743334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan               const char* file,
1744334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan               int line,
17454b6829f0d28990dd645e16386eb226d0f10c8731shiqian               const char* message);
1746f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  ~AssertHelper();
1747f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
17484b6829f0d28990dd645e16386eb226d0f10c8731shiqian  // Message assignment is a semantic trick to enable assertion
1749e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  // streaming; see the GTEST_MESSAGE_ macro below.
17504b6829f0d28990dd645e16386eb226d0f10c8731shiqian  void operator=(const Message& message) const;
1751f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
17524b6829f0d28990dd645e16386eb226d0f10c8731shiqian private:
1753f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // We put our data in a struct so that the size of the AssertHelper class can
1754f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // be as small as possible.  This is important because gcc is incapable of
1755f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // re-using stack space even for temporary variables, so every EXPECT_EQ
1756f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  // reserves stack space for another AssertHelper.
1757f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  struct AssertHelperData {
1758334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan    AssertHelperData(TestPartResult::Type t,
1759334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan                     const char* srcfile,
1760334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan                     int line_num,
1761f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan                     const char* msg)
1762f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan        : type(t), file(srcfile), line(line_num), message(msg) { }
1763f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1764334aaead71ccf797a18f2128c320f0304e724860zhanyong.wan    TestPartResult::Type const type;
176503c314931649a999b0cf5deb0a434a1009157416jgm@google.com    const char* const file;
176603c314931649a999b0cf5deb0a434a1009157416jgm@google.com    int const line;
176703c314931649a999b0cf5deb0a434a1009157416jgm@google.com    std::string const message;
1768f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1769f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan   private:
1770f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
1771f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  };
1772f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
1773f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan  AssertHelperData* const data_;
17744b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1775e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
17764b6829f0d28990dd645e16386eb226d0f10c8731shiqian};
17774b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17784b6829f0d28990dd645e16386eb226d0f10c8731shiqian}  // namespace internal
17794b6829f0d28990dd645e16386eb226d0f10c8731shiqian
17804cd62602913a032a7aec091d4c8055ff9af95e37zhanyong.wan#if GTEST_HAS_PARAM_TEST
178171874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// The pure interface class that all value-parameterized tests inherit from.
178271874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// A value-parameterized class must inherit from both ::testing::Test and
178371874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// ::testing::WithParamInterface. In most cases that just means inheriting
178471874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// from ::testing::TestWithParam, but more complicated test hierarchies
178571874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// may need to inherit from Test and WithParamInterface at different levels.
1786f904a612d9444ab36c07a8e619c113432e046f49vladlosev//
178771874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// This interface has support for accessing the test parameter value via
1788f904a612d9444ab36c07a8e619c113432e046f49vladlosev// the GetParam() method.
1789f904a612d9444ab36c07a8e619c113432e046f49vladlosev//
1790f904a612d9444ab36c07a8e619c113432e046f49vladlosev// Use it with one of the parameter generator defining functions, like Range(),
1791f904a612d9444ab36c07a8e619c113432e046f49vladlosev// Values(), ValuesIn(), Bool(), and Combine().
1792f904a612d9444ab36c07a8e619c113432e046f49vladlosev//
1793f904a612d9444ab36c07a8e619c113432e046f49vladlosev// class FooTest : public ::testing::TestWithParam<int> {
1794f904a612d9444ab36c07a8e619c113432e046f49vladlosev//  protected:
1795f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   FooTest() {
1796f904a612d9444ab36c07a8e619c113432e046f49vladlosev//     // Can use GetParam() here.
1797f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   }
1798f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   virtual ~FooTest() {
1799f904a612d9444ab36c07a8e619c113432e046f49vladlosev//     // Can use GetParam() here.
1800f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   }
1801f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   virtual void SetUp() {
1802f904a612d9444ab36c07a8e619c113432e046f49vladlosev//     // Can use GetParam() here.
1803f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   }
1804f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   virtual void TearDown {
1805f904a612d9444ab36c07a8e619c113432e046f49vladlosev//     // Can use GetParam() here.
1806f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   }
1807f904a612d9444ab36c07a8e619c113432e046f49vladlosev// };
1808f904a612d9444ab36c07a8e619c113432e046f49vladlosev// TEST_P(FooTest, DoesBar) {
1809f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   // Can use GetParam() method here.
1810f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   Foo foo;
1811f904a612d9444ab36c07a8e619c113432e046f49vladlosev//   ASSERT_TRUE(foo.DoesBar(GetParam()));
1812f904a612d9444ab36c07a8e619c113432e046f49vladlosev// }
1813f904a612d9444ab36c07a8e619c113432e046f49vladlosev// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1814f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1815f904a612d9444ab36c07a8e619c113432e046f49vladlosevtemplate <typename T>
181671874246c3a054977d94fd4729576484c2af62e9zhanyong.wanclass WithParamInterface {
1817f904a612d9444ab36c07a8e619c113432e046f49vladlosev public:
1818f904a612d9444ab36c07a8e619c113432e046f49vladlosev  typedef T ParamType;
181971874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  virtual ~WithParamInterface() {}
1820f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1821f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // The current parameter value. Is also available in the test fixture's
182271874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  // constructor. This member function is non-static, even though it only
182371874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  // references static data, to reduce the opportunity for incorrect uses
182471874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
182571874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  // uses a fixture whose parameter type is int.
1826726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan  const ParamType& GetParam() const {
1827726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan    GTEST_CHECK_(parameter_ != NULL)
1828726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan        << "GetParam() can only be called inside a value-parameterized test "
1829726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan        << "-- did you intend to write TEST_P instead of TEST_F?";
1830726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan    return *parameter_;
1831726afc27a7873cb99e562df47d57188a09464fa5zhanyong.wan  }
1832f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1833f904a612d9444ab36c07a8e619c113432e046f49vladlosev private:
1834f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // Sets parameter value. The caller is responsible for making sure the value
1835f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // remains alive and unchanged throughout the current test.
1836f904a612d9444ab36c07a8e619c113432e046f49vladlosev  static void SetParam(const ParamType* parameter) {
1837f904a612d9444ab36c07a8e619c113432e046f49vladlosev    parameter_ = parameter;
1838f904a612d9444ab36c07a8e619c113432e046f49vladlosev  }
1839f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1840f904a612d9444ab36c07a8e619c113432e046f49vladlosev  // Static value used for accessing parameter during a test lifetime.
1841f904a612d9444ab36c07a8e619c113432e046f49vladlosev  static const ParamType* parameter_;
1842f904a612d9444ab36c07a8e619c113432e046f49vladlosev
184371874246c3a054977d94fd4729576484c2af62e9zhanyong.wan  // TestClass must be a subclass of WithParamInterface<T> and Test.
1844f904a612d9444ab36c07a8e619c113432e046f49vladlosev  template <class TestClass> friend class internal::ParameterizedTestFactory;
1845f904a612d9444ab36c07a8e619c113432e046f49vladlosev};
1846f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1847f904a612d9444ab36c07a8e619c113432e046f49vladlosevtemplate <typename T>
184871874246c3a054977d94fd4729576484c2af62e9zhanyong.wanconst T* WithParamInterface<T>::parameter_ = NULL;
184971874246c3a054977d94fd4729576484c2af62e9zhanyong.wan
185071874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// Most value-parameterized classes can ignore the existence of
185171874246c3a054977d94fd4729576484c2af62e9zhanyong.wan// WithParamInterface, and can just inherit from ::testing::TestWithParam.
185271874246c3a054977d94fd4729576484c2af62e9zhanyong.wan
185371874246c3a054977d94fd4729576484c2af62e9zhanyong.wantemplate <typename T>
185471874246c3a054977d94fd4729576484c2af62e9zhanyong.wanclass TestWithParam : public Test, public WithParamInterface<T> {
185571874246c3a054977d94fd4729576484c2af62e9zhanyong.wan};
1856f904a612d9444ab36c07a8e619c113432e046f49vladlosev
1857f904a612d9444ab36c07a8e619c113432e046f49vladlosev#endif  // GTEST_HAS_PARAM_TEST
1858f904a612d9444ab36c07a8e619c113432e046f49vladlosev
18594b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Macros for indicating success/failure in test code.
18604b6829f0d28990dd645e16386eb226d0f10c8731shiqian
18614b6829f0d28990dd645e16386eb226d0f10c8731shiqian// ADD_FAILURE unconditionally adds a failure to the current test.
18624b6829f0d28990dd645e16386eb226d0f10c8731shiqian// SUCCEED generates a success - it doesn't automatically make the
18634b6829f0d28990dd645e16386eb226d0f10c8731shiqian// current test successful, as a test is only successful when it has
18644b6829f0d28990dd645e16386eb226d0f10c8731shiqian// no failure.
18654b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
18664b6829f0d28990dd645e16386eb226d0f10c8731shiqian// EXPECT_* verifies that a certain condition is satisfied.  If not,
18674b6829f0d28990dd645e16386eb226d0f10c8731shiqian// it behaves like ADD_FAILURE.  In particular:
18684b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
18694b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_TRUE  verifies that a Boolean condition is true.
18704b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_FALSE verifies that a Boolean condition is false.
18714b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
18724b6829f0d28990dd645e16386eb226d0f10c8731shiqian// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
18734b6829f0d28990dd645e16386eb226d0f10c8731shiqian// that they will also abort the current function on failure.  People
18744b6829f0d28990dd645e16386eb226d0f10c8731shiqian// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
18754b6829f0d28990dd645e16386eb226d0f10c8731shiqian// writing data-driven tests often find themselves using ADD_FAILURE
18764b6829f0d28990dd645e16386eb226d0f10c8731shiqian// and EXPECT_* more.
18774b6829f0d28990dd645e16386eb226d0f10c8731shiqian
18784b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Generates a nonfatal failure with a generic message.
1879e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
18804b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1881d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan// Generates a nonfatal failure at the given source file location with
1882d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan// a generic message.
1883d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan#define ADD_FAILURE_AT(file, line) \
1884d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan  GTEST_MESSAGE_AT_(file, line, "Failed", \
1885d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan                    ::testing::TestPartResult::kNonFatalFailure)
1886d5ad2ca82051c34b19af628a3c81131ca65010c2zhanyong.wan
18874b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Generates a fatal failure with a generic message.
18881618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
18891618bb491b881bc39faa3317ee8778847646226dzhanyong.wan
18901618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// Define this macro to 1 to omit the definition of FAIL(), which is a
18911618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// generic name and clashes with some other libraries.
18921618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#if !GTEST_DONT_DEFINE_FAIL
1893733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define FAIL() GTEST_FAIL()
18941618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#endif
18954b6829f0d28990dd645e16386eb226d0f10c8731shiqian
18964b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Generates a success with a generic message.
18971618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
18981618bb491b881bc39faa3317ee8778847646226dzhanyong.wan
18991618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// Define this macro to 1 to omit the definition of SUCCEED(), which
19001618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// is a generic name and clashes with some other libraries.
19011618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#if !GTEST_DONT_DEFINE_SUCCEED
1902733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define SUCCEED() GTEST_SUCCEED()
19031618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#endif
19044b6829f0d28990dd645e16386eb226d0f10c8731shiqian
19059204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian// Macros for testing exceptions.
19069204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//
19079204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
19089204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//         Tests that the statement throws the expected exception.
19099204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//    * {ASSERT|EXPECT}_NO_THROW(statement):
19109204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//         Tests that the statement doesn't throw any exception.
19119204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//    * {ASSERT|EXPECT}_ANY_THROW(statement):
19129204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian//         Tests that the statement throws an exception.
19139204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian
19149204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define EXPECT_THROW(statement, expected_exception) \
1915e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
19169204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define EXPECT_NO_THROW(statement) \
1917e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
19189204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define EXPECT_ANY_THROW(statement) \
1919e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
19209204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define ASSERT_THROW(statement, expected_exception) \
1921e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
19229204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define ASSERT_NO_THROW(statement) \
1923e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
19249204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian#define ASSERT_ANY_THROW(statement) \
1925e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
19269204c8ec6edda2013cd81bf3c93e9cb6c45b9bb5shiqian
1927fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// Boolean assertions. Condition can be either a Boolean expression or an
1928fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// AssertionResult. For more information on how to use AssertionResult with
1929fbd53a53c1e01dec71c65754cf73282e4759bc40vladlosev// these macros see comments on that class.
19304b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_TRUE(condition) \
1931e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1932e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      GTEST_NONFATAL_FAILURE_)
19334b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_FALSE(condition) \
1934e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1935e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      GTEST_NONFATAL_FAILURE_)
19364b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_TRUE(condition) \
1937e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1938e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      GTEST_FATAL_FAILURE_)
19394b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_FALSE(condition) \
1940e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1941e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      GTEST_FATAL_FAILURE_)
19424b6829f0d28990dd645e16386eb226d0f10c8731shiqian
19434b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Includes the auto-generated header that implements a family of
19444b6829f0d28990dd645e16386eb226d0f10c8731shiqian// generic predicate assertion macros.
19452620c79810d4741922e9fa89050c0af564994f24zhanyong.wan#include "gtest/gtest_pred_impl.h"
19464b6829f0d28990dd645e16386eb226d0f10c8731shiqian
19474b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Macros for testing equalities and inequalities.
19484b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19494b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
19504b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_NE(v1, v2):           Tests that v1 != v2
19514b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_LT(v1, v2):           Tests that v1 < v2
19524b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_LE(v1, v2):           Tests that v1 <= v2
19534b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_GT(v1, v2):           Tests that v1 > v2
19544b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_GE(v1, v2):           Tests that v1 >= v2
19554b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19564b6829f0d28990dd645e16386eb226d0f10c8731shiqian// When they are not, Google Test prints both the tested expressions and
19574b6829f0d28990dd645e16386eb226d0f10c8731shiqian// their actual values.  The values must be compatible built-in types,
19584b6829f0d28990dd645e16386eb226d0f10c8731shiqian// or you will get a compiler error.  By "compatible" we mean that the
19594b6829f0d28990dd645e16386eb226d0f10c8731shiqian// values can be compared by the respective operator.
19604b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19614b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Note:
19624b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19634b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   1. It is possible to make a user-defined type work with
19644b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   {ASSERT|EXPECT}_??(), but that requires overloading the
19654b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   comparison operators and is thus discouraged by the Google C++
19664b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   Usage Guide.  Therefore, you are advised to use the
19674b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
19684b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   equal.
19694b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19704b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
19714b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   pointers (in particular, C strings).  Therefore, if you use it
19724b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   with two C strings, you are testing how their locations in memory
19734b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   are related, not how their content is related.  To compare two C
19744b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   strings by content, use {ASSERT|EXPECT}_STR*().
19754b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19764b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
19774b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
19784b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   what the actual value is when it fails, and similarly for the
19794b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   other comparisons.
19804b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19814b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
19824b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   evaluate their arguments, which is undefined.
19834b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19844b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   5. These macros evaluate their arguments exactly once.
19854b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19864b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Examples:
19874b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
19884b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_NE(5, Foo());
19894b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_EQ(NULL, a_pointer);
19904b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   ASSERT_LT(i, array_size);
19914b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   ASSERT_GT(records.size(), 0) << "There is no record left.";
19924b6829f0d28990dd645e16386eb226d0f10c8731shiqian
19934b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_EQ(expected, actual) \
19944b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal:: \
1995e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
19964b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
19974b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_NE(expected, actual) \
19984b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
19994b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_LE(val1, val2) \
20004b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
20014b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_LT(val1, val2) \
20024b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
20034b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_GE(val1, val2) \
20044b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
20054b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_GT(val1, val2) \
20064b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
20074b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20080bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_EQ(expected, actual) \
20094b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal:: \
2010e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
20114b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
20120bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_NE(val1, val2) \
20134b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
20140bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_LE(val1, val2) \
20154b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
20160bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_LT(val1, val2) \
20174b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
20180bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_GE(val1, val2) \
20194b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
20200bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#define GTEST_ASSERT_GT(val1, val2) \
20214b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
20224b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20230bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
20240bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan// ASSERT_XY(), which clashes with some users' own code.
20250bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20260bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_EQ
2027733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
20280bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20290bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20300bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_NE
2031733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
20320bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20330bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20340bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_LE
2035733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
20360bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20370bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20380bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_LT
2039733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
20400bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20410bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20420bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_GE
2043733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
20440bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20450bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
20460bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#if !GTEST_DONT_DEFINE_ASSERT_GT
2047733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
20480bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan#endif
20490bfb56317785c7960bedee9fda0bb879347e2121zhanyong.wan
205003c314931649a999b0cf5deb0a434a1009157416jgm@google.com// C-string Comparisons.  All tests treat NULL and any non-NULL string
20514b6829f0d28990dd645e16386eb226d0f10c8731shiqian// as different.  Two NULLs are equal.
20524b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20534b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
20544b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
20554b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
20564b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
20574b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20584b6829f0d28990dd645e16386eb226d0f10c8731shiqian// For wide or narrow string objects, you can use the
20594b6829f0d28990dd645e16386eb226d0f10c8731shiqian// {ASSERT|EXPECT}_??() macros.
20604b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20614b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Don't depend on the order in which the arguments are evaluated,
20624b6829f0d28990dd645e16386eb226d0f10c8731shiqian// which is undefined.
20634b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20644b6829f0d28990dd645e16386eb226d0f10c8731shiqian// These macros evaluate their arguments exactly once.
20654b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20664b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_STREQ(expected, actual) \
20674b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
20684b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_STRNE(s1, s2) \
20694b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
20704b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_STRCASEEQ(expected, actual) \
20714b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
20724b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_STRCASENE(s1, s2)\
20734b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20744b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20754b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_STREQ(expected, actual) \
20764b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
20774b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_STRNE(s1, s2) \
20784b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
20794b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_STRCASEEQ(expected, actual) \
20804b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
20814b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_STRCASENE(s1, s2)\
20824b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20834b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20844b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Macros for comparing floating-point numbers.
20854b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20864b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
20874b6829f0d28990dd645e16386eb226d0f10c8731shiqian//         Tests that two float values are almost equal.
20884b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
20894b6829f0d28990dd645e16386eb226d0f10c8731shiqian//         Tests that two double values are almost equal.
20904b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
20914b6829f0d28990dd645e16386eb226d0f10c8731shiqian//         Tests that v1 and v2 are within the given distance to each other.
20924b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
20934b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Google Test uses ULP-based comparison to automatically pick a default
20944b6829f0d28990dd645e16386eb226d0f10c8731shiqian// error bound that is appropriate for the operands.  See the
20954b6829f0d28990dd645e16386eb226d0f10c8731shiqian// FloatingPoint template class in gtest-internal.h if you are
20964b6829f0d28990dd645e16386eb226d0f10c8731shiqian// interested in the implementation details.
20974b6829f0d28990dd645e16386eb226d0f10c8731shiqian
20984b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_FLOAT_EQ(expected, actual)\
20994b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
21004b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
21014b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21024b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_DOUBLE_EQ(expected, actual)\
21034b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
21044b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
21054b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21064b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_FLOAT_EQ(expected, actual)\
21074b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
21084b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
21094b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21104b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_DOUBLE_EQ(expected, actual)\
21114b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
21124b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      expected, actual)
21134b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21144b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define EXPECT_NEAR(val1, val2, abs_error)\
21154b6829f0d28990dd645e16386eb226d0f10c8731shiqian  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
21164b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      val1, val2, abs_error)
21174b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21184b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ASSERT_NEAR(val1, val2, abs_error)\
21194b6829f0d28990dd645e16386eb226d0f10c8731shiqian  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
21204b6829f0d28990dd645e16386eb226d0f10c8731shiqian                      val1, val2, abs_error)
21214b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21224b6829f0d28990dd645e16386eb226d0f10c8731shiqian// These predicate format functions work on floating-point values, and
21234b6829f0d28990dd645e16386eb226d0f10c8731shiqian// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
21244b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
21254b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
21264b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21274b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Asserts that val1 is less than, or almost equal to, val2.  Fails
21284b6829f0d28990dd645e16386eb226d0f10c8731shiqian// otherwise.  In particular, it fails if either val1 or val2 is NaN.
2129e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
2130e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                   float val1, float val2);
2131e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wanGTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
2132e4092294d7c1f38f303e8c7f67da31ba3e7e7d9azhanyong.wan                                    double val1, double val2);
21334b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21344b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21354cd62602913a032a7aec091d4c8055ff9af95e37zhanyong.wan#if GTEST_OS_WINDOWS
21364b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21374b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Macros that test for HRESULT failure and success, these are only useful
21384b6829f0d28990dd645e16386eb226d0f10c8731shiqian// on Windows, and rely on Windows SDK macros and APIs to compile.
21394b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
21404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
21414b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
2142e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian// When expr unexpectedly fails or succeeds, Google Test prints the
2143e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian// expected result and the actual result with both a human-readable
2144e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian// string representation of the error, if available, as well as the
2145e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian// hex result code.
2146733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define EXPECT_HRESULT_SUCCEEDED(expr) \
21474b6829f0d28990dd645e16386eb226d0f10c8731shiqian    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
21484b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2149733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_HRESULT_SUCCEEDED(expr) \
21504b6829f0d28990dd645e16386eb226d0f10c8731shiqian    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
21514b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2152733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define EXPECT_HRESULT_FAILED(expr) \
21534b6829f0d28990dd645e16386eb226d0f10c8731shiqian    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
21544b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2155733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define ASSERT_HRESULT_FAILED(expr) \
21564b6829f0d28990dd645e16386eb226d0f10c8731shiqian    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
21574b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21584b6829f0d28990dd645e16386eb226d0f10c8731shiqian#endif  // GTEST_OS_WINDOWS
21594b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2160e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian// Macros that execute statement and check that it doesn't generate new fatal
2161e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian// failures in the current thread.
2162e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//
2163e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2164e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//
2165e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian// Examples:
2166e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//
2167e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//   EXPECT_NO_FATAL_FAILURE(Process());
2168e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2169e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian//
2170e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian#define ASSERT_NO_FATAL_FAILURE(statement) \
2171e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
2172e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian#define EXPECT_NO_FATAL_FAILURE(statement) \
2173e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
21744b6829f0d28990dd645e16386eb226d0f10c8731shiqian
21754b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Causes a trace (including the source file path, the current line
21764b6829f0d28990dd645e16386eb226d0f10c8731shiqian// number, and the given message) to be included in every test failure
21774b6829f0d28990dd645e16386eb226d0f10c8731shiqian// message generated by code in the current scope.  The effect is
21784b6829f0d28990dd645e16386eb226d0f10c8731shiqian// undone when the control leaves the current scope.
21794b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
21804b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The message argument can be anything streamable to std::ostream.
21814b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
21824b6829f0d28990dd645e16386eb226d0f10c8731shiqian// In the implementation, we include the current line number as part
21834b6829f0d28990dd645e16386eb226d0f10c8731shiqian// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
21844b6829f0d28990dd645e16386eb226d0f10c8731shiqian// to appear in the same block - as long as they are on different
21854b6829f0d28990dd645e16386eb226d0f10c8731shiqian// lines.
21864b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define SCOPED_TRACE(message) \
2187e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
21884b6829f0d28990dd645e16386eb226d0f10c8731shiqian    __FILE__, __LINE__, ::testing::Message() << (message))
21894b6829f0d28990dd645e16386eb226d0f10c8731shiqian
219021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// Compile-time assertion for type equality.
219121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
219221d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// the same type.  The value it returns is not interesting.
219321d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
219421d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// Instead of making StaticAssertTypeEq a class template, we make it a
219521d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// function template that invokes a helper class template.  This
219621d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
219721d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// defining objects of that type.
219821d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
219921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// CAVEAT:
220021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
220121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// When used inside a method of a class template,
220221d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
220321d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// instantiated.  For example, given:
220421d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
220521d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//   template <typename T> class Foo {
220621d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//    public:
220721d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
220821d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//   };
220921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
221021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// the code:
221121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
221221d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//   void Test1() { Foo<bool> foo; }
221321d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
221421d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// will NOT generate a compiler error, as Foo<bool>::Bar() is never
221521d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// actually instantiated.  Instead, you need:
221621d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
221721d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//   void Test2() { Foo<bool> foo; foo.Bar(); }
221821d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian//
221921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian// to cause a compiler error.
222021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqiantemplate <typename T1, typename T2>
222121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqianbool StaticAssertTypeEq() {
222299f2fd8ac474e2a8cf922410af199fa7a0057f7bzhanyong.wan  (void)internal::StaticAssertTypeEqHelper<T1, T2>();
222321d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian  return true;
222421d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian}
22254b6829f0d28990dd645e16386eb226d0f10c8731shiqian
22264b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Defines a test.
22274b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22284b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The first parameter is the name of the test case, and the second
22294b6829f0d28990dd645e16386eb226d0f10c8731shiqian// parameter is the name of the test within the test case.
22304b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22314b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The convention is to end the test case name with "Test".  For
22324b6829f0d28990dd645e16386eb226d0f10c8731shiqian// example, a test case for the Foo class can be named FooTest.
22334b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22342f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// Test code should appear between braces after an invocation of
22352f9c469cd2ac136ca4b496b8682a316ce6bf466dkosak@google.com// this macro.  Example:
22364b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22374b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   TEST(FooTest, InitializesCorrectly) {
22384b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     Foo foo;
22394b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     EXPECT_TRUE(foo.StatusIsOK());
22404b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   }
22414b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2242fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// Note that we call GetTestTypeId() instead of GetTypeId<
2243fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// ::testing::Test>() here to get the type ID of testing::Test.  This
2244fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// is to work around a suspected linker bug when using Google Test as
2245fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// a framework on Mac OS X.  The bug causes GetTypeId<
2246fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// ::testing::Test>() to return different values depending on whether
2247fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// the call is from the Google Test framework itself or from user test
2248fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// code.  GetTestTypeId() is guaranteed to always return the same
2249fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// value, as it always calls GetTypeId<>() from the Google Test
2250fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian// framework.
22511618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#define GTEST_TEST(test_case_name, test_name)\
2252b0a12f719caf4e37894868334ce41b1864b0be53zhanyong.wan  GTEST_TEST_(test_case_name, test_name, \
2253fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian              ::testing::Test, ::testing::internal::GetTestTypeId())
22544b6829f0d28990dd645e16386eb226d0f10c8731shiqian
22551618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// Define this macro to 1 to omit the definition of TEST(), which
22561618bb491b881bc39faa3317ee8778847646226dzhanyong.wan// is a generic name and clashes with some other libraries.
22571618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#if !GTEST_DONT_DEFINE_TEST
2258733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
22591618bb491b881bc39faa3317ee8778847646226dzhanyong.wan#endif
22604b6829f0d28990dd645e16386eb226d0f10c8731shiqian
22614b6829f0d28990dd645e16386eb226d0f10c8731shiqian// Defines a test that uses a test fixture.
22624b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22634b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The first parameter is the name of the test fixture class, which
22644b6829f0d28990dd645e16386eb226d0f10c8731shiqian// also doubles as the test case name.  The second parameter is the
22654b6829f0d28990dd645e16386eb226d0f10c8731shiqian// name of the test within the test case.
22664b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22674b6829f0d28990dd645e16386eb226d0f10c8731shiqian// A test fixture class must be declared earlier.  The user should put
22684b6829f0d28990dd645e16386eb226d0f10c8731shiqian// his test code between braces after using this macro.  Example:
22694b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22704b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   class FooTest : public testing::Test {
22714b6829f0d28990dd645e16386eb226d0f10c8731shiqian//    protected:
22724b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     virtual void SetUp() { b_.AddElement(3); }
22734b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22744b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     Foo a_;
22754b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     Foo b_;
22764b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   };
22774b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22784b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   TEST_F(FooTest, InitializesCorrectly) {
22794b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     EXPECT_TRUE(a_.StatusIsOK());
22804b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   }
22814b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22824b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   TEST_F(FooTest, ReturnsElementCountCorrectly) {
22834b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     EXPECT_EQ(0, a_.size());
22844b6829f0d28990dd645e16386eb226d0f10c8731shiqian//     EXPECT_EQ(1, b_.size());
22854b6829f0d28990dd645e16386eb226d0f10c8731shiqian//   }
22864b6829f0d28990dd645e16386eb226d0f10c8731shiqian
22874b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define TEST_F(test_fixture, test_name)\
2288b0a12f719caf4e37894868334ce41b1864b0be53zhanyong.wan  GTEST_TEST_(test_fixture, test_name, test_fixture, \
2289fe6a9a48c2a8280439e58c2e9020268a80df89b3shiqian              ::testing::internal::GetTypeId<test_fixture>())
22904b6829f0d28990dd645e16386eb226d0f10c8731shiqian
229199788d751da80001db223de2cd6178046ff5bad0zhanyong.wan}  // namespace testing
229299788d751da80001db223de2cd6178046ff5bad0zhanyong.wan
229399788d751da80001db223de2cd6178046ff5bad0zhanyong.wan// Use this function in main() to run all tests.  It returns 0 if all
22944b6829f0d28990dd645e16386eb226d0f10c8731shiqian// tests are successful, or 1 otherwise.
22954b6829f0d28990dd645e16386eb226d0f10c8731shiqian//
22964b6829f0d28990dd645e16386eb226d0f10c8731shiqian// RUN_ALL_TESTS() should be invoked after the command line has been
22974b6829f0d28990dd645e16386eb226d0f10c8731shiqian// parsed by InitGoogleTest().
229899788d751da80001db223de2cd6178046ff5bad0zhanyong.wan//
229999788d751da80001db223de2cd6178046ff5bad0zhanyong.wan// This function was formerly a macro; thus, it is in the global
230099788d751da80001db223de2cd6178046ff5bad0zhanyong.wan// namespace and has an all-caps name.
230199788d751da80001db223de2cd6178046ff5bad0zhanyong.wanint RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
23024b6829f0d28990dd645e16386eb226d0f10c8731shiqian
230399788d751da80001db223de2cd6178046ff5bad0zhanyong.waninline int RUN_ALL_TESTS() {
230499788d751da80001db223de2cd6178046ff5bad0zhanyong.wan  return ::testing::UnitTest::GetInstance()->Run();
230599788d751da80001db223de2cd6178046ff5bad0zhanyong.wan}
23064b6829f0d28990dd645e16386eb226d0f10c8731shiqian
23074b6829f0d28990dd645e16386eb226d0f10c8731shiqian#endif  // GTEST_INCLUDE_GTEST_GTEST_H_
2308