37 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
38 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
44 # include <sys/types.h>
45 # include <sys/wait.h>
49 #if GTEST_HAS_EXCEPTIONS
61 #include <type_traits>
77 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
78 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
81 #define GTEST_STRINGIFY_(name) #name
89 class AssertionResult;
120 template <
typename T,
121 typename std::enable_if<!std::is_convertible<T, Sink>::value,
130 #if GTEST_HAS_EXCEPTIONS
141 class
GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
143 explicit GoogleTestFailureException(
const TestPartResult& failure);
150 namespace edit_distance {
158 const std::vector<size_t>& left,
const std::vector<size_t>& right);
162 const std::vector<std::string>& left,
163 const std::vector<std::string>& right);
167 const std::vector<std::string>& right,
178 size_t* total_line_count);
196 const char* actual_expression,
203 const AssertionResult& assertion_result,
204 const char* expression_text,
205 const char* actual_predicate_value,
206 const char* expected_predicate_value);
237 template <
typename RawType>
251 std::numeric_limits<RawType>::digits - 1;
339 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
345 union FloatingPointUnion {
365 static Bits SignAndMagnitudeToBiased(
const Bits &sam) {
377 static Bits DistanceBetweenSignAndMagnitudeNumbers(
const Bits &sam1,
379 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
380 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
381 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
384 FloatingPointUnion u_;
407 template <
typename T>
416 template <
typename T>
422 template <
typename T>
457 template <
class TestClass>
469 GTEST_API_ AssertionResult IsHRESULTSuccess(
const char* expr,
471 GTEST_API_ AssertionResult IsHRESULTFailure(
const char* expr,
496 return a == def ? nullptr : a;
499 template <
typename T>
507 typename std::conditional<
sizeof(T) != 0, ::
testing::Test,
void>::type;
516 <<
"Test can not provide both SetUpTestSuite and SetUpTestCase, please "
517 "make sure there is only one present ";
519 return test_case_fp !=
nullptr ? test_case_fp : test_suite_fp;
529 <<
"Test can not provide both TearDownTestSuite and TearDownTestCase,"
530 " please make sure there is only one present ";
532 return test_case_fp !=
nullptr ? test_case_fp : test_suite_fp;
555 const char* test_suite_name,
const char* name,
const char* type_param,
565 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
573 TypedTestSuitePState() : registered_(false) {}
578 bool AddTestName(
const char* file,
int line,
const char* case_name,
579 const char* test_name) {
582 "%s Test %s must be defined before "
583 "REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n",
588 registered_tests_.insert(
589 ::std::make_pair(test_name, CodeLocation(file, line)));
593 bool TestExists(
const std::string& test_name)
const {
594 return registered_tests_.count(test_name) > 0;
597 const CodeLocation& GetCodeLocation(
const std::string& test_name)
const {
598 RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
606 const char* VerifyRegisteredTestNames(
607 const char* file,
int line,
const char* registered_tests);
610 typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
613 RegisteredTestsMap registered_tests_;
617 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
618 using TypedTestCasePState = TypedTestSuitePState;
625 inline const
char* SkipComma(const
char* str) {
626 const char* comma = strchr(str,
',');
627 if (comma ==
nullptr) {
636 inline std::string GetPrefixUntilComma(
const char* str) {
637 const char* comma = strchr(str,
',');
638 return comma ==
nullptr ? str :
std::string(str, comma);
644 ::std::vector< ::std::string>* dest);
648 struct DefaultNameGenerator {
649 template <
typename T>
655 template <
typename Prov
ided = DefaultNameGenerator>
656 struct NameGeneratorSelector {
657 typedef Provided type;
660 template <
typename NameGenerator>
661 void GenerateNamesRecursively(Types0, std::vector<std::string>*,
int) {}
663 template <
typename NameGenerator,
typename Types>
664 void GenerateNamesRecursively(Types, std::vector<std::string>* result,
int i) {
665 result->push_back(NameGenerator::template GetName<typename Types::Head>(i));
666 GenerateNamesRecursively<NameGenerator>(
typename Types::Tail(), result,
670 template <
typename NameGenerator,
typename Types>
671 std::vector<std::string> GenerateNames() {
672 std::vector<std::string> result;
673 GenerateNamesRecursively<NameGenerator>(Types(), &result, 0);
684 template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
685 class TypeParameterizedTest {
691 static bool Register(
const char* prefix,
const CodeLocation& code_location,
692 const char* case_name,
const char* test_names,
int index,
693 const std::vector<std::string>& type_names =
694 GenerateNames<DefaultNameGenerator, Types>()) {
695 typedef typename Types::Head Type;
696 typedef Fixture<Type> FixtureClass;
697 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
702 (
std::string(prefix) + (prefix[0] ==
'\0' ?
"" :
"/") + case_name +
703 "/" + type_names[index])
706 GetTypeName<Type>().c_str(),
708 code_location, GetTypeId<FixtureClass>(),
711 new TestFactoryImpl<TestClass>);
714 return TypeParameterizedTest<Fixture, TestSel,
715 typename Types::Tail>::Register(prefix,
725 template <GTEST_TEMPLATE_ Fixture,
class TestSel>
726 class TypeParameterizedTest<Fixture, TestSel, Types0> {
728 static bool Register(
const char* ,
const CodeLocation&,
729 const char* ,
const char* ,
731 const std::vector<std::string>& =
732 std::vector<std::string>() ) {
741 template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
742 class TypeParameterizedTestSuite {
744 static bool Register(
const char* prefix, CodeLocation code_location,
745 const TypedTestSuitePState* state,
const char* case_name,
746 const char* test_names,
747 const std::vector<std::string>& type_names =
748 GenerateNames<DefaultNameGenerator, Types>()) {
750 GetPrefixUntilComma(test_names));
751 if (!state->TestExists(test_name)) {
752 fprintf(stderr,
"Failed to get code location for test %s.%s at %s.",
753 case_name, test_name.c_str(),
755 code_location.line).c_str());
759 const CodeLocation& test_location = state->GetCodeLocation(test_name);
761 typedef typename Tests::Head Head;
764 TypeParameterizedTest<Fixture, Head, Types>::Register(
765 prefix, test_location, case_name, test_names, 0, type_names);
768 return TypeParameterizedTestSuite<Fixture,
typename Tests::Tail,
769 Types>::Register(prefix, code_location,
771 SkipComma(test_names),
777 template <GTEST_TEMPLATE_ Fixture,
typename Types>
778 class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
780 static bool Register(
const char* ,
const CodeLocation&,
781 const TypedTestSuitePState* ,
782 const char* ,
const char* ,
783 const std::vector<std::string>& =
784 std::vector<std::string>() ) {
802 UnitTest* unit_test,
int skip_count);
818 operator bool()
const {
return true; }
829 static const UInt32 kMaxRange = 1u << 31;
846 template <
typename T1,
typename T2>
849 template <
typename T>
856 template <
typename T>
858 template <
typename T>
863 #define GTEST_REMOVE_REFERENCE_(T) \
864 typename ::testing::internal::RemoveReference<T>::type
869 template <
typename T>
871 template <
typename T>
877 template <
typename T,
size_t N>
884 #define GTEST_REMOVE_CONST_(T) \
885 typename ::testing::internal::RemoveConst<T>::type
888 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
889 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
893 template <
typename T>
896 std::is_convertible<const T*, const ::proto2::Message*>::value> {
925 class Iterator = decltype(::std::declval<const C&>().begin()),
926 class = decltype(::std::declval<const C&>().
end()),
927 class = decltype(++::std::declval<Iterator&>()),
928 class = decltype(*::std::declval<Iterator>()),
929 class =
typename C::const_iterator>
942 template <
typename T>
945 template <
typename U>
946 static char test(
typename U::hasher*,
typename U::reverse_iterator*);
947 template <
typename U>
948 static int test(
typename U::hasher*, ...);
949 template <
typename U>
950 static char test(...);
953 static const bool value =
sizeof(test<T>(
nullptr,
nullptr)) ==
sizeof(
int);
956 template <
typename T>
959 template <
typename C,
960 bool =
sizeof(IsContainerTest<C>(0)) ==
sizeof(
IsContainer)>
963 template <
typename C>
970 template <
typename C>
972 using value_type = decltype(*std::declval<typename C::const_iterator>());
974 is_same<
typename std::remove_const<
975 typename std::remove_reference<value_type>::type>
::type,
985 template <
typename C>
1001 template <
typename T,
typename U>
1002 bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs);
1005 template <
typename T,
typename U>
1006 inline bool ArrayEq(
const T& lhs,
const U& rhs) {
return lhs == rhs; }
1009 template <
typename T,
typename U,
size_t N>
1010 inline bool ArrayEq(
const T(&lhs)[N],
const U(&rhs)[N]) {
1017 template <
typename T,
typename U>
1018 bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs) {
1019 for (
size_t i = 0; i != size; i++) {
1028 template <
typename Iter,
typename Element>
1030 for (Iter it = begin; it !=
end; ++it) {
1041 template <
typename T,
typename U>
1042 void CopyArray(
const T* from,
size_t size, U* to);
1045 template <
typename T,
typename U>
1049 template <
typename T,
typename U,
size_t N>
1057 template <
typename T,
typename U>
1059 for (
size_t i = 0; i != size; i++) {
1079 template <
typename Element>
1089 InitRef(array, count);
1094 InitCopy(array, count);
1099 (this->*rhs.clone_)(rhs.array_, rhs.size_);
1103 if (clone_ != &NativeArray::InitRef)
1108 size_t size()
const {
return size_; }
1123 void InitCopy(
const Element* array,
size_t a_size) {
1124 Element*
const copy =
new Element[a_size];
1128 clone_ = &NativeArray::InitCopy;
1132 void InitRef(
const Element* array,
size_t a_size) {
1135 clone_ = &NativeArray::InitRef;
1138 const Element* array_;
1140 void (
NativeArray::*clone_)(
const Element*, size_t);
1146 template <
size_t... Is>
1152 template <
bool plus_one,
typename T,
size_t sizeofT>
1154 template <
size_t... I,
size_t sizeofT>
1158 template <
size_t... I,
size_t sizeofT>
1167 :
DoubleSequence<N % 2 == 1, typename MakeIndexSequence<N / 2>::type,
1176 template <
typename T,
size_t,
size_t>
1179 template <
typename T,
size_t I>
1186 template <
size_t N,
typename I,
typename... T>
1189 template <
size_t N,
size_t... I,
typename... T>
1193 template <
typename... T>
1196 template <
typename Derived,
size_t I>
1199 template <
typename... T,
size_t I>
1209 template <
typename Derived,
typename Idx>
1212 template <
size_t... Idx,
typename... T>
1230 template <
typename... T>
1233 typename MakeIndexSequence<sizeof...(T)>::type> {
1234 using Indices =
typename FlatTuple::FlatTupleBase::Indices;
1254 "INSTANTIATE_TEST_CASE_P is deprecated, please use "
1255 "INSTANTIATE_TEST_SUITE_P")
1256 constexpr
bool InstantiateTestCase_P_IsDeprecated() {
return true; }
1259 "TYPED_TEST_CASE_P is deprecated, please use "
1260 "TYPED_TEST_SUITE_P")
1261 constexpr
bool TypedTestCase_P_IsDeprecated() {
return true; }
1264 "TYPED_TEST_CASE is deprecated, please use "
1266 constexpr
bool TypedTestCaseIsDeprecated() {
return true; }
1269 "REGISTER_TYPED_TEST_CASE_P is deprecated, please use "
1270 "REGISTER_TYPED_TEST_SUITE_P")
1271 constexpr
bool RegisterTypedTestCase_P_IsDeprecated() {
return true; }
1274 "INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use "
1275 "INSTANTIATE_TYPED_TEST_SUITE_P")
1276 constexpr
bool InstantiateTypedTestCase_P_IsDeprecated() {
return true; }
1281 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1282 ::testing::internal::AssertHelper(result_type, file, line, message) \
1283 = ::testing::Message()
1285 #define GTEST_MESSAGE_(message, result_type) \
1286 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1288 #define GTEST_FATAL_FAILURE_(message) \
1289 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1291 #define GTEST_NONFATAL_FAILURE_(message) \
1292 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1294 #define GTEST_SUCCESS_(message) \
1295 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1297 #define GTEST_SKIP_(message) \
1298 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kSkip)
1303 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1304 if (::testing::internal::AlwaysTrue()) { statement; }
1306 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1307 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1308 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1309 bool gtest_caught_expected = false; \
1311 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1313 catch (expected_exception const&) { \
1314 gtest_caught_expected = true; \
1318 "Expected: " #statement " throws an exception of type " \
1319 #expected_exception ".\n Actual: it throws a different type."; \
1320 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1322 if (!gtest_caught_expected) { \
1324 "Expected: " #statement " throws an exception of type " \
1325 #expected_exception ".\n Actual: it throws nothing."; \
1326 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1329 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1330 fail(gtest_msg.value)
1332 #define GTEST_TEST_NO_THROW_(statement, fail) \
1333 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1334 if (::testing::internal::AlwaysTrue()) { \
1336 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1339 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1342 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1343 fail("Expected: " #statement " doesn't throw an exception.\n" \
1344 " Actual: it throws.")
1346 #define GTEST_TEST_ANY_THROW_(statement, fail) \
1347 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1348 if (::testing::internal::AlwaysTrue()) { \
1349 bool gtest_caught_any = false; \
1351 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1354 gtest_caught_any = true; \
1356 if (!gtest_caught_any) { \
1357 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1360 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1361 fail("Expected: " #statement " throws an exception.\n" \
1362 " Actual: it doesn't.")
1368 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1369 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1370 if (const ::testing::AssertionResult gtest_ar_ = \
1371 ::testing::AssertionResult(expression)) \
1374 fail(::testing::internal::GetBoolAssertionFailureMessage(\
1375 gtest_ar_, text, #actual, #expected).c_str())
1377 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1378 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1379 if (::testing::internal::AlwaysTrue()) { \
1380 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1381 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1382 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1383 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1386 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1387 fail("Expected: " #statement " doesn't generate new fatal " \
1388 "failures in the current thread.\n" \
1389 " Actual: it does.")
1392 #define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
1393 test_suite_name##_##test_name##_Test
1396 #define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
1397 class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
1398 : public parent_class { \
1400 GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
1403 virtual void TestBody(); \
1404 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
1405 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
1409 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \
1410 test_name)::test_info_ = \
1411 ::testing::internal::MakeAndRegisterTestInfo( \
1412 #test_suite_name, #test_name, nullptr, nullptr, \
1413 ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
1414 ::testing::internal::SuiteApiResolver< \
1415 parent_class>::GetSetUpCaseOrSuite(), \
1416 ::testing::internal::SuiteApiResolver< \
1417 parent_class>::GetTearDownCaseOrSuite(), \
1418 new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
1419 test_suite_name, test_name)>); \
1420 void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
double test(int data_type)
static void SetUpTestCase()
static void TearDownTestSuite()
static void SetUpTestSuite()
static void TearDownTestCase()
ElemFromList< I, Indices, T... >::type & Get()
const ElemFromList< I, Indices, T... >::type & Get() const
static const Bits kFractionBitMask
static const size_t kFractionBitCount
FloatingPoint(const RawType &x)
static const size_t kExponentBitCount
static RawType Infinity()
static const Bits kExponentBitMask
bool AlmostEquals(const FloatingPoint &rhs) const
Bits fraction_bits() const
const Bits & bits() const
static const size_t kMaxUlps
static const size_t kBitCount
TypeWithSize< sizeof(RawType)>::UInt Bits
static RawType ReinterpretBits(const Bits bits)
static const Bits kSignBitMask
Bits exponent_bits() const
const_iterator begin() const
NativeArray(const Element *array, size_t count, RelationToSourceReference)
bool operator==(const NativeArray &rhs) const
const Element * const_iterator
NativeArray(const NativeArray &rhs)
NativeArray(const Element *array, size_t count, RelationToSourceCopy)
const_iterator end() const
UInt32 Generate(UInt32 range)
virtual Test * CreateTest()=0
virtual ~TestFactoryBase()
Test * CreateTest() override
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
void copy(ColorSpinorField &dst, const ColorSpinorField &src)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
FloatingPoint< float > Float
void(*)() SetUpTearDownSuiteFuncType
GTEST_API_ TypeId GetTestTypeId()
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ bool AlwaysTrue()
GTEST_API_ std::string DiffStrings(const std::string &left, const std::string &right, size_t *total_line_count)
FloatingPoint< double > Double
IsContainer IsContainerTest(int)
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_suite_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase *factory)
void(*)() TearDownTestSuiteFunc
void(*)() SetUpTestSuiteFunc
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
SetUpTearDownSuiteFuncType GetNotDefaultOrNull(SetUpTearDownSuiteFuncType a, SetUpTearDownSuiteFuncType def)
GTEST_API_ const char kStackTraceMarker[]
std::string StripTrailingSpaces(std::string str)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
std::string StreamableToString(const T &streamable)
GTEST_INTERNAL_DEPRECATED("INSTANTIATE_TEST_CASE_P is deprecated, please use " "INSTANTIATE_TEST_SUITE_P") const expr bool InstantiateTestCase_P_IsDeprecated()
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)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
void CopyArray(const T *from, size_t size, U *to)
::std::string PrintToString(const T &value)
CodeLocation(const std::string &a_file, int a_line)
ConstCharPtr(const char *str)
FlatTupleElemBase(value_type t)
typename ElemFromList< I, typename MakeIndexSequence< sizeof...(T)>::type, T... >::type value_type
decltype(*std::declval< typename C::const_iterator >()) value_type
typename std::conditional< sizeof(T) !=0, ::testing::Test, void >::type Test
static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite()
static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite()