36#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
37#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
43# include <sys/types.h>
48#if GTEST_HAS_EXCEPTIONS
75#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
76#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
79#define GTEST_STRINGIFY_(name) #name
82namespace proto2 {
class Message; }
128#ifdef GTEST_ELLIPSIS_NEEDS_POD_
131# define GTEST_IS_NULL_LITERAL_(x) false
133# define GTEST_IS_NULL_LITERAL_(x) \
134 (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
139 const std::string& gtest_msg,
const Message& user_msg);
141#if GTEST_HAS_EXCEPTIONS
149class GTEST_API_ GoogleTestFailureException :
public ::std::runtime_error {
151 explicit GoogleTestFailureException(
const TestPartResult& failure);
156namespace edit_distance {
164 const std::vector<size_t>& left,
const std::vector<size_t>& right);
168 const std::vector<std::string>& left,
169 const std::vector<std::string>& right);
173 const std::vector<std::string>& right,
183 const std::string& right,
184 size_t* total_line_count);
202 const char* actual_expression,
203 const std::string& expected_value,
204 const std::string& actual_value,
210 const char* expression_text,
211 const char* actual_predicate_value,
212 const char* expected_predicate_value);
243template <
typename RawType>
257 std::numeric_limits<RawType>::digits - 1;
345 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
351 union FloatingPointUnion {
371 static Bits SignAndMagnitudeToBiased(
const Bits &sam) {
383 static Bits DistanceBetweenSignAndMagnitudeNumbers(
const Bits &sam1,
385 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
386 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
387 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
390 FloatingPointUnion u_;
463template <
class TestClass>
488 : file(a_file),
line(a_line) {}
513 const char* test_case_name,
515 const char* type_param,
516 const char* value_param,
528#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
533 TypedTestCasePState() : registered_(false) {}
538 bool AddTestName(
const char* file,
int line,
const char* case_name,
539 const char* test_name) {
541 fprintf(stderr,
"%s Test %s must be defined before "
542 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
543 FormatFileLocation(file, line).c_str(), test_name, case_name);
547 registered_tests_.insert(
548 ::std::make_pair(test_name, CodeLocation(file, line)));
552 bool TestExists(
const std::string& test_name)
const {
553 return registered_tests_.count(test_name) > 0;
556 const CodeLocation& GetCodeLocation(
const std::string& test_name)
const {
557 RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
565 const char* VerifyRegisteredTestNames(
566 const char* file,
int line,
const char* registered_tests);
569 typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
572 RegisteredTestsMap registered_tests_;
577inline const char* SkipComma(
const char* str) {
578 const char* comma = strchr(str,
',');
588inline std::string GetPrefixUntilComma(
const char* str) {
589 const char* comma = strchr(str,
',');
590 return comma == NULL ?
str : std::string(str, comma);
595void SplitString(const ::std::string& str,
char delimiter,
596 ::std::vector< ::std::string>* dest);
605template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
606class TypeParameterizedTest {
612 static bool Register(
const char* prefix,
613 const CodeLocation& code_location,
614 const char* case_name,
const char* test_names,
616 typedef typename Types::Head
Type;
623 (std::string(prefix) + (prefix[0] ==
'\0' ?
"" :
"/") + case_name +
"/"
624 + StreamableToString(index)).c_str(),
626 GetTypeName<Type>().c_str(),
629 GetTypeId<FixtureClass>(),
630 TestClass::SetUpTestCase,
631 TestClass::TearDownTestCase,
632 new TestFactoryImpl<TestClass>);
635 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
636 ::Register(prefix, code_location, case_name, test_names, index + 1);
641template <GTEST_TEMPLATE_ Fixture,
class TestSel>
642class TypeParameterizedTest<
Fixture, TestSel, Types0> {
644 static bool Register(
const char* ,
const CodeLocation&,
645 const char* ,
const char* ,
655template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
656class TypeParameterizedTestCase {
658 static bool Register(
const char* prefix, CodeLocation code_location,
659 const TypedTestCasePState*
state,
660 const char* case_name,
const char* test_names) {
662 GetPrefixUntilComma(test_names));
663 if (!
state->TestExists(test_name)) {
664 fprintf(stderr,
"Failed to get code location for test %s.%s at %s.",
665 case_name, test_name.c_str(),
666 FormatFileLocation(code_location.file.c_str(),
667 code_location.line).c_str());
671 const CodeLocation& test_location =
state->GetCodeLocation(test_name);
673 typedef typename Tests::Head Head;
676 TypeParameterizedTest<Fixture, Head, Types>::Register(
677 prefix, test_location, case_name, test_names, 0);
680 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
681 ::Register(prefix, code_location,
state,
682 case_name, SkipComma(test_names));
687template <GTEST_TEMPLATE_ Fixture,
typename Types>
688class TypeParameterizedTestCase<
Fixture, Templates0, Types> {
690 static bool Register(
const char* ,
const CodeLocation&,
691 const TypedTestCasePState* ,
692 const char* ,
const char* ) {
710 UnitTest* unit_test,
int skip_count);
726 operator bool()
const {
return true; }
737 static const UInt32 kMaxRange = 1u << 31;
754template <
typename T1,
typename T2>
771#define GTEST_REMOVE_REFERENCE_(T) \
772 typename ::testing::internal::RemoveReference<T>::type
785template <
typename T,
size_t N>
790#if defined(_MSC_VER) && _MSC_VER < 1400
794template <
typename T,
size_t N>
802#define GTEST_REMOVE_CONST_(T) \
803 typename ::testing::internal::RemoveConst<T>::type
806#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
807 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
812template <
typename From,
typename To>
833 static char Helper(
To);
834 static char (&Helper(...))[2];
839#if defined(__BORLANDC__)
843 static const bool value = __is_convertible(From,
To);
854template <
typename From,
typename To>
863 ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
864 ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
894 class Iterator =
decltype(::std::declval<const C&>().begin()),
895 class =
decltype(::std::declval<const C&>().end()),
896 class =
decltype(++::std::declval<Iterator&>()),
897 class =
decltype(*::std::declval<Iterator>()),
898 class =
typename C::const_iterator>
905 typename C::iterator* = NULL,
906 typename C::const_iterator* = NULL) {
922 template <
typename U>
923 static char test(
typename U::hasher*,
typename U::reverse_iterator*);
924 template <
typename U>
925 static int test(
typename U::hasher*, ...);
926 template <
typename U>
927 static char test(...);
930 static const bool value =
sizeof(test<T>(0, 0)) ==
sizeof(
int);
941template <
typename T,
typename =
void>
952template <
typename C,
bool HV>
995template <
typename T,
typename U>
996bool ArrayEq(
const T* lhs,
size_t size,
const U* rhs);
999template <
typename T,
typename U>
1000inline bool ArrayEq(
const T& lhs,
const U& rhs) {
return lhs == rhs; }
1003template <
typename T,
typename U,
size_t N>
1011template <
typename T,
typename U>
1013 for (
size_t i = 0; i != size; i++) {
1022template <
typename Iter,
typename Element>
1024 for (Iter it = begin; it != end; ++it) {
1035template <
typename T,
typename U>
1039template <
typename T,
typename U>
1043template <
typename T,
typename U,
size_t N>
1051template <
typename T,
typename U>
1053 for (
size_t i = 0; i != size; i++) {
1073template <
typename Element>
1083 InitRef(array,
count);
1088 InitCopy(array,
count);
1093 (this->*rhs.clone_)(rhs.array_, rhs.size_);
1097 if (clone_ != &NativeArray::InitRef)
1102 size_t size()
const {
return size_; }
1117 void InitCopy(
const Element* array,
size_t a_size) {
1118 Element*
const copy =
new Element[a_size];
1122 clone_ = &NativeArray::InitCopy;
1126 void InitRef(
const Element* array,
size_t a_size) {
1129 clone_ = &NativeArray::InitRef;
1132 const Element* array_;
1134 void (
NativeArray::*clone_)(
const Element*, size_t);
1142#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1143 ::testing::internal::AssertHelper(result_type, file, line, message) \
1144 = ::testing::Message()
1146#define GTEST_MESSAGE_(message, result_type) \
1147 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1149#define GTEST_FATAL_FAILURE_(message) \
1150 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1152#define GTEST_NONFATAL_FAILURE_(message) \
1153 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1155#define GTEST_SUCCESS_(message) \
1156 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1161#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1162 if (::testing::internal::AlwaysTrue()) { statement; }
1164#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1165 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1166 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1167 bool gtest_caught_expected = false; \
1169 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1171 catch (expected_exception const&) { \
1172 gtest_caught_expected = true; \
1176 "Expected: " #statement " throws an exception of type " \
1177 #expected_exception ".\n Actual: it throws a different type."; \
1178 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1180 if (!gtest_caught_expected) { \
1182 "Expected: " #statement " throws an exception of type " \
1183 #expected_exception ".\n Actual: it throws nothing."; \
1184 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1187 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1188 fail(gtest_msg.value)
1190#define GTEST_TEST_NO_THROW_(statement, fail) \
1191 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1192 if (::testing::internal::AlwaysTrue()) { \
1194 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1197 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1200 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1201 fail("Expected: " #statement " doesn't throw an exception.\n" \
1202 " Actual: it throws.")
1204#define GTEST_TEST_ANY_THROW_(statement, fail) \
1205 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1206 if (::testing::internal::AlwaysTrue()) { \
1207 bool gtest_caught_any = false; \
1209 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1212 gtest_caught_any = true; \
1214 if (!gtest_caught_any) { \
1215 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1218 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1219 fail("Expected: " #statement " throws an exception.\n" \
1220 " Actual: it doesn't.")
1226#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1227 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1228 if (const ::testing::AssertionResult gtest_ar_ = \
1229 ::testing::AssertionResult(expression)) \
1232 fail(::testing::internal::GetBoolAssertionFailureMessage(\
1233 gtest_ar_, text, #actual, #expected).c_str())
1235#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1236 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1237 if (::testing::internal::AlwaysTrue()) { \
1238 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1239 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1240 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1241 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1244 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1245 fail("Expected: " #statement " doesn't generate new fatal " \
1246 "failures in the current thread.\n" \
1247 " Actual: it does.")
1250#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1251 test_case_name##_##test_name##_Test
1254#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
1255class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
1257 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
1259 virtual void TestBody();\
1260 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
1261 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1262 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
1265::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
1267 ::testing::internal::MakeAndRegisterTestInfo(\
1268 #test_case_name, #test_name, NULL, NULL, \
1269 ::testing::internal::CodeLocation(__FILE__, __LINE__), \
1271 parent_class::SetUpTestCase, \
1272 parent_class::TearDownTestCase, \
1273 new ::testing::internal::TestFactoryImpl<\
1274 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
1275void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
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
static const size_t kMaxUlps
static const size_t kBitCount
static RawType ReinterpretBits(const Bits bits)
TypeWithSize< sizeof(RawType)>::UInt Bits
static const Bits kSignBitMask
const Bits & bits() const
Bits exponent_bits() const
const_iterator begin() const
NativeArray(const Element *array, size_t count, RelationToSourceReference)
bool operator==(const NativeArray &rhs) const
NativeArray(const NativeArray &rhs)
NativeArray(const Element *array, size_t count, RelationToSourceCopy)
const_iterator end() const
const Element * const_iterator
virtual ~TestFactoryBase()
virtual Test * CreateTest()=0
virtual Test * CreateTest()
#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_ASSIGN_(type)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
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)
FloatingPoint< float > Float
void(* TearDownTestCaseFunc)()
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_ bool SkipPrefix(const char *prefix, const char **pstr)
void(* SetUpTestCaseFunc)()
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ std::string DiffStrings(const std::string &left, const std::string &right, size_t *total_line_count)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
FloatingPoint< double > Double
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 SplitString(const ::std::string &str, char delimiter, ::std::vector< ::std::string > *dest)
GTEST_API_ bool AlwaysTrue()
Iter ArrayAwareFind(Iter begin, Iter end, const Element &elem)
std::string StripTrailingSpaces(std::string str)
GTEST_API_ const char kStackTraceMarker[]
IsContainer IsContainerTest(int, typename C::iterator *=NULL, typename C::const_iterator *=NULL)
GTEST_API_ TypeId GetTestTypeId()
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
bool ArrayEq(const T *lhs, size_t size, const U *rhs)
char IsNullLiteralHelper(Secret *p)
void CopyArray(const T *from, size_t size, U *to)
::std::string PrintToString(const T &value)
#define T(meth, val, expected)
CodeLocation(const std::string &a_file, int a_line)
ConstCharPtr(const char *str)
IteratorTraits< typenameC::iterator >::value_type value_type
is_same< value_type, C > type
Iterator::value_type value_type
c_gkp_out sizeof(template))