11b362b15af34006e6a11974088a46d42b903418eJohann// Copyright 2005, Google Inc.
21b362b15af34006e6a11974088a46d42b903418eJohann// All rights reserved.
31b362b15af34006e6a11974088a46d42b903418eJohann//
41b362b15af34006e6a11974088a46d42b903418eJohann// Redistribution and use in source and binary forms, with or without
51b362b15af34006e6a11974088a46d42b903418eJohann// modification, are permitted provided that the following conditions are
61b362b15af34006e6a11974088a46d42b903418eJohann// met:
71b362b15af34006e6a11974088a46d42b903418eJohann//
81b362b15af34006e6a11974088a46d42b903418eJohann//     * Redistributions of source code must retain the above copyright
91b362b15af34006e6a11974088a46d42b903418eJohann// notice, this list of conditions and the following disclaimer.
101b362b15af34006e6a11974088a46d42b903418eJohann//     * Redistributions in binary form must reproduce the above
111b362b15af34006e6a11974088a46d42b903418eJohann// copyright notice, this list of conditions and the following disclaimer
121b362b15af34006e6a11974088a46d42b903418eJohann// in the documentation and/or other materials provided with the
131b362b15af34006e6a11974088a46d42b903418eJohann// distribution.
141b362b15af34006e6a11974088a46d42b903418eJohann//     * Neither the name of Google Inc. nor the names of its
151b362b15af34006e6a11974088a46d42b903418eJohann// contributors may be used to endorse or promote products derived from
161b362b15af34006e6a11974088a46d42b903418eJohann// this software without specific prior written permission.
171b362b15af34006e6a11974088a46d42b903418eJohann//
181b362b15af34006e6a11974088a46d42b903418eJohann// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191b362b15af34006e6a11974088a46d42b903418eJohann// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211b362b15af34006e6a11974088a46d42b903418eJohann// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221b362b15af34006e6a11974088a46d42b903418eJohann// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231b362b15af34006e6a11974088a46d42b903418eJohann// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251b362b15af34006e6a11974088a46d42b903418eJohann// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261b362b15af34006e6a11974088a46d42b903418eJohann// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271b362b15af34006e6a11974088a46d42b903418eJohann// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281b362b15af34006e6a11974088a46d42b903418eJohann// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291b362b15af34006e6a11974088a46d42b903418eJohann//
301b362b15af34006e6a11974088a46d42b903418eJohann// Author: wan@google.com (Zhanyong Wan)
311b362b15af34006e6a11974088a46d42b903418eJohann//
321b362b15af34006e6a11974088a46d42b903418eJohann// The Google C++ Testing Framework (Google Test)
331b362b15af34006e6a11974088a46d42b903418eJohann//
341b362b15af34006e6a11974088a46d42b903418eJohann// This header file defines the public API for Google Test.  It should be
351b362b15af34006e6a11974088a46d42b903418eJohann// included by any test program that uses Google Test.
361b362b15af34006e6a11974088a46d42b903418eJohann//
371b362b15af34006e6a11974088a46d42b903418eJohann// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
381b362b15af34006e6a11974088a46d42b903418eJohann// leave some internal implementation details in this header file.
391b362b15af34006e6a11974088a46d42b903418eJohann// They are clearly marked by comments like this:
401b362b15af34006e6a11974088a46d42b903418eJohann//
411b362b15af34006e6a11974088a46d42b903418eJohann//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
421b362b15af34006e6a11974088a46d42b903418eJohann//
431b362b15af34006e6a11974088a46d42b903418eJohann// Such code is NOT meant to be used by a user directly, and is subject
441b362b15af34006e6a11974088a46d42b903418eJohann// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
451b362b15af34006e6a11974088a46d42b903418eJohann// program!
461b362b15af34006e6a11974088a46d42b903418eJohann//
471b362b15af34006e6a11974088a46d42b903418eJohann// Acknowledgment: Google Test borrowed the idea of automatic test
481b362b15af34006e6a11974088a46d42b903418eJohann// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
491b362b15af34006e6a11974088a46d42b903418eJohann// easyUnit framework.
501b362b15af34006e6a11974088a46d42b903418eJohann
511b362b15af34006e6a11974088a46d42b903418eJohann#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
521b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_INCLUDE_GTEST_GTEST_H_
531b362b15af34006e6a11974088a46d42b903418eJohann
541b362b15af34006e6a11974088a46d42b903418eJohann#include <limits>
555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <ostream>
561b362b15af34006e6a11974088a46d42b903418eJohann#include <vector>
571b362b15af34006e6a11974088a46d42b903418eJohann
588b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/internal/gtest-internal.h"
598b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/internal/gtest-string.h"
608b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-death-test.h"
618b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-message.h"
628b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-param-test.h"
638b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-printers.h"
648b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest_prod.h"
658b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-test-part.h"
668b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest-typed-test.h"
671b362b15af34006e6a11974088a46d42b903418eJohann
681b362b15af34006e6a11974088a46d42b903418eJohann// Depending on the platform, different string classes are available.
691b362b15af34006e6a11974088a46d42b903418eJohann// On Linux, in addition to ::std::string, Google also makes use of
701b362b15af34006e6a11974088a46d42b903418eJohann// class ::string, which has the same interface as ::std::string, but
711b362b15af34006e6a11974088a46d42b903418eJohann// has a different implementation.
721b362b15af34006e6a11974088a46d42b903418eJohann//
738b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
741b362b15af34006e6a11974088a46d42b903418eJohann// ::string is available AND is a distinct type to ::std::string, or
751b362b15af34006e6a11974088a46d42b903418eJohann// define it to 0 to indicate otherwise.
761b362b15af34006e6a11974088a46d42b903418eJohann//
778b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// If ::std::string and ::string are the same class on your platform
788b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
791b362b15af34006e6a11974088a46d42b903418eJohann//
808b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
811b362b15af34006e6a11974088a46d42b903418eJohann// heuristically.
821b362b15af34006e6a11974088a46d42b903418eJohann
831b362b15af34006e6a11974088a46d42b903418eJohannnamespace testing {
841b362b15af34006e6a11974088a46d42b903418eJohann
851b362b15af34006e6a11974088a46d42b903418eJohann// Declares the flags.
861b362b15af34006e6a11974088a46d42b903418eJohann
871b362b15af34006e6a11974088a46d42b903418eJohann// This flag temporary enables the disabled tests.
881b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(also_run_disabled_tests);
891b362b15af34006e6a11974088a46d42b903418eJohann
901b362b15af34006e6a11974088a46d42b903418eJohann// This flag brings the debugger on an assertion failure.
911b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(break_on_failure);
921b362b15af34006e6a11974088a46d42b903418eJohann
931b362b15af34006e6a11974088a46d42b903418eJohann// This flag controls whether Google Test catches all test-thrown exceptions
941b362b15af34006e6a11974088a46d42b903418eJohann// and logs them as failures.
951b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(catch_exceptions);
961b362b15af34006e6a11974088a46d42b903418eJohann
971b362b15af34006e6a11974088a46d42b903418eJohann// This flag enables using colors in terminal output. Available values are
981b362b15af34006e6a11974088a46d42b903418eJohann// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
991b362b15af34006e6a11974088a46d42b903418eJohann// to let Google Test decide.
1001b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_string_(color);
1011b362b15af34006e6a11974088a46d42b903418eJohann
1021b362b15af34006e6a11974088a46d42b903418eJohann// This flag sets up the filter to select by name using a glob pattern
1031b362b15af34006e6a11974088a46d42b903418eJohann// the tests to run. If the filter is not given all tests are executed.
1041b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_string_(filter);
1051b362b15af34006e6a11974088a46d42b903418eJohann
1061b362b15af34006e6a11974088a46d42b903418eJohann// This flag causes the Google Test to list tests. None of the tests listed
1071b362b15af34006e6a11974088a46d42b903418eJohann// are actually run if the flag is provided.
1081b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(list_tests);
1091b362b15af34006e6a11974088a46d42b903418eJohann
1101b362b15af34006e6a11974088a46d42b903418eJohann// This flag controls whether Google Test emits a detailed XML report to a file
1111b362b15af34006e6a11974088a46d42b903418eJohann// in addition to its normal textual output.
1121b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_string_(output);
1131b362b15af34006e6a11974088a46d42b903418eJohann
1141b362b15af34006e6a11974088a46d42b903418eJohann// This flags control whether Google Test prints the elapsed time for each
1151b362b15af34006e6a11974088a46d42b903418eJohann// test.
1161b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(print_time);
1171b362b15af34006e6a11974088a46d42b903418eJohann
1181b362b15af34006e6a11974088a46d42b903418eJohann// This flag specifies the random number seed.
1191b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_int32_(random_seed);
1201b362b15af34006e6a11974088a46d42b903418eJohann
1211b362b15af34006e6a11974088a46d42b903418eJohann// This flag sets how many times the tests are repeated. The default value
1221b362b15af34006e6a11974088a46d42b903418eJohann// is 1. If the value is -1 the tests are repeating forever.
1231b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_int32_(repeat);
1241b362b15af34006e6a11974088a46d42b903418eJohann
1251b362b15af34006e6a11974088a46d42b903418eJohann// This flag controls whether Google Test includes Google Test internal
1261b362b15af34006e6a11974088a46d42b903418eJohann// stack frames in failure stack traces.
1271b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(show_internal_stack_frames);
1281b362b15af34006e6a11974088a46d42b903418eJohann
1291b362b15af34006e6a11974088a46d42b903418eJohann// When this flag is specified, tests' order is randomized on every iteration.
1301b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(shuffle);
1311b362b15af34006e6a11974088a46d42b903418eJohann
1321b362b15af34006e6a11974088a46d42b903418eJohann// This flag specifies the maximum number of stack frames to be
1331b362b15af34006e6a11974088a46d42b903418eJohann// printed in a failure message.
1341b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_int32_(stack_trace_depth);
1351b362b15af34006e6a11974088a46d42b903418eJohann
1361b362b15af34006e6a11974088a46d42b903418eJohann// When this flag is specified, a failed assertion will throw an
1371b362b15af34006e6a11974088a46d42b903418eJohann// exception if exceptions are enabled, or exit the program with a
1381b362b15af34006e6a11974088a46d42b903418eJohann// non-zero code otherwise.
1391b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_bool_(throw_on_failure);
1401b362b15af34006e6a11974088a46d42b903418eJohann
1411b362b15af34006e6a11974088a46d42b903418eJohann// When this flag is set with a "host:port" string, on supported
1421b362b15af34006e6a11974088a46d42b903418eJohann// platforms test results are streamed to the specified port on
1431b362b15af34006e6a11974088a46d42b903418eJohann// the specified host machine.
1441b362b15af34006e6a11974088a46d42b903418eJohannGTEST_DECLARE_string_(stream_result_to);
1451b362b15af34006e6a11974088a46d42b903418eJohann
1461b362b15af34006e6a11974088a46d42b903418eJohann// The upper limit for valid stack trace depths.
1471b362b15af34006e6a11974088a46d42b903418eJohannconst int kMaxStackTraceDepth = 100;
1481b362b15af34006e6a11974088a46d42b903418eJohann
1491b362b15af34006e6a11974088a46d42b903418eJohannnamespace internal {
1501b362b15af34006e6a11974088a46d42b903418eJohann
1511b362b15af34006e6a11974088a46d42b903418eJohannclass AssertHelper;
1521b362b15af34006e6a11974088a46d42b903418eJohannclass DefaultGlobalTestPartResultReporter;
1531b362b15af34006e6a11974088a46d42b903418eJohannclass ExecDeathTest;
1541b362b15af34006e6a11974088a46d42b903418eJohannclass NoExecDeathTest;
1551b362b15af34006e6a11974088a46d42b903418eJohannclass FinalSuccessChecker;
1561b362b15af34006e6a11974088a46d42b903418eJohannclass GTestFlagSaver;
1575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass StreamingListenerTest;
1581b362b15af34006e6a11974088a46d42b903418eJohannclass TestResultAccessor;
1591b362b15af34006e6a11974088a46d42b903418eJohannclass TestEventListenersAccessor;
1601b362b15af34006e6a11974088a46d42b903418eJohannclass TestEventRepeater;
1615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass UnitTestRecordPropertyTestHelper;
1621b362b15af34006e6a11974088a46d42b903418eJohannclass WindowsDeathTest;
1631b362b15af34006e6a11974088a46d42b903418eJohannclass UnitTestImpl* GetUnitTestImpl();
1641b362b15af34006e6a11974088a46d42b903418eJohannvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,
1655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang                                    const std::string& message);
1661b362b15af34006e6a11974088a46d42b903418eJohann
1671b362b15af34006e6a11974088a46d42b903418eJohann}  // namespace internal
1681b362b15af34006e6a11974088a46d42b903418eJohann
1691b362b15af34006e6a11974088a46d42b903418eJohann// The friend relationship of some of these classes is cyclic.
1701b362b15af34006e6a11974088a46d42b903418eJohann// If we don't forward declare them the compiler might confuse the classes
1711b362b15af34006e6a11974088a46d42b903418eJohann// in friendship clauses with same named classes on the scope.
1721b362b15af34006e6a11974088a46d42b903418eJohannclass Test;
1731b362b15af34006e6a11974088a46d42b903418eJohannclass TestCase;
1741b362b15af34006e6a11974088a46d42b903418eJohannclass TestInfo;
1751b362b15af34006e6a11974088a46d42b903418eJohannclass UnitTest;
1761b362b15af34006e6a11974088a46d42b903418eJohann
1771b362b15af34006e6a11974088a46d42b903418eJohann// A class for indicating whether an assertion was successful.  When
1781b362b15af34006e6a11974088a46d42b903418eJohann// the assertion wasn't successful, the AssertionResult object
1791b362b15af34006e6a11974088a46d42b903418eJohann// remembers a non-empty message that describes how it failed.
1801b362b15af34006e6a11974088a46d42b903418eJohann//
1811b362b15af34006e6a11974088a46d42b903418eJohann// To create an instance of this class, use one of the factory functions
1821b362b15af34006e6a11974088a46d42b903418eJohann// (AssertionSuccess() and AssertionFailure()).
1831b362b15af34006e6a11974088a46d42b903418eJohann//
1841b362b15af34006e6a11974088a46d42b903418eJohann// This class is useful for two purposes:
1851b362b15af34006e6a11974088a46d42b903418eJohann//   1. Defining predicate functions to be used with Boolean test assertions
1861b362b15af34006e6a11974088a46d42b903418eJohann//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
1871b362b15af34006e6a11974088a46d42b903418eJohann//   2. Defining predicate-format functions to be
1881b362b15af34006e6a11974088a46d42b903418eJohann//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
1891b362b15af34006e6a11974088a46d42b903418eJohann//
1901b362b15af34006e6a11974088a46d42b903418eJohann// For example, if you define IsEven predicate:
1911b362b15af34006e6a11974088a46d42b903418eJohann//
1921b362b15af34006e6a11974088a46d42b903418eJohann//   testing::AssertionResult IsEven(int n) {
1931b362b15af34006e6a11974088a46d42b903418eJohann//     if ((n % 2) == 0)
1941b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionSuccess();
1951b362b15af34006e6a11974088a46d42b903418eJohann//     else
1961b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionFailure() << n << " is odd";
1971b362b15af34006e6a11974088a46d42b903418eJohann//   }
1981b362b15af34006e6a11974088a46d42b903418eJohann//
1991b362b15af34006e6a11974088a46d42b903418eJohann// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
2001b362b15af34006e6a11974088a46d42b903418eJohann// will print the message
2011b362b15af34006e6a11974088a46d42b903418eJohann//
2021b362b15af34006e6a11974088a46d42b903418eJohann//   Value of: IsEven(Fib(5))
2031b362b15af34006e6a11974088a46d42b903418eJohann//     Actual: false (5 is odd)
2041b362b15af34006e6a11974088a46d42b903418eJohann//   Expected: true
2051b362b15af34006e6a11974088a46d42b903418eJohann//
2061b362b15af34006e6a11974088a46d42b903418eJohann// instead of a more opaque
2071b362b15af34006e6a11974088a46d42b903418eJohann//
2081b362b15af34006e6a11974088a46d42b903418eJohann//   Value of: IsEven(Fib(5))
2091b362b15af34006e6a11974088a46d42b903418eJohann//     Actual: false
2101b362b15af34006e6a11974088a46d42b903418eJohann//   Expected: true
2111b362b15af34006e6a11974088a46d42b903418eJohann//
2121b362b15af34006e6a11974088a46d42b903418eJohann// in case IsEven is a simple Boolean predicate.
2131b362b15af34006e6a11974088a46d42b903418eJohann//
2141b362b15af34006e6a11974088a46d42b903418eJohann// If you expect your predicate to be reused and want to support informative
2151b362b15af34006e6a11974088a46d42b903418eJohann// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
2161b362b15af34006e6a11974088a46d42b903418eJohann// about half as often as positive ones in our tests), supply messages for
2171b362b15af34006e6a11974088a46d42b903418eJohann// both success and failure cases:
2181b362b15af34006e6a11974088a46d42b903418eJohann//
2191b362b15af34006e6a11974088a46d42b903418eJohann//   testing::AssertionResult IsEven(int n) {
2201b362b15af34006e6a11974088a46d42b903418eJohann//     if ((n % 2) == 0)
2211b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionSuccess() << n << " is even";
2221b362b15af34006e6a11974088a46d42b903418eJohann//     else
2231b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionFailure() << n << " is odd";
2241b362b15af34006e6a11974088a46d42b903418eJohann//   }
2251b362b15af34006e6a11974088a46d42b903418eJohann//
2261b362b15af34006e6a11974088a46d42b903418eJohann// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
2271b362b15af34006e6a11974088a46d42b903418eJohann//
2281b362b15af34006e6a11974088a46d42b903418eJohann//   Value of: IsEven(Fib(6))
2291b362b15af34006e6a11974088a46d42b903418eJohann//     Actual: true (8 is even)
2301b362b15af34006e6a11974088a46d42b903418eJohann//   Expected: false
2311b362b15af34006e6a11974088a46d42b903418eJohann//
2321b362b15af34006e6a11974088a46d42b903418eJohann// NB: Predicates that support negative Boolean assertions have reduced
2331b362b15af34006e6a11974088a46d42b903418eJohann// performance in positive ones so be careful not to use them in tests
2341b362b15af34006e6a11974088a46d42b903418eJohann// that have lots (tens of thousands) of positive Boolean assertions.
2351b362b15af34006e6a11974088a46d42b903418eJohann//
2361b362b15af34006e6a11974088a46d42b903418eJohann// To use this class with EXPECT_PRED_FORMAT assertions such as:
2371b362b15af34006e6a11974088a46d42b903418eJohann//
2381b362b15af34006e6a11974088a46d42b903418eJohann//   // Verifies that Foo() returns an even number.
2391b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_PRED_FORMAT1(IsEven, Foo());
2401b362b15af34006e6a11974088a46d42b903418eJohann//
2411b362b15af34006e6a11974088a46d42b903418eJohann// you need to define:
2421b362b15af34006e6a11974088a46d42b903418eJohann//
2431b362b15af34006e6a11974088a46d42b903418eJohann//   testing::AssertionResult IsEven(const char* expr, int n) {
2441b362b15af34006e6a11974088a46d42b903418eJohann//     if ((n % 2) == 0)
2451b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionSuccess();
2461b362b15af34006e6a11974088a46d42b903418eJohann//     else
2471b362b15af34006e6a11974088a46d42b903418eJohann//       return testing::AssertionFailure()
2481b362b15af34006e6a11974088a46d42b903418eJohann//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
2491b362b15af34006e6a11974088a46d42b903418eJohann//   }
2501b362b15af34006e6a11974088a46d42b903418eJohann//
2511b362b15af34006e6a11974088a46d42b903418eJohann// If Foo() returns 5, you will see the following message:
2521b362b15af34006e6a11974088a46d42b903418eJohann//
2531b362b15af34006e6a11974088a46d42b903418eJohann//   Expected: Foo() is even
2541b362b15af34006e6a11974088a46d42b903418eJohann//     Actual: it's 5
2551b362b15af34006e6a11974088a46d42b903418eJohann//
2561b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ AssertionResult {
2571b362b15af34006e6a11974088a46d42b903418eJohann public:
2581b362b15af34006e6a11974088a46d42b903418eJohann  // Copy constructor.
2591b362b15af34006e6a11974088a46d42b903418eJohann  // Used in EXPECT_TRUE/FALSE(assertion_result).
2601b362b15af34006e6a11974088a46d42b903418eJohann  AssertionResult(const AssertionResult& other);
2618b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
2628b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
2638b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
2641b362b15af34006e6a11974088a46d42b903418eJohann  // Used in the EXPECT_TRUE/FALSE(bool_expression).
2658b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  //
2668b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // T must be contextually convertible to bool.
2678b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  //
2688b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // The second parameter prevents this overload from being considered if
2698b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // the argument is implicitly convertible to AssertionResult. In that case
2708b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // we want AssertionResult's copy constructor to be used.
2718b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  template <typename T>
2728b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  explicit AssertionResult(
2738b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const T& success,
2748b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      typename internal::EnableIf<
2758b92989c89bec8632aa47dc58dc162f199d62edcJames Zern          !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
2768b92989c89bec8632aa47dc58dc162f199d62edcJames Zern          /*enabler*/ = NULL)
2778b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      : success_(success) {}
2788b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
2798b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  GTEST_DISABLE_MSC_WARNINGS_POP_()
2808b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
2818b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // Assignment operator.
2828b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  AssertionResult& operator=(AssertionResult other) {
2838b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    swap(other);
2848b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return *this;
2858b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  }
2861b362b15af34006e6a11974088a46d42b903418eJohann
2871b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the assertion succeeded.
2881b362b15af34006e6a11974088a46d42b903418eJohann  operator bool() const { return success_; }  // NOLINT
2891b362b15af34006e6a11974088a46d42b903418eJohann
2901b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
2911b362b15af34006e6a11974088a46d42b903418eJohann  AssertionResult operator!() const;
2921b362b15af34006e6a11974088a46d42b903418eJohann
2931b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the text streamed into this AssertionResult. Test assertions
2941b362b15af34006e6a11974088a46d42b903418eJohann  // use it when they fail (i.e., the predicate's outcome doesn't match the
2951b362b15af34006e6a11974088a46d42b903418eJohann  // assertion's expectation). When nothing has been streamed into the
2961b362b15af34006e6a11974088a46d42b903418eJohann  // object, returns an empty string.
2971b362b15af34006e6a11974088a46d42b903418eJohann  const char* message() const {
2981b362b15af34006e6a11974088a46d42b903418eJohann    return message_.get() != NULL ?  message_->c_str() : "";
2991b362b15af34006e6a11974088a46d42b903418eJohann  }
3001b362b15af34006e6a11974088a46d42b903418eJohann  // TODO(vladl@google.com): Remove this after making sure no clients use it.
3011b362b15af34006e6a11974088a46d42b903418eJohann  // Deprecated; please use message() instead.
3021b362b15af34006e6a11974088a46d42b903418eJohann  const char* failure_message() const { return message(); }
3031b362b15af34006e6a11974088a46d42b903418eJohann
3041b362b15af34006e6a11974088a46d42b903418eJohann  // Streams a custom failure message into this object.
3051b362b15af34006e6a11974088a46d42b903418eJohann  template <typename T> AssertionResult& operator<<(const T& value) {
3061b362b15af34006e6a11974088a46d42b903418eJohann    AppendMessage(Message() << value);
3071b362b15af34006e6a11974088a46d42b903418eJohann    return *this;
3081b362b15af34006e6a11974088a46d42b903418eJohann  }
3091b362b15af34006e6a11974088a46d42b903418eJohann
3101b362b15af34006e6a11974088a46d42b903418eJohann  // Allows streaming basic output manipulators such as endl or flush into
3111b362b15af34006e6a11974088a46d42b903418eJohann  // this object.
3121b362b15af34006e6a11974088a46d42b903418eJohann  AssertionResult& operator<<(
3131b362b15af34006e6a11974088a46d42b903418eJohann      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
3141b362b15af34006e6a11974088a46d42b903418eJohann    AppendMessage(Message() << basic_manipulator);
3151b362b15af34006e6a11974088a46d42b903418eJohann    return *this;
3161b362b15af34006e6a11974088a46d42b903418eJohann  }
3171b362b15af34006e6a11974088a46d42b903418eJohann
3181b362b15af34006e6a11974088a46d42b903418eJohann private:
3191b362b15af34006e6a11974088a46d42b903418eJohann  // Appends the contents of message to message_.
3201b362b15af34006e6a11974088a46d42b903418eJohann  void AppendMessage(const Message& a_message) {
3211b362b15af34006e6a11974088a46d42b903418eJohann    if (message_.get() == NULL)
3221b362b15af34006e6a11974088a46d42b903418eJohann      message_.reset(new ::std::string);
3231b362b15af34006e6a11974088a46d42b903418eJohann    message_->append(a_message.GetString().c_str());
3241b362b15af34006e6a11974088a46d42b903418eJohann  }
3251b362b15af34006e6a11974088a46d42b903418eJohann
3268b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // Swap the contents of this AssertionResult with other.
3278b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  void swap(AssertionResult& other);
3288b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
3291b362b15af34006e6a11974088a46d42b903418eJohann  // Stores result of the assertion predicate.
3301b362b15af34006e6a11974088a46d42b903418eJohann  bool success_;
3311b362b15af34006e6a11974088a46d42b903418eJohann  // Stores the message describing the condition in case the expectation
3321b362b15af34006e6a11974088a46d42b903418eJohann  // construct is not satisfied with the predicate's outcome.
3331b362b15af34006e6a11974088a46d42b903418eJohann  // Referenced via a pointer to avoid taking too much stack frame space
3341b362b15af34006e6a11974088a46d42b903418eJohann  // with test assertions.
3351b362b15af34006e6a11974088a46d42b903418eJohann  internal::scoped_ptr< ::std::string> message_;
3361b362b15af34006e6a11974088a46d42b903418eJohann};
3371b362b15af34006e6a11974088a46d42b903418eJohann
3381b362b15af34006e6a11974088a46d42b903418eJohann// Makes a successful assertion result.
3391b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult AssertionSuccess();
3401b362b15af34006e6a11974088a46d42b903418eJohann
3411b362b15af34006e6a11974088a46d42b903418eJohann// Makes a failed assertion result.
3421b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult AssertionFailure();
3431b362b15af34006e6a11974088a46d42b903418eJohann
3441b362b15af34006e6a11974088a46d42b903418eJohann// Makes a failed assertion result with the given failure message.
3451b362b15af34006e6a11974088a46d42b903418eJohann// Deprecated; use AssertionFailure() << msg.
3461b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult AssertionFailure(const Message& msg);
3471b362b15af34006e6a11974088a46d42b903418eJohann
3481b362b15af34006e6a11974088a46d42b903418eJohann// The abstract class that all tests inherit from.
3491b362b15af34006e6a11974088a46d42b903418eJohann//
3501b362b15af34006e6a11974088a46d42b903418eJohann// In Google Test, a unit test program contains one or many TestCases, and
3511b362b15af34006e6a11974088a46d42b903418eJohann// each TestCase contains one or many Tests.
3521b362b15af34006e6a11974088a46d42b903418eJohann//
3531b362b15af34006e6a11974088a46d42b903418eJohann// When you define a test using the TEST macro, you don't need to
3541b362b15af34006e6a11974088a46d42b903418eJohann// explicitly derive from Test - the TEST macro automatically does
3551b362b15af34006e6a11974088a46d42b903418eJohann// this for you.
3561b362b15af34006e6a11974088a46d42b903418eJohann//
3571b362b15af34006e6a11974088a46d42b903418eJohann// The only time you derive from Test is when defining a test fixture
3581b362b15af34006e6a11974088a46d42b903418eJohann// to be used a TEST_F.  For example:
3591b362b15af34006e6a11974088a46d42b903418eJohann//
3601b362b15af34006e6a11974088a46d42b903418eJohann//   class FooTest : public testing::Test {
3611b362b15af34006e6a11974088a46d42b903418eJohann//    protected:
3628b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//     void SetUp() override { ... }
3638b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//     void TearDown() override { ... }
3641b362b15af34006e6a11974088a46d42b903418eJohann//     ...
3651b362b15af34006e6a11974088a46d42b903418eJohann//   };
3661b362b15af34006e6a11974088a46d42b903418eJohann//
3671b362b15af34006e6a11974088a46d42b903418eJohann//   TEST_F(FooTest, Bar) { ... }
3681b362b15af34006e6a11974088a46d42b903418eJohann//   TEST_F(FooTest, Baz) { ... }
3691b362b15af34006e6a11974088a46d42b903418eJohann//
3701b362b15af34006e6a11974088a46d42b903418eJohann// Test is not copyable.
3711b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ Test {
3721b362b15af34006e6a11974088a46d42b903418eJohann public:
3731b362b15af34006e6a11974088a46d42b903418eJohann  friend class TestInfo;
3741b362b15af34006e6a11974088a46d42b903418eJohann
3751b362b15af34006e6a11974088a46d42b903418eJohann  // Defines types for pointers to functions that set up and tear down
3761b362b15af34006e6a11974088a46d42b903418eJohann  // a test case.
3771b362b15af34006e6a11974088a46d42b903418eJohann  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
3781b362b15af34006e6a11974088a46d42b903418eJohann  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
3791b362b15af34006e6a11974088a46d42b903418eJohann
3801b362b15af34006e6a11974088a46d42b903418eJohann  // The d'tor is virtual as we intend to inherit from Test.
3811b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~Test();
3821b362b15af34006e6a11974088a46d42b903418eJohann
3831b362b15af34006e6a11974088a46d42b903418eJohann  // Sets up the stuff shared by all tests in this test case.
3841b362b15af34006e6a11974088a46d42b903418eJohann  //
3851b362b15af34006e6a11974088a46d42b903418eJohann  // Google Test will call Foo::SetUpTestCase() before running the first
3861b362b15af34006e6a11974088a46d42b903418eJohann  // test in test case Foo.  Hence a sub-class can define its own
3871b362b15af34006e6a11974088a46d42b903418eJohann  // SetUpTestCase() method to shadow the one defined in the super
3881b362b15af34006e6a11974088a46d42b903418eJohann  // class.
3891b362b15af34006e6a11974088a46d42b903418eJohann  static void SetUpTestCase() {}
3901b362b15af34006e6a11974088a46d42b903418eJohann
3911b362b15af34006e6a11974088a46d42b903418eJohann  // Tears down the stuff shared by all tests in this test case.
3921b362b15af34006e6a11974088a46d42b903418eJohann  //
3931b362b15af34006e6a11974088a46d42b903418eJohann  // Google Test will call Foo::TearDownTestCase() after running the last
3941b362b15af34006e6a11974088a46d42b903418eJohann  // test in test case Foo.  Hence a sub-class can define its own
3951b362b15af34006e6a11974088a46d42b903418eJohann  // TearDownTestCase() method to shadow the one defined in the super
3961b362b15af34006e6a11974088a46d42b903418eJohann  // class.
3971b362b15af34006e6a11974088a46d42b903418eJohann  static void TearDownTestCase() {}
3981b362b15af34006e6a11974088a46d42b903418eJohann
3991b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the current test has a fatal failure.
4001b362b15af34006e6a11974088a46d42b903418eJohann  static bool HasFatalFailure();
4011b362b15af34006e6a11974088a46d42b903418eJohann
4021b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the current test has a non-fatal failure.
4031b362b15af34006e6a11974088a46d42b903418eJohann  static bool HasNonfatalFailure();
4041b362b15af34006e6a11974088a46d42b903418eJohann
4051b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the current test has a (either fatal or
4061b362b15af34006e6a11974088a46d42b903418eJohann  // non-fatal) failure.
4071b362b15af34006e6a11974088a46d42b903418eJohann  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
4081b362b15af34006e6a11974088a46d42b903418eJohann
4095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Logs a property for the current test, test case, or for the entire
4105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // invocation of the test program when used outside of the context of a
4115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // test case.  Only the last value for a given key is remembered.  These
4125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // are public static so they can be called from utility functions that are
4135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // not members of the test fixture.  Calls to RecordProperty made during
4145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // lifespan of the test (from the moment its constructor starts to the
4155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // moment its destructor finishes) will be output in XML as attributes of
4165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // the <testcase> element.  Properties recorded from fixture's
4175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // SetUpTestCase or TearDownTestCase are logged as attributes of the
4185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // corresponding <testsuite> element.  Calls to RecordProperty made in the
4195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // global context (before or after invocation of RUN_ALL_TESTS and from
4205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // SetUp/TearDown method of Environment objects registered with Google
4215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Test) will be output as attributes of the <testsuites> element.
4225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  static void RecordProperty(const std::string& key, const std::string& value);
4235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  static void RecordProperty(const std::string& key, int value);
4241b362b15af34006e6a11974088a46d42b903418eJohann
4251b362b15af34006e6a11974088a46d42b903418eJohann protected:
4261b362b15af34006e6a11974088a46d42b903418eJohann  // Creates a Test object.
4271b362b15af34006e6a11974088a46d42b903418eJohann  Test();
4281b362b15af34006e6a11974088a46d42b903418eJohann
4291b362b15af34006e6a11974088a46d42b903418eJohann  // Sets up the test fixture.
4301b362b15af34006e6a11974088a46d42b903418eJohann  virtual void SetUp();
4311b362b15af34006e6a11974088a46d42b903418eJohann
4321b362b15af34006e6a11974088a46d42b903418eJohann  // Tears down the test fixture.
4331b362b15af34006e6a11974088a46d42b903418eJohann  virtual void TearDown();
4341b362b15af34006e6a11974088a46d42b903418eJohann
4351b362b15af34006e6a11974088a46d42b903418eJohann private:
4361b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the current test has the same fixture class as
4371b362b15af34006e6a11974088a46d42b903418eJohann  // the first test in the current test case.
4381b362b15af34006e6a11974088a46d42b903418eJohann  static bool HasSameFixtureClass();
4391b362b15af34006e6a11974088a46d42b903418eJohann
4401b362b15af34006e6a11974088a46d42b903418eJohann  // Runs the test after the test fixture has been set up.
4411b362b15af34006e6a11974088a46d42b903418eJohann  //
4421b362b15af34006e6a11974088a46d42b903418eJohann  // A sub-class must implement this to define the test logic.
4431b362b15af34006e6a11974088a46d42b903418eJohann  //
4441b362b15af34006e6a11974088a46d42b903418eJohann  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
4451b362b15af34006e6a11974088a46d42b903418eJohann  // Instead, use the TEST or TEST_F macro.
4461b362b15af34006e6a11974088a46d42b903418eJohann  virtual void TestBody() = 0;
4471b362b15af34006e6a11974088a46d42b903418eJohann
4481b362b15af34006e6a11974088a46d42b903418eJohann  // Sets up, executes, and tears down the test.
4491b362b15af34006e6a11974088a46d42b903418eJohann  void Run();
4501b362b15af34006e6a11974088a46d42b903418eJohann
4511b362b15af34006e6a11974088a46d42b903418eJohann  // Deletes self.  We deliberately pick an unusual name for this
4521b362b15af34006e6a11974088a46d42b903418eJohann  // internal method to avoid clashing with names used in user TESTs.
4531b362b15af34006e6a11974088a46d42b903418eJohann  void DeleteSelf_() { delete this; }
4541b362b15af34006e6a11974088a46d42b903418eJohann
4558b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
4561b362b15af34006e6a11974088a46d42b903418eJohann
4578b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // Often a user misspells SetUp() as Setup() and spends a long time
4581b362b15af34006e6a11974088a46d42b903418eJohann  // wondering why it is never called by Google Test.  The declaration of
4591b362b15af34006e6a11974088a46d42b903418eJohann  // the following method is solely for catching such an error at
4601b362b15af34006e6a11974088a46d42b903418eJohann  // compile time:
4611b362b15af34006e6a11974088a46d42b903418eJohann  //
4621b362b15af34006e6a11974088a46d42b903418eJohann  //   - The return type is deliberately chosen to be not void, so it
4638b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  //   will be a conflict if void Setup() is declared in the user's
4648b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  //   test fixture.
4651b362b15af34006e6a11974088a46d42b903418eJohann  //
4661b362b15af34006e6a11974088a46d42b903418eJohann  //   - This method is private, so it will be another compiler error
4678b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  //   if the method is called from the user's test fixture.
4681b362b15af34006e6a11974088a46d42b903418eJohann  //
4691b362b15af34006e6a11974088a46d42b903418eJohann  // DO NOT OVERRIDE THIS FUNCTION.
4701b362b15af34006e6a11974088a46d42b903418eJohann  //
4711b362b15af34006e6a11974088a46d42b903418eJohann  // If you see an error about overriding the following function or
4721b362b15af34006e6a11974088a46d42b903418eJohann  // about it being private, you have mis-spelled SetUp() as Setup().
4731b362b15af34006e6a11974088a46d42b903418eJohann  struct Setup_should_be_spelled_SetUp {};
4741b362b15af34006e6a11974088a46d42b903418eJohann  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
4751b362b15af34006e6a11974088a46d42b903418eJohann
4761b362b15af34006e6a11974088a46d42b903418eJohann  // We disallow copying Tests.
4771b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
4781b362b15af34006e6a11974088a46d42b903418eJohann};
4791b362b15af34006e6a11974088a46d42b903418eJohann
4801b362b15af34006e6a11974088a46d42b903418eJohanntypedef internal::TimeInMillis TimeInMillis;
4811b362b15af34006e6a11974088a46d42b903418eJohann
4821b362b15af34006e6a11974088a46d42b903418eJohann// A copyable object representing a user specified test property which can be
4831b362b15af34006e6a11974088a46d42b903418eJohann// output as a key/value string pair.
4841b362b15af34006e6a11974088a46d42b903418eJohann//
4851b362b15af34006e6a11974088a46d42b903418eJohann// Don't inherit from TestProperty as its destructor is not virtual.
4861b362b15af34006e6a11974088a46d42b903418eJohannclass TestProperty {
4871b362b15af34006e6a11974088a46d42b903418eJohann public:
4881b362b15af34006e6a11974088a46d42b903418eJohann  // C'tor.  TestProperty does NOT have a default constructor.
4891b362b15af34006e6a11974088a46d42b903418eJohann  // Always use this constructor (with parameters) to create a
4901b362b15af34006e6a11974088a46d42b903418eJohann  // TestProperty object.
4915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  TestProperty(const std::string& a_key, const std::string& a_value) :
4921b362b15af34006e6a11974088a46d42b903418eJohann    key_(a_key), value_(a_value) {
4931b362b15af34006e6a11974088a46d42b903418eJohann  }
4941b362b15af34006e6a11974088a46d42b903418eJohann
4951b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the user supplied key.
4961b362b15af34006e6a11974088a46d42b903418eJohann  const char* key() const {
4971b362b15af34006e6a11974088a46d42b903418eJohann    return key_.c_str();
4981b362b15af34006e6a11974088a46d42b903418eJohann  }
4991b362b15af34006e6a11974088a46d42b903418eJohann
5001b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the user supplied value.
5011b362b15af34006e6a11974088a46d42b903418eJohann  const char* value() const {
5021b362b15af34006e6a11974088a46d42b903418eJohann    return value_.c_str();
5031b362b15af34006e6a11974088a46d42b903418eJohann  }
5041b362b15af34006e6a11974088a46d42b903418eJohann
5051b362b15af34006e6a11974088a46d42b903418eJohann  // Sets a new value, overriding the one supplied in the constructor.
5065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  void SetValue(const std::string& new_value) {
5071b362b15af34006e6a11974088a46d42b903418eJohann    value_ = new_value;
5081b362b15af34006e6a11974088a46d42b903418eJohann  }
5091b362b15af34006e6a11974088a46d42b903418eJohann
5101b362b15af34006e6a11974088a46d42b903418eJohann private:
5111b362b15af34006e6a11974088a46d42b903418eJohann  // The key supplied by the user.
5125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  std::string key_;
5131b362b15af34006e6a11974088a46d42b903418eJohann  // The value supplied by the user.
5145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  std::string value_;
5151b362b15af34006e6a11974088a46d42b903418eJohann};
5161b362b15af34006e6a11974088a46d42b903418eJohann
5171b362b15af34006e6a11974088a46d42b903418eJohann// The result of a single Test.  This includes a list of
5181b362b15af34006e6a11974088a46d42b903418eJohann// TestPartResults, a list of TestProperties, a count of how many
5191b362b15af34006e6a11974088a46d42b903418eJohann// death tests there are in the Test, and how much time it took to run
5201b362b15af34006e6a11974088a46d42b903418eJohann// the Test.
5211b362b15af34006e6a11974088a46d42b903418eJohann//
5221b362b15af34006e6a11974088a46d42b903418eJohann// TestResult is not copyable.
5231b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ TestResult {
5241b362b15af34006e6a11974088a46d42b903418eJohann public:
5251b362b15af34006e6a11974088a46d42b903418eJohann  // Creates an empty TestResult.
5261b362b15af34006e6a11974088a46d42b903418eJohann  TestResult();
5271b362b15af34006e6a11974088a46d42b903418eJohann
5281b362b15af34006e6a11974088a46d42b903418eJohann  // D'tor.  Do not inherit from TestResult.
5291b362b15af34006e6a11974088a46d42b903418eJohann  ~TestResult();
5301b362b15af34006e6a11974088a46d42b903418eJohann
5311b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of all test parts.  This is the sum of the number
5321b362b15af34006e6a11974088a46d42b903418eJohann  // of successful test parts and the number of failed test parts.
5331b362b15af34006e6a11974088a46d42b903418eJohann  int total_part_count() const;
5341b362b15af34006e6a11974088a46d42b903418eJohann
5351b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the number of the test properties.
5361b362b15af34006e6a11974088a46d42b903418eJohann  int test_property_count() const;
5371b362b15af34006e6a11974088a46d42b903418eJohann
5381b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test passed (i.e. no test part failed).
5391b362b15af34006e6a11974088a46d42b903418eJohann  bool Passed() const { return !Failed(); }
5401b362b15af34006e6a11974088a46d42b903418eJohann
5411b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test failed.
5421b362b15af34006e6a11974088a46d42b903418eJohann  bool Failed() const;
5431b362b15af34006e6a11974088a46d42b903418eJohann
5441b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test fatally failed.
5451b362b15af34006e6a11974088a46d42b903418eJohann  bool HasFatalFailure() const;
5461b362b15af34006e6a11974088a46d42b903418eJohann
5471b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test has a non-fatal failure.
5481b362b15af34006e6a11974088a46d42b903418eJohann  bool HasNonfatalFailure() const;
5491b362b15af34006e6a11974088a46d42b903418eJohann
5501b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the elapsed time, in milliseconds.
5511b362b15af34006e6a11974088a46d42b903418eJohann  TimeInMillis elapsed_time() const { return elapsed_time_; }
5521b362b15af34006e6a11974088a46d42b903418eJohann
5531b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the i-th test part result among all the results. i can range
5541b362b15af34006e6a11974088a46d42b903418eJohann  // from 0 to test_property_count() - 1. If i is not in that range, aborts
5551b362b15af34006e6a11974088a46d42b903418eJohann  // the program.
5561b362b15af34006e6a11974088a46d42b903418eJohann  const TestPartResult& GetTestPartResult(int i) const;
5571b362b15af34006e6a11974088a46d42b903418eJohann
5581b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the i-th test property. i can range from 0 to
5591b362b15af34006e6a11974088a46d42b903418eJohann  // test_property_count() - 1. If i is not in that range, aborts the
5601b362b15af34006e6a11974088a46d42b903418eJohann  // program.
5611b362b15af34006e6a11974088a46d42b903418eJohann  const TestProperty& GetTestProperty(int i) const;
5621b362b15af34006e6a11974088a46d42b903418eJohann
5631b362b15af34006e6a11974088a46d42b903418eJohann private:
5641b362b15af34006e6a11974088a46d42b903418eJohann  friend class TestInfo;
5655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  friend class TestCase;
5661b362b15af34006e6a11974088a46d42b903418eJohann  friend class UnitTest;
5671b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::DefaultGlobalTestPartResultReporter;
5681b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::ExecDeathTest;
5691b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::TestResultAccessor;
5701b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::UnitTestImpl;
5711b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::WindowsDeathTest;
5721b362b15af34006e6a11974088a46d42b903418eJohann
5731b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the vector of TestPartResults.
5741b362b15af34006e6a11974088a46d42b903418eJohann  const std::vector<TestPartResult>& test_part_results() const {
5751b362b15af34006e6a11974088a46d42b903418eJohann    return test_part_results_;
5761b362b15af34006e6a11974088a46d42b903418eJohann  }
5771b362b15af34006e6a11974088a46d42b903418eJohann
5781b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the vector of TestProperties.
5791b362b15af34006e6a11974088a46d42b903418eJohann  const std::vector<TestProperty>& test_properties() const {
5801b362b15af34006e6a11974088a46d42b903418eJohann    return test_properties_;
5811b362b15af34006e6a11974088a46d42b903418eJohann  }
5821b362b15af34006e6a11974088a46d42b903418eJohann
5831b362b15af34006e6a11974088a46d42b903418eJohann  // Sets the elapsed time.
5841b362b15af34006e6a11974088a46d42b903418eJohann  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
5851b362b15af34006e6a11974088a46d42b903418eJohann
5861b362b15af34006e6a11974088a46d42b903418eJohann  // Adds a test property to the list. The property is validated and may add
5871b362b15af34006e6a11974088a46d42b903418eJohann  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
5881b362b15af34006e6a11974088a46d42b903418eJohann  // key names). If a property is already recorded for the same key, the
5891b362b15af34006e6a11974088a46d42b903418eJohann  // value will be updated, rather than storing multiple values for the same
5905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // key.  xml_element specifies the element for which the property is being
5915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // recorded and is used for validation.
5925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  void RecordProperty(const std::string& xml_element,
5935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang                      const TestProperty& test_property);
5941b362b15af34006e6a11974088a46d42b903418eJohann
5951b362b15af34006e6a11974088a46d42b903418eJohann  // Adds a failure if the key is a reserved attribute of Google Test
5961b362b15af34006e6a11974088a46d42b903418eJohann  // testcase tags.  Returns true if the property is valid.
5971b362b15af34006e6a11974088a46d42b903418eJohann  // TODO(russr): Validate attribute names are legal and human readable.
5985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  static bool ValidateTestProperty(const std::string& xml_element,
5995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang                                   const TestProperty& test_property);
6001b362b15af34006e6a11974088a46d42b903418eJohann
6011b362b15af34006e6a11974088a46d42b903418eJohann  // Adds a test part result to the list.
6021b362b15af34006e6a11974088a46d42b903418eJohann  void AddTestPartResult(const TestPartResult& test_part_result);
6031b362b15af34006e6a11974088a46d42b903418eJohann
6041b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the death test count.
6051b362b15af34006e6a11974088a46d42b903418eJohann  int death_test_count() const { return death_test_count_; }
6061b362b15af34006e6a11974088a46d42b903418eJohann
6071b362b15af34006e6a11974088a46d42b903418eJohann  // Increments the death test count, returning the new count.
6081b362b15af34006e6a11974088a46d42b903418eJohann  int increment_death_test_count() { return ++death_test_count_; }
6091b362b15af34006e6a11974088a46d42b903418eJohann
6101b362b15af34006e6a11974088a46d42b903418eJohann  // Clears the test part results.
6111b362b15af34006e6a11974088a46d42b903418eJohann  void ClearTestPartResults();
6121b362b15af34006e6a11974088a46d42b903418eJohann
6131b362b15af34006e6a11974088a46d42b903418eJohann  // Clears the object.
6141b362b15af34006e6a11974088a46d42b903418eJohann  void Clear();
6151b362b15af34006e6a11974088a46d42b903418eJohann
6161b362b15af34006e6a11974088a46d42b903418eJohann  // Protects mutable state of the property vector and of owned
6171b362b15af34006e6a11974088a46d42b903418eJohann  // properties, whose values may be updated.
6181b362b15af34006e6a11974088a46d42b903418eJohann  internal::Mutex test_properites_mutex_;
6191b362b15af34006e6a11974088a46d42b903418eJohann
6201b362b15af34006e6a11974088a46d42b903418eJohann  // The vector of TestPartResults
6211b362b15af34006e6a11974088a46d42b903418eJohann  std::vector<TestPartResult> test_part_results_;
6221b362b15af34006e6a11974088a46d42b903418eJohann  // The vector of TestProperties
6231b362b15af34006e6a11974088a46d42b903418eJohann  std::vector<TestProperty> test_properties_;
6241b362b15af34006e6a11974088a46d42b903418eJohann  // Running count of death tests.
6251b362b15af34006e6a11974088a46d42b903418eJohann  int death_test_count_;
6261b362b15af34006e6a11974088a46d42b903418eJohann  // The elapsed time, in milliseconds.
6271b362b15af34006e6a11974088a46d42b903418eJohann  TimeInMillis elapsed_time_;
6281b362b15af34006e6a11974088a46d42b903418eJohann
6291b362b15af34006e6a11974088a46d42b903418eJohann  // We disallow copying TestResult.
6301b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
6311b362b15af34006e6a11974088a46d42b903418eJohann};  // class TestResult
6321b362b15af34006e6a11974088a46d42b903418eJohann
6331b362b15af34006e6a11974088a46d42b903418eJohann// A TestInfo object stores the following information about a test:
6341b362b15af34006e6a11974088a46d42b903418eJohann//
6351b362b15af34006e6a11974088a46d42b903418eJohann//   Test case name
6361b362b15af34006e6a11974088a46d42b903418eJohann//   Test name
6371b362b15af34006e6a11974088a46d42b903418eJohann//   Whether the test should be run
6381b362b15af34006e6a11974088a46d42b903418eJohann//   A function pointer that creates the test object when invoked
6391b362b15af34006e6a11974088a46d42b903418eJohann//   Test result
6401b362b15af34006e6a11974088a46d42b903418eJohann//
6411b362b15af34006e6a11974088a46d42b903418eJohann// The constructor of TestInfo registers itself with the UnitTest
6421b362b15af34006e6a11974088a46d42b903418eJohann// singleton such that the RUN_ALL_TESTS() macro knows which tests to
6431b362b15af34006e6a11974088a46d42b903418eJohann// run.
6441b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ TestInfo {
6451b362b15af34006e6a11974088a46d42b903418eJohann public:
6461b362b15af34006e6a11974088a46d42b903418eJohann  // Destructs a TestInfo object.  This function is not virtual, so
6471b362b15af34006e6a11974088a46d42b903418eJohann  // don't inherit from TestInfo.
6481b362b15af34006e6a11974088a46d42b903418eJohann  ~TestInfo();
6491b362b15af34006e6a11974088a46d42b903418eJohann
6501b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the test case name.
6511b362b15af34006e6a11974088a46d42b903418eJohann  const char* test_case_name() const { return test_case_name_.c_str(); }
6521b362b15af34006e6a11974088a46d42b903418eJohann
6531b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the test name.
6541b362b15af34006e6a11974088a46d42b903418eJohann  const char* name() const { return name_.c_str(); }
6551b362b15af34006e6a11974088a46d42b903418eJohann
6561b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the name of the parameter type, or NULL if this is not a typed
6571b362b15af34006e6a11974088a46d42b903418eJohann  // or a type-parameterized test.
6581b362b15af34006e6a11974088a46d42b903418eJohann  const char* type_param() const {
6591b362b15af34006e6a11974088a46d42b903418eJohann    if (type_param_.get() != NULL)
6601b362b15af34006e6a11974088a46d42b903418eJohann      return type_param_->c_str();
6611b362b15af34006e6a11974088a46d42b903418eJohann    return NULL;
6621b362b15af34006e6a11974088a46d42b903418eJohann  }
6631b362b15af34006e6a11974088a46d42b903418eJohann
6641b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the text representation of the value parameter, or NULL if this
6651b362b15af34006e6a11974088a46d42b903418eJohann  // is not a value-parameterized test.
6661b362b15af34006e6a11974088a46d42b903418eJohann  const char* value_param() const {
6671b362b15af34006e6a11974088a46d42b903418eJohann    if (value_param_.get() != NULL)
6681b362b15af34006e6a11974088a46d42b903418eJohann      return value_param_->c_str();
6691b362b15af34006e6a11974088a46d42b903418eJohann    return NULL;
6701b362b15af34006e6a11974088a46d42b903418eJohann  }
6711b362b15af34006e6a11974088a46d42b903418eJohann
6728b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // Returns the file name where this test is defined.
6738b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  const char* file() const { return location_.file.c_str(); }
6748b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
6758b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  // Returns the line where this test is defined.
6768b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  int line() const { return location_.line; }
6778b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
6785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns true if this test should run, that is if the test is not
6795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // disabled (or it is disabled but the also_run_disabled_tests flag has
6805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // been specified) and its full name matches the user-specified filter.
6811b362b15af34006e6a11974088a46d42b903418eJohann  //
6821b362b15af34006e6a11974088a46d42b903418eJohann  // Google Test allows the user to filter the tests by their full names.
6831b362b15af34006e6a11974088a46d42b903418eJohann  // The full name of a test Bar in test case Foo is defined as
6841b362b15af34006e6a11974088a46d42b903418eJohann  // "Foo.Bar".  Only the tests that match the filter will run.
6851b362b15af34006e6a11974088a46d42b903418eJohann  //
6861b362b15af34006e6a11974088a46d42b903418eJohann  // A filter is a colon-separated list of glob (not regex) patterns,
6871b362b15af34006e6a11974088a46d42b903418eJohann  // optionally followed by a '-' and a colon-separated list of
6881b362b15af34006e6a11974088a46d42b903418eJohann  // negative patterns (tests to exclude).  A test is run if it
6891b362b15af34006e6a11974088a46d42b903418eJohann  // matches one of the positive patterns and does not match any of
6901b362b15af34006e6a11974088a46d42b903418eJohann  // the negative patterns.
6911b362b15af34006e6a11974088a46d42b903418eJohann  //
6921b362b15af34006e6a11974088a46d42b903418eJohann  // For example, *A*:Foo.* is a filter that matches any string that
6931b362b15af34006e6a11974088a46d42b903418eJohann  // contains the character 'A' or starts with "Foo.".
6941b362b15af34006e6a11974088a46d42b903418eJohann  bool should_run() const { return should_run_; }
6951b362b15af34006e6a11974088a46d42b903418eJohann
6965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns true iff this test will appear in the XML report.
6975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  bool is_reportable() const {
6985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    // For now, the XML report includes all tests matching the filter.
6995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    // In the future, we may trim tests that are excluded because of
7005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    // sharding.
7015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    return matches_filter_;
7025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  }
7035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
7041b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the result of the test.
7051b362b15af34006e6a11974088a46d42b903418eJohann  const TestResult* result() const { return &result_; }
7061b362b15af34006e6a11974088a46d42b903418eJohann
7071b362b15af34006e6a11974088a46d42b903418eJohann private:
7081b362b15af34006e6a11974088a46d42b903418eJohann#if GTEST_HAS_DEATH_TEST
7091b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::DefaultDeathTestFactory;
7101b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_HAS_DEATH_TEST
7111b362b15af34006e6a11974088a46d42b903418eJohann  friend class Test;
7121b362b15af34006e6a11974088a46d42b903418eJohann  friend class TestCase;
7131b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::UnitTestImpl;
7145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  friend class internal::StreamingListenerTest;
7151b362b15af34006e6a11974088a46d42b903418eJohann  friend TestInfo* internal::MakeAndRegisterTestInfo(
7165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      const char* test_case_name,
7175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      const char* name,
7181b362b15af34006e6a11974088a46d42b903418eJohann      const char* type_param,
7191b362b15af34006e6a11974088a46d42b903418eJohann      const char* value_param,
7208b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      internal::CodeLocation code_location,
7211b362b15af34006e6a11974088a46d42b903418eJohann      internal::TypeId fixture_class_id,
7221b362b15af34006e6a11974088a46d42b903418eJohann      Test::SetUpTestCaseFunc set_up_tc,
7231b362b15af34006e6a11974088a46d42b903418eJohann      Test::TearDownTestCaseFunc tear_down_tc,
7241b362b15af34006e6a11974088a46d42b903418eJohann      internal::TestFactoryBase* factory);
7251b362b15af34006e6a11974088a46d42b903418eJohann
7261b362b15af34006e6a11974088a46d42b903418eJohann  // Constructs a TestInfo object. The newly constructed instance assumes
7271b362b15af34006e6a11974088a46d42b903418eJohann  // ownership of the factory object.
7285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  TestInfo(const std::string& test_case_name,
7295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang           const std::string& name,
7305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang           const char* a_type_param,   // NULL if not a type-parameterized test
7315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang           const char* a_value_param,  // NULL if not a value-parameterized test
7328b92989c89bec8632aa47dc58dc162f199d62edcJames Zern           internal::CodeLocation a_code_location,
7331b362b15af34006e6a11974088a46d42b903418eJohann           internal::TypeId fixture_class_id,
7341b362b15af34006e6a11974088a46d42b903418eJohann           internal::TestFactoryBase* factory);
7351b362b15af34006e6a11974088a46d42b903418eJohann
7361b362b15af34006e6a11974088a46d42b903418eJohann  // Increments the number of death tests encountered in this test so
7371b362b15af34006e6a11974088a46d42b903418eJohann  // far.
7381b362b15af34006e6a11974088a46d42b903418eJohann  int increment_death_test_count() {
7391b362b15af34006e6a11974088a46d42b903418eJohann    return result_.increment_death_test_count();
7401b362b15af34006e6a11974088a46d42b903418eJohann  }
7411b362b15af34006e6a11974088a46d42b903418eJohann
7421b362b15af34006e6a11974088a46d42b903418eJohann  // Creates the test object, runs it, records its result, and then
7431b362b15af34006e6a11974088a46d42b903418eJohann  // deletes it.
7441b362b15af34006e6a11974088a46d42b903418eJohann  void Run();
7451b362b15af34006e6a11974088a46d42b903418eJohann
7461b362b15af34006e6a11974088a46d42b903418eJohann  static void ClearTestResult(TestInfo* test_info) {
7471b362b15af34006e6a11974088a46d42b903418eJohann    test_info->result_.Clear();
7481b362b15af34006e6a11974088a46d42b903418eJohann  }
7491b362b15af34006e6a11974088a46d42b903418eJohann
7501b362b15af34006e6a11974088a46d42b903418eJohann  // These fields are immutable properties of the test.
7511b362b15af34006e6a11974088a46d42b903418eJohann  const std::string test_case_name_;     // Test case name
7521b362b15af34006e6a11974088a46d42b903418eJohann  const std::string name_;               // Test name
7531b362b15af34006e6a11974088a46d42b903418eJohann  // Name of the parameter type, or NULL if this is not a typed or a
7541b362b15af34006e6a11974088a46d42b903418eJohann  // type-parameterized test.
7551b362b15af34006e6a11974088a46d42b903418eJohann  const internal::scoped_ptr<const ::std::string> type_param_;
7561b362b15af34006e6a11974088a46d42b903418eJohann  // Text representation of the value parameter, or NULL if this is not a
7571b362b15af34006e6a11974088a46d42b903418eJohann  // value-parameterized test.
7581b362b15af34006e6a11974088a46d42b903418eJohann  const internal::scoped_ptr<const ::std::string> value_param_;
7598b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  internal::CodeLocation location_;
7601b362b15af34006e6a11974088a46d42b903418eJohann  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
7611b362b15af34006e6a11974088a46d42b903418eJohann  bool should_run_;                 // True iff this test should run
7621b362b15af34006e6a11974088a46d42b903418eJohann  bool is_disabled_;                // True iff this test is disabled
7631b362b15af34006e6a11974088a46d42b903418eJohann  bool matches_filter_;             // True if this test matches the
7641b362b15af34006e6a11974088a46d42b903418eJohann                                    // user-specified filter.
7651b362b15af34006e6a11974088a46d42b903418eJohann  internal::TestFactoryBase* const factory_;  // The factory that creates
7661b362b15af34006e6a11974088a46d42b903418eJohann                                              // the test object
7671b362b15af34006e6a11974088a46d42b903418eJohann
7681b362b15af34006e6a11974088a46d42b903418eJohann  // This field is mutable and needs to be reset before running the
7691b362b15af34006e6a11974088a46d42b903418eJohann  // test for the second time.
7701b362b15af34006e6a11974088a46d42b903418eJohann  TestResult result_;
7711b362b15af34006e6a11974088a46d42b903418eJohann
7721b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
7731b362b15af34006e6a11974088a46d42b903418eJohann};
7741b362b15af34006e6a11974088a46d42b903418eJohann
7751b362b15af34006e6a11974088a46d42b903418eJohann// A test case, which consists of a vector of TestInfos.
7761b362b15af34006e6a11974088a46d42b903418eJohann//
7771b362b15af34006e6a11974088a46d42b903418eJohann// TestCase is not copyable.
7781b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ TestCase {
7791b362b15af34006e6a11974088a46d42b903418eJohann public:
7801b362b15af34006e6a11974088a46d42b903418eJohann  // Creates a TestCase with the given name.
7811b362b15af34006e6a11974088a46d42b903418eJohann  //
7821b362b15af34006e6a11974088a46d42b903418eJohann  // TestCase does NOT have a default constructor.  Always use this
7831b362b15af34006e6a11974088a46d42b903418eJohann  // constructor to create a TestCase object.
7841b362b15af34006e6a11974088a46d42b903418eJohann  //
7851b362b15af34006e6a11974088a46d42b903418eJohann  // Arguments:
7861b362b15af34006e6a11974088a46d42b903418eJohann  //
7871b362b15af34006e6a11974088a46d42b903418eJohann  //   name:         name of the test case
7881b362b15af34006e6a11974088a46d42b903418eJohann  //   a_type_param: the name of the test's type parameter, or NULL if
7891b362b15af34006e6a11974088a46d42b903418eJohann  //                 this is not a type-parameterized test.
7901b362b15af34006e6a11974088a46d42b903418eJohann  //   set_up_tc:    pointer to the function that sets up the test case
7911b362b15af34006e6a11974088a46d42b903418eJohann  //   tear_down_tc: pointer to the function that tears down the test case
7921b362b15af34006e6a11974088a46d42b903418eJohann  TestCase(const char* name, const char* a_type_param,
7931b362b15af34006e6a11974088a46d42b903418eJohann           Test::SetUpTestCaseFunc set_up_tc,
7941b362b15af34006e6a11974088a46d42b903418eJohann           Test::TearDownTestCaseFunc tear_down_tc);
7951b362b15af34006e6a11974088a46d42b903418eJohann
7961b362b15af34006e6a11974088a46d42b903418eJohann  // Destructor of TestCase.
7971b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~TestCase();
7981b362b15af34006e6a11974088a46d42b903418eJohann
7991b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the name of the TestCase.
8001b362b15af34006e6a11974088a46d42b903418eJohann  const char* name() const { return name_.c_str(); }
8011b362b15af34006e6a11974088a46d42b903418eJohann
8021b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the name of the parameter type, or NULL if this is not a
8031b362b15af34006e6a11974088a46d42b903418eJohann  // type-parameterized test case.
8041b362b15af34006e6a11974088a46d42b903418eJohann  const char* type_param() const {
8051b362b15af34006e6a11974088a46d42b903418eJohann    if (type_param_.get() != NULL)
8061b362b15af34006e6a11974088a46d42b903418eJohann      return type_param_->c_str();
8071b362b15af34006e6a11974088a46d42b903418eJohann    return NULL;
8081b362b15af34006e6a11974088a46d42b903418eJohann  }
8091b362b15af34006e6a11974088a46d42b903418eJohann
8101b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true if any test in this test case should run.
8111b362b15af34006e6a11974088a46d42b903418eJohann  bool should_run() const { return should_run_; }
8121b362b15af34006e6a11974088a46d42b903418eJohann
8131b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of successful tests in this test case.
8141b362b15af34006e6a11974088a46d42b903418eJohann  int successful_test_count() const;
8151b362b15af34006e6a11974088a46d42b903418eJohann
8161b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of failed tests in this test case.
8171b362b15af34006e6a11974088a46d42b903418eJohann  int failed_test_count() const;
8181b362b15af34006e6a11974088a46d42b903418eJohann
8195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Gets the number of disabled tests that will be reported in the XML report.
8205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  int reportable_disabled_test_count() const;
8215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
8221b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of disabled tests in this test case.
8231b362b15af34006e6a11974088a46d42b903418eJohann  int disabled_test_count() const;
8241b362b15af34006e6a11974088a46d42b903418eJohann
8255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Gets the number of tests to be printed in the XML report.
8265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  int reportable_test_count() const;
8275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
8281b362b15af34006e6a11974088a46d42b903418eJohann  // Get the number of tests in this test case that should run.
8291b362b15af34006e6a11974088a46d42b903418eJohann  int test_to_run_count() const;
8301b362b15af34006e6a11974088a46d42b903418eJohann
8311b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of all tests in this test case.
8321b362b15af34006e6a11974088a46d42b903418eJohann  int total_test_count() const;
8331b362b15af34006e6a11974088a46d42b903418eJohann
8341b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test case passed.
8351b362b15af34006e6a11974088a46d42b903418eJohann  bool Passed() const { return !Failed(); }
8361b362b15af34006e6a11974088a46d42b903418eJohann
8371b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the test case failed.
8381b362b15af34006e6a11974088a46d42b903418eJohann  bool Failed() const { return failed_test_count() > 0; }
8391b362b15af34006e6a11974088a46d42b903418eJohann
8401b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the elapsed time, in milliseconds.
8411b362b15af34006e6a11974088a46d42b903418eJohann  TimeInMillis elapsed_time() const { return elapsed_time_; }
8421b362b15af34006e6a11974088a46d42b903418eJohann
8431b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the i-th test among all the tests. i can range from 0 to
8441b362b15af34006e6a11974088a46d42b903418eJohann  // total_test_count() - 1. If i is not in that range, returns NULL.
8451b362b15af34006e6a11974088a46d42b903418eJohann  const TestInfo* GetTestInfo(int i) const;
8461b362b15af34006e6a11974088a46d42b903418eJohann
8475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns the TestResult that holds test properties recorded during
8485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // execution of SetUpTestCase and TearDownTestCase.
8495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
8505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
8511b362b15af34006e6a11974088a46d42b903418eJohann private:
8521b362b15af34006e6a11974088a46d42b903418eJohann  friend class Test;
8531b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::UnitTestImpl;
8541b362b15af34006e6a11974088a46d42b903418eJohann
8551b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the (mutable) vector of TestInfos in this TestCase.
8561b362b15af34006e6a11974088a46d42b903418eJohann  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
8571b362b15af34006e6a11974088a46d42b903418eJohann
8581b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the (immutable) vector of TestInfos in this TestCase.
8591b362b15af34006e6a11974088a46d42b903418eJohann  const std::vector<TestInfo*>& test_info_list() const {
8601b362b15af34006e6a11974088a46d42b903418eJohann    return test_info_list_;
8611b362b15af34006e6a11974088a46d42b903418eJohann  }
8621b362b15af34006e6a11974088a46d42b903418eJohann
8631b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the i-th test among all the tests. i can range from 0 to
8641b362b15af34006e6a11974088a46d42b903418eJohann  // total_test_count() - 1. If i is not in that range, returns NULL.
8651b362b15af34006e6a11974088a46d42b903418eJohann  TestInfo* GetMutableTestInfo(int i);
8661b362b15af34006e6a11974088a46d42b903418eJohann
8671b362b15af34006e6a11974088a46d42b903418eJohann  // Sets the should_run member.
8681b362b15af34006e6a11974088a46d42b903418eJohann  void set_should_run(bool should) { should_run_ = should; }
8691b362b15af34006e6a11974088a46d42b903418eJohann
8701b362b15af34006e6a11974088a46d42b903418eJohann  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
8711b362b15af34006e6a11974088a46d42b903418eJohann  // destruction of the TestCase object.
8721b362b15af34006e6a11974088a46d42b903418eJohann  void AddTestInfo(TestInfo * test_info);
8731b362b15af34006e6a11974088a46d42b903418eJohann
8741b362b15af34006e6a11974088a46d42b903418eJohann  // Clears the results of all tests in this test case.
8751b362b15af34006e6a11974088a46d42b903418eJohann  void ClearResult();
8761b362b15af34006e6a11974088a46d42b903418eJohann
8771b362b15af34006e6a11974088a46d42b903418eJohann  // Clears the results of all tests in the given test case.
8781b362b15af34006e6a11974088a46d42b903418eJohann  static void ClearTestCaseResult(TestCase* test_case) {
8791b362b15af34006e6a11974088a46d42b903418eJohann    test_case->ClearResult();
8801b362b15af34006e6a11974088a46d42b903418eJohann  }
8811b362b15af34006e6a11974088a46d42b903418eJohann
8821b362b15af34006e6a11974088a46d42b903418eJohann  // Runs every test in this TestCase.
8831b362b15af34006e6a11974088a46d42b903418eJohann  void Run();
8841b362b15af34006e6a11974088a46d42b903418eJohann
8851b362b15af34006e6a11974088a46d42b903418eJohann  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
8861b362b15af34006e6a11974088a46d42b903418eJohann  // for catching exceptions thrown from SetUpTestCase().
8871b362b15af34006e6a11974088a46d42b903418eJohann  void RunSetUpTestCase() { (*set_up_tc_)(); }
8881b362b15af34006e6a11974088a46d42b903418eJohann
8891b362b15af34006e6a11974088a46d42b903418eJohann  // Runs TearDownTestCase() for this TestCase.  This wrapper is
8901b362b15af34006e6a11974088a46d42b903418eJohann  // needed for catching exceptions thrown from TearDownTestCase().
8911b362b15af34006e6a11974088a46d42b903418eJohann  void RunTearDownTestCase() { (*tear_down_tc_)(); }
8921b362b15af34006e6a11974088a46d42b903418eJohann
8931b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff test passed.
8941b362b15af34006e6a11974088a46d42b903418eJohann  static bool TestPassed(const TestInfo* test_info) {
8951b362b15af34006e6a11974088a46d42b903418eJohann    return test_info->should_run() && test_info->result()->Passed();
8961b362b15af34006e6a11974088a46d42b903418eJohann  }
8971b362b15af34006e6a11974088a46d42b903418eJohann
8981b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff test failed.
8991b362b15af34006e6a11974088a46d42b903418eJohann  static bool TestFailed(const TestInfo* test_info) {
9001b362b15af34006e6a11974088a46d42b903418eJohann    return test_info->should_run() && test_info->result()->Failed();
9011b362b15af34006e6a11974088a46d42b903418eJohann  }
9021b362b15af34006e6a11974088a46d42b903418eJohann
9035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns true iff the test is disabled and will be reported in the XML
9045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // report.
9055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  static bool TestReportableDisabled(const TestInfo* test_info) {
9065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    return test_info->is_reportable() && test_info->is_disabled_;
9075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  }
9085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
9091b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff test is disabled.
9101b362b15af34006e6a11974088a46d42b903418eJohann  static bool TestDisabled(const TestInfo* test_info) {
9111b362b15af34006e6a11974088a46d42b903418eJohann    return test_info->is_disabled_;
9121b362b15af34006e6a11974088a46d42b903418eJohann  }
9131b362b15af34006e6a11974088a46d42b903418eJohann
9145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns true iff this test will appear in the XML report.
9155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  static bool TestReportable(const TestInfo* test_info) {
9165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    return test_info->is_reportable();
9175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  }
9185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
9191b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true if the given test should run.
9201b362b15af34006e6a11974088a46d42b903418eJohann  static bool ShouldRunTest(const TestInfo* test_info) {
9211b362b15af34006e6a11974088a46d42b903418eJohann    return test_info->should_run();
9221b362b15af34006e6a11974088a46d42b903418eJohann  }
9231b362b15af34006e6a11974088a46d42b903418eJohann
9241b362b15af34006e6a11974088a46d42b903418eJohann  // Shuffles the tests in this test case.
9251b362b15af34006e6a11974088a46d42b903418eJohann  void ShuffleTests(internal::Random* random);
9261b362b15af34006e6a11974088a46d42b903418eJohann
9271b362b15af34006e6a11974088a46d42b903418eJohann  // Restores the test order to before the first shuffle.
9281b362b15af34006e6a11974088a46d42b903418eJohann  void UnshuffleTests();
9291b362b15af34006e6a11974088a46d42b903418eJohann
9301b362b15af34006e6a11974088a46d42b903418eJohann  // Name of the test case.
9315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  std::string name_;
9321b362b15af34006e6a11974088a46d42b903418eJohann  // Name of the parameter type, or NULL if this is not a typed or a
9331b362b15af34006e6a11974088a46d42b903418eJohann  // type-parameterized test.
9341b362b15af34006e6a11974088a46d42b903418eJohann  const internal::scoped_ptr<const ::std::string> type_param_;
9351b362b15af34006e6a11974088a46d42b903418eJohann  // The vector of TestInfos in their original order.  It owns the
9361b362b15af34006e6a11974088a46d42b903418eJohann  // elements in the vector.
9371b362b15af34006e6a11974088a46d42b903418eJohann  std::vector<TestInfo*> test_info_list_;
9381b362b15af34006e6a11974088a46d42b903418eJohann  // Provides a level of indirection for the test list to allow easy
9391b362b15af34006e6a11974088a46d42b903418eJohann  // shuffling and restoring the test order.  The i-th element in this
9401b362b15af34006e6a11974088a46d42b903418eJohann  // vector is the index of the i-th test in the shuffled test list.
9411b362b15af34006e6a11974088a46d42b903418eJohann  std::vector<int> test_indices_;
9421b362b15af34006e6a11974088a46d42b903418eJohann  // Pointer to the function that sets up the test case.
9431b362b15af34006e6a11974088a46d42b903418eJohann  Test::SetUpTestCaseFunc set_up_tc_;
9441b362b15af34006e6a11974088a46d42b903418eJohann  // Pointer to the function that tears down the test case.
9451b362b15af34006e6a11974088a46d42b903418eJohann  Test::TearDownTestCaseFunc tear_down_tc_;
9461b362b15af34006e6a11974088a46d42b903418eJohann  // True iff any test in this test case should run.
9471b362b15af34006e6a11974088a46d42b903418eJohann  bool should_run_;
9481b362b15af34006e6a11974088a46d42b903418eJohann  // Elapsed time, in milliseconds.
9491b362b15af34006e6a11974088a46d42b903418eJohann  TimeInMillis elapsed_time_;
9505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Holds test properties recorded during execution of SetUpTestCase and
9515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // TearDownTestCase.
9525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  TestResult ad_hoc_test_result_;
9531b362b15af34006e6a11974088a46d42b903418eJohann
9541b362b15af34006e6a11974088a46d42b903418eJohann  // We disallow copying TestCases.
9551b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
9561b362b15af34006e6a11974088a46d42b903418eJohann};
9571b362b15af34006e6a11974088a46d42b903418eJohann
9581b362b15af34006e6a11974088a46d42b903418eJohann// An Environment object is capable of setting up and tearing down an
9598b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// environment.  You should subclass this to define your own
9601b362b15af34006e6a11974088a46d42b903418eJohann// environment(s).
9611b362b15af34006e6a11974088a46d42b903418eJohann//
9621b362b15af34006e6a11974088a46d42b903418eJohann// An Environment object does the set-up and tear-down in virtual
9631b362b15af34006e6a11974088a46d42b903418eJohann// methods SetUp() and TearDown() instead of the constructor and the
9641b362b15af34006e6a11974088a46d42b903418eJohann// destructor, as:
9651b362b15af34006e6a11974088a46d42b903418eJohann//
9661b362b15af34006e6a11974088a46d42b903418eJohann//   1. You cannot safely throw from a destructor.  This is a problem
9671b362b15af34006e6a11974088a46d42b903418eJohann//      as in some cases Google Test is used where exceptions are enabled, and
9681b362b15af34006e6a11974088a46d42b903418eJohann//      we may want to implement ASSERT_* using exceptions where they are
9691b362b15af34006e6a11974088a46d42b903418eJohann//      available.
9701b362b15af34006e6a11974088a46d42b903418eJohann//   2. You cannot use ASSERT_* directly in a constructor or
9711b362b15af34006e6a11974088a46d42b903418eJohann//      destructor.
9721b362b15af34006e6a11974088a46d42b903418eJohannclass Environment {
9731b362b15af34006e6a11974088a46d42b903418eJohann public:
9741b362b15af34006e6a11974088a46d42b903418eJohann  // The d'tor is virtual as we need to subclass Environment.
9751b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~Environment() {}
9761b362b15af34006e6a11974088a46d42b903418eJohann
9771b362b15af34006e6a11974088a46d42b903418eJohann  // Override this to define how to set up the environment.
9781b362b15af34006e6a11974088a46d42b903418eJohann  virtual void SetUp() {}
9791b362b15af34006e6a11974088a46d42b903418eJohann
9801b362b15af34006e6a11974088a46d42b903418eJohann  // Override this to define how to tear down the environment.
9811b362b15af34006e6a11974088a46d42b903418eJohann  virtual void TearDown() {}
9821b362b15af34006e6a11974088a46d42b903418eJohann private:
9831b362b15af34006e6a11974088a46d42b903418eJohann  // If you see an error about overriding the following function or
9841b362b15af34006e6a11974088a46d42b903418eJohann  // about it being private, you have mis-spelled SetUp() as Setup().
9851b362b15af34006e6a11974088a46d42b903418eJohann  struct Setup_should_be_spelled_SetUp {};
9861b362b15af34006e6a11974088a46d42b903418eJohann  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
9871b362b15af34006e6a11974088a46d42b903418eJohann};
9881b362b15af34006e6a11974088a46d42b903418eJohann
9891b362b15af34006e6a11974088a46d42b903418eJohann// The interface for tracing execution of tests. The methods are organized in
9901b362b15af34006e6a11974088a46d42b903418eJohann// the order the corresponding events are fired.
9911b362b15af34006e6a11974088a46d42b903418eJohannclass TestEventListener {
9921b362b15af34006e6a11974088a46d42b903418eJohann public:
9931b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~TestEventListener() {}
9941b362b15af34006e6a11974088a46d42b903418eJohann
9951b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before any test activity starts.
9961b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
9971b362b15af34006e6a11974088a46d42b903418eJohann
9981b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before each iteration of tests starts.  There may be more than
9991b362b15af34006e6a11974088a46d42b903418eJohann  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
10001b362b15af34006e6a11974088a46d42b903418eJohann  // index, starting from 0.
10011b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestIterationStart(const UnitTest& unit_test,
10021b362b15af34006e6a11974088a46d42b903418eJohann                                    int iteration) = 0;
10031b362b15af34006e6a11974088a46d42b903418eJohann
10041b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before environment set-up for each iteration of tests starts.
10051b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
10061b362b15af34006e6a11974088a46d42b903418eJohann
10071b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after environment set-up for each iteration of tests ends.
10081b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
10091b362b15af34006e6a11974088a46d42b903418eJohann
10101b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before the test case starts.
10111b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
10121b362b15af34006e6a11974088a46d42b903418eJohann
10131b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before the test starts.
10141b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestStart(const TestInfo& test_info) = 0;
10151b362b15af34006e6a11974088a46d42b903418eJohann
10161b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after a failed assertion or a SUCCEED() invocation.
10171b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
10181b362b15af34006e6a11974088a46d42b903418eJohann
10191b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after the test ends.
10201b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestEnd(const TestInfo& test_info) = 0;
10211b362b15af34006e6a11974088a46d42b903418eJohann
10221b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after the test case ends.
10231b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
10241b362b15af34006e6a11974088a46d42b903418eJohann
10251b362b15af34006e6a11974088a46d42b903418eJohann  // Fired before environment tear-down for each iteration of tests starts.
10261b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
10271b362b15af34006e6a11974088a46d42b903418eJohann
10281b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after environment tear-down for each iteration of tests ends.
10291b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
10301b362b15af34006e6a11974088a46d42b903418eJohann
10311b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after each iteration of tests finishes.
10321b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestIterationEnd(const UnitTest& unit_test,
10331b362b15af34006e6a11974088a46d42b903418eJohann                                  int iteration) = 0;
10341b362b15af34006e6a11974088a46d42b903418eJohann
10351b362b15af34006e6a11974088a46d42b903418eJohann  // Fired after all test activities have ended.
10361b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
10371b362b15af34006e6a11974088a46d42b903418eJohann};
10381b362b15af34006e6a11974088a46d42b903418eJohann
10391b362b15af34006e6a11974088a46d42b903418eJohann// The convenience class for users who need to override just one or two
10401b362b15af34006e6a11974088a46d42b903418eJohann// methods and are not concerned that a possible change to a signature of
10411b362b15af34006e6a11974088a46d42b903418eJohann// the methods they override will not be caught during the build.  For
10421b362b15af34006e6a11974088a46d42b903418eJohann// comments about each method please see the definition of TestEventListener
10431b362b15af34006e6a11974088a46d42b903418eJohann// above.
10441b362b15af34006e6a11974088a46d42b903418eJohannclass EmptyTestEventListener : public TestEventListener {
10451b362b15af34006e6a11974088a46d42b903418eJohann public:
10461b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
10471b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
10481b362b15af34006e6a11974088a46d42b903418eJohann                                    int /*iteration*/) {}
10491b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
10501b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
10511b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
10521b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
10531b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
10541b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
10551b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
10561b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
10571b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
10581b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
10591b362b15af34006e6a11974088a46d42b903418eJohann                                  int /*iteration*/) {}
10601b362b15af34006e6a11974088a46d42b903418eJohann  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
10611b362b15af34006e6a11974088a46d42b903418eJohann};
10621b362b15af34006e6a11974088a46d42b903418eJohann
10631b362b15af34006e6a11974088a46d42b903418eJohann// TestEventListeners lets users add listeners to track events in Google Test.
10641b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ TestEventListeners {
10651b362b15af34006e6a11974088a46d42b903418eJohann public:
10661b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListeners();
10671b362b15af34006e6a11974088a46d42b903418eJohann  ~TestEventListeners();
10681b362b15af34006e6a11974088a46d42b903418eJohann
10691b362b15af34006e6a11974088a46d42b903418eJohann  // Appends an event listener to the end of the list. Google Test assumes
10701b362b15af34006e6a11974088a46d42b903418eJohann  // the ownership of the listener (i.e. it will delete the listener when
10711b362b15af34006e6a11974088a46d42b903418eJohann  // the test program finishes).
10721b362b15af34006e6a11974088a46d42b903418eJohann  void Append(TestEventListener* listener);
10731b362b15af34006e6a11974088a46d42b903418eJohann
10741b362b15af34006e6a11974088a46d42b903418eJohann  // Removes the given event listener from the list and returns it.  It then
10751b362b15af34006e6a11974088a46d42b903418eJohann  // becomes the caller's responsibility to delete the listener. Returns
10761b362b15af34006e6a11974088a46d42b903418eJohann  // NULL if the listener is not found in the list.
10771b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* Release(TestEventListener* listener);
10781b362b15af34006e6a11974088a46d42b903418eJohann
10791b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the standard listener responsible for the default console
10801b362b15af34006e6a11974088a46d42b903418eJohann  // output.  Can be removed from the listeners list to shut down default
10811b362b15af34006e6a11974088a46d42b903418eJohann  // console output.  Note that removing this object from the listener list
10821b362b15af34006e6a11974088a46d42b903418eJohann  // with Release transfers its ownership to the caller and makes this
10831b362b15af34006e6a11974088a46d42b903418eJohann  // function return NULL the next time.
10841b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* default_result_printer() const {
10851b362b15af34006e6a11974088a46d42b903418eJohann    return default_result_printer_;
10861b362b15af34006e6a11974088a46d42b903418eJohann  }
10871b362b15af34006e6a11974088a46d42b903418eJohann
10881b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the standard listener responsible for the default XML output
10891b362b15af34006e6a11974088a46d42b903418eJohann  // controlled by the --gtest_output=xml flag.  Can be removed from the
10901b362b15af34006e6a11974088a46d42b903418eJohann  // listeners list by users who want to shut down the default XML output
10911b362b15af34006e6a11974088a46d42b903418eJohann  // controlled by this flag and substitute it with custom one.  Note that
10921b362b15af34006e6a11974088a46d42b903418eJohann  // removing this object from the listener list with Release transfers its
10931b362b15af34006e6a11974088a46d42b903418eJohann  // ownership to the caller and makes this function return NULL the next
10941b362b15af34006e6a11974088a46d42b903418eJohann  // time.
10951b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* default_xml_generator() const {
10961b362b15af34006e6a11974088a46d42b903418eJohann    return default_xml_generator_;
10971b362b15af34006e6a11974088a46d42b903418eJohann  }
10981b362b15af34006e6a11974088a46d42b903418eJohann
10991b362b15af34006e6a11974088a46d42b903418eJohann private:
11001b362b15af34006e6a11974088a46d42b903418eJohann  friend class TestCase;
11011b362b15af34006e6a11974088a46d42b903418eJohann  friend class TestInfo;
11021b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::DefaultGlobalTestPartResultReporter;
11031b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::NoExecDeathTest;
11041b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::TestEventListenersAccessor;
11051b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::UnitTestImpl;
11061b362b15af34006e6a11974088a46d42b903418eJohann
11071b362b15af34006e6a11974088a46d42b903418eJohann  // Returns repeater that broadcasts the TestEventListener events to all
11081b362b15af34006e6a11974088a46d42b903418eJohann  // subscribers.
11091b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* repeater();
11101b362b15af34006e6a11974088a46d42b903418eJohann
11111b362b15af34006e6a11974088a46d42b903418eJohann  // Sets the default_result_printer attribute to the provided listener.
11121b362b15af34006e6a11974088a46d42b903418eJohann  // The listener is also added to the listener list and previous
11131b362b15af34006e6a11974088a46d42b903418eJohann  // default_result_printer is removed from it and deleted. The listener can
11141b362b15af34006e6a11974088a46d42b903418eJohann  // also be NULL in which case it will not be added to the list. Does
11151b362b15af34006e6a11974088a46d42b903418eJohann  // nothing if the previous and the current listener objects are the same.
11161b362b15af34006e6a11974088a46d42b903418eJohann  void SetDefaultResultPrinter(TestEventListener* listener);
11171b362b15af34006e6a11974088a46d42b903418eJohann
11181b362b15af34006e6a11974088a46d42b903418eJohann  // Sets the default_xml_generator attribute to the provided listener.  The
11191b362b15af34006e6a11974088a46d42b903418eJohann  // listener is also added to the listener list and previous
11201b362b15af34006e6a11974088a46d42b903418eJohann  // default_xml_generator is removed from it and deleted. The listener can
11211b362b15af34006e6a11974088a46d42b903418eJohann  // also be NULL in which case it will not be added to the list. Does
11221b362b15af34006e6a11974088a46d42b903418eJohann  // nothing if the previous and the current listener objects are the same.
11231b362b15af34006e6a11974088a46d42b903418eJohann  void SetDefaultXmlGenerator(TestEventListener* listener);
11241b362b15af34006e6a11974088a46d42b903418eJohann
11251b362b15af34006e6a11974088a46d42b903418eJohann  // Controls whether events will be forwarded by the repeater to the
11261b362b15af34006e6a11974088a46d42b903418eJohann  // listeners in the list.
11271b362b15af34006e6a11974088a46d42b903418eJohann  bool EventForwardingEnabled() const;
11281b362b15af34006e6a11974088a46d42b903418eJohann  void SuppressEventForwarding();
11291b362b15af34006e6a11974088a46d42b903418eJohann
11301b362b15af34006e6a11974088a46d42b903418eJohann  // The actual list of listeners.
11311b362b15af34006e6a11974088a46d42b903418eJohann  internal::TestEventRepeater* repeater_;
11321b362b15af34006e6a11974088a46d42b903418eJohann  // Listener responsible for the standard result output.
11331b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* default_result_printer_;
11341b362b15af34006e6a11974088a46d42b903418eJohann  // Listener responsible for the creation of the XML output file.
11351b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListener* default_xml_generator_;
11361b362b15af34006e6a11974088a46d42b903418eJohann
11371b362b15af34006e6a11974088a46d42b903418eJohann  // We disallow copying TestEventListeners.
11381b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
11391b362b15af34006e6a11974088a46d42b903418eJohann};
11401b362b15af34006e6a11974088a46d42b903418eJohann
11411b362b15af34006e6a11974088a46d42b903418eJohann// A UnitTest consists of a vector of TestCases.
11421b362b15af34006e6a11974088a46d42b903418eJohann//
11431b362b15af34006e6a11974088a46d42b903418eJohann// This is a singleton class.  The only instance of UnitTest is
11441b362b15af34006e6a11974088a46d42b903418eJohann// created when UnitTest::GetInstance() is first called.  This
11451b362b15af34006e6a11974088a46d42b903418eJohann// instance is never deleted.
11461b362b15af34006e6a11974088a46d42b903418eJohann//
11471b362b15af34006e6a11974088a46d42b903418eJohann// UnitTest is not copyable.
11481b362b15af34006e6a11974088a46d42b903418eJohann//
11491b362b15af34006e6a11974088a46d42b903418eJohann// This class is thread-safe as long as the methods are called
11501b362b15af34006e6a11974088a46d42b903418eJohann// according to their specification.
11511b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ UnitTest {
11521b362b15af34006e6a11974088a46d42b903418eJohann public:
11531b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the singleton UnitTest object.  The first time this method
11541b362b15af34006e6a11974088a46d42b903418eJohann  // is called, a UnitTest object is constructed and returned.
11551b362b15af34006e6a11974088a46d42b903418eJohann  // Consecutive calls will return the same object.
11561b362b15af34006e6a11974088a46d42b903418eJohann  static UnitTest* GetInstance();
11571b362b15af34006e6a11974088a46d42b903418eJohann
11581b362b15af34006e6a11974088a46d42b903418eJohann  // Runs all tests in this UnitTest object and prints the result.
11591b362b15af34006e6a11974088a46d42b903418eJohann  // Returns 0 if successful, or 1 otherwise.
11601b362b15af34006e6a11974088a46d42b903418eJohann  //
11611b362b15af34006e6a11974088a46d42b903418eJohann  // This method can only be called from the main thread.
11621b362b15af34006e6a11974088a46d42b903418eJohann  //
11631b362b15af34006e6a11974088a46d42b903418eJohann  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
11641b362b15af34006e6a11974088a46d42b903418eJohann  int Run() GTEST_MUST_USE_RESULT_;
11651b362b15af34006e6a11974088a46d42b903418eJohann
11661b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the working directory when the first TEST() or TEST_F()
11671b362b15af34006e6a11974088a46d42b903418eJohann  // was executed.  The UnitTest object owns the string.
11681b362b15af34006e6a11974088a46d42b903418eJohann  const char* original_working_dir() const;
11691b362b15af34006e6a11974088a46d42b903418eJohann
11701b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the TestCase object for the test that's currently running,
11711b362b15af34006e6a11974088a46d42b903418eJohann  // or NULL if no test is running.
11725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  const TestCase* current_test_case() const
11735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
11741b362b15af34006e6a11974088a46d42b903418eJohann
11751b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the TestInfo object for the test that's currently running,
11761b362b15af34006e6a11974088a46d42b903418eJohann  // or NULL if no test is running.
11775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  const TestInfo* current_test_info() const
11785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
11791b362b15af34006e6a11974088a46d42b903418eJohann
11801b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the random seed used at the start of the current test run.
11811b362b15af34006e6a11974088a46d42b903418eJohann  int random_seed() const;
11821b362b15af34006e6a11974088a46d42b903418eJohann
11831b362b15af34006e6a11974088a46d42b903418eJohann#if GTEST_HAS_PARAM_TEST
11841b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the ParameterizedTestCaseRegistry object used to keep track of
11851b362b15af34006e6a11974088a46d42b903418eJohann  // value-parameterized tests and instantiate and register them.
11861b362b15af34006e6a11974088a46d42b903418eJohann  //
11871b362b15af34006e6a11974088a46d42b903418eJohann  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
11885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
11895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
11901b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_HAS_PARAM_TEST
11911b362b15af34006e6a11974088a46d42b903418eJohann
11921b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of successful test cases.
11931b362b15af34006e6a11974088a46d42b903418eJohann  int successful_test_case_count() const;
11941b362b15af34006e6a11974088a46d42b903418eJohann
11951b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of failed test cases.
11961b362b15af34006e6a11974088a46d42b903418eJohann  int failed_test_case_count() const;
11971b362b15af34006e6a11974088a46d42b903418eJohann
11981b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of all test cases.
11991b362b15af34006e6a11974088a46d42b903418eJohann  int total_test_case_count() const;
12001b362b15af34006e6a11974088a46d42b903418eJohann
12011b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of all test cases that contain at least one test
12021b362b15af34006e6a11974088a46d42b903418eJohann  // that should run.
12031b362b15af34006e6a11974088a46d42b903418eJohann  int test_case_to_run_count() const;
12041b362b15af34006e6a11974088a46d42b903418eJohann
12051b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of successful tests.
12061b362b15af34006e6a11974088a46d42b903418eJohann  int successful_test_count() const;
12071b362b15af34006e6a11974088a46d42b903418eJohann
12081b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of failed tests.
12091b362b15af34006e6a11974088a46d42b903418eJohann  int failed_test_count() const;
12101b362b15af34006e6a11974088a46d42b903418eJohann
12115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Gets the number of disabled tests that will be reported in the XML report.
12125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  int reportable_disabled_test_count() const;
12135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
12141b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of disabled tests.
12151b362b15af34006e6a11974088a46d42b903418eJohann  int disabled_test_count() const;
12161b362b15af34006e6a11974088a46d42b903418eJohann
12175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Gets the number of tests to be printed in the XML report.
12185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  int reportable_test_count() const;
12195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
12201b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of all tests.
12211b362b15af34006e6a11974088a46d42b903418eJohann  int total_test_count() const;
12221b362b15af34006e6a11974088a46d42b903418eJohann
12231b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the number of tests that should run.
12241b362b15af34006e6a11974088a46d42b903418eJohann  int test_to_run_count() const;
12251b362b15af34006e6a11974088a46d42b903418eJohann
12265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Gets the time of the test program start, in ms from the start of the
12275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // UNIX epoch.
12285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  TimeInMillis start_timestamp() const;
12295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
12301b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the elapsed time, in milliseconds.
12311b362b15af34006e6a11974088a46d42b903418eJohann  TimeInMillis elapsed_time() const;
12321b362b15af34006e6a11974088a46d42b903418eJohann
12331b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the unit test passed (i.e. all test cases passed).
12341b362b15af34006e6a11974088a46d42b903418eJohann  bool Passed() const;
12351b362b15af34006e6a11974088a46d42b903418eJohann
12361b362b15af34006e6a11974088a46d42b903418eJohann  // Returns true iff the unit test failed (i.e. some test case failed
12371b362b15af34006e6a11974088a46d42b903418eJohann  // or something outside of all tests failed).
12381b362b15af34006e6a11974088a46d42b903418eJohann  bool Failed() const;
12391b362b15af34006e6a11974088a46d42b903418eJohann
12401b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the i-th test case among all the test cases. i can range from 0 to
12411b362b15af34006e6a11974088a46d42b903418eJohann  // total_test_case_count() - 1. If i is not in that range, returns NULL.
12421b362b15af34006e6a11974088a46d42b903418eJohann  const TestCase* GetTestCase(int i) const;
12431b362b15af34006e6a11974088a46d42b903418eJohann
12445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Returns the TestResult containing information on test failures and
12455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // properties logged outside of individual test cases.
12465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  const TestResult& ad_hoc_test_result() const;
12475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
12481b362b15af34006e6a11974088a46d42b903418eJohann  // Returns the list of event listeners that can be used to track events
12491b362b15af34006e6a11974088a46d42b903418eJohann  // inside Google Test.
12501b362b15af34006e6a11974088a46d42b903418eJohann  TestEventListeners& listeners();
12511b362b15af34006e6a11974088a46d42b903418eJohann
12521b362b15af34006e6a11974088a46d42b903418eJohann private:
12531b362b15af34006e6a11974088a46d42b903418eJohann  // Registers and returns a global test environment.  When a test
12541b362b15af34006e6a11974088a46d42b903418eJohann  // program is run, all global test environments will be set-up in
12551b362b15af34006e6a11974088a46d42b903418eJohann  // the order they were registered.  After all tests in the program
12561b362b15af34006e6a11974088a46d42b903418eJohann  // have finished, all global test environments will be torn-down in
12571b362b15af34006e6a11974088a46d42b903418eJohann  // the *reverse* order they were registered.
12581b362b15af34006e6a11974088a46d42b903418eJohann  //
12591b362b15af34006e6a11974088a46d42b903418eJohann  // The UnitTest object takes ownership of the given environment.
12601b362b15af34006e6a11974088a46d42b903418eJohann  //
12611b362b15af34006e6a11974088a46d42b903418eJohann  // This method can only be called from the main thread.
12621b362b15af34006e6a11974088a46d42b903418eJohann  Environment* AddEnvironment(Environment* env);
12631b362b15af34006e6a11974088a46d42b903418eJohann
12641b362b15af34006e6a11974088a46d42b903418eJohann  // Adds a TestPartResult to the current TestResult object.  All
12651b362b15af34006e6a11974088a46d42b903418eJohann  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
12661b362b15af34006e6a11974088a46d42b903418eJohann  // eventually call this to report their results.  The user code
12671b362b15af34006e6a11974088a46d42b903418eJohann  // should use the assertion macros instead of calling this directly.
12681b362b15af34006e6a11974088a46d42b903418eJohann  void AddTestPartResult(TestPartResult::Type result_type,
12691b362b15af34006e6a11974088a46d42b903418eJohann                         const char* file_name,
12701b362b15af34006e6a11974088a46d42b903418eJohann                         int line_number,
12715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang                         const std::string& message,
12725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang                         const std::string& os_stack_trace)
12735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
12741b362b15af34006e6a11974088a46d42b903418eJohann
12755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // Adds a TestProperty to the current TestResult object when invoked from
12765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
12775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // from SetUpTestCase or TearDownTestCase, or to the global property set
12785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // when invoked elsewhere.  If the result already contains a property with
12795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  // the same key, the value will be updated.
12805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  void RecordProperty(const std::string& key, const std::string& value);
12811b362b15af34006e6a11974088a46d42b903418eJohann
12821b362b15af34006e6a11974088a46d42b903418eJohann  // Gets the i-th test case among all the test cases. i can range from 0 to
12831b362b15af34006e6a11974088a46d42b903418eJohann  // total_test_case_count() - 1. If i is not in that range, returns NULL.
12841b362b15af34006e6a11974088a46d42b903418eJohann  TestCase* GetMutableTestCase(int i);
12851b362b15af34006e6a11974088a46d42b903418eJohann
12861b362b15af34006e6a11974088a46d42b903418eJohann  // Accessors for the implementation object.
12871b362b15af34006e6a11974088a46d42b903418eJohann  internal::UnitTestImpl* impl() { return impl_; }
12881b362b15af34006e6a11974088a46d42b903418eJohann  const internal::UnitTestImpl* impl() const { return impl_; }
12891b362b15af34006e6a11974088a46d42b903418eJohann
12901b362b15af34006e6a11974088a46d42b903418eJohann  // These classes and funcions are friends as they need to access private
12911b362b15af34006e6a11974088a46d42b903418eJohann  // members of UnitTest.
12921b362b15af34006e6a11974088a46d42b903418eJohann  friend class Test;
12931b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::AssertHelper;
12941b362b15af34006e6a11974088a46d42b903418eJohann  friend class internal::ScopedTrace;
12955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  friend class internal::StreamingListenerTest;
12965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  friend class internal::UnitTestRecordPropertyTestHelper;
12971b362b15af34006e6a11974088a46d42b903418eJohann  friend Environment* AddGlobalTestEnvironment(Environment* env);
12981b362b15af34006e6a11974088a46d42b903418eJohann  friend internal::UnitTestImpl* internal::GetUnitTestImpl();
12991b362b15af34006e6a11974088a46d42b903418eJohann  friend void internal::ReportFailureInUnknownLocation(
13001b362b15af34006e6a11974088a46d42b903418eJohann      TestPartResult::Type result_type,
13015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      const std::string& message);
13021b362b15af34006e6a11974088a46d42b903418eJohann
13031b362b15af34006e6a11974088a46d42b903418eJohann  // Creates an empty UnitTest.
13041b362b15af34006e6a11974088a46d42b903418eJohann  UnitTest();
13051b362b15af34006e6a11974088a46d42b903418eJohann
13061b362b15af34006e6a11974088a46d42b903418eJohann  // D'tor
13071b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~UnitTest();
13081b362b15af34006e6a11974088a46d42b903418eJohann
13091b362b15af34006e6a11974088a46d42b903418eJohann  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
13101b362b15af34006e6a11974088a46d42b903418eJohann  // Google Test trace stack.
13115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  void PushGTestTrace(const internal::TraceInfo& trace)
13125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
13131b362b15af34006e6a11974088a46d42b903418eJohann
13141b362b15af34006e6a11974088a46d42b903418eJohann  // Pops a trace from the per-thread Google Test trace stack.
13155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  void PopGTestTrace()
13165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang      GTEST_LOCK_EXCLUDED_(mutex_);
13171b362b15af34006e6a11974088a46d42b903418eJohann
13181b362b15af34006e6a11974088a46d42b903418eJohann  // Protects mutable state in *impl_.  This is mutable as some const
13191b362b15af34006e6a11974088a46d42b903418eJohann  // methods need to lock it too.
13201b362b15af34006e6a11974088a46d42b903418eJohann  mutable internal::Mutex mutex_;
13211b362b15af34006e6a11974088a46d42b903418eJohann
13221b362b15af34006e6a11974088a46d42b903418eJohann  // Opaque implementation object.  This field is never changed once
13231b362b15af34006e6a11974088a46d42b903418eJohann  // the object is constructed.  We don't mark it as const here, as
13241b362b15af34006e6a11974088a46d42b903418eJohann  // doing so will cause a warning in the constructor of UnitTest.
13251b362b15af34006e6a11974088a46d42b903418eJohann  // Mutable state in *impl_ is protected by mutex_.
13261b362b15af34006e6a11974088a46d42b903418eJohann  internal::UnitTestImpl* impl_;
13271b362b15af34006e6a11974088a46d42b903418eJohann
13281b362b15af34006e6a11974088a46d42b903418eJohann  // We disallow copying UnitTest.
13291b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
13301b362b15af34006e6a11974088a46d42b903418eJohann};
13311b362b15af34006e6a11974088a46d42b903418eJohann
13321b362b15af34006e6a11974088a46d42b903418eJohann// A convenient wrapper for adding an environment for the test
13331b362b15af34006e6a11974088a46d42b903418eJohann// program.
13341b362b15af34006e6a11974088a46d42b903418eJohann//
13351b362b15af34006e6a11974088a46d42b903418eJohann// You should call this before RUN_ALL_TESTS() is called, probably in
13361b362b15af34006e6a11974088a46d42b903418eJohann// main().  If you use gtest_main, you need to call this before main()
13371b362b15af34006e6a11974088a46d42b903418eJohann// starts for it to take effect.  For example, you can define a global
13381b362b15af34006e6a11974088a46d42b903418eJohann// variable like this:
13391b362b15af34006e6a11974088a46d42b903418eJohann//
13401b362b15af34006e6a11974088a46d42b903418eJohann//   testing::Environment* const foo_env =
13411b362b15af34006e6a11974088a46d42b903418eJohann//       testing::AddGlobalTestEnvironment(new FooEnvironment);
13421b362b15af34006e6a11974088a46d42b903418eJohann//
13431b362b15af34006e6a11974088a46d42b903418eJohann// However, we strongly recommend you to write your own main() and
13441b362b15af34006e6a11974088a46d42b903418eJohann// call AddGlobalTestEnvironment() there, as relying on initialization
13451b362b15af34006e6a11974088a46d42b903418eJohann// of global variables makes the code harder to read and may cause
13461b362b15af34006e6a11974088a46d42b903418eJohann// problems when you register multiple environments from different
13471b362b15af34006e6a11974088a46d42b903418eJohann// translation units and the environments have dependencies among them
13481b362b15af34006e6a11974088a46d42b903418eJohann// (remember that the compiler doesn't guarantee the order in which
13491b362b15af34006e6a11974088a46d42b903418eJohann// global variables from different translation units are initialized).
13501b362b15af34006e6a11974088a46d42b903418eJohanninline Environment* AddGlobalTestEnvironment(Environment* env) {
13511b362b15af34006e6a11974088a46d42b903418eJohann  return UnitTest::GetInstance()->AddEnvironment(env);
13521b362b15af34006e6a11974088a46d42b903418eJohann}
13531b362b15af34006e6a11974088a46d42b903418eJohann
13541b362b15af34006e6a11974088a46d42b903418eJohann// Initializes Google Test.  This must be called before calling
13551b362b15af34006e6a11974088a46d42b903418eJohann// RUN_ALL_TESTS().  In particular, it parses a command line for the
13561b362b15af34006e6a11974088a46d42b903418eJohann// flags that Google Test recognizes.  Whenever a Google Test flag is
13571b362b15af34006e6a11974088a46d42b903418eJohann// seen, it is removed from argv, and *argc is decremented.
13581b362b15af34006e6a11974088a46d42b903418eJohann//
13591b362b15af34006e6a11974088a46d42b903418eJohann// No value is returned.  Instead, the Google Test flag variables are
13601b362b15af34006e6a11974088a46d42b903418eJohann// updated.
13611b362b15af34006e6a11974088a46d42b903418eJohann//
13621b362b15af34006e6a11974088a46d42b903418eJohann// Calling the function for the second time has no user-visible effect.
13631b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ void InitGoogleTest(int* argc, char** argv);
13641b362b15af34006e6a11974088a46d42b903418eJohann
13651b362b15af34006e6a11974088a46d42b903418eJohann// This overloaded version can be used in Windows programs compiled in
13661b362b15af34006e6a11974088a46d42b903418eJohann// UNICODE mode.
13671b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
13681b362b15af34006e6a11974088a46d42b903418eJohann
13691b362b15af34006e6a11974088a46d42b903418eJohannnamespace internal {
13701b362b15af34006e6a11974088a46d42b903418eJohann
13718b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// Separate the error generating code from the code path to reduce the stack
13728b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
13738b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// when calling EXPECT_* in a tight loop.
13741b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T1, typename T2>
13758b92989c89bec8632aa47dc58dc162f199d62edcJames ZernAssertionResult CmpHelperEQFailure(const char* lhs_expression,
13768b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                   const char* rhs_expression,
13778b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                   const T1& lhs, const T2& rhs) {
13788b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  return EqFailure(lhs_expression,
13798b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   rhs_expression,
13808b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   FormatForComparisonFailureMessage(lhs, rhs),
13818b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   FormatForComparisonFailureMessage(rhs, lhs),
13828b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   false);
13831b362b15af34006e6a11974088a46d42b903418eJohann}
13841b362b15af34006e6a11974088a46d42b903418eJohann
13851b362b15af34006e6a11974088a46d42b903418eJohann// The helper function for {ASSERT|EXPECT}_EQ.
13861b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T1, typename T2>
13878b92989c89bec8632aa47dc58dc162f199d62edcJames ZernAssertionResult CmpHelperEQ(const char* lhs_expression,
13888b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                            const char* rhs_expression,
13898b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                            const T1& lhs,
13908b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                            const T2& rhs) {
13918b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
13928b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  if (lhs == rhs) {
13931b362b15af34006e6a11974088a46d42b903418eJohann    return AssertionSuccess();
13941b362b15af34006e6a11974088a46d42b903418eJohann  }
13958b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_DISABLE_MSC_WARNINGS_POP_()
13961b362b15af34006e6a11974088a46d42b903418eJohann
13978b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
13981b362b15af34006e6a11974088a46d42b903418eJohann}
13991b362b15af34006e6a11974088a46d42b903418eJohann
14001b362b15af34006e6a11974088a46d42b903418eJohann// With this overloaded version, we allow anonymous enums to be used
14011b362b15af34006e6a11974088a46d42b903418eJohann// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
14021b362b15af34006e6a11974088a46d42b903418eJohann// can be implicitly cast to BiggestInt.
14038b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
14048b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                       const char* rhs_expression,
14058b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                       BiggestInt lhs,
14068b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                       BiggestInt rhs);
14071b362b15af34006e6a11974088a46d42b903418eJohann
14081b362b15af34006e6a11974088a46d42b903418eJohann// The helper class for {ASSERT|EXPECT}_EQ.  The template argument
14091b362b15af34006e6a11974088a46d42b903418eJohann// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
14101b362b15af34006e6a11974088a46d42b903418eJohann// is a null pointer literal.  The following default implementation is
14111b362b15af34006e6a11974088a46d42b903418eJohann// for lhs_is_null_literal being false.
14121b362b15af34006e6a11974088a46d42b903418eJohanntemplate <bool lhs_is_null_literal>
14131b362b15af34006e6a11974088a46d42b903418eJohannclass EqHelper {
14141b362b15af34006e6a11974088a46d42b903418eJohann public:
14151b362b15af34006e6a11974088a46d42b903418eJohann  // This templatized version is for the general case.
14161b362b15af34006e6a11974088a46d42b903418eJohann  template <typename T1, typename T2>
14178b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  static AssertionResult Compare(const char* lhs_expression,
14188b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 const char* rhs_expression,
14198b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 const T1& lhs,
14208b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 const T2& rhs) {
14218b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
14221b362b15af34006e6a11974088a46d42b903418eJohann  }
14231b362b15af34006e6a11974088a46d42b903418eJohann
14241b362b15af34006e6a11974088a46d42b903418eJohann  // With this overloaded version, we allow anonymous enums to be used
14251b362b15af34006e6a11974088a46d42b903418eJohann  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
14261b362b15af34006e6a11974088a46d42b903418eJohann  // enums can be implicitly cast to BiggestInt.
14271b362b15af34006e6a11974088a46d42b903418eJohann  //
14281b362b15af34006e6a11974088a46d42b903418eJohann  // Even though its body looks the same as the above version, we
14291b362b15af34006e6a11974088a46d42b903418eJohann  // cannot merge the two, as it will make anonymous enums unhappy.
14308b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  static AssertionResult Compare(const char* lhs_expression,
14318b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 const char* rhs_expression,
14328b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 BiggestInt lhs,
14338b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                 BiggestInt rhs) {
14348b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
14351b362b15af34006e6a11974088a46d42b903418eJohann  }
14361b362b15af34006e6a11974088a46d42b903418eJohann};
14371b362b15af34006e6a11974088a46d42b903418eJohann
14381b362b15af34006e6a11974088a46d42b903418eJohann// This specialization is used when the first argument to ASSERT_EQ()
14391b362b15af34006e6a11974088a46d42b903418eJohann// is a null pointer literal, like NULL, false, or 0.
14401b362b15af34006e6a11974088a46d42b903418eJohanntemplate <>
14411b362b15af34006e6a11974088a46d42b903418eJohannclass EqHelper<true> {
14421b362b15af34006e6a11974088a46d42b903418eJohann public:
14431b362b15af34006e6a11974088a46d42b903418eJohann  // We define two overloaded versions of Compare().  The first
14441b362b15af34006e6a11974088a46d42b903418eJohann  // version will be picked when the second argument to ASSERT_EQ() is
14451b362b15af34006e6a11974088a46d42b903418eJohann  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
14461b362b15af34006e6a11974088a46d42b903418eJohann  // EXPECT_EQ(false, a_bool).
14471b362b15af34006e6a11974088a46d42b903418eJohann  template <typename T1, typename T2>
14481b362b15af34006e6a11974088a46d42b903418eJohann  static AssertionResult Compare(
14498b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const char* lhs_expression,
14508b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const char* rhs_expression,
14518b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const T1& lhs,
14528b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const T2& rhs,
14531b362b15af34006e6a11974088a46d42b903418eJohann      // The following line prevents this overload from being considered if T2
14541b362b15af34006e6a11974088a46d42b903418eJohann      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
14551b362b15af34006e6a11974088a46d42b903418eJohann      // expands to Compare("", "", NULL, my_ptr), which requires a conversion
14561b362b15af34006e6a11974088a46d42b903418eJohann      // to match the Secret* in the other overload, which would otherwise make
14571b362b15af34006e6a11974088a46d42b903418eJohann      // this template match better.
14581b362b15af34006e6a11974088a46d42b903418eJohann      typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
14598b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
14601b362b15af34006e6a11974088a46d42b903418eJohann  }
14611b362b15af34006e6a11974088a46d42b903418eJohann
14621b362b15af34006e6a11974088a46d42b903418eJohann  // This version will be picked when the second argument to ASSERT_EQ() is a
14631b362b15af34006e6a11974088a46d42b903418eJohann  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
14641b362b15af34006e6a11974088a46d42b903418eJohann  template <typename T>
14651b362b15af34006e6a11974088a46d42b903418eJohann  static AssertionResult Compare(
14668b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const char* lhs_expression,
14678b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      const char* rhs_expression,
14681b362b15af34006e6a11974088a46d42b903418eJohann      // We used to have a second template parameter instead of Secret*.  That
14691b362b15af34006e6a11974088a46d42b903418eJohann      // template parameter would deduce to 'long', making this a better match
14701b362b15af34006e6a11974088a46d42b903418eJohann      // than the first overload even without the first overload's EnableIf.
14711b362b15af34006e6a11974088a46d42b903418eJohann      // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
14721b362b15af34006e6a11974088a46d42b903418eJohann      // non-pointer argument" (even a deduced integral argument), so the old
14731b362b15af34006e6a11974088a46d42b903418eJohann      // implementation caused warnings in user code.
14748b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      Secret* /* lhs (NULL) */,
14758b92989c89bec8632aa47dc58dc162f199d62edcJames Zern      T* rhs) {
14768b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    // We already know that 'lhs' is a null pointer.
14778b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return CmpHelperEQ(lhs_expression, rhs_expression,
14788b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                       static_cast<T*>(NULL), rhs);
14791b362b15af34006e6a11974088a46d42b903418eJohann  }
14801b362b15af34006e6a11974088a46d42b903418eJohann};
14811b362b15af34006e6a11974088a46d42b903418eJohann
14828b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// Separate the error generating code from the code path to reduce the stack
14838b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
14848b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// when calling EXPECT_OP in a tight loop.
14858b92989c89bec8632aa47dc58dc162f199d62edcJames Zerntemplate <typename T1, typename T2>
14868b92989c89bec8632aa47dc58dc162f199d62edcJames ZernAssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
14878b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                   const T1& val1, const T2& val2,
14888b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                   const char* op) {
14898b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  return AssertionFailure()
14908b92989c89bec8632aa47dc58dc162f199d62edcJames Zern         << "Expected: (" << expr1 << ") " << op << " (" << expr2
14918b92989c89bec8632aa47dc58dc162f199d62edcJames Zern         << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
14928b92989c89bec8632aa47dc58dc162f199d62edcJames Zern         << " vs " << FormatForComparisonFailureMessage(val2, val1);
14938b92989c89bec8632aa47dc58dc162f199d62edcJames Zern}
14948b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
14951b362b15af34006e6a11974088a46d42b903418eJohann// A macro for implementing the helper functions needed to implement
14961b362b15af34006e6a11974088a46d42b903418eJohann// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
14971b362b15af34006e6a11974088a46d42b903418eJohann// of similar code.
14981b362b15af34006e6a11974088a46d42b903418eJohann//
14991b362b15af34006e6a11974088a46d42b903418eJohann// For each templatized helper function, we also define an overloaded
15001b362b15af34006e6a11974088a46d42b903418eJohann// version for BiggestInt in order to reduce code bloat and allow
15011b362b15af34006e6a11974088a46d42b903418eJohann// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
15021b362b15af34006e6a11974088a46d42b903418eJohann// with gcc 4.
15031b362b15af34006e6a11974088a46d42b903418eJohann//
15041b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15058b92989c89bec8632aa47dc58dc162f199d62edcJames Zern
15061b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
15071b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T1, typename T2>\
15081b362b15af34006e6a11974088a46d42b903418eJohannAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
15091b362b15af34006e6a11974088a46d42b903418eJohann                                   const T1& val1, const T2& val2) {\
15101b362b15af34006e6a11974088a46d42b903418eJohann  if (val1 op val2) {\
15111b362b15af34006e6a11974088a46d42b903418eJohann    return AssertionSuccess();\
15121b362b15af34006e6a11974088a46d42b903418eJohann  } else {\
15138b92989c89bec8632aa47dc58dc162f199d62edcJames Zern    return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
15141b362b15af34006e6a11974088a46d42b903418eJohann  }\
15151b362b15af34006e6a11974088a46d42b903418eJohann}\
15161b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult CmpHelper##op_name(\
15171b362b15af34006e6a11974088a46d42b903418eJohann    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
15181b362b15af34006e6a11974088a46d42b903418eJohann
15191b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15201b362b15af34006e6a11974088a46d42b903418eJohann
15211b362b15af34006e6a11974088a46d42b903418eJohann// Implements the helper function for {ASSERT|EXPECT}_NE
15221b362b15af34006e6a11974088a46d42b903418eJohannGTEST_IMPL_CMP_HELPER_(NE, !=);
15231b362b15af34006e6a11974088a46d42b903418eJohann// Implements the helper function for {ASSERT|EXPECT}_LE
15241b362b15af34006e6a11974088a46d42b903418eJohannGTEST_IMPL_CMP_HELPER_(LE, <=);
15251b362b15af34006e6a11974088a46d42b903418eJohann// Implements the helper function for {ASSERT|EXPECT}_LT
15265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_IMPL_CMP_HELPER_(LT, <);
15271b362b15af34006e6a11974088a46d42b903418eJohann// Implements the helper function for {ASSERT|EXPECT}_GE
15281b362b15af34006e6a11974088a46d42b903418eJohannGTEST_IMPL_CMP_HELPER_(GE, >=);
15291b362b15af34006e6a11974088a46d42b903418eJohann// Implements the helper function for {ASSERT|EXPECT}_GT
15305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_IMPL_CMP_HELPER_(GT, >);
15311b362b15af34006e6a11974088a46d42b903418eJohann
15321b362b15af34006e6a11974088a46d42b903418eJohann#undef GTEST_IMPL_CMP_HELPER_
15331b362b15af34006e6a11974088a46d42b903418eJohann
15341b362b15af34006e6a11974088a46d42b903418eJohann// The helper function for {ASSERT|EXPECT}_STREQ.
15351b362b15af34006e6a11974088a46d42b903418eJohann//
15361b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15378b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
15388b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const char* s2_expression,
15398b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const char* s1,
15408b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const char* s2);
15411b362b15af34006e6a11974088a46d42b903418eJohann
15421b362b15af34006e6a11974088a46d42b903418eJohann// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
15431b362b15af34006e6a11974088a46d42b903418eJohann//
15441b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15458b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
15468b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                              const char* s2_expression,
15478b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                              const char* s1,
15488b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                              const char* s2);
15491b362b15af34006e6a11974088a46d42b903418eJohann
15501b362b15af34006e6a11974088a46d42b903418eJohann// The helper function for {ASSERT|EXPECT}_STRNE.
15511b362b15af34006e6a11974088a46d42b903418eJohann//
15521b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15531b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
15541b362b15af34006e6a11974088a46d42b903418eJohann                                          const char* s2_expression,
15551b362b15af34006e6a11974088a46d42b903418eJohann                                          const char* s1,
15561b362b15af34006e6a11974088a46d42b903418eJohann                                          const char* s2);
15571b362b15af34006e6a11974088a46d42b903418eJohann
15581b362b15af34006e6a11974088a46d42b903418eJohann// The helper function for {ASSERT|EXPECT}_STRCASENE.
15591b362b15af34006e6a11974088a46d42b903418eJohann//
15601b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15611b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
15621b362b15af34006e6a11974088a46d42b903418eJohann                                              const char* s2_expression,
15631b362b15af34006e6a11974088a46d42b903418eJohann                                              const char* s1,
15641b362b15af34006e6a11974088a46d42b903418eJohann                                              const char* s2);
15651b362b15af34006e6a11974088a46d42b903418eJohann
15661b362b15af34006e6a11974088a46d42b903418eJohann
15671b362b15af34006e6a11974088a46d42b903418eJohann// Helper function for *_STREQ on wide strings.
15681b362b15af34006e6a11974088a46d42b903418eJohann//
15691b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15708b92989c89bec8632aa47dc58dc162f199d62edcJames ZernGTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
15718b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const char* s2_expression,
15728b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const wchar_t* s1,
15738b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                          const wchar_t* s2);
15741b362b15af34006e6a11974088a46d42b903418eJohann
15751b362b15af34006e6a11974088a46d42b903418eJohann// Helper function for *_STRNE on wide strings.
15761b362b15af34006e6a11974088a46d42b903418eJohann//
15771b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
15781b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
15791b362b15af34006e6a11974088a46d42b903418eJohann                                          const char* s2_expression,
15801b362b15af34006e6a11974088a46d42b903418eJohann                                          const wchar_t* s1,
15811b362b15af34006e6a11974088a46d42b903418eJohann                                          const wchar_t* s2);
15821b362b15af34006e6a11974088a46d42b903418eJohann
15831b362b15af34006e6a11974088a46d42b903418eJohann}  // namespace internal
15841b362b15af34006e6a11974088a46d42b903418eJohann
15851b362b15af34006e6a11974088a46d42b903418eJohann// IsSubstring() and IsNotSubstring() are intended to be used as the
15861b362b15af34006e6a11974088a46d42b903418eJohann// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
15871b362b15af34006e6a11974088a46d42b903418eJohann// themselves.  They check whether needle is a substring of haystack
15881b362b15af34006e6a11974088a46d42b903418eJohann// (NULL is considered a substring of itself only), and return an
15891b362b15af34006e6a11974088a46d42b903418eJohann// appropriate error message when they fail.
15901b362b15af34006e6a11974088a46d42b903418eJohann//
15911b362b15af34006e6a11974088a46d42b903418eJohann// The {needle,haystack}_expr arguments are the stringified
15921b362b15af34006e6a11974088a46d42b903418eJohann// expressions that generated the two real arguments.
15931b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsSubstring(
15941b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
15951b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle, const char* haystack);
15961b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsSubstring(
15971b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
15981b362b15af34006e6a11974088a46d42b903418eJohann    const wchar_t* needle, const wchar_t* haystack);
15991b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsNotSubstring(
16001b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16011b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle, const char* haystack);
16021b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsNotSubstring(
16031b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16041b362b15af34006e6a11974088a46d42b903418eJohann    const wchar_t* needle, const wchar_t* haystack);
16051b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsSubstring(
16061b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16071b362b15af34006e6a11974088a46d42b903418eJohann    const ::std::string& needle, const ::std::string& haystack);
16081b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsNotSubstring(
16091b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16101b362b15af34006e6a11974088a46d42b903418eJohann    const ::std::string& needle, const ::std::string& haystack);
16111b362b15af34006e6a11974088a46d42b903418eJohann
16121b362b15af34006e6a11974088a46d42b903418eJohann#if GTEST_HAS_STD_WSTRING
16131b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsSubstring(
16141b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16151b362b15af34006e6a11974088a46d42b903418eJohann    const ::std::wstring& needle, const ::std::wstring& haystack);
16161b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult IsNotSubstring(
16171b362b15af34006e6a11974088a46d42b903418eJohann    const char* needle_expr, const char* haystack_expr,
16181b362b15af34006e6a11974088a46d42b903418eJohann    const ::std::wstring& needle, const ::std::wstring& haystack);
16191b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_HAS_STD_WSTRING
16201b362b15af34006e6a11974088a46d42b903418eJohann
16211b362b15af34006e6a11974088a46d42b903418eJohannnamespace internal {
16221b362b15af34006e6a11974088a46d42b903418eJohann
16231b362b15af34006e6a11974088a46d42b903418eJohann// Helper template function for comparing floating-points.
16241b362b15af34006e6a11974088a46d42b903418eJohann//
16251b362b15af34006e6a11974088a46d42b903418eJohann// Template parameter:
16261b362b15af34006e6a11974088a46d42b903418eJohann//
16271b362b15af34006e6a11974088a46d42b903418eJohann//   RawType: the raw floating-point type (either float or double)
16281b362b15af34006e6a11974088a46d42b903418eJohann//
16291b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
16301b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename RawType>
16318b92989c89bec8632aa47dc58dc162f199d62edcJames ZernAssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
16328b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                         const char* rhs_expression,
16338b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                         RawType lhs_value,
16348b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                                         RawType rhs_value) {
16358b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
16361b362b15af34006e6a11974088a46d42b903418eJohann
16371b362b15af34006e6a11974088a46d42b903418eJohann  if (lhs.AlmostEquals(rhs)) {
16381b362b15af34006e6a11974088a46d42b903418eJohann    return AssertionSuccess();
16391b362b15af34006e6a11974088a46d42b903418eJohann  }
16401b362b15af34006e6a11974088a46d42b903418eJohann
16418b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  ::std::stringstream lhs_ss;
16428b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
16438b92989c89bec8632aa47dc58dc162f199d62edcJames Zern         << lhs_value;
16441b362b15af34006e6a11974088a46d42b903418eJohann
16458b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  ::std::stringstream rhs_ss;
16468b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
16478b92989c89bec8632aa47dc58dc162f199d62edcJames Zern         << rhs_value;
16481b362b15af34006e6a11974088a46d42b903418eJohann
16498b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  return EqFailure(lhs_expression,
16508b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   rhs_expression,
16518b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   StringStreamToString(&lhs_ss),
16528b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                   StringStreamToString(&rhs_ss),
16531b362b15af34006e6a11974088a46d42b903418eJohann                   false);
16541b362b15af34006e6a11974088a46d42b903418eJohann}
16551b362b15af34006e6a11974088a46d42b903418eJohann
16561b362b15af34006e6a11974088a46d42b903418eJohann// Helper function for implementing ASSERT_NEAR.
16571b362b15af34006e6a11974088a46d42b903418eJohann//
16581b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
16591b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
16601b362b15af34006e6a11974088a46d42b903418eJohann                                                const char* expr2,
16611b362b15af34006e6a11974088a46d42b903418eJohann                                                const char* abs_error_expr,
16621b362b15af34006e6a11974088a46d42b903418eJohann                                                double val1,
16631b362b15af34006e6a11974088a46d42b903418eJohann                                                double val2,
16641b362b15af34006e6a11974088a46d42b903418eJohann                                                double abs_error);
16651b362b15af34006e6a11974088a46d42b903418eJohann
16661b362b15af34006e6a11974088a46d42b903418eJohann// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
16671b362b15af34006e6a11974088a46d42b903418eJohann// A class that enables one to stream messages to assertion macros
16681b362b15af34006e6a11974088a46d42b903418eJohannclass GTEST_API_ AssertHelper {
16691b362b15af34006e6a11974088a46d42b903418eJohann public:
16701b362b15af34006e6a11974088a46d42b903418eJohann  // Constructor.
16711b362b15af34006e6a11974088a46d42b903418eJohann  AssertHelper(TestPartResult::Type type,
16721b362b15af34006e6a11974088a46d42b903418eJohann               const char* file,
16731b362b15af34006e6a11974088a46d42b903418eJohann               int line,
16741b362b15af34006e6a11974088a46d42b903418eJohann               const char* message);
16751b362b15af34006e6a11974088a46d42b903418eJohann  ~AssertHelper();
16761b362b15af34006e6a11974088a46d42b903418eJohann
16771b362b15af34006e6a11974088a46d42b903418eJohann  // Message assignment is a semantic trick to enable assertion
16781b362b15af34006e6a11974088a46d42b903418eJohann  // streaming; see the GTEST_MESSAGE_ macro below.
16791b362b15af34006e6a11974088a46d42b903418eJohann  void operator=(const Message& message) const;
16801b362b15af34006e6a11974088a46d42b903418eJohann
16811b362b15af34006e6a11974088a46d42b903418eJohann private:
16821b362b15af34006e6a11974088a46d42b903418eJohann  // We put our data in a struct so that the size of the AssertHelper class can
16831b362b15af34006e6a11974088a46d42b903418eJohann  // be as small as possible.  This is important because gcc is incapable of
16841b362b15af34006e6a11974088a46d42b903418eJohann  // re-using stack space even for temporary variables, so every EXPECT_EQ
16851b362b15af34006e6a11974088a46d42b903418eJohann  // reserves stack space for another AssertHelper.
16861b362b15af34006e6a11974088a46d42b903418eJohann  struct AssertHelperData {
16871b362b15af34006e6a11974088a46d42b903418eJohann    AssertHelperData(TestPartResult::Type t,
16881b362b15af34006e6a11974088a46d42b903418eJohann                     const char* srcfile,
16891b362b15af34006e6a11974088a46d42b903418eJohann                     int line_num,
16901b362b15af34006e6a11974088a46d42b903418eJohann                     const char* msg)
16911b362b15af34006e6a11974088a46d42b903418eJohann        : type(t), file(srcfile), line(line_num), message(msg) { }
16921b362b15af34006e6a11974088a46d42b903418eJohann
16931b362b15af34006e6a11974088a46d42b903418eJohann    TestPartResult::Type const type;
16945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    const char* const file;
16955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    int const line;
16965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    std::string const message;
16971b362b15af34006e6a11974088a46d42b903418eJohann
16981b362b15af34006e6a11974088a46d42b903418eJohann   private:
16991b362b15af34006e6a11974088a46d42b903418eJohann    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
17001b362b15af34006e6a11974088a46d42b903418eJohann  };
17011b362b15af34006e6a11974088a46d42b903418eJohann
17021b362b15af34006e6a11974088a46d42b903418eJohann  AssertHelperData* const data_;
17031b362b15af34006e6a11974088a46d42b903418eJohann
17041b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
17051b362b15af34006e6a11974088a46d42b903418eJohann};
17061b362b15af34006e6a11974088a46d42b903418eJohann
17071b362b15af34006e6a11974088a46d42b903418eJohann}  // namespace internal
17081b362b15af34006e6a11974088a46d42b903418eJohann
17091b362b15af34006e6a11974088a46d42b903418eJohann#if GTEST_HAS_PARAM_TEST
17101b362b15af34006e6a11974088a46d42b903418eJohann// The pure interface class that all value-parameterized tests inherit from.
17111b362b15af34006e6a11974088a46d42b903418eJohann// A value-parameterized class must inherit from both ::testing::Test and
17121b362b15af34006e6a11974088a46d42b903418eJohann// ::testing::WithParamInterface. In most cases that just means inheriting
17131b362b15af34006e6a11974088a46d42b903418eJohann// from ::testing::TestWithParam, but more complicated test hierarchies
17141b362b15af34006e6a11974088a46d42b903418eJohann// may need to inherit from Test and WithParamInterface at different levels.
17151b362b15af34006e6a11974088a46d42b903418eJohann//
17161b362b15af34006e6a11974088a46d42b903418eJohann// This interface has support for accessing the test parameter value via
17171b362b15af34006e6a11974088a46d42b903418eJohann// the GetParam() method.
17181b362b15af34006e6a11974088a46d42b903418eJohann//
17191b362b15af34006e6a11974088a46d42b903418eJohann// Use it with one of the parameter generator defining functions, like Range(),
17201b362b15af34006e6a11974088a46d42b903418eJohann// Values(), ValuesIn(), Bool(), and Combine().
17211b362b15af34006e6a11974088a46d42b903418eJohann//
17221b362b15af34006e6a11974088a46d42b903418eJohann// class FooTest : public ::testing::TestWithParam<int> {
17231b362b15af34006e6a11974088a46d42b903418eJohann//  protected:
17241b362b15af34006e6a11974088a46d42b903418eJohann//   FooTest() {
17251b362b15af34006e6a11974088a46d42b903418eJohann//     // Can use GetParam() here.
17261b362b15af34006e6a11974088a46d42b903418eJohann//   }
17271b362b15af34006e6a11974088a46d42b903418eJohann//   virtual ~FooTest() {
17281b362b15af34006e6a11974088a46d42b903418eJohann//     // Can use GetParam() here.
17291b362b15af34006e6a11974088a46d42b903418eJohann//   }
17301b362b15af34006e6a11974088a46d42b903418eJohann//   virtual void SetUp() {
17311b362b15af34006e6a11974088a46d42b903418eJohann//     // Can use GetParam() here.
17321b362b15af34006e6a11974088a46d42b903418eJohann//   }
17331b362b15af34006e6a11974088a46d42b903418eJohann//   virtual void TearDown {
17341b362b15af34006e6a11974088a46d42b903418eJohann//     // Can use GetParam() here.
17351b362b15af34006e6a11974088a46d42b903418eJohann//   }
17361b362b15af34006e6a11974088a46d42b903418eJohann// };
17371b362b15af34006e6a11974088a46d42b903418eJohann// TEST_P(FooTest, DoesBar) {
17381b362b15af34006e6a11974088a46d42b903418eJohann//   // Can use GetParam() method here.
17391b362b15af34006e6a11974088a46d42b903418eJohann//   Foo foo;
17401b362b15af34006e6a11974088a46d42b903418eJohann//   ASSERT_TRUE(foo.DoesBar(GetParam()));
17411b362b15af34006e6a11974088a46d42b903418eJohann// }
17421b362b15af34006e6a11974088a46d42b903418eJohann// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
17431b362b15af34006e6a11974088a46d42b903418eJohann
17441b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T>
17451b362b15af34006e6a11974088a46d42b903418eJohannclass WithParamInterface {
17461b362b15af34006e6a11974088a46d42b903418eJohann public:
17471b362b15af34006e6a11974088a46d42b903418eJohann  typedef T ParamType;
17481b362b15af34006e6a11974088a46d42b903418eJohann  virtual ~WithParamInterface() {}
17491b362b15af34006e6a11974088a46d42b903418eJohann
17501b362b15af34006e6a11974088a46d42b903418eJohann  // The current parameter value. Is also available in the test fixture's
17511b362b15af34006e6a11974088a46d42b903418eJohann  // constructor. This member function is non-static, even though it only
17521b362b15af34006e6a11974088a46d42b903418eJohann  // references static data, to reduce the opportunity for incorrect uses
17531b362b15af34006e6a11974088a46d42b903418eJohann  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
17541b362b15af34006e6a11974088a46d42b903418eJohann  // uses a fixture whose parameter type is int.
17555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  const ParamType& GetParam() const {
17565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    GTEST_CHECK_(parameter_ != NULL)
17575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang        << "GetParam() can only be called inside a value-parameterized test "
17585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang        << "-- did you intend to write TEST_P instead of TEST_F?";
17595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang    return *parameter_;
17605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  }
17611b362b15af34006e6a11974088a46d42b903418eJohann
17621b362b15af34006e6a11974088a46d42b903418eJohann private:
17631b362b15af34006e6a11974088a46d42b903418eJohann  // Sets parameter value. The caller is responsible for making sure the value
17641b362b15af34006e6a11974088a46d42b903418eJohann  // remains alive and unchanged throughout the current test.
17651b362b15af34006e6a11974088a46d42b903418eJohann  static void SetParam(const ParamType* parameter) {
17661b362b15af34006e6a11974088a46d42b903418eJohann    parameter_ = parameter;
17671b362b15af34006e6a11974088a46d42b903418eJohann  }
17681b362b15af34006e6a11974088a46d42b903418eJohann
17691b362b15af34006e6a11974088a46d42b903418eJohann  // Static value used for accessing parameter during a test lifetime.
17701b362b15af34006e6a11974088a46d42b903418eJohann  static const ParamType* parameter_;
17711b362b15af34006e6a11974088a46d42b903418eJohann
17721b362b15af34006e6a11974088a46d42b903418eJohann  // TestClass must be a subclass of WithParamInterface<T> and Test.
17731b362b15af34006e6a11974088a46d42b903418eJohann  template <class TestClass> friend class internal::ParameterizedTestFactory;
17741b362b15af34006e6a11974088a46d42b903418eJohann};
17751b362b15af34006e6a11974088a46d42b903418eJohann
17761b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T>
17771b362b15af34006e6a11974088a46d42b903418eJohannconst T* WithParamInterface<T>::parameter_ = NULL;
17781b362b15af34006e6a11974088a46d42b903418eJohann
17791b362b15af34006e6a11974088a46d42b903418eJohann// Most value-parameterized classes can ignore the existence of
17801b362b15af34006e6a11974088a46d42b903418eJohann// WithParamInterface, and can just inherit from ::testing::TestWithParam.
17811b362b15af34006e6a11974088a46d42b903418eJohann
17821b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T>
17831b362b15af34006e6a11974088a46d42b903418eJohannclass TestWithParam : public Test, public WithParamInterface<T> {
17841b362b15af34006e6a11974088a46d42b903418eJohann};
17851b362b15af34006e6a11974088a46d42b903418eJohann
17861b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_HAS_PARAM_TEST
17871b362b15af34006e6a11974088a46d42b903418eJohann
17881b362b15af34006e6a11974088a46d42b903418eJohann// Macros for indicating success/failure in test code.
17891b362b15af34006e6a11974088a46d42b903418eJohann
17901b362b15af34006e6a11974088a46d42b903418eJohann// ADD_FAILURE unconditionally adds a failure to the current test.
17911b362b15af34006e6a11974088a46d42b903418eJohann// SUCCEED generates a success - it doesn't automatically make the
17921b362b15af34006e6a11974088a46d42b903418eJohann// current test successful, as a test is only successful when it has
17931b362b15af34006e6a11974088a46d42b903418eJohann// no failure.
17941b362b15af34006e6a11974088a46d42b903418eJohann//
17951b362b15af34006e6a11974088a46d42b903418eJohann// EXPECT_* verifies that a certain condition is satisfied.  If not,
17961b362b15af34006e6a11974088a46d42b903418eJohann// it behaves like ADD_FAILURE.  In particular:
17971b362b15af34006e6a11974088a46d42b903418eJohann//
17981b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_TRUE  verifies that a Boolean condition is true.
17991b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_FALSE verifies that a Boolean condition is false.
18001b362b15af34006e6a11974088a46d42b903418eJohann//
18011b362b15af34006e6a11974088a46d42b903418eJohann// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
18021b362b15af34006e6a11974088a46d42b903418eJohann// that they will also abort the current function on failure.  People
18031b362b15af34006e6a11974088a46d42b903418eJohann// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
18041b362b15af34006e6a11974088a46d42b903418eJohann// writing data-driven tests often find themselves using ADD_FAILURE
18051b362b15af34006e6a11974088a46d42b903418eJohann// and EXPECT_* more.
18061b362b15af34006e6a11974088a46d42b903418eJohann
18071b362b15af34006e6a11974088a46d42b903418eJohann// Generates a nonfatal failure with a generic message.
18081b362b15af34006e6a11974088a46d42b903418eJohann#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
18091b362b15af34006e6a11974088a46d42b903418eJohann
18101b362b15af34006e6a11974088a46d42b903418eJohann// Generates a nonfatal failure at the given source file location with
18111b362b15af34006e6a11974088a46d42b903418eJohann// a generic message.
18121b362b15af34006e6a11974088a46d42b903418eJohann#define ADD_FAILURE_AT(file, line) \
18131b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_MESSAGE_AT_(file, line, "Failed", \
18141b362b15af34006e6a11974088a46d42b903418eJohann                    ::testing::TestPartResult::kNonFatalFailure)
18151b362b15af34006e6a11974088a46d42b903418eJohann
18161b362b15af34006e6a11974088a46d42b903418eJohann// Generates a fatal failure with a generic message.
18171b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
18181b362b15af34006e6a11974088a46d42b903418eJohann
18191b362b15af34006e6a11974088a46d42b903418eJohann// Define this macro to 1 to omit the definition of FAIL(), which is a
18201b362b15af34006e6a11974088a46d42b903418eJohann// generic name and clashes with some other libraries.
18211b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_FAIL
18221b362b15af34006e6a11974088a46d42b903418eJohann# define FAIL() GTEST_FAIL()
18231b362b15af34006e6a11974088a46d42b903418eJohann#endif
18241b362b15af34006e6a11974088a46d42b903418eJohann
18251b362b15af34006e6a11974088a46d42b903418eJohann// Generates a success with a generic message.
18261b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
18271b362b15af34006e6a11974088a46d42b903418eJohann
18281b362b15af34006e6a11974088a46d42b903418eJohann// Define this macro to 1 to omit the definition of SUCCEED(), which
18291b362b15af34006e6a11974088a46d42b903418eJohann// is a generic name and clashes with some other libraries.
18301b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_SUCCEED
18311b362b15af34006e6a11974088a46d42b903418eJohann# define SUCCEED() GTEST_SUCCEED()
18321b362b15af34006e6a11974088a46d42b903418eJohann#endif
18331b362b15af34006e6a11974088a46d42b903418eJohann
18341b362b15af34006e6a11974088a46d42b903418eJohann// Macros for testing exceptions.
18351b362b15af34006e6a11974088a46d42b903418eJohann//
18361b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
18371b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that the statement throws the expected exception.
18381b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_NO_THROW(statement):
18391b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that the statement doesn't throw any exception.
18401b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_ANY_THROW(statement):
18411b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that the statement throws an exception.
18421b362b15af34006e6a11974088a46d42b903418eJohann
18431b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_THROW(statement, expected_exception) \
18441b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
18451b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_NO_THROW(statement) \
18461b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
18471b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_ANY_THROW(statement) \
18481b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
18491b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_THROW(statement, expected_exception) \
18501b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
18511b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_NO_THROW(statement) \
18521b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
18531b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_ANY_THROW(statement) \
18541b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
18551b362b15af34006e6a11974088a46d42b903418eJohann
18561b362b15af34006e6a11974088a46d42b903418eJohann// Boolean assertions. Condition can be either a Boolean expression or an
18571b362b15af34006e6a11974088a46d42b903418eJohann// AssertionResult. For more information on how to use AssertionResult with
18581b362b15af34006e6a11974088a46d42b903418eJohann// these macros see comments on that class.
18591b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_TRUE(condition) \
18608b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
18611b362b15af34006e6a11974088a46d42b903418eJohann                      GTEST_NONFATAL_FAILURE_)
18621b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_FALSE(condition) \
18631b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
18641b362b15af34006e6a11974088a46d42b903418eJohann                      GTEST_NONFATAL_FAILURE_)
18651b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_TRUE(condition) \
18668b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
18671b362b15af34006e6a11974088a46d42b903418eJohann                      GTEST_FATAL_FAILURE_)
18681b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_FALSE(condition) \
18691b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
18701b362b15af34006e6a11974088a46d42b903418eJohann                      GTEST_FATAL_FAILURE_)
18711b362b15af34006e6a11974088a46d42b903418eJohann
18721b362b15af34006e6a11974088a46d42b903418eJohann// Includes the auto-generated header that implements a family of
18731b362b15af34006e6a11974088a46d42b903418eJohann// generic predicate assertion macros.
18748b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#include "gtest/gtest_pred_impl.h"
18751b362b15af34006e6a11974088a46d42b903418eJohann
18761b362b15af34006e6a11974088a46d42b903418eJohann// Macros for testing equalities and inequalities.
18771b362b15af34006e6a11974088a46d42b903418eJohann//
18788b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
18798b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
18808b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
18818b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
18828b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
18838b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
18841b362b15af34006e6a11974088a46d42b903418eJohann//
18851b362b15af34006e6a11974088a46d42b903418eJohann// When they are not, Google Test prints both the tested expressions and
18861b362b15af34006e6a11974088a46d42b903418eJohann// their actual values.  The values must be compatible built-in types,
18871b362b15af34006e6a11974088a46d42b903418eJohann// or you will get a compiler error.  By "compatible" we mean that the
18881b362b15af34006e6a11974088a46d42b903418eJohann// values can be compared by the respective operator.
18891b362b15af34006e6a11974088a46d42b903418eJohann//
18901b362b15af34006e6a11974088a46d42b903418eJohann// Note:
18911b362b15af34006e6a11974088a46d42b903418eJohann//
18921b362b15af34006e6a11974088a46d42b903418eJohann//   1. It is possible to make a user-defined type work with
18931b362b15af34006e6a11974088a46d42b903418eJohann//   {ASSERT|EXPECT}_??(), but that requires overloading the
18941b362b15af34006e6a11974088a46d42b903418eJohann//   comparison operators and is thus discouraged by the Google C++
18951b362b15af34006e6a11974088a46d42b903418eJohann//   Usage Guide.  Therefore, you are advised to use the
18961b362b15af34006e6a11974088a46d42b903418eJohann//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
18971b362b15af34006e6a11974088a46d42b903418eJohann//   equal.
18981b362b15af34006e6a11974088a46d42b903418eJohann//
18991b362b15af34006e6a11974088a46d42b903418eJohann//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
19001b362b15af34006e6a11974088a46d42b903418eJohann//   pointers (in particular, C strings).  Therefore, if you use it
19011b362b15af34006e6a11974088a46d42b903418eJohann//   with two C strings, you are testing how their locations in memory
19021b362b15af34006e6a11974088a46d42b903418eJohann//   are related, not how their content is related.  To compare two C
19031b362b15af34006e6a11974088a46d42b903418eJohann//   strings by content, use {ASSERT|EXPECT}_STR*().
19041b362b15af34006e6a11974088a46d42b903418eJohann//
19058b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//   3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
19068b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//   {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
19071b362b15af34006e6a11974088a46d42b903418eJohann//   what the actual value is when it fails, and similarly for the
19081b362b15af34006e6a11974088a46d42b903418eJohann//   other comparisons.
19091b362b15af34006e6a11974088a46d42b903418eJohann//
19101b362b15af34006e6a11974088a46d42b903418eJohann//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
19111b362b15af34006e6a11974088a46d42b903418eJohann//   evaluate their arguments, which is undefined.
19121b362b15af34006e6a11974088a46d42b903418eJohann//
19131b362b15af34006e6a11974088a46d42b903418eJohann//   5. These macros evaluate their arguments exactly once.
19141b362b15af34006e6a11974088a46d42b903418eJohann//
19151b362b15af34006e6a11974088a46d42b903418eJohann// Examples:
19161b362b15af34006e6a11974088a46d42b903418eJohann//
19171b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_NE(5, Foo());
19181b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_EQ(NULL, a_pointer);
19191b362b15af34006e6a11974088a46d42b903418eJohann//   ASSERT_LT(i, array_size);
19201b362b15af34006e6a11974088a46d42b903418eJohann//   ASSERT_GT(records.size(), 0) << "There is no record left.";
19211b362b15af34006e6a11974088a46d42b903418eJohann
19228b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_EQ(val1, val2) \
19231b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal:: \
19248b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
19258b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
19268b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_NE(val1, val2) \
19278b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
19281b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_LE(val1, val2) \
19291b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
19301b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_LT(val1, val2) \
19311b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
19321b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_GE(val1, val2) \
19331b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
19341b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_GT(val1, val2) \
19351b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
19361b362b15af34006e6a11974088a46d42b903418eJohann
19378b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define GTEST_ASSERT_EQ(val1, val2) \
19381b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal:: \
19398b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
19408b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
19411b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_ASSERT_NE(val1, val2) \
19421b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
19431b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_ASSERT_LE(val1, val2) \
19441b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
19451b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_ASSERT_LT(val1, val2) \
19461b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
19471b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_ASSERT_GE(val1, val2) \
19481b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
19491b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_ASSERT_GT(val1, val2) \
19501b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
19511b362b15af34006e6a11974088a46d42b903418eJohann
19521b362b15af34006e6a11974088a46d42b903418eJohann// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
19531b362b15af34006e6a11974088a46d42b903418eJohann// ASSERT_XY(), which clashes with some users' own code.
19541b362b15af34006e6a11974088a46d42b903418eJohann
19551b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_EQ
19561b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
19571b362b15af34006e6a11974088a46d42b903418eJohann#endif
19581b362b15af34006e6a11974088a46d42b903418eJohann
19591b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_NE
19601b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
19611b362b15af34006e6a11974088a46d42b903418eJohann#endif
19621b362b15af34006e6a11974088a46d42b903418eJohann
19631b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_LE
19641b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
19651b362b15af34006e6a11974088a46d42b903418eJohann#endif
19661b362b15af34006e6a11974088a46d42b903418eJohann
19671b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_LT
19681b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
19691b362b15af34006e6a11974088a46d42b903418eJohann#endif
19701b362b15af34006e6a11974088a46d42b903418eJohann
19711b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_GE
19721b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
19731b362b15af34006e6a11974088a46d42b903418eJohann#endif
19741b362b15af34006e6a11974088a46d42b903418eJohann
19751b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_ASSERT_GT
19761b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
19771b362b15af34006e6a11974088a46d42b903418eJohann#endif
19781b362b15af34006e6a11974088a46d42b903418eJohann
19795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// C-string Comparisons.  All tests treat NULL and any non-NULL string
19801b362b15af34006e6a11974088a46d42b903418eJohann// as different.  Two NULLs are equal.
19811b362b15af34006e6a11974088a46d42b903418eJohann//
19821b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
19831b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
19841b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
19851b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
19861b362b15af34006e6a11974088a46d42b903418eJohann//
19871b362b15af34006e6a11974088a46d42b903418eJohann// For wide or narrow string objects, you can use the
19881b362b15af34006e6a11974088a46d42b903418eJohann// {ASSERT|EXPECT}_??() macros.
19891b362b15af34006e6a11974088a46d42b903418eJohann//
19901b362b15af34006e6a11974088a46d42b903418eJohann// Don't depend on the order in which the arguments are evaluated,
19911b362b15af34006e6a11974088a46d42b903418eJohann// which is undefined.
19921b362b15af34006e6a11974088a46d42b903418eJohann//
19931b362b15af34006e6a11974088a46d42b903418eJohann// These macros evaluate their arguments exactly once.
19941b362b15af34006e6a11974088a46d42b903418eJohann
19958b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_STREQ(s1, s2) \
19968b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
19971b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_STRNE(s1, s2) \
19981b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
19998b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_STRCASEEQ(s1, s2) \
20008b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
20011b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_STRCASENE(s1, s2)\
20021b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20031b362b15af34006e6a11974088a46d42b903418eJohann
20048b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define ASSERT_STREQ(s1, s2) \
20058b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
20061b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_STRNE(s1, s2) \
20071b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
20088b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define ASSERT_STRCASEEQ(s1, s2) \
20098b92989c89bec8632aa47dc58dc162f199d62edcJames Zern  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
20101b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_STRCASENE(s1, s2)\
20111b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
20121b362b15af34006e6a11974088a46d42b903418eJohann
20131b362b15af34006e6a11974088a46d42b903418eJohann// Macros for comparing floating-point numbers.
20141b362b15af34006e6a11974088a46d42b903418eJohann//
20158b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
20161b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that two float values are almost equal.
20178b92989c89bec8632aa47dc58dc162f199d62edcJames Zern//    * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
20181b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that two double values are almost equal.
20191b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
20201b362b15af34006e6a11974088a46d42b903418eJohann//         Tests that v1 and v2 are within the given distance to each other.
20211b362b15af34006e6a11974088a46d42b903418eJohann//
20221b362b15af34006e6a11974088a46d42b903418eJohann// Google Test uses ULP-based comparison to automatically pick a default
20231b362b15af34006e6a11974088a46d42b903418eJohann// error bound that is appropriate for the operands.  See the
20241b362b15af34006e6a11974088a46d42b903418eJohann// FloatingPoint template class in gtest-internal.h if you are
20251b362b15af34006e6a11974088a46d42b903418eJohann// interested in the implementation details.
20261b362b15af34006e6a11974088a46d42b903418eJohann
20278b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_FLOAT_EQ(val1, val2)\
20281b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
20298b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
20301b362b15af34006e6a11974088a46d42b903418eJohann
20318b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define EXPECT_DOUBLE_EQ(val1, val2)\
20321b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
20338b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
20341b362b15af34006e6a11974088a46d42b903418eJohann
20358b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define ASSERT_FLOAT_EQ(val1, val2)\
20361b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
20378b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
20381b362b15af34006e6a11974088a46d42b903418eJohann
20398b92989c89bec8632aa47dc58dc162f199d62edcJames Zern#define ASSERT_DOUBLE_EQ(val1, val2)\
20401b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
20418b92989c89bec8632aa47dc58dc162f199d62edcJames Zern                      val1, val2)
20421b362b15af34006e6a11974088a46d42b903418eJohann
20431b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_NEAR(val1, val2, abs_error)\
20441b362b15af34006e6a11974088a46d42b903418eJohann  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
20451b362b15af34006e6a11974088a46d42b903418eJohann                      val1, val2, abs_error)
20461b362b15af34006e6a11974088a46d42b903418eJohann
20471b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_NEAR(val1, val2, abs_error)\
20481b362b15af34006e6a11974088a46d42b903418eJohann  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
20491b362b15af34006e6a11974088a46d42b903418eJohann                      val1, val2, abs_error)
20501b362b15af34006e6a11974088a46d42b903418eJohann
20511b362b15af34006e6a11974088a46d42b903418eJohann// These predicate format functions work on floating-point values, and
20521b362b15af34006e6a11974088a46d42b903418eJohann// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
20531b362b15af34006e6a11974088a46d42b903418eJohann//
20541b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
20551b362b15af34006e6a11974088a46d42b903418eJohann
20561b362b15af34006e6a11974088a46d42b903418eJohann// Asserts that val1 is less than, or almost equal to, val2.  Fails
20571b362b15af34006e6a11974088a46d42b903418eJohann// otherwise.  In particular, it fails if either val1 or val2 is NaN.
20581b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
20591b362b15af34006e6a11974088a46d42b903418eJohann                                   float val1, float val2);
20601b362b15af34006e6a11974088a46d42b903418eJohannGTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
20611b362b15af34006e6a11974088a46d42b903418eJohann                                    double val1, double val2);
20621b362b15af34006e6a11974088a46d42b903418eJohann
20631b362b15af34006e6a11974088a46d42b903418eJohann
20641b362b15af34006e6a11974088a46d42b903418eJohann#if GTEST_OS_WINDOWS
20651b362b15af34006e6a11974088a46d42b903418eJohann
20661b362b15af34006e6a11974088a46d42b903418eJohann// Macros that test for HRESULT failure and success, these are only useful
20671b362b15af34006e6a11974088a46d42b903418eJohann// on Windows, and rely on Windows SDK macros and APIs to compile.
20681b362b15af34006e6a11974088a46d42b903418eJohann//
20691b362b15af34006e6a11974088a46d42b903418eJohann//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
20701b362b15af34006e6a11974088a46d42b903418eJohann//
20711b362b15af34006e6a11974088a46d42b903418eJohann// When expr unexpectedly fails or succeeds, Google Test prints the
20721b362b15af34006e6a11974088a46d42b903418eJohann// expected result and the actual result with both a human-readable
20731b362b15af34006e6a11974088a46d42b903418eJohann// string representation of the error, if available, as well as the
20741b362b15af34006e6a11974088a46d42b903418eJohann// hex result code.
20751b362b15af34006e6a11974088a46d42b903418eJohann# define EXPECT_HRESULT_SUCCEEDED(expr) \
20761b362b15af34006e6a11974088a46d42b903418eJohann    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
20771b362b15af34006e6a11974088a46d42b903418eJohann
20781b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_HRESULT_SUCCEEDED(expr) \
20791b362b15af34006e6a11974088a46d42b903418eJohann    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
20801b362b15af34006e6a11974088a46d42b903418eJohann
20811b362b15af34006e6a11974088a46d42b903418eJohann# define EXPECT_HRESULT_FAILED(expr) \
20821b362b15af34006e6a11974088a46d42b903418eJohann    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
20831b362b15af34006e6a11974088a46d42b903418eJohann
20841b362b15af34006e6a11974088a46d42b903418eJohann# define ASSERT_HRESULT_FAILED(expr) \
20851b362b15af34006e6a11974088a46d42b903418eJohann    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
20861b362b15af34006e6a11974088a46d42b903418eJohann
20871b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_OS_WINDOWS
20881b362b15af34006e6a11974088a46d42b903418eJohann
20891b362b15af34006e6a11974088a46d42b903418eJohann// Macros that execute statement and check that it doesn't generate new fatal
20901b362b15af34006e6a11974088a46d42b903418eJohann// failures in the current thread.
20911b362b15af34006e6a11974088a46d42b903418eJohann//
20921b362b15af34006e6a11974088a46d42b903418eJohann//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
20931b362b15af34006e6a11974088a46d42b903418eJohann//
20941b362b15af34006e6a11974088a46d42b903418eJohann// Examples:
20951b362b15af34006e6a11974088a46d42b903418eJohann//
20961b362b15af34006e6a11974088a46d42b903418eJohann//   EXPECT_NO_FATAL_FAILURE(Process());
20971b362b15af34006e6a11974088a46d42b903418eJohann//   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
20981b362b15af34006e6a11974088a46d42b903418eJohann//
20991b362b15af34006e6a11974088a46d42b903418eJohann#define ASSERT_NO_FATAL_FAILURE(statement) \
21001b362b15af34006e6a11974088a46d42b903418eJohann    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
21011b362b15af34006e6a11974088a46d42b903418eJohann#define EXPECT_NO_FATAL_FAILURE(statement) \
21021b362b15af34006e6a11974088a46d42b903418eJohann    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
21031b362b15af34006e6a11974088a46d42b903418eJohann
21041b362b15af34006e6a11974088a46d42b903418eJohann// Causes a trace (including the source file path, the current line
21051b362b15af34006e6a11974088a46d42b903418eJohann// number, and the given message) to be included in every test failure
21061b362b15af34006e6a11974088a46d42b903418eJohann// message generated by code in the current scope.  The effect is
21071b362b15af34006e6a11974088a46d42b903418eJohann// undone when the control leaves the current scope.
21081b362b15af34006e6a11974088a46d42b903418eJohann//
21091b362b15af34006e6a11974088a46d42b903418eJohann// The message argument can be anything streamable to std::ostream.
21101b362b15af34006e6a11974088a46d42b903418eJohann//
21111b362b15af34006e6a11974088a46d42b903418eJohann// In the implementation, we include the current line number as part
21121b362b15af34006e6a11974088a46d42b903418eJohann// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
21131b362b15af34006e6a11974088a46d42b903418eJohann// to appear in the same block - as long as they are on different
21141b362b15af34006e6a11974088a46d42b903418eJohann// lines.
21151b362b15af34006e6a11974088a46d42b903418eJohann#define SCOPED_TRACE(message) \
21161b362b15af34006e6a11974088a46d42b903418eJohann  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
21171b362b15af34006e6a11974088a46d42b903418eJohann    __FILE__, __LINE__, ::testing::Message() << (message))
21181b362b15af34006e6a11974088a46d42b903418eJohann
21191b362b15af34006e6a11974088a46d42b903418eJohann// Compile-time assertion for type equality.
21201b362b15af34006e6a11974088a46d42b903418eJohann// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
21211b362b15af34006e6a11974088a46d42b903418eJohann// the same type.  The value it returns is not interesting.
21221b362b15af34006e6a11974088a46d42b903418eJohann//
21231b362b15af34006e6a11974088a46d42b903418eJohann// Instead of making StaticAssertTypeEq a class template, we make it a
21241b362b15af34006e6a11974088a46d42b903418eJohann// function template that invokes a helper class template.  This
21251b362b15af34006e6a11974088a46d42b903418eJohann// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
21261b362b15af34006e6a11974088a46d42b903418eJohann// defining objects of that type.
21271b362b15af34006e6a11974088a46d42b903418eJohann//
21281b362b15af34006e6a11974088a46d42b903418eJohann// CAVEAT:
21291b362b15af34006e6a11974088a46d42b903418eJohann//
21301b362b15af34006e6a11974088a46d42b903418eJohann// When used inside a method of a class template,
21311b362b15af34006e6a11974088a46d42b903418eJohann// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
21321b362b15af34006e6a11974088a46d42b903418eJohann// instantiated.  For example, given:
21331b362b15af34006e6a11974088a46d42b903418eJohann//
21341b362b15af34006e6a11974088a46d42b903418eJohann//   template <typename T> class Foo {
21351b362b15af34006e6a11974088a46d42b903418eJohann//    public:
21361b362b15af34006e6a11974088a46d42b903418eJohann//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
21371b362b15af34006e6a11974088a46d42b903418eJohann//   };
21381b362b15af34006e6a11974088a46d42b903418eJohann//
21391b362b15af34006e6a11974088a46d42b903418eJohann// the code:
21401b362b15af34006e6a11974088a46d42b903418eJohann//
21411b362b15af34006e6a11974088a46d42b903418eJohann//   void Test1() { Foo<bool> foo; }
21421b362b15af34006e6a11974088a46d42b903418eJohann//
21431b362b15af34006e6a11974088a46d42b903418eJohann// will NOT generate a compiler error, as Foo<bool>::Bar() is never
21441b362b15af34006e6a11974088a46d42b903418eJohann// actually instantiated.  Instead, you need:
21451b362b15af34006e6a11974088a46d42b903418eJohann//
21461b362b15af34006e6a11974088a46d42b903418eJohann//   void Test2() { Foo<bool> foo; foo.Bar(); }
21471b362b15af34006e6a11974088a46d42b903418eJohann//
21481b362b15af34006e6a11974088a46d42b903418eJohann// to cause a compiler error.
21491b362b15af34006e6a11974088a46d42b903418eJohanntemplate <typename T1, typename T2>
21501b362b15af34006e6a11974088a46d42b903418eJohannbool StaticAssertTypeEq() {
21511b362b15af34006e6a11974088a46d42b903418eJohann  (void)internal::StaticAssertTypeEqHelper<T1, T2>();
21521b362b15af34006e6a11974088a46d42b903418eJohann  return true;
21531b362b15af34006e6a11974088a46d42b903418eJohann}
21541b362b15af34006e6a11974088a46d42b903418eJohann
21551b362b15af34006e6a11974088a46d42b903418eJohann// Defines a test.
21561b362b15af34006e6a11974088a46d42b903418eJohann//
21571b362b15af34006e6a11974088a46d42b903418eJohann// The first parameter is the name of the test case, and the second
21581b362b15af34006e6a11974088a46d42b903418eJohann// parameter is the name of the test within the test case.
21591b362b15af34006e6a11974088a46d42b903418eJohann//
21601b362b15af34006e6a11974088a46d42b903418eJohann// The convention is to end the test case name with "Test".  For
21611b362b15af34006e6a11974088a46d42b903418eJohann// example, a test case for the Foo class can be named FooTest.
21621b362b15af34006e6a11974088a46d42b903418eJohann//
21638b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// Test code should appear between braces after an invocation of
21648b92989c89bec8632aa47dc58dc162f199d62edcJames Zern// this macro.  Example:
21651b362b15af34006e6a11974088a46d42b903418eJohann//
21661b362b15af34006e6a11974088a46d42b903418eJohann//   TEST(FooTest, InitializesCorrectly) {
21671b362b15af34006e6a11974088a46d42b903418eJohann//     Foo foo;
21681b362b15af34006e6a11974088a46d42b903418eJohann//     EXPECT_TRUE(foo.StatusIsOK());
21691b362b15af34006e6a11974088a46d42b903418eJohann//   }
21701b362b15af34006e6a11974088a46d42b903418eJohann
21711b362b15af34006e6a11974088a46d42b903418eJohann// Note that we call GetTestTypeId() instead of GetTypeId<
21721b362b15af34006e6a11974088a46d42b903418eJohann// ::testing::Test>() here to get the type ID of testing::Test.  This
21731b362b15af34006e6a11974088a46d42b903418eJohann// is to work around a suspected linker bug when using Google Test as
21741b362b15af34006e6a11974088a46d42b903418eJohann// a framework on Mac OS X.  The bug causes GetTypeId<
21751b362b15af34006e6a11974088a46d42b903418eJohann// ::testing::Test>() to return different values depending on whether
21761b362b15af34006e6a11974088a46d42b903418eJohann// the call is from the Google Test framework itself or from user test
21771b362b15af34006e6a11974088a46d42b903418eJohann// code.  GetTestTypeId() is guaranteed to always return the same
21781b362b15af34006e6a11974088a46d42b903418eJohann// value, as it always calls GetTypeId<>() from the Google Test
21791b362b15af34006e6a11974088a46d42b903418eJohann// framework.
21801b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_TEST(test_case_name, test_name)\
21811b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_(test_case_name, test_name, \
21821b362b15af34006e6a11974088a46d42b903418eJohann              ::testing::Test, ::testing::internal::GetTestTypeId())
21831b362b15af34006e6a11974088a46d42b903418eJohann
21841b362b15af34006e6a11974088a46d42b903418eJohann// Define this macro to 1 to omit the definition of TEST(), which
21851b362b15af34006e6a11974088a46d42b903418eJohann// is a generic name and clashes with some other libraries.
21861b362b15af34006e6a11974088a46d42b903418eJohann#if !GTEST_DONT_DEFINE_TEST
21871b362b15af34006e6a11974088a46d42b903418eJohann# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
21881b362b15af34006e6a11974088a46d42b903418eJohann#endif
21891b362b15af34006e6a11974088a46d42b903418eJohann
21901b362b15af34006e6a11974088a46d42b903418eJohann// Defines a test that uses a test fixture.
21911b362b15af34006e6a11974088a46d42b903418eJohann//
21921b362b15af34006e6a11974088a46d42b903418eJohann// The first parameter is the name of the test fixture class, which
21931b362b15af34006e6a11974088a46d42b903418eJohann// also doubles as the test case name.  The second parameter is the
21941b362b15af34006e6a11974088a46d42b903418eJohann// name of the test within the test case.
21951b362b15af34006e6a11974088a46d42b903418eJohann//
21961b362b15af34006e6a11974088a46d42b903418eJohann// A test fixture class must be declared earlier.  The user should put
21971b362b15af34006e6a11974088a46d42b903418eJohann// his test code between braces after using this macro.  Example:
21981b362b15af34006e6a11974088a46d42b903418eJohann//
21991b362b15af34006e6a11974088a46d42b903418eJohann//   class FooTest : public testing::Test {
22001b362b15af34006e6a11974088a46d42b903418eJohann//    protected:
22011b362b15af34006e6a11974088a46d42b903418eJohann//     virtual void SetUp() { b_.AddElement(3); }
22021b362b15af34006e6a11974088a46d42b903418eJohann//
22031b362b15af34006e6a11974088a46d42b903418eJohann//     Foo a_;
22041b362b15af34006e6a11974088a46d42b903418eJohann//     Foo b_;
22051b362b15af34006e6a11974088a46d42b903418eJohann//   };
22061b362b15af34006e6a11974088a46d42b903418eJohann//
22071b362b15af34006e6a11974088a46d42b903418eJohann//   TEST_F(FooTest, InitializesCorrectly) {
22081b362b15af34006e6a11974088a46d42b903418eJohann//     EXPECT_TRUE(a_.StatusIsOK());
22091b362b15af34006e6a11974088a46d42b903418eJohann//   }
22101b362b15af34006e6a11974088a46d42b903418eJohann//
22111b362b15af34006e6a11974088a46d42b903418eJohann//   TEST_F(FooTest, ReturnsElementCountCorrectly) {
22121b362b15af34006e6a11974088a46d42b903418eJohann//     EXPECT_EQ(0, a_.size());
22131b362b15af34006e6a11974088a46d42b903418eJohann//     EXPECT_EQ(1, b_.size());
22141b362b15af34006e6a11974088a46d42b903418eJohann//   }
22151b362b15af34006e6a11974088a46d42b903418eJohann
22161b362b15af34006e6a11974088a46d42b903418eJohann#define TEST_F(test_fixture, test_name)\
22171b362b15af34006e6a11974088a46d42b903418eJohann  GTEST_TEST_(test_fixture, test_name, test_fixture, \
22181b362b15af34006e6a11974088a46d42b903418eJohann              ::testing::internal::GetTypeId<test_fixture>())
22191b362b15af34006e6a11974088a46d42b903418eJohann
22205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}  // namespace testing
22215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang
22225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Use this function in main() to run all tests.  It returns 0 if all
22231b362b15af34006e6a11974088a46d42b903418eJohann// tests are successful, or 1 otherwise.
22241b362b15af34006e6a11974088a46d42b903418eJohann//
22251b362b15af34006e6a11974088a46d42b903418eJohann// RUN_ALL_TESTS() should be invoked after the command line has been
22261b362b15af34006e6a11974088a46d42b903418eJohann// parsed by InitGoogleTest().
22275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang//
22285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// This function was formerly a macro; thus, it is in the global
22295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// namespace and has an all-caps name.
22305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangint RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
22311b362b15af34006e6a11974088a46d42b903418eJohann
22325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline int RUN_ALL_TESTS() {
22335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang  return ::testing::UnitTest::GetInstance()->Run();
22345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}
22351b362b15af34006e6a11974088a46d42b903418eJohann
22361b362b15af34006e6a11974088a46d42b903418eJohann#endif  // GTEST_INCLUDE_GTEST_GTEST_H_
2237