⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtest-internal.h

📁 Search s framework 老外写的
💻 H
📖 第 1 页 / 共 3 页
字号:
// Copyright 2005, Google Inc.// All rights reserved.//// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met:////     * Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.//     * Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following disclaimer// in the documentation and/or other materials provided with the// distribution.//     * Neither the name of Google Inc. nor the names of its// contributors may be used to endorse or promote products derived from// this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.//// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)//// The Google C++ Testing Framework (Google Test)//// This header file declares functions and macros used internally by// Google Test.  They are subject to change without notice.#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_#include <gtest/internal/gtest-port.h>#ifdef GTEST_OS_LINUX#include <stdlib.h>#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#endif  // GTEST_OS_LINUX#include <ctype.h>#include <string.h>#include <iomanip>#include <limits>#include <set>#include <gtest/internal/gtest-string.h>#include <gtest/internal/gtest-filepath.h>#include <gtest/internal/gtest-type-util.h>// Due to C++ preprocessor weirdness, we need double indirection to// concatenate two tokens when one of them is __LINE__.  Writing////   foo ## __LINE__//// will result in the token foo__LINE__, instead of foo followed by// the current line number.  For more details, see// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar// Google Test defines the testing::Message class to allow construction of// test messages via the << operator.  The idea is that anything// streamable to std::ostream can be streamed to a testing::Message.// This allows a user to use his own types in Google Test assertions by// overloading the << operator.//// util/gtl/stl_logging-inl.h overloads << for STL containers.  These// overloads cannot be defined in the std namespace, as that will be// undefined behavior.  Therefore, they are defined in the global// namespace instead.//// C++'s symbol lookup rule (i.e. Koenig lookup) says that these// overloads are visible in either the std namespace or the global// namespace, but not other namespaces, including the testing// namespace which Google Test's Message class is in.//// To allow STL containers (and other types that has a << operator// defined in the global namespace) to be used in Google Test assertions,// testing::Message must access the custom << operator from the global// namespace.  Hence this helper function.//// Note: Jeffrey Yasskin suggested an alternative fix by "using// ::operator<<;" in the definition of Message's operator<<.  That fix// doesn't require a helper function, but unfortunately doesn't// compile with MSVC.template <typename T>inline void GTestStreamToHelper(std::ostream* os, const T& val) {  *os << val;}namespace testing {// Forward declaration of classes.class Message;                         // Represents a failure message.class Test;                            // Represents a test.class TestCase;                        // A collection of related tests.class TestPartResult;                  // Result of a test part.class TestInfo;                        // Information about a test.class UnitTest;                        // A collection of test cases.class UnitTestEventListenerInterface;  // Listens to Google Test events.class AssertionResult;                 // Result of an assertion.namespace internal {struct TraceInfo;                      // Information about a trace point.class ScopedTrace;                     // Implements scoped trace.class TestInfoImpl;                    // Opaque implementation of TestInfoclass TestResult;                      // Result of a single Test.class UnitTestImpl;                    // Opaque implementation of UnitTesttemplate <typename E> class List;      // A generic list.template <typename E> class ListNode;  // A node in a generic list.// How many times InitGoogleTest() has been called.extern int g_init_gtest_count;// The text used in failure messages to indicate the start of the// stack trace.extern const char kStackTraceMarker[];// A secret type that Google Test users don't know about.  It has no// definition on purpose.  Therefore it's impossible to create a// Secret object, which is what we want.class Secret;// Two overloaded helpers for checking at compile time whether an// expression is a null pointer literal (i.e. NULL or any 0-valued// compile-time integral constant).  Their return values have// different sizes, so we can use sizeof() to test which version is// picked by the compiler.  These helpers have no implementations, as// we only need their signatures.//// Given IsNullLiteralHelper(x), the compiler will pick the first// version if x can be implicitly converted to Secret*, and pick the// second version otherwise.  Since Secret is a secret and incomplete// type, the only expression a user can write that has type Secret* is// a null pointer literal.  Therefore, we know that x is a null// pointer literal if and only if the first version is picked by the// compiler.char IsNullLiteralHelper(Secret* p);char (&IsNullLiteralHelper(...))[2];  // NOLINT// A compile-time bool constant that is true if and only if x is a// null pointer literal (i.e. NULL or any 0-valued compile-time// integral constant).#ifdef GTEST_ELLIPSIS_NEEDS_COPY_// Passing non-POD classes through ellipsis (...) crashes the ARM// compiler.  The Nokia Symbian and the IBM XL C/C++ compiler try to// instantiate a copy constructor for objects passed through ellipsis// (...), failing for uncopyable objects.  Hence we define this to// false (and lose support for NULL detection).#define GTEST_IS_NULL_LITERAL_(x) false#else#define GTEST_IS_NULL_LITERAL_(x) \    (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)#endif  // GTEST_ELLIPSIS_NEEDS_COPY_// Appends the user-supplied message to the Google-Test-generated message.String AppendUserMessage(const String& gtest_msg,                         const Message& user_msg);// A helper class for creating scoped traces in user programs.class ScopedTrace { public:  // The c'tor pushes the given source file location and message onto  // a trace stack maintained by Google Test.  ScopedTrace(const char* file, int line, const Message& message);  // The d'tor pops the info pushed by the c'tor.  //  // Note that the d'tor is not virtual in order to be efficient.  // Don't inherit from ScopedTrace!  ~ScopedTrace(); private:  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);} GTEST_ATTRIBUTE_UNUSED_;  // A ScopedTrace object does its job in its                            // c'tor and d'tor.  Therefore it doesn't                            // need to be used otherwise.// Converts a streamable value to a String.  A NULL pointer is// converted to "(null)".  When the input value is a ::string,// ::std::string, ::wstring, or ::std::wstring object, each NUL// character in it is replaced with "\\0".// Declared here but defined in gtest.h, so that it has access// to the definition of the Message class, required by the ARM// compiler.template <typename T>String StreamableToString(const T& streamable);// Formats a value to be used in a failure message.#ifdef GTEST_NEEDS_IS_POINTER_// These are needed as the Nokia Symbian and IBM XL C/C++ compilers// cannot decide between const T& and const T* in a function template.// These compilers _can_ decide between class template specializations// for T and T*, so a tr1::type_traits-like is_pointer works, and we// can overload on that.// This overload makes sure that all pointers (including// those to char or wchar_t) are printed as raw pointers.template <typename T>inline String FormatValueForFailureMessage(internal::true_type dummy,                                           T* pointer) {  return StreamableToString(static_cast<const void*>(pointer));}template <typename T>inline String FormatValueForFailureMessage(internal::false_type dummy,                                           const T& value) {  return StreamableToString(value);}template <typename T>inline String FormatForFailureMessage(const T& value) {  return FormatValueForFailureMessage(      typename internal::is_pointer<T>::type(), value);}#else// These are needed as the above solution using is_pointer has the// limitation that T cannot be a type without external linkage, when// compiled using MSVC.template <typename T>inline String FormatForFailureMessage(const T& value) {  return StreamableToString(value);}// This overload makes sure that all pointers (including// those to char or wchar_t) are printed as raw pointers.template <typename T>inline String FormatForFailureMessage(T* pointer) {  return StreamableToString(static_cast<const void*>(pointer));}#endif  // GTEST_NEEDS_IS_POINTER_// These overloaded versions handle narrow and wide characters.String FormatForFailureMessage(char ch);String FormatForFailureMessage(wchar_t wchar);// When this operand is a const char* or char*, and the other operand// is a ::std::string or ::string, we print this operand as a C string// rather than a pointer.  We do the same for wide strings.// This internal macro is used to avoid duplicated code.#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\inline String FormatForComparisonFailureMessage(\    operand2_type::value_type* str, const operand2_type& /*operand2*/) {\  return operand1_printer(str);\}\inline String FormatForComparisonFailureMessage(\    const operand2_type::value_type* str, const operand2_type& /*operand2*/) {\  return operand1_printer(str);\}#if GTEST_HAS_STD_STRINGGTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)#endif  // GTEST_HAS_STD_STRING#if GTEST_HAS_STD_WSTRINGGTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted)#endif  // GTEST_HAS_STD_WSTRING#if GTEST_HAS_GLOBAL_STRINGGTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted)#endif  // GTEST_HAS_GLOBAL_STRING#if GTEST_HAS_GLOBAL_WSTRINGGTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)#endif  // GTEST_HAS_GLOBAL_WSTRING#undef GTEST_FORMAT_IMPL_// Constructs and returns the message for an equality assertion// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.//// The first four parameters are the expressions used in the assertion// and their values, as strings.  For example, for ASSERT_EQ(foo, bar)// where foo is 5 and bar is 6, we have:////   expected_expression: "foo"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -