53 #define GTEST_IMPLEMENTATION_ 1
55 #undef GTEST_IMPLEMENTATION_
58 # include <sys/types.h>
61 class ProtocolMessage;
72 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
78 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
85 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
93 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
100 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
106 TEST(PointeeOfTest, WorksForSmartPointers) {
108 PointeeOf<internal::linked_ptr<const char> >
::type>();
109 #if GTEST_HAS_STD_UNIQUE_PTR_
111 #endif // GTEST_HAS_STD_UNIQUE_PTR_
112 #if GTEST_HAS_STD_SHARED_PTR_
114 PointeeOf<std::shared_ptr<std::string> >
::type>();
115 #endif // GTEST_HAS_STD_SHARED_PTR_
118 TEST(PointeeOfTest, WorksForRawPointers) {
124 TEST(GetRawPointerTest, WorksForSmartPointers) {
125 #if GTEST_HAS_STD_UNIQUE_PTR_
126 const char*
const raw_p1 =
new const char(
'a');
127 const std::unique_ptr<const char> p1(raw_p1);
129 #endif // GTEST_HAS_STD_UNIQUE_PTR_
130 #if GTEST_HAS_STD_SHARED_PTR_
131 double*
const raw_p2 =
new double(2.5);
132 const std::shared_ptr<double> p2(raw_p2);
134 #endif // GTEST_HAS_STD_SHARED_PTR_
136 const char*
const raw_p4 =
new const char(
'a');
137 const internal::linked_ptr<const char> p4(raw_p4);
141 TEST(GetRawPointerTest, WorksForRawPointers) {
152 class Derived :
public Base {};
158 TEST(KindOfTest, Integer) {
172 #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
178 TEST(KindOfTest, FloatingPoint) {
184 TEST(KindOfTest, Other) {
192 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
196 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
203 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
208 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
213 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
224 signed char,
unsigned int>::
value));
228 unsigned char,
unsigned char>::
value));
232 unsigned long,
unsigned long>::
value));
236 unsigned char,
signed char>::
value));
246 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
252 short,
long double>::
value));
255 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
260 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
266 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
279 if (sizeof(
double) == sizeof(
long double)) {
291 TEST(TupleMatchesTest, WorksForSize0) {
298 TEST(TupleMatchesTest, WorksForSize1) {
307 TEST(TupleMatchesTest, WorksForSize2) {
320 TEST(TupleMatchesTest, WorksForSize5) {
323 matchers(
Eq(1),
Eq(
'a'),
Eq(
true),
Eq(2
L),
Eq(
"hi"));
325 values1(1,
'a',
true, 2
L,
"hi"),
326 values2(1,
'a',
true, 2
L,
"hello"),
327 values3(2,
'a',
true, 2
L,
"hi");
335 TEST(AssertTest, SucceedsOnTrue) {
336 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
337 Assert(
true, __FILE__, __LINE__);
341 TEST(AssertTest, FailsFatallyOnFalse) {
343 Assert(
false, __FILE__, __LINE__,
"This should fail.");
347 Assert(
false, __FILE__, __LINE__);
352 TEST(ExpectTest, SucceedsOnTrue) {
353 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
354 Expect(
true, __FILE__, __LINE__);
358 TEST(ExpectTest, FailsNonfatallyOnFalse) {
360 Expect(
false, __FILE__, __LINE__,
"This should fail.");
361 },
"This should fail");
364 Expect(
false, __FILE__, __LINE__);
365 },
"Expectation failed");
372 virtual void SetUp() {
381 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
387 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
393 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
399 #if GTEST_HAS_STREAM_REDIRECTION
410 Log(severity,
"Test log.\n", 0);
415 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
416 "^\nTest log\\.\nStack trace:\n"));
425 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
435 virtual string CurrentStackTrace(
int max_depth,
int skip_count) {
439 virtual void UponLeavingGTest() {}
444 TEST(LogTest, NoSkippingStackFrameInOptMode) {
445 MockStackTraceGetter* mock_os_stack_trace_getter =
new MockStackTraceGetter;
452 string expected_trace =
454 string expected_message =
460 int skip_count = atoi(log.substr(expected_message.size()).c_str());
464 const int expected_skip_count = 0;
467 const int expected_skip_count = 100;
474 AllOf(
Ge(expected_skip_count),
Le(expected_skip_count + 10)));
482 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
489 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
496 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
503 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
504 TestLogWithSeverity(
"invalid",
kInfo,
false);
505 TestLogWithSeverity(
"invalid",
kWarning,
true);
508 #endif // GTEST_HAS_STREAM_REDIRECTION
518 TEST(TypeTraitsTest, is_reference) {
524 TEST(TypeTraitsTest, is_pointer) {
530 TEST(TypeTraitsTest, type_equals) {
537 TEST(TypeTraitsTest, remove_reference) {
545 #if GTEST_HAS_STREAM_REDIRECTION
564 void ExpectCallLogger() {
571 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
573 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
578 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
584 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
588 void OnCallLogger() {
594 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
596 HasSubstr(
"ON_CALL(mock, TestMethod())"));
601 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
607 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
611 void OnCallAnyArgumentLogger() {
617 TEST(OnCallTest, LogsAnythingArgument) {
619 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
622 #endif // GTEST_HAS_STREAM_REDIRECTION
626 TEST(StlContainerViewTest, WorksForStlContainer) {
627 StaticAssertTypeEq<std::vector<int>,
628 StlContainerView<std::vector<int> >
::type>();
629 StaticAssertTypeEq<const std::vector<double>&,
630 StlContainerView<std::vector<double> >::const_reference>();
632 typedef std::vector<char> Chars;
634 const Chars&
v2(StlContainerView<Chars>::ConstReference(v1));
642 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
643 StaticAssertTypeEq<NativeArray<int>,
645 StaticAssertTypeEq<NativeArray<double>,
647 StaticAssertTypeEq<NativeArray<char[3]>,
650 StaticAssertTypeEq<const NativeArray<int>,
651 StlContainerView<int[2]>::const_reference>();
653 int a1[3] = { 0, 1, 2 };
669 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
670 StaticAssertTypeEq<NativeArray<int>,
671 StlContainerView<tuple<const int*, size_t> >
::type>();
672 StaticAssertTypeEq<NativeArray<double>,
673 StlContainerView<tuple<linked_ptr<double>,
int> >
::type>();
675 StaticAssertTypeEq<const NativeArray<int>,
676 StlContainerView<tuple<const int*, int> >::const_reference>();
678 int a1[3] = { 0, 1, 2 };
679 const int*
const p1 = a1;
680 NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
685 const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::