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
76 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
77 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
79 class ProtocolMessage;
80 namespace proto2 {
class Message; }
86 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
174 namespace 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,
202 size_t* total_line_count);
220 const char* actual_expression,
228 const char* expression_text,
229 const char* actual_predicate_value,
230 const char* expected_predicate_value);
261 template <
typename RawType>
275 std::numeric_limits<RawType>::digits - 1;
329 static RawType
Max();
405 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
431 template <
typename T>
440 template <
typename T>
446 template <
typename T>
481 template <
class TestClass>
498 #endif // GTEST_OS_WINDOWS
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",
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_;
594 inline const char* SkipComma(
const char*
str) {
595 const char* comma = strchr(str,
',');
605 inline std::string GetPrefixUntilComma(
const char* str) {
606 const char* comma = strchr(str,
',');
607 return comma == NULL ? str :
std::string(str, comma);
613 ::std::vector< ::std::string>*
dest);
622 template <GTEST_TEMPLATE_ Fixture,
class TestSel,
typename Types>
623 class 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);
658 template <GTEST_TEMPLATE_ Fixture, class TestSel>
659 class TypeParameterizedTest<Fixture, TestSel, Types0> {
661 static bool Register(
const char* , CodeLocation,
662 const char* ,
const char* ,
672 template <GTEST_TEMPLATE_ Fixture,
typename Tests,
typename Types>
673 class 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));
704 template <GTEST_TEMPLATE_ Fixture,
typename Types>
705 class TypeParameterizedTestCase<Fixture, Templates0, Types> {
707 static bool Register(
const char* , CodeLocation,
708 const TypedTestCasePState* ,
709 const char* ,
const char* ) {
714 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
727 UnitTest* unit_test,
int skip_count);
743 operator bool()
const {
return true; }
771 template <
typename T1,
typename T2>
774 template <
typename T>
781 template <
typename T>
783 template <
typename T>
788 #define GTEST_REMOVE_REFERENCE_(T) \
789 typename ::testing::internal::RemoveReference<T>::type
794 template <
typename T>
796 template <
typename T>
802 template <
typename T,
size_t N>
807 #if defined(_MSC_VER) && _MSC_VER < 1400
811 template <
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))
829 template <
typename T>
831 template <
typename 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))
854 template <
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);
894 #endif // __BORLANDC__
896 template <
typename From,
typename To>
902 template <
typename T>
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) {
955 template <
typename T,
typename U>
959 template <
typename T,
typename U>
963 template <
typename T,
typename U,
size_t N>
971 template <
typename T,
typename U>
973 for (
size_t i = 0;
i !=
size;
i++) {
982 template <
typename Iter,
typename Element>
995 template <
typename T,
typename U>
999 template <
typename T,
typename U>
1003 template <
typename T,
typename U,
size_t N>
1011 template <
typename T,
typename U>
1013 for (
size_t i = 0;
i !=
size;
i++) {
1033 template <
typename Element>
1043 InitRef(array, count);
1048 InitCopy(array, count);
1062 size_t size()
const {
return size_; }
1078 Element*
const copy =
new Element[a_size];
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)\
1215 class 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)>);\
1235 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
1237 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_