mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 17:38:35 +02:00
ThirdParty: Update included gtest
This commit is contained in:
+296
-164
@@ -34,8 +34,8 @@
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include <ctype.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
@@ -78,9 +79,20 @@
|
||||
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
|
||||
|
||||
// Stringifies its argument.
|
||||
#define GTEST_STRINGIFY_(name) #name
|
||||
// Work around a bug in visual studio which doesn't accept code like this:
|
||||
//
|
||||
// #define GTEST_STRINGIFY_(name) #name
|
||||
// #define MACRO(a, b, c) ... GTEST_STRINGIFY_(a) ...
|
||||
// MACRO(, x, y)
|
||||
//
|
||||
// Complaining about the argument to GTEST_STRINGIFY_ being empty.
|
||||
// This is allowed by the spec.
|
||||
#define GTEST_STRINGIFY_HELPER_(name, ...) #name
|
||||
#define GTEST_STRINGIFY_(...) GTEST_STRINGIFY_HELPER_(__VA_ARGS__, )
|
||||
|
||||
namespace proto2 { class Message; }
|
||||
namespace proto2 {
|
||||
class MessageLite;
|
||||
}
|
||||
|
||||
namespace testing {
|
||||
|
||||
@@ -189,7 +201,7 @@ GTEST_API_ std::string DiffStrings(const std::string& left,
|
||||
// expected_value: "5"
|
||||
// actual_value: "6"
|
||||
//
|
||||
// The ignoring_case parameter is true iff the assertion is a
|
||||
// The ignoring_case parameter is true if and only if the assertion is a
|
||||
// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
|
||||
// be inserted into the message.
|
||||
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
|
||||
@@ -275,7 +287,7 @@ class FloatingPoint {
|
||||
//
|
||||
// See the following article for more details on ULP:
|
||||
// http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
static const size_t kMaxUlps = 4;
|
||||
static const uint32_t kMaxUlps = 4;
|
||||
|
||||
// Constructs a FloatingPoint from a raw floating-point number.
|
||||
//
|
||||
@@ -318,15 +330,15 @@ class FloatingPoint {
|
||||
// Returns the sign bit of this number.
|
||||
Bits sign_bit() const { return kSignBitMask & u_.bits_; }
|
||||
|
||||
// Returns true iff this is NAN (not a number).
|
||||
// Returns true if and only if this is NAN (not a number).
|
||||
bool is_nan() const {
|
||||
// It's a NAN if the exponent bits are all ones and the fraction
|
||||
// bits are not entirely zeros.
|
||||
return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
|
||||
}
|
||||
|
||||
// Returns true iff this number is at most kMaxUlps ULP's away from
|
||||
// rhs. In particular, this function:
|
||||
// Returns true if and only if this number is at most kMaxUlps ULP's away
|
||||
// from rhs. In particular, this function:
|
||||
//
|
||||
// - returns false if either number is (or both are) NAN.
|
||||
// - treats really large numbers as almost equal to infinity.
|
||||
@@ -508,6 +520,7 @@ struct SuiteApiResolver : T {
|
||||
|
||||
static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite(const char* filename,
|
||||
int line_num) {
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
SetUpTearDownSuiteFuncType test_case_fp =
|
||||
GetNotDefaultOrNull(&T::SetUpTestCase, &Test::SetUpTestCase);
|
||||
SetUpTearDownSuiteFuncType test_suite_fp =
|
||||
@@ -519,10 +532,16 @@ struct SuiteApiResolver : T {
|
||||
<< filename << ":" << line_num;
|
||||
|
||||
return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
|
||||
#else
|
||||
(void)(filename);
|
||||
(void)(line_num);
|
||||
return &T::SetUpTestSuite;
|
||||
#endif
|
||||
}
|
||||
|
||||
static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite(const char* filename,
|
||||
int line_num) {
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
SetUpTearDownSuiteFuncType test_case_fp =
|
||||
GetNotDefaultOrNull(&T::TearDownTestCase, &Test::TearDownTestCase);
|
||||
SetUpTearDownSuiteFuncType test_suite_fp =
|
||||
@@ -534,6 +553,11 @@ struct SuiteApiResolver : T {
|
||||
<< filename << ":" << line_num;
|
||||
|
||||
return test_case_fp != nullptr ? test_case_fp : test_suite_fp;
|
||||
#else
|
||||
(void)(filename);
|
||||
(void)(line_num);
|
||||
return &T::TearDownTestSuite;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -542,11 +566,11 @@ struct SuiteApiResolver : T {
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// test_suite_name: name of the test suite
|
||||
// test_suite_name: name of the test suite
|
||||
// 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.
|
||||
// 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.
|
||||
// code_location: code location where the test is defined
|
||||
// fixture_class_id: ID of the test fixture class
|
||||
@@ -566,8 +590,6 @@ GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||
// and returns false. None of pstr, *pstr, and prefix can be NULL.
|
||||
GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
@@ -607,8 +629,9 @@ class GTEST_API_ TypedTestSuitePState {
|
||||
// Verifies that registered_tests match the test names in
|
||||
// defined_test_names_; returns registered_tests if successful, or
|
||||
// aborts the program otherwise.
|
||||
const char* VerifyRegisteredTestNames(
|
||||
const char* file, int line, const char* registered_tests);
|
||||
const char* VerifyRegisteredTestNames(const char* test_suite_name,
|
||||
const char* file, int line,
|
||||
const char* registered_tests);
|
||||
|
||||
private:
|
||||
typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
|
||||
@@ -662,7 +685,7 @@ struct NameGeneratorSelector {
|
||||
};
|
||||
|
||||
template <typename NameGenerator>
|
||||
void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
|
||||
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
|
||||
|
||||
template <typename NameGenerator, typename Types>
|
||||
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
|
||||
@@ -729,7 +752,7 @@ class TypeParameterizedTest {
|
||||
|
||||
// The base case for the compile time recursion.
|
||||
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
||||
class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
|
||||
public:
|
||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||
const char* /*case_name*/, const char* /*test_names*/,
|
||||
@@ -740,6 +763,11 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||
}
|
||||
};
|
||||
|
||||
GTEST_API_ void RegisterTypeParameterizedTestSuite(const char* test_suite_name,
|
||||
CodeLocation code_location);
|
||||
GTEST_API_ void RegisterTypeParameterizedTestSuiteInstantiation(
|
||||
const char* case_name);
|
||||
|
||||
// TypeParameterizedTestSuite<Fixture, Tests, Types>::Register()
|
||||
// registers *all combinations* of 'Tests' and 'Types' with Google
|
||||
// Test. The return value is insignificant - we just need to return
|
||||
@@ -752,6 +780,7 @@ class TypeParameterizedTestSuite {
|
||||
const char* test_names,
|
||||
const std::vector<std::string>& type_names =
|
||||
GenerateNames<DefaultNameGenerator, Types>()) {
|
||||
RegisterTypeParameterizedTestSuiteInstantiation(case_name);
|
||||
std::string test_name = StripTrailingSpaces(
|
||||
GetPrefixUntilComma(test_names));
|
||||
if (!state->TestExists(test_name)) {
|
||||
@@ -781,7 +810,7 @@ class TypeParameterizedTestSuite {
|
||||
|
||||
// The base case for the compile time recursion.
|
||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
||||
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
|
||||
class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
|
||||
public:
|
||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||
const TypedTestSuitePState* /*state*/,
|
||||
@@ -792,8 +821,6 @@ class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// Returns the current OS stack trace as an std::string.
|
||||
//
|
||||
// The maximum number of stack frames to be included is specified by
|
||||
@@ -825,6 +852,16 @@ struct GTEST_API_ ConstCharPtr {
|
||||
const char* value;
|
||||
};
|
||||
|
||||
// Helper for declaring std::string within 'if' statement
|
||||
// in pre C++17 build environment.
|
||||
struct TrueWithString {
|
||||
TrueWithString() = default;
|
||||
explicit TrueWithString(const char* str) : value(str) {}
|
||||
explicit TrueWithString(const std::string& str) : value(str) {}
|
||||
explicit operator bool() const { return true; }
|
||||
std::string value;
|
||||
};
|
||||
|
||||
// A simple Linear Congruential Generator for generating random
|
||||
// numbers with a uniform distribution. Unlike rand() and srand(), it
|
||||
// doesn't use global state (and therefore can't interfere with user
|
||||
@@ -832,76 +869,54 @@ struct GTEST_API_ ConstCharPtr {
|
||||
// but it's good enough for our purposes.
|
||||
class GTEST_API_ Random {
|
||||
public:
|
||||
static const UInt32 kMaxRange = 1u << 31;
|
||||
static const uint32_t kMaxRange = 1u << 31;
|
||||
|
||||
explicit Random(UInt32 seed) : state_(seed) {}
|
||||
explicit Random(uint32_t seed) : state_(seed) {}
|
||||
|
||||
void Reseed(UInt32 seed) { state_ = seed; }
|
||||
void Reseed(uint32_t seed) { state_ = seed; }
|
||||
|
||||
// Generates a random number from [0, range). Crashes if 'range' is
|
||||
// 0 or greater than kMaxRange.
|
||||
UInt32 Generate(UInt32 range);
|
||||
uint32_t Generate(uint32_t range);
|
||||
|
||||
private:
|
||||
UInt32 state_;
|
||||
uint32_t state_;
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
|
||||
};
|
||||
|
||||
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
|
||||
// compiler error iff T1 and T2 are different types.
|
||||
template <typename T1, typename T2>
|
||||
struct CompileAssertTypesEqual;
|
||||
|
||||
template <typename T>
|
||||
struct CompileAssertTypesEqual<T, T> {
|
||||
};
|
||||
|
||||
// Removes the reference from a type if it is a reference type,
|
||||
// otherwise leaves it unchanged. This is the same as
|
||||
// tr1::remove_reference, which is not widely available yet.
|
||||
template <typename T>
|
||||
struct RemoveReference { typedef T type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct RemoveReference<T&> { typedef T type; }; // NOLINT
|
||||
|
||||
// A handy wrapper around RemoveReference that works when the argument
|
||||
// T depends on template parameters.
|
||||
#define GTEST_REMOVE_REFERENCE_(T) \
|
||||
typename ::testing::internal::RemoveReference<T>::type
|
||||
|
||||
// Removes const from a type if it is a const type, otherwise leaves
|
||||
// it unchanged. This is the same as tr1::remove_const, which is not
|
||||
// widely available yet.
|
||||
template <typename T>
|
||||
struct RemoveConst { typedef T type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct RemoveConst<const T> { typedef T type; }; // NOLINT
|
||||
|
||||
// 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
|
||||
// char[3][4]'. The following specialization works around the bug.
|
||||
template <typename T, size_t N>
|
||||
struct RemoveConst<const T[N]> {
|
||||
typedef typename RemoveConst<T>::type type[N];
|
||||
};
|
||||
|
||||
// A handy wrapper around RemoveConst that works when the argument
|
||||
// T depends on template parameters.
|
||||
#define GTEST_REMOVE_CONST_(T) \
|
||||
typename ::testing::internal::RemoveConst<T>::type
|
||||
|
||||
// Turns const U&, U&, const U, and U all into U.
|
||||
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
|
||||
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
|
||||
typename std::remove_const<typename std::remove_reference<T>::type>::type
|
||||
|
||||
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
|
||||
// true iff T is type proto2::Message or a subclass of it.
|
||||
// HasDebugStringAndShortDebugString<T>::value is a compile-time bool constant
|
||||
// that's true if and only if T has methods DebugString() and ShortDebugString()
|
||||
// that return std::string.
|
||||
template <typename T>
|
||||
struct IsAProtocolMessage
|
||||
: public bool_constant<
|
||||
std::is_convertible<const T*, const ::proto2::Message*>::value> {
|
||||
class HasDebugStringAndShortDebugString {
|
||||
private:
|
||||
template <typename C>
|
||||
static auto CheckDebugString(C*) -> typename std::is_same<
|
||||
std::string, decltype(std::declval<const C>().DebugString())>::type;
|
||||
template <typename>
|
||||
static std::false_type CheckDebugString(...);
|
||||
|
||||
template <typename C>
|
||||
static auto CheckShortDebugString(C*) -> typename std::is_same<
|
||||
std::string, decltype(std::declval<const C>().ShortDebugString())>::type;
|
||||
template <typename>
|
||||
static std::false_type CheckShortDebugString(...);
|
||||
|
||||
using HasDebugStringType = decltype(CheckDebugString<T>(nullptr));
|
||||
using HasShortDebugStringType = decltype(CheckShortDebugString<T>(nullptr));
|
||||
|
||||
public:
|
||||
static constexpr bool value =
|
||||
HasDebugStringType::value && HasShortDebugStringType::value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr bool HasDebugStringAndShortDebugString<T>::value;
|
||||
|
||||
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
||||
// STL-style container class, the first overload of IsContainerTest
|
||||
// will be viable (since both C::iterator* and C::const_iterator* are
|
||||
@@ -967,7 +982,7 @@ template <typename C,
|
||||
struct IsRecursiveContainerImpl;
|
||||
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, false> : public false_type {};
|
||||
struct IsRecursiveContainerImpl<C, false> : public std::false_type {};
|
||||
|
||||
// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
|
||||
// obey the same inconsistencies as the IsContainerTest, namely check if
|
||||
@@ -977,9 +992,9 @@ template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true> {
|
||||
using value_type = decltype(*std::declval<typename C::const_iterator>());
|
||||
using type =
|
||||
is_same<typename std::remove_const<
|
||||
typename std::remove_reference<value_type>::type>::type,
|
||||
C>;
|
||||
std::is_same<typename std::remove_const<
|
||||
typename std::remove_reference<value_type>::type>::type,
|
||||
C>;
|
||||
};
|
||||
|
||||
// IsRecursiveContainer<Type> is a unary compile-time predicate that
|
||||
@@ -991,13 +1006,6 @@ struct IsRecursiveContainerImpl<C, true> {
|
||||
template <typename C>
|
||||
struct IsRecursiveContainer : public IsRecursiveContainerImpl<C>::type {};
|
||||
|
||||
// EnableIf<condition>::type is void when 'Cond' is true, and
|
||||
// undefined when 'Cond' is false. To use SFINAE to make a function
|
||||
// overload only apply when a particular expression is true, add
|
||||
// "typename EnableIf<expression>::type* = 0" as the last parameter.
|
||||
template<bool> struct EnableIf;
|
||||
template<> struct EnableIf<true> { typedef void type; }; // NOLINT
|
||||
|
||||
// Utilities for native arrays.
|
||||
|
||||
// ArrayEq() compares two k-dimensional native arrays using the
|
||||
@@ -1120,10 +1128,9 @@ class NativeArray {
|
||||
}
|
||||
|
||||
private:
|
||||
enum {
|
||||
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
|
||||
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value
|
||||
};
|
||||
static_assert(!std::is_const<Element>::value, "Type must not be const");
|
||||
static_assert(!std::is_reference<Element>::value,
|
||||
"Type must not be a reference");
|
||||
|
||||
// Initializes this object with a copy of the input.
|
||||
void InitCopy(const Element* array, size_t a_size) {
|
||||
@@ -1144,8 +1151,6 @@ class NativeArray {
|
||||
const Element* array_;
|
||||
size_t size_;
|
||||
void (NativeArray::*clone_)(const Element*, size_t);
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||
};
|
||||
|
||||
// Backport of std::index_sequence.
|
||||
@@ -1169,32 +1174,44 @@ struct DoubleSequence<false, IndexSequence<I...>, sizeofT> {
|
||||
// Backport of std::make_index_sequence.
|
||||
// It uses O(ln(N)) instantiation depth.
|
||||
template <size_t N>
|
||||
struct MakeIndexSequence
|
||||
: DoubleSequence<N % 2 == 1, typename MakeIndexSequence<N / 2>::type,
|
||||
struct MakeIndexSequenceImpl
|
||||
: DoubleSequence<N % 2 == 1, typename MakeIndexSequenceImpl<N / 2>::type,
|
||||
N / 2>::type {};
|
||||
|
||||
template <>
|
||||
struct MakeIndexSequence<0> : IndexSequence<> {};
|
||||
struct MakeIndexSequenceImpl<0> : IndexSequence<> {};
|
||||
|
||||
// FIXME: This implementation of ElemFromList is O(1) in instantiation depth,
|
||||
// but it is O(N^2) in total instantiations. Not sure if this is the best
|
||||
// tradeoff, as it will make it somewhat slow to compile.
|
||||
template <typename T, size_t, size_t>
|
||||
struct ElemFromListImpl {};
|
||||
template <size_t N>
|
||||
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::type;
|
||||
|
||||
template <typename T, size_t I>
|
||||
struct ElemFromListImpl<T, I, I> {
|
||||
using type = T;
|
||||
template <typename... T>
|
||||
using IndexSequenceFor = typename MakeIndexSequence<sizeof...(T)>::type;
|
||||
|
||||
template <size_t>
|
||||
struct Ignore {
|
||||
Ignore(...); // NOLINT
|
||||
};
|
||||
|
||||
// Get the Nth element from T...
|
||||
// It uses O(1) instantiation depth.
|
||||
template <size_t N, typename I, typename... T>
|
||||
struct ElemFromList;
|
||||
template <typename>
|
||||
struct ElemFromListImpl;
|
||||
template <size_t... I>
|
||||
struct ElemFromListImpl<IndexSequence<I...>> {
|
||||
// We make Ignore a template to solve a problem with MSVC.
|
||||
// A non-template Ignore would work fine with `decltype(Ignore(I))...`, but
|
||||
// MSVC doesn't understand how to deal with that pack expansion.
|
||||
// Use `0 * I` to have a single instantiation of Ignore.
|
||||
template <typename R>
|
||||
static R Apply(Ignore<0 * I>..., R (*)(), ...);
|
||||
};
|
||||
|
||||
template <size_t N, size_t... I, typename... T>
|
||||
struct ElemFromList<N, IndexSequence<I...>, T...>
|
||||
: ElemFromListImpl<T, N, I>... {};
|
||||
template <size_t N, typename... T>
|
||||
struct ElemFromList {
|
||||
using type =
|
||||
decltype(ElemFromListImpl<typename MakeIndexSequence<N>::type>::Apply(
|
||||
static_cast<T (*)()>(nullptr)...));
|
||||
};
|
||||
|
||||
struct FlatTupleConstructTag {};
|
||||
|
||||
template <typename... T>
|
||||
class FlatTuple;
|
||||
@@ -1204,11 +1221,11 @@ struct FlatTupleElemBase;
|
||||
|
||||
template <typename... T, size_t I>
|
||||
struct FlatTupleElemBase<FlatTuple<T...>, I> {
|
||||
using value_type =
|
||||
typename ElemFromList<I, typename MakeIndexSequence<sizeof...(T)>::type,
|
||||
T...>::type;
|
||||
using value_type = typename ElemFromList<I, T...>::type;
|
||||
FlatTupleElemBase() = default;
|
||||
explicit FlatTupleElemBase(value_type t) : value(std::move(t)) {}
|
||||
template <typename Arg>
|
||||
explicit FlatTupleElemBase(FlatTupleConstructTag, Arg&& t)
|
||||
: value(std::forward<Arg>(t)) {}
|
||||
value_type value;
|
||||
};
|
||||
|
||||
@@ -1220,13 +1237,35 @@ struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>>
|
||||
: FlatTupleElemBase<FlatTuple<T...>, Idx>... {
|
||||
using Indices = IndexSequence<Idx...>;
|
||||
FlatTupleBase() = default;
|
||||
explicit FlatTupleBase(T... t)
|
||||
: FlatTupleElemBase<FlatTuple<T...>, Idx>(std::move(t))... {}
|
||||
template <typename... Args>
|
||||
explicit FlatTupleBase(FlatTupleConstructTag, Args&&... args)
|
||||
: FlatTupleElemBase<FlatTuple<T...>, Idx>(FlatTupleConstructTag{},
|
||||
std::forward<Args>(args))... {}
|
||||
|
||||
template <size_t I>
|
||||
const typename ElemFromList<I, T...>::type& Get() const {
|
||||
return FlatTupleElemBase<FlatTuple<T...>, I>::value;
|
||||
}
|
||||
|
||||
template <size_t I>
|
||||
typename ElemFromList<I, T...>::type& Get() {
|
||||
return FlatTupleElemBase<FlatTuple<T...>, I>::value;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
auto Apply(F&& f) -> decltype(std::forward<F>(f)(this->Get<Idx>()...)) {
|
||||
return std::forward<F>(f)(Get<Idx>()...);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
auto Apply(F&& f) const -> decltype(std::forward<F>(f)(this->Get<Idx>()...)) {
|
||||
return std::forward<F>(f)(Get<Idx>()...);
|
||||
}
|
||||
};
|
||||
|
||||
// Analog to std::tuple but with different tradeoffs.
|
||||
// This class minimizes the template instantiation depth, thus allowing more
|
||||
// elements that std::tuple would. std::tuple has been seen to require an
|
||||
// elements than std::tuple would. std::tuple has been seen to require an
|
||||
// instantiation depth of more than 10x the number of elements in some
|
||||
// implementations.
|
||||
// FlatTuple and ElemFromList are not recursive and have a fixed depth
|
||||
@@ -1237,21 +1276,17 @@ template <typename... T>
|
||||
class FlatTuple
|
||||
: private FlatTupleBase<FlatTuple<T...>,
|
||||
typename MakeIndexSequence<sizeof...(T)>::type> {
|
||||
using Indices = typename FlatTuple::FlatTupleBase::Indices;
|
||||
using Indices = typename FlatTupleBase<
|
||||
FlatTuple<T...>, typename MakeIndexSequence<sizeof...(T)>::type>::Indices;
|
||||
|
||||
public:
|
||||
FlatTuple() = default;
|
||||
explicit FlatTuple(T... t) : FlatTuple::FlatTupleBase(std::move(t)...) {}
|
||||
template <typename... Args>
|
||||
explicit FlatTuple(FlatTupleConstructTag tag, Args&&... args)
|
||||
: FlatTuple::FlatTupleBase(tag, std::forward<Args>(args)...) {}
|
||||
|
||||
template <size_t I>
|
||||
const typename ElemFromList<I, Indices, T...>::type& Get() const {
|
||||
return static_cast<const FlatTupleElemBase<FlatTuple, I>*>(this)->value;
|
||||
}
|
||||
|
||||
template <size_t I>
|
||||
typename ElemFromList<I, Indices, T...>::type& Get() {
|
||||
return static_cast<FlatTupleElemBase<FlatTuple, I>*>(this)->value;
|
||||
}
|
||||
using FlatTuple::FlatTupleBase::Apply;
|
||||
using FlatTuple::FlatTupleBase::Get;
|
||||
};
|
||||
|
||||
// Utility functions to be called with static_assert to induce deprecation
|
||||
@@ -1284,6 +1319,22 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
namespace std {
|
||||
// Some standard library implementations use `struct tuple_size` and some use
|
||||
// `class tuple_size`. Clang warns about the mismatch.
|
||||
// https://reviews.llvm.org/D55466
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
template <typename... Ts>
|
||||
struct tuple_size<testing::internal::FlatTuple<Ts...>>
|
||||
: std::integral_constant<size_t, sizeof...(Ts)> {};
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
|
||||
::testing::internal::AssertHelper(result_type, file, line, message) \
|
||||
= ::testing::Message()
|
||||
@@ -1306,48 +1357,122 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
|
||||
// Suppress MSVC warning 4072 (unreachable code) for the code following
|
||||
// statement if it returns or throws (or doesn't return or throw in some
|
||||
// situations).
|
||||
// NOTE: The "else" is important to keep this expansion to prevent a top-level
|
||||
// "else" from attaching to our "if".
|
||||
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
|
||||
if (::testing::internal::AlwaysTrue()) { statement; }
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
statement; \
|
||||
} else /* NOLINT */ \
|
||||
static_assert(true, "") // User must have a semicolon after expansion.
|
||||
|
||||
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::ConstCharPtr gtest_msg = "") { \
|
||||
bool gtest_caught_expected = false; \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} \
|
||||
catch (expected_exception const&) { \
|
||||
gtest_caught_expected = true; \
|
||||
} \
|
||||
catch (...) { \
|
||||
gtest_msg.value = \
|
||||
"Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws a different type."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
if (!gtest_caught_expected) { \
|
||||
gtest_msg.value = \
|
||||
"Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws nothing."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
||||
fail(gtest_msg.value)
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
class NeverThrown {
|
||||
public:
|
||||
const char* what() const noexcept {
|
||||
return "this exception should never be thrown";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#if GTEST_HAS_RTTI
|
||||
|
||||
#define GTEST_EXCEPTION_TYPE_(e) ::testing::internal::GetTypeName(typeid(e))
|
||||
|
||||
#else // GTEST_HAS_RTTI
|
||||
|
||||
#define GTEST_EXCEPTION_TYPE_(e) \
|
||||
std::string { "an std::exception-derived error" }
|
||||
|
||||
#endif // GTEST_HAS_RTTI
|
||||
|
||||
#define GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception) \
|
||||
catch (typename std::conditional< \
|
||||
std::is_same<typename std::remove_cv<typename std::remove_reference< \
|
||||
expected_exception>::type>::type, \
|
||||
std::exception>::value, \
|
||||
const ::testing::internal::NeverThrown&, const std::exception&>::type \
|
||||
e) { \
|
||||
gtest_msg.value = "Expected: " #statement \
|
||||
" throws an exception of type " #expected_exception \
|
||||
".\n Actual: it throws "; \
|
||||
gtest_msg.value += GTEST_EXCEPTION_TYPE_(e); \
|
||||
gtest_msg.value += " with description \""; \
|
||||
gtest_msg.value += e.what(); \
|
||||
gtest_msg.value += "\"."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
}
|
||||
|
||||
#else // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#define GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception)
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::TrueWithString gtest_msg{}) { \
|
||||
bool gtest_caught_expected = false; \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} catch (expected_exception const&) { \
|
||||
gtest_caught_expected = true; \
|
||||
} \
|
||||
GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception) \
|
||||
catch (...) { \
|
||||
gtest_msg.value = "Expected: " #statement \
|
||||
" throws an exception of type " #expected_exception \
|
||||
".\n Actual: it throws a different type."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
if (!gtest_caught_expected) { \
|
||||
gtest_msg.value = "Expected: " #statement \
|
||||
" throws an exception of type " #expected_exception \
|
||||
".\n Actual: it throws nothing."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
} else /*NOLINT*/ \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \
|
||||
: fail(gtest_msg.value.c_str())
|
||||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \
|
||||
catch (std::exception const& e) { \
|
||||
gtest_msg.value = "it throws "; \
|
||||
gtest_msg.value += GTEST_EXCEPTION_TYPE_(e); \
|
||||
gtest_msg.value += " with description \""; \
|
||||
gtest_msg.value += e.what(); \
|
||||
gtest_msg.value += "\"."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||
}
|
||||
|
||||
#else // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_()
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
if (::testing::internal::TrueWithString gtest_msg{}) { \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} \
|
||||
GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \
|
||||
catch (...) { \
|
||||
gtest_msg.value = "it throws."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
|
||||
fail("Expected: " #statement " doesn't throw an exception.\n" \
|
||||
" Actual: it throws.")
|
||||
fail(("Expected: " #statement " doesn't throw an exception.\n" \
|
||||
" Actual: " + gtest_msg.value).c_str())
|
||||
|
||||
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
@@ -1370,7 +1495,7 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
|
||||
|
||||
// Implements Boolean test assertions such as EXPECT_TRUE. expression can be
|
||||
// either a boolean expression or an AssertionResult. text is a textual
|
||||
// represenation of expression as it was passed into the EXPECT_TRUE.
|
||||
// representation of expression as it was passed into the EXPECT_TRUE.
|
||||
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const ::testing::AssertionResult gtest_ar_ = \
|
||||
@@ -1400,16 +1525,23 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
|
||||
|
||||
// Helper macro for defining tests.
|
||||
#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
|
||||
static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \
|
||||
"test_suite_name must not be empty"); \
|
||||
static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \
|
||||
"test_name must not be empty"); \
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
: public parent_class { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||
\
|
||||
private: \
|
||||
virtual void TestBody(); \
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \
|
||||
~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)); \
|
||||
GTEST_DISALLOW_MOVE_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)); \
|
||||
\
|
||||
private: \
|
||||
void TestBody() override; \
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
}; \
|
||||
\
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
@@ -1425,4 +1557,4 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
|
||||
test_suite_name, test_name)>); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
|
||||
Reference in New Issue
Block a user