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>
47 #endif // GTEST_OS_LINUX
49 #if GTEST_HAS_EXCEPTIONS
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;
83 class AssertionResult;
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)
134 #endif // GTEST_ELLIPSIS_NEEDS_POD_
138 const std::string& gtest_msg,
const Message& user_msg);
140 #if GTEST_HAS_EXCEPTIONS
148 class GTEST_API_ GoogleTestFailureException :
public ::std::runtime_error {
150 explicit GoogleTestFailureException(
const TestPartResult& failure);
153 #endif // GTEST_HAS_EXCEPTIONS
190 const char* actual_expression,
198 const char* expression_text,
199 const char* actual_predicate_value,
200 const char* expected_predicate_value);
231 template <
typename RawType>
245 std::numeric_limits<RawType>::digits - 1;
251 static const Bits
kSignBitMask =
static_cast<Bits
>(1) << (kBitCount - 1);
255 ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
299 static RawType
Max();
304 const Bits &
bits()
const {
return u_.bits_; }
313 Bits
sign_bit()
const {
return kSignBitMask & u_.bits_; }
333 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
339 union FloatingPointUnion {
359 static Bits SignAndMagnitudeToBiased(
const Bits &sam) {
360 if (kSignBitMask & sam) {
365 return kSignBitMask | sam;
371 static Bits DistanceBetweenSignAndMagnitudeNumbers(
const Bits &sam1,
373 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
374 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
375 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
378 FloatingPointUnion u_;
401 template <
typename T>
410 template <
typename T>
416 template <
typename T>
422 return &(TypeIdHelper<T>::dummy_);
451 template <
class TestClass>
468 #endif // GTEST_OS_WINDOWS
492 const char* test_case_name,
494 const char* type_param,
495 const char* value_param,
496 TypeId fixture_class_id,
506 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
511 TypedTestCasePState() : registered_(false) {}
516 bool AddTestName(
const char* file,
int line,
const char* case_name,
517 const char* test_name) {
519 fprintf(stderr,
"%s Test %s must be defined before "
520 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
525 defined_test_names_.insert(test_name);
532 const char* VerifyRegisteredTestNames(
533 const char* file,
int line,
const char* registered_tests);
537 ::std::set<const char*> defined_test_names_;
542 inline const char* SkipComma(
const char* str) {
543 const char* comma = strchr(str,
',');
553 inline std::string GetPrefixUntilComma(
const char* str) {
554 const char* comma = strchr(str,
',');
555 return comma == NULL ? str :
std::string(str, comma);
565 template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
566 class TypeParameterizedTest {
572 static bool Register(
const char*
prefix,
const char* case_name,
573 const char* test_names,
int index) {
574 typedef typename Types::Head Type;
575 typedef Fixture<Type> FixtureClass;
576 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
581 (
std::
string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
583 GetPrefixUntilComma(test_names).c_str(),
587 TestClass::SetUpTestCase,
588 TestClass::TearDownTestCase,
589 new TestFactoryImpl<TestClass>);
592 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
593 ::Register(prefix, case_name, test_names, index + 1);
598 template <GTEST_TEMPLATE_ Fixture, class TestSel>
599 class TypeParameterizedTest<Fixture, TestSel, Types0> {
601 static bool Register(
const char* ,
const char* ,
602 const char* ,
int ) {
611 template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
612 class TypeParameterizedTestCase {
614 static bool Register(
const char* prefix,
const char* case_name,
615 const char* test_names) {
616 typedef typename Tests::Head Head;
619 TypeParameterizedTest<Fixture, Head, Types>::Register(
620 prefix, case_name, test_names, 0);
623 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
624 ::Register(prefix, case_name, SkipComma(test_names));
629 template <GTEST_TEMPLATE_ Fixture,
typename Types>
630 class TypeParameterizedTestCase<Fixture, Templates0, Types> {
632 static bool Register(
const char* ,
const char* ,
638 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
651 UnitTest* unit_test,
int skip_count);
667 operator bool()
const {
return true; }
678 static const UInt32 kMaxRange = 1u << 31;
695 template <
typename T1,
typename T2>
698 template <
typename T>
705 template <
typename T>
707 template <
typename T>
712 #define GTEST_REMOVE_REFERENCE_(T) \
713 typename ::testing::internal::RemoveReference<T>::type
718 template <
typename T>
720 template <
typename T>
726 template <
typename T,
size_t N>
731 #if defined(_MSC_VER) && _MSC_VER < 1400
735 template <
typename T,
size_t N>
743 #define GTEST_REMOVE_CONST_(T) \
744 typename ::testing::internal::RemoveConst<T>::type
747 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
748 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
753 template <
typename T>
755 template <
typename T>
760 #define GTEST_ADD_REFERENCE_(T) \
761 typename ::testing::internal::AddReference<T>::type
772 #define GTEST_REFERENCE_TO_CONST_(T) \
773 GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
778 template <
typename From,
typename To>
787 static From MakeFrom();
799 static char Helper(To);
800 static char (&Helper(...))[2];
809 # pragma warning(push) // Saves the current warning state.
810 # pragma warning(disable:4244) // Temporarily disables warning 4244.
812 static const bool value =
813 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
814 # pragma warning(pop) // Restores the warning state.
815 #elif defined(__BORLANDC__)
819 static const bool value = __is_convertible(From, To);
821 static const bool value =
822 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
825 template <
typename From,
typename To>
831 template <
typename T>
834 ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
835 ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
862 typename C::iterator* = NULL,
863 typename C::const_iterator* = NULL) {
884 template <
typename T,
typename U>
885 bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs);
888 template <
typename T,
typename U>
889 inline bool ArrayEq(
const T& lhs,
const U& rhs) {
return lhs == rhs; }
892 template <
typename T,
typename U,
size_t N>
893 inline bool ArrayEq(
const T(&lhs)[
N],
const U(&rhs)[N]) {
900 template <
typename T,
typename U>
901 bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs) {
902 for (
size_t i = 0; i != size; i++) {
911 template <
typename Iter,
typename Element>
913 for (Iter it = begin; it != end; ++it) {
924 template <
typename T,
typename U>
925 void CopyArray(
const T* from,
size_t size, U* to);
928 template <
typename T,
typename U>
932 template <
typename T,
typename U,
size_t N>
940 template <
typename T,
typename U>
942 for (
size_t i = 0; i != size; i++) {
963 template <
typename Element>
973 Init(array, count, relation);
978 Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
986 if (relation_to_source_ ==
kCopy)
991 size_t size()
const {
return size_; }
992 const_iterator
begin()
const {
return array_; }
993 const_iterator
end()
const {
return array_ + size_; }
995 return size() == rhs.
size() &&
1006 Element*
const copy =
new Element[a_size];
1011 relation_to_source_ = relation;
1014 const Element* array_;
1024 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1025 ::testing::internal::AssertHelper(result_type, file, line, message) \
1026 = ::testing::Message()
1028 #define GTEST_MESSAGE_(message, result_type) \
1029 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1031 #define GTEST_FATAL_FAILURE_(message) \
1032 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1034 #define GTEST_NONFATAL_FAILURE_(message) \
1035 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1037 #define GTEST_SUCCESS_(message) \
1038 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1043 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1044 if (::testing::internal::AlwaysTrue()) { statement; }
1046 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1047 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1048 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1049 bool gtest_caught_expected = false; \
1051 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1053 catch (expected_exception const&) { \
1054 gtest_caught_expected = true; \
1058 "Expected: " #statement " throws an exception of type " \
1059 #expected_exception ".\n Actual: it throws a different type."; \
1060 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1062 if (!gtest_caught_expected) { \
1064 "Expected: " #statement " throws an exception of type " \
1065 #expected_exception ".\n Actual: it throws nothing."; \
1066 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1069 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1070 fail(gtest_msg.value)
1072 #define GTEST_TEST_NO_THROW_(statement, fail) \
1073 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1074 if (::testing::internal::AlwaysTrue()) { \
1076 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1079 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1082 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1083 fail("Expected: " #statement " doesn't throw an exception.\n" \
1084 " Actual: it throws.")
1086 #define GTEST_TEST_ANY_THROW_(statement, fail) \
1087 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1088 if (::testing::internal::AlwaysTrue()) { \
1089 bool gtest_caught_any = false; \
1091 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1094 gtest_caught_any = true; \
1096 if (!gtest_caught_any) { \
1097 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1100 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1101 fail("Expected: " #statement " throws an exception.\n" \
1102 " Actual: it doesn't.")
1108 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1109 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1110 if (const ::testing::AssertionResult gtest_ar_ = \
1111 ::testing::AssertionResult(expression)) \
1114 fail(::testing::internal::GetBoolAssertionFailureMessage(\
1115 gtest_ar_, text, #actual, #expected).c_str())
1117 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1118 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1119 if (::testing::internal::AlwaysTrue()) { \
1120 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1121 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1122 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1123 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1126 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1127 fail("Expected: " #statement " doesn't generate new fatal " \
1128 "failures in the current thread.\n" \
1129 " Actual: it does.")
1132 #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1133 test_case_name##_##test_name##_Test
1136 #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
1137 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
1139 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
1141 virtual void TestBody();\
1142 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
1143 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1144 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
1147 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
1149 ::testing::internal::MakeAndRegisterTestInfo(\
1150 #test_case_name, #test_name, NULL, NULL, \
1152 parent_class::SetUpTestCase, \
1153 parent_class::TearDownTestCase, \
1154 new ::testing::internal::TestFactoryImpl<\
1155 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
1156 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
1158 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
Element * iterator
Definition: gtest-internal.h:968
TypeId GetTypeId()
Definition: gtest-internal.h:417
bool operator==(const NativeArray &rhs) const
Definition: gtest-internal.h:994
const char * value
Definition: gtest-internal.h:668
Definition: gtest-death-test.h:43
void(* TearDownTestCaseFunc)()
Definition: gtest-internal.h:472
T type
Definition: gtest-internal.h:721
Definition: gtest-internal.h:964
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
Definition: gtest.cc:4635
Bits exponent_bits() const
Definition: gtest-internal.h:307
virtual ~TestFactoryBase()
Definition: gtest-internal.h:436
static const size_t kMaxUlps
Definition: gtest-internal.h:272
static RawType Infinity()
Definition: gtest-internal.h:294
T & type
Definition: gtest-internal.h:756
const std::string prefix
Definition: wavef.h:63
T type
Definition: gtest-internal.h:706
Definition: gtest-internal.h:665
T type
Definition: gtest-internal.h:708
int IsContainer
Definition: gtest-internal.h:859
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
static RawType ReinterpretBits(const Bits bits)
Definition: gtest-internal.h:287
::std::string PrintToString(const T &value)
Definition: gtest-printers.h:847
virtual Test * CreateTest()=0
Bits sign_bit() const
Definition: gtest-internal.h:313
const Element * const_iterator
Definition: gtest-internal.h:969
GTEST_API_ int g_init_gtest_count
Definition: gtest.cc:315
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Definition: gtest-port.cc:456
FloatingPoint(const RawType &x)
Definition: gtest-internal.h:280
::std::string string
Definition: gtest-port.h:872
static const size_t kExponentBitCount
Definition: gtest-internal.h:248
void(* SetUpTestCaseFunc)()
Definition: gtest-internal.h:471
Definition: gtest-internal.h:706
Definition: mpreal.h:3066
Definition: gtest-internal.h:676
T type
Definition: gtest-internal.h:719
const_iterator begin() const
Definition: gtest-internal.h:992
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
Definition: gtest.cc:4663
Definition: gtest-port.h:1867
Definition: gtest-internal.h:452
#define GTEST_API_
Definition: gtest-port.h:768
Definition: gtest-internal.h:696
GTEST_API_ 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)
Definition: gtest.cc:2216
Element value_type
Definition: gtest-internal.h:967
Definition: gtest-message.h:85
Definition: gtest-internal.h:434
#define GTEST_DISALLOW_ASSIGN_(type)
Definition: gtest-port.h:721
std::string StreamableToString(const T &streamable)
Definition: gtest-message.h:243
std::string GetTypeName()
Definition: gtest-type-util.h:64
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
Definition: gtest-internal.h:901
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:1901
const void * TypeId
Definition: gtest-internal.h:399
bool IsSpace(char ch)
Definition: gtest-port.h:1671
GTEST_API_ TypeId GetTestTypeId()
Definition: gtest.cc:598
T & type
Definition: gtest-internal.h:754
FloatingPoint< float > Float
Definition: gtest-internal.h:390
FloatingPoint< double > Double
Definition: gtest-internal.h:391
Definition: gtest-internal.h:875
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
void Reseed(UInt32 seed)
Definition: gtest-internal.h:682
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
GTEST_API_ bool AlwaysTrue()
Definition: gtest.cc:4650
bool AlwaysFalse()
Definition: gtest-internal.h:660
const double N
Definition: navstokes_cosines.cc:94
bool AlmostEquals(const FloatingPoint &rhs) const
Definition: gtest-internal.h:328
NativeArray(const NativeArray &rhs)
Definition: gtest-internal.h:977
Definition: gtest-port.h:864
void type
Definition: gtest-internal.h:876
Definition: gtest-internal.h:779
void Init(int &argc, char **&argv)
Analogous to MPI_Init.
Definition: safempi.h:730
Definition: gtest-port.h:1611
Definition: gtest-internal.h:77
GTEST_API_ const char kStackTraceMarker[]
Definition: gtest.cc:177
Definition: gtest-internal.h:232
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
Definition: gtest.cc:1678
Definition: gtest-internal.h:156
Definition: gtest-internal.h:754
char IsNotContainer
Definition: gtest-internal.h:867
Bits fraction_bits() const
Definition: gtest-internal.h:310
TestFactoryBase()
Definition: gtest-internal.h:443
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)
Definition: gtest.cc:1000
const Bits & bits() const
Definition: gtest-internal.h:304
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
Definition: gtest.cc:1023
static const size_t kFractionBitCount
Definition: gtest-internal.h:244
void Abort()
Definition: gtest-port.h:1816
TypeWithSize< sizeof(RawType)>::UInt Bits
Definition: gtest-internal.h:236
Definition: gtest-internal.h:832
const_iterator end() const
Definition: gtest-internal.h:993
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:726
Definition: gtest-internal.h:951
ConstCharPtr(const char *str)
Definition: gtest-internal.h:666
void CopyArray(const T *from, size_t size, U *to)
Definition: gtest-internal.h:941
static const Bits kFractionBitMask
Definition: gtest-internal.h:254
Definition: gtest-internal.h:402
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
Definition: gtest-internal.h:912
Definition: gtest-internal.h:950
Random(UInt32 seed)
Definition: gtest-internal.h:680
virtual Test * CreateTest()
Definition: gtest-internal.h:454
RelationToSource
Definition: gtest-internal.h:949
char IsNullLiteralHelper(Secret *p)
static const Bits kSignBitMask
Definition: gtest-internal.h:251
static const size_t kBitCount
Definition: gtest-internal.h:241
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
Definition: gtest-internal.h:861
size_t size() const
Definition: gtest-internal.h:991
NativeArray(const Element *array, size_t count, RelationToSource relation)
Definition: gtest-internal.h:972
static bool dummy_
Definition: gtest-internal.h:407
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T)
Definition: gtest-internal.h:747
Definition: gtest-internal.h:719
~NativeArray()
Definition: gtest-internal.h:981
static const Bits kExponentBitMask
Definition: gtest-internal.h:258
bool is_nan() const
Definition: gtest-internal.h:316