36 #include "gmock/internal/gmock-internal-utils.h" 43 #include "gmock/gmock.h" 44 #include "gmock/internal/gmock-port.h" 45 #include "gtest/gtest.h" 46 #include "gtest/gtest-spi.h" 53 #define GTEST_IMPLEMENTATION_ 1 54 #include "src/gtest-internal-inl.h" 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) {
107 CompileAssertTypesEqual<
const char,
108 PointeeOf<internal::linked_ptr<const char> >
::type>();
109 #if GTEST_HAS_STD_UNIQUE_PTR_ 110 CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >
::type>();
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 {};
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) {
291 TEST(TupleMatchesTest, WorksForSize0) {
298 TEST(TupleMatchesTest, WorksForSize1) {
299 tuple<Matcher<int> > matchers(
Eq(1));
300 tuple<int> values1(1),
307 TEST(TupleMatchesTest, WorksForSize2) {
308 tuple<Matcher<int>, Matcher<char> > matchers(
Eq(1),
Eq(
'a'));
309 tuple<int, char> values1(1,
'a'),
320 TEST(TupleMatchesTest, WorksForSize5) {
321 tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>,
323 matchers(
Eq(1),
Eq(
'a'),
Eq(
true),
Eq(2L),
Eq(
"hi"));
324 tuple<int, char, bool, long, string>
325 values1(1,
'a',
true, 2L,
"hi"),
326 values2(1,
'a',
true, 2L,
"hello"),
327 values3(2,
'a',
true, 2L,
"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) {
426 const string saved_flag =
GMOCK_FLAG(verbose);
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 549 std::string GrabOutput(
void(*logger)(),
const char* verbosity) {
550 const string saved_flag =
GMOCK_FLAG(verbose);
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));
638 Chars v3 = StlContainerView<Chars>::Copy(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 };
654 NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
658 const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
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> >::
class UnitTestImpl * GetUnitTestImpl()
#define TEST(test_case_name, test_name)
GTEST_API_ string ConvertIdentifierNameToWords(const char *id_name)
#define ASSERT_EQ(val1, val2)
struct folly::detail::LastElementImpl sizeof
internal::EqMatcher< T > Eq(T x)
const char kErrorVerbosity[]
#define EXPECT_EQ(val1, val2)
#define GTEST_INTENTIONAL_CONST_COND_POP_()
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
TypeWithSize< 8 >::UInt UInt64
bool TupleMatches(const MatcherTuple &matcher_tuple, const ValueTuple &value_tuple)
bool_constant< true > true_type
const char kInfoVerbosity[]
#define EXPECT_STREQ(s1, s2)
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
internal::LeMatcher< Rhs > Le(Rhs x)
void Expect(bool condition, const char *file, int line, const string &msg)
const char kWarningVerbosity[]
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
GTEST_API_ void Log(LogSeverity severity, const string &message, int stack_frames_to_skip)
AtomicCounter< T, DeterministicAtomic > Base
static const char *const value
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
GTEST_API_ bool LogIsVisible(LogSeverity severity)
StrictConjunction< T< As >... > AllOf
#define EXPECT_TRUE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define EXPECT_THAT(value, matcher)
#define ON_CALL(obj, call)
void Assert(bool condition, const char *file, int line)
#define MOCK_METHOD1(m,...)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
const Pointer::element_type * GetRawPointer(const Pointer &p)
bool_constant< false > false_type
#define EXPECT_CALL(obj, call)
std::string GetCapturedStdout()
const internal::AnythingMatcher _
#define GMOCK_KIND_OF_(type)
#define EXPECT_FALSE(condition)
internal::GeMatcher< Rhs > Ge(Rhs x)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
std::vector< int > values(1'000)
#define TEST_F(test_fixture, test_name)
#define MOCK_METHOD0(m,...)