13d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Copyright 2005, Google Inc. 23d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// All rights reserved. 33d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 43d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Redistribution and use in source and binary forms, with or without 53d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// modification, are permitted provided that the following conditions are 63d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// met: 73d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 83d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Redistributions of source code must retain the above copyright 93d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// notice, this list of conditions and the following disclaimer. 103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Redistributions in binary form must reproduce the above 113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// copyright notice, this list of conditions and the following disclaimer 123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// in the documentation and/or other materials provided with the 133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// distribution. 143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// * Neither the name of Google Inc. nor the names of its 153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// contributors may be used to endorse or promote products derived from 163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this software without specific prior written permission. 173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) 313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The Google C++ Testing Framework (Google Test) 333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This header file declares functions and macros used internally by 353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Google Test. They are subject to change without notice. 363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ 383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ 393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-port.h" 413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_OS_LINUX 433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <stdlib.h> 443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <sys/types.h> 453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <sys/wait.h> 463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# include <unistd.h> 473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_OS_LINUX 483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <ctype.h> 503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <string.h> 513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <iomanip> 523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <limits> 533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include <set> 543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-string.h" 563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-filepath.h" 573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#include "gtest/internal/gtest-type-util.h" 583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Due to C++ preprocessor weirdness, we need double indirection to 603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// concatenate two tokens when one of them is __LINE__. Writing 613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// foo ## __LINE__ 633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// will result in the token foo__LINE__, instead of foo followed by 653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the current line number. For more details, see 663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) 683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar 693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Google Test defines the testing::Message class to allow construction of 713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// test messages via the << operator. The idea is that anything 723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// streamable to std::ostream can be streamed to a testing::Message. 733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This allows a user to use his own types in Google Test assertions by 743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// overloading the << operator. 753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// util/gtl/stl_logging-inl.h overloads << for STL containers. These 773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// overloads cannot be defined in the std namespace, as that will be 783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// undefined behavior. Therefore, they are defined in the global 793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// namespace instead. 803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// C++'s symbol lookup rule (i.e. Koenig lookup) says that these 823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// overloads are visible in either the std namespace or the global 833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// namespace, but not other namespaces, including the testing 843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// namespace which Google Test's Message class is in. 853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// To allow STL containers (and other types that has a << operator 873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// defined in the global namespace) to be used in Google Test assertions, 883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// testing::Message must access the custom << operator from the global 893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// namespace. Hence this helper function. 903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Note: Jeffrey Yasskin suggested an alternative fix by "using 923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ::operator<<;" in the definition of Message's operator<<. That fix 933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// doesn't require a helper function, but unfortunately doesn't 943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compile with MSVC. 953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline void GTestStreamToHelper(std::ostream* os, const T& val) { 973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick *os << val; 983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass ProtocolMessage; 1013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace proto2 { class Message; } 1023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace testing { 1043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Forward declarations. 1063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass AssertionResult; // Result of an assertion. 1083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass Message; // Represents a failure message. 1093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass Test; // Represents a test. 1103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestInfo; // Information about a test. 1113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestPartResult; // Result of a test part. 1123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass UnitTest; // A collection of test cases. 1133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 1153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick::std::string PrintToString(const T& value); 1163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicknamespace internal { 1183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct TraceInfo; // Information about a trace point. 1203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass ScopedTrace; // Implements scoped trace. 1213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestInfoImpl; // Opaque implementation of TestInfo 1223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass UnitTestImpl; // Opaque implementation of UnitTest 1233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// How many times InitGoogleTest() has been called. 1253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickextern int g_init_gtest_count; 1263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The text used in failure messages to indicate the start of the 1283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// stack trace. 1293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ extern const char kStackTraceMarker[]; 1303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A secret type that Google Test users don't know about. It has no 1323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// definition on purpose. Therefore it's impossible to create a 1333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Secret object, which is what we want. 1343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass Secret; 1353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Two overloaded helpers for checking at compile time whether an 1373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// expression is a null pointer literal (i.e. NULL or any 0-valued 1383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compile-time integral constant). Their return values have 1393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// different sizes, so we can use sizeof() to test which version is 1403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// picked by the compiler. These helpers have no implementations, as 1413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// we only need their signatures. 1423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 1433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Given IsNullLiteralHelper(x), the compiler will pick the first 1443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// version if x can be implicitly converted to Secret*, and pick the 1453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// second version otherwise. Since Secret is a secret and incomplete 1463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// type, the only expression a user can write that has type Secret* is 1473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// a null pointer literal. Therefore, we know that x is a null 1483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// pointer literal if and only if the first version is picked by the 1493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compiler. 1503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickchar IsNullLiteralHelper(Secret* p); 1513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickchar (&IsNullLiteralHelper(...))[2]; // NOLINT 1523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A compile-time bool constant that is true if and only if x is a 1543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// null pointer literal (i.e. NULL or any 0-valued compile-time 1553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// integral constant). 1563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef GTEST_ELLIPSIS_NEEDS_POD_ 1573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// We lose support for NULL detection where the compiler doesn't like 1583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// passing non-POD classes through ellipsis (...). 1593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_IS_NULL_LITERAL_(x) false 1603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else 1613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_IS_NULL_LITERAL_(x) \ 1623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) 1633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_ELLIPSIS_NEEDS_POD_ 1643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Appends the user-supplied message to the Google-Test-generated message. 1663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ String AppendUserMessage(const String& gtest_msg, 1673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Message& user_msg); 1683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A helper class for creating scoped traces in user programs. 1703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ ScopedTrace { 1713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 1723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The c'tor pushes the given source file location and message onto 1733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // a trace stack maintained by Google Test. 1743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ScopedTrace(const char* file, int line, const Message& message); 1753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The d'tor pops the info pushed by the c'tor. 1773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 1783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Note that the d'tor is not virtual in order to be efficient. 1793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Don't inherit from ScopedTrace! 1803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ~ScopedTrace(); 1813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 1833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace); 1843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its 1853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // c'tor and d'tor. Therefore it doesn't 1863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // need to be used otherwise. 1873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Converts a streamable value to a String. A NULL pointer is 1893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// converted to "(null)". When the input value is a ::string, 1903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ::std::string, ::wstring, or ::std::wstring object, each NUL 1913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// character in it is replaced with "\\0". 1923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Declared here but defined in gtest.h, so that it has access 1933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// to the definition of the Message class, required by the ARM 1943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compiler. 1953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 1963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickString StreamableToString(const T& streamable); 1973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 1983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The Symbian compiler has a bug that prevents it from selecting the 1993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// correct overload of FormatForComparisonFailureMessage (see below) 2003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// unless we pass the first argument by reference. If we do that, 2013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// however, Visual Age C++ 10.1 generates a compiler error. Therefore 2023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// we only apply the work-around for Symbian. 2033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if defined(__SYMBIAN32__) 2043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_CREF_WORKAROUND_ const& 2053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else 2063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# define GTEST_CREF_WORKAROUND_ 2073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif 2083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When this operand is a const char* or char*, if the other operand 2103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// is a ::std::string or ::string, we print this operand as a C string 2113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// rather than a pointer (we do the same for wide strings); otherwise 2123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// we print it as a pointer to be safe. 2133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This internal macro is used to avoid duplicated code. 2153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ 2163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline String FormatForComparisonFailureMessage(\ 2173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ 2183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const operand2_type& /*operand2*/) {\ 2193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return operand1_printer(str);\ 2203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}\ 2213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline String FormatForComparisonFailureMessage(\ 2223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ 2233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const operand2_type& /*operand2*/) {\ 2243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return operand1_printer(str);\ 2253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 2263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) 2283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_STD_WSTRING 2293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted) 2303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_HAS_STD_WSTRING 2313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_STRING 2333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted) 2343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_HAS_GLOBAL_STRING 2353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_GLOBAL_WSTRING 2363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) 2373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_HAS_GLOBAL_WSTRING 2383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#undef GTEST_FORMAT_IMPL_ 2403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The next four overloads handle the case where the operand being 2423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// printed is a char/wchar_t pointer and the other operand is not a 2433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// string/wstring object. In such cases, we just print the operand as 2443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// a pointer to be safe. 2453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \ 2463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick template <typename T> \ 2473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \ 2483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const T&) { \ 2493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return PrintToString(static_cast<const void*>(p)); \ 2503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 2513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_CHAR_PTR_IMPL_(char) 2533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_CHAR_PTR_IMPL_(const char) 2543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t) 2553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t) 2563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#undef GTEST_FORMAT_CHAR_PTR_IMPL_ 2583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Constructs and returns the message for an equality assertion 2603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. 2613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The first four parameters are the expressions used in the assertion 2633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// and their values, as strings. For example, for ASSERT_EQ(foo, bar) 2643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// where foo is 5 and bar is 6, we have: 2653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// expected_expression: "foo" 2673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// actual_expression: "bar" 2683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// expected_value: "5" 2693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// actual_value: "6" 2703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The ignoring_case parameter is true iff the assertion is a 2723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will 2733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// be inserted into the message. 2743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult EqFailure(const char* expected_expression, 2753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* actual_expression, 2763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const String& expected_value, 2773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const String& actual_value, 2783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool ignoring_case); 2793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. 2813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ String GetBoolAssertionFailureMessage( 2823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const AssertionResult& assertion_result, 2833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* expression_text, 2843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* actual_predicate_value, 2853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* expected_predicate_value); 2863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 2873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This template class represents an IEEE floating-point number 2883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// (either single-precision or double-precision, depending on the 2893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// template parameters). 2903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The purpose of this class is to do more sophisticated number 2923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// comparison. (Due to round-off error, etc, it's very unlikely that 2933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// two floating-points will be equal exactly. Hence a naive 2943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// comparison by the == operation often doesn't work.) 2953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Format of IEEE floating-point: 2973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 2983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The most-significant bit being the leftmost, an IEEE 2993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// floating-point looks like 3003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// sign_bit exponent_bits fraction_bits 3023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Here, sign_bit is a single bit that designates the sign of the 3043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// number. 3053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For float, there are 8 exponent bits and 23 fraction bits. 3073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For double, there are 11 exponent bits and 52 fraction bits. 3093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// More details can be found at 3113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. 3123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Template parameter: 3143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 3153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// RawType: the raw floating-point type (either float or double) 3163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename RawType> 3173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass FloatingPoint { 3183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 3193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Defines the unsigned integer type that has the same size as the 3203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // floating point number. 3213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits; 3223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Constants. 3243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // # of bits in a number. 3263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const size_t kBitCount = 8*sizeof(RawType); 3273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // # of fraction bits in a number. 3293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const size_t kFractionBitCount = 3303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick std::numeric_limits<RawType>::digits - 1; 3313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // # of exponent bits in a number. 3333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; 3343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The mask for the sign bit. 3363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1); 3373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The mask for the fraction bits. 3393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const Bits kFractionBitMask = 3403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ~static_cast<Bits>(0) >> (kExponentBitCount + 1); 3413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The mask for the exponent bits. 3433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); 3443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // How many ULP's (Units in the Last Place) we want to tolerate when 3463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // comparing two numbers. The larger the value, the more error we 3473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // allow. A 0 value means that two numbers must be exactly the same 3483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // to be considered equal. 3493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 3503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The maximum error of a single floating-point operation is 0.5 3513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // units in the last place. On Intel CPU's, all floating-point 3523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // calculations are done with 80-bit precision, while double has 64 3533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // bits. Therefore, 4 should be enough for ordinary use. 3543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 3553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // See the following article for more details on ULP: 3563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm. 3573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const size_t kMaxUlps = 4; 3583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Constructs a FloatingPoint from a raw floating-point number. 3603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 3613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // On an Intel CPU, passing a non-normalized NAN (Not a Number) 3623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // around may change its bits, although the new value is guaranteed 3633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // to be also a NAN. Therefore, don't expect this constructor to 3643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // preserve the bits in x when x is a NAN. 3653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick explicit FloatingPoint(const RawType& x) { u_.value_ = x; } 3663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Static methods 3683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Reinterprets a bit pattern as a floating-point number. 3703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 3713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // This function is needed to test the AlmostEquals() method. 3723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static RawType ReinterpretBits(const Bits bits) { 3733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick FloatingPoint fp(0); 3743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fp.u_.bits_ = bits; 3753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return fp.u_.value_; 3763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 3773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns the floating-point number that represent positive infinity. 3793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static RawType Infinity() { 3803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return ReinterpretBits(kExponentBitMask); 3813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 3823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Non-static methods 3843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns the bits that represents this number. 3863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Bits &bits() const { return u_.bits_; } 3873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns the exponent bits of this number. 3893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } 3903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns the fraction bits of this number. 3923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } 3933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns the sign bit of this number. 3953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Bits sign_bit() const { return kSignBitMask & u_.bits_; } 3963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 3973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns true iff this is NAN (not a number). 3983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool is_nan() const { 3993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // It's a NAN if the exponent bits are all ones and the fraction 4003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // bits are not entirely zeros. 4013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0); 4023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 4033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Returns true iff this number is at most kMaxUlps ULP's away from 4053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // rhs. In particular, this function: 4063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 4073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // - returns false if either number is (or both are) NAN. 4083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // - treats really large numbers as almost equal to infinity. 4093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // - thinks +0.0 and -0.0 are 0 DLP's apart. 4103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool AlmostEquals(const FloatingPoint& rhs) const { 4113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The IEEE standard says that any comparison operation involving 4123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // a NAN must return false. 4133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (is_nan() || rhs.is_nan()) return false; 4143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) 4163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick <= kMaxUlps; 4173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 4183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 4203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The data type used to store the actual floating-point number. 4213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick union FloatingPointUnion { 4223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick RawType value_; // The raw floating-point number. 4233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Bits bits_; // The bits that represent the number. 4243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick }; 4253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Converts an integer from the sign-and-magnitude representation to 4273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // the biased representation. More precisely, let N be 2 to the 4283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // power of (kBitCount - 1), an integer x is represented by the 4293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // unsigned number x + N. 4303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 4313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // For instance, 4323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 4333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // -N + 1 (the most negative number representable using 4343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // sign-and-magnitude) is represented by 1; 4353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 0 is represented by N; and 4363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // N - 1 (the biggest number representable using 4373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // sign-and-magnitude) is represented by 2N - 1. 4383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 4393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Read http://en.wikipedia.org/wiki/Signed_number_representations 4403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // for more details on signed number representations. 4413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static Bits SignAndMagnitudeToBiased(const Bits &sam) { 4423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (kSignBitMask & sam) { 4433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // sam represents a negative number. 4443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return ~sam + 1; 4453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else { 4463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // sam represents a positive number. 4473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return kSignBitMask | sam; 4483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 4493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 4503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Given two numbers in the sign-and-magnitude representation, 4523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // returns the distance between them as an unsigned number. 4533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, 4543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Bits &sam2) { 4553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Bits biased1 = SignAndMagnitudeToBiased(sam1); 4563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Bits biased2 = SignAndMagnitudeToBiased(sam2); 4573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); 4583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 4593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick FloatingPointUnion u_; 4613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 4623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Typedefs the instances of the FloatingPoint template class that we 4643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// care to use. 4653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef FloatingPoint<float> Float; 4663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef FloatingPoint<double> Double; 4673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// In order to catch the mistake of putting tests that use different 4693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// test fixture classes in the same test case, we need to assign 4703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// unique IDs to fixture classes and compare them. The TypeId type is 4713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// used to hold such IDs. The user should treat TypeId as an opaque 4723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// type: the only operation allowed on TypeId values is to compare 4733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// them for equality using the == operator. 4743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef const void* TypeId; 4753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 4773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TypeIdHelper { 4783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 4793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // dummy_ must not have a const type. Otherwise an overly eager 4803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // compiler (e.g. MSVC 7.1 & 8.0) may try to merge 4813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // TypeIdHelper<T>::dummy_ for different Ts as an "optimization". 4823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static bool dummy_; 4833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 4843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 4863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickbool TypeIdHelper<T>::dummy_ = false; 4873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 4883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// GetTypeId<T>() returns the ID of type T. Different values will be 4893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// returned for different types. Calling the function twice with the 4903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// same type argument is guaranteed to return the same ID. 4913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 4923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickTypeId GetTypeId() { 4933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The compiler is required to allocate a different 4943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // TypeIdHelper<T>::dummy_ variable for each T used to instantiate 4953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // the template. Therefore, the address of dummy_ is guaranteed to 4963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // be unique. 4973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return &(TypeIdHelper<T>::dummy_); 4983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 4993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Returns the type ID of ::testing::Test. Always call this instead 5013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// of GetTypeId< ::testing::Test>() to get the type ID of 5023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ::testing::Test, as the latter may give the wrong result due to a 5033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// suspected linker bug when compiling Google Test as a Mac OS X 5043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// framework. 5053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ TypeId GetTestTypeId(); 5063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defines the abstract factory interface that creates instances 5083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// of a Test object. 5093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestFactoryBase { 5103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 5113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual ~TestFactoryBase() {} 5123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Creates a test instance to run. The instance is both created and destroyed 5143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // within TestInfoImpl::Run() 5153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual Test* CreateTest() = 0; 5163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick protected: 5183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestFactoryBase() {} 5193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 5213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase); 5223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 5233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This class provides implementation of TeastFactoryBase interface. 5253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// It is used in TEST and TEST_F macros. 5263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <class TestClass> 5273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TestFactoryImpl : public TestFactoryBase { 5283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 5293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual Test* CreateTest() { return new TestClass; } 5303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 5313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_OS_WINDOWS 5333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Predicate-formatters for implementing the HRESULT checking macros 5353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} 5363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// We pass a long instead of HRESULT to avoid causing an 5373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// include dependency for the HRESULT type. 5383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr, 5393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick long hr); // NOLINT 5403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, 5413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick long hr); // NOLINT 5423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_OS_WINDOWS 5443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Types of SetUpTestCase() and TearDownTestCase() functions. 5463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef void (*SetUpTestCaseFunc)(); 5473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef void (*TearDownTestCaseFunc)(); 5483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Creates a new TestInfo object and registers it with Google Test; 5503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// returns the created object. 5513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 5523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Arguments: 5533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 5543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// test_case_name: name of the test case 5553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// name: name of the test 5563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// type_param the name of the test's type parameter, or NULL if 5573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this is not a typed or a type-parameterized test. 5583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// value_param text representation of the test's value parameter, 5593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// or NULL if this is not a type-parameterized test. 5603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// fixture_class_id: ID of the test fixture class 5613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// set_up_tc: pointer to the function that sets up the test case 5623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// tear_down_tc: pointer to the function that tears down the test case 5633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// factory: pointer to the factory that creates a test object. 5643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The newly created TestInfo instance will assume 5653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ownership of the factory object. 5663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ TestInfo* MakeAndRegisterTestInfo( 5673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* test_case_name, const char* name, 5683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* type_param, 5693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* value_param, 5703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TypeId fixture_class_id, 5713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick SetUpTestCaseFunc set_up_tc, 5723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TearDownTestCaseFunc tear_down_tc, 5733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestFactoryBase* factory); 5743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// If *pstr starts with the given prefix, modifies *pstr to be right 5763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// past the prefix and returns true; otherwise leaves *pstr unchanged 5773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// and returns false. None of pstr, *pstr, and prefix can be NULL. 5783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr); 5793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 5813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// State of the definition of a type-parameterized test case. 5833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ TypedTestCasePState { 5843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 5853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TypedTestCasePState() : registered_(false) {} 5863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 5873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Adds the given test name to defined_test_names_ and return true 5883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // if the test case hasn't been registered; otherwise aborts the 5893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // program. 5903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool AddTestName(const char* file, int line, const char* case_name, 5913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* test_name) { 5923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (registered_) { 5933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fprintf(stderr, "%s Test %s must be defined before " 5943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", 5953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick FormatFileLocation(file, line).c_str(), test_name, case_name); 5963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fflush(stderr); 5973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick posix::Abort(); 5983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 5993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick defined_test_names_.insert(test_name); 6003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return true; 6013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 6023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Verifies that registered_tests match the test names in 6043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // defined_test_names_; returns registered_tests if successful, or 6053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // aborts the program otherwise. 6063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* VerifyRegisteredTestNames( 6073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* file, int line, const char* registered_tests); 6083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 6103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool registered_; 6113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::std::set<const char*> defined_test_names_; 6123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 6133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Skips to the first non-space char after the first comma in 'str'; 6153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// returns NULL if no comma is found in 'str'. 6163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline const char* SkipComma(const char* str) { 6173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* comma = strchr(str, ','); 6183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (comma == NULL) { 6193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return NULL; 6203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 6213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick while (IsSpace(*(++comma))) {} 6223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return comma; 6233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 6243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Returns the prefix of 'str' before the first comma in it; returns 6263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the entire string if it contains no comma. 6273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline String GetPrefixUntilComma(const char* str) { 6283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* comma = strchr(str, ','); 6293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return comma == NULL ? String(str) : String(str, comma - str); 6303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 6313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TypeParameterizedTest<Fixture, TestSel, Types>::Register() 6333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// registers a list of type-parameterized tests with Google Test. The 6343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// return value is insignificant - we just need to return something 6353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// such that we can call this function in a namespace scope. 6363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 6373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Implementation note: The GTEST_TEMPLATE_ macro declares a template 6383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// template parameter. It's defined in gtest-type-util.h. 6393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types> 6403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TypeParameterizedTest { 6413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 6423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 'index' is the index of the test in the type list 'Types' 6433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase, 6443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Types). Valid values for 'index' are [0, N - 1] where N is the 6453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // length of Types. 6463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static bool Register(const char* prefix, const char* case_name, 6473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* test_names, int index) { 6483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef typename Types::Head Type; 6493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef Fixture<Type> FixtureClass; 6503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef typename GTEST_BIND_(TestSel, Type) TestClass; 6513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // First, registers the first type-parameterized test in the type 6533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // list. 6543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick MakeAndRegisterTestInfo( 6553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", 6563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick case_name, index).c_str(), 6573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GetPrefixUntilComma(test_names).c_str(), 6583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GetTypeName<Type>().c_str(), 6593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick NULL, // No value parameter. 6603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GetTypeId<FixtureClass>(), 6613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestClass::SetUpTestCase, 6623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TestClass::TearDownTestCase, 6633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick new TestFactoryImpl<TestClass>); 6643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Next, recurses (at compile time) with the tail of the type list. 6663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail> 6673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::Register(prefix, case_name, test_names, index + 1); 6683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 6693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 6703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The base case for the compile time recursion. 6723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <GTEST_TEMPLATE_ Fixture, class TestSel> 6733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TypeParameterizedTest<Fixture, TestSel, Types0> { 6743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 6753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static bool Register(const char* /*prefix*/, const char* /*case_name*/, 6763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* /*test_names*/, int /*index*/) { 6773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return true; 6783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 6793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 6803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// TypeParameterizedTestCase<Fixture, Tests, Types>::Register() 6823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// registers *all combinations* of 'Tests' and 'Types' with Google 6833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Test. The return value is insignificant - we just need to return 6843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// something such that we can call this function in a namespace scope. 6853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types> 6863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TypeParameterizedTestCase { 6873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 6883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static bool Register(const char* prefix, const char* case_name, 6893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* test_names) { 6903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef typename Tests::Head Head; 6913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // First, register the first test in 'Test' for each type in 'Types'. 6933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick TypeParameterizedTest<Fixture, Head, Types>::Register( 6943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick prefix, case_name, test_names, 0); 6953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 6963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Next, recurses (at compile time) with the tail of the test list. 6973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types> 6983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::Register(prefix, case_name, SkipComma(test_names)); 6993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 7003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 7013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The base case for the compile time recursion. 7033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <GTEST_TEMPLATE_ Fixture, typename Types> 7043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass TypeParameterizedTestCase<Fixture, Templates0, Types> { 7053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 7063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static bool Register(const char* /*prefix*/, const char* /*case_name*/, 7073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* /*test_names*/) { 7083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return true; 7093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 7103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 7113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 7133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Returns the current OS stack trace as a String. 7153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 7163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The maximum number of stack frames to be included is specified by 7173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the gtest_stack_trace_depth flag. The skip_count parameter 7183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// specifies the number of top frames to be skipped, which doesn't 7193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// count against the number of frames to be included. 7203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 7213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// For example, if Foo() calls Bar(), which in turn calls 7223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in 7233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. 7243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, 7253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick int skip_count); 7263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Helpers for suppressing warnings on unreachable code or constant 7283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// condition. 7293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Always returns true. 7313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickGTEST_API_ bool AlwaysTrue(); 7323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Always returns false. 7343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline bool AlwaysFalse() { return !AlwaysTrue(); } 7353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Helper for suppressing false warning from Clang on a const char* 7373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// variable declared in a conditional expression always being NULL in 7383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the else branch. 7393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct GTEST_API_ ConstCharPtr { 7403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ConstCharPtr(const char* str) : value(str) {} 7413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick operator bool() const { return true; } 7423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const char* value; 7433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 7443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A simple Linear Congruential Generator for generating random 7463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// numbers with a uniform distribution. Unlike rand() and srand(), it 7473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// doesn't use global state (and therefore can't interfere with user 7483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// code). Unlike rand_r(), it's portable. An LCG isn't very random, 7493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// but it's good enough for our purposes. 7503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_API_ Random { 7513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 7523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const UInt32 kMaxRange = 1u << 31; 7533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick explicit Random(UInt32 seed) : state_(seed) {} 7553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick void Reseed(UInt32 seed) { state_ = seed; } 7573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Generates a random number from [0, range). Crashes if 'range' is 7593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 0 or greater than kMaxRange. 7603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick UInt32 Generate(UInt32 range); 7613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 7633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick UInt32 state_; 7643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); 7653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 7663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a 7683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// compiler error iff T1 and T2 are different types. 7693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T1, typename T2> 7703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct CompileAssertTypesEqual; 7713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 7733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct CompileAssertTypesEqual<T, T> { 7743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 7753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Removes the reference from a type if it is a reference type, 7773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// otherwise leaves it unchanged. This is the same as 7783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// tr1::remove_reference, which is not widely available yet. 7793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 7803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct RemoveReference { typedef T type; }; // NOLINT 7813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 7823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct RemoveReference<T&> { typedef T type; }; // NOLINT 7833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A handy wrapper around RemoveReference that works when the argument 7853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// T depends on template parameters. 7863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_REMOVE_REFERENCE_(T) \ 7873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typename ::testing::internal::RemoveReference<T>::type 7883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Removes const from a type if it is a const type, otherwise leaves 7903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// it unchanged. This is the same as tr1::remove_const, which is not 7913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// widely available yet. 7923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 7933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct RemoveConst { typedef T type; }; // NOLINT 7943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 7953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct RemoveConst<const T> { typedef T type; }; // NOLINT 7963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 7973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above 7983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// definition to fail to remove the const in 'const int[3]' and 'const 7993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// char[3][4]'. The following specialization works around the bug. 8003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// However, it causes trouble with GCC and thus needs to be 8013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// conditionally compiled. 8023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__) 8033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, size_t N> 8043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct RemoveConst<const T[N]> { 8053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef typename RemoveConst<T>::type type[N]; 8063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 8073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif 8083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A handy wrapper around RemoveConst that works when the argument 8103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// T depends on template parameters. 8113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_REMOVE_CONST_(T) \ 8123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typename ::testing::internal::RemoveConst<T>::type 8133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Turns const U&, U&, const U, and U all into U. 8153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ 8163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) 8173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Adds reference to a type if it is not a reference type, 8193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// otherwise leaves it unchanged. This is the same as 8203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// tr1::add_reference, which is not widely available yet. 8213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 8223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct AddReference { typedef T& type; }; // NOLINT 8233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 8243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct AddReference<T&> { typedef T& type; }; // NOLINT 8253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// A handy wrapper around AddReference that works when the argument T 8273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// depends on template parameters. 8283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_ADD_REFERENCE_(T) \ 8293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typename ::testing::internal::AddReference<T>::type 8303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Adds a reference to const on top of T as necessary. For example, 8323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// it transforms 8333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 8343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// char ==> const char& 8353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// const char ==> const char& 8363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// char& ==> const char& 8373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// const char& ==> const char& 8383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 8393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The argument T must depend on some template parameters. 8403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_REFERENCE_TO_CONST_(T) \ 8413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T)) 8423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ImplicitlyConvertible<From, To>::value is a compile-time bool 8443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// constant that's true iff type From can be implicitly converted to 8453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// type To. 8463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename From, typename To> 8473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass ImplicitlyConvertible { 8483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 8493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // We need the following helper functions only for their types. 8503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // They have no implementations. 8513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // MakeFrom() is an expression whose type is From. We cannot simply 8533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // use From(), as the type From may not have a public default 8543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // constructor. 8553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static From MakeFrom(); 8563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // These two functions are overloaded. Given an expression 8583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Helper(x), the compiler will pick the first version if x can be 8593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // implicitly converted to type To; otherwise it will pick the 8603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // second version. 8613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 8623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // The first version returns a value of size 1, and the second 8633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // version returns a value of size 2. Therefore, by checking the 8643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // size of Helper(x), which can be done at compile time, we can tell 8653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // which version of Helper() is used, and hence whether x can be 8663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // implicitly converted to type To. 8673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static char Helper(To); 8683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static char (&Helper(...))[2]; // NOLINT 8693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // We have to put the 'public' section after the 'private' section, 8713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // or MSVC refuses to compile the code. 8723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 8733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // MSVC warns about implicitly converting from double to int for 8743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // possible loss of data, so we need to temporarily disable the 8753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // warning. 8763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#ifdef _MSC_VER 8773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# pragma warning(push) // Saves the current warning state. 8783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# pragma warning(disable:4244) // Temporarily disables warning 4244. 8793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const bool value = 8813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; 8823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick# pragma warning(pop) // Restores the warning state. 8833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#elif defined(__BORLANDC__) 8843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // C++Builder cannot use member overload resolution during template 8853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // instantiation. The simplest workaround is to use its C++0x type traits 8863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // functions (C++Builder 2009 and above only). 8873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const bool value = __is_convertible(From, To); 8883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#else 8893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static const bool value = 8903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; 8913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // _MSV_VER 8923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 8933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename From, typename To> 8943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickconst bool ImplicitlyConvertible<From, To>::value; 8953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 8963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// IsAProtocolMessage<T>::value is a compile-time bool constant that's 8973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// true iff T is type ProtocolMessage, proto2::Message, or a subclass 8983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// of those. 8993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T> 9003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickstruct IsAProtocolMessage 9013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick : public bool_constant< 9023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value || 9033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> { 9043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 9053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// When the compiler sees expression IsContainerTest<C>(0), if C is an 9073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// STL-style container class, the first overload of IsContainerTest 9083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// will be viable (since both C::iterator* and C::const_iterator* are 9093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// valid types and NULL can be implicitly converted to them). It will 9103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// be picked over the second overload as 'int' is a perfect match for 9113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the type of argument 0. If C::iterator or C::const_iterator is not 9123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// a valid type, the first overload is not viable, and the second 9133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// overload will be picked. Therefore, we can determine whether C is 9143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// a container class by checking the type of IsContainerTest<C>(0). 9153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The value of the expression is insignificant. 9163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 9173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Note that we look for both C::iterator and C::const_iterator. The 9183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// reason is that C++ injects the name of a class as a member of the 9193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// class itself (e.g. you can refer to class iterator as either 9203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 'iterator' or 'iterator::iterator'). If we look for C::iterator 9213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// only, for example, we would mistakenly think that a class named 9223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// iterator is an STL container. 9233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 9243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Also note that the simpler approach of overloading 9253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// IsContainerTest(typename C::const_iterator*) and 9263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++. 9273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef int IsContainer; 9283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <class C> 9293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickIsContainer IsContainerTest(int /* dummy */, 9303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typename C::iterator* /* it */ = NULL, 9313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typename C::const_iterator* /* const_it */ = NULL) { 9323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return 0; 9333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 9343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktypedef char IsNotContainer; 9363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <class C> 9373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickIsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } 9383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// EnableIf<condition>::type is void when 'Cond' is true, and 9403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// undefined when 'Cond' is false. To use SFINAE to make a function 9413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// overload only apply when a particular expression is true, add 9423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// "typename EnableIf<expression>::type* = 0" as the last parameter. 9433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate<bool> struct EnableIf; 9443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate<> struct EnableIf<true> { typedef void type; }; // NOLINT 9453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Utilities for native arrays. 9473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// ArrayEq() compares two k-dimensional native arrays using the 9493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// elements' operator==, where k can be any integer >= 0. When k is 9503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// 0, ArrayEq() degenerates into comparing a single pair of values. 9513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 9533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickbool ArrayEq(const T* lhs, size_t size, const U* rhs); 9543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This generic version is used when k is 0. 9563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 9573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } 9583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This overload is used when k >= 1. 9603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U, size_t N> 9613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { 9623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return internal::ArrayEq(lhs, N, rhs); 9633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 9643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This helper reduces code bloat. If we instead put its logic inside 9663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the previous ArrayEq() function, arrays with different sizes would 9673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// lead to different copies of the template code. 9683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 9693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickbool ArrayEq(const T* lhs, size_t size, const U* rhs) { 9703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick for (size_t i = 0; i != size; i++) { 9713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (!internal::ArrayEq(lhs[i], rhs[i])) 9723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return false; 9733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 9743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return true; 9753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 9763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Finds the first element in the iterator range [begin, end) that 9783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// equals elem. Element may be a native array type itself. 9793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename Iter, typename Element> 9803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian RomanickIter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { 9813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick for (Iter it = begin; it != end; ++it) { 9823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (internal::ArrayEq(*it, elem)) 9833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return it; 9843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 9853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return end; 9863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 9873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// CopyArray() copies a k-dimensional native array using the elements' 9893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// operator=, where k can be any integer >= 0. When k is 0, 9903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// CopyArray() degenerates into copying a single value. 9913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 9933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickvoid CopyArray(const T* from, size_t size, U* to); 9943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This generic version is used when k is 0. 9963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 9973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline void CopyArray(const T& from, U* to) { *to = from; } 9983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 9993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This overload is used when k >= 1. 10003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U, size_t N> 10013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickinline void CopyArray(const T(&from)[N], U(*to)[N]) { 10023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick internal::CopyArray(from, N, *to); 10033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 10043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// This helper reduces code bloat. If we instead put its logic inside 10063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// the previous CopyArray() function, arrays with different sizes 10073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// would lead to different copies of the template code. 10083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename T, typename U> 10093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickvoid CopyArray(const T* from, size_t size, U* to) { 10103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick for (size_t i = 0; i != size; i++) { 10113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick internal::CopyArray(from[i], to + i); 10123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} 10143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// The relation between an NativeArray object (see below) and the 10163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// native array it represents. 10173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickenum RelationToSource { 10183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick kReference, // The NativeArray references the native array. 10193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick kCopy // The NativeArray makes a copy of the native array and 10203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // owns the copy. 10213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 10223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Adapts a native array to a read-only STL-style container. Instead 10243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// of the complete STL container concept, this adaptor only implements 10253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// members useful for Google Mock's container matchers. New members 10263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// should be added as needed. To simplify the implementation, we only 10273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// support Element being a raw type (i.e. having no top-level const or 10283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// reference modifier). It's the client's responsibility to satisfy 10293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// this requirement. Element can be an array type itself (hence 10303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// multi-dimensional arrays are supported). 10313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanicktemplate <typename Element> 10323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass NativeArray { 10333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public: 10343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // STL-style container typedefs. 10353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef Element value_type; 10363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef Element* iterator; 10373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick typedef const Element* const_iterator; 10383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Constructs from a native array. 10403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick NativeArray(const Element* array, size_t count, RelationToSource relation) { 10413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Init(array, count, relation); 10423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Copy constructor. 10453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick NativeArray(const NativeArray& rhs) { 10463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Init(rhs.array_, rhs.size_, rhs.relation_to_source_); 10473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ~NativeArray() { 10503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Ensures that the user doesn't instantiate NativeArray with a 10513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // const or reference type. 10523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static_cast<void>(StaticAssertTypeEqHelper<Element, 10533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>()); 10543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (relation_to_source_ == kCopy) 10553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick delete[] array_; 10563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // STL-style container methods. 10593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick size_t size() const { return size_; } 10603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const_iterator begin() const { return array_; } 10613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const_iterator end() const { return array_ + size_; } 10623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool operator==(const NativeArray& rhs) const { 10633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return size() == rhs.size() && 10643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ArrayEq(begin(), size(), rhs.begin()); 10653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private: 10683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // Initializes this object; makes a copy of the input array if 10693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick // 'relation' is kCopy. 10703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick void Init(const Element* array, size_t a_size, RelationToSource relation) { 10713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (relation == kReference) { 10723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick array_ = array; 10733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else { 10743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick Element* const copy = new Element[a_size]; 10753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick CopyArray(array, a_size, copy); 10763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick array_ = copy; 10773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick size_ = a_size; 10793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick relation_to_source_ = relation; 10803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } 10813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick const Element* array_; 10833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick size_t size_; 10843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick RelationToSource relation_to_source_; 10853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_ASSIGN_(NativeArray); 10873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick}; 10883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} // namespace internal 10903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick} // namespace testing 10913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ 10933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::AssertHelper(result_type, file, line, message) \ 10943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick = ::testing::Message() 10953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_MESSAGE_(message, result_type) \ 10973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) 10983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 10993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_FATAL_FAILURE_(message) \ 11003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) 11013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_NONFATAL_FAILURE_(message) \ 11033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) 11043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_SUCCESS_(message) \ 11063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) 11073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Suppresses MSVC warnings 4072 (unreachable code) for the code following 11093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// statement if it returns or throws (or doesn't return or throw in some 11103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// situations). 11113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ 11123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { statement; } 11133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ 11153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 11163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::ConstCharPtr gtest_msg = "") { \ 11173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool gtest_caught_expected = false; \ 11183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick try { \ 11193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 11203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick catch (expected_exception const&) { \ 11223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick gtest_caught_expected = true; \ 11233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick catch (...) { \ 11253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick gtest_msg.value = \ 11263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick "Expected: " #statement " throws an exception of type " \ 11273d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick #expected_exception ".\n Actual: it throws a different type."; \ 11283d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ 11293d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11303d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (!gtest_caught_expected) { \ 11313d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick gtest_msg.value = \ 11323d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick "Expected: " #statement " throws an exception of type " \ 11333d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick #expected_exception ".\n Actual: it throws nothing."; \ 11343d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ 11353d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11363d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else \ 11373d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ 11383d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fail(gtest_msg.value) 11393d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11403d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_NO_THROW_(statement, fail) \ 11413d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 11423d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { \ 11433d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick try { \ 11443d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 11453d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11463d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick catch (...) { \ 11473d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ 11483d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11493d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else \ 11503d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ 11513d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fail("Expected: " #statement " doesn't throw an exception.\n" \ 11523d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick " Actual: it throws.") 11533d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11543d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_ANY_THROW_(statement, fail) \ 11553d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 11563d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { \ 11573d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick bool gtest_caught_any = false; \ 11583d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick try { \ 11593d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 11603d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11613d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick catch (...) { \ 11623d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick gtest_caught_any = true; \ 11633d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11643d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (!gtest_caught_any) { \ 11653d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ 11663d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11673d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else \ 11683d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ 11693d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fail("Expected: " #statement " throws an exception.\n" \ 11703d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick " Actual: it doesn't.") 11713d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11723d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11733d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Implements Boolean test assertions such as EXPECT_TRUE. expression can be 11743d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// either a boolean expression or an AssertionResult. text is a textual 11753d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// represenation of expression as it was passed into the EXPECT_TRUE. 11763d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ 11773d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 11783d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (const ::testing::AssertionResult gtest_ar_ = \ 11793d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::AssertionResult(expression)) \ 11803d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ; \ 11813d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick else \ 11823d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fail(::testing::internal::GetBoolAssertionFailureMessage(\ 11833d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick gtest_ar_, text, #actual, #expected).c_str()) 11843d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11853d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ 11863d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 11873d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (::testing::internal::AlwaysTrue()) { \ 11883d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ 11893d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 11903d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ 11913d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ 11923d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } \ 11933d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick } else \ 11943d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ 11953d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick fail("Expected: " #statement " doesn't generate new fatal " \ 11963d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick "failures in the current thread.\n" \ 11973d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick " Actual: it does.") 11983d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 11993d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Expands to the name of the class that implements the given test. 12003d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ 12013d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick test_case_name##_##test_name##_Test 12023d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 12033d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick// Helper macro for defining tests. 12043d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ 12053d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickclass GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ 12063d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick public:\ 12073d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ 12083d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick private:\ 12093d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick virtual void TestBody();\ 12103d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ 12113d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_DISALLOW_COPY_AND_ASSIGN_(\ 12123d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ 12133d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick};\ 12143d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick\ 12153d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ 12163d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::test_info_ =\ 12173d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick ::testing::internal::MakeAndRegisterTestInfo(\ 12183d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick #test_case_name, #test_name, NULL, NULL, \ 12193d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick (parent_id), \ 12203d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick parent_class::SetUpTestCase, \ 12213d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick parent_class::TearDownTestCase, \ 12223d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick new ::testing::internal::TestFactoryImpl<\ 12233d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ 12243d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanickvoid GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() 12253d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick 12263d000e7dd14c3185b9e27a6c38a67288b4d10431Ian Romanick#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ 1227