37#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
38#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
44# include <sys/types.h>
49#if GTEST_HAS_EXCEPTIONS
76#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
77#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
127#ifdef GTEST_ELLIPSIS_NEEDS_POD_
130# define GTEST_IS_NULL_LITERAL_(x) false
132# define GTEST_IS_NULL_LITERAL_(x) \
133 (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
138 const std::string& gtest_msg,
const Message& user_msg);
140#if GTEST_HAS_EXCEPTIONS
148class GTEST_API_ GoogleTestFailureException :
public ::std::runtime_error {
150 explicit GoogleTestFailureException(
const TestPartResult& failure);
174namespace edit_distance {
182 const std::vector<size_t>& left,
const std::vector<size_t>& right);
186 const std::vector<std::string>& left,
187 const std::vector<std::string>& right);
191 const std::vector<std::string>& right,
201 const std::string& right,
202 size_t* total_line_count);
220 const char* actual_expression,
221 const std::string& expected_value,
222 const std::string& actual_value,
228 const char* expression_text,
229 const char* actual_predicate_value,
230 const char* expected_predicate_value);
261template <
typename RawType>
275 std::numeric_limits<RawType>::digits - 1;
363 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
369 union FloatingPointUnion {
389 static Bits SignAndMagnitudeToBiased(
const Bits &sam) {
401 static Bits DistanceBetweenSignAndMagnitudeNumbers(
const Bits &sam1,
403 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
404 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
405 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
408 FloatingPointUnion u_;
481template <
class TestClass>
530 const char* test_case_name,
532 const char* type_param,
533 const char* value_param,
545#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
550 TypedTestCasePState() : registered_(false) {}
555 bool AddTestName(
const char* file,
int line,
const char* case_name,
556 const char* test_name) {
558 fprintf(stderr,
"%s Test %s must be defined before "
559 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
560 FormatFileLocation(file, line).c_str(), test_name, case_name);
564 registered_tests_.insert(
565 ::std::make_pair(test_name, CodeLocation(file, line)));
569 bool TestExists(
const std::string& test_name)
const {
570 return registered_tests_.count(test_name) > 0;
573 const CodeLocation& GetCodeLocation(
const std::string& test_name)
const {
574 RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
582 const char* VerifyRegisteredTestNames(
583 const char* file,
int line,
const char* registered_tests);
586 typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
589 RegisteredTestsMap registered_tests_;
594inline const char* SkipComma(
const char* str) {
595 const char* comma = strchr(str,
',');
605inline std::string GetPrefixUntilComma(
const char* str) {
606 const char* comma = strchr(str,
',');
607 return comma == NULL ? str : std::string(str, comma);
612void SplitString(const ::std::string& str,
char delimiter,
613 ::std::vector< ::std::string>* dest);
622template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
623class TypeParameterizedTest {
629 static bool Register(
const char* prefix,
630 CodeLocation code_location,
631 const char* case_name,
const char* test_names,
633 typedef typename Types::Head Type;
634 typedef Fixture<Type> FixtureClass;
635 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
640 (std::string(prefix) + (prefix[0] ==
'\0' ?
"" :
"/") + case_name +
"/"
647 TestClass::SetUpTestCase,
648 TestClass::TearDownTestCase,
649 new TestFactoryImpl<TestClass>);
652 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
653 ::Register(prefix, code_location, case_name, test_names, index + 1);
658template <GTEST_TEMPLATE_ Fixture,
class TestSel>
659class TypeParameterizedTest<Fixture, TestSel, Types0> {
661 static bool Register(
const char* , CodeLocation,
662 const char* ,
const char* ,
672template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
673class TypeParameterizedTestCase {
675 static bool Register(
const char* prefix, CodeLocation code_location,
676 const TypedTestCasePState* state,
677 const char* case_name,
const char* test_names) {
679 GetPrefixUntilComma(test_names));
680 if (!state->TestExists(test_name)) {
681 fprintf(stderr,
"Failed to get code location for test %s.%s at %s.",
682 case_name, test_name.c_str(),
684 code_location.line).c_str());
688 const CodeLocation& test_location = state->GetCodeLocation(test_name);
690 typedef typename Tests::Head Head;
693 TypeParameterizedTest<Fixture, Head, Types>::Register(
694 prefix, test_location, case_name, test_names, 0);
697 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
698 ::Register(prefix, code_location, state,
699 case_name, SkipComma(test_names));
704template <GTEST_TEMPLATE_ Fixture,
typename Types>
705class TypeParameterizedTestCase<Fixture, Templates0, Types> {
707 static bool Register(
const char* , CodeLocation,
708 const TypedTestCasePState* ,
709 const char* ,
const char* ) {
727 UnitTest* unit_test,
int skip_count);
743 operator bool()
const {
return true; }
754 static const UInt32 kMaxRange = 1u << 31;
771template <
typename T1,
typename T2>
788#define GTEST_REMOVE_REFERENCE_(T) \
789 typename ::testing::internal::RemoveReference<T>::type
802template <
typename T,
size_t N>
807#if defined(_MSC_VER) && _MSC_VER < 1400
811template <
typename T,
size_t N>
819#define GTEST_REMOVE_CONST_(T) \
820 typename ::testing::internal::RemoveConst<T>::type
823#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
824 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
836#define GTEST_ADD_REFERENCE_(T) \
837 typename ::testing::internal::AddReference<T>::type
848#define GTEST_REFERENCE_TO_CONST_(T) \
849 GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
854template <
typename From,
typename To>
875 static char Helper(To);
876 static char (&Helper(...))[2];
881#if defined(__BORLANDC__)
885 static const bool value = __is_convertible(From, To);
896template <
typename From,
typename To>
905 ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
906 ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
933 typename C::iterator* = NULL,
934 typename C::const_iterator* = NULL) {
955template <
typename T,
typename U>
956bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs);
959template <
typename T,
typename U>
960inline bool ArrayEq(
const T& lhs,
const U& rhs) {
return lhs == rhs; }
963template <
typename T,
typename U,
size_t N>
964inline bool ArrayEq(
const T(&lhs)[N],
const U(&rhs)[N]) {
971template <
typename T,
typename U>
972bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs) {
973 for (
size_t i = 0; i != size; i++) {
982template <
typename Iter,
typename Element>
984 for (Iter it = begin; it != end; ++it) {
995template <
typename T,
typename U>
996void CopyArray(
const T* from,
size_t size, U* to);
999template <
typename T,
typename U>
1003template <
typename T,
typename U,
size_t N>
1011template <
typename T,
typename U>
1013 for (
size_t i = 0; i != size; i++) {
1033template <
typename Element>
1043 InitRef(array, count);
1048 InitCopy(array, count);
1053 (this->*rhs.clone_)(rhs.array_, rhs.size_);
1057 if (clone_ != &NativeArray::InitRef)
1062 size_t size()
const {
return size_; }
1077 void InitCopy(
const Element* array,
size_t a_size) {
1078 Element*
const copy =
new Element[a_size];
1082 clone_ = &NativeArray::InitCopy;
1086 void InitRef(
const Element* array,
size_t a_size) {
1089 clone_ = &NativeArray::InitRef;
1092 const Element* array_;
1094 void (
NativeArray::*clone_)(const Element*, size_t);
1102#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1103 ::testing::internal::AssertHelper(result_type, file, line, message) \
1104 = ::testing::Message()
1106#define GTEST_MESSAGE_(message, result_type) \
1107 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1109#define GTEST_FATAL_FAILURE_(message) \
1110 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1112#define GTEST_NONFATAL_FAILURE_(message) \
1113 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1115#define GTEST_SUCCESS_(message) \
1116 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1121#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1122 if (::testing::internal::AlwaysTrue()) { statement; }
1124#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1125 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1126 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1127 bool gtest_caught_expected = false; \
1129 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1131 catch (expected_exception const&) { \
1132 gtest_caught_expected = true; \
1136 "Expected: " #statement " throws an exception of type " \
1137 #expected_exception ".\n Actual: it throws a different type."; \
1138 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1140 if (!gtest_caught_expected) { \
1142 "Expected: " #statement " throws an exception of type " \
1143 #expected_exception ".\n Actual: it throws nothing."; \
1144 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1147 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1148 fail(gtest_msg.value)
1150#define GTEST_TEST_NO_THROW_(statement, fail) \
1151 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1152 if (::testing::internal::AlwaysTrue()) { \
1154 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1157 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1160 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1161 fail("Expected: " #statement " doesn't throw an exception.\n" \
1162 " Actual: it throws.")
1164#define GTEST_TEST_ANY_THROW_(statement, fail) \
1165 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1166 if (::testing::internal::AlwaysTrue()) { \
1167 bool gtest_caught_any = false; \
1169 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1172 gtest_caught_any = true; \
1174 if (!gtest_caught_any) { \
1175 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1178 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1179 fail("Expected: " #statement " throws an exception.\n" \
1180 " Actual: it doesn't.")
1186#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1187 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1188 if (const ::testing::AssertionResult gtest_ar_ = \
1189 ::testing::AssertionResult(expression)) \
1192 fail(::testing::internal::GetBoolAssertionFailureMessage(\
1193 gtest_ar_, text, #actual, #expected).c_str())
1195#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1196 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1197 if (::testing::internal::AlwaysTrue()) { \
1198 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1199 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1200 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1201 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1204 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1205 fail("Expected: " #statement " doesn't generate new fatal " \
1206 "failures in the current thread.\n" \
1207 " Actual: it does.")
1210#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1211 test_case_name##_##test_name##_Test
1214#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
1215class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
1217 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
1219 virtual void TestBody();\
1220 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
1221 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1222 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
1225::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
1227 ::testing::internal::MakeAndRegisterTestInfo(\
1228 #test_case_name, #test_name, NULL, NULL, \
1229 ::testing::internal::CodeLocation(__FILE__, __LINE__), \
1231 parent_class::SetUpTestCase, \
1232 parent_class::TearDownTestCase, \
1233 new ::testing::internal::TestFactoryImpl<\
1234 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
1235void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
bsoncxx::types::value value
Definition DocumentManager.h:16
Definition gtest-message.h:85
Definition gtest-test-part.h:47
Definition gtest-internal.h:262
static const Bits kFractionBitMask
Definition gtest-internal.h:284
static const size_t kFractionBitCount
Definition gtest-internal.h:274
FloatingPoint(const RawType &x)
Definition gtest-internal.h:310
static const size_t kExponentBitCount
Definition gtest-internal.h:278
bool is_nan() const
Definition gtest-internal.h:346
static RawType Infinity()
Definition gtest-internal.h:324
static const Bits kExponentBitMask
Definition gtest-internal.h:288
bool AlmostEquals(const FloatingPoint &rhs) const
Definition gtest-internal.h:358
Bits fraction_bits() const
Definition gtest-internal.h:340
static const size_t kMaxUlps
Definition gtest-internal.h:302
static const size_t kBitCount
Definition gtest-internal.h:271
TypeWithSize< sizeof(RawType)>::UInt Bits
Definition gtest-internal.h:266
static RawType ReinterpretBits(const Bits bits)
Definition gtest-internal.h:317
static const Bits kSignBitMask
Definition gtest-internal.h:281
const Bits & bits() const
Definition gtest-internal.h:334
Bits exponent_bits() const
Definition gtest-internal.h:337
Bits sign_bit() const
Definition gtest-internal.h:343
Definition gtest-internal.h:855
Definition gtest-internal.h:1034
Element value_type
Definition gtest-internal.h:1037
const_iterator begin() const
Definition gtest-internal.h:1063
NativeArray(const Element *array, size_t count, RelationToSourceReference)
Definition gtest-internal.h:1042
~NativeArray()
Definition gtest-internal.h:1056
bool operator==(const NativeArray &rhs) const
Definition gtest-internal.h:1065
const Element * const_iterator
Definition gtest-internal.h:1039
NativeArray(const NativeArray &rhs)
Definition gtest-internal.h:1052
Element * iterator
Definition gtest-internal.h:1038
NativeArray(const Element *array, size_t count, RelationToSourceCopy)
Definition gtest-internal.h:1047
const_iterator end() const
Definition gtest-internal.h:1064
size_t size() const
Definition gtest-internal.h:1062
Definition gtest-internal.h:752
Random(UInt32 seed)
Definition gtest-internal.h:756
UInt32 Generate(UInt32 range)
void Reseed(UInt32 seed)
Definition gtest-internal.h:758
Definition gtest-internal.h:156
ScopedTrace(const char *file, int line, const Message &message)
Definition gtest-internal.h:464
virtual ~TestFactoryBase()
Definition gtest-internal.h:466
virtual Test * CreateTest()=0
TestFactoryBase()
Definition gtest-internal.h:473
Definition gtest-internal.h:482
virtual Test * CreateTest()
Definition gtest-internal.h:484
Definition gtest-internal.h:432
static bool dummy_
Definition gtest-internal.h:437
Definition gtest-port.h:2461
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
Definition gtest-internal.h:823
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition gtest-port.h:317
#define GTEST_API_
Definition gtest-port.h:934
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition gtest-port.h:318
#define GTEST_CHECK_(condition)
Definition gtest-port.h:1295
#define GTEST_DISALLOW_ASSIGN_(type)
Definition gtest-port.h:869
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:874
Definition gtest-internal.h:80
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
EditType
Definition gtest-internal.h:180
@ kAdd
Definition gtest-internal.h:180
@ kMatch
Definition gtest-internal.h:180
@ kRemove
Definition gtest-internal.h:180
@ kReplace
Definition gtest-internal.h:180
FloatingPoint< float > Float
Definition gtest-internal.h:420
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
void(* TearDownTestCaseFunc)()
Definition gtest-internal.h:502
GTEST_API_ TypeId GetTestTypeId()
void(* SetUpTestCaseFunc)()
Definition gtest-internal.h:501
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
TypeWithSize< 4 >::UInt UInt32
Definition gtest-port.h:2495
bool AlwaysFalse()
Definition gtest-internal.h:736
GTEST_API_ bool AlwaysTrue()
GTEST_API_ std::string DiffStrings(const std::string &left, const std::string &right, size_t *total_line_count)
std::string GetTypeName()
Definition gtest-type-util.h:64
FloatingPoint< double > Double
Definition gtest-internal.h:421
TypeId GetTypeId()
Definition gtest-internal.h:447
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
Definition gtest-internal.h:983
GTEST_API_ const char kStackTraceMarker[]
std::string StripTrailingSpaces(std::string str)
Definition gtest-port.h:2284
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
std::string StreamableToString(const T &streamable)
Definition gtest-message.h:243
const void * TypeId
Definition gtest-internal.h:429
char IsNotContainer
Definition gtest-internal.h:938
GTEST_API_ AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
Definition gtest-internal.h:932
int IsContainer
Definition gtest-internal.h:930
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
bool IsSpace(char ch)
Definition gtest-port.h:2263
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
Definition gtest-internal.h:972
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
char IsNullLiteralHelper(Secret *p)
void CopyArray(const T *from, size_t size, U *to)
Definition gtest-internal.h:1012
Definition gtest-death-test.h:43
::std::string PrintToString(const T &value)
Definition gtest-printers.h:980
T & type
Definition gtest-internal.h:832
Definition gtest-internal.h:830
T & type
Definition gtest-internal.h:830
Definition gtest-internal.h:504
int line
Definition gtest-internal.h:508
string file
Definition gtest-internal.h:507
CodeLocation(const string &a_file, int a_line)
Definition gtest-internal.h:505
Definition gtest-internal.h:772
Definition gtest-internal.h:741
const char * value
Definition gtest-internal.h:744
ConstCharPtr(const char *str)
Definition gtest-internal.h:742
void type
Definition gtest-internal.h:947
Definition gtest-internal.h:946
Definition gtest-internal.h:906
Definition gtest-internal.h:1023
Definition gtest-internal.h:1022
T type
Definition gtest-internal.h:797
Definition gtest-internal.h:795
T type
Definition gtest-internal.h:795
T type
Definition gtest-internal.h:784
Definition gtest-internal.h:782
T type
Definition gtest-internal.h:782
Definition gtest-port.h:1084
Definition gtest-port.h:2203