37 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ 38 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ 40 #include "gtest/internal/gtest-port.h" 44 # include <sys/types.h> 45 # include <sys/wait.h> 47 #endif // GTEST_OS_LINUX 49 #if GTEST_HAS_EXCEPTIONS 60 #include "gtest/gtest-message.h" 61 #include "gtest/internal/gtest-string.h" 62 #include "gtest/internal/gtest-filepath.h" 63 #include "gtest/internal/gtest-type-util.h" 73 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) 74 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar 76 class ProtocolMessage;
84 class AssertionResult;
129 #ifdef GTEST_ELLIPSIS_NEEDS_POD_ 132 # define GTEST_IS_NULL_LITERAL_(x) false 134 # define GTEST_IS_NULL_LITERAL_(x) \ 135 (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) 136 #endif // GTEST_ELLIPSIS_NEEDS_POD_ 142 #if GTEST_HAS_EXCEPTIONS 150 class GTEST_API_ GoogleTestFailureException :
public ::std::runtime_error
153 explicit GoogleTestFailureException(
const TestPartResult & failure);
156 #endif // GTEST_HAS_EXCEPTIONS 164 ScopedTrace(
const char * file,
int line,
const Message &
message);
194 const char * actual_expression,
201 const AssertionResult & assertion_result,
202 const char * expression_text,
203 const char * actual_predicate_value,
204 const char * expected_predicate_value);
235 template <
typename RawType>
246 static const size_t kBitCount = 8 *
sizeof(RawType);
249 static const size_t kFractionBitCount =
250 std::numeric_limits<RawType>::digits - 1;
253 static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
256 static const Bits kSignBitMask =
static_cast<Bits
>(1) << (kBitCount - 1);
259 static const Bits kFractionBitMask =
260 ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
263 static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
277 static const size_t kMaxUlps = 4;
302 return ReinterpretBits(kExponentBitMask);
306 static RawType Max();
311 const Bits &
bits()
const {
return u_.bits_; }
320 Bits
sign_bit()
const {
return kSignBitMask & u_.bits_; }
327 return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
340 if (is_nan() || rhs.is_nan()) {
return false; }
342 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
371 if (kSignBitMask & sam)
380 return kSignBitMask | sam;
389 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
390 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
391 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
415 typedef const void *
TypeId;
417 template <
typename T>
427 template <
typename T>
433 template <
typename T>
440 return &(TypeIdHelper<T>::dummy_);
459 virtual Test * CreateTest() = 0;
470 template <
class TestClass>
488 #endif // GTEST_OS_WINDOWS 512 const char * test_case_name,
514 const char * type_param,
515 const char * value_param,
516 TypeId fixture_class_id,
526 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 532 TypedTestCasePState() : registered_(
false) {}
537 bool AddTestName(
const char * file,
int line,
const char * case_name,
538 const char * test_name)
542 fprintf(stderr,
"%s Test %s must be defined before " 543 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
549 defined_test_names_.insert(test_name);
556 const char * VerifyRegisteredTestNames(
557 const char * file,
int line,
const char * registered_tests);
561 ::std::set<const char *> defined_test_names_;
566 inline const char * SkipComma(
const char * str)
568 const char * comma = strchr(str,
',');
582 inline std::string GetPrefixUntilComma(
const char * str)
584 const char * comma = strchr(str,
',');
585 return comma == NULL ? str :
std::string(str, comma);
595 template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
596 class TypeParameterizedTest
603 static bool Register(
const char * prefix,
const char * case_name,
604 const char * test_names,
int index)
606 typedef typename Types::Head Type;
607 typedef Fixture<Type> FixtureClass;
608 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
613 (
std::string(prefix) + (prefix[0] ==
'\0' ?
"" :
"/") + case_name +
"/" 615 GetPrefixUntilComma(test_names).c_str(),
616 GetTypeName<Type>().c_str(),
618 GetTypeId<FixtureClass>(),
619 TestClass::SetUpTestCase,
620 TestClass::TearDownTestCase,
624 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
625 ::Register(prefix, case_name, test_names, index + 1);
630 template <GTEST_TEMPLATE_ Fixture,
class TestSel>
631 class TypeParameterizedTest<Fixture, TestSel, Types0>
634 static bool Register(
const char * ,
const char * ,
645 template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
646 class TypeParameterizedTestCase
649 static bool Register(
const char * prefix,
const char * case_name,
650 const char * test_names)
652 typedef typename Tests::Head Head;
655 TypeParameterizedTest<Fixture, Head, Types>::Register(
656 prefix, case_name, test_names, 0);
659 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
660 ::Register(prefix, case_name, SkipComma(test_names));
665 template <GTEST_TEMPLATE_ Fixture,
typename Types>
666 class TypeParameterizedTestCase<Fixture, Templates0, Types>
669 static bool Register(
const char * ,
const char * ,
676 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 689 UnitTest * unit_test,
int skip_count);
706 operator bool()
const {
return true; }
718 static const UInt32 kMaxRange = 1u << 31;
735 template <
typename T1,
typename T2>
738 template <
typename T>
746 template <
typename T>
748 template <
typename T>
753 #define GTEST_REMOVE_REFERENCE_(T) \ 754 typename ::testing::internal::RemoveReference<T>::type 759 template <
typename T>
761 template <
typename T>
767 template <
typename T,
size_t N>
773 #if defined(_MSC_VER) && _MSC_VER < 1400 777 template <
typename T,
size_t N>
786 #define GTEST_REMOVE_CONST_(T) \ 787 typename ::testing::internal::RemoveConst<T>::type 790 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ 791 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) 796 template <
typename T>
798 template <
typename T>
803 #define GTEST_ADD_REFERENCE_(T) \ 804 typename ::testing::internal::AddReference<T>::type 815 #define GTEST_REFERENCE_TO_CONST_(T) \ 816 GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T)) 821 template <
typename From,
typename To>
822 class ImplicitlyConvertible
831 static From MakeFrom();
843 static char Helper(To);
844 static char (&Helper(...))[2];
853 # pragma warning(push) // Saves the current warning state. 854 # pragma warning(disable:4244) // Temporarily disables warning 4244. 856 static const bool value =
857 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
858 # pragma warning(pop) // Restores the warning state. 859 #elif defined(__BORLANDC__) 863 static const bool value = __is_convertible(From, To);
865 static const bool value =
866 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
869 template <
typename From,
typename To>
870 const bool ImplicitlyConvertible<From, To>::value;
875 template <
typename T>
876 struct IsAProtocolMessage
877 :
public bool_constant <
878 ImplicitlyConvertible<const T *, const ::ProtocolMessage *>::value ||
879 ImplicitlyConvertible<const T *, const ::proto2::Message *>::value >
907 typename C::iterator * = NULL,
908 typename C::const_iterator * = NULL)
921 template<
bool>
struct EnableIf;
930 template <
typename T,
typename U>
931 bool ArrayEq(
const T * lhs,
size_t size,
const U * rhs);
934 template <
typename T,
typename U>
935 inline bool ArrayEq(
const T & lhs,
const U & rhs) {
return lhs == rhs; }
938 template <
typename T,
typename U,
size_t N>
939 inline bool ArrayEq(
const T(&lhs)[N],
const U(&rhs)[N])
947 template <
typename T,
typename U>
948 bool ArrayEq(
const T * lhs,
size_t size,
const U * rhs)
950 for (
size_t i = 0; i != size; i++)
961 template <
typename Iter,
typename Element>
964 for (
Iter it = begin; it !=
end; ++it)
977 template <
typename T,
typename U>
978 void CopyArray(
const T * from,
size_t size, U * to);
981 template <
typename T,
typename U>
982 inline void CopyArray(
const T & from, U * to) { *to = from; }
985 template <
typename T,
typename U,
size_t N>
986 inline void CopyArray(
const T(&from)[N], U(*to)[N])
994 template <
typename T,
typename U>
995 void CopyArray(
const T * from,
size_t size, U * to)
997 for (
size_t i = 0; i != size; i++)
1020 template <
typename Element>
1032 Init(array, count, relation);
1048 if (relation_to_source_ == kCopy)
1049 {
delete[] array_; }
1053 size_t size()
const {
return size_; }
1054 const_iterator
begin()
const {
return array_; }
1055 const_iterator
end()
const {
return array_ + size_; }
1058 return size() == rhs.
size() &&
1074 Element *
const copy =
new Element[a_size];
1080 relation_to_source_ = relation;
1083 const Element * array_;
1093 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \ 1094 ::testing::internal::AssertHelper(result_type, file, line, message) \ 1095 = ::testing::Message() 1097 #define GTEST_MESSAGE_(message, result_type) \ 1098 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) 1100 #define GTEST_FATAL_FAILURE_(message) \ 1101 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) 1103 #define GTEST_NONFATAL_FAILURE_(message) \ 1104 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) 1106 #define GTEST_SUCCESS_(message) \ 1107 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) 1112 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ 1113 if (::testing::internal::AlwaysTrue()) { statement; } 1115 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ 1116 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1117 if (::testing::internal::ConstCharPtr gtest_msg = "") { \ 1118 bool gtest_caught_expected = false; \ 1120 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 1122 catch (expected_exception const&) { \ 1123 gtest_caught_expected = true; \ 1127 "Expected: " #statement " throws an exception of type " \ 1128 #expected_exception ".\n Actual: it throws a different type."; \ 1129 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ 1131 if (!gtest_caught_expected) { \ 1133 "Expected: " #statement " throws an exception of type " \ 1134 #expected_exception ".\n Actual: it throws nothing."; \ 1135 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ 1138 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ 1139 fail(gtest_msg.value) 1141 #define GTEST_TEST_NO_THROW_(statement, fail) \ 1142 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1143 if (::testing::internal::AlwaysTrue()) { \ 1145 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 1148 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ 1151 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ 1152 fail("Expected: " #statement " doesn't throw an exception.\n" \ 1153 " Actual: it throws.") 1155 #define GTEST_TEST_ANY_THROW_(statement, fail) \ 1156 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1157 if (::testing::internal::AlwaysTrue()) { \ 1158 bool gtest_caught_any = false; \ 1160 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 1163 gtest_caught_any = true; \ 1165 if (!gtest_caught_any) { \ 1166 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ 1169 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ 1170 fail("Expected: " #statement " throws an exception.\n" \ 1171 " Actual: it doesn't.") 1177 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ 1178 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1179 if (const ::testing::AssertionResult gtest_ar_ = \ 1180 ::testing::AssertionResult(expression)) \ 1183 fail(::testing::internal::GetBoolAssertionFailureMessage(\ 1184 gtest_ar_, text, #actual, #expected).c_str()) 1186 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ 1187 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 1188 if (::testing::internal::AlwaysTrue()) { \ 1189 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ 1190 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 1191 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ 1192 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ 1195 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ 1196 fail("Expected: " #statement " doesn't generate new fatal " \ 1197 "failures in the current thread.\n" \ 1198 " Actual: it does.") 1201 #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ 1202 test_case_name##_##test_name##_Test 1205 #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ 1206 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ 1208 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ 1210 virtual void TestBody();\ 1211 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ 1212 GTEST_DISALLOW_COPY_AND_ASSIGN_(\ 1213 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ 1216 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ 1218 ::testing::internal::MakeAndRegisterTestInfo(\ 1219 #test_case_name, #test_name, NULL, NULL, \ 1221 parent_class::SetUpTestCase, \ 1222 parent_class::TearDownTestCase, \ 1223 new ::testing::internal::TestFactoryImpl<\ 1224 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ 1225 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() 1227 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
bool operator==(const NativeArray &rhs) const
static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, const Bits &sam2)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
void(* TearDownTestCaseFunc)()
Bits exponent_bits() const
virtual ~TestFactoryBase()
static RawType Infinity()
static RawType ReinterpretBits(const Bits bits)
::std::string PrintToString(const T &value)
const Element * const_iterator
GTEST_API_ int g_init_gtest_count
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
TypeWithSize< 4 >::UInt UInt32
FloatingPoint(const RawType &x)
void(* SetUpTestCaseFunc)()
const_iterator begin() const
bool SkipPrefix(const char *prefix, const char **pstr)
RelationToSource relation_to_source_
TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
std::string StreamableToString(const T &streamable)
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
def Iter(n, format, sep='')
std::string GetCurrentOsStackTraceExceptTop(UnitTest *, int skip_count)
bool AlmostEquals(const FloatingPoint &rhs) const
#define GTEST_DISALLOW_ASSIGN_(type)
NativeArray(const NativeArray &rhs)
void Init(const Element *array, size_t a_size, RelationToSource relation)
static Bits SignAndMagnitudeToBiased(const Bits &sam)
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
const char kStackTraceMarker[]
std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
Bits fraction_bits() const
AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
const Bits & bits() const
std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
TypeWithSize< sizeof(RawType)>::UInt Bits
const_iterator end() const
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
ConstCharPtr(const char *str)
void CopyArray(const T *from, size_t size, U *to)
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
virtual Test * CreateTest()
char IsNullLiteralHelper(Secret *p)
#define GTEST_ATTRIBUTE_UNUSED_
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
NativeArray(const Element *array, size_t count, RelationToSource relation)