56#define GTEST_IMPLEMENTATION_ 1
58#undef GTEST_IMPLEMENTATION_
61# include <sys/types.h>
73TEST(JoinAsTupleTest, JoinsEmptyTuple) {
77TEST(JoinAsTupleTest, JoinsOneTuple) {
78 const char* fields[] = {
"1"};
82TEST(JoinAsTupleTest, JoinsTwoTuple) {
83 const char* fields[] = {
"1",
"a"};
87TEST(JoinAsTupleTest, JoinsTenTuple) {
88 const char* fields[] = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10"};
89 EXPECT_EQ(
"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
93TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
99TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
106TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
114TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
121TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
127TEST(GetRawPointerTest, WorksForSmartPointers) {
128 const char*
const raw_p1 =
new const char(
'a');
129 const std::unique_ptr<const char> p1(raw_p1);
131 double*
const raw_p2 =
new double(2.5);
132 const std::shared_ptr<double> p2(raw_p2);
136TEST(GetRawPointerTest, WorksForRawPointers) {
146class Derived :
public Base {};
152TEST(KindOfTest, Integer) {
166#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
172TEST(KindOfTest, FloatingPoint) {
178TEST(KindOfTest, Other) {
186TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
190TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
197TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
202TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
207TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
213 unsigned short, uint64_t>
::value));
219 signed char,
unsigned int>
::value));
223 unsigned char,
unsigned char>
::value));
227 unsigned long,
unsigned long>
::value));
231 unsigned char,
signed char>
::value));
241TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
250TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
255TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
261TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
274 if (sizeof(
double) == sizeof(
long double)) {
286TEST(TupleMatchesTest, WorksForSize0) {
287 std::tuple<> matchers;
293TEST(TupleMatchesTest, WorksForSize1) {
294 std::tuple<Matcher<int> > matchers(Eq(1));
295 std::tuple<int> values1(1), values2(2);
301TEST(TupleMatchesTest, WorksForSize2) {
302 std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq(
'a'));
303 std::tuple<int, char> values1(1,
'a'), values2(1,
'b'), values3(2,
'a'),
312TEST(TupleMatchesTest, WorksForSize5) {
313 std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
315 Matcher<std::string> >
316 matchers(Eq(1), Eq(
'a'), Eq(
true), Eq(2L), Eq(
"hi"));
317 std::tuple<int, char, bool, long, std::string>
318 values1(1,
'a',
true, 2L,
"hi"), values2(1,
'a',
true, 2L,
"hello"),
319 values3(2,
'a',
true, 2L,
"hi");
327TEST(AssertTest, SucceedsOnTrue) {
328 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
329 Assert(
true, __FILE__, __LINE__);
333TEST(AssertTest, FailsFatallyOnFalse) {
335 Assert(
false, __FILE__, __LINE__,
"This should fail.");
339 Assert(
false, __FILE__, __LINE__);
344TEST(ExpectTest, SucceedsOnTrue) {
345 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
346 Expect(
true, __FILE__, __LINE__);
350TEST(ExpectTest, FailsNonfatallyOnFalse) {
352 Expect(
false, __FILE__, __LINE__,
"This should fail.");
353 },
"This should fail");
356 Expect(
false, __FILE__, __LINE__);
357 },
"Expectation failed");
371TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
377TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
383TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
389#if GTEST_HAS_STREAM_REDIRECTION
397 const std::string old_flag =
GMOCK_FLAG(verbose);
400 Log(severity,
"Test log.\n", 0);
405 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
406 "^\nTest log\\.\nStack trace:\n"));
415TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
416 const std::string saved_flag =
GMOCK_FLAG(verbose);
424struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
425 std::string CurrentStackTrace(
int max_depth,
int skip_count)
override {
429 void UponLeavingGTest()
override {}
434TEST(LogTest, NoSkippingStackFrameInOptMode) {
435 MockStackTraceGetter* mock_os_stack_trace_getter =
new MockStackTraceGetter;
436 GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter);
442 std::string expected_trace =
444 std::string expected_message =
450 int skip_count = atoi(log.substr(expected_message.size()).c_str());
454 const int expected_skip_count = 0;
457 const int expected_skip_count = 100;
464 AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
467 GetUnitTestImpl()->set_os_stack_trace_getter(
nullptr);
472TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
479TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
486TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
493TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
494 TestLogWithSeverity(
"invalid",
kInfo,
false);
495 TestLogWithSeverity(
"invalid",
kWarning,
true);
500std::string GrabOutput(
void(*logger)(),
const char*
verbosity) {
501 const std::string saved_flag =
GMOCK_FLAG(verbose);
515void ExpectCallLogger() {
522TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
524 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
529TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
535TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
545TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
547 HasSubstr(
"ON_CALL(mock, TestMethod())"));
552TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
558TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
562void OnCallAnyArgumentLogger() {
564 ON_CALL(mock, TestMethodArg(_));
568TEST(OnCallTest, LogsAnythingArgument) {
570 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
577TEST(StlContainerViewTest, WorksForStlContainer) {
578 StaticAssertTypeEq<std::vector<int>,
579 StlContainerView<std::vector<int> >
::type>();
580 StaticAssertTypeEq<const std::vector<double>&,
581 StlContainerView<std::vector<double> >::const_reference>();
583 typedef std::vector<char> Chars;
593TEST(StlContainerViewTest, WorksForStaticNativeArray) {
594 StaticAssertTypeEq<NativeArray<int>,
596 StaticAssertTypeEq<NativeArray<double>,
598 StaticAssertTypeEq<NativeArray<char[3]>,
601 StaticAssertTypeEq<const NativeArray<int>,
604 int a1[3] = { 0, 1, 2 };
620TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
621 StaticAssertTypeEq<NativeArray<int>,
622 StlContainerView<std::tuple<const int*, size_t> >
::type>();
625 StlContainerView<std::tuple<std::shared_ptr<double>,
int> >
::type>();
628 const NativeArray<int>,
629 StlContainerView<std::tuple<const int*, int> >::const_reference>();
631 int a1[3] = { 0, 1, 2 };
632 const int*
const p1 = a1;
633 NativeArray<int> a2 =
634 StlContainerView<std::tuple<const int*, int> >::ConstReference(
635 std::make_tuple(p1, 3));
639 const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
640 std::make_tuple(
static_cast<int*
>(a1), 3));
654 typedef Function<int()> F;
664 typedef Function<int(
bool)> F;
670 std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>
::value));
673 F::MakeResultIgnoredValue>
::value));
677 typedef Function<int(
bool,
const long&)> F;
682 EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>,
685 (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>,
686 F::ArgumentMatcherTuple>
::value));
689 EXPECT_TRUE((std::is_same<IgnoredValue(
bool,
const long&),
690 F::MakeResultIgnoredValue>
::value));
693TEST(FunctionTest, LongArgumentList) {
694 typedef Function<char(
bool,
int,
char*,
int&,
const long&)> F;
703 (std::is_same<std::tuple<bool, int, char*, int&, const long&>,
707 std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
708 Matcher<const long&>>,
709 F::ArgumentMatcherTuple>
::value));
711 (std::is_same<
void(
bool,
int,
char*,
int&,
const long&),
714 std::is_same<IgnoredValue(
bool,
int,
char*,
int&,
const long&),
715 F::MakeResultIgnoredValue>
::value));
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)
#define EXPECT_THAT(value, matcher)
#define GMOCK_KIND_OF_(type)
#define MOCK_METHOD0(m,...)
#define MOCK_METHOD1(m,...)
std::string original_verbose_
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_FALSE(condition)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_INTENTIONAL_CONST_COND_POP_()
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
constexpr bool StaticAssertTypeEq() noexcept
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
TEST(IsXDigitTest, WorksForNarrowAscii)
const char kErrorVerbosity[]
GTEST_API_ std::string JoinAsTuple(const Strings &fields)
::std::vector< ::std::string > Strings
GTEST_API_ bool LogIsVisible(LogSeverity severity)
TEST_F(ListenerTest, DoesFoo)
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
const char kInfoVerbosity[]
void Assert(bool condition, const char *file, int line, const std::string &msg)
LosslessArithmeticConvertibleImpl< GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To > LosslessArithmeticConvertible
GTEST_API_ void CaptureStdout()
const Pointer::element_type * GetRawPointer(const Pointer &p)
void Expect(bool condition, const char *file, int line, const std::string &msg)
const char kWarningVerbosity[]
GTEST_API_ std::string GetCapturedStdout()
const char * Binary(const char *input, short n)
static const_reference ConstReference(const RawContainer &container)
static type Copy(const RawContainer &container)
const type & const_reference