forked from OSchip/llvm-project
[gtest] Upgrade googletest to version 1.8.0, minimizing local changes.
This required re-working the streaming support and lit's support for '--gtest_list_tests' but otherwise seems to be a clean upgrade. Differential Revision: https://reviews.llvm.org/D28154 llvm-svn: 291029
This commit is contained in:
parent
dbf7ca9ce6
commit
a977582dea
|
@ -314,6 +314,8 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
||||||
|
check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments"
|
||||||
|
SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
|
||||||
|
|
||||||
set(USE_NO_MAYBE_UNINITIALIZED 0)
|
set(USE_NO_MAYBE_UNINITIALIZED 0)
|
||||||
set(USE_NO_UNINITIALIZED 0)
|
set(USE_NO_UNINITIALIZED 0)
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
add_custom_target(UnitTests)
|
add_custom_target(UnitTests)
|
||||||
set_target_properties(UnitTests PROPERTIES FOLDER "Tests")
|
set_target_properties(UnitTests PROPERTIES FOLDER "Tests")
|
||||||
|
|
||||||
|
# Some parts of gtest rely on this GNU extension, don't warn on it.
|
||||||
|
if(SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
|
||||||
|
add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
|
||||||
|
endif()
|
||||||
|
|
||||||
function(add_llvm_unittest test_dirname)
|
function(add_llvm_unittest test_dirname)
|
||||||
add_unittest(UnitTests ${test_dirname} ${ARGN})
|
add_unittest(UnitTests ${test_dirname} ${ARGN})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
|
@ -43,7 +43,13 @@ class GoogleTest(TestFormat):
|
||||||
|
|
||||||
nested_tests = []
|
nested_tests = []
|
||||||
for ln in lines:
|
for ln in lines:
|
||||||
if not ln.strip():
|
# The test name list includes trailing comments beginning with
|
||||||
|
# a '#' on some lines, so skip those. We don't support test names
|
||||||
|
# that use escaping to embed '#' into their name as the names come
|
||||||
|
# from C++ class and method names where such things are hard and
|
||||||
|
# uninteresting to support.
|
||||||
|
ln = ln.split('#', 1)[0].rstrip()
|
||||||
|
if not ln.lstrip():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 'Running main() from gtest_main.cc' in ln:
|
if 'Running main() from gtest_main.cc' in ln:
|
||||||
|
|
|
@ -24,6 +24,12 @@ endif()
|
||||||
if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
||||||
add_definitions("-Wno-variadic-macros")
|
add_definitions("-Wno-variadic-macros")
|
||||||
endif()
|
endif()
|
||||||
|
if(SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
|
||||||
|
add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
|
||||||
|
endif()
|
||||||
|
if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
|
||||||
|
add_definitions("-Wno-covered-switch-default")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(LLVM_REQUIRES_RTTI 1)
|
set(LLVM_REQUIRES_RTTI 1)
|
||||||
add_definitions( -DGTEST_HAS_RTTI=0 )
|
add_definitions( -DGTEST_HAS_RTTI=0 )
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
LLVM notes
|
LLVM notes
|
||||||
----------
|
----------
|
||||||
|
|
||||||
This directory contains Google Test 1.6.0, with all elements removed except for
|
This directory contains Google Test 1.8.0, with all elements removed except for
|
||||||
the actual source code, to minimize the addition to the LLVM distribution.
|
the actual source code, to minimize the addition to the LLVM distribution.
|
||||||
|
|
||||||
Cleaned up as follows:
|
Cleaned up as follows:
|
||||||
|
|
||||||
# Remove all the unnecessary files and directories
|
# Remove all the unnecessary files and directories
|
||||||
$ rm -f aclocal* CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README
|
$ rm -f CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README README.md .gitignore
|
||||||
$ rm -rf build-aux cmake codegear fused-src m4 make msvc samples scripts test xcode
|
$ rm -rf build-aux cmake codegear m4 make msvc samples scripts test xcode docs
|
||||||
$ rm -f `find . -name \*\.pump`
|
$ rm -f `find . -name \*\.pump`
|
||||||
$ rm -f src/gtest_main.cc
|
$ rm -f src/gtest_main.cc
|
||||||
|
|
||||||
# Put the license in the consistent place for LLVM.
|
# Put the license in the consistent place for LLVM.
|
||||||
$ mv COPYING LICENSE.TXT
|
$ mv LICENSE LICENSE.TXT
|
||||||
|
|
||||||
Modified as follows:
|
Modified as follows:
|
||||||
* Added support for FreeBSD.
|
* Added support for Minix and Haiku.
|
||||||
* Added support for Minix (PR6797).
|
* Added raw_os_ostream support to include/gtest/internal/custom/gtest-printers.h.
|
||||||
* To GTestStreamToHelper in include/gtest/internal/gtest-internal.h,
|
|
||||||
added the ability to stream with raw_os_ostream.
|
|
||||||
* To refresh Haiku support in include/gtest/internal/gtest-port.h,
|
|
||||||
see http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20100621/102898.html
|
|
||||||
|
|
|
@ -51,6 +51,17 @@ GTEST_DECLARE_string_(death_test_style);
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
// Returns a Boolean value indicating whether the caller is currently
|
||||||
|
// executing in the context of the death test child process. Tools such as
|
||||||
|
// Valgrind heap checkers may need this to modify their behavior in death
|
||||||
|
// tests. IMPORTANT: This is an internal utility. Using it may break the
|
||||||
|
// implementation of death tests. User code MUST NOT use it.
|
||||||
|
GTEST_API_ bool InDeathTestChild();
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// The following macros are useful for writing death tests.
|
// The following macros are useful for writing death tests.
|
||||||
|
|
||||||
// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
|
// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
|
||||||
|
@ -75,7 +86,7 @@ GTEST_DECLARE_string_(death_test_style);
|
||||||
// for (int i = 0; i < 5; i++) {
|
// for (int i = 0; i < 5; i++) {
|
||||||
// EXPECT_DEATH(server.ProcessRequest(i),
|
// EXPECT_DEATH(server.ProcessRequest(i),
|
||||||
// "Invalid request .* in ProcessRequest()")
|
// "Invalid request .* in ProcessRequest()")
|
||||||
// << "Failed to die on request " << i);
|
// << "Failed to die on request " << i;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
|
// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
|
||||||
|
@ -245,10 +256,10 @@ class GTEST_API_ KilledBySignal {
|
||||||
# ifdef NDEBUG
|
# ifdef NDEBUG
|
||||||
|
|
||||||
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||||
do { statement; } while (::testing::internal::AlwaysFalse())
|
GTEST_EXECUTE_STATEMENT_(statement, regex)
|
||||||
|
|
||||||
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||||
do { statement; } while (::testing::internal::AlwaysFalse())
|
GTEST_EXECUTE_STATEMENT_(statement, regex)
|
||||||
|
|
||||||
# else
|
# else
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,41 @@
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "gtest/internal/gtest-string.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
#include "gtest/internal/gtest-internal.h"
|
|
||||||
|
#if !GTEST_NO_LLVM_RAW_OSTREAM
|
||||||
|
#include "llvm/Support/raw_os_ostream.h"
|
||||||
|
|
||||||
|
// LLVM INTERNAL CHANGE: To allow operator<< to work with both
|
||||||
|
// std::ostreams and LLVM's raw_ostreams, we define a special
|
||||||
|
// std::ostream with an implicit conversion to raw_ostream& and stream
|
||||||
|
// to that. This causes the compiler to prefer std::ostream overloads
|
||||||
|
// but still find raw_ostream& overloads.
|
||||||
|
namespace llvm {
|
||||||
|
class convertible_fwd_ostream : public std::ostream {
|
||||||
|
raw_os_ostream ros_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
convertible_fwd_ostream(std::ostream& os)
|
||||||
|
: std::ostream(os.rdbuf()), ros_(*this) {}
|
||||||
|
operator raw_ostream&() { return ros_; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
inline void GTestStreamToHelper(std::ostream& os, const T& val) {
|
||||||
|
llvm::convertible_fwd_ostream cos(os);
|
||||||
|
cos << val;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template <typename T>
|
||||||
|
inline void GTestStreamToHelper(std::ostream& os, const T& val) {
|
||||||
|
os << val;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Ensures that there is at least one operator<< in the global namespace.
|
||||||
|
// See Message& operator<<(...) below for why.
|
||||||
|
void operator<<(const testing::internal::Secret&, int);
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
|
@ -87,15 +120,7 @@ class GTEST_API_ Message {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructs an empty Message.
|
// Constructs an empty Message.
|
||||||
// We allocate the stringstream separately because otherwise each use of
|
Message();
|
||||||
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
|
|
||||||
// stack frame leading to huge stack frames in some cases; gcc does not reuse
|
|
||||||
// the stack space.
|
|
||||||
Message() : ss_(new ::std::stringstream) {
|
|
||||||
// By default, we want there to be enough precision when printing
|
|
||||||
// a double to a Message.
|
|
||||||
*ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy constructor.
|
// Copy constructor.
|
||||||
Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
|
Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
|
||||||
|
@ -118,7 +143,26 @@ class GTEST_API_ Message {
|
||||||
// Streams a non-pointer value to this object.
|
// Streams a non-pointer value to this object.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline Message& operator <<(const T& val) {
|
inline Message& operator <<(const T& val) {
|
||||||
::GTestStreamToHelper(ss_.get(), val);
|
// Some libraries overload << for STL containers. These
|
||||||
|
// overloads are defined in the global namespace instead of ::std.
|
||||||
|
//
|
||||||
|
// 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. With this using declaration,
|
||||||
|
// overloads of << defined in the global namespace and those
|
||||||
|
// visible via Koenig lookup are both exposed in this function.
|
||||||
|
#if GTEST_NO_LLVM_RAW_OSTREAM
|
||||||
|
using ::operator <<;
|
||||||
|
*ss_ << val;
|
||||||
|
#else
|
||||||
|
::GTestStreamToHelper(*ss_, val);
|
||||||
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +184,11 @@ class GTEST_API_ Message {
|
||||||
if (pointer == NULL) {
|
if (pointer == NULL) {
|
||||||
*ss_ << "(null)";
|
*ss_ << "(null)";
|
||||||
} else {
|
} else {
|
||||||
::GTestStreamToHelper(ss_.get(), pointer);
|
#if GTEST_NO_LLVM_RAW_OSTREAM
|
||||||
|
*ss_ << pointer;
|
||||||
|
#else
|
||||||
|
::GTestStreamToHelper(*ss_, pointer);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -164,12 +212,8 @@ class GTEST_API_ Message {
|
||||||
|
|
||||||
// These two overloads allow streaming a wide C string to a Message
|
// These two overloads allow streaming a wide C string to a Message
|
||||||
// using the UTF-8 encoding.
|
// using the UTF-8 encoding.
|
||||||
Message& operator <<(const wchar_t* wide_c_str) {
|
Message& operator <<(const wchar_t* wide_c_str);
|
||||||
return *this << internal::String::ShowWideCString(wide_c_str);
|
Message& operator <<(wchar_t* wide_c_str);
|
||||||
}
|
|
||||||
Message& operator <<(wchar_t* wide_c_str) {
|
|
||||||
return *this << internal::String::ShowWideCString(wide_c_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GTEST_HAS_STD_WSTRING
|
#if GTEST_HAS_STD_WSTRING
|
||||||
// Converts the given wide string to a narrow string using the UTF-8
|
// Converts the given wide string to a narrow string using the UTF-8
|
||||||
|
@ -183,13 +227,11 @@ class GTEST_API_ Message {
|
||||||
Message& operator <<(const ::wstring& wstr);
|
Message& operator <<(const ::wstring& wstr);
|
||||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
#endif // GTEST_HAS_GLOBAL_WSTRING
|
||||||
|
|
||||||
// Gets the text streamed to this object so far as a String.
|
// Gets the text streamed to this object so far as an std::string.
|
||||||
// Each '\0' character in the buffer is replaced with "\\0".
|
// Each '\0' character in the buffer is replaced with "\\0".
|
||||||
//
|
//
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||||
internal::String GetString() const {
|
std::string GetString() const;
|
||||||
return internal::StringStreamToString(ss_.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -199,16 +241,20 @@ class GTEST_API_ Message {
|
||||||
// decide between class template specializations for T and T*, so a
|
// decide between class template specializations for T and T*, so a
|
||||||
// tr1::type_traits-like is_pointer works, and we can overload on that.
|
// tr1::type_traits-like is_pointer works, and we can overload on that.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {
|
inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
|
||||||
if (pointer == NULL) {
|
if (pointer == NULL) {
|
||||||
*ss_ << "(null)";
|
*ss_ << "(null)";
|
||||||
} else {
|
} else {
|
||||||
::GTestStreamToHelper(ss_.get(), pointer);
|
*ss_ << pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {
|
inline void StreamHelper(internal::false_type /*is_pointer*/,
|
||||||
::GTestStreamToHelper(ss_.get(), value);
|
const T& value) {
|
||||||
|
// See the comments in Message& operator <<(const T&) above for why
|
||||||
|
// we need this using statement.
|
||||||
|
using ::operator <<;
|
||||||
|
*ss_ << value;
|
||||||
}
|
}
|
||||||
#endif // GTEST_OS_SYMBIAN
|
#endif // GTEST_OS_SYMBIAN
|
||||||
|
|
||||||
|
@ -225,6 +271,18 @@ inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
|
||||||
return os << sb.GetString();
|
return os << sb.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
// Converts a streamable value to an std::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".
|
||||||
|
template <typename T>
|
||||||
|
std::string StreamableToString(const T& streamable) {
|
||||||
|
return (Message() << streamable).GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||||
|
|
|
@ -190,6 +190,7 @@ TEST_P(DerivedTest, DoesBlah) {
|
||||||
// inside #if GTEST_HAS_PARAM_TEST.
|
// inside #if GTEST_HAS_PARAM_TEST.
|
||||||
#include "gtest/internal/gtest-internal.h"
|
#include "gtest/internal/gtest-internal.h"
|
||||||
#include "gtest/internal/gtest-param-util.h"
|
#include "gtest/internal/gtest-param-util.h"
|
||||||
|
#include "gtest/internal/gtest-param-util-generated.h"
|
||||||
|
|
||||||
#if GTEST_HAS_PARAM_TEST
|
#if GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
|
@ -324,12 +325,6 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||||
return ValuesIn(container.begin(), container.end());
|
return ValuesIn(container.begin(), container.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace testing
|
|
||||||
|
|
||||||
#include <gtest/internal/gtest-param-util-generated.h>
|
|
||||||
|
|
||||||
namespace testing {
|
|
||||||
|
|
||||||
// Values() allows generating tests from explicitly specified list of
|
// Values() allows generating tests from explicitly specified list of
|
||||||
// parameters.
|
// parameters.
|
||||||
//
|
//
|
||||||
|
@ -1262,7 +1257,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||||
// Boolean flags:
|
// Boolean flags:
|
||||||
//
|
//
|
||||||
// class FlagDependentTest
|
// class FlagDependentTest
|
||||||
// : public testing::TestWithParam<tuple(bool, bool)> > {
|
// : public testing::TestWithParam<tuple<bool, bool> > {
|
||||||
// virtual void SetUp() {
|
// virtual void SetUp() {
|
||||||
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
|
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
|
||||||
// tie(external_flag_1, external_flag_2) = GetParam();
|
// tie(external_flag_1, external_flag_2) = GetParam();
|
||||||
|
@ -1392,14 +1387,17 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||||
static int AddToRegistry() { \
|
static int AddToRegistry() { \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
GetTestCasePatternHolder<test_case_name>(\
|
||||||
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
|
#test_case_name, \
|
||||||
#test_case_name, \
|
::testing::internal::CodeLocation(\
|
||||||
#test_name, \
|
__FILE__, __LINE__))->AddTestPattern(\
|
||||||
new ::testing::internal::TestMetaFactory< \
|
#test_case_name, \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
|
#test_name, \
|
||||||
|
new ::testing::internal::TestMetaFactory< \
|
||||||
|
GTEST_TEST_CLASS_NAME_(\
|
||||||
|
test_case_name, test_name)>()); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
static int gtest_registering_dummy_; \
|
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
||||||
}; \
|
}; \
|
||||||
|
@ -1408,16 +1406,36 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||||
|
|
||||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
|
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
||||||
|
// to specify a function or functor that generates custom test name suffixes
|
||||||
|
// based on the test parameters. The function should accept one argument of
|
||||||
|
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||||
|
//
|
||||||
|
// testing::PrintToStringParamName is a builtin test suffix generator that
|
||||||
|
// returns the value of testing::PrintToString(GetParam()). It does not work
|
||||||
|
// for std::string or C strings.
|
||||||
|
//
|
||||||
|
// Note: test names must be non-empty, unique, and may only contain ASCII
|
||||||
|
// alphanumeric characters or underscore.
|
||||||
|
|
||||||
|
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
||||||
::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||||
int gtest_##prefix##test_case_name##_dummy_ = \
|
::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
||||||
|
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
||||||
|
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
||||||
|
(__VA_ARGS__)(info); \
|
||||||
|
} \
|
||||||
|
int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
GetTestCasePatternHolder<test_case_name>(\
|
||||||
#test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
|
#test_case_name, \
|
||||||
#prefix, \
|
::testing::internal::CodeLocation(\
|
||||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
||||||
__FILE__, __LINE__)
|
#prefix, \
|
||||||
|
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||||
|
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
||||||
|
__FILE__, __LINE__)
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,10 @@
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
#include "gtest/internal/gtest-internal.h"
|
#include "gtest/internal/gtest-internal.h"
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_TUPLE_
|
||||||
|
# include <tuple>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
// Definitions in the 'internal' and 'internal2' name spaces are
|
// Definitions in the 'internal' and 'internal2' name spaces are
|
||||||
|
@ -250,6 +254,103 @@ void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
|
||||||
|
// value of type ToPrint that is an operand of a comparison assertion
|
||||||
|
// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
|
||||||
|
// the comparison, and is used to help determine the best way to
|
||||||
|
// format the value. In particular, when the value is a C string
|
||||||
|
// (char pointer) and the other operand is an STL string object, we
|
||||||
|
// want to format the C string as a string, since we know it is
|
||||||
|
// compared by value with the string object. If the value is a char
|
||||||
|
// pointer but the other operand is not an STL string object, we don't
|
||||||
|
// know whether the pointer is supposed to point to a NUL-terminated
|
||||||
|
// string, and thus want to print it as a pointer to be safe.
|
||||||
|
//
|
||||||
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||||
|
|
||||||
|
// The default case.
|
||||||
|
template <typename ToPrint, typename OtherOperand>
|
||||||
|
class FormatForComparison {
|
||||||
|
public:
|
||||||
|
static ::std::string Format(const ToPrint& value) {
|
||||||
|
return ::testing::PrintToString(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Array.
|
||||||
|
template <typename ToPrint, size_t N, typename OtherOperand>
|
||||||
|
class FormatForComparison<ToPrint[N], OtherOperand> {
|
||||||
|
public:
|
||||||
|
static ::std::string Format(const ToPrint* value) {
|
||||||
|
return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// By default, print C string as pointers to be safe, as we don't know
|
||||||
|
// whether they actually point to a NUL-terminated string.
|
||||||
|
|
||||||
|
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
|
||||||
|
template <typename OtherOperand> \
|
||||||
|
class FormatForComparison<CharType*, OtherOperand> { \
|
||||||
|
public: \
|
||||||
|
static ::std::string Format(CharType* value) { \
|
||||||
|
return ::testing::PrintToString(static_cast<const void*>(value)); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
|
||||||
|
|
||||||
|
#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
|
||||||
|
|
||||||
|
// If a C string is compared with an STL string object, we know it's meant
|
||||||
|
// to point to a NUL-terminated string, and thus can print it as a string.
|
||||||
|
|
||||||
|
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
|
||||||
|
template <> \
|
||||||
|
class FormatForComparison<CharType*, OtherStringType> { \
|
||||||
|
public: \
|
||||||
|
static ::std::string Format(CharType* value) { \
|
||||||
|
return ::testing::PrintToString(value); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_WSTRING
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_WSTRING
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
|
||||||
|
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
|
||||||
|
|
||||||
|
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
|
||||||
|
// operand to be used in a failure message. The type (but not value)
|
||||||
|
// of the other operand may affect the format. This allows us to
|
||||||
|
// print a char* as a raw pointer when it is compared against another
|
||||||
|
// char* or void*, and print it as a C string when it is compared
|
||||||
|
// against an std::string object, for example.
|
||||||
|
//
|
||||||
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::string FormatForComparisonFailureMessage(
|
||||||
|
const T1& value, const T2& /* other_operand */) {
|
||||||
|
return FormatForComparison<T1, T2>::Format(value);
|
||||||
|
}
|
||||||
|
|
||||||
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
|
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
|
||||||
// value to the given ostream. The caller must ensure that
|
// value to the given ostream. The caller must ensure that
|
||||||
// 'ostream_ptr' is not NULL, or the behavior is undefined.
|
// 'ostream_ptr' is not NULL, or the behavior is undefined.
|
||||||
|
@ -480,14 +581,16 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_STD_WSTRING
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
#if GTEST_HAS_TR1_TUPLE
|
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||||
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
|
||||||
// which are packed as tuples.
|
|
||||||
|
|
||||||
// Helper function for printing a tuple. T must be instantiated with
|
// Helper function for printing a tuple. T must be instantiated with
|
||||||
// a tuple type.
|
// a tuple type.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void PrintTupleTo(const T& t, ::std::ostream* os);
|
void PrintTupleTo(const T& t, ::std::ostream* os);
|
||||||
|
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||||
|
|
||||||
|
#if GTEST_HAS_TR1_TUPLE
|
||||||
|
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
||||||
|
// which are packed as tuples.
|
||||||
|
|
||||||
// Overloaded PrintTo() for tuples of various arities. We support
|
// Overloaded PrintTo() for tuples of various arities. We support
|
||||||
// tuples of up-to 10 fields. The following implementation works
|
// tuples of up-to 10 fields. The following implementation works
|
||||||
|
@ -561,6 +664,13 @@ void PrintTo(
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_TR1_TUPLE
|
#endif // GTEST_HAS_TR1_TUPLE
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_TUPLE_
|
||||||
|
template <typename... Types>
|
||||||
|
void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
|
||||||
|
PrintTupleTo(t, os);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_STD_TUPLE_
|
||||||
|
|
||||||
// Overload for std::pair.
|
// Overload for std::pair.
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
|
void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
|
||||||
|
@ -580,10 +690,7 @@ class UniversalPrinter {
|
||||||
public:
|
public:
|
||||||
// MSVC warns about adding const to a function type, so we want to
|
// MSVC warns about adding const to a function type, so we want to
|
||||||
// disable the warning.
|
// disable the warning.
|
||||||
#ifdef _MSC_VER
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||||
# pragma warning(push) // Saves the current warning state.
|
|
||||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
|
||||||
#endif // _MSC_VER
|
|
||||||
|
|
||||||
// Note: we deliberately don't call this PrintTo(), as that name
|
// Note: we deliberately don't call this PrintTo(), as that name
|
||||||
// conflicts with ::testing::internal::PrintTo in the body of the
|
// conflicts with ::testing::internal::PrintTo in the body of the
|
||||||
|
@ -600,9 +707,7 @@ class UniversalPrinter {
|
||||||
PrintTo(value, os);
|
PrintTo(value, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||||
# pragma warning(pop) // Restores the warning state.
|
|
||||||
#endif // _MSC_VER
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||||
|
@ -630,9 +735,12 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// This overload prints a (const) char array compactly.
|
// This overload prints a (const) char array compactly.
|
||||||
GTEST_API_ void UniversalPrintArray(const char* begin,
|
GTEST_API_ void UniversalPrintArray(
|
||||||
size_t len,
|
const char* begin, size_t len, ::std::ostream* os);
|
||||||
::std::ostream* os);
|
|
||||||
|
// This overload prints a (const) wchar_t array compactly.
|
||||||
|
GTEST_API_ void UniversalPrintArray(
|
||||||
|
const wchar_t* begin, size_t len, ::std::ostream* os);
|
||||||
|
|
||||||
// Implements printing an array type T[N].
|
// Implements printing an array type T[N].
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
|
@ -651,10 +759,7 @@ class UniversalPrinter<T&> {
|
||||||
public:
|
public:
|
||||||
// MSVC warns about adding const to a function type, so we want to
|
// MSVC warns about adding const to a function type, so we want to
|
||||||
// disable the warning.
|
// disable the warning.
|
||||||
#ifdef _MSC_VER
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||||
# pragma warning(push) // Saves the current warning state.
|
|
||||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
|
||||||
#endif // _MSC_VER
|
|
||||||
|
|
||||||
static void Print(const T& value, ::std::ostream* os) {
|
static void Print(const T& value, ::std::ostream* os) {
|
||||||
// Prints the address of the value. We use reinterpret_cast here
|
// Prints the address of the value. We use reinterpret_cast here
|
||||||
|
@ -665,27 +770,78 @@ class UniversalPrinter<T&> {
|
||||||
UniversalPrint(value, os);
|
UniversalPrint(value, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||||
# pragma warning(pop) // Restores the warning state.
|
|
||||||
#endif // _MSC_VER
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prints a value tersely: for a reference type, the referenced value
|
// Prints a value tersely: for a reference type, the referenced value
|
||||||
// (but not the address) is printed; for a (const) char pointer, the
|
// (but not the address) is printed; for a (const) char pointer, the
|
||||||
// NUL-terminated string (but not the pointer) is printed.
|
// NUL-terminated string (but not the pointer) is printed.
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class UniversalTersePrinter {
|
||||||
|
public:
|
||||||
|
static void Print(const T& value, ::std::ostream* os) {
|
||||||
|
UniversalPrint(value, os);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
class UniversalTersePrinter<T&> {
|
||||||
|
public:
|
||||||
|
static void Print(const T& value, ::std::ostream* os) {
|
||||||
|
UniversalPrint(value, os);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename T, size_t N>
|
||||||
|
class UniversalTersePrinter<T[N]> {
|
||||||
|
public:
|
||||||
|
static void Print(const T (&value)[N], ::std::ostream* os) {
|
||||||
|
UniversalPrinter<T[N]>::Print(value, os);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
class UniversalTersePrinter<const char*> {
|
||||||
|
public:
|
||||||
|
static void Print(const char* str, ::std::ostream* os) {
|
||||||
|
if (str == NULL) {
|
||||||
|
*os << "NULL";
|
||||||
|
} else {
|
||||||
|
UniversalPrint(string(str), os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
class UniversalTersePrinter<char*> {
|
||||||
|
public:
|
||||||
|
static void Print(char* str, ::std::ostream* os) {
|
||||||
|
UniversalTersePrinter<const char*>::Print(str, os);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_WSTRING
|
||||||
|
template <>
|
||||||
|
class UniversalTersePrinter<const wchar_t*> {
|
||||||
|
public:
|
||||||
|
static void Print(const wchar_t* str, ::std::ostream* os) {
|
||||||
|
if (str == NULL) {
|
||||||
|
*os << "NULL";
|
||||||
|
} else {
|
||||||
|
UniversalPrint(::std::wstring(str), os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class UniversalTersePrinter<wchar_t*> {
|
||||||
|
public:
|
||||||
|
static void Print(wchar_t* str, ::std::ostream* os) {
|
||||||
|
UniversalTersePrinter<const wchar_t*>::Print(str, os);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
||||||
UniversalPrint(value, os);
|
UniversalTersePrinter<T>::Print(value, os);
|
||||||
}
|
|
||||||
inline void UniversalTersePrint(const char* str, ::std::ostream* os) {
|
|
||||||
if (str == NULL) {
|
|
||||||
*os << "NULL";
|
|
||||||
} else {
|
|
||||||
UniversalPrint(string(str), os);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline void UniversalTersePrint(char* str, ::std::ostream* os) {
|
|
||||||
UniversalTersePrint(static_cast<const char*>(str), os);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints a value using the type inferred by the compiler. The
|
// Prints a value using the type inferred by the compiler. The
|
||||||
|
@ -694,19 +850,71 @@ inline void UniversalTersePrint(char* str, ::std::ostream* os) {
|
||||||
// NUL-terminated string.
|
// NUL-terminated string.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void UniversalPrint(const T& value, ::std::ostream* os) {
|
void UniversalPrint(const T& value, ::std::ostream* os) {
|
||||||
UniversalPrinter<T>::Print(value, os);
|
// A workarond for the bug in VC++ 7.1 that prevents us from instantiating
|
||||||
|
// UniversalPrinter with T directly.
|
||||||
|
typedef T T1;
|
||||||
|
UniversalPrinter<T1>::Print(value, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_TR1_TUPLE
|
|
||||||
typedef ::std::vector<string> Strings;
|
typedef ::std::vector<string> Strings;
|
||||||
|
|
||||||
|
// TuplePolicy<TupleT> must provide:
|
||||||
|
// - tuple_size
|
||||||
|
// size of tuple TupleT.
|
||||||
|
// - get<size_t I>(const TupleT& t)
|
||||||
|
// static function extracting element I of tuple TupleT.
|
||||||
|
// - tuple_element<size_t I>::type
|
||||||
|
// type of element I of tuple TupleT.
|
||||||
|
template <typename TupleT>
|
||||||
|
struct TuplePolicy;
|
||||||
|
|
||||||
|
#if GTEST_HAS_TR1_TUPLE
|
||||||
|
template <typename TupleT>
|
||||||
|
struct TuplePolicy {
|
||||||
|
typedef TupleT Tuple;
|
||||||
|
static const size_t tuple_size = ::std::tr1::tuple_size<Tuple>::value;
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
struct tuple_element : ::std::tr1::tuple_element<I, Tuple> {};
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
static typename AddReference<
|
||||||
|
const typename ::std::tr1::tuple_element<I, Tuple>::type>::type get(
|
||||||
|
const Tuple& tuple) {
|
||||||
|
return ::std::tr1::get<I>(tuple);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename TupleT>
|
||||||
|
const size_t TuplePolicy<TupleT>::tuple_size;
|
||||||
|
#endif // GTEST_HAS_TR1_TUPLE
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_TUPLE_
|
||||||
|
template <typename... Types>
|
||||||
|
struct TuplePolicy< ::std::tuple<Types...> > {
|
||||||
|
typedef ::std::tuple<Types...> Tuple;
|
||||||
|
static const size_t tuple_size = ::std::tuple_size<Tuple>::value;
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
struct tuple_element : ::std::tuple_element<I, Tuple> {};
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
static const typename ::std::tuple_element<I, Tuple>::type& get(
|
||||||
|
const Tuple& tuple) {
|
||||||
|
return ::std::get<I>(tuple);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename... Types>
|
||||||
|
const size_t TuplePolicy< ::std::tuple<Types...> >::tuple_size;
|
||||||
|
#endif // GTEST_HAS_STD_TUPLE_
|
||||||
|
|
||||||
|
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||||
// This helper template allows PrintTo() for tuples and
|
// This helper template allows PrintTo() for tuples and
|
||||||
// UniversalTersePrintTupleFieldsToStrings() to be defined by
|
// UniversalTersePrintTupleFieldsToStrings() to be defined by
|
||||||
// induction on the number of tuple fields. The idea is that
|
// induction on the number of tuple fields. The idea is that
|
||||||
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
|
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
|
||||||
// fields in tuple t, and can be defined in terms of
|
// fields in tuple t, and can be defined in terms of
|
||||||
// TuplePrefixPrinter<N - 1>.
|
// TuplePrefixPrinter<N - 1>.
|
||||||
|
//
|
||||||
// The inductive case.
|
// The inductive case.
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct TuplePrefixPrinter {
|
struct TuplePrefixPrinter {
|
||||||
|
@ -714,9 +922,14 @@ struct TuplePrefixPrinter {
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||||
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
||||||
*os << ", ";
|
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||||
UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
|
if (N > 1) {
|
||||||
::Print(::std::tr1::get<N - 1>(t), os);
|
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||||
|
*os << ", ";
|
||||||
|
}
|
||||||
|
UniversalPrinter<
|
||||||
|
typename TuplePolicy<Tuple>::template tuple_element<N - 1>::type>
|
||||||
|
::Print(TuplePolicy<Tuple>::template get<N - 1>(t), os);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tersely prints the first N fields of a tuple to a string vector,
|
// Tersely prints the first N fields of a tuple to a string vector,
|
||||||
|
@ -725,12 +938,12 @@ struct TuplePrefixPrinter {
|
||||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||||
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
|
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
|
||||||
::std::stringstream ss;
|
::std::stringstream ss;
|
||||||
UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
|
UniversalTersePrint(TuplePolicy<Tuple>::template get<N - 1>(t), &ss);
|
||||||
strings->push_back(ss.str());
|
strings->push_back(ss.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Base cases.
|
// Base case.
|
||||||
template <>
|
template <>
|
||||||
struct TuplePrefixPrinter<0> {
|
struct TuplePrefixPrinter<0> {
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
|
@ -739,34 +952,13 @@ struct TuplePrefixPrinter<0> {
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
|
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
|
||||||
};
|
};
|
||||||
// We have to specialize the entire TuplePrefixPrinter<> class
|
|
||||||
// template here, even though the definition of
|
|
||||||
// TersePrintPrefixToStrings() is the same as the generic version, as
|
|
||||||
// Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't
|
|
||||||
// support specializing a method template of a class template.
|
|
||||||
template <>
|
|
||||||
struct TuplePrefixPrinter<1> {
|
|
||||||
template <typename Tuple>
|
|
||||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
|
||||||
UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
|
|
||||||
Print(::std::tr1::get<0>(t), os);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Tuple>
|
// Helper function for printing a tuple.
|
||||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
// Tuple must be either std::tr1::tuple or std::tuple type.
|
||||||
::std::stringstream ss;
|
template <typename Tuple>
|
||||||
UniversalTersePrint(::std::tr1::get<0>(t), &ss);
|
void PrintTupleTo(const Tuple& t, ::std::ostream* os) {
|
||||||
strings->push_back(ss.str());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function for printing a tuple. T must be instantiated with
|
|
||||||
// a tuple type.
|
|
||||||
template <typename T>
|
|
||||||
void PrintTupleTo(const T& t, ::std::ostream* os) {
|
|
||||||
*os << "(";
|
*os << "(";
|
||||||
TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
|
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::PrintPrefixTo(t, os);
|
||||||
PrintPrefixTo(t, os);
|
|
||||||
*os << ")";
|
*os << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,21 +968,26 @@ void PrintTupleTo(const T& t, ::std::ostream* os) {
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
||||||
Strings result;
|
Strings result;
|
||||||
TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
|
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::
|
||||||
TersePrintPrefixToStrings(value, &result);
|
TersePrintPrefixToStrings(value, &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_TR1_TUPLE
|
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
::std::string PrintToString(const T& value) {
|
::std::string PrintToString(const T& value) {
|
||||||
::std::stringstream ss;
|
::std::stringstream ss;
|
||||||
internal::UniversalTersePrint(value, &ss);
|
internal::UniversalTersePrinter<T>::Print(value, &ss);
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
|
// Include any custom printer added by the local installation.
|
||||||
|
// We must include this header at the end to make sure it can use the
|
||||||
|
// declarations from this file.
|
||||||
|
#include "gtest/internal/custom/gtest-printers.h"
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||||
|
|
|
@ -68,15 +68,14 @@ class GTEST_API_ ScopedFakeTestPartResultReporter
|
||||||
TestPartResultArray* result);
|
TestPartResultArray* result);
|
||||||
|
|
||||||
// The d'tor restores the previous test part result reporter.
|
// The d'tor restores the previous test part result reporter.
|
||||||
~ScopedFakeTestPartResultReporter() override;
|
virtual ~ScopedFakeTestPartResultReporter();
|
||||||
|
|
||||||
// Appends the TestPartResult object to the TestPartResultArray
|
// Appends the TestPartResult object to the TestPartResultArray
|
||||||
// received in the constructor.
|
// received in the constructor.
|
||||||
//
|
//
|
||||||
// This method is from the TestPartResultReporterInterface
|
// This method is from the TestPartResultReporterInterface
|
||||||
// interface.
|
// interface.
|
||||||
void ReportTestPartResult(const TestPartResult &result) override;
|
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
@ -224,7 +223,7 @@ class GTEST_API_ SingleFailureChecker {
|
||||||
(substr));\
|
(substr));\
|
||||||
{\
|
{\
|
||||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||||
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
|
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
|
||||||
>est_failures);\
|
>est_failures);\
|
||||||
if (::testing::internal::AlwaysTrue()) { statement; }\
|
if (::testing::internal::AlwaysTrue()) { statement; }\
|
||||||
}\
|
}\
|
||||||
|
|
|
@ -62,7 +62,7 @@ class GTEST_API_ TestPartResult {
|
||||||
int a_line_number,
|
int a_line_number,
|
||||||
const char* a_message)
|
const char* a_message)
|
||||||
: type_(a_type),
|
: type_(a_type),
|
||||||
file_name_(a_file_name),
|
file_name_(a_file_name == NULL ? "" : a_file_name),
|
||||||
line_number_(a_line_number),
|
line_number_(a_line_number),
|
||||||
summary_(ExtractSummary(a_message)),
|
summary_(ExtractSummary(a_message)),
|
||||||
message_(a_message) {
|
message_(a_message) {
|
||||||
|
@ -73,7 +73,9 @@ class GTEST_API_ TestPartResult {
|
||||||
|
|
||||||
// Gets the name of the source file where the test part took place, or
|
// Gets the name of the source file where the test part took place, or
|
||||||
// NULL if it's unknown.
|
// NULL if it's unknown.
|
||||||
const char* file_name() const { return file_name_.c_str(); }
|
const char* file_name() const {
|
||||||
|
return file_name_.empty() ? NULL : file_name_.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
// Gets the line in the source file where the test part took place,
|
// Gets the line in the source file where the test part took place,
|
||||||
// or -1 if it's unknown.
|
// or -1 if it's unknown.
|
||||||
|
@ -96,21 +98,22 @@ class GTEST_API_ TestPartResult {
|
||||||
|
|
||||||
// Returns true iff the test part fatally failed.
|
// Returns true iff the test part fatally failed.
|
||||||
bool fatally_failed() const { return type_ == kFatalFailure; }
|
bool fatally_failed() const { return type_ == kFatalFailure; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type type_;
|
Type type_;
|
||||||
|
|
||||||
// Gets the summary of the failure message by omitting the stack
|
// Gets the summary of the failure message by omitting the stack
|
||||||
// trace in it.
|
// trace in it.
|
||||||
static internal::String ExtractSummary(const char* message);
|
static std::string ExtractSummary(const char* message);
|
||||||
|
|
||||||
// The name of the source file where the test part took place, or
|
// The name of the source file where the test part took place, or
|
||||||
// NULL if the source file is unknown.
|
// "" if the source file is unknown.
|
||||||
internal::String file_name_;
|
std::string file_name_;
|
||||||
// The line in the source file where the test part took place, or -1
|
// The line in the source file where the test part took place, or -1
|
||||||
// if the line number is unknown.
|
// if the line number is unknown.
|
||||||
int line_number_;
|
int line_number_;
|
||||||
internal::String summary_; // The test failure summary.
|
std::string summary_; // The test failure summary.
|
||||||
internal::String message_; // The test failure message.
|
std::string message_; // The test failure message.
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prints a TestPartResult object.
|
// Prints a TestPartResult object.
|
||||||
|
@ -142,7 +145,7 @@ class GTEST_API_ TestPartResultArray {
|
||||||
// This interface knows how to report a test part result.
|
// This interface knows how to report a test part result.
|
||||||
class TestPartResultReporterInterface {
|
class TestPartResultReporterInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~TestPartResultReporterInterface();
|
virtual ~TestPartResultReporterInterface() {}
|
||||||
|
|
||||||
virtual void ReportTestPartResult(const TestPartResult& result) = 0;
|
virtual void ReportTestPartResult(const TestPartResult& result) = 0;
|
||||||
};
|
};
|
||||||
|
@ -159,8 +162,8 @@ class GTEST_API_ HasNewFatalFailureHelper
|
||||||
: public TestPartResultReporterInterface {
|
: public TestPartResultReporterInterface {
|
||||||
public:
|
public:
|
||||||
HasNewFatalFailureHelper();
|
HasNewFatalFailureHelper();
|
||||||
~HasNewFatalFailureHelper() override;
|
virtual ~HasNewFatalFailureHelper();
|
||||||
void ReportTestPartResult(const TestPartResult &result) override;
|
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||||
bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
|
bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
|
||||||
private:
|
private:
|
||||||
bool has_new_fatal_failure_;
|
bool has_new_fatal_failure_;
|
||||||
|
|
|
@ -181,7 +181,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||||
::testing::internal::TemplateSel< \
|
::testing::internal::TemplateSel< \
|
||||||
GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
|
GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
|
||||||
GTEST_TYPE_PARAMS_(CaseName)>::Register(\
|
GTEST_TYPE_PARAMS_(CaseName)>::Register(\
|
||||||
"", #CaseName, #TestName, 0); \
|
"", ::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||||
|
#CaseName, #TestName, 0); \
|
||||||
template <typename gtest_TypeParam_> \
|
template <typename gtest_TypeParam_> \
|
||||||
void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()
|
void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()
|
||||||
|
|
||||||
|
@ -236,8 +237,6 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||||
template <typename gtest_TypeParam_> \
|
template <typename gtest_TypeParam_> \
|
||||||
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
|
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
|
||||||
|
|
||||||
// Silencing C99 build warnings
|
|
||||||
#if 0
|
|
||||||
# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
||||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||||
|
@ -245,7 +244,6 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||||
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
|
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
|
||||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
|
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
|
||||||
__FILE__, __LINE__, #__VA_ARGS__)
|
__FILE__, __LINE__, #__VA_ARGS__)
|
||||||
#endif
|
|
||||||
|
|
||||||
// The 'Types' template argument below must have spaces around it
|
// The 'Types' template argument below must have spaces around it
|
||||||
// since some compilers may choke on '>>' when passing a template
|
// since some compilers may choke on '>>' when passing a template
|
||||||
|
@ -255,7 +253,10 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||||
::testing::internal::TypeParameterizedTestCase<CaseName, \
|
::testing::internal::TypeParameterizedTestCase<CaseName, \
|
||||||
GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
||||||
::testing::internal::TypeList< Types >::type>::Register(\
|
::testing::internal::TypeList< Types >::type>::Register(\
|
||||||
#Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
|
#Prefix, \
|
||||||
|
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||||
|
>EST_TYPED_TEST_CASE_P_STATE_(CaseName), \
|
||||||
|
#CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
|
||||||
|
|
||||||
#endif // GTEST_HAS_TYPED_TEST_P
|
#endif // GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,7 +27,7 @@
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command
|
// This file is AUTOMATICALLY GENERATED on 10/31/2011 by command
|
||||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||||
//
|
//
|
||||||
// Implements a family of generic predicate assertion macros.
|
// Implements a family of generic predicate assertion macros.
|
||||||
|
@ -98,7 +98,7 @@ AssertionResult AssertPred1Helper(const char* pred_text,
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
||||||
// Don't use this in your code.
|
// Don't use this in your code.
|
||||||
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
|
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
|
||||||
GTEST_ASSERT_(pred_format(#v1, v1),\
|
GTEST_ASSERT_(pred_format(#v1, v1), \
|
||||||
on_failure)
|
on_failure)
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
|
||||||
|
@ -144,7 +144,7 @@ AssertionResult AssertPred2Helper(const char* pred_text,
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
||||||
// Don't use this in your code.
|
// Don't use this in your code.
|
||||||
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
|
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
|
||||||
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
|
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
|
||||||
on_failure)
|
on_failure)
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
|
||||||
|
@ -197,7 +197,7 @@ AssertionResult AssertPred3Helper(const char* pred_text,
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
||||||
// Don't use this in your code.
|
// Don't use this in your code.
|
||||||
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
|
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
|
||||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\
|
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
|
||||||
on_failure)
|
on_failure)
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
|
||||||
|
@ -257,7 +257,7 @@ AssertionResult AssertPred4Helper(const char* pred_text,
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
||||||
// Don't use this in your code.
|
// Don't use this in your code.
|
||||||
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
|
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
|
||||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\
|
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
|
||||||
on_failure)
|
on_failure)
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
|
||||||
|
@ -324,7 +324,7 @@ AssertionResult AssertPred5Helper(const char* pred_text,
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
||||||
// Don't use this in your code.
|
// Don't use this in your code.
|
||||||
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
|
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
|
||||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\
|
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
|
||||||
on_failure)
|
on_failure)
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
// Copyright 2015, 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.
|
||||||
|
//
|
||||||
|
// Injection point for custom user configurations.
|
||||||
|
// The following macros can be defined:
|
||||||
|
//
|
||||||
|
// Flag related macros:
|
||||||
|
// GTEST_FLAG(flag_name)
|
||||||
|
// GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its
|
||||||
|
// own flagfile flag parsing.
|
||||||
|
// GTEST_DECLARE_bool_(name)
|
||||||
|
// GTEST_DECLARE_int32_(name)
|
||||||
|
// GTEST_DECLARE_string_(name)
|
||||||
|
// GTEST_DEFINE_bool_(name, default_val, doc)
|
||||||
|
// GTEST_DEFINE_int32_(name, default_val, doc)
|
||||||
|
// GTEST_DEFINE_string_(name, default_val, doc)
|
||||||
|
//
|
||||||
|
// Test filtering:
|
||||||
|
// GTEST_TEST_FILTER_ENV_VAR_ - The name of an environment variable that
|
||||||
|
// will be used if --GTEST_FLAG(test_filter)
|
||||||
|
// is not provided.
|
||||||
|
//
|
||||||
|
// Logging:
|
||||||
|
// GTEST_LOG_(severity)
|
||||||
|
// GTEST_CHECK_(condition)
|
||||||
|
// Functions LogToStderr() and FlushInfoLog() have to be provided too.
|
||||||
|
//
|
||||||
|
// Threading:
|
||||||
|
// GTEST_HAS_NOTIFICATION_ - Enabled if Notification is already provided.
|
||||||
|
// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Enabled if Mutex and ThreadLocal are
|
||||||
|
// already provided.
|
||||||
|
// Must also provide GTEST_DECLARE_STATIC_MUTEX_(mutex) and
|
||||||
|
// GTEST_DEFINE_STATIC_MUTEX_(mutex)
|
||||||
|
//
|
||||||
|
// GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
|
||||||
|
// GTEST_LOCK_EXCLUDED_(locks)
|
||||||
|
//
|
||||||
|
// ** Custom implementation starts here **
|
||||||
|
|
||||||
|
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||||
|
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||||
|
|
||||||
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Copyright 2015, 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.
|
||||||
|
//
|
||||||
|
// This file provides an injection point for custom printers in a local
|
||||||
|
// installation of gTest.
|
||||||
|
// It will be included from gtest-printers.h and the overrides in this file
|
||||||
|
// will be visible to everyone.
|
||||||
|
// See documentation at gtest/gtest-printers.h for details on how to define a
|
||||||
|
// custom printer.
|
||||||
|
//
|
||||||
|
// ** Custom implementation starts here **
|
||||||
|
|
||||||
|
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||||
|
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||||
|
|
||||||
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright 2015, 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.
|
||||||
|
//
|
||||||
|
// Injection point for custom user configurations.
|
||||||
|
// The following macros can be defined:
|
||||||
|
//
|
||||||
|
// GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of
|
||||||
|
// OsStackTraceGetterInterface.
|
||||||
|
//
|
||||||
|
// ** Custom implementation starts here **
|
||||||
|
|
||||||
|
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||||
|
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||||
|
|
||||||
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
|
@ -79,7 +79,7 @@ class GTEST_API_ DeathTest {
|
||||||
static bool Create(const char* statement, const RE* regex,
|
static bool Create(const char* statement, const RE* regex,
|
||||||
const char* file, int line, DeathTest** test);
|
const char* file, int line, DeathTest** test);
|
||||||
DeathTest();
|
DeathTest();
|
||||||
virtual ~DeathTest();
|
virtual ~DeathTest() { }
|
||||||
|
|
||||||
// A helper class that aborts a death test when it's deleted.
|
// A helper class that aborts a death test when it's deleted.
|
||||||
class ReturnSentinel {
|
class ReturnSentinel {
|
||||||
|
@ -127,11 +127,11 @@ class GTEST_API_ DeathTest {
|
||||||
// the last death test.
|
// the last death test.
|
||||||
static const char* LastMessage();
|
static const char* LastMessage();
|
||||||
|
|
||||||
static void set_last_death_test_message(const String& message);
|
static void set_last_death_test_message(const std::string& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// A string containing a description of the outcome of the last death test.
|
// A string containing a description of the outcome of the last death test.
|
||||||
static String last_death_test_message_;
|
static std::string last_death_test_message_;
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
|
||||||
};
|
};
|
||||||
|
@ -139,7 +139,7 @@ class GTEST_API_ DeathTest {
|
||||||
// Factory interface for death tests. May be mocked out for testing.
|
// Factory interface for death tests. May be mocked out for testing.
|
||||||
class DeathTestFactory {
|
class DeathTestFactory {
|
||||||
public:
|
public:
|
||||||
virtual ~DeathTestFactory();
|
virtual ~DeathTestFactory() { }
|
||||||
virtual bool Create(const char* statement, const RE* regex,
|
virtual bool Create(const char* statement, const RE* regex,
|
||||||
const char* file, int line, DeathTest** test) = 0;
|
const char* file, int line, DeathTest** test) = 0;
|
||||||
};
|
};
|
||||||
|
@ -147,8 +147,8 @@ class DeathTestFactory {
|
||||||
// A concrete DeathTestFactory implementation for normal use.
|
// A concrete DeathTestFactory implementation for normal use.
|
||||||
class DefaultDeathTestFactory : public DeathTestFactory {
|
class DefaultDeathTestFactory : public DeathTestFactory {
|
||||||
public:
|
public:
|
||||||
bool Create(const char *statement, const RE *regex, const char *file,
|
virtual bool Create(const char* statement, const RE* regex,
|
||||||
int line, DeathTest **test) override;
|
const char* file, int line, DeathTest** test);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns true if exit_status describes a process that was terminated
|
// Returns true if exit_status describes a process that was terminated
|
||||||
|
@ -215,12 +215,23 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||||
// The symbol "fail" here expands to something into which a message
|
// The symbol "fail" here expands to something into which a message
|
||||||
// can be streamed.
|
// can be streamed.
|
||||||
|
|
||||||
|
// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
|
||||||
|
// NDEBUG mode. In this case we need the statements to be executed, the regex is
|
||||||
|
// ignored, and the macro must accept a streamed message even though the message
|
||||||
|
// is never printed.
|
||||||
|
# define GTEST_EXECUTE_STATEMENT_(statement, regex) \
|
||||||
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
|
if (::testing::internal::AlwaysTrue()) { \
|
||||||
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
|
} else \
|
||||||
|
::testing::Message()
|
||||||
|
|
||||||
// A class representing the parsed contents of the
|
// A class representing the parsed contents of the
|
||||||
// --gtest_internal_run_death_test flag, as it existed when
|
// --gtest_internal_run_death_test flag, as it existed when
|
||||||
// RUN_ALL_TESTS was called.
|
// RUN_ALL_TESTS was called.
|
||||||
class InternalRunDeathTestFlag {
|
class InternalRunDeathTestFlag {
|
||||||
public:
|
public:
|
||||||
InternalRunDeathTestFlag(const String& a_file,
|
InternalRunDeathTestFlag(const std::string& a_file,
|
||||||
int a_line,
|
int a_line,
|
||||||
int an_index,
|
int an_index,
|
||||||
int a_write_fd)
|
int a_write_fd)
|
||||||
|
@ -232,13 +243,13 @@ class InternalRunDeathTestFlag {
|
||||||
posix::Close(write_fd_);
|
posix::Close(write_fd_);
|
||||||
}
|
}
|
||||||
|
|
||||||
String file() const { return file_; }
|
const std::string& file() const { return file_; }
|
||||||
int line() const { return line_; }
|
int line() const { return line_; }
|
||||||
int index() const { return index_; }
|
int index() const { return index_; }
|
||||||
int write_fd() const { return write_fd_; }
|
int write_fd() const { return write_fd_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String file_;
|
std::string file_;
|
||||||
int line_;
|
int line_;
|
||||||
int index_;
|
int index_;
|
||||||
int write_fd_;
|
int write_fd_;
|
||||||
|
|
|
@ -61,11 +61,7 @@ class GTEST_API_ FilePath {
|
||||||
FilePath() : pathname_("") { }
|
FilePath() : pathname_("") { }
|
||||||
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
|
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
|
||||||
|
|
||||||
explicit FilePath(const char* pathname) : pathname_(pathname) {
|
explicit FilePath(const std::string& pathname) : pathname_(pathname) {
|
||||||
Normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit FilePath(const String& pathname) : pathname_(pathname) {
|
|
||||||
Normalize();
|
Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +74,7 @@ class GTEST_API_ FilePath {
|
||||||
pathname_ = rhs.pathname_;
|
pathname_ = rhs.pathname_;
|
||||||
}
|
}
|
||||||
|
|
||||||
String ToString() const { return pathname_; }
|
const std::string& string() const { return pathname_; }
|
||||||
const char* c_str() const { return pathname_.c_str(); }
|
const char* c_str() const { return pathname_.c_str(); }
|
||||||
|
|
||||||
// Returns the current working directory, or "" if unsuccessful.
|
// Returns the current working directory, or "" if unsuccessful.
|
||||||
|
@ -111,8 +107,8 @@ class GTEST_API_ FilePath {
|
||||||
const FilePath& base_name,
|
const FilePath& base_name,
|
||||||
const char* extension);
|
const char* extension);
|
||||||
|
|
||||||
// Returns true iff the path is NULL or "".
|
// Returns true iff the path is "".
|
||||||
bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; }
|
bool IsEmpty() const { return pathname_.empty(); }
|
||||||
|
|
||||||
// If input name has a trailing separator character, removes it and returns
|
// If input name has a trailing separator character, removes it and returns
|
||||||
// the name, otherwise return the name string unmodified.
|
// the name, otherwise return the name string unmodified.
|
||||||
|
@ -196,12 +192,12 @@ class GTEST_API_ FilePath {
|
||||||
|
|
||||||
void Normalize();
|
void Normalize();
|
||||||
|
|
||||||
// Returns a pointer to the last occurrence of a valid path separator in
|
// Returns a pointer to the last occurence of a valid path separator in
|
||||||
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
||||||
// separators. Returns NULL if no path separator was found.
|
// separators. Returns NULL if no path separator was found.
|
||||||
const char* FindLastPathSeparator() const;
|
const char* FindLastPathSeparator() const;
|
||||||
|
|
||||||
String pathname_;
|
std::string pathname_;
|
||||||
}; // class FilePath
|
}; // class FilePath
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -46,20 +46,25 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif // GTEST_OS_LINUX
|
#endif // GTEST_OS_LINUX
|
||||||
|
|
||||||
|
#if GTEST_HAS_EXCEPTIONS
|
||||||
|
# include <stdexcept>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <float.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "gtest/gtest-message.h"
|
||||||
#include "gtest/internal/gtest-string.h"
|
#include "gtest/internal/gtest-string.h"
|
||||||
#include "gtest/internal/gtest-filepath.h"
|
#include "gtest/internal/gtest-filepath.h"
|
||||||
#include "gtest/internal/gtest-type-util.h"
|
#include "gtest/internal/gtest-type-util.h"
|
||||||
|
|
||||||
#if !GTEST_NO_LLVM_RAW_OSTREAM
|
|
||||||
#include "llvm/Support/raw_os_ostream.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Due to C++ preprocessor weirdness, we need double indirection to
|
// Due to C++ preprocessor weirdness, we need double indirection to
|
||||||
// concatenate two tokens when one of them is __LINE__. Writing
|
// concatenate two tokens when one of them is __LINE__. Writing
|
||||||
//
|
//
|
||||||
|
@ -71,61 +76,6 @@
|
||||||
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
|
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
|
||||||
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) 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.
|
|
||||||
|
|
||||||
// LLVM INTERNAL CHANGE: To allow operator<< to work with both
|
|
||||||
// std::ostreams and LLVM's raw_ostreams, we define a special
|
|
||||||
// std::ostream with an implicit conversion to raw_ostream& and stream
|
|
||||||
// to that. This causes the compiler to prefer std::ostream overloads
|
|
||||||
// but still find raw_ostream& overloads.
|
|
||||||
#if !GTEST_NO_LLVM_RAW_OSTREAM
|
|
||||||
namespace llvm {
|
|
||||||
class convertible_fwd_ostream : public std::ostream {
|
|
||||||
virtual void anchor();
|
|
||||||
raw_os_ostream ros_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
convertible_fwd_ostream(std::ostream& os)
|
|
||||||
: std::ostream(os.rdbuf()), ros_(*this) {}
|
|
||||||
operator raw_ostream&() { return ros_; }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
inline void GTestStreamToHelper(std::ostream* os, const T& val) {
|
|
||||||
llvm::convertible_fwd_ostream cos(*os);
|
|
||||||
cos << val;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
template <typename T>
|
|
||||||
inline void GTestStreamToHelper(std::ostream* os, const T& val) {
|
|
||||||
*os << val;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class ProtocolMessage;
|
class ProtocolMessage;
|
||||||
namespace proto2 { class Message; }
|
namespace proto2 { class Message; }
|
||||||
|
|
||||||
|
@ -150,18 +100,10 @@ class ScopedTrace; // Implements scoped trace.
|
||||||
class TestInfoImpl; // Opaque implementation of TestInfo
|
class TestInfoImpl; // Opaque implementation of TestInfo
|
||||||
class UnitTestImpl; // Opaque implementation of UnitTest
|
class UnitTestImpl; // Opaque implementation of UnitTest
|
||||||
|
|
||||||
// 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
|
// The text used in failure messages to indicate the start of the
|
||||||
// stack trace.
|
// stack trace.
|
||||||
GTEST_API_ extern const char kStackTraceMarker[];
|
GTEST_API_ 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
|
// Two overloaded helpers for checking at compile time whether an
|
||||||
// expression is a null pointer literal (i.e. NULL or any 0-valued
|
// expression is a null pointer literal (i.e. NULL or any 0-valued
|
||||||
// compile-time integral constant). Their return values have
|
// compile-time integral constant). Their return values have
|
||||||
|
@ -192,8 +134,23 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
|
||||||
#endif // GTEST_ELLIPSIS_NEEDS_POD_
|
#endif // GTEST_ELLIPSIS_NEEDS_POD_
|
||||||
|
|
||||||
// Appends the user-supplied message to the Google-Test-generated message.
|
// Appends the user-supplied message to the Google-Test-generated message.
|
||||||
GTEST_API_ String AppendUserMessage(const String& gtest_msg,
|
GTEST_API_ std::string AppendUserMessage(
|
||||||
const Message& user_msg);
|
const std::string& gtest_msg, const Message& user_msg);
|
||||||
|
|
||||||
|
#if GTEST_HAS_EXCEPTIONS
|
||||||
|
|
||||||
|
// This exception is thrown by (and only by) a failed Google Test
|
||||||
|
// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
|
||||||
|
// are enabled). We derive it from std::runtime_error, which is for
|
||||||
|
// errors presumably detectable only at run time. Since
|
||||||
|
// std::runtime_error inherits from std::exception, many testing
|
||||||
|
// frameworks know how to extract and print the message inside it.
|
||||||
|
class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
|
||||||
|
public:
|
||||||
|
explicit GoogleTestFailureException(const TestPartResult& failure);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GTEST_HAS_EXCEPTIONS
|
||||||
|
|
||||||
// A helper class for creating scoped traces in user programs.
|
// A helper class for creating scoped traces in user programs.
|
||||||
class GTEST_API_ ScopedTrace {
|
class GTEST_API_ ScopedTrace {
|
||||||
|
@ -214,76 +171,35 @@ class GTEST_API_ ScopedTrace {
|
||||||
// c'tor and d'tor. Therefore it doesn't
|
// c'tor and d'tor. Therefore it doesn't
|
||||||
// need to be used otherwise.
|
// need to be used otherwise.
|
||||||
|
|
||||||
// Converts a streamable value to a String. A NULL pointer is
|
namespace edit_distance {
|
||||||
// converted to "(null)". When the input value is a ::string,
|
// Returns the optimal edits to go from 'left' to 'right'.
|
||||||
// ::std::string, ::wstring, or ::std::wstring object, each NUL
|
// All edits cost the same, with replace having lower priority than
|
||||||
// character in it is replaced with "\\0".
|
// add/remove.
|
||||||
// Declared here but defined in gtest.h, so that it has access
|
// Simple implementation of the Wagner–Fischer algorithm.
|
||||||
// to the definition of the Message class, required by the ARM
|
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
||||||
// compiler.
|
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
||||||
template <typename T>
|
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||||
String StreamableToString(const T& streamable);
|
const std::vector<size_t>& left, const std::vector<size_t>& right);
|
||||||
|
|
||||||
// The Symbian compiler has a bug that prevents it from selecting the
|
// Same as above, but the input is represented as strings.
|
||||||
// correct overload of FormatForComparisonFailureMessage (see below)
|
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||||
// unless we pass the first argument by reference. If we do that,
|
const std::vector<std::string>& left,
|
||||||
// however, Visual Age C++ 10.1 generates a compiler error. Therefore
|
const std::vector<std::string>& right);
|
||||||
// we only apply the work-around for Symbian.
|
|
||||||
#if defined(__SYMBIAN32__)
|
|
||||||
# define GTEST_CREF_WORKAROUND_ const&
|
|
||||||
#else
|
|
||||||
# define GTEST_CREF_WORKAROUND_
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// When this operand is a const char* or char*, if the other operand
|
// Create a diff of the input strings in Unified diff format.
|
||||||
// is a ::std::string or ::string, we print this operand as a C string
|
GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
|
||||||
// rather than a pointer (we do the same for wide strings); otherwise
|
const std::vector<std::string>& right,
|
||||||
// we print it as a pointer to be safe.
|
size_t context = 2);
|
||||||
|
|
||||||
// This internal macro is used to avoid duplicated code.
|
} // namespace edit_distance
|
||||||
#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\
|
|
||||||
inline String FormatForComparisonFailureMessage(\
|
|
||||||
operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
|
|
||||||
const operand2_type& /*operand2*/) {\
|
|
||||||
return operand1_printer(str);\
|
|
||||||
}\
|
|
||||||
inline String FormatForComparisonFailureMessage(\
|
|
||||||
const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
|
|
||||||
const operand2_type& /*operand2*/) {\
|
|
||||||
return operand1_printer(str);\
|
|
||||||
}
|
|
||||||
|
|
||||||
GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)
|
// Calculate the diff between 'left' and 'right' and return it in unified diff
|
||||||
#if GTEST_HAS_STD_WSTRING
|
// format.
|
||||||
GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted)
|
// If not null, stores in 'total_line_count' the total number of lines found
|
||||||
#endif // GTEST_HAS_STD_WSTRING
|
// in left + right.
|
||||||
|
GTEST_API_ std::string DiffStrings(const std::string& left,
|
||||||
#if GTEST_HAS_GLOBAL_STRING
|
const std::string& right,
|
||||||
GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted)
|
size_t* total_line_count);
|
||||||
#endif // GTEST_HAS_GLOBAL_STRING
|
|
||||||
#if GTEST_HAS_GLOBAL_WSTRING
|
|
||||||
GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)
|
|
||||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
|
||||||
|
|
||||||
#undef GTEST_FORMAT_IMPL_
|
|
||||||
|
|
||||||
// The next four overloads handle the case where the operand being
|
|
||||||
// printed is a char/wchar_t pointer and the other operand is not a
|
|
||||||
// string/wstring object. In such cases, we just print the operand as
|
|
||||||
// a pointer to be safe.
|
|
||||||
#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \
|
|
||||||
template <typename T> \
|
|
||||||
String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \
|
|
||||||
const T&) { \
|
|
||||||
return PrintToString(static_cast<const void*>(p)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
GTEST_FORMAT_CHAR_PTR_IMPL_(char)
|
|
||||||
GTEST_FORMAT_CHAR_PTR_IMPL_(const char)
|
|
||||||
GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t)
|
|
||||||
GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)
|
|
||||||
|
|
||||||
#undef GTEST_FORMAT_CHAR_PTR_IMPL_
|
|
||||||
|
|
||||||
// Constructs and returns the message for an equality assertion
|
// Constructs and returns the message for an equality assertion
|
||||||
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
|
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
|
||||||
|
@ -302,12 +218,12 @@ GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)
|
||||||
// be inserted into the message.
|
// be inserted into the message.
|
||||||
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
|
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
|
||||||
const char* actual_expression,
|
const char* actual_expression,
|
||||||
const String& expected_value,
|
const std::string& expected_value,
|
||||||
const String& actual_value,
|
const std::string& actual_value,
|
||||||
bool ignoring_case);
|
bool ignoring_case);
|
||||||
|
|
||||||
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
|
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
|
||||||
GTEST_API_ String GetBoolAssertionFailureMessage(
|
GTEST_API_ std::string GetBoolAssertionFailureMessage(
|
||||||
const AssertionResult& assertion_result,
|
const AssertionResult& assertion_result,
|
||||||
const char* expression_text,
|
const char* expression_text,
|
||||||
const char* actual_predicate_value,
|
const char* actual_predicate_value,
|
||||||
|
@ -382,7 +298,7 @@ class FloatingPoint {
|
||||||
// bits. Therefore, 4 should be enough for ordinary use.
|
// bits. Therefore, 4 should be enough for ordinary use.
|
||||||
//
|
//
|
||||||
// See the following article for more details on ULP:
|
// See the following article for more details on ULP:
|
||||||
// http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm.
|
// http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||||
static const size_t kMaxUlps = 4;
|
static const size_t kMaxUlps = 4;
|
||||||
|
|
||||||
// Constructs a FloatingPoint from a raw floating-point number.
|
// Constructs a FloatingPoint from a raw floating-point number.
|
||||||
|
@ -409,6 +325,9 @@ class FloatingPoint {
|
||||||
return ReinterpretBits(kExponentBitMask);
|
return ReinterpretBits(kExponentBitMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the maximum representable finite floating-point number.
|
||||||
|
static RawType Max();
|
||||||
|
|
||||||
// Non-static methods
|
// Non-static methods
|
||||||
|
|
||||||
// Returns the bits that represents this number.
|
// Returns the bits that represents this number.
|
||||||
|
@ -489,6 +408,13 @@ class FloatingPoint {
|
||||||
FloatingPointUnion u_;
|
FloatingPointUnion u_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We cannot use std::numeric_limits<T>::max() as it clashes with the max()
|
||||||
|
// macro defined by <windows.h>.
|
||||||
|
template <>
|
||||||
|
inline float FloatingPoint<float>::Max() { return FLT_MAX; }
|
||||||
|
template <>
|
||||||
|
inline double FloatingPoint<double>::Max() { return DBL_MAX; }
|
||||||
|
|
||||||
// Typedefs the instances of the FloatingPoint template class that we
|
// Typedefs the instances of the FloatingPoint template class that we
|
||||||
// care to use.
|
// care to use.
|
||||||
typedef FloatingPoint<float> Float;
|
typedef FloatingPoint<float> Float;
|
||||||
|
@ -537,7 +463,7 @@ GTEST_API_ TypeId GetTestTypeId();
|
||||||
// of a Test object.
|
// of a Test object.
|
||||||
class TestFactoryBase {
|
class TestFactoryBase {
|
||||||
public:
|
public:
|
||||||
virtual ~TestFactoryBase();
|
virtual ~TestFactoryBase() {}
|
||||||
|
|
||||||
// Creates a test instance to run. The instance is both created and destroyed
|
// Creates a test instance to run. The instance is both created and destroyed
|
||||||
// within TestInfoImpl::Run()
|
// within TestInfoImpl::Run()
|
||||||
|
@ -555,7 +481,7 @@ class TestFactoryBase {
|
||||||
template <class TestClass>
|
template <class TestClass>
|
||||||
class TestFactoryImpl : public TestFactoryBase {
|
class TestFactoryImpl : public TestFactoryBase {
|
||||||
public:
|
public:
|
||||||
Test *CreateTest() override { return new TestClass; }
|
virtual Test* CreateTest() { return new TestClass; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS
|
#if GTEST_OS_WINDOWS
|
||||||
|
@ -575,6 +501,13 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
|
||||||
typedef void (*SetUpTestCaseFunc)();
|
typedef void (*SetUpTestCaseFunc)();
|
||||||
typedef void (*TearDownTestCaseFunc)();
|
typedef void (*TearDownTestCaseFunc)();
|
||||||
|
|
||||||
|
struct CodeLocation {
|
||||||
|
CodeLocation(const string& a_file, int a_line) : file(a_file), line(a_line) {}
|
||||||
|
|
||||||
|
string file;
|
||||||
|
int line;
|
||||||
|
};
|
||||||
|
|
||||||
// Creates a new TestInfo object and registers it with Google Test;
|
// Creates a new TestInfo object and registers it with Google Test;
|
||||||
// returns the created object.
|
// returns the created object.
|
||||||
//
|
//
|
||||||
|
@ -583,9 +516,10 @@ typedef void (*TearDownTestCaseFunc)();
|
||||||
// test_case_name: name of the test case
|
// test_case_name: name of the test case
|
||||||
// name: name of the test
|
// name: name of the test
|
||||||
// type_param the name of the test's type parameter, or NULL if
|
// type_param the name of the test's type parameter, or NULL if
|
||||||
// this is not a typed or a type-parameterized test.
|
// this is not a typed or a type-parameterized test.
|
||||||
// value_param text representation of the test's value parameter,
|
// value_param text representation of the test's value parameter,
|
||||||
// or NULL if this is not a type-parameterized test.
|
// or NULL if this is not a type-parameterized test.
|
||||||
|
// code_location: code location where the test is defined
|
||||||
// fixture_class_id: ID of the test fixture class
|
// fixture_class_id: ID of the test fixture class
|
||||||
// set_up_tc: pointer to the function that sets up the test case
|
// set_up_tc: pointer to the function that sets up the test case
|
||||||
// tear_down_tc: pointer to the function that tears down the test case
|
// tear_down_tc: pointer to the function that tears down the test case
|
||||||
|
@ -593,9 +527,11 @@ typedef void (*TearDownTestCaseFunc)();
|
||||||
// The newly created TestInfo instance will assume
|
// The newly created TestInfo instance will assume
|
||||||
// ownership of the factory object.
|
// ownership of the factory object.
|
||||||
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||||
const char* test_case_name, const char* name,
|
const char* test_case_name,
|
||||||
|
const char* name,
|
||||||
const char* type_param,
|
const char* type_param,
|
||||||
const char* value_param,
|
const char* value_param,
|
||||||
|
CodeLocation code_location,
|
||||||
TypeId fixture_class_id,
|
TypeId fixture_class_id,
|
||||||
SetUpTestCaseFunc set_up_tc,
|
SetUpTestCaseFunc set_up_tc,
|
||||||
TearDownTestCaseFunc tear_down_tc,
|
TearDownTestCaseFunc tear_down_tc,
|
||||||
|
@ -625,10 +561,21 @@ class GTEST_API_ TypedTestCasePState {
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
posix::Abort();
|
posix::Abort();
|
||||||
}
|
}
|
||||||
defined_test_names_.insert(test_name);
|
registered_tests_.insert(
|
||||||
|
::std::make_pair(test_name, CodeLocation(file, line)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TestExists(const std::string& test_name) const {
|
||||||
|
return registered_tests_.count(test_name) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CodeLocation& GetCodeLocation(const std::string& test_name) const {
|
||||||
|
RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
|
||||||
|
GTEST_CHECK_(it != registered_tests_.end());
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
// Verifies that registered_tests match the test names in
|
// Verifies that registered_tests match the test names in
|
||||||
// defined_test_names_; returns registered_tests if successful, or
|
// defined_test_names_; returns registered_tests if successful, or
|
||||||
// aborts the program otherwise.
|
// aborts the program otherwise.
|
||||||
|
@ -636,8 +583,10 @@ class GTEST_API_ TypedTestCasePState {
|
||||||
const char* file, int line, const char* registered_tests);
|
const char* file, int line, const char* registered_tests);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
|
||||||
|
|
||||||
bool registered_;
|
bool registered_;
|
||||||
::std::set<const char*> defined_test_names_;
|
RegisteredTestsMap registered_tests_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Skips to the first non-space char after the first comma in 'str';
|
// Skips to the first non-space char after the first comma in 'str';
|
||||||
|
@ -653,11 +602,16 @@ inline const char* SkipComma(const char* str) {
|
||||||
|
|
||||||
// Returns the prefix of 'str' before the first comma in it; returns
|
// Returns the prefix of 'str' before the first comma in it; returns
|
||||||
// the entire string if it contains no comma.
|
// the entire string if it contains no comma.
|
||||||
inline String GetPrefixUntilComma(const char* str) {
|
inline std::string GetPrefixUntilComma(const char* str) {
|
||||||
const char* comma = strchr(str, ',');
|
const char* comma = strchr(str, ',');
|
||||||
return comma == NULL ? String(str) : String(str, comma - str);
|
return comma == NULL ? str : std::string(str, comma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Splits a given string on a given delimiter, populating a given
|
||||||
|
// vector with the fields.
|
||||||
|
void SplitString(const ::std::string& str, char delimiter,
|
||||||
|
::std::vector< ::std::string>* dest);
|
||||||
|
|
||||||
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
|
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
|
||||||
// registers a list of type-parameterized tests with Google Test. The
|
// registers a list of type-parameterized tests with Google Test. The
|
||||||
// return value is insignificant - we just need to return something
|
// return value is insignificant - we just need to return something
|
||||||
|
@ -672,8 +626,10 @@ class TypeParameterizedTest {
|
||||||
// specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
|
// specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
|
||||||
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
||||||
// length of Types.
|
// length of Types.
|
||||||
static bool Register(const char* prefix, const char* case_name,
|
static bool Register(const char* prefix,
|
||||||
const char* test_names, int index) {
|
CodeLocation code_location,
|
||||||
|
const char* case_name, const char* test_names,
|
||||||
|
int index) {
|
||||||
typedef typename Types::Head Type;
|
typedef typename Types::Head Type;
|
||||||
typedef Fixture<Type> FixtureClass;
|
typedef Fixture<Type> FixtureClass;
|
||||||
typedef typename GTEST_BIND_(TestSel, Type) TestClass;
|
typedef typename GTEST_BIND_(TestSel, Type) TestClass;
|
||||||
|
@ -681,11 +637,12 @@ class TypeParameterizedTest {
|
||||||
// First, registers the first type-parameterized test in the type
|
// First, registers the first type-parameterized test in the type
|
||||||
// list.
|
// list.
|
||||||
MakeAndRegisterTestInfo(
|
MakeAndRegisterTestInfo(
|
||||||
String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/",
|
(std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
|
||||||
case_name, index).c_str(),
|
+ StreamableToString(index)).c_str(),
|
||||||
GetPrefixUntilComma(test_names).c_str(),
|
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
|
||||||
GetTypeName<Type>().c_str(),
|
GetTypeName<Type>().c_str(),
|
||||||
NULL, // No value parameter.
|
NULL, // No value parameter.
|
||||||
|
code_location,
|
||||||
GetTypeId<FixtureClass>(),
|
GetTypeId<FixtureClass>(),
|
||||||
TestClass::SetUpTestCase,
|
TestClass::SetUpTestCase,
|
||||||
TestClass::TearDownTestCase,
|
TestClass::TearDownTestCase,
|
||||||
|
@ -693,7 +650,7 @@ class TypeParameterizedTest {
|
||||||
|
|
||||||
// Next, recurses (at compile time) with the tail of the type list.
|
// Next, recurses (at compile time) with the tail of the type list.
|
||||||
return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
|
return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
|
||||||
::Register(prefix, case_name, test_names, index + 1);
|
::Register(prefix, code_location, case_name, test_names, index + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -701,8 +658,9 @@ class TypeParameterizedTest {
|
||||||
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
||||||
class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* /*prefix*/, const char* /*case_name*/,
|
static bool Register(const char* /*prefix*/, CodeLocation,
|
||||||
const char* /*test_names*/, int /*index*/) {
|
const char* /*case_name*/, const char* /*test_names*/,
|
||||||
|
int /*index*/) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -714,17 +672,31 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||||
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
||||||
class TypeParameterizedTestCase {
|
class TypeParameterizedTestCase {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* prefix, const char* case_name,
|
static bool Register(const char* prefix, CodeLocation code_location,
|
||||||
const char* test_names) {
|
const TypedTestCasePState* state,
|
||||||
|
const char* case_name, const char* test_names) {
|
||||||
|
std::string test_name = StripTrailingSpaces(
|
||||||
|
GetPrefixUntilComma(test_names));
|
||||||
|
if (!state->TestExists(test_name)) {
|
||||||
|
fprintf(stderr, "Failed to get code location for test %s.%s at %s.",
|
||||||
|
case_name, test_name.c_str(),
|
||||||
|
FormatFileLocation(code_location.file.c_str(),
|
||||||
|
code_location.line).c_str());
|
||||||
|
fflush(stderr);
|
||||||
|
posix::Abort();
|
||||||
|
}
|
||||||
|
const CodeLocation& test_location = state->GetCodeLocation(test_name);
|
||||||
|
|
||||||
typedef typename Tests::Head Head;
|
typedef typename Tests::Head Head;
|
||||||
|
|
||||||
// First, register the first test in 'Test' for each type in 'Types'.
|
// First, register the first test in 'Test' for each type in 'Types'.
|
||||||
TypeParameterizedTest<Fixture, Head, Types>::Register(
|
TypeParameterizedTest<Fixture, Head, Types>::Register(
|
||||||
prefix, case_name, test_names, 0);
|
prefix, test_location, case_name, test_names, 0);
|
||||||
|
|
||||||
// Next, recurses (at compile time) with the tail of the test list.
|
// Next, recurses (at compile time) with the tail of the test list.
|
||||||
return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
|
return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
|
||||||
::Register(prefix, case_name, SkipComma(test_names));
|
::Register(prefix, code_location, state,
|
||||||
|
case_name, SkipComma(test_names));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -732,15 +704,16 @@ class TypeParameterizedTestCase {
|
||||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
||||||
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* /*prefix*/, const char* /*case_name*/,
|
static bool Register(const char* /*prefix*/, CodeLocation,
|
||||||
const char* /*test_names*/) {
|
const TypedTestCasePState* /*state*/,
|
||||||
|
const char* /*case_name*/, const char* /*test_names*/) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
// Returns the current OS stack trace as a String.
|
// Returns the current OS stack trace as an std::string.
|
||||||
//
|
//
|
||||||
// The maximum number of stack frames to be included is specified by
|
// The maximum number of stack frames to be included is specified by
|
||||||
// the gtest_stack_trace_depth flag. The skip_count parameter
|
// the gtest_stack_trace_depth flag. The skip_count parameter
|
||||||
|
@ -750,8 +723,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
||||||
// For example, if Foo() calls Bar(), which in turn calls
|
// For example, if Foo() calls Bar(), which in turn calls
|
||||||
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
|
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
|
||||||
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
|
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
|
||||||
GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,
|
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
|
||||||
int skip_count);
|
UnitTest* unit_test, int skip_count);
|
||||||
|
|
||||||
// Helpers for suppressing warnings on unreachable code or constant
|
// Helpers for suppressing warnings on unreachable code or constant
|
||||||
// condition.
|
// condition.
|
||||||
|
@ -826,13 +799,19 @@ struct RemoveConst<const T> { typedef T type; }; // NOLINT
|
||||||
// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
|
// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
|
||||||
// definition to fail to remove the const in 'const int[3]' and 'const
|
// definition to fail to remove the const in 'const int[3]' and 'const
|
||||||
// char[3][4]'. The following specialization works around the bug.
|
// char[3][4]'. The following specialization works around the bug.
|
||||||
// However, it causes trouble with GCC and thus needs to be
|
|
||||||
// conditionally compiled.
|
|
||||||
#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
|
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
struct RemoveConst<const T[N]> {
|
struct RemoveConst<const T[N]> {
|
||||||
typedef typename RemoveConst<T>::type type[N];
|
typedef typename RemoveConst<T>::type type[N];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||||
|
// This is the only specialization that allows VC++ 7.1 to remove const in
|
||||||
|
// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC
|
||||||
|
// and thus needs to be conditionally compiled.
|
||||||
|
template <typename T, size_t N>
|
||||||
|
struct RemoveConst<T[N]> {
|
||||||
|
typedef typename RemoveConst<T>::type type[N];
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// A handy wrapper around RemoveConst that works when the argument
|
// A handy wrapper around RemoveConst that works when the argument
|
||||||
|
@ -881,7 +860,7 @@ class ImplicitlyConvertible {
|
||||||
// MakeFrom() is an expression whose type is From. We cannot simply
|
// MakeFrom() is an expression whose type is From. We cannot simply
|
||||||
// use From(), as the type From may not have a public default
|
// use From(), as the type From may not have a public default
|
||||||
// constructor.
|
// constructor.
|
||||||
static From MakeFrom();
|
static typename AddReference<From>::type MakeFrom();
|
||||||
|
|
||||||
// These two functions are overloaded. Given an expression
|
// These two functions are overloaded. Given an expression
|
||||||
// Helper(x), the compiler will pick the first version if x can be
|
// Helper(x), the compiler will pick the first version if x can be
|
||||||
|
@ -899,25 +878,20 @@ class ImplicitlyConvertible {
|
||||||
// We have to put the 'public' section after the 'private' section,
|
// We have to put the 'public' section after the 'private' section,
|
||||||
// or MSVC refuses to compile the code.
|
// or MSVC refuses to compile the code.
|
||||||
public:
|
public:
|
||||||
// MSVC warns about implicitly converting from double to int for
|
#if defined(__BORLANDC__)
|
||||||
// possible loss of data, so we need to temporarily disable the
|
|
||||||
// warning.
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# pragma warning(push) // Saves the current warning state.
|
|
||||||
# pragma warning(disable:4244) // Temporarily disables warning 4244.
|
|
||||||
|
|
||||||
static const bool value =
|
|
||||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
|
||||||
# pragma warning(pop) // Restores the warning state.
|
|
||||||
#elif defined(__BORLANDC__)
|
|
||||||
// C++Builder cannot use member overload resolution during template
|
// C++Builder cannot use member overload resolution during template
|
||||||
// instantiation. The simplest workaround is to use its C++0x type traits
|
// instantiation. The simplest workaround is to use its C++0x type traits
|
||||||
// functions (C++Builder 2009 and above only).
|
// functions (C++Builder 2009 and above only).
|
||||||
static const bool value = __is_convertible(From, To);
|
static const bool value = __is_convertible(From, To);
|
||||||
#else
|
#else
|
||||||
|
// MSVC warns about implicitly converting from double to int for
|
||||||
|
// possible loss of data, so we need to temporarily disable the
|
||||||
|
// warning.
|
||||||
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244)
|
||||||
static const bool value =
|
static const bool value =
|
||||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
||||||
#endif // _MSV_VER
|
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||||
|
#endif // __BORLANDC__
|
||||||
};
|
};
|
||||||
template <typename From, typename To>
|
template <typename From, typename To>
|
||||||
const bool ImplicitlyConvertible<From, To>::value;
|
const bool ImplicitlyConvertible<From, To>::value;
|
||||||
|
@ -1043,11 +1017,10 @@ void CopyArray(const T* from, size_t size, U* to) {
|
||||||
|
|
||||||
// The relation between an NativeArray object (see below) and the
|
// The relation between an NativeArray object (see below) and the
|
||||||
// native array it represents.
|
// native array it represents.
|
||||||
enum RelationToSource {
|
// We use 2 different structs to allow non-copyable types to be used, as long
|
||||||
kReference, // The NativeArray references the native array.
|
// as RelationToSourceReference() is passed.
|
||||||
kCopy // The NativeArray makes a copy of the native array and
|
struct RelationToSourceReference {};
|
||||||
// owns the copy.
|
struct RelationToSourceCopy {};
|
||||||
};
|
|
||||||
|
|
||||||
// Adapts a native array to a read-only STL-style container. Instead
|
// Adapts a native array to a read-only STL-style container. Instead
|
||||||
// of the complete STL container concept, this adaptor only implements
|
// of the complete STL container concept, this adaptor only implements
|
||||||
|
@ -1065,22 +1038,23 @@ class NativeArray {
|
||||||
typedef Element* iterator;
|
typedef Element* iterator;
|
||||||
typedef const Element* const_iterator;
|
typedef const Element* const_iterator;
|
||||||
|
|
||||||
// Constructs from a native array.
|
// Constructs from a native array. References the source.
|
||||||
NativeArray(const Element* array, size_t count, RelationToSource relation) {
|
NativeArray(const Element* array, size_t count, RelationToSourceReference) {
|
||||||
Init(array, count, relation);
|
InitRef(array, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructs from a native array. Copies the source.
|
||||||
|
NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
|
||||||
|
InitCopy(array, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy constructor.
|
// Copy constructor.
|
||||||
NativeArray(const NativeArray& rhs) {
|
NativeArray(const NativeArray& rhs) {
|
||||||
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
|
(this->*rhs.clone_)(rhs.array_, rhs.size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
~NativeArray() {
|
~NativeArray() {
|
||||||
// Ensures that the user doesn't instantiate NativeArray with a
|
if (clone_ != &NativeArray::InitRef)
|
||||||
// const or reference type.
|
|
||||||
static_cast<void>(StaticAssertTypeEqHelper<Element,
|
|
||||||
GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
|
|
||||||
if (relation_to_source_ == kCopy)
|
|
||||||
delete[] array_;
|
delete[] array_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,23 +1068,30 @@ class NativeArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Initializes this object; makes a copy of the input array if
|
enum {
|
||||||
// 'relation' is kCopy.
|
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
|
||||||
void Init(const Element* array, size_t a_size, RelationToSource relation) {
|
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value,
|
||||||
if (relation == kReference) {
|
};
|
||||||
array_ = array;
|
|
||||||
} else {
|
// Initializes this object with a copy of the input.
|
||||||
Element* const copy = new Element[a_size];
|
void InitCopy(const Element* array, size_t a_size) {
|
||||||
CopyArray(array, a_size, copy);
|
Element* const copy = new Element[a_size];
|
||||||
array_ = copy;
|
CopyArray(array, a_size, copy);
|
||||||
}
|
array_ = copy;
|
||||||
size_ = a_size;
|
size_ = a_size;
|
||||||
relation_to_source_ = relation;
|
clone_ = &NativeArray::InitCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initializes this object with a reference of the input.
|
||||||
|
void InitRef(const Element* array, size_t a_size) {
|
||||||
|
array_ = array;
|
||||||
|
size_ = a_size;
|
||||||
|
clone_ = &NativeArray::InitRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Element* array_;
|
const Element* array_;
|
||||||
size_t size_;
|
size_t size_;
|
||||||
RelationToSource relation_to_source_;
|
void (NativeArray::*clone_)(const Element*, size_t);
|
||||||
|
|
||||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||||
};
|
};
|
||||||
|
@ -1245,6 +1226,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||||
::test_info_ =\
|
::test_info_ =\
|
||||||
::testing::internal::MakeAndRegisterTestInfo(\
|
::testing::internal::MakeAndRegisterTestInfo(\
|
||||||
#test_case_name, #test_name, NULL, NULL, \
|
#test_case_name, #test_name, NULL, NULL, \
|
||||||
|
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||||
(parent_id), \
|
(parent_id), \
|
||||||
parent_class::SetUpTestCase, \
|
parent_class::SetUpTestCase, \
|
||||||
parent_class::TearDownTestCase, \
|
parent_class::TearDownTestCase, \
|
||||||
|
@ -1253,3 +1235,4 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||||
|
|
||||||
|
|
|
@ -105,25 +105,35 @@ class linked_ptr_internal {
|
||||||
// framework.
|
// framework.
|
||||||
|
|
||||||
// Join an existing circle.
|
// Join an existing circle.
|
||||||
// L < g_linked_ptr_mutex
|
void join(linked_ptr_internal const* ptr)
|
||||||
void join(linked_ptr_internal const* ptr) {
|
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
|
||||||
MutexLock lock(&g_linked_ptr_mutex);
|
MutexLock lock(&g_linked_ptr_mutex);
|
||||||
|
|
||||||
linked_ptr_internal const* p = ptr;
|
linked_ptr_internal const* p = ptr;
|
||||||
while (p->next_ != ptr) p = p->next_;
|
while (p->next_ != ptr) {
|
||||||
|
assert(p->next_ != this &&
|
||||||
|
"Trying to join() a linked ring we are already in. "
|
||||||
|
"Is GMock thread safety enabled?");
|
||||||
|
p = p->next_;
|
||||||
|
}
|
||||||
p->next_ = this;
|
p->next_ = this;
|
||||||
next_ = ptr;
|
next_ = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave whatever circle we're part of. Returns true if we were the
|
// Leave whatever circle we're part of. Returns true if we were the
|
||||||
// last member of the circle. Once this is done, you can join() another.
|
// last member of the circle. Once this is done, you can join() another.
|
||||||
// L < g_linked_ptr_mutex
|
bool depart()
|
||||||
bool depart() {
|
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
|
||||||
MutexLock lock(&g_linked_ptr_mutex);
|
MutexLock lock(&g_linked_ptr_mutex);
|
||||||
|
|
||||||
if (next_ == this) return true;
|
if (next_ == this) return true;
|
||||||
linked_ptr_internal const* p = next_;
|
linked_ptr_internal const* p = next_;
|
||||||
while (p->next_ != this) p = p->next_;
|
while (p->next_ != this) {
|
||||||
|
assert(p->next_ != next_ &&
|
||||||
|
"Trying to depart() a linked ring we are not in. "
|
||||||
|
"Is GMock thread safety enabled?");
|
||||||
|
p = p->next_;
|
||||||
|
}
|
||||||
p->next_ = next_;
|
p->next_ = next_;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -34,7 +34,10 @@
|
||||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -49,6 +52,27 @@
|
||||||
#if GTEST_HAS_PARAM_TEST
|
#if GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
|
// Input to a parameterized test name generator, describing a test parameter.
|
||||||
|
// Consists of the parameter value and the integer parameter index.
|
||||||
|
template <class ParamType>
|
||||||
|
struct TestParamInfo {
|
||||||
|
TestParamInfo(const ParamType& a_param, size_t an_index) :
|
||||||
|
param(a_param),
|
||||||
|
index(an_index) {}
|
||||||
|
ParamType param;
|
||||||
|
size_t index;
|
||||||
|
};
|
||||||
|
|
||||||
|
// A builtin parameterized test name generator which returns the result of
|
||||||
|
// testing::PrintToString.
|
||||||
|
struct PrintToStringParamName {
|
||||||
|
template <class ParamType>
|
||||||
|
std::string operator()(const TestParamInfo<ParamType>& info) const {
|
||||||
|
return PrintToString(info.param);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
|
@ -58,7 +82,7 @@ namespace internal {
|
||||||
// TEST_P macro is used to define two tests with the same name
|
// TEST_P macro is used to define two tests with the same name
|
||||||
// but in different namespaces.
|
// but in different namespaces.
|
||||||
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
||||||
const char* file, int line);
|
CodeLocation code_location);
|
||||||
|
|
||||||
template <typename> class ParamGeneratorInterface;
|
template <typename> class ParamGeneratorInterface;
|
||||||
template <typename> class ParamGenerator;
|
template <typename> class ParamGenerator;
|
||||||
|
@ -206,7 +230,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
return base_;
|
return base_;
|
||||||
}
|
}
|
||||||
virtual void Advance() {
|
virtual void Advance() {
|
||||||
value_ = value_ + step_;
|
value_ = static_cast<T>(value_ + step_);
|
||||||
index_++;
|
index_++;
|
||||||
}
|
}
|
||||||
virtual ParamIteratorInterface<T>* Clone() const {
|
virtual ParamIteratorInterface<T>* Clone() const {
|
||||||
|
@ -243,7 +267,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
const T& end,
|
const T& end,
|
||||||
const IncrementT& step) {
|
const IncrementT& step) {
|
||||||
int end_index = 0;
|
int end_index = 0;
|
||||||
for (T i = begin; i < end; i = i + step)
|
for (T i = begin; i < end; i = static_cast<T>(i + step))
|
||||||
end_index++;
|
end_index++;
|
||||||
return end_index;
|
return end_index;
|
||||||
}
|
}
|
||||||
|
@ -270,12 +294,12 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
template <typename ForwardIterator>
|
template <typename ForwardIterator>
|
||||||
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
|
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
|
||||||
: container_(begin, end) {}
|
: container_(begin, end) {}
|
||||||
~ValuesInIteratorRangeGenerator() override {}
|
virtual ~ValuesInIteratorRangeGenerator() {}
|
||||||
|
|
||||||
ParamIteratorInterface<T> *Begin() const override {
|
virtual ParamIteratorInterface<T>* Begin() const {
|
||||||
return new Iterator(this, container_.begin());
|
return new Iterator(this, container_.begin());
|
||||||
}
|
}
|
||||||
ParamIteratorInterface<T> *End() const override {
|
virtual ParamIteratorInterface<T>* End() const {
|
||||||
return new Iterator(this, container_.end());
|
return new Iterator(this, container_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,16 +311,16 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
Iterator(const ParamGeneratorInterface<T>* base,
|
Iterator(const ParamGeneratorInterface<T>* base,
|
||||||
typename ContainerType::const_iterator iterator)
|
typename ContainerType::const_iterator iterator)
|
||||||
: base_(base), iterator_(iterator) {}
|
: base_(base), iterator_(iterator) {}
|
||||||
~Iterator() override {}
|
virtual ~Iterator() {}
|
||||||
|
|
||||||
const ParamGeneratorInterface<T> *BaseGenerator() const override {
|
virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
|
||||||
return base_;
|
return base_;
|
||||||
}
|
}
|
||||||
void Advance() override {
|
virtual void Advance() {
|
||||||
++iterator_;
|
++iterator_;
|
||||||
value_.reset();
|
value_.reset();
|
||||||
}
|
}
|
||||||
ParamIteratorInterface<T> *Clone() const override {
|
virtual ParamIteratorInterface<T>* Clone() const {
|
||||||
return new Iterator(*this);
|
return new Iterator(*this);
|
||||||
}
|
}
|
||||||
// We need to use cached value referenced by iterator_ because *iterator_
|
// We need to use cached value referenced by iterator_ because *iterator_
|
||||||
|
@ -306,12 +330,12 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
// can advance iterator_ beyond the end of the range, and we cannot
|
// can advance iterator_ beyond the end of the range, and we cannot
|
||||||
// detect that fact. The client code, on the other hand, is
|
// detect that fact. The client code, on the other hand, is
|
||||||
// responsible for not calling Current() on an out-of-range iterator.
|
// responsible for not calling Current() on an out-of-range iterator.
|
||||||
const T *Current() const override {
|
virtual const T* Current() const {
|
||||||
if (value_.get() == NULL)
|
if (value_.get() == NULL)
|
||||||
value_.reset(new T(*iterator_));
|
value_.reset(new T(*iterator_));
|
||||||
return value_.get();
|
return value_.get();
|
||||||
}
|
}
|
||||||
bool Equals(const ParamIteratorInterface<T> &other) const override {
|
virtual bool Equals(const ParamIteratorInterface<T>& other) const {
|
||||||
// Having the same base generator guarantees that the other
|
// Having the same base generator guarantees that the other
|
||||||
// iterator is of the same type and we can downcast.
|
// iterator is of the same type and we can downcast.
|
||||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||||
|
@ -345,6 +369,37 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||||
const ContainerType container_;
|
const ContainerType container_;
|
||||||
}; // class ValuesInIteratorRangeGenerator
|
}; // class ValuesInIteratorRangeGenerator
|
||||||
|
|
||||||
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
|
//
|
||||||
|
// Default parameterized test name generator, returns a string containing the
|
||||||
|
// integer test parameter index.
|
||||||
|
template <class ParamType>
|
||||||
|
std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
|
||||||
|
Message name_stream;
|
||||||
|
name_stream << info.index;
|
||||||
|
return name_stream.GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
|
//
|
||||||
|
// Parameterized test name overload helpers, which help the
|
||||||
|
// INSTANTIATE_TEST_CASE_P macro choose between the default parameterized
|
||||||
|
// test name generator and user param name generator.
|
||||||
|
template <class ParamType, class ParamNameGenFunctor>
|
||||||
|
ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) {
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParamType>
|
||||||
|
struct ParamNameGenFunc {
|
||||||
|
typedef std::string Type(const TestParamInfo<ParamType>&);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class ParamType>
|
||||||
|
typename ParamNameGenFunc<ParamType>::Type *GetParamNameGen() {
|
||||||
|
return DefaultParamName;
|
||||||
|
}
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Stores a parameter value and later creates tests parameterized with that
|
// Stores a parameter value and later creates tests parameterized with that
|
||||||
|
@ -355,7 +410,7 @@ class ParameterizedTestFactory : public TestFactoryBase {
|
||||||
typedef typename TestClass::ParamType ParamType;
|
typedef typename TestClass::ParamType ParamType;
|
||||||
explicit ParameterizedTestFactory(ParamType parameter) :
|
explicit ParameterizedTestFactory(ParamType parameter) :
|
||||||
parameter_(parameter) {}
|
parameter_(parameter) {}
|
||||||
Test *CreateTest() override {
|
virtual Test* CreateTest() {
|
||||||
TestClass::SetParam(¶meter_);
|
TestClass::SetParam(¶meter_);
|
||||||
return new TestClass();
|
return new TestClass();
|
||||||
}
|
}
|
||||||
|
@ -394,7 +449,7 @@ class TestMetaFactory
|
||||||
|
|
||||||
TestMetaFactory() {}
|
TestMetaFactory() {}
|
||||||
|
|
||||||
TestFactoryBase *CreateTestFactory(ParamType parameter) override {
|
virtual TestFactoryBase* CreateTestFactory(ParamType parameter) {
|
||||||
return new ParameterizedTestFactory<TestCase>(parameter);
|
return new ParameterizedTestFactory<TestCase>(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +469,7 @@ class TestMetaFactory
|
||||||
// and calls RegisterTests() on each of them when asked.
|
// and calls RegisterTests() on each of them when asked.
|
||||||
class ParameterizedTestCaseInfoBase {
|
class ParameterizedTestCaseInfoBase {
|
||||||
public:
|
public:
|
||||||
virtual ~ParameterizedTestCaseInfoBase();
|
virtual ~ParameterizedTestCaseInfoBase() {}
|
||||||
|
|
||||||
// Base part of test case name for display purposes.
|
// Base part of test case name for display purposes.
|
||||||
virtual const string& GetTestCaseName() const = 0;
|
virtual const string& GetTestCaseName() const = 0;
|
||||||
|
@ -449,14 +504,16 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||||
typedef typename TestCase::ParamType ParamType;
|
typedef typename TestCase::ParamType ParamType;
|
||||||
// A function that returns an instance of appropriate generator type.
|
// A function that returns an instance of appropriate generator type.
|
||||||
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
||||||
|
typedef typename ParamNameGenFunc<ParamType>::Type ParamNameGeneratorFunc;
|
||||||
|
|
||||||
explicit ParameterizedTestCaseInfo(const char* name)
|
explicit ParameterizedTestCaseInfo(
|
||||||
: test_case_name_(name) {}
|
const char* name, CodeLocation code_location)
|
||||||
|
: test_case_name_(name), code_location_(code_location) {}
|
||||||
|
|
||||||
// Test case base name for display purposes.
|
// Test case base name for display purposes.
|
||||||
const string &GetTestCaseName() const override { return test_case_name_; }
|
virtual const string& GetTestCaseName() const { return test_case_name_; }
|
||||||
// Test case id to verify identity.
|
// Test case id to verify identity.
|
||||||
TypeId GetTestCaseTypeId() const override { return GetTypeId<TestCase>(); }
|
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
|
||||||
// TEST_P macro uses AddTestPattern() to record information
|
// TEST_P macro uses AddTestPattern() to record information
|
||||||
// about a single test in a LocalTestInfo structure.
|
// about a single test in a LocalTestInfo structure.
|
||||||
// test_case_name is the base name of the test case (without invocation
|
// test_case_name is the base name of the test case (without invocation
|
||||||
|
@ -474,9 +531,11 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||||
// about a generator.
|
// about a generator.
|
||||||
int AddTestCaseInstantiation(const string& instantiation_name,
|
int AddTestCaseInstantiation(const string& instantiation_name,
|
||||||
GeneratorCreationFunc* func,
|
GeneratorCreationFunc* func,
|
||||||
const char* /* file */,
|
ParamNameGeneratorFunc* name_func,
|
||||||
int /* line */) {
|
const char* file,
|
||||||
instantiations_.push_back(::std::make_pair(instantiation_name, func));
|
int line) {
|
||||||
|
instantiations_.push_back(
|
||||||
|
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
||||||
return 0; // Return value used only to run this method in namespace scope.
|
return 0; // Return value used only to run this method in namespace scope.
|
||||||
}
|
}
|
||||||
// UnitTest class invokes this method to register tests in this test case
|
// UnitTest class invokes this method to register tests in this test case
|
||||||
|
@ -484,32 +543,52 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||||
// This method should not be called more then once on any single
|
// This method should not be called more then once on any single
|
||||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
// instance of a ParameterizedTestCaseInfoBase derived class.
|
||||||
// UnitTest has a guard to prevent from calling this method more then once.
|
// UnitTest has a guard to prevent from calling this method more then once.
|
||||||
void RegisterTests() override {
|
virtual void RegisterTests() {
|
||||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||||
test_it != tests_.end(); ++test_it) {
|
test_it != tests_.end(); ++test_it) {
|
||||||
linked_ptr<TestInfo> test_info = *test_it;
|
linked_ptr<TestInfo> test_info = *test_it;
|
||||||
for (typename InstantiationContainer::iterator gen_it =
|
for (typename InstantiationContainer::iterator gen_it =
|
||||||
instantiations_.begin(); gen_it != instantiations_.end();
|
instantiations_.begin(); gen_it != instantiations_.end();
|
||||||
++gen_it) {
|
++gen_it) {
|
||||||
const string& instantiation_name = gen_it->first;
|
const string& instantiation_name = gen_it->name;
|
||||||
ParamGenerator<ParamType> generator((*gen_it->second)());
|
ParamGenerator<ParamType> generator((*gen_it->generator)());
|
||||||
|
ParamNameGeneratorFunc* name_func = gen_it->name_func;
|
||||||
|
const char* file = gen_it->file;
|
||||||
|
int line = gen_it->line;
|
||||||
|
|
||||||
Message test_case_name_stream;
|
string test_case_name;
|
||||||
if ( !instantiation_name.empty() )
|
if ( !instantiation_name.empty() )
|
||||||
test_case_name_stream << instantiation_name << "/";
|
test_case_name = instantiation_name + "/";
|
||||||
test_case_name_stream << test_info->test_case_base_name;
|
test_case_name += test_info->test_case_base_name;
|
||||||
|
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
|
std::set<std::string> test_param_names;
|
||||||
for (typename ParamGenerator<ParamType>::iterator param_it =
|
for (typename ParamGenerator<ParamType>::iterator param_it =
|
||||||
generator.begin();
|
generator.begin();
|
||||||
param_it != generator.end(); ++param_it, ++i) {
|
param_it != generator.end(); ++param_it, ++i) {
|
||||||
Message test_name_stream;
|
Message test_name_stream;
|
||||||
test_name_stream << test_info->test_base_name << "/" << i;
|
|
||||||
|
std::string param_name = name_func(
|
||||||
|
TestParamInfo<ParamType>(*param_it, i));
|
||||||
|
|
||||||
|
GTEST_CHECK_(IsValidParamName(param_name))
|
||||||
|
<< "Parameterized test name '" << param_name
|
||||||
|
<< "' is invalid, in " << file
|
||||||
|
<< " line " << line << std::endl;
|
||||||
|
|
||||||
|
GTEST_CHECK_(test_param_names.count(param_name) == 0)
|
||||||
|
<< "Duplicate parameterized test name '" << param_name
|
||||||
|
<< "', in " << file << " line " << line << std::endl;
|
||||||
|
|
||||||
|
test_param_names.insert(param_name);
|
||||||
|
|
||||||
|
test_name_stream << test_info->test_base_name << "/" << param_name;
|
||||||
MakeAndRegisterTestInfo(
|
MakeAndRegisterTestInfo(
|
||||||
test_case_name_stream.GetString().c_str(),
|
test_case_name.c_str(),
|
||||||
test_name_stream.GetString().c_str(),
|
test_name_stream.GetString().c_str(),
|
||||||
NULL, // No type parameter.
|
NULL, // No type parameter.
|
||||||
PrintToString(*param_it).c_str(),
|
PrintToString(*param_it).c_str(),
|
||||||
|
code_location_,
|
||||||
GetTestCaseTypeId(),
|
GetTestCaseTypeId(),
|
||||||
TestCase::SetUpTestCase,
|
TestCase::SetUpTestCase,
|
||||||
TestCase::TearDownTestCase,
|
TestCase::TearDownTestCase,
|
||||||
|
@ -535,12 +614,45 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||||
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||||
};
|
};
|
||||||
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
|
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
|
||||||
// Keeps pairs of <Instantiation name, Sequence generator creation function>
|
// Records data received from INSTANTIATE_TEST_CASE_P macros:
|
||||||
// received from INSTANTIATE_TEST_CASE_P macros.
|
// <Instantiation name, Sequence generator creation function,
|
||||||
typedef ::std::vector<std::pair<string, GeneratorCreationFunc*> >
|
// Name generator function, Source file, Source line>
|
||||||
InstantiationContainer;
|
struct InstantiationInfo {
|
||||||
|
InstantiationInfo(const std::string &name_in,
|
||||||
|
GeneratorCreationFunc* generator_in,
|
||||||
|
ParamNameGeneratorFunc* name_func_in,
|
||||||
|
const char* file_in,
|
||||||
|
int line_in)
|
||||||
|
: name(name_in),
|
||||||
|
generator(generator_in),
|
||||||
|
name_func(name_func_in),
|
||||||
|
file(file_in),
|
||||||
|
line(line_in) {}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
GeneratorCreationFunc* generator;
|
||||||
|
ParamNameGeneratorFunc* name_func;
|
||||||
|
const char* file;
|
||||||
|
int line;
|
||||||
|
};
|
||||||
|
typedef ::std::vector<InstantiationInfo> InstantiationContainer;
|
||||||
|
|
||||||
|
static bool IsValidParamName(const std::string& name) {
|
||||||
|
// Check for empty string
|
||||||
|
if (name.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check for invalid characters
|
||||||
|
for (std::string::size_type index = 0; index < name.size(); ++index) {
|
||||||
|
if (!isalnum(name[index]) && name[index] != '_')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const string test_case_name_;
|
const string test_case_name_;
|
||||||
|
CodeLocation code_location_;
|
||||||
TestInfoContainer tests_;
|
TestInfoContainer tests_;
|
||||||
InstantiationContainer instantiations_;
|
InstantiationContainer instantiations_;
|
||||||
|
|
||||||
|
@ -568,8 +680,7 @@ class ParameterizedTestCaseRegistry {
|
||||||
template <class TestCase>
|
template <class TestCase>
|
||||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
||||||
const char* test_case_name,
|
const char* test_case_name,
|
||||||
const char* file,
|
CodeLocation code_location) {
|
||||||
int line) {
|
|
||||||
ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;
|
ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;
|
||||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
||||||
it != test_case_infos_.end(); ++it) {
|
it != test_case_infos_.end(); ++it) {
|
||||||
|
@ -578,7 +689,7 @@ class ParameterizedTestCaseRegistry {
|
||||||
// Complain about incorrect usage of Google Test facilities
|
// Complain about incorrect usage of Google Test facilities
|
||||||
// and terminate the program since we cannot guaranty correct
|
// and terminate the program since we cannot guaranty correct
|
||||||
// test case setup and tear-down in this case.
|
// test case setup and tear-down in this case.
|
||||||
ReportInvalidTestCaseType(test_case_name, file, line);
|
ReportInvalidTestCaseType(test_case_name, code_location);
|
||||||
posix::Abort();
|
posix::Abort();
|
||||||
} else {
|
} else {
|
||||||
// At this point we are sure that the object we found is of the same
|
// At this point we are sure that the object we found is of the same
|
||||||
|
@ -591,7 +702,8 @@ class ParameterizedTestCaseRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typed_test_info == NULL) {
|
if (typed_test_info == NULL) {
|
||||||
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(test_case_name);
|
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(
|
||||||
|
test_case_name, code_location);
|
||||||
test_case_infos_.push_back(typed_test_info);
|
test_case_infos_.push_back(typed_test_info);
|
||||||
}
|
}
|
||||||
return typed_test_info;
|
return typed_test_info;
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
// Copyright 2015, 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.
|
||||||
|
//
|
||||||
|
// The Google C++ Testing Framework (Google Test)
|
||||||
|
//
|
||||||
|
// This header file defines the GTEST_OS_* macro.
|
||||||
|
// It is separate from gtest-port.h so that custom/gtest-port.h can include it.
|
||||||
|
|
||||||
|
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||||
|
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||||
|
|
||||||
|
// Determines the platform on which Google Test is compiled.
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
# define GTEST_OS_CYGWIN 1
|
||||||
|
#elif defined __SYMBIAN32__
|
||||||
|
# define GTEST_OS_SYMBIAN 1
|
||||||
|
#elif defined _WIN32
|
||||||
|
# define GTEST_OS_WINDOWS 1
|
||||||
|
# ifdef _WIN32_WCE
|
||||||
|
# define GTEST_OS_WINDOWS_MOBILE 1
|
||||||
|
# elif defined(__MINGW__) || defined(__MINGW32__)
|
||||||
|
# define GTEST_OS_WINDOWS_MINGW 1
|
||||||
|
# elif defined(WINAPI_FAMILY)
|
||||||
|
# include <winapifamily.h>
|
||||||
|
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||||
|
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||||
|
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
|
||||||
|
# define GTEST_OS_WINDOWS_PHONE 1
|
||||||
|
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||||
|
# define GTEST_OS_WINDOWS_RT 1
|
||||||
|
# else
|
||||||
|
// WINAPI_FAMILY defined but no known partition matched.
|
||||||
|
// Default to desktop.
|
||||||
|
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||||
|
# endif // _WIN32_WCE
|
||||||
|
#elif defined __APPLE__
|
||||||
|
# define GTEST_OS_MAC 1
|
||||||
|
# if TARGET_OS_IPHONE
|
||||||
|
# define GTEST_OS_IOS 1
|
||||||
|
# endif
|
||||||
|
#elif defined __FreeBSD__
|
||||||
|
# define GTEST_OS_FREEBSD 1
|
||||||
|
#elif defined __linux__
|
||||||
|
# define GTEST_OS_LINUX 1
|
||||||
|
# if defined __ANDROID__
|
||||||
|
# define GTEST_OS_LINUX_ANDROID 1
|
||||||
|
# endif
|
||||||
|
#elif defined __MVS__
|
||||||
|
# define GTEST_OS_ZOS 1
|
||||||
|
#elif defined(__sun) && defined(__SVR4)
|
||||||
|
# define GTEST_OS_SOLARIS 1
|
||||||
|
#elif defined(_AIX)
|
||||||
|
# define GTEST_OS_AIX 1
|
||||||
|
#elif defined(__hpux)
|
||||||
|
# define GTEST_OS_HPUX 1
|
||||||
|
#elif defined __native_client__
|
||||||
|
# define GTEST_OS_NACL 1
|
||||||
|
#elif defined __OpenBSD__
|
||||||
|
# define GTEST_OS_OPENBSD 1
|
||||||
|
#elif defined __QNX__
|
||||||
|
# define GTEST_OS_QNX 1
|
||||||
|
#elif defined(__HAIKU__)
|
||||||
|
# define GTEST_OS_HAIKU 1
|
||||||
|
#elif defined(_MINIX)
|
||||||
|
# define GTEST_OS_MINIX 1
|
||||||
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
File diff suppressed because it is too large
Load Diff
|
@ -47,50 +47,18 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "gtest/internal/gtest-port.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// String - a UTF-8 string class.
|
// String - an abstract class holding static string utilities.
|
||||||
//
|
|
||||||
// For historic reasons, we don't use std::string.
|
|
||||||
//
|
|
||||||
// TODO(wan@google.com): replace this class with std::string or
|
|
||||||
// implement it in terms of the latter.
|
|
||||||
//
|
|
||||||
// Note that String can represent both NULL and the empty string,
|
|
||||||
// while std::string cannot represent NULL.
|
|
||||||
//
|
|
||||||
// NULL and the empty string are considered different. NULL is less
|
|
||||||
// than anything (including the empty string) except itself.
|
|
||||||
//
|
|
||||||
// This class only provides minimum functionality necessary for
|
|
||||||
// implementing Google Test. We do not intend to implement a full-fledged
|
|
||||||
// string class here.
|
|
||||||
//
|
|
||||||
// Since the purpose of this class is to provide a substitute for
|
|
||||||
// std::string on platforms where it cannot be used, we define a copy
|
|
||||||
// constructor and assignment operators such that we don't need
|
|
||||||
// conditional compilation in a lot of places.
|
|
||||||
//
|
|
||||||
// In order to make the representation efficient, the d'tor of String
|
|
||||||
// is not virtual. Therefore DO NOT INHERIT FROM String.
|
|
||||||
class GTEST_API_ String {
|
class GTEST_API_ String {
|
||||||
public:
|
public:
|
||||||
// Static utility methods
|
// Static utility methods
|
||||||
|
|
||||||
// Returns the input enclosed in double quotes if it's not NULL;
|
|
||||||
// otherwise returns "(null)". For example, "\"Hello\"" is returned
|
|
||||||
// for input "Hello".
|
|
||||||
//
|
|
||||||
// This is useful for printing a C string in the syntax of a literal.
|
|
||||||
//
|
|
||||||
// Known issue: escape sequences are not handled yet.
|
|
||||||
static String ShowCStringQuoted(const char* c_str);
|
|
||||||
|
|
||||||
// Clones a 0-terminated C string, allocating memory using new. The
|
// Clones a 0-terminated C string, allocating memory using new. The
|
||||||
// caller is responsible for deleting the return value using
|
// caller is responsible for deleting the return value using
|
||||||
// delete[]. Returns the cloned string, or NULL if the input is
|
// delete[]. Returns the cloned string, or NULL if the input is
|
||||||
|
@ -137,11 +105,7 @@ class GTEST_API_ String {
|
||||||
// NULL will be converted to "(null)". If an error occurred during
|
// NULL will be converted to "(null)". If an error occurred during
|
||||||
// the conversion, "(failed to convert from wide string)" is
|
// the conversion, "(failed to convert from wide string)" is
|
||||||
// returned.
|
// returned.
|
||||||
static String ShowWideCString(const wchar_t* wide_c_str);
|
static std::string ShowWideCString(const wchar_t* wide_c_str);
|
||||||
|
|
||||||
// Similar to ShowWideCString(), except that this function encloses
|
|
||||||
// the converted string in double quotes.
|
|
||||||
static String ShowWideCStringQuoted(const wchar_t* wide_c_str);
|
|
||||||
|
|
||||||
// Compares two wide C strings. Returns true iff they have the same
|
// Compares two wide C strings. Returns true iff they have the same
|
||||||
// content.
|
// content.
|
||||||
|
@ -175,174 +139,27 @@ class GTEST_API_ String {
|
||||||
static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
|
static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
|
||||||
const wchar_t* rhs);
|
const wchar_t* rhs);
|
||||||
|
|
||||||
// Formats a list of arguments to a String, using the same format
|
// Returns true iff the given string ends with the given suffix, ignoring
|
||||||
// spec string as for printf.
|
// case. Any string is considered to end with an empty suffix.
|
||||||
//
|
static bool EndsWithCaseInsensitive(
|
||||||
// We do not use the StringPrintf class as it is not universally
|
const std::string& str, const std::string& suffix);
|
||||||
// available.
|
|
||||||
//
|
|
||||||
// The result is limited to 4096 characters (including the tailing
|
|
||||||
// 0). If 4096 characters are not enough to format the input,
|
|
||||||
// "<buffer exceeded>" is returned.
|
|
||||||
static String Format(const char* format, ...);
|
|
||||||
|
|
||||||
// C'tors
|
// Formats an int value as "%02d".
|
||||||
|
static std::string FormatIntWidth2(int value); // "%02d" for width == 2
|
||||||
|
|
||||||
// The default c'tor constructs a NULL string.
|
// Formats an int value as "%X".
|
||||||
String() : c_str_(NULL), length_(0) {}
|
static std::string FormatHexInt(int value);
|
||||||
|
|
||||||
// Constructs a String by cloning a 0-terminated C string.
|
// Formats a byte as "%02X".
|
||||||
String(const char* a_c_str) { // NOLINT
|
static std::string FormatByte(unsigned char value);
|
||||||
if (a_c_str == NULL) {
|
|
||||||
c_str_ = NULL;
|
|
||||||
length_ = 0;
|
|
||||||
} else {
|
|
||||||
ConstructNonNull(a_c_str, strlen(a_c_str));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructs a String by copying a given number of chars from a
|
|
||||||
// buffer. E.g. String("hello", 3) creates the string "hel",
|
|
||||||
// String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
|
|
||||||
// and String(NULL, 1) results in access violation.
|
|
||||||
String(const char* buffer, size_t a_length) {
|
|
||||||
ConstructNonNull(buffer, a_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The copy c'tor creates a new copy of the string. The two
|
|
||||||
// String objects do not share content.
|
|
||||||
String(const String& str) : c_str_(NULL), length_(0) { *this = str; }
|
|
||||||
|
|
||||||
// D'tor. String is intended to be a final class, so the d'tor
|
|
||||||
// doesn't need to be virtual.
|
|
||||||
~String() { delete[] c_str_; }
|
|
||||||
|
|
||||||
// Allows a String to be implicitly converted to an ::std::string or
|
|
||||||
// ::string, and vice versa. Converting a String containing a NULL
|
|
||||||
// pointer to ::std::string or ::string is undefined behavior.
|
|
||||||
// Converting a ::std::string or ::string containing an embedded NUL
|
|
||||||
// character to a String will result in the prefix up to the first
|
|
||||||
// NUL character.
|
|
||||||
String(const ::std::string& str) {
|
|
||||||
ConstructNonNull(str.c_str(), str.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
operator ::std::string() const { return ::std::string(c_str(), length()); }
|
|
||||||
|
|
||||||
#if GTEST_HAS_GLOBAL_STRING
|
|
||||||
String(const ::string& str) {
|
|
||||||
ConstructNonNull(str.c_str(), str.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
operator ::string() const { return ::string(c_str(), length()); }
|
|
||||||
#endif // GTEST_HAS_GLOBAL_STRING
|
|
||||||
|
|
||||||
// Returns true iff this is an empty string (i.e. "").
|
|
||||||
bool empty() const { return (c_str() != NULL) && (length() == 0); }
|
|
||||||
|
|
||||||
// Compares this with another String.
|
|
||||||
// Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0
|
|
||||||
// if this is greater than rhs.
|
|
||||||
int Compare(const String& rhs) const;
|
|
||||||
|
|
||||||
// Returns true iff this String equals the given C string. A NULL
|
|
||||||
// string and a non-NULL string are considered not equal.
|
|
||||||
bool operator==(const char* a_c_str) const { return Compare(a_c_str) == 0; }
|
|
||||||
|
|
||||||
// Returns true iff this String is less than the given String. A
|
|
||||||
// NULL string is considered less than "".
|
|
||||||
bool operator<(const String& rhs) const { return Compare(rhs) < 0; }
|
|
||||||
|
|
||||||
// Returns true iff this String doesn't equal the given C string. A NULL
|
|
||||||
// string and a non-NULL string are considered not equal.
|
|
||||||
bool operator!=(const char* a_c_str) const { return !(*this == a_c_str); }
|
|
||||||
|
|
||||||
// Returns true iff this String ends with the given suffix. *Any*
|
|
||||||
// String is considered to end with a NULL or empty suffix.
|
|
||||||
bool EndsWith(const char* suffix) const;
|
|
||||||
|
|
||||||
// Returns true iff this String ends with the given suffix, not considering
|
|
||||||
// case. Any String is considered to end with a NULL or empty suffix.
|
|
||||||
bool EndsWithCaseInsensitive(const char* suffix) const;
|
|
||||||
|
|
||||||
// Returns the length of the encapsulated string, or 0 if the
|
|
||||||
// string is NULL.
|
|
||||||
size_t length() const { return length_; }
|
|
||||||
|
|
||||||
// Gets the 0-terminated C string this String object represents.
|
|
||||||
// The String object still owns the string. Therefore the caller
|
|
||||||
// should NOT delete the return value.
|
|
||||||
const char* c_str() const { return c_str_; }
|
|
||||||
|
|
||||||
// Assigns a C string to this object. Self-assignment works.
|
|
||||||
const String& operator=(const char* a_c_str) {
|
|
||||||
return *this = String(a_c_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assigns a String object to this object. Self-assignment works.
|
|
||||||
const String& operator=(const String& rhs) {
|
|
||||||
if (this != &rhs) {
|
|
||||||
delete[] c_str_;
|
|
||||||
if (rhs.c_str() == NULL) {
|
|
||||||
c_str_ = NULL;
|
|
||||||
length_ = 0;
|
|
||||||
} else {
|
|
||||||
ConstructNonNull(rhs.c_str(), rhs.length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Constructs a non-NULL String from the given content. This
|
String(); // Not meant to be instantiated.
|
||||||
// function can only be called when c_str_ has not been allocated.
|
|
||||||
// ConstructNonNull(NULL, 0) results in an empty string ("").
|
|
||||||
// ConstructNonNull(NULL, non_zero) is undefined behavior.
|
|
||||||
void ConstructNonNull(const char* buffer, size_t a_length) {
|
|
||||||
char* const str = new char[a_length + 1];
|
|
||||||
memcpy(str, buffer, a_length);
|
|
||||||
str[a_length] = '\0';
|
|
||||||
c_str_ = str;
|
|
||||||
length_ = a_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* c_str_;
|
|
||||||
size_t length_;
|
|
||||||
}; // class String
|
}; // class String
|
||||||
|
|
||||||
// Streams a String to an ostream. Each '\0' character in the String
|
// Gets the content of the stringstream's buffer as an std::string. Each '\0'
|
||||||
// is replaced with "\\0".
|
|
||||||
inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
|
|
||||||
if (str.c_str() == NULL) {
|
|
||||||
os << "(null)";
|
|
||||||
} else {
|
|
||||||
const char* const c_str = str.c_str();
|
|
||||||
for (size_t i = 0; i != str.length(); i++) {
|
|
||||||
if (c_str[i] == '\0') {
|
|
||||||
os << "\\0";
|
|
||||||
} else {
|
|
||||||
os << c_str[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the content of the stringstream's buffer as a String. Each '\0'
|
|
||||||
// character in the buffer is replaced with "\\0".
|
// character in the buffer is replaced with "\\0".
|
||||||
GTEST_API_ String StringStreamToString(::std::stringstream* stream);
|
GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
|
// This file was GENERATED by command:
|
||||||
|
// pump.py gtest-tuple.h.pump
|
||||||
|
// DO NOT EDIT BY HAND!!!
|
||||||
|
|
||||||
// Copyright 2009 Google Inc.
|
// Copyright 2009 Google Inc.
|
||||||
// All Rights Reserved.
|
// All Rights Reserved.
|
||||||
|
@ -51,6 +53,14 @@
|
||||||
private:
|
private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
|
||||||
|
// with our own definitions. Therefore using our own tuple does not work on
|
||||||
|
// those compilers.
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */
|
||||||
|
# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \
|
||||||
|
GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers."
|
||||||
|
#endif
|
||||||
|
|
||||||
// GTEST_n_TUPLE_(T) is the type of an n-tuple.
|
// GTEST_n_TUPLE_(T) is the type of an n-tuple.
|
||||||
#define GTEST_0_TUPLE_(T) tuple<>
|
#define GTEST_0_TUPLE_(T) tuple<>
|
||||||
#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
|
#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
|
||||||
|
@ -140,34 +150,54 @@ template <bool kIndexValid, int kIndex, class Tuple>
|
||||||
struct TupleElement;
|
struct TupleElement;
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 0, GTEST_10_TUPLE_(T)> { typedef T0 type; };
|
struct TupleElement<true, 0, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T0 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 1, GTEST_10_TUPLE_(T)> { typedef T1 type; };
|
struct TupleElement<true, 1, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T1 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 2, GTEST_10_TUPLE_(T)> { typedef T2 type; };
|
struct TupleElement<true, 2, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T2 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 3, GTEST_10_TUPLE_(T)> { typedef T3 type; };
|
struct TupleElement<true, 3, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T3 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 4, GTEST_10_TUPLE_(T)> { typedef T4 type; };
|
struct TupleElement<true, 4, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T4 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 5, GTEST_10_TUPLE_(T)> { typedef T5 type; };
|
struct TupleElement<true, 5, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T5 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 6, GTEST_10_TUPLE_(T)> { typedef T6 type; };
|
struct TupleElement<true, 6, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T6 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 7, GTEST_10_TUPLE_(T)> { typedef T7 type; };
|
struct TupleElement<true, 7, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T7 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 8, GTEST_10_TUPLE_(T)> { typedef T8 type; };
|
struct TupleElement<true, 8, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T8 type;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct TupleElement<true, 9, GTEST_10_TUPLE_(T)> { typedef T9 type; };
|
struct TupleElement<true, 9, GTEST_10_TUPLE_(T) > {
|
||||||
|
typedef T9 type;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace gtest_internal
|
} // namespace gtest_internal
|
||||||
|
|
||||||
|
@ -708,37 +738,59 @@ inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
|
||||||
template <typename Tuple> struct tuple_size;
|
template <typename Tuple> struct tuple_size;
|
||||||
|
|
||||||
template <GTEST_0_TYPENAMES_(T)>
|
template <GTEST_0_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_0_TUPLE_(T)> { static const int value = 0; };
|
struct tuple_size<GTEST_0_TUPLE_(T) > {
|
||||||
|
static const int value = 0;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_1_TYPENAMES_(T)>
|
template <GTEST_1_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_1_TUPLE_(T)> { static const int value = 1; };
|
struct tuple_size<GTEST_1_TUPLE_(T) > {
|
||||||
|
static const int value = 1;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_2_TYPENAMES_(T)>
|
template <GTEST_2_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_2_TUPLE_(T)> { static const int value = 2; };
|
struct tuple_size<GTEST_2_TUPLE_(T) > {
|
||||||
|
static const int value = 2;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_3_TYPENAMES_(T)>
|
template <GTEST_3_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_3_TUPLE_(T)> { static const int value = 3; };
|
struct tuple_size<GTEST_3_TUPLE_(T) > {
|
||||||
|
static const int value = 3;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_4_TYPENAMES_(T)>
|
template <GTEST_4_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_4_TUPLE_(T)> { static const int value = 4; };
|
struct tuple_size<GTEST_4_TUPLE_(T) > {
|
||||||
|
static const int value = 4;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_5_TYPENAMES_(T)>
|
template <GTEST_5_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_5_TUPLE_(T)> { static const int value = 5; };
|
struct tuple_size<GTEST_5_TUPLE_(T) > {
|
||||||
|
static const int value = 5;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_6_TYPENAMES_(T)>
|
template <GTEST_6_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_6_TUPLE_(T)> { static const int value = 6; };
|
struct tuple_size<GTEST_6_TUPLE_(T) > {
|
||||||
|
static const int value = 6;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_7_TYPENAMES_(T)>
|
template <GTEST_7_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_7_TUPLE_(T)> { static const int value = 7; };
|
struct tuple_size<GTEST_7_TUPLE_(T) > {
|
||||||
|
static const int value = 7;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_8_TYPENAMES_(T)>
|
template <GTEST_8_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_8_TUPLE_(T)> { static const int value = 8; };
|
struct tuple_size<GTEST_8_TUPLE_(T) > {
|
||||||
|
static const int value = 8;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_9_TYPENAMES_(T)>
|
template <GTEST_9_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_9_TUPLE_(T)> { static const int value = 9; };
|
struct tuple_size<GTEST_9_TUPLE_(T) > {
|
||||||
|
static const int value = 9;
|
||||||
|
};
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T)>
|
template <GTEST_10_TYPENAMES_(T)>
|
||||||
struct tuple_size<GTEST_10_TUPLE_(T)> { static const int value = 10; };
|
struct tuple_size<GTEST_10_TUPLE_(T) > {
|
||||||
|
static const int value = 10;
|
||||||
|
};
|
||||||
|
|
||||||
template <int k, class Tuple>
|
template <int k, class Tuple>
|
||||||
struct tuple_element {
|
struct tuple_element {
|
||||||
|
@ -922,8 +974,8 @@ template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
|
||||||
inline bool operator==(const GTEST_10_TUPLE_(T)& t,
|
inline bool operator==(const GTEST_10_TUPLE_(T)& t,
|
||||||
const GTEST_10_TUPLE_(U)& u) {
|
const GTEST_10_TUPLE_(U)& u) {
|
||||||
return gtest_internal::SameSizeTuplePrefixComparator<
|
return gtest_internal::SameSizeTuplePrefixComparator<
|
||||||
tuple_size<GTEST_10_TUPLE_(T)>::value,
|
tuple_size<GTEST_10_TUPLE_(T) >::value,
|
||||||
tuple_size<GTEST_10_TUPLE_(U)>::value>::Eq(t, u);
|
tuple_size<GTEST_10_TUPLE_(U) >::value>::Eq(t, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
|
template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
|
||||||
|
|
|
@ -45,15 +45,14 @@
|
||||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||||
|
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
#include "gtest/internal/gtest-string.h"
|
|
||||||
|
|
||||||
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
|
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
|
||||||
// libstdc++ (which is where cxxabi.h comes from).
|
// libstdc++ (which is where cxxabi.h comes from).
|
||||||
# ifdef __GLIBCXX__
|
# if GTEST_HAS_CXXABI_H_
|
||||||
# include <cxxabi.h>
|
# include <cxxabi.h>
|
||||||
# elif defined(__HP_aCC)
|
# elif defined(__HP_aCC)
|
||||||
# include <acxx_demangle.h>
|
# include <acxx_demangle.h>
|
||||||
# endif // __GLIBCXX__
|
# endif // GTEST_HASH_CXXABI_H_
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
@ -62,24 +61,24 @@ namespace internal {
|
||||||
// NB: This function is also used in Google Mock, so don't move it inside of
|
// NB: This function is also used in Google Mock, so don't move it inside of
|
||||||
// the typed-test-only section below.
|
// the typed-test-only section below.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
String GetTypeName() {
|
std::string GetTypeName() {
|
||||||
# if GTEST_HAS_RTTI
|
# if GTEST_HAS_RTTI
|
||||||
|
|
||||||
const char* const name = typeid(T).name();
|
const char* const name = typeid(T).name();
|
||||||
# if defined(__GLIBCXX__) || defined(__HP_aCC)
|
# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
|
||||||
int status = 0;
|
int status = 0;
|
||||||
// gcc's implementation of typeid(T).name() mangles the type name,
|
// gcc's implementation of typeid(T).name() mangles the type name,
|
||||||
// so we have to demangle it.
|
// so we have to demangle it.
|
||||||
# ifdef __GLIBCXX__
|
# if GTEST_HAS_CXXABI_H_
|
||||||
using abi::__cxa_demangle;
|
using abi::__cxa_demangle;
|
||||||
# endif // __GLIBCXX__
|
# endif // GTEST_HAS_CXXABI_H_
|
||||||
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
||||||
const String name_str(status == 0 ? readable_name : name);
|
const std::string name_str(status == 0 ? readable_name : name);
|
||||||
free(readable_name);
|
free(readable_name);
|
||||||
return name_str;
|
return name_str;
|
||||||
# else
|
# else
|
||||||
return name;
|
return name;
|
||||||
# endif // __GLIBCXX__ || __HP_aCC
|
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
|
||||||
|
|
||||||
# else
|
# else
|
||||||
|
|
||||||
|
@ -3300,7 +3299,9 @@ struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
|
||||||
// INSTANTIATE_TYPED_TEST_CASE_P().
|
// INSTANTIATE_TYPED_TEST_CASE_P().
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeList { typedef Types1<T> type; };
|
struct TypeList {
|
||||||
|
typedef Types1<T> type;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest-death-test.h"
|
#include "gtest/gtest-death-test.h"
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
#include "gtest/internal/custom/gtest.h"
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
|
@ -43,6 +44,11 @@
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
|
|
||||||
|
# if GTEST_OS_LINUX
|
||||||
|
# include <signal.h>
|
||||||
|
# endif // GTEST_OS_LINUX
|
||||||
|
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
# if GTEST_OS_WINDOWS
|
# if GTEST_OS_WINDOWS
|
||||||
|
@ -52,6 +58,10 @@
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
# endif // GTEST_OS_WINDOWS
|
# endif // GTEST_OS_WINDOWS
|
||||||
|
|
||||||
|
# if GTEST_OS_QNX
|
||||||
|
# include <spawn.h>
|
||||||
|
# endif // GTEST_OS_QNX
|
||||||
|
|
||||||
#endif // GTEST_HAS_DEATH_TEST
|
#endif // GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
#include "gtest/gtest-message.h"
|
#include "gtest/gtest-message.h"
|
||||||
|
@ -59,9 +69,9 @@
|
||||||
|
|
||||||
// Indicates that this translation unit is part of Google Test's
|
// Indicates that this translation unit is part of Google Test's
|
||||||
// implementation. It must come before gtest-internal-inl.h is
|
// implementation. It must come before gtest-internal-inl.h is
|
||||||
// included, or there will be a compiler error. This trick is to
|
// included, or there will be a compiler error. This trick exists to
|
||||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
// prevent the accidental inclusion of gtest-internal-inl.h in the
|
||||||
// his code.
|
// user's code.
|
||||||
#define GTEST_IMPLEMENTATION_ 1
|
#define GTEST_IMPLEMENTATION_ 1
|
||||||
#include "src/gtest-internal-inl.h"
|
#include "src/gtest-internal-inl.h"
|
||||||
#undef GTEST_IMPLEMENTATION_
|
#undef GTEST_IMPLEMENTATION_
|
||||||
|
@ -100,13 +110,44 @@ GTEST_DEFINE_string_(
|
||||||
"Indicates the file, line number, temporal index of "
|
"Indicates the file, line number, temporal index of "
|
||||||
"the single death test to run, and a file descriptor to "
|
"the single death test to run, and a file descriptor to "
|
||||||
"which a success code may be sent, all separated by "
|
"which a success code may be sent, all separated by "
|
||||||
"colons. This flag is specified if and only if the current "
|
"the '|' characters. This flag is specified if and only if the current "
|
||||||
"process is a sub-process launched for running a thread-safe "
|
"process is a sub-process launched for running a thread-safe "
|
||||||
"death test. FOR INTERNAL USE ONLY.");
|
"death test. FOR INTERNAL USE ONLY.");
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
// Valid only for fast death tests. Indicates the code is running in the
|
||||||
|
// child process of a fast style death test.
|
||||||
|
# if !GTEST_OS_WINDOWS
|
||||||
|
static bool g_in_fast_death_test_child = false;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
// Returns a Boolean value indicating whether the caller is currently
|
||||||
|
// executing in the context of the death test child process. Tools such as
|
||||||
|
// Valgrind heap checkers may need this to modify their behavior in death
|
||||||
|
// tests. IMPORTANT: This is an internal utility. Using it may break the
|
||||||
|
// implementation of death tests. User code MUST NOT use it.
|
||||||
|
bool InDeathTestChild() {
|
||||||
|
# if GTEST_OS_WINDOWS
|
||||||
|
|
||||||
|
// On Windows, death tests are thread-safe regardless of the value of the
|
||||||
|
// death_test_style flag.
|
||||||
|
return !GTEST_FLAG(internal_run_death_test).empty();
|
||||||
|
|
||||||
|
# else
|
||||||
|
|
||||||
|
if (GTEST_FLAG(death_test_style) == "threadsafe")
|
||||||
|
return !GTEST_FLAG(internal_run_death_test).empty();
|
||||||
|
else
|
||||||
|
return g_in_fast_death_test_child;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// ExitedWithCode constructor.
|
// ExitedWithCode constructor.
|
||||||
ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
|
ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
|
||||||
}
|
}
|
||||||
|
@ -131,6 +172,14 @@ KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
|
||||||
|
|
||||||
// KilledBySignal function-call operator.
|
// KilledBySignal function-call operator.
|
||||||
bool KilledBySignal::operator()(int exit_status) const {
|
bool KilledBySignal::operator()(int exit_status) const {
|
||||||
|
# if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
|
||||||
return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
|
return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
|
||||||
}
|
}
|
||||||
# endif // !GTEST_OS_WINDOWS
|
# endif // !GTEST_OS_WINDOWS
|
||||||
|
@ -141,7 +190,7 @@ namespace internal {
|
||||||
|
|
||||||
// Generates a textual description of a given exit code, in the format
|
// Generates a textual description of a given exit code, in the format
|
||||||
// specified by wait(2).
|
// specified by wait(2).
|
||||||
static String ExitSummary(int exit_code) {
|
static std::string ExitSummary(int exit_code) {
|
||||||
Message m;
|
Message m;
|
||||||
|
|
||||||
# if GTEST_OS_WINDOWS
|
# if GTEST_OS_WINDOWS
|
||||||
|
@ -176,7 +225,7 @@ bool ExitedUnsuccessfully(int exit_status) {
|
||||||
// one thread running, or cannot determine the number of threads, prior
|
// one thread running, or cannot determine the number of threads, prior
|
||||||
// to executing the given statement. It is the responsibility of the
|
// to executing the given statement. It is the responsibility of the
|
||||||
// caller not to pass a thread_count of 1.
|
// caller not to pass a thread_count of 1.
|
||||||
static String DeathTestThreadWarning(size_t thread_count) {
|
static std::string DeathTestThreadWarning(size_t thread_count) {
|
||||||
Message msg;
|
Message msg;
|
||||||
msg << "Death tests use fork(), which is unsafe particularly"
|
msg << "Death tests use fork(), which is unsafe particularly"
|
||||||
<< " in a threaded context. For this test, " << GTEST_NAME_ << " ";
|
<< " in a threaded context. For this test, " << GTEST_NAME_ << " ";
|
||||||
|
@ -210,7 +259,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
|
||||||
// message is propagated back to the parent process. Otherwise, the
|
// message is propagated back to the parent process. Otherwise, the
|
||||||
// message is simply printed to stderr. In either case, the program
|
// message is simply printed to stderr. In either case, the program
|
||||||
// then exits with status 1.
|
// then exits with status 1.
|
||||||
void DeathTestAbort(const String& message) {
|
void DeathTestAbort(const std::string& message) {
|
||||||
// On a POSIX system, this function may be called from a threadsafe-style
|
// On a POSIX system, this function may be called from a threadsafe-style
|
||||||
// death test child process, which operates on a very small stack. Use
|
// death test child process, which operates on a very small stack. Use
|
||||||
// the heap for any additional non-minuscule memory requirements.
|
// the heap for any additional non-minuscule memory requirements.
|
||||||
|
@ -234,9 +283,10 @@ void DeathTestAbort(const String& message) {
|
||||||
# define GTEST_DEATH_TEST_CHECK_(expression) \
|
# define GTEST_DEATH_TEST_CHECK_(expression) \
|
||||||
do { \
|
do { \
|
||||||
if (!::testing::internal::IsTrue(expression)) { \
|
if (!::testing::internal::IsTrue(expression)) { \
|
||||||
DeathTestAbort(::testing::internal::String::Format( \
|
DeathTestAbort( \
|
||||||
"CHECK failed: File %s, line %d: %s", \
|
::std::string("CHECK failed: File ") + __FILE__ + ", line " \
|
||||||
__FILE__, __LINE__, #expression)); \
|
+ ::testing::internal::StreamableToString(__LINE__) + ": " \
|
||||||
|
+ #expression); \
|
||||||
} \
|
} \
|
||||||
} while (::testing::internal::AlwaysFalse())
|
} while (::testing::internal::AlwaysFalse())
|
||||||
|
|
||||||
|
@ -254,15 +304,16 @@ void DeathTestAbort(const String& message) {
|
||||||
gtest_retval = (expression); \
|
gtest_retval = (expression); \
|
||||||
} while (gtest_retval == -1 && errno == EINTR); \
|
} while (gtest_retval == -1 && errno == EINTR); \
|
||||||
if (gtest_retval == -1) { \
|
if (gtest_retval == -1) { \
|
||||||
DeathTestAbort(::testing::internal::String::Format( \
|
DeathTestAbort( \
|
||||||
"CHECK failed: File %s, line %d: %s != -1", \
|
::std::string("CHECK failed: File ") + __FILE__ + ", line " \
|
||||||
__FILE__, __LINE__, #expression)); \
|
+ ::testing::internal::StreamableToString(__LINE__) + ": " \
|
||||||
|
+ #expression + " != -1"); \
|
||||||
} \
|
} \
|
||||||
} while (::testing::internal::AlwaysFalse())
|
} while (::testing::internal::AlwaysFalse())
|
||||||
|
|
||||||
// Returns the message describing the last system error in errno.
|
// Returns the message describing the last system error in errno.
|
||||||
String GetLastErrnoDescription() {
|
std::string GetLastErrnoDescription() {
|
||||||
return String(errno == 0 ? "" : posix::StrError(errno));
|
return errno == 0 ? "" : posix::StrError(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called from a death test parent process to read a failure
|
// This is called from a death test parent process to read a failure
|
||||||
|
@ -300,9 +351,6 @@ DeathTest::DeathTest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pin the vtable to this file.
|
|
||||||
DeathTest::~DeathTest() {}
|
|
||||||
|
|
||||||
// Creates and returns a death test by dispatching to the current
|
// Creates and returns a death test by dispatching to the current
|
||||||
// death test factory.
|
// death test factory.
|
||||||
bool DeathTest::Create(const char* statement, const RE* regex,
|
bool DeathTest::Create(const char* statement, const RE* regex,
|
||||||
|
@ -315,11 +363,11 @@ const char* DeathTest::LastMessage() {
|
||||||
return last_death_test_message_.c_str();
|
return last_death_test_message_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeathTest::set_last_death_test_message(const String& message) {
|
void DeathTest::set_last_death_test_message(const std::string& message) {
|
||||||
last_death_test_message_ = message;
|
last_death_test_message_ = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
String DeathTest::last_death_test_message_;
|
std::string DeathTest::last_death_test_message_;
|
||||||
|
|
||||||
// Provides cross platform implementation for some death functionality.
|
// Provides cross platform implementation for some death functionality.
|
||||||
class DeathTestImpl : public DeathTest {
|
class DeathTestImpl : public DeathTest {
|
||||||
|
@ -334,10 +382,10 @@ class DeathTestImpl : public DeathTest {
|
||||||
write_fd_(-1) {}
|
write_fd_(-1) {}
|
||||||
|
|
||||||
// read_fd_ is expected to be closed and cleared by a derived class.
|
// read_fd_ is expected to be closed and cleared by a derived class.
|
||||||
~DeathTestImpl() override { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
|
~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
|
||||||
|
|
||||||
void Abort(AbortReason reason) override;
|
void Abort(AbortReason reason);
|
||||||
bool Passed(bool status_ok) override;
|
virtual bool Passed(bool status_ok);
|
||||||
|
|
||||||
const char* statement() const { return statement_; }
|
const char* statement() const { return statement_; }
|
||||||
const RE* regex() const { return regex_; }
|
const RE* regex() const { return regex_; }
|
||||||
|
@ -494,7 +542,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||||
if (!spawned())
|
if (!spawned())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const String error_message = GetCapturedStderr();
|
const std::string error_message = GetCapturedStderr();
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
Message buffer;
|
Message buffer;
|
||||||
|
@ -530,6 +578,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IN_PROGRESS:
|
case IN_PROGRESS:
|
||||||
|
default:
|
||||||
GTEST_LOG_(FATAL)
|
GTEST_LOG_(FATAL)
|
||||||
<< "DeathTest::Passed somehow called before conclusion of test";
|
<< "DeathTest::Passed somehow called before conclusion of test";
|
||||||
}
|
}
|
||||||
|
@ -675,22 +724,19 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||||
FALSE, // The initial state is non-signalled.
|
FALSE, // The initial state is non-signalled.
|
||||||
NULL)); // The even is unnamed.
|
NULL)); // The even is unnamed.
|
||||||
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
|
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
|
||||||
const String filter_flag = String::Format("--%s%s=%s.%s",
|
const std::string filter_flag =
|
||||||
GTEST_FLAG_PREFIX_, kFilterFlag,
|
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
|
||||||
info->test_case_name(),
|
info->test_case_name() + "." + info->name();
|
||||||
info->name());
|
const std::string internal_flag =
|
||||||
const String internal_flag = String::Format(
|
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
|
||||||
"--%s%s=%s|%d|%d|%u|%Iu|%Iu",
|
"=" + file_ + "|" + StreamableToString(line_) + "|" +
|
||||||
GTEST_FLAG_PREFIX_,
|
StreamableToString(death_test_index) + "|" +
|
||||||
kInternalRunDeathTestFlag,
|
StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
|
||||||
file_, line_,
|
// size_t has the same width as pointers on both 32-bit and 64-bit
|
||||||
death_test_index,
|
|
||||||
static_cast<unsigned int>(::GetCurrentProcessId()),
|
|
||||||
// size_t has the same with as pointers on both 32-bit and 64-bit
|
|
||||||
// Windows platforms.
|
// Windows platforms.
|
||||||
// See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
|
// See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
|
||||||
reinterpret_cast<size_t>(write_handle),
|
"|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) +
|
||||||
reinterpret_cast<size_t>(event_handle_.Get()));
|
"|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
|
||||||
|
|
||||||
char executable_path[_MAX_PATH + 1]; // NOLINT
|
char executable_path[_MAX_PATH + 1]; // NOLINT
|
||||||
GTEST_DEATH_TEST_CHECK_(
|
GTEST_DEATH_TEST_CHECK_(
|
||||||
|
@ -698,10 +744,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||||
executable_path,
|
executable_path,
|
||||||
_MAX_PATH));
|
_MAX_PATH));
|
||||||
|
|
||||||
String command_line = String::Format("%s %s \"%s\"",
|
std::string command_line =
|
||||||
::GetCommandLineA(),
|
std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
|
||||||
filter_flag.c_str(),
|
internal_flag + "\"";
|
||||||
internal_flag.c_str());
|
|
||||||
|
|
||||||
DeathTest::set_last_death_test_message("");
|
DeathTest::set_last_death_test_message("");
|
||||||
|
|
||||||
|
@ -744,7 +789,7 @@ class ForkingDeathTest : public DeathTestImpl {
|
||||||
ForkingDeathTest(const char* statement, const RE* regex);
|
ForkingDeathTest(const char* statement, const RE* regex);
|
||||||
|
|
||||||
// All of these virtual functions are inherited from DeathTest.
|
// All of these virtual functions are inherited from DeathTest.
|
||||||
int Wait() override;
|
virtual int Wait();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
|
void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
|
||||||
|
@ -780,7 +825,7 @@ class NoExecDeathTest : public ForkingDeathTest {
|
||||||
public:
|
public:
|
||||||
NoExecDeathTest(const char* a_statement, const RE* a_regex) :
|
NoExecDeathTest(const char* a_statement, const RE* a_regex) :
|
||||||
ForkingDeathTest(a_statement, a_regex) { }
|
ForkingDeathTest(a_statement, a_regex) { }
|
||||||
TestRole AssumeRole() override;
|
virtual TestRole AssumeRole();
|
||||||
};
|
};
|
||||||
|
|
||||||
// The AssumeRole process for a fork-and-run death test. It implements a
|
// The AssumeRole process for a fork-and-run death test. It implements a
|
||||||
|
@ -818,6 +863,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
|
||||||
// Event forwarding to the listeners of event listener API mush be shut
|
// Event forwarding to the listeners of event listener API mush be shut
|
||||||
// down in death test subprocesses.
|
// down in death test subprocesses.
|
||||||
GetUnitTestImpl()->listeners()->SuppressEventForwarding();
|
GetUnitTestImpl()->listeners()->SuppressEventForwarding();
|
||||||
|
g_in_fast_death_test_child = true;
|
||||||
return EXECUTE_TEST;
|
return EXECUTE_TEST;
|
||||||
} else {
|
} else {
|
||||||
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
|
||||||
|
@ -835,9 +881,18 @@ class ExecDeathTest : public ForkingDeathTest {
|
||||||
ExecDeathTest(const char* a_statement, const RE* a_regex,
|
ExecDeathTest(const char* a_statement, const RE* a_regex,
|
||||||
const char* file, int line) :
|
const char* file, int line) :
|
||||||
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
|
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
|
||||||
TestRole AssumeRole() override;
|
virtual TestRole AssumeRole();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static ::std::vector<testing::internal::string>
|
||||||
|
GetArgvsForDeathTestChildProcess() {
|
||||||
|
::std::vector<testing::internal::string> args = GetInjectableArgvs();
|
||||||
|
# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
|
||||||
|
::std::vector<testing::internal::string> extra_args =
|
||||||
|
GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_();
|
||||||
|
args.insert(args.end(), extra_args.begin(), extra_args.end());
|
||||||
|
# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
|
||||||
|
return args;
|
||||||
|
}
|
||||||
// The name of the file in which the death test is located.
|
// The name of the file in which the death test is located.
|
||||||
const char* const file_;
|
const char* const file_;
|
||||||
// The line number on which the death test is located.
|
// The line number on which the death test is located.
|
||||||
|
@ -872,6 +927,7 @@ class Arguments {
|
||||||
char* const* Argv() {
|
char* const* Argv() {
|
||||||
return &args_[0];
|
return &args_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char*> args_;
|
std::vector<char*> args_;
|
||||||
};
|
};
|
||||||
|
@ -897,6 +953,7 @@ extern "C" char** environ;
|
||||||
inline char** GetEnviron() { return environ; }
|
inline char** GetEnviron() { return environ; }
|
||||||
# endif // GTEST_OS_MAC
|
# endif // GTEST_OS_MAC
|
||||||
|
|
||||||
|
# if !GTEST_OS_QNX
|
||||||
// The main function for a threadsafe-style death test child process.
|
// The main function for a threadsafe-style death test child process.
|
||||||
// This function is called in a clone()-ed process and thus must avoid
|
// This function is called in a clone()-ed process and thus must avoid
|
||||||
// any potentially unsafe operations like malloc or libc functions.
|
// any potentially unsafe operations like malloc or libc functions.
|
||||||
|
@ -911,9 +968,8 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||||
UnitTest::GetInstance()->original_working_dir();
|
UnitTest::GetInstance()->original_working_dir();
|
||||||
// We can safely call chdir() as it's a direct system call.
|
// We can safely call chdir() as it's a direct system call.
|
||||||
if (chdir(original_dir) != 0) {
|
if (chdir(original_dir) != 0) {
|
||||||
DeathTestAbort(String::Format("chdir(\"%s\") failed: %s",
|
DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
|
||||||
original_dir,
|
GetLastErrnoDescription());
|
||||||
GetLastErrnoDescription().c_str()));
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,12 +979,12 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||||
// invoke the test program via a valid path that contains at least
|
// invoke the test program via a valid path that contains at least
|
||||||
// one path separator.
|
// one path separator.
|
||||||
execve(args->argv[0], args->argv, GetEnviron());
|
execve(args->argv[0], args->argv, GetEnviron());
|
||||||
DeathTestAbort(String::Format("execve(%s, ...) in %s failed: %s",
|
DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " +
|
||||||
args->argv[0],
|
original_dir + " failed: " +
|
||||||
original_dir,
|
GetLastErrnoDescription());
|
||||||
GetLastErrnoDescription().c_str()));
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
# endif // !GTEST_OS_QNX
|
||||||
|
|
||||||
// Two utility routines that together determine the direction the stack
|
// Two utility routines that together determine the direction the stack
|
||||||
// grows.
|
// grows.
|
||||||
|
@ -939,25 +995,77 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||||
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
|
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
|
||||||
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
|
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
|
||||||
// correct answer.
|
// correct answer.
|
||||||
bool StackLowerThanAddress(const void* ptr) GTEST_NO_INLINE_;
|
void StackLowerThanAddress(const void* ptr, bool* result) GTEST_NO_INLINE_;
|
||||||
bool StackLowerThanAddress(const void* ptr) {
|
void StackLowerThanAddress(const void* ptr, bool* result) {
|
||||||
int dummy;
|
int dummy;
|
||||||
return &dummy < ptr;
|
*result = (&dummy < ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure AddressSanitizer does not tamper with the stack here.
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||||
bool StackGrowsDown() {
|
bool StackGrowsDown() {
|
||||||
int dummy;
|
int dummy;
|
||||||
return StackLowerThanAddress(&dummy);
|
bool result;
|
||||||
|
StackLowerThanAddress(&dummy, &result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A threadsafe implementation of fork(2) for threadsafe-style death tests
|
// Spawns a child process with the same executable as the current process in
|
||||||
// that uses clone(2). It dies with an error message if anything goes
|
// a thread-safe manner and instructs it to run the death test. The
|
||||||
// wrong.
|
// implementation uses fork(2) + exec. On systems where clone(2) is
|
||||||
static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
|
// available, it is used instead, being slightly more thread-safe. On QNX,
|
||||||
|
// fork supports only single-threaded environments, so this function uses
|
||||||
|
// spawn(2) there instead. The function dies with an error message if
|
||||||
|
// anything goes wrong.
|
||||||
|
static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
|
||||||
ExecDeathTestArgs args = { argv, close_fd };
|
ExecDeathTestArgs args = { argv, close_fd };
|
||||||
pid_t child_pid = -1;
|
pid_t child_pid = -1;
|
||||||
|
|
||||||
# if GTEST_HAS_CLONE
|
# if GTEST_OS_QNX
|
||||||
|
// Obtains the current directory and sets it to be closed in the child
|
||||||
|
// process.
|
||||||
|
const int cwd_fd = open(".", O_RDONLY);
|
||||||
|
GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
|
||||||
|
// We need to execute the test program in the same environment where
|
||||||
|
// it was originally invoked. Therefore we change to the original
|
||||||
|
// working directory first.
|
||||||
|
const char* const original_dir =
|
||||||
|
UnitTest::GetInstance()->original_working_dir();
|
||||||
|
// We can safely call chdir() as it's a direct system call.
|
||||||
|
if (chdir(original_dir) != 0) {
|
||||||
|
DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
|
||||||
|
GetLastErrnoDescription());
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fd_flags;
|
||||||
|
// Set close_fd to be closed after spawn.
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
|
||||||
|
fd_flags | FD_CLOEXEC));
|
||||||
|
struct inheritance inherit = {0};
|
||||||
|
// spawn is a system call.
|
||||||
|
child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
|
||||||
|
// Restores the current working directory.
|
||||||
|
GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
|
||||||
|
|
||||||
|
# else // GTEST_OS_QNX
|
||||||
|
# if GTEST_OS_LINUX
|
||||||
|
// When a SIGPROF signal is received while fork() or clone() are executing,
|
||||||
|
// the process may hang. To avoid this, we ignore SIGPROF here and re-enable
|
||||||
|
// it after the call to fork()/clone() is complete.
|
||||||
|
struct sigaction saved_sigprof_action;
|
||||||
|
struct sigaction ignore_sigprof_action;
|
||||||
|
memset(&ignore_sigprof_action, 0, sizeof(ignore_sigprof_action));
|
||||||
|
sigemptyset(&ignore_sigprof_action.sa_mask);
|
||||||
|
ignore_sigprof_action.sa_handler = SIG_IGN;
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
|
||||||
|
SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
|
||||||
|
# endif // GTEST_OS_LINUX
|
||||||
|
|
||||||
|
# if GTEST_HAS_CLONE
|
||||||
const bool use_fork = GTEST_FLAG(death_test_use_fork);
|
const bool use_fork = GTEST_FLAG(death_test_use_fork);
|
||||||
|
|
||||||
if (!use_fork) {
|
if (!use_fork) {
|
||||||
|
@ -967,21 +1075,37 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
|
||||||
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
|
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
|
||||||
MAP_ANON | MAP_PRIVATE, -1, 0);
|
MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||||
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
|
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
|
||||||
|
|
||||||
|
// Maximum stack alignment in bytes: For a downward-growing stack, this
|
||||||
|
// amount is subtracted from size of the stack space to get an address
|
||||||
|
// that is within the stack space and is aligned on all systems we care
|
||||||
|
// about. As far as I know there is no ABI with stack alignment greater
|
||||||
|
// than 64. We assume stack and stack_size already have alignment of
|
||||||
|
// kMaxStackAlignment.
|
||||||
|
const size_t kMaxStackAlignment = 64;
|
||||||
void* const stack_top =
|
void* const stack_top =
|
||||||
static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
|
static_cast<char*>(stack) +
|
||||||
|
(stack_grows_down ? stack_size - kMaxStackAlignment : 0);
|
||||||
|
GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
|
||||||
|
reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
|
||||||
|
|
||||||
child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
|
child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
|
||||||
|
|
||||||
GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
|
GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
const bool use_fork = true;
|
const bool use_fork = true;
|
||||||
# endif // GTEST_HAS_CLONE
|
# endif // GTEST_HAS_CLONE
|
||||||
|
|
||||||
if (use_fork && (child_pid = fork()) == 0) {
|
if (use_fork && (child_pid = fork()) == 0) {
|
||||||
ExecDeathTestChildMain(&args);
|
ExecDeathTestChildMain(&args);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
# endif // GTEST_OS_QNX
|
||||||
|
# if GTEST_OS_LINUX
|
||||||
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(
|
||||||
|
sigaction(SIGPROF, &saved_sigprof_action, NULL));
|
||||||
|
# endif // GTEST_OS_LINUX
|
||||||
|
|
||||||
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
|
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
|
||||||
return child_pid;
|
return child_pid;
|
||||||
|
@ -1009,16 +1133,16 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
||||||
// it be closed when the child process does an exec:
|
// it be closed when the child process does an exec:
|
||||||
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
|
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
|
||||||
|
|
||||||
const String filter_flag =
|
const std::string filter_flag =
|
||||||
String::Format("--%s%s=%s.%s",
|
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
||||||
GTEST_FLAG_PREFIX_, kFilterFlag,
|
+ info->test_case_name() + "." + info->name();
|
||||||
info->test_case_name(), info->name());
|
const std::string internal_flag =
|
||||||
const String internal_flag =
|
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||||
String::Format("--%s%s=%s|%d|%d|%d",
|
+ file_ + "|" + StreamableToString(line_) + "|"
|
||||||
GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag,
|
+ StreamableToString(death_test_index) + "|"
|
||||||
file_, line_, death_test_index, pipe_fd[1]);
|
+ StreamableToString(pipe_fd[1]);
|
||||||
Arguments args;
|
Arguments args;
|
||||||
args.AddArguments(GetArgvs());
|
args.AddArguments(GetArgvsForDeathTestChildProcess());
|
||||||
args.AddArgument(filter_flag.c_str());
|
args.AddArgument(filter_flag.c_str());
|
||||||
args.AddArgument(internal_flag.c_str());
|
args.AddArgument(internal_flag.c_str());
|
||||||
|
|
||||||
|
@ -1029,7 +1153,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
||||||
// is necessary.
|
// is necessary.
|
||||||
FlushInfoLog();
|
FlushInfoLog();
|
||||||
|
|
||||||
const pid_t child_pid = ExecDeathTestFork(args.Argv(), pipe_fd[0]);
|
const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
|
||||||
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
|
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
|
||||||
set_child_pid(child_pid);
|
set_child_pid(child_pid);
|
||||||
set_read_fd(pipe_fd[0]);
|
set_read_fd(pipe_fd[0]);
|
||||||
|
@ -1055,9 +1179,10 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||||
|
|
||||||
if (flag != NULL) {
|
if (flag != NULL) {
|
||||||
if (death_test_index > flag->index()) {
|
if (death_test_index > flag->index()) {
|
||||||
DeathTest::set_last_death_test_message(String::Format(
|
DeathTest::set_last_death_test_message(
|
||||||
"Death test count (%d) somehow exceeded expected maximum (%d)",
|
"Death test count (" + StreamableToString(death_test_index)
|
||||||
death_test_index, flag->index()));
|
+ ") somehow exceeded expected maximum ("
|
||||||
|
+ StreamableToString(flag->index()) + ")");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1086,38 +1211,15 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||||
# endif // GTEST_OS_WINDOWS
|
# endif // GTEST_OS_WINDOWS
|
||||||
|
|
||||||
else { // NOLINT - this is more readable than unbalanced brackets inside #if.
|
else { // NOLINT - this is more readable than unbalanced brackets inside #if.
|
||||||
DeathTest::set_last_death_test_message(String::Format(
|
DeathTest::set_last_death_test_message(
|
||||||
"Unknown death test style \"%s\" encountered",
|
"Unknown death test style \"" + GTEST_FLAG(death_test_style)
|
||||||
GTEST_FLAG(death_test_style).c_str()));
|
+ "\" encountered");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pin the vtable to this file.
|
|
||||||
DeathTestFactory::~DeathTestFactory() {}
|
|
||||||
|
|
||||||
// Splits a given string on a given delimiter, populating a given
|
|
||||||
// vector with the fields. GTEST_HAS_DEATH_TEST implies that we have
|
|
||||||
// ::std::string, so we can use it here.
|
|
||||||
static void SplitString(const ::std::string& str, char delimiter,
|
|
||||||
::std::vector< ::std::string>* dest) {
|
|
||||||
::std::vector< ::std::string> parsed;
|
|
||||||
::std::string::size_type pos = 0;
|
|
||||||
while (::testing::internal::AlwaysTrue()) {
|
|
||||||
const ::std::string::size_type colon = str.find(delimiter, pos);
|
|
||||||
if (colon == ::std::string::npos) {
|
|
||||||
parsed.push_back(str.substr(pos));
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
parsed.push_back(str.substr(pos, colon - pos));
|
|
||||||
pos = colon + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dest->swap(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
# if GTEST_OS_WINDOWS
|
# if GTEST_OS_WINDOWS
|
||||||
// Recreates the pipe and event handles from the provided parameters,
|
// Recreates the pipe and event handles from the provided parameters,
|
||||||
// signals the event, and returns a file descriptor wrapped around the pipe
|
// signals the event, and returns a file descriptor wrapped around the pipe
|
||||||
|
@ -1129,8 +1231,8 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||||
FALSE, // Non-inheritable.
|
FALSE, // Non-inheritable.
|
||||||
parent_process_id));
|
parent_process_id));
|
||||||
if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
|
if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
|
||||||
DeathTestAbort(String::Format("Unable to open parent process %u",
|
DeathTestAbort("Unable to open parent process " +
|
||||||
parent_process_id));
|
StreamableToString(parent_process_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vladl@google.com): Replace the following check with a
|
// TODO(vladl@google.com): Replace the following check with a
|
||||||
|
@ -1150,9 +1252,10 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||||
// DUPLICATE_SAME_ACCESS is used.
|
// DUPLICATE_SAME_ACCESS is used.
|
||||||
FALSE, // Request non-inheritable handler.
|
FALSE, // Request non-inheritable handler.
|
||||||
DUPLICATE_SAME_ACCESS)) {
|
DUPLICATE_SAME_ACCESS)) {
|
||||||
DeathTestAbort(String::Format(
|
DeathTestAbort("Unable to duplicate the pipe handle " +
|
||||||
"Unable to duplicate the pipe handle %Iu from the parent process %u",
|
StreamableToString(write_handle_as_size_t) +
|
||||||
write_handle_as_size_t, parent_process_id));
|
" from the parent process " +
|
||||||
|
StreamableToString(parent_process_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
|
const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
|
||||||
|
@ -1163,17 +1266,18 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||||
0x0,
|
0x0,
|
||||||
FALSE,
|
FALSE,
|
||||||
DUPLICATE_SAME_ACCESS)) {
|
DUPLICATE_SAME_ACCESS)) {
|
||||||
DeathTestAbort(String::Format(
|
DeathTestAbort("Unable to duplicate the event handle " +
|
||||||
"Unable to duplicate the event handle %Iu from the parent process %u",
|
StreamableToString(event_handle_as_size_t) +
|
||||||
event_handle_as_size_t, parent_process_id));
|
" from the parent process " +
|
||||||
|
StreamableToString(parent_process_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const int write_fd =
|
const int write_fd =
|
||||||
::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
|
::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
|
||||||
if (write_fd == -1) {
|
if (write_fd == -1) {
|
||||||
DeathTestAbort(String::Format(
|
DeathTestAbort("Unable to convert pipe handle " +
|
||||||
"Unable to convert pipe handle %Iu to a file descriptor",
|
StreamableToString(write_handle_as_size_t) +
|
||||||
write_handle_as_size_t));
|
" to a file descriptor");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signals the parent that the write end of the pipe has been acquired
|
// Signals the parent that the write end of the pipe has been acquired
|
||||||
|
@ -1210,9 +1314,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||||
|| !ParseNaturalNumber(fields[3], &parent_process_id)
|
|| !ParseNaturalNumber(fields[3], &parent_process_id)
|
||||||
|| !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
|
|| !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
|
||||||
|| !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
|
|| !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
|
||||||
DeathTestAbort(String::Format(
|
DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
|
||||||
"Bad --gtest_internal_run_death_test flag: %s",
|
GTEST_FLAG(internal_run_death_test));
|
||||||
GTEST_FLAG(internal_run_death_test).c_str()));
|
|
||||||
}
|
}
|
||||||
write_fd = GetStatusFileDescriptor(parent_process_id,
|
write_fd = GetStatusFileDescriptor(parent_process_id,
|
||||||
write_handle_as_size_t,
|
write_handle_as_size_t,
|
||||||
|
@ -1223,9 +1326,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||||
|| !ParseNaturalNumber(fields[1], &line)
|
|| !ParseNaturalNumber(fields[1], &line)
|
||||||
|| !ParseNaturalNumber(fields[2], &index)
|
|| !ParseNaturalNumber(fields[2], &index)
|
||||||
|| !ParseNaturalNumber(fields[3], &write_fd)) {
|
|| !ParseNaturalNumber(fields[3], &write_fd)) {
|
||||||
DeathTestAbort(String::Format(
|
DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
|
||||||
"Bad --gtest_internal_run_death_test flag: %s",
|
+ GTEST_FLAG(internal_run_death_test));
|
||||||
GTEST_FLAG(internal_run_death_test).c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif // GTEST_OS_WINDOWS
|
# endif // GTEST_OS_WINDOWS
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
//
|
//
|
||||||
// Authors: keith.ray@gmail.com (Keith Ray)
|
// Authors: keith.ray@gmail.com (Keith Ray)
|
||||||
|
|
||||||
|
#include "gtest/gtest-message.h"
|
||||||
#include "gtest/internal/gtest-filepath.h"
|
#include "gtest/internal/gtest-filepath.h"
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
|
||||||
|
@ -39,8 +40,8 @@
|
||||||
#elif GTEST_OS_WINDOWS
|
#elif GTEST_OS_WINDOWS
|
||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#elif GTEST_OS_SYMBIAN || GTEST_OS_NACL
|
#elif GTEST_OS_SYMBIAN
|
||||||
// Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h
|
// Symbian OpenC has PATH_MAX in sys/syslimits.h
|
||||||
# include <sys/syslimits.h>
|
# include <sys/syslimits.h>
|
||||||
#else
|
#else
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
|
@ -96,7 +97,7 @@ static bool IsPathSeparator(char c) {
|
||||||
|
|
||||||
// Returns the current working directory, or "" if unsuccessful.
|
// Returns the current working directory, or "" if unsuccessful.
|
||||||
FilePath FilePath::GetCurrentDir() {
|
FilePath FilePath::GetCurrentDir() {
|
||||||
#if GTEST_OS_WINDOWS_MOBILE
|
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
|
||||||
// Windows CE doesn't have a current directory, so we just return
|
// Windows CE doesn't have a current directory, so we just return
|
||||||
// something reasonable.
|
// something reasonable.
|
||||||
return FilePath(kCurrentDirectoryString);
|
return FilePath(kCurrentDirectoryString);
|
||||||
|
@ -105,7 +106,14 @@ FilePath FilePath::GetCurrentDir() {
|
||||||
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
||||||
#else
|
#else
|
||||||
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
||||||
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
char* result = getcwd(cwd, sizeof(cwd));
|
||||||
|
# if GTEST_OS_NACL
|
||||||
|
// getcwd will likely fail in NaCl due to the sandbox, so return something
|
||||||
|
// reasonable. The user may have provided a shim implementation for getcwd,
|
||||||
|
// however, so fallback only when failure is detected.
|
||||||
|
return FilePath(result == NULL ? kCurrentDirectoryString : cwd);
|
||||||
|
# endif // GTEST_OS_NACL
|
||||||
|
return FilePath(result == NULL ? "" : cwd);
|
||||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,14 +122,15 @@ FilePath FilePath::GetCurrentDir() {
|
||||||
// FilePath("dir/file"). If a case-insensitive extension is not
|
// FilePath("dir/file"). If a case-insensitive extension is not
|
||||||
// found, returns a copy of the original FilePath.
|
// found, returns a copy of the original FilePath.
|
||||||
FilePath FilePath::RemoveExtension(const char* extension) const {
|
FilePath FilePath::RemoveExtension(const char* extension) const {
|
||||||
String dot_extension(String::Format(".%s", extension));
|
const std::string dot_extension = std::string(".") + extension;
|
||||||
if (pathname_.EndsWithCaseInsensitive(dot_extension.c_str())) {
|
if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
|
||||||
return FilePath(String(pathname_.c_str(), pathname_.length() - 4));
|
return FilePath(pathname_.substr(
|
||||||
|
0, pathname_.length() - dot_extension.length()));
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a pointer to the last occurrence of a valid path separator in
|
// Returns a pointer to the last occurence of a valid path separator in
|
||||||
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
||||||
// separators. Returns NULL if no path separator was found.
|
// separators. Returns NULL if no path separator was found.
|
||||||
const char* FilePath::FindLastPathSeparator() const {
|
const char* FilePath::FindLastPathSeparator() const {
|
||||||
|
@ -145,7 +154,7 @@ const char* FilePath::FindLastPathSeparator() const {
|
||||||
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
||||||
FilePath FilePath::RemoveDirectoryName() const {
|
FilePath FilePath::RemoveDirectoryName() const {
|
||||||
const char* const last_sep = FindLastPathSeparator();
|
const char* const last_sep = FindLastPathSeparator();
|
||||||
return last_sep ? FilePath(String(last_sep + 1)) : *this;
|
return last_sep ? FilePath(last_sep + 1) : *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveFileName returns the directory path with the filename removed.
|
// RemoveFileName returns the directory path with the filename removed.
|
||||||
|
@ -156,9 +165,9 @@ FilePath FilePath::RemoveDirectoryName() const {
|
||||||
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
||||||
FilePath FilePath::RemoveFileName() const {
|
FilePath FilePath::RemoveFileName() const {
|
||||||
const char* const last_sep = FindLastPathSeparator();
|
const char* const last_sep = FindLastPathSeparator();
|
||||||
String dir;
|
std::string dir;
|
||||||
if (last_sep) {
|
if (last_sep) {
|
||||||
dir = String(c_str(), last_sep + 1 - c_str());
|
dir = std::string(c_str(), last_sep + 1 - c_str());
|
||||||
} else {
|
} else {
|
||||||
dir = kCurrentDirectoryString;
|
dir = kCurrentDirectoryString;
|
||||||
}
|
}
|
||||||
|
@ -175,11 +184,12 @@ FilePath FilePath::MakeFileName(const FilePath& directory,
|
||||||
const FilePath& base_name,
|
const FilePath& base_name,
|
||||||
int number,
|
int number,
|
||||||
const char* extension) {
|
const char* extension) {
|
||||||
String file;
|
std::string file;
|
||||||
if (number == 0) {
|
if (number == 0) {
|
||||||
file = String::Format("%s.%s", base_name.c_str(), extension);
|
file = base_name.string() + "." + extension;
|
||||||
} else {
|
} else {
|
||||||
file = String::Format("%s_%d.%s", base_name.c_str(), number, extension);
|
file = base_name.string() + "_" + StreamableToString(number)
|
||||||
|
+ "." + extension;
|
||||||
}
|
}
|
||||||
return ConcatPaths(directory, FilePath(file));
|
return ConcatPaths(directory, FilePath(file));
|
||||||
}
|
}
|
||||||
|
@ -191,8 +201,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory,
|
||||||
if (directory.IsEmpty())
|
if (directory.IsEmpty())
|
||||||
return relative_path;
|
return relative_path;
|
||||||
const FilePath dir(directory.RemoveTrailingPathSeparator());
|
const FilePath dir(directory.RemoveTrailingPathSeparator());
|
||||||
return FilePath(String::Format("%s%c%s", dir.c_str(), kPathSeparator,
|
return FilePath(dir.string() + kPathSeparator + relative_path.string());
|
||||||
relative_path.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if pathname describes something findable in the file-system,
|
// Returns true if pathname describes something findable in the file-system,
|
||||||
|
@ -336,7 +345,7 @@ bool FilePath::CreateFolder() const {
|
||||||
// On Windows platform, uses \ as the separator, other platforms use /.
|
// On Windows platform, uses \ as the separator, other platforms use /.
|
||||||
FilePath FilePath::RemoveTrailingPathSeparator() const {
|
FilePath FilePath::RemoveTrailingPathSeparator() const {
|
||||||
return IsDirectory()
|
return IsDirectory()
|
||||||
? FilePath(String(pathname_.c_str(), pathname_.length() - 1))
|
? FilePath(pathname_.substr(0, pathname_.length() - 1))
|
||||||
: *this;
|
: *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
|
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
|
||||||
// part of Google Test's implementation; otherwise it's undefined.
|
// part of Google Test's implementation; otherwise it's undefined.
|
||||||
#if !GTEST_IMPLEMENTATION_
|
#if !GTEST_IMPLEMENTATION_
|
||||||
// A user is trying to include this from his code - just say no.
|
// If this file is included from the user's code, just say no.
|
||||||
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
||||||
# error "It must not be included except by Google Test itself."
|
# error "It must not be included except by Google Test itself."
|
||||||
#endif // GTEST_IMPLEMENTATION_
|
#endif // GTEST_IMPLEMENTATION_
|
||||||
|
@ -58,6 +58,11 @@
|
||||||
|
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
|
||||||
|
#if GTEST_CAN_STREAM_RESULTS_
|
||||||
|
# include <arpa/inet.h> // NOLINT
|
||||||
|
# include <netdb.h> // NOLINT
|
||||||
|
#endif
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS
|
#if GTEST_OS_WINDOWS
|
||||||
# include <windows.h> // NOLINT
|
# include <windows.h> // NOLINT
|
||||||
#endif // GTEST_OS_WINDOWS
|
#endif // GTEST_OS_WINDOWS
|
||||||
|
@ -95,6 +100,7 @@ const char kShuffleFlag[] = "shuffle";
|
||||||
const char kStackTraceDepthFlag[] = "stack_trace_depth";
|
const char kStackTraceDepthFlag[] = "stack_trace_depth";
|
||||||
const char kStreamResultToFlag[] = "stream_result_to";
|
const char kStreamResultToFlag[] = "stream_result_to";
|
||||||
const char kThrowOnFailureFlag[] = "throw_on_failure";
|
const char kThrowOnFailureFlag[] = "throw_on_failure";
|
||||||
|
const char kFlagfileFlag[] = "flagfile";
|
||||||
|
|
||||||
// A valid random seed must be in [1, kMaxRandomSeed].
|
// A valid random seed must be in [1, kMaxRandomSeed].
|
||||||
const int kMaxRandomSeed = 99999;
|
const int kMaxRandomSeed = 99999;
|
||||||
|
@ -112,6 +118,12 @@ GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
|
||||||
// Formats the given time in milliseconds as seconds.
|
// Formats the given time in milliseconds as seconds.
|
||||||
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
|
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
|
||||||
|
|
||||||
|
// Converts the given time in milliseconds to a date string in the ISO 8601
|
||||||
|
// format, without the timezone information. N.B.: due to the use the
|
||||||
|
// non-reentrant localtime() function, this function is not thread safe. Do
|
||||||
|
// not use it in any code that can be called from multiple threads.
|
||||||
|
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
|
||||||
|
|
||||||
// Parses a string for an Int32 flag, in the form of "--flag=value".
|
// Parses a string for an Int32 flag, in the form of "--flag=value".
|
||||||
//
|
//
|
||||||
// On success, stores the value of the flag in *value, and returns
|
// On success, stores the value of the flag in *value, and returns
|
||||||
|
@ -151,79 +163,74 @@ class GTestFlagSaver {
|
||||||
public:
|
public:
|
||||||
// The c'tor.
|
// The c'tor.
|
||||||
GTestFlagSaver() {
|
GTestFlagSaver() {
|
||||||
color_ = GTEST_FLAG(color);
|
|
||||||
death_test_style_ = GTEST_FLAG(death_test_style);
|
|
||||||
filter_ = GTEST_FLAG(filter);
|
|
||||||
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
|
|
||||||
output_ = GTEST_FLAG(output);
|
|
||||||
stream_result_to_ = GTEST_FLAG(stream_result_to);
|
|
||||||
|
|
||||||
random_seed_ = GTEST_FLAG(random_seed);
|
|
||||||
repeat_ = GTEST_FLAG(repeat);
|
|
||||||
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
|
|
||||||
|
|
||||||
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
|
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
|
||||||
break_on_failure_ = GTEST_FLAG(break_on_failure);
|
break_on_failure_ = GTEST_FLAG(break_on_failure);
|
||||||
catch_exceptions_ = GTEST_FLAG(catch_exceptions);
|
catch_exceptions_ = GTEST_FLAG(catch_exceptions);
|
||||||
|
color_ = GTEST_FLAG(color);
|
||||||
|
death_test_style_ = GTEST_FLAG(death_test_style);
|
||||||
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
|
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
|
||||||
|
filter_ = GTEST_FLAG(filter);
|
||||||
|
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
|
||||||
list_tests_ = GTEST_FLAG(list_tests);
|
list_tests_ = GTEST_FLAG(list_tests);
|
||||||
|
output_ = GTEST_FLAG(output);
|
||||||
print_time_ = GTEST_FLAG(print_time);
|
print_time_ = GTEST_FLAG(print_time);
|
||||||
|
random_seed_ = GTEST_FLAG(random_seed);
|
||||||
|
repeat_ = GTEST_FLAG(repeat);
|
||||||
shuffle_ = GTEST_FLAG(shuffle);
|
shuffle_ = GTEST_FLAG(shuffle);
|
||||||
|
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
|
||||||
|
stream_result_to_ = GTEST_FLAG(stream_result_to);
|
||||||
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
|
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
|
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
|
||||||
~GTestFlagSaver() {
|
~GTestFlagSaver() {
|
||||||
GTEST_FLAG(color) = color_;
|
|
||||||
GTEST_FLAG(death_test_style) = death_test_style_;
|
|
||||||
GTEST_FLAG(filter) = filter_;
|
|
||||||
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
|
|
||||||
GTEST_FLAG(output) = output_;
|
|
||||||
GTEST_FLAG(stream_result_to) = stream_result_to_;
|
|
||||||
|
|
||||||
GTEST_FLAG(random_seed) = random_seed_;
|
|
||||||
GTEST_FLAG(repeat) = repeat_;
|
|
||||||
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
|
|
||||||
|
|
||||||
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
|
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
|
||||||
GTEST_FLAG(break_on_failure) = break_on_failure_;
|
GTEST_FLAG(break_on_failure) = break_on_failure_;
|
||||||
GTEST_FLAG(catch_exceptions) = catch_exceptions_;
|
GTEST_FLAG(catch_exceptions) = catch_exceptions_;
|
||||||
|
GTEST_FLAG(color) = color_;
|
||||||
|
GTEST_FLAG(death_test_style) = death_test_style_;
|
||||||
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
|
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
|
||||||
|
GTEST_FLAG(filter) = filter_;
|
||||||
|
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
|
||||||
GTEST_FLAG(list_tests) = list_tests_;
|
GTEST_FLAG(list_tests) = list_tests_;
|
||||||
|
GTEST_FLAG(output) = output_;
|
||||||
GTEST_FLAG(print_time) = print_time_;
|
GTEST_FLAG(print_time) = print_time_;
|
||||||
|
GTEST_FLAG(random_seed) = random_seed_;
|
||||||
|
GTEST_FLAG(repeat) = repeat_;
|
||||||
GTEST_FLAG(shuffle) = shuffle_;
|
GTEST_FLAG(shuffle) = shuffle_;
|
||||||
|
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
|
||||||
|
GTEST_FLAG(stream_result_to) = stream_result_to_;
|
||||||
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
|
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Fields for saving the original values of flags.
|
// Fields for saving the original values of flags.
|
||||||
String color_;
|
|
||||||
String death_test_style_;
|
|
||||||
String filter_;
|
|
||||||
String internal_run_death_test_;
|
|
||||||
String output_;
|
|
||||||
String stream_result_to_;
|
|
||||||
internal::Int32 random_seed_;
|
|
||||||
internal::Int32 repeat_;
|
|
||||||
internal::Int32 stack_trace_depth_;
|
|
||||||
bool also_run_disabled_tests_;
|
bool also_run_disabled_tests_;
|
||||||
bool break_on_failure_;
|
bool break_on_failure_;
|
||||||
bool catch_exceptions_;
|
bool catch_exceptions_;
|
||||||
|
std::string color_;
|
||||||
|
std::string death_test_style_;
|
||||||
bool death_test_use_fork_;
|
bool death_test_use_fork_;
|
||||||
|
std::string filter_;
|
||||||
|
std::string internal_run_death_test_;
|
||||||
bool list_tests_;
|
bool list_tests_;
|
||||||
|
std::string output_;
|
||||||
bool print_time_;
|
bool print_time_;
|
||||||
|
internal::Int32 random_seed_;
|
||||||
|
internal::Int32 repeat_;
|
||||||
bool shuffle_;
|
bool shuffle_;
|
||||||
|
internal::Int32 stack_trace_depth_;
|
||||||
|
std::string stream_result_to_;
|
||||||
bool throw_on_failure_;
|
bool throw_on_failure_;
|
||||||
} GTEST_ATTRIBUTE_UNUSED_;
|
} GTEST_ATTRIBUTE_UNUSED_;
|
||||||
|
|
||||||
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
|
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
|
||||||
// code_point parameter is of type UInt32 because wchar_t may not be
|
// code_point parameter is of type UInt32 because wchar_t may not be
|
||||||
// wide enough to contain a code point.
|
// wide enough to contain a code point.
|
||||||
// The output buffer str must containt at least 32 characters.
|
|
||||||
// The function returns the address of the output buffer.
|
|
||||||
// If the code_point is not a valid Unicode code point
|
// If the code_point is not a valid Unicode code point
|
||||||
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
|
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
|
||||||
// as '(Invalid Unicode 0xXXXXXXXX)'.
|
// to "(Invalid Unicode 0xXXXXXXXX)".
|
||||||
GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
|
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
|
||||||
|
|
||||||
// Converts a wide string to a narrow string in UTF-8 encoding.
|
// Converts a wide string to a narrow string in UTF-8 encoding.
|
||||||
// The wide string is assumed to have the following encoding:
|
// The wide string is assumed to have the following encoding:
|
||||||
|
@ -238,7 +245,7 @@ GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
|
||||||
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
|
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
|
||||||
// and contains invalid UTF-16 surrogate pairs, values in those pairs
|
// and contains invalid UTF-16 surrogate pairs, values in those pairs
|
||||||
// will be encoded as individual Unicode characters from Basic Normal Plane.
|
// will be encoded as individual Unicode characters from Basic Normal Plane.
|
||||||
GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);
|
GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
|
||||||
|
|
||||||
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
|
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
|
||||||
// if the variable is present. If a file already exists at this location, this
|
// if the variable is present. If a file already exists at this location, this
|
||||||
|
@ -342,16 +349,15 @@ class TestPropertyKeyIs {
|
||||||
// Constructor.
|
// Constructor.
|
||||||
//
|
//
|
||||||
// TestPropertyKeyIs has NO default constructor.
|
// TestPropertyKeyIs has NO default constructor.
|
||||||
explicit TestPropertyKeyIs(const char* key)
|
explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
|
||||||
: key_(key) {}
|
|
||||||
|
|
||||||
// Returns true iff the test name of test property matches on key_.
|
// Returns true iff the test name of test property matches on key_.
|
||||||
bool operator()(const TestProperty& test_property) const {
|
bool operator()(const TestProperty& test_property) const {
|
||||||
return String(test_property.key()).Compare(key_) == 0;
|
return test_property.key() == key_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String key_;
|
std::string key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class UnitTestOptions.
|
// Class UnitTestOptions.
|
||||||
|
@ -369,12 +375,12 @@ class GTEST_API_ UnitTestOptions {
|
||||||
// Functions for processing the gtest_output flag.
|
// Functions for processing the gtest_output flag.
|
||||||
|
|
||||||
// Returns the output format, or "" for normal printed output.
|
// Returns the output format, or "" for normal printed output.
|
||||||
static String GetOutputFormat();
|
static std::string GetOutputFormat();
|
||||||
|
|
||||||
// Returns the absolute path of the requested output file, or the
|
// Returns the absolute path of the requested output file, or the
|
||||||
// default (test_detail.xml in the original working directory) if
|
// default (test_detail.xml in the original working directory) if
|
||||||
// none was explicitly specified.
|
// none was explicitly specified.
|
||||||
static String GetAbsolutePathToOutputFile();
|
static std::string GetAbsolutePathToOutputFile();
|
||||||
|
|
||||||
// Functions for processing the gtest_filter flag.
|
// Functions for processing the gtest_filter flag.
|
||||||
|
|
||||||
|
@ -387,8 +393,8 @@ class GTEST_API_ UnitTestOptions {
|
||||||
|
|
||||||
// Returns true iff the user-specified filter matches the test case
|
// Returns true iff the user-specified filter matches the test case
|
||||||
// name and the test name.
|
// name and the test name.
|
||||||
static bool FilterMatchesTest(const String &test_case_name,
|
static bool FilterMatchesTest(const std::string &test_case_name,
|
||||||
const String &test_name);
|
const std::string &test_name);
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS
|
#if GTEST_OS_WINDOWS
|
||||||
// Function for supporting the gtest_catch_exception flag.
|
// Function for supporting the gtest_catch_exception flag.
|
||||||
|
@ -401,7 +407,7 @@ class GTEST_API_ UnitTestOptions {
|
||||||
|
|
||||||
// Returns true if "name" matches the ':' separated list of glob-style
|
// Returns true if "name" matches the ':' separated list of glob-style
|
||||||
// filters in "filter".
|
// filters in "filter".
|
||||||
static bool MatchesFilter(const String& name, const char* filter);
|
static bool MatchesFilter(const std::string& name, const char* filter);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns the current application's name, removing directory path if that
|
// Returns the current application's name, removing directory path if that
|
||||||
|
@ -412,21 +418,25 @@ GTEST_API_ FilePath GetCurrentExecutableName();
|
||||||
class OsStackTraceGetterInterface {
|
class OsStackTraceGetterInterface {
|
||||||
public:
|
public:
|
||||||
OsStackTraceGetterInterface() {}
|
OsStackTraceGetterInterface() {}
|
||||||
virtual ~OsStackTraceGetterInterface();
|
virtual ~OsStackTraceGetterInterface() {}
|
||||||
|
|
||||||
// Returns the current OS stack trace as a String. Parameters:
|
// Returns the current OS stack trace as an std::string. Parameters:
|
||||||
//
|
//
|
||||||
// max_depth - the maximum number of stack frames to be included
|
// max_depth - the maximum number of stack frames to be included
|
||||||
// in the trace.
|
// in the trace.
|
||||||
// skip_count - the number of top frames to be skipped; doesn't count
|
// skip_count - the number of top frames to be skipped; doesn't count
|
||||||
// against max_depth.
|
// against max_depth.
|
||||||
virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;
|
virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
|
||||||
|
|
||||||
// UponLeavingGTest() should be called immediately before Google Test calls
|
// UponLeavingGTest() should be called immediately before Google Test calls
|
||||||
// user code. It saves some information about the current stack that
|
// user code. It saves some information about the current stack that
|
||||||
// CurrentStackTrace() will use to find and hide Google Test stack frames.
|
// CurrentStackTrace() will use to find and hide Google Test stack frames.
|
||||||
virtual void UponLeavingGTest() = 0;
|
virtual void UponLeavingGTest() = 0;
|
||||||
|
|
||||||
|
// This string is inserted in place of stack frames that are part of
|
||||||
|
// Google Test's implementation.
|
||||||
|
static const char* const kElidedFramesMarker;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
|
||||||
};
|
};
|
||||||
|
@ -434,23 +444,12 @@ class OsStackTraceGetterInterface {
|
||||||
// A working implementation of the OsStackTraceGetterInterface interface.
|
// A working implementation of the OsStackTraceGetterInterface interface.
|
||||||
class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
||||||
public:
|
public:
|
||||||
OsStackTraceGetter() : caller_frame_(NULL) {}
|
OsStackTraceGetter() {}
|
||||||
String CurrentStackTrace(int max_depth, int skip_count) override;
|
|
||||||
void UponLeavingGTest() override;
|
|
||||||
|
|
||||||
// This string is inserted in place of stack frames that are part of
|
virtual string CurrentStackTrace(int max_depth, int skip_count);
|
||||||
// Google Test's implementation.
|
virtual void UponLeavingGTest();
|
||||||
static const char* const kElidedFramesMarker;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex mutex_; // protects all internal state
|
|
||||||
|
|
||||||
// We save the stack frame below the frame that calls user code.
|
|
||||||
// We do this because the address of the frame immediately below
|
|
||||||
// the user code changes between the call to UponLeavingGTest()
|
|
||||||
// and any calls to CurrentStackTrace() from within the user code.
|
|
||||||
void* caller_frame_;
|
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -458,7 +457,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
||||||
struct TraceInfo {
|
struct TraceInfo {
|
||||||
const char* file;
|
const char* file;
|
||||||
int line;
|
int line;
|
||||||
String message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the default global test part result reporter used in UnitTestImpl.
|
// This is the default global test part result reporter used in UnitTestImpl.
|
||||||
|
@ -469,7 +468,7 @@ class DefaultGlobalTestPartResultReporter
|
||||||
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
|
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
|
||||||
// Implements the TestPartResultReporterInterface. Reports the test part
|
// Implements the TestPartResultReporterInterface. Reports the test part
|
||||||
// result in the current test.
|
// result in the current test.
|
||||||
void ReportTestPartResult(const TestPartResult &result) override;
|
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnitTestImpl* const unit_test_;
|
UnitTestImpl* const unit_test_;
|
||||||
|
@ -485,7 +484,7 @@ class DefaultPerThreadTestPartResultReporter
|
||||||
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
|
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
|
||||||
// Implements the TestPartResultReporterInterface. The implementation just
|
// Implements the TestPartResultReporterInterface. The implementation just
|
||||||
// delegates to the current global test part result reporter of *unit_test_.
|
// delegates to the current global test part result reporter of *unit_test_.
|
||||||
void ReportTestPartResult(const TestPartResult &result) override;
|
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnitTestImpl* const unit_test_;
|
UnitTestImpl* const unit_test_;
|
||||||
|
@ -542,15 +541,25 @@ class GTEST_API_ UnitTestImpl {
|
||||||
// Gets the number of failed tests.
|
// Gets the number of failed tests.
|
||||||
int failed_test_count() const;
|
int failed_test_count() const;
|
||||||
|
|
||||||
|
// Gets the number of disabled tests that will be reported in the XML report.
|
||||||
|
int reportable_disabled_test_count() const;
|
||||||
|
|
||||||
// Gets the number of disabled tests.
|
// Gets the number of disabled tests.
|
||||||
int disabled_test_count() const;
|
int disabled_test_count() const;
|
||||||
|
|
||||||
|
// Gets the number of tests to be printed in the XML report.
|
||||||
|
int reportable_test_count() const;
|
||||||
|
|
||||||
// Gets the number of all tests.
|
// Gets the number of all tests.
|
||||||
int total_test_count() const;
|
int total_test_count() const;
|
||||||
|
|
||||||
// Gets the number of tests that should run.
|
// Gets the number of tests that should run.
|
||||||
int test_to_run_count() const;
|
int test_to_run_count() const;
|
||||||
|
|
||||||
|
// Gets the time of the test program start, in ms from the start of the
|
||||||
|
// UNIX epoch.
|
||||||
|
TimeInMillis start_timestamp() const { return start_timestamp_; }
|
||||||
|
|
||||||
// Gets the elapsed time, in milliseconds.
|
// Gets the elapsed time, in milliseconds.
|
||||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||||
|
|
||||||
|
@ -599,7 +608,7 @@ class GTEST_API_ UnitTestImpl {
|
||||||
// getter, and returns it.
|
// getter, and returns it.
|
||||||
OsStackTraceGetterInterface* os_stack_trace_getter();
|
OsStackTraceGetterInterface* os_stack_trace_getter();
|
||||||
|
|
||||||
// Returns the current OS stack trace as a String.
|
// Returns the current OS stack trace as an std::string.
|
||||||
//
|
//
|
||||||
// The maximum number of stack frames to be included is specified by
|
// The maximum number of stack frames to be included is specified by
|
||||||
// the gtest_stack_trace_depth flag. The skip_count parameter
|
// the gtest_stack_trace_depth flag. The skip_count parameter
|
||||||
|
@ -609,7 +618,7 @@ class GTEST_API_ UnitTestImpl {
|
||||||
// For example, if Foo() calls Bar(), which in turn calls
|
// For example, if Foo() calls Bar(), which in turn calls
|
||||||
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
|
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
|
||||||
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
||||||
String CurrentOsStackTraceExceptTop(int skip_count);
|
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
|
||||||
|
|
||||||
// Finds and returns a TestCase with the given name. If one doesn't
|
// Finds and returns a TestCase with the given name. If one doesn't
|
||||||
// exist, creates one and returns it.
|
// exist, creates one and returns it.
|
||||||
|
@ -699,6 +708,12 @@ class GTEST_API_ UnitTestImpl {
|
||||||
ad_hoc_test_result_.Clear();
|
ad_hoc_test_result_.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds a TestProperty to the current TestResult object when invoked in a
|
||||||
|
// context of a test or a test case, or to the global property set. If the
|
||||||
|
// result already contains a property with the same key, the value will be
|
||||||
|
// updated.
|
||||||
|
void RecordProperty(const TestProperty& test_property);
|
||||||
|
|
||||||
enum ReactionToSharding {
|
enum ReactionToSharding {
|
||||||
HONOR_SHARDING_PROTOCOL,
|
HONOR_SHARDING_PROTOCOL,
|
||||||
IGNORE_SHARDING_PROTOCOL
|
IGNORE_SHARDING_PROTOCOL
|
||||||
|
@ -883,6 +898,10 @@ class GTEST_API_ UnitTestImpl {
|
||||||
// Our random number generator.
|
// Our random number generator.
|
||||||
internal::Random random_;
|
internal::Random random_;
|
||||||
|
|
||||||
|
// The time of the test program start, in ms from the start of the
|
||||||
|
// UNIX epoch.
|
||||||
|
TimeInMillis start_timestamp_;
|
||||||
|
|
||||||
// How long the test took to run, in milliseconds.
|
// How long the test took to run, in milliseconds.
|
||||||
TimeInMillis elapsed_time_;
|
TimeInMillis elapsed_time_;
|
||||||
|
|
||||||
|
@ -938,33 +957,7 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
|
||||||
|
|
||||||
// Returns the message describing the last system error, regardless of the
|
// Returns the message describing the last system error, regardless of the
|
||||||
// platform.
|
// platform.
|
||||||
GTEST_API_ String GetLastErrnoDescription();
|
GTEST_API_ std::string GetLastErrnoDescription();
|
||||||
|
|
||||||
# if GTEST_OS_WINDOWS
|
|
||||||
// Provides leak-safe Windows kernel handle ownership.
|
|
||||||
class AutoHandle {
|
|
||||||
public:
|
|
||||||
AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
|
|
||||||
explicit AutoHandle(HANDLE handle) : handle_(handle) {}
|
|
||||||
|
|
||||||
~AutoHandle() { Reset(); }
|
|
||||||
|
|
||||||
HANDLE Get() const { return handle_; }
|
|
||||||
void Reset() { Reset(INVALID_HANDLE_VALUE); }
|
|
||||||
void Reset(HANDLE handle) {
|
|
||||||
if (handle != handle_) {
|
|
||||||
if (handle_ != INVALID_HANDLE_VALUE)
|
|
||||||
::CloseHandle(handle_);
|
|
||||||
handle_ = handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
HANDLE handle_;
|
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
|
||||||
};
|
|
||||||
# endif // GTEST_OS_WINDOWS
|
|
||||||
|
|
||||||
// Attempts to parse a string into a positive integer pointed to by the
|
// Attempts to parse a string into a positive integer pointed to by the
|
||||||
// number parameter. Returns true if that is possible.
|
// number parameter. Returns true if that is possible.
|
||||||
|
@ -1021,8 +1014,9 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
||||||
class TestResultAccessor {
|
class TestResultAccessor {
|
||||||
public:
|
public:
|
||||||
static void RecordProperty(TestResult* test_result,
|
static void RecordProperty(TestResult* test_result,
|
||||||
|
const std::string& xml_element,
|
||||||
const TestProperty& property) {
|
const TestProperty& property) {
|
||||||
test_result->RecordProperty(property);
|
test_result->RecordProperty(xml_element, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ClearTestPartResults(TestResult* test_result) {
|
static void ClearTestPartResults(TestResult* test_result) {
|
||||||
|
@ -1035,6 +1029,154 @@ class TestResultAccessor {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if GTEST_CAN_STREAM_RESULTS_
|
||||||
|
|
||||||
|
// Streams test results to the given port on the given host machine.
|
||||||
|
class GTEST_API_ StreamingListener : public EmptyTestEventListener {
|
||||||
|
public:
|
||||||
|
// Abstract base class for writing strings to a socket.
|
||||||
|
class AbstractSocketWriter {
|
||||||
|
public:
|
||||||
|
virtual ~AbstractSocketWriter() {}
|
||||||
|
|
||||||
|
// Sends a string to the socket.
|
||||||
|
virtual void Send(const string& message) = 0;
|
||||||
|
|
||||||
|
// Closes the socket.
|
||||||
|
virtual void CloseConnection() {}
|
||||||
|
|
||||||
|
// Sends a string and a newline to the socket.
|
||||||
|
void SendLn(const string& message) {
|
||||||
|
Send(message + "\n");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Concrete class for actually writing strings to a socket.
|
||||||
|
class SocketWriter : public AbstractSocketWriter {
|
||||||
|
public:
|
||||||
|
SocketWriter(const string& host, const string& port)
|
||||||
|
: sockfd_(-1), host_name_(host), port_num_(port) {
|
||||||
|
MakeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~SocketWriter() {
|
||||||
|
if (sockfd_ != -1)
|
||||||
|
CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sends a string to the socket.
|
||||||
|
virtual void Send(const string& message) {
|
||||||
|
GTEST_CHECK_(sockfd_ != -1)
|
||||||
|
<< "Send() can be called only when there is a connection.";
|
||||||
|
|
||||||
|
const int len = static_cast<int>(message.length());
|
||||||
|
if (write(sockfd_, message.c_str(), len) != len) {
|
||||||
|
GTEST_LOG_(WARNING)
|
||||||
|
<< "stream_result_to: failed to stream to "
|
||||||
|
<< host_name_ << ":" << port_num_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Creates a client socket and connects to the server.
|
||||||
|
void MakeConnection();
|
||||||
|
|
||||||
|
// Closes the socket.
|
||||||
|
void CloseConnection() {
|
||||||
|
GTEST_CHECK_(sockfd_ != -1)
|
||||||
|
<< "CloseConnection() can be called only when there is a connection.";
|
||||||
|
|
||||||
|
close(sockfd_);
|
||||||
|
sockfd_ = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sockfd_; // socket file descriptor
|
||||||
|
const string host_name_;
|
||||||
|
const string port_num_;
|
||||||
|
|
||||||
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
|
||||||
|
}; // class SocketWriter
|
||||||
|
|
||||||
|
// Escapes '=', '&', '%', and '\n' characters in str as "%xx".
|
||||||
|
static string UrlEncode(const char* str);
|
||||||
|
|
||||||
|
StreamingListener(const string& host, const string& port)
|
||||||
|
: socket_writer_(new SocketWriter(host, port)) { Start(); }
|
||||||
|
|
||||||
|
explicit StreamingListener(AbstractSocketWriter* socket_writer)
|
||||||
|
: socket_writer_(socket_writer) { Start(); }
|
||||||
|
|
||||||
|
void OnTestProgramStart(const UnitTest& /* unit_test */) {
|
||||||
|
SendLn("event=TestProgramStart");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestProgramEnd(const UnitTest& unit_test) {
|
||||||
|
// Note that Google Test current only report elapsed time for each
|
||||||
|
// test iteration, not for the entire test program.
|
||||||
|
SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
|
||||||
|
|
||||||
|
// Notify the streaming server to stop.
|
||||||
|
socket_writer_->CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
|
||||||
|
SendLn("event=TestIterationStart&iteration=" +
|
||||||
|
StreamableToString(iteration));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
|
||||||
|
SendLn("event=TestIterationEnd&passed=" +
|
||||||
|
FormatBool(unit_test.Passed()) + "&elapsed_time=" +
|
||||||
|
StreamableToString(unit_test.elapsed_time()) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestCaseStart(const TestCase& test_case) {
|
||||||
|
SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestCaseEnd(const TestCase& test_case) {
|
||||||
|
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
|
||||||
|
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
|
||||||
|
+ "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestStart(const TestInfo& test_info) {
|
||||||
|
SendLn(std::string("event=TestStart&name=") + test_info.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestEnd(const TestInfo& test_info) {
|
||||||
|
SendLn("event=TestEnd&passed=" +
|
||||||
|
FormatBool((test_info.result())->Passed()) +
|
||||||
|
"&elapsed_time=" +
|
||||||
|
StreamableToString((test_info.result())->elapsed_time()) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTestPartResult(const TestPartResult& test_part_result) {
|
||||||
|
const char* file_name = test_part_result.file_name();
|
||||||
|
if (file_name == NULL)
|
||||||
|
file_name = "";
|
||||||
|
SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
|
||||||
|
"&line=" + StreamableToString(test_part_result.line_number()) +
|
||||||
|
"&message=" + UrlEncode(test_part_result.message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Sends the given message and a newline to the socket.
|
||||||
|
void SendLn(const string& message) { socket_writer_->SendLn(message); }
|
||||||
|
|
||||||
|
// Called at the start of streaming to notify the receiver what
|
||||||
|
// protocol we are using.
|
||||||
|
void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
|
||||||
|
|
||||||
|
string FormatBool(bool value) { return value ? "1" : "0"; }
|
||||||
|
|
||||||
|
const scoped_ptr<AbstractSocketWriter> socket_writer_;
|
||||||
|
|
||||||
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
|
||||||
|
}; // class StreamingListener
|
||||||
|
|
||||||
|
#endif // GTEST_CAN_STREAM_RESULTS_
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
|
|
|
@ -35,15 +35,16 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS_MOBILE
|
#if GTEST_OS_WINDOWS
|
||||||
# include <windows.h> // For TerminateProcess()
|
# include <windows.h>
|
||||||
#elif GTEST_OS_WINDOWS
|
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
|
# include <map> // Used in ThreadLocal.
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
#endif // GTEST_OS_WINDOWS
|
||||||
|
|
||||||
#if GTEST_OS_MAC
|
#if GTEST_OS_MAC
|
||||||
# include <mach/mach_init.h>
|
# include <mach/mach_init.h>
|
||||||
|
@ -51,6 +52,17 @@
|
||||||
# include <mach/vm_map.h>
|
# include <mach/vm_map.h>
|
||||||
#endif // GTEST_OS_MAC
|
#endif // GTEST_OS_MAC
|
||||||
|
|
||||||
|
#if GTEST_OS_QNX
|
||||||
|
# include <devctl.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
# include <sys/procfs.h>
|
||||||
|
#endif // GTEST_OS_QNX
|
||||||
|
|
||||||
|
#if GTEST_OS_AIX
|
||||||
|
# include <procinfo.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif // GTEST_OS_AIX
|
||||||
|
|
||||||
#include "gtest/gtest-spi.h"
|
#include "gtest/gtest-spi.h"
|
||||||
#include "gtest/gtest-message.h"
|
#include "gtest/gtest-message.h"
|
||||||
#include "gtest/internal/gtest-internal.h"
|
#include "gtest/internal/gtest-internal.h"
|
||||||
|
@ -58,9 +70,9 @@
|
||||||
|
|
||||||
// Indicates that this translation unit is part of Google Test's
|
// Indicates that this translation unit is part of Google Test's
|
||||||
// implementation. It must come before gtest-internal-inl.h is
|
// implementation. It must come before gtest-internal-inl.h is
|
||||||
// included, or there will be a compiler error. This trick is to
|
// included, or there will be a compiler error. This trick exists to
|
||||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
// prevent the accidental inclusion of gtest-internal-inl.h in the
|
||||||
// his code.
|
// user's code.
|
||||||
#define GTEST_IMPLEMENTATION_ 1
|
#define GTEST_IMPLEMENTATION_ 1
|
||||||
#include "src/gtest-internal-inl.h"
|
#include "src/gtest-internal-inl.h"
|
||||||
#undef GTEST_IMPLEMENTATION_
|
#undef GTEST_IMPLEMENTATION_
|
||||||
|
@ -77,10 +89,31 @@ const int kStdOutFileno = STDOUT_FILENO;
|
||||||
const int kStdErrFileno = STDERR_FILENO;
|
const int kStdErrFileno = STDERR_FILENO;
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
|
|
||||||
#if GTEST_OS_MAC
|
#if GTEST_OS_LINUX
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <typename T>
|
||||||
|
T ReadProcFileField(const string& filename, int field) {
|
||||||
|
std::string dummy;
|
||||||
|
std::ifstream file(filename.c_str());
|
||||||
|
while (field-- > 0) {
|
||||||
|
file >> dummy;
|
||||||
|
}
|
||||||
|
T output = 0;
|
||||||
|
file >> output;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Returns the number of active threads, or 0 when there is an error.
|
||||||
|
size_t GetThreadCount() {
|
||||||
|
const string filename =
|
||||||
|
(Message() << "/proc/" << getpid() << "/stat").GetString();
|
||||||
|
return ReadProcFileField<int>(filename, 19);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif GTEST_OS_MAC
|
||||||
|
|
||||||
// Returns the number of threads running in the process, or 0 to indicate that
|
|
||||||
// we cannot detect it.
|
|
||||||
size_t GetThreadCount() {
|
size_t GetThreadCount() {
|
||||||
const task_t task = mach_task_self();
|
const task_t task = mach_task_self();
|
||||||
mach_msg_type_number_t thread_count;
|
mach_msg_type_number_t thread_count;
|
||||||
|
@ -98,6 +131,39 @@ size_t GetThreadCount() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif GTEST_OS_QNX
|
||||||
|
|
||||||
|
// Returns the number of threads running in the process, or 0 to indicate that
|
||||||
|
// we cannot detect it.
|
||||||
|
size_t GetThreadCount() {
|
||||||
|
const int fd = open("/proc/self/as", O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
procfs_info process_info;
|
||||||
|
const int status =
|
||||||
|
devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), NULL);
|
||||||
|
close(fd);
|
||||||
|
if (status == EOK) {
|
||||||
|
return static_cast<size_t>(process_info.num_threads);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif GTEST_OS_AIX
|
||||||
|
|
||||||
|
size_t GetThreadCount() {
|
||||||
|
struct procentry64 entry;
|
||||||
|
pid_t pid = getpid();
|
||||||
|
int status = getprocs64(&entry, sizeof(entry), NULL, 0, &pid, 1);
|
||||||
|
if (status == 1) {
|
||||||
|
return entry.pi_thcount;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
size_t GetThreadCount() {
|
size_t GetThreadCount() {
|
||||||
|
@ -106,7 +172,390 @@ size_t GetThreadCount() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GTEST_OS_MAC
|
#endif // GTEST_OS_LINUX
|
||||||
|
|
||||||
|
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||||
|
|
||||||
|
void SleepMilliseconds(int n) {
|
||||||
|
::Sleep(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoHandle::AutoHandle()
|
||||||
|
: handle_(INVALID_HANDLE_VALUE) {}
|
||||||
|
|
||||||
|
AutoHandle::AutoHandle(Handle handle)
|
||||||
|
: handle_(handle) {}
|
||||||
|
|
||||||
|
AutoHandle::~AutoHandle() {
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoHandle::Handle AutoHandle::Get() const {
|
||||||
|
return handle_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoHandle::Reset() {
|
||||||
|
Reset(INVALID_HANDLE_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoHandle::Reset(HANDLE handle) {
|
||||||
|
// Resetting with the same handle we already own is invalid.
|
||||||
|
if (handle_ != handle) {
|
||||||
|
if (IsCloseable()) {
|
||||||
|
::CloseHandle(handle_);
|
||||||
|
}
|
||||||
|
handle_ = handle;
|
||||||
|
} else {
|
||||||
|
GTEST_CHECK_(!IsCloseable())
|
||||||
|
<< "Resetting a valid handle to itself is likely a programmer error "
|
||||||
|
"and thus not allowed.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AutoHandle::IsCloseable() const {
|
||||||
|
// Different Windows APIs may use either of these values to represent an
|
||||||
|
// invalid handle.
|
||||||
|
return handle_ != NULL && handle_ != INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::Notification()
|
||||||
|
: event_(::CreateEvent(NULL, // Default security attributes.
|
||||||
|
TRUE, // Do not reset automatically.
|
||||||
|
FALSE, // Initially unset.
|
||||||
|
NULL)) { // Anonymous event.
|
||||||
|
GTEST_CHECK_(event_.Get() != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notification::Notify() {
|
||||||
|
GTEST_CHECK_(::SetEvent(event_.Get()) != FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notification::WaitForNotification() {
|
||||||
|
GTEST_CHECK_(
|
||||||
|
::WaitForSingleObject(event_.Get(), INFINITE) == WAIT_OBJECT_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex::Mutex()
|
||||||
|
: owner_thread_id_(0),
|
||||||
|
type_(kDynamic),
|
||||||
|
critical_section_init_phase_(0),
|
||||||
|
critical_section_(new CRITICAL_SECTION) {
|
||||||
|
::InitializeCriticalSection(critical_section_);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex::~Mutex() {
|
||||||
|
// Static mutexes are leaked intentionally. It is not thread-safe to try
|
||||||
|
// to clean them up.
|
||||||
|
// TODO(yukawa): Switch to Slim Reader/Writer (SRW) Locks, which requires
|
||||||
|
// nothing to clean it up but is available only on Vista and later.
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa904937.aspx
|
||||||
|
if (type_ == kDynamic) {
|
||||||
|
::DeleteCriticalSection(critical_section_);
|
||||||
|
delete critical_section_;
|
||||||
|
critical_section_ = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::Lock() {
|
||||||
|
ThreadSafeLazyInit();
|
||||||
|
::EnterCriticalSection(critical_section_);
|
||||||
|
owner_thread_id_ = ::GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::Unlock() {
|
||||||
|
ThreadSafeLazyInit();
|
||||||
|
// We don't protect writing to owner_thread_id_ here, as it's the
|
||||||
|
// caller's responsibility to ensure that the current thread holds the
|
||||||
|
// mutex when this is called.
|
||||||
|
owner_thread_id_ = 0;
|
||||||
|
::LeaveCriticalSection(critical_section_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Does nothing if the current thread holds the mutex. Otherwise, crashes
|
||||||
|
// with high probability.
|
||||||
|
void Mutex::AssertHeld() {
|
||||||
|
ThreadSafeLazyInit();
|
||||||
|
GTEST_CHECK_(owner_thread_id_ == ::GetCurrentThreadId())
|
||||||
|
<< "The current thread is not holding the mutex @" << this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initializes owner_thread_id_ and critical_section_ in static mutexes.
|
||||||
|
void Mutex::ThreadSafeLazyInit() {
|
||||||
|
// Dynamic mutexes are initialized in the constructor.
|
||||||
|
if (type_ == kStatic) {
|
||||||
|
switch (
|
||||||
|
::InterlockedCompareExchange(&critical_section_init_phase_, 1L, 0L)) {
|
||||||
|
case 0:
|
||||||
|
// If critical_section_init_phase_ was 0 before the exchange, we
|
||||||
|
// are the first to test it and need to perform the initialization.
|
||||||
|
owner_thread_id_ = 0;
|
||||||
|
critical_section_ = new CRITICAL_SECTION;
|
||||||
|
::InitializeCriticalSection(critical_section_);
|
||||||
|
// Updates the critical_section_init_phase_ to 2 to signal
|
||||||
|
// initialization complete.
|
||||||
|
GTEST_CHECK_(::InterlockedCompareExchange(
|
||||||
|
&critical_section_init_phase_, 2L, 1L) ==
|
||||||
|
1L);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
// Somebody else is already initializing the mutex; spin until they
|
||||||
|
// are done.
|
||||||
|
while (::InterlockedCompareExchange(&critical_section_init_phase_,
|
||||||
|
2L,
|
||||||
|
2L) != 2L) {
|
||||||
|
// Possibly yields the rest of the thread's time slice to other
|
||||||
|
// threads.
|
||||||
|
::Sleep(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
break; // The mutex is already initialized and ready for use.
|
||||||
|
|
||||||
|
default:
|
||||||
|
GTEST_CHECK_(false)
|
||||||
|
<< "Unexpected value of critical_section_init_phase_ "
|
||||||
|
<< "while initializing a static mutex.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class ThreadWithParamSupport : public ThreadWithParamBase {
|
||||||
|
public:
|
||||||
|
static HANDLE CreateThread(Runnable* runnable,
|
||||||
|
Notification* thread_can_start) {
|
||||||
|
ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start);
|
||||||
|
DWORD thread_id;
|
||||||
|
// TODO(yukawa): Consider to use _beginthreadex instead.
|
||||||
|
HANDLE thread_handle = ::CreateThread(
|
||||||
|
NULL, // Default security.
|
||||||
|
0, // Default stack size.
|
||||||
|
&ThreadWithParamSupport::ThreadMain,
|
||||||
|
param, // Parameter to ThreadMainStatic
|
||||||
|
0x0, // Default creation flags.
|
||||||
|
&thread_id); // Need a valid pointer for the call to work under Win98.
|
||||||
|
GTEST_CHECK_(thread_handle != NULL) << "CreateThread failed with error "
|
||||||
|
<< ::GetLastError() << ".";
|
||||||
|
if (thread_handle == NULL) {
|
||||||
|
delete param;
|
||||||
|
}
|
||||||
|
return thread_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct ThreadMainParam {
|
||||||
|
ThreadMainParam(Runnable* runnable, Notification* thread_can_start)
|
||||||
|
: runnable_(runnable),
|
||||||
|
thread_can_start_(thread_can_start) {
|
||||||
|
}
|
||||||
|
scoped_ptr<Runnable> runnable_;
|
||||||
|
// Does not own.
|
||||||
|
Notification* thread_can_start_;
|
||||||
|
};
|
||||||
|
|
||||||
|
static DWORD WINAPI ThreadMain(void* ptr) {
|
||||||
|
// Transfers ownership.
|
||||||
|
scoped_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
|
||||||
|
if (param->thread_can_start_ != NULL)
|
||||||
|
param->thread_can_start_->WaitForNotification();
|
||||||
|
param->runnable_->Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prohibit instantiation.
|
||||||
|
ThreadWithParamSupport();
|
||||||
|
|
||||||
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParamSupport);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ThreadWithParamBase::ThreadWithParamBase(Runnable *runnable,
|
||||||
|
Notification* thread_can_start)
|
||||||
|
: thread_(ThreadWithParamSupport::CreateThread(runnable,
|
||||||
|
thread_can_start)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadWithParamBase::~ThreadWithParamBase() {
|
||||||
|
Join();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadWithParamBase::Join() {
|
||||||
|
GTEST_CHECK_(::WaitForSingleObject(thread_.Get(), INFINITE) == WAIT_OBJECT_0)
|
||||||
|
<< "Failed to join the thread with error " << ::GetLastError() << ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maps a thread to a set of ThreadIdToThreadLocals that have values
|
||||||
|
// instantiated on that thread and notifies them when the thread exits. A
|
||||||
|
// ThreadLocal instance is expected to persist until all threads it has
|
||||||
|
// values on have terminated.
|
||||||
|
class ThreadLocalRegistryImpl {
|
||||||
|
public:
|
||||||
|
// Registers thread_local_instance as having value on the current thread.
|
||||||
|
// Returns a value that can be used to identify the thread from other threads.
|
||||||
|
static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
|
||||||
|
const ThreadLocalBase* thread_local_instance) {
|
||||||
|
DWORD current_thread = ::GetCurrentThreadId();
|
||||||
|
MutexLock lock(&mutex_);
|
||||||
|
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||||
|
GetThreadLocalsMapLocked();
|
||||||
|
ThreadIdToThreadLocals::iterator thread_local_pos =
|
||||||
|
thread_to_thread_locals->find(current_thread);
|
||||||
|
if (thread_local_pos == thread_to_thread_locals->end()) {
|
||||||
|
thread_local_pos = thread_to_thread_locals->insert(
|
||||||
|
std::make_pair(current_thread, ThreadLocalValues())).first;
|
||||||
|
StartWatcherThreadFor(current_thread);
|
||||||
|
}
|
||||||
|
ThreadLocalValues& thread_local_values = thread_local_pos->second;
|
||||||
|
ThreadLocalValues::iterator value_pos =
|
||||||
|
thread_local_values.find(thread_local_instance);
|
||||||
|
if (value_pos == thread_local_values.end()) {
|
||||||
|
value_pos =
|
||||||
|
thread_local_values
|
||||||
|
.insert(std::make_pair(
|
||||||
|
thread_local_instance,
|
||||||
|
linked_ptr<ThreadLocalValueHolderBase>(
|
||||||
|
thread_local_instance->NewValueForCurrentThread())))
|
||||||
|
.first;
|
||||||
|
}
|
||||||
|
return value_pos->second.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnThreadLocalDestroyed(
|
||||||
|
const ThreadLocalBase* thread_local_instance) {
|
||||||
|
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||||
|
// Clean up the ThreadLocalValues data structure while holding the lock, but
|
||||||
|
// defer the destruction of the ThreadLocalValueHolderBases.
|
||||||
|
{
|
||||||
|
MutexLock lock(&mutex_);
|
||||||
|
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||||
|
GetThreadLocalsMapLocked();
|
||||||
|
for (ThreadIdToThreadLocals::iterator it =
|
||||||
|
thread_to_thread_locals->begin();
|
||||||
|
it != thread_to_thread_locals->end();
|
||||||
|
++it) {
|
||||||
|
ThreadLocalValues& thread_local_values = it->second;
|
||||||
|
ThreadLocalValues::iterator value_pos =
|
||||||
|
thread_local_values.find(thread_local_instance);
|
||||||
|
if (value_pos != thread_local_values.end()) {
|
||||||
|
value_holders.push_back(value_pos->second);
|
||||||
|
thread_local_values.erase(value_pos);
|
||||||
|
// This 'if' can only be successful at most once, so theoretically we
|
||||||
|
// could break out of the loop here, but we don't bother doing so.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Outside the lock, let the destructor for 'value_holders' deallocate the
|
||||||
|
// ThreadLocalValueHolderBases.
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnThreadExit(DWORD thread_id) {
|
||||||
|
GTEST_CHECK_(thread_id != 0) << ::GetLastError();
|
||||||
|
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||||
|
// Clean up the ThreadIdToThreadLocals data structure while holding the
|
||||||
|
// lock, but defer the destruction of the ThreadLocalValueHolderBases.
|
||||||
|
{
|
||||||
|
MutexLock lock(&mutex_);
|
||||||
|
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||||
|
GetThreadLocalsMapLocked();
|
||||||
|
ThreadIdToThreadLocals::iterator thread_local_pos =
|
||||||
|
thread_to_thread_locals->find(thread_id);
|
||||||
|
if (thread_local_pos != thread_to_thread_locals->end()) {
|
||||||
|
ThreadLocalValues& thread_local_values = thread_local_pos->second;
|
||||||
|
for (ThreadLocalValues::iterator value_pos =
|
||||||
|
thread_local_values.begin();
|
||||||
|
value_pos != thread_local_values.end();
|
||||||
|
++value_pos) {
|
||||||
|
value_holders.push_back(value_pos->second);
|
||||||
|
}
|
||||||
|
thread_to_thread_locals->erase(thread_local_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Outside the lock, let the destructor for 'value_holders' deallocate the
|
||||||
|
// ThreadLocalValueHolderBases.
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// In a particular thread, maps a ThreadLocal object to its value.
|
||||||
|
typedef std::map<const ThreadLocalBase*,
|
||||||
|
linked_ptr<ThreadLocalValueHolderBase> > ThreadLocalValues;
|
||||||
|
// Stores all ThreadIdToThreadLocals having values in a thread, indexed by
|
||||||
|
// thread's ID.
|
||||||
|
typedef std::map<DWORD, ThreadLocalValues> ThreadIdToThreadLocals;
|
||||||
|
|
||||||
|
// Holds the thread id and thread handle that we pass from
|
||||||
|
// StartWatcherThreadFor to WatcherThreadFunc.
|
||||||
|
typedef std::pair<DWORD, HANDLE> ThreadIdAndHandle;
|
||||||
|
|
||||||
|
static void StartWatcherThreadFor(DWORD thread_id) {
|
||||||
|
// The returned handle will be kept in thread_map and closed by
|
||||||
|
// watcher_thread in WatcherThreadFunc.
|
||||||
|
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
|
||||||
|
FALSE,
|
||||||
|
thread_id);
|
||||||
|
GTEST_CHECK_(thread != NULL);
|
||||||
|
// We need to to pass a valid thread ID pointer into CreateThread for it
|
||||||
|
// to work correctly under Win98.
|
||||||
|
DWORD watcher_thread_id;
|
||||||
|
HANDLE watcher_thread = ::CreateThread(
|
||||||
|
NULL, // Default security.
|
||||||
|
0, // Default stack size
|
||||||
|
&ThreadLocalRegistryImpl::WatcherThreadFunc,
|
||||||
|
reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
|
||||||
|
CREATE_SUSPENDED,
|
||||||
|
&watcher_thread_id);
|
||||||
|
GTEST_CHECK_(watcher_thread != NULL);
|
||||||
|
// Give the watcher thread the same priority as ours to avoid being
|
||||||
|
// blocked by it.
|
||||||
|
::SetThreadPriority(watcher_thread,
|
||||||
|
::GetThreadPriority(::GetCurrentThread()));
|
||||||
|
::ResumeThread(watcher_thread);
|
||||||
|
::CloseHandle(watcher_thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Monitors exit from a given thread and notifies those
|
||||||
|
// ThreadIdToThreadLocals about thread termination.
|
||||||
|
static DWORD WINAPI WatcherThreadFunc(LPVOID param) {
|
||||||
|
const ThreadIdAndHandle* tah =
|
||||||
|
reinterpret_cast<const ThreadIdAndHandle*>(param);
|
||||||
|
GTEST_CHECK_(
|
||||||
|
::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0);
|
||||||
|
OnThreadExit(tah->first);
|
||||||
|
::CloseHandle(tah->second);
|
||||||
|
delete tah;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns map of thread local instances.
|
||||||
|
static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() {
|
||||||
|
mutex_.AssertHeld();
|
||||||
|
static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals;
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protects access to GetThreadLocalsMapLocked() and its return value.
|
||||||
|
static Mutex mutex_;
|
||||||
|
// Protects access to GetThreadMapLocked() and its return value.
|
||||||
|
static Mutex thread_map_mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
Mutex ThreadLocalRegistryImpl::mutex_(Mutex::kStaticMutex);
|
||||||
|
Mutex ThreadLocalRegistryImpl::thread_map_mutex_(Mutex::kStaticMutex);
|
||||||
|
|
||||||
|
ThreadLocalValueHolderBase* ThreadLocalRegistry::GetValueOnCurrentThread(
|
||||||
|
const ThreadLocalBase* thread_local_instance) {
|
||||||
|
return ThreadLocalRegistryImpl::GetValueOnCurrentThread(
|
||||||
|
thread_local_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalRegistry::OnThreadLocalDestroyed(
|
||||||
|
const ThreadLocalBase* thread_local_instance) {
|
||||||
|
ThreadLocalRegistryImpl::OnThreadLocalDestroyed(thread_local_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||||
|
|
||||||
#if GTEST_USES_POSIX_RE
|
#if GTEST_USES_POSIX_RE
|
||||||
|
|
||||||
|
@ -222,7 +671,7 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function used by ValidateRegex() to format error messages.
|
// Helper function used by ValidateRegex() to format error messages.
|
||||||
String FormatRegexSyntaxError(const char* regex, int index) {
|
std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||||
return (Message() << "Syntax error at index " << index
|
return (Message() << "Syntax error at index " << index
|
||||||
<< " in simple regular expression \"" << regex << "\": ").GetString();
|
<< " in simple regular expression \"" << regex << "\": ").GetString();
|
||||||
}
|
}
|
||||||
|
@ -429,15 +878,15 @@ const char kUnknownFile[] = "unknown file";
|
||||||
// Formats a source file path and a line number as they would appear
|
// Formats a source file path and a line number as they would appear
|
||||||
// in an error message from the compiler used to compile this code.
|
// in an error message from the compiler used to compile this code.
|
||||||
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
|
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
|
||||||
const char* const file_name = file == NULL ? kUnknownFile : file;
|
const std::string file_name(file == NULL ? kUnknownFile : file);
|
||||||
|
|
||||||
if (line < 0) {
|
if (line < 0) {
|
||||||
return String::Format("%s:", file_name).c_str();
|
return file_name + ":";
|
||||||
}
|
}
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
return String::Format("%s(%d):", file_name, line).c_str();
|
return file_name + "(" + StreamableToString(line) + "):";
|
||||||
#else
|
#else
|
||||||
return String::Format("%s:%d:", file_name, line).c_str();
|
return file_name + ":" + StreamableToString(line) + ":";
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,15 +897,14 @@ GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
|
||||||
// to the file location it produces, unlike FormatFileLocation().
|
// to the file location it produces, unlike FormatFileLocation().
|
||||||
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
|
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
|
||||||
const char* file, int line) {
|
const char* file, int line) {
|
||||||
const char* const file_name = file == NULL ? kUnknownFile : file;
|
const std::string file_name(file == NULL ? kUnknownFile : file);
|
||||||
|
|
||||||
if (line < 0)
|
if (line < 0)
|
||||||
return file_name;
|
return file_name;
|
||||||
else
|
else
|
||||||
return String::Format("%s:%d", file_name, line).c_str();
|
return file_name + ":" + StreamableToString(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
|
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
|
||||||
: severity_(severity) {
|
: severity_(severity) {
|
||||||
const char* const marker =
|
const char* const marker =
|
||||||
|
@ -477,10 +925,7 @@ GTestLog::~GTestLog() {
|
||||||
}
|
}
|
||||||
// Disable Microsoft deprecation warnings for POSIX functions called from
|
// Disable Microsoft deprecation warnings for POSIX functions called from
|
||||||
// this class (creat, dup, dup2, and close)
|
// this class (creat, dup, dup2, and close)
|
||||||
#ifdef _MSC_VER
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
|
||||||
# pragma warning(push)
|
|
||||||
# pragma warning(disable: 4996)
|
|
||||||
#endif // _MSC_VER
|
|
||||||
|
|
||||||
#if GTEST_HAS_STREAM_REDIRECTION
|
#if GTEST_HAS_STREAM_REDIRECTION
|
||||||
|
|
||||||
|
@ -488,8 +933,7 @@ GTestLog::~GTestLog() {
|
||||||
class CapturedStream {
|
class CapturedStream {
|
||||||
public:
|
public:
|
||||||
// The ctor redirects the stream to a temporary file.
|
// The ctor redirects the stream to a temporary file.
|
||||||
CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
|
explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
|
||||||
|
|
||||||
# if GTEST_OS_WINDOWS
|
# if GTEST_OS_WINDOWS
|
||||||
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
||||||
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
||||||
|
@ -505,15 +949,30 @@ class CapturedStream {
|
||||||
GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
|
GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
|
||||||
<< temp_file_path;
|
<< temp_file_path;
|
||||||
filename_ = temp_file_path;
|
filename_ = temp_file_path;
|
||||||
#elif GTEST_OS_LINUX_ANDROID
|
|
||||||
char name_template[] = "/sdcard/captured_stderr.XXXXXX";
|
|
||||||
const int captured_fd = mkstemp(name_template);
|
|
||||||
filename_ = name_template;
|
|
||||||
# else
|
# else
|
||||||
// There's no guarantee that a test has write access to the
|
// There's no guarantee that a test has write access to the current
|
||||||
// current directory, so we create the temporary file in the /tmp
|
// directory, so we create the temporary file in the /tmp directory
|
||||||
// directory instead.
|
// instead. We use /tmp on most systems, and /sdcard on Android.
|
||||||
|
// That's because Android doesn't have /tmp.
|
||||||
|
# if GTEST_OS_LINUX_ANDROID
|
||||||
|
// Note: Android applications are expected to call the framework's
|
||||||
|
// Context.getExternalStorageDirectory() method through JNI to get
|
||||||
|
// the location of the world-writable SD Card directory. However,
|
||||||
|
// this requires a Context handle, which cannot be retrieved
|
||||||
|
// globally from native code. Doing so also precludes running the
|
||||||
|
// code as part of a regular standalone executable, which doesn't
|
||||||
|
// run in a Dalvik process (e.g. when running it through 'adb shell').
|
||||||
|
//
|
||||||
|
// The location /sdcard is directly accessible from native code
|
||||||
|
// and is the only location (unofficially) supported by the Android
|
||||||
|
// team. It's generally a symlink to the real SD Card mount point
|
||||||
|
// which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
|
||||||
|
// other OEM-customized locations. Never rely on these, and always
|
||||||
|
// use /sdcard.
|
||||||
|
char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX";
|
||||||
|
# else
|
||||||
char name_template[] = "/tmp/captured_stream.XXXXXX";
|
char name_template[] = "/tmp/captured_stream.XXXXXX";
|
||||||
|
# endif // GTEST_OS_LINUX_ANDROID
|
||||||
const int captured_fd = mkstemp(name_template);
|
const int captured_fd = mkstemp(name_template);
|
||||||
filename_ = name_template;
|
filename_ = name_template;
|
||||||
# endif // GTEST_OS_WINDOWS
|
# endif // GTEST_OS_WINDOWS
|
||||||
|
@ -526,7 +985,7 @@ class CapturedStream {
|
||||||
remove(filename_.c_str());
|
remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
String GetCapturedString() {
|
std::string GetCapturedString() {
|
||||||
if (uncaptured_fd_ != -1) {
|
if (uncaptured_fd_ != -1) {
|
||||||
// Restores the original stream.
|
// Restores the original stream.
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
@ -536,18 +995,12 @@ class CapturedStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* const file = posix::FOpen(filename_.c_str(), "r");
|
FILE* const file = posix::FOpen(filename_.c_str(), "r");
|
||||||
const String content = ReadEntireFile(file);
|
const std::string content = ReadEntireFile(file);
|
||||||
posix::FClose(file);
|
posix::FClose(file);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Reads the entire content of a file as a String.
|
|
||||||
static String ReadEntireFile(FILE* file);
|
|
||||||
|
|
||||||
// Returns the size (in bytes) of a file.
|
|
||||||
static size_t GetFileSize(FILE* file);
|
|
||||||
|
|
||||||
const int fd_; // A stream to capture.
|
const int fd_; // A stream to capture.
|
||||||
int uncaptured_fd_;
|
int uncaptured_fd_;
|
||||||
// Name of the temporary file holding the stderr output.
|
// Name of the temporary file holding the stderr output.
|
||||||
|
@ -556,38 +1009,7 @@ class CapturedStream {
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns the size (in bytes) of a file.
|
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||||
size_t CapturedStream::GetFileSize(FILE* file) {
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
return static_cast<size_t>(ftell(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads the entire content of a file as a string.
|
|
||||||
String CapturedStream::ReadEntireFile(FILE* file) {
|
|
||||||
const size_t file_size = GetFileSize(file);
|
|
||||||
char* const buffer = new char[file_size];
|
|
||||||
|
|
||||||
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
|
||||||
size_t bytes_read = 0; // # of bytes read so far
|
|
||||||
|
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
|
|
||||||
// Keeps reading the file until we cannot read further or the
|
|
||||||
// pre-determined file size is reached.
|
|
||||||
do {
|
|
||||||
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
|
|
||||||
bytes_read += bytes_last_read;
|
|
||||||
} while (bytes_last_read > 0 && bytes_read < file_size);
|
|
||||||
|
|
||||||
const String content(buffer, bytes_read);
|
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef _MSC_VER
|
|
||||||
# pragma warning(pop)
|
|
||||||
# endif // _MSC_VER
|
|
||||||
|
|
||||||
static CapturedStream* g_captured_stderr = NULL;
|
static CapturedStream* g_captured_stderr = NULL;
|
||||||
static CapturedStream* g_captured_stdout = NULL;
|
static CapturedStream* g_captured_stdout = NULL;
|
||||||
|
@ -602,8 +1024,8 @@ void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stops capturing the output stream and returns the captured string.
|
// Stops capturing the output stream and returns the captured string.
|
||||||
String GetCapturedStream(CapturedStream** captured_stream) {
|
std::string GetCapturedStream(CapturedStream** captured_stream) {
|
||||||
const String content = (*captured_stream)->GetCapturedString();
|
const std::string content = (*captured_stream)->GetCapturedString();
|
||||||
|
|
||||||
delete *captured_stream;
|
delete *captured_stream;
|
||||||
*captured_stream = NULL;
|
*captured_stream = NULL;
|
||||||
|
@ -622,21 +1044,79 @@ void CaptureStderr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stops capturing stdout and returns the captured string.
|
// Stops capturing stdout and returns the captured string.
|
||||||
String GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); }
|
std::string GetCapturedStdout() {
|
||||||
|
return GetCapturedStream(&g_captured_stdout);
|
||||||
|
}
|
||||||
|
|
||||||
// Stops capturing stderr and returns the captured string.
|
// Stops capturing stderr and returns the captured string.
|
||||||
String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }
|
std::string GetCapturedStderr() {
|
||||||
|
return GetCapturedStream(&g_captured_stderr);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||||
|
|
||||||
|
std::string TempDir() {
|
||||||
|
#if GTEST_OS_WINDOWS_MOBILE
|
||||||
|
return "\\temp\\";
|
||||||
|
#elif GTEST_OS_WINDOWS
|
||||||
|
const char* temp_dir = posix::GetEnv("TEMP");
|
||||||
|
if (temp_dir == NULL || temp_dir[0] == '\0')
|
||||||
|
return "\\temp\\";
|
||||||
|
else if (temp_dir[strlen(temp_dir) - 1] == '\\')
|
||||||
|
return temp_dir;
|
||||||
|
else
|
||||||
|
return std::string(temp_dir) + "\\";
|
||||||
|
#elif GTEST_OS_LINUX_ANDROID
|
||||||
|
return "/sdcard/";
|
||||||
|
#else
|
||||||
|
return "/tmp/";
|
||||||
|
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetFileSize(FILE* file) {
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
return static_cast<size_t>(ftell(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ReadEntireFile(FILE* file) {
|
||||||
|
const size_t file_size = GetFileSize(file);
|
||||||
|
char* const buffer = new char[file_size];
|
||||||
|
|
||||||
|
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
||||||
|
size_t bytes_read = 0; // # of bytes read so far
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_SET);
|
||||||
|
|
||||||
|
// Keeps reading the file until we cannot read further or the
|
||||||
|
// pre-determined file size is reached.
|
||||||
|
do {
|
||||||
|
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
|
||||||
|
bytes_read += bytes_last_read;
|
||||||
|
} while (bytes_last_read > 0 && bytes_read < file_size);
|
||||||
|
|
||||||
|
const std::string content(buffer, bytes_read);
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
// A copy of all command line arguments. Set by InitGoogleTest().
|
static const ::std::vector<testing::internal::string>* g_injected_test_argvs =
|
||||||
::std::vector<String> g_argvs;
|
NULL; // Owned.
|
||||||
|
|
||||||
// Returns the command line as a vector of strings.
|
void SetInjectableArgvs(const ::std::vector<testing::internal::string>* argvs) {
|
||||||
const ::std::vector<String>& GetArgvs() { return g_argvs; }
|
if (g_injected_test_argvs != argvs)
|
||||||
|
delete g_injected_test_argvs;
|
||||||
|
g_injected_test_argvs = argvs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ::std::vector<testing::internal::string>& GetInjectableArgvs() {
|
||||||
|
if (g_injected_test_argvs != NULL) {
|
||||||
|
return *g_injected_test_argvs;
|
||||||
|
}
|
||||||
|
return GetArgvs();
|
||||||
|
}
|
||||||
#endif // GTEST_HAS_DEATH_TEST
|
#endif // GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS_MOBILE
|
#if GTEST_OS_WINDOWS_MOBILE
|
||||||
|
@ -651,8 +1131,8 @@ void Abort() {
|
||||||
// Returns the name of the environment variable corresponding to the
|
// Returns the name of the environment variable corresponding to the
|
||||||
// given flag. For example, FlagToEnvVar("foo") will return
|
// given flag. For example, FlagToEnvVar("foo") will return
|
||||||
// "GTEST_FOO" in the open-source version.
|
// "GTEST_FOO" in the open-source version.
|
||||||
static String FlagToEnvVar(const char* flag) {
|
static std::string FlagToEnvVar(const char* flag) {
|
||||||
const String full_flag =
|
const std::string full_flag =
|
||||||
(Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
|
(Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
|
||||||
|
|
||||||
Message env_var;
|
Message env_var;
|
||||||
|
@ -709,7 +1189,10 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
|
||||||
//
|
//
|
||||||
// The value is considered true iff it's not "0".
|
// The value is considered true iff it's not "0".
|
||||||
bool BoolFromGTestEnv(const char* flag, bool default_value) {
|
bool BoolFromGTestEnv(const char* flag, bool default_value) {
|
||||||
const String env_var = FlagToEnvVar(flag);
|
#if defined(GTEST_GET_BOOL_FROM_ENV_)
|
||||||
|
return GTEST_GET_BOOL_FROM_ENV_(flag, default_value);
|
||||||
|
#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
|
||||||
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||||
return string_value == NULL ?
|
return string_value == NULL ?
|
||||||
default_value : strcmp(string_value, "0") != 0;
|
default_value : strcmp(string_value, "0") != 0;
|
||||||
|
@ -719,7 +1202,10 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
|
||||||
// variable corresponding to the given flag; if it isn't set or
|
// variable corresponding to the given flag; if it isn't set or
|
||||||
// doesn't represent a valid 32-bit integer, returns default_value.
|
// doesn't represent a valid 32-bit integer, returns default_value.
|
||||||
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
||||||
const String env_var = FlagToEnvVar(flag);
|
#if defined(GTEST_GET_INT32_FROM_ENV_)
|
||||||
|
return GTEST_GET_INT32_FROM_ENV_(flag, default_value);
|
||||||
|
#endif // defined(GTEST_GET_INT32_FROM_ENV_)
|
||||||
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||||
if (string_value == NULL) {
|
if (string_value == NULL) {
|
||||||
// The environment variable is not set.
|
// The environment variable is not set.
|
||||||
|
@ -740,25 +1226,34 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
||||||
|
|
||||||
// Reads and returns the string environment variable corresponding to
|
// Reads and returns the string environment variable corresponding to
|
||||||
// the given flag; if it's not set, returns default_value.
|
// the given flag; if it's not set, returns default_value.
|
||||||
const char* StringFromGTestEnv(const char* flag, const char* default_value) {
|
std::string StringFromGTestEnv(const char* flag, const char* default_value) {
|
||||||
const String env_var = FlagToEnvVar(flag);
|
#if defined(GTEST_GET_STRING_FROM_ENV_)
|
||||||
const char* const value = posix::GetEnv(env_var.c_str());
|
return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
|
||||||
return value == NULL ? default_value : value;
|
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
|
||||||
}
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
|
const char* value = posix::GetEnv(env_var.c_str());
|
||||||
|
if (value != NULL) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
// Pin the vtables to this file.
|
// As a special case for the 'output' flag, if GTEST_OUTPUT is not
|
||||||
#if GTEST_HAS_PTHREAD
|
// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build
|
||||||
ThreadWithParamBase::~ThreadWithParamBase() {}
|
// system. The value of XML_OUTPUT_FILE is a filename without the
|
||||||
ThreadLocalValueHolderBase::~ThreadLocalValueHolderBase() {}
|
// "xml:" prefix of GTEST_OUTPUT.
|
||||||
#endif
|
//
|
||||||
TestFactoryBase::~TestFactoryBase() {}
|
// The net priority order after flag processing is thus:
|
||||||
|
// --gtest_output command line flag
|
||||||
|
// GTEST_OUTPUT environment variable
|
||||||
|
// XML_OUTPUT_FILE environment variable
|
||||||
|
// 'default_value'
|
||||||
|
if (strcmp(flag, "output") == 0) {
|
||||||
|
value = posix::GetEnv("XML_OUTPUT_FILE");
|
||||||
|
if (value != NULL) {
|
||||||
|
return std::string("xml:") + value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
// Pin the vtable to this file.
|
|
||||||
#if !GTEST_NO_LLVM_RAW_OSTREAM
|
|
||||||
namespace llvm {
|
|
||||||
void convertible_fwd_ostream::anchor() {}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "gtest/gtest-printers.h"
|
#include "gtest/gtest-printers.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <cwchar>
|
||||||
#include <ostream> // NOLINT
|
#include <ostream> // NOLINT
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "gtest/internal/gtest-port.h"
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
@ -55,15 +56,10 @@ namespace {
|
||||||
|
|
||||||
using ::std::ostream;
|
using ::std::ostream;
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
|
|
||||||
# define snprintf _snprintf
|
|
||||||
#elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
|
|
||||||
# define snprintf _snprintf_s
|
|
||||||
#elif _MSC_VER
|
|
||||||
# define snprintf _snprintf
|
|
||||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
|
||||||
|
|
||||||
// Prints a segment of bytes in the given object.
|
// Prints a segment of bytes in the given object.
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||||
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
|
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
|
||||||
size_t count, ostream* os) {
|
size_t count, ostream* os) {
|
||||||
char text[5] = "";
|
char text[5] = "";
|
||||||
|
@ -77,7 +73,7 @@ void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
|
||||||
else
|
else
|
||||||
*os << '-';
|
*os << '-';
|
||||||
}
|
}
|
||||||
snprintf(text, sizeof(text), "%02X", obj_bytes[j]);
|
GTEST_SNPRINTF_(text, sizeof(text), "%02X", obj_bytes[j]);
|
||||||
*os << text;
|
*os << text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +123,7 @@ namespace internal {
|
||||||
// Depending on the value of a char (or wchar_t), we print it in one
|
// Depending on the value of a char (or wchar_t), we print it in one
|
||||||
// of three formats:
|
// of three formats:
|
||||||
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
|
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
|
||||||
// - as a hexadecimal escape sequence (e.g. '\x7F'), or
|
// - as a hexidecimal escape sequence (e.g. '\x7F'), or
|
||||||
// - as a special escape sequence (e.g. '\r', '\n').
|
// - as a special escape sequence (e.g. '\r', '\n').
|
||||||
enum CharFormat {
|
enum CharFormat {
|
||||||
kAsIs,
|
kAsIs,
|
||||||
|
@ -184,16 +180,16 @@ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
|
||||||
*os << static_cast<char>(c);
|
*os << static_cast<char>(c);
|
||||||
return kAsIs;
|
return kAsIs;
|
||||||
} else {
|
} else {
|
||||||
*os << String::Format("\\x%X", static_cast<UnsignedChar>(c));
|
*os << "\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c));
|
||||||
return kHexEscape;
|
return kHexEscape;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return kSpecialEscape;
|
return kSpecialEscape;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints a char c as if it's part of a string literal, escaping it when
|
// Prints a wchar_t c as if it's part of a string literal, escaping it when
|
||||||
// necessary; returns how c was formatted.
|
// necessary; returns how c was formatted.
|
||||||
static CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {
|
static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case L'\'':
|
case L'\'':
|
||||||
*os << "'";
|
*os << "'";
|
||||||
|
@ -208,8 +204,9 @@ static CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {
|
||||||
|
|
||||||
// Prints a char c as if it's part of a string literal, escaping it when
|
// Prints a char c as if it's part of a string literal, escaping it when
|
||||||
// necessary; returns how c was formatted.
|
// necessary; returns how c was formatted.
|
||||||
static CharFormat PrintAsNarrowStringLiteralTo(char c, ostream* os) {
|
static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
|
||||||
return PrintAsWideStringLiteralTo(static_cast<unsigned char>(c), os);
|
return PrintAsStringLiteralTo(
|
||||||
|
static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints a wide or narrow character c and its code. '\0' is printed
|
// Prints a wide or narrow character c and its code. '\0' is printed
|
||||||
|
@ -228,16 +225,15 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
|
||||||
// obvious).
|
// obvious).
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
return;
|
return;
|
||||||
*os << " (" << String::Format("%d", c).c_str();
|
*os << " (" << static_cast<int>(c);
|
||||||
|
|
||||||
// For more convenience, we print c's code again in hexadecimal,
|
// For more convenience, we print c's code again in hexidecimal,
|
||||||
// unless c was already printed in the form '\x##' or the code is in
|
// unless c was already printed in the form '\x##' or the code is in
|
||||||
// [1, 9].
|
// [1, 9].
|
||||||
if (format == kHexEscape || (1 <= c && c <= 9)) {
|
if (format == kHexEscape || (1 <= c && c <= 9)) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
} else {
|
} else {
|
||||||
*os << String::Format(", 0x%X",
|
*os << ", 0x" << String::FormatHexInt(static_cast<UnsignedChar>(c));
|
||||||
static_cast<UnsignedChar>(c)).c_str();
|
|
||||||
}
|
}
|
||||||
*os << ")";
|
*os << ")";
|
||||||
}
|
}
|
||||||
|
@ -255,48 +251,69 @@ void PrintTo(wchar_t wc, ostream* os) {
|
||||||
PrintCharAndCodeTo<wchar_t>(wc, os);
|
PrintCharAndCodeTo<wchar_t>(wc, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the given array of characters to the ostream.
|
// Prints the given array of characters to the ostream. CharType must be either
|
||||||
// The array starts at *begin, the length is len, it may include '\0' characters
|
// char or wchar_t.
|
||||||
// and may not be null-terminated.
|
// The array starts at begin, the length is len, it may include '\0' characters
|
||||||
static void PrintCharsAsStringTo(const char* begin, size_t len, ostream* os) {
|
// and may not be NUL-terminated.
|
||||||
*os << "\"";
|
template <typename CharType>
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||||
|
static void PrintCharsAsStringTo(
|
||||||
|
const CharType* begin, size_t len, ostream* os) {
|
||||||
|
const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
|
||||||
|
*os << kQuoteBegin;
|
||||||
bool is_previous_hex = false;
|
bool is_previous_hex = false;
|
||||||
for (size_t index = 0; index < len; ++index) {
|
for (size_t index = 0; index < len; ++index) {
|
||||||
const char cur = begin[index];
|
const CharType cur = begin[index];
|
||||||
if (is_previous_hex && IsXDigit(cur)) {
|
if (is_previous_hex && IsXDigit(cur)) {
|
||||||
// Previous character is of '\x..' form and this character can be
|
// Previous character is of '\x..' form and this character can be
|
||||||
// interpreted as another hexadecimal digit in its number. Break string to
|
// interpreted as another hexadecimal digit in its number. Break string to
|
||||||
// disambiguate.
|
// disambiguate.
|
||||||
*os << "\" \"";
|
*os << "\" " << kQuoteBegin;
|
||||||
}
|
}
|
||||||
is_previous_hex = PrintAsNarrowStringLiteralTo(cur, os) == kHexEscape;
|
is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
|
||||||
}
|
}
|
||||||
*os << "\"";
|
*os << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
|
||||||
|
// 'begin'. CharType must be either char or wchar_t.
|
||||||
|
template <typename CharType>
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||||
|
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||||
|
static void UniversalPrintCharArray(
|
||||||
|
const CharType* begin, size_t len, ostream* os) {
|
||||||
|
// The code
|
||||||
|
// const char kFoo[] = "foo";
|
||||||
|
// generates an array of 4, not 3, elements, with the last one being '\0'.
|
||||||
|
//
|
||||||
|
// Therefore when printing a char array, we don't print the last element if
|
||||||
|
// it's '\0', such that the output matches the string literal as it's
|
||||||
|
// written in the source code.
|
||||||
|
if (len > 0 && begin[len - 1] == '\0') {
|
||||||
|
PrintCharsAsStringTo(begin, len - 1, os);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If, however, the last element in the array is not '\0', e.g.
|
||||||
|
// const char kFoo[] = { 'f', 'o', 'o' };
|
||||||
|
// we must print the entire array. We also print a message to indicate
|
||||||
|
// that the array is not NUL-terminated.
|
||||||
|
PrintCharsAsStringTo(begin, len, os);
|
||||||
|
*os << " (no terminating NUL)";
|
||||||
|
}
|
||||||
|
|
||||||
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
|
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
|
||||||
void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
|
void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
|
||||||
PrintCharsAsStringTo(begin, len, os);
|
UniversalPrintCharArray(begin, len, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the given array of wide characters to the ostream.
|
// Prints a (const) wchar_t array of 'len' elements, starting at address
|
||||||
// The array starts at *begin, the length is len, it may include L'\0'
|
// 'begin'.
|
||||||
// characters and may not be null-terminated.
|
void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) {
|
||||||
static void PrintWideCharsAsStringTo(const wchar_t* begin, size_t len,
|
UniversalPrintCharArray(begin, len, os);
|
||||||
ostream* os) {
|
|
||||||
*os << "L\"";
|
|
||||||
bool is_previous_hex = false;
|
|
||||||
for (size_t index = 0; index < len; ++index) {
|
|
||||||
const wchar_t cur = begin[index];
|
|
||||||
if (is_previous_hex && isascii(cur) && IsXDigit(static_cast<char>(cur))) {
|
|
||||||
// Previous character is of '\x..' form and this character can be
|
|
||||||
// interpreted as another hexadecimal digit in its number. Break string to
|
|
||||||
// disambiguate.
|
|
||||||
*os << "\" L\"";
|
|
||||||
}
|
|
||||||
is_previous_hex = PrintAsWideStringLiteralTo(cur, os) == kHexEscape;
|
|
||||||
}
|
|
||||||
*os << "\"";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the given C string to the ostream.
|
// Prints the given C string to the ostream.
|
||||||
|
@ -322,7 +339,7 @@ void PrintTo(const wchar_t* s, ostream* os) {
|
||||||
*os << "NULL";
|
*os << "NULL";
|
||||||
} else {
|
} else {
|
||||||
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
||||||
PrintWideCharsAsStringTo(s, wcslen(s), os);
|
PrintCharsAsStringTo(s, std::wcslen(s), os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // wchar_t is native
|
#endif // wchar_t is native
|
||||||
|
@ -341,13 +358,13 @@ void PrintStringTo(const ::std::string& s, ostream* os) {
|
||||||
// Prints a ::wstring object.
|
// Prints a ::wstring object.
|
||||||
#if GTEST_HAS_GLOBAL_WSTRING
|
#if GTEST_HAS_GLOBAL_WSTRING
|
||||||
void PrintWideStringTo(const ::wstring& s, ostream* os) {
|
void PrintWideStringTo(const ::wstring& s, ostream* os) {
|
||||||
PrintWideCharsAsStringTo(s.data(), s.size(), os);
|
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
#endif // GTEST_HAS_GLOBAL_WSTRING
|
||||||
|
|
||||||
#if GTEST_HAS_STD_WSTRING
|
#if GTEST_HAS_STD_WSTRING
|
||||||
void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
|
void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
|
||||||
PrintWideCharsAsStringTo(s.data(), s.size(), os);
|
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_STD_WSTRING
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,9 @@
|
||||||
|
|
||||||
// Indicates that this translation unit is part of Google Test's
|
// Indicates that this translation unit is part of Google Test's
|
||||||
// implementation. It must come before gtest-internal-inl.h is
|
// implementation. It must come before gtest-internal-inl.h is
|
||||||
// included, or there will be a compiler error. This trick is to
|
// included, or there will be a compiler error. This trick exists to
|
||||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
// prevent the accidental inclusion of gtest-internal-inl.h in the
|
||||||
// his code.
|
// user's code.
|
||||||
#define GTEST_IMPLEMENTATION_ 1
|
#define GTEST_IMPLEMENTATION_ 1
|
||||||
#include "src/gtest-internal-inl.h"
|
#include "src/gtest-internal-inl.h"
|
||||||
#undef GTEST_IMPLEMENTATION_
|
#undef GTEST_IMPLEMENTATION_
|
||||||
|
@ -48,10 +48,10 @@ using internal::GetUnitTestImpl;
|
||||||
|
|
||||||
// Gets the summary of the failure message by omitting the stack trace
|
// Gets the summary of the failure message by omitting the stack trace
|
||||||
// in it.
|
// in it.
|
||||||
internal::String TestPartResult::ExtractSummary(const char* message) {
|
std::string TestPartResult::ExtractSummary(const char* message) {
|
||||||
const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
|
const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
|
||||||
return stack_trace == NULL ? internal::String(message) :
|
return stack_trace == NULL ? message :
|
||||||
internal::String(message, stack_trace - message);
|
std::string(message, stack_trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints a TestPartResult object.
|
// Prints a TestPartResult object.
|
||||||
|
|
|
@ -45,33 +45,41 @@ static const char* SkipSpaces(const char* str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> SplitIntoTestNames(const char* src) {
|
||||||
|
std::vector<std::string> name_vec;
|
||||||
|
src = SkipSpaces(src);
|
||||||
|
for (; src != NULL; src = SkipComma(src)) {
|
||||||
|
name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src)));
|
||||||
|
}
|
||||||
|
return name_vec;
|
||||||
|
}
|
||||||
|
|
||||||
// Verifies that registered_tests match the test names in
|
// Verifies that registered_tests match the test names in
|
||||||
// defined_test_names_; returns registered_tests if successful, or
|
// registered_tests_; returns registered_tests if successful, or
|
||||||
// aborts the program otherwise.
|
// aborts the program otherwise.
|
||||||
const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||||
const char* file, int line, const char* registered_tests) {
|
const char* file, int line, const char* registered_tests) {
|
||||||
typedef ::std::set<const char*>::const_iterator DefinedTestIter;
|
typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
|
||||||
registered_ = true;
|
registered_ = true;
|
||||||
|
|
||||||
// Skip initial whitespace in registered_tests since some
|
std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
|
||||||
// preprocessors prefix stringizied literals with whitespace.
|
|
||||||
registered_tests = SkipSpaces(registered_tests);
|
|
||||||
|
|
||||||
Message errors;
|
Message errors;
|
||||||
::std::set<String> tests;
|
|
||||||
for (const char* names = registered_tests; names != NULL;
|
std::set<std::string> tests;
|
||||||
names = SkipComma(names)) {
|
for (std::vector<std::string>::const_iterator name_it = name_vec.begin();
|
||||||
const String name = GetPrefixUntilComma(names);
|
name_it != name_vec.end(); ++name_it) {
|
||||||
|
const std::string& name = *name_it;
|
||||||
if (tests.count(name) != 0) {
|
if (tests.count(name) != 0) {
|
||||||
errors << "Test " << name << " is listed more than once.\n";
|
errors << "Test " << name << " is listed more than once.\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (DefinedTestIter it = defined_test_names_.begin();
|
for (RegisteredTestIter it = registered_tests_.begin();
|
||||||
it != defined_test_names_.end();
|
it != registered_tests_.end();
|
||||||
++it) {
|
++it) {
|
||||||
if (name == *it) {
|
if (name == it->first) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -85,15 +93,15 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (DefinedTestIter it = defined_test_names_.begin();
|
for (RegisteredTestIter it = registered_tests_.begin();
|
||||||
it != defined_test_names_.end();
|
it != registered_tests_.end();
|
||||||
++it) {
|
++it) {
|
||||||
if (tests.count(*it) == 0) {
|
if (tests.count(it->first) == 0) {
|
||||||
errors << "You forgot to list test " << *it << ".\n";
|
errors << "You forgot to list test " << it->first << ".\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const String& errors_str = errors.GetString();
|
const std::string& errors_str = errors.GetString();
|
||||||
if (errors_str != "") {
|
if (errors_str != "") {
|
||||||
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
|
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
|
||||||
errors_str.c_str());
|
errors_str.c_str());
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue