56 #define GTEST_IMPLEMENTATION_ 1
58 #undef GTEST_IMPLEMENTATION_
61 # include <sys/types.h>
73 TEST(JoinAsTupleTest, JoinsEmptyTuple) {
77 TEST(JoinAsTupleTest, JoinsOneTuple) {
78 const char* fields[] = {
"1"};
82 TEST(JoinAsTupleTest, JoinsTwoTuple) {
83 const char* fields[] = {
"1",
"a"};
87 TEST(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)",
93 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
99 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
106 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
114 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
121 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
127 TEST(PointeeOfTest, WorksForSmartPointers) {
129 (std::is_same<
int, PointeeOf<std::unique_ptr<int>>::type>::
value));
131 (std::is_same<std::string,
132 PointeeOf<std::shared_ptr<std::string>>::type>::
value));
135 TEST(PointeeOfTest, WorksForRawPointers) {
137 EXPECT_TRUE((std::is_same<
const char, PointeeOf<const char*>::type>::
value));
141 TEST(GetRawPointerTest, WorksForSmartPointers) {
142 const char*
const raw_p1 =
new const char(
'a');
143 const std::unique_ptr<const char> p1(raw_p1);
145 double*
const raw_p2 =
new double(2.5);
146 const std::shared_ptr<double> p2(raw_p2);
150 TEST(GetRawPointerTest, WorksForRawPointers) {
160 class Derived :
public Base {};
166 TEST(KindOfTest, Integer) {
180 #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
186 TEST(KindOfTest, FloatingPoint) {
192 TEST(KindOfTest, Other) {
200 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
204 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
211 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
216 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
221 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
227 unsigned short, uint64_t>::
value));
231 short, uint64_t>::
value));
233 signed char,
unsigned int>::
value));
237 unsigned char,
unsigned char>::
value));
241 unsigned long,
unsigned long>::
value));
245 unsigned char,
signed char>::
value));
255 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
261 short,
long double>::
value));
264 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
269 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
275 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
288 if (sizeof(
double) == sizeof(
long double)) {
300 TEST(TupleMatchesTest, WorksForSize0) {
301 std::tuple<> matchers;
307 TEST(TupleMatchesTest, WorksForSize1) {
308 std::tuple<Matcher<int> > matchers(Eq(1));
309 std::tuple<int> values1(1), values2(2);
315 TEST(TupleMatchesTest, WorksForSize2) {
316 std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq(
'a'));
317 std::tuple<int, char> values1(1,
'a'), values2(1,
'b'), values3(2,
'a'),
326 TEST(TupleMatchesTest, WorksForSize5) {
327 std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
329 Matcher<std::string> >
330 matchers(Eq(1), Eq(
'a'), Eq(
true), Eq(2L), Eq(
"hi"));
331 std::tuple<int, char, bool, long, std::string>
332 values1(1,
'a',
true, 2L,
"hi"), values2(1,
'a',
true, 2L,
"hello"),
333 values3(2,
'a',
true, 2L,
"hi");
341 TEST(AssertTest, SucceedsOnTrue) {
342 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
343 Assert(
true, __FILE__, __LINE__);
347 TEST(AssertTest, FailsFatallyOnFalse) {
349 Assert(
false, __FILE__, __LINE__,
"This should fail.");
353 Assert(
false, __FILE__, __LINE__);
358 TEST(ExpectTest, SucceedsOnTrue) {
359 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
360 Expect(
true, __FILE__, __LINE__);
364 TEST(ExpectTest, FailsNonfatallyOnFalse) {
366 Expect(
false, __FILE__, __LINE__,
"This should fail.");
367 },
"This should fail");
370 Expect(
false, __FILE__, __LINE__);
371 },
"Expectation failed");
385 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
391 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
397 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
403 #if GTEST_HAS_STREAM_REDIRECTION
409 void TestLogWithSeverity(
const std::string& verbosity,
LogSeverity severity,
411 const std::string old_flag =
GMOCK_FLAG(verbose);
414 Log(severity,
"Test log.\n", 0);
419 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
420 "^\nTest log\\.\nStack trace:\n"));
429 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
430 const std::string saved_flag =
GMOCK_FLAG(verbose);
438 struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
439 std::string CurrentStackTrace(
int max_depth,
int skip_count)
override {
443 void UponLeavingGTest()
override {}
448 TEST(LogTest, NoSkippingStackFrameInOptMode) {
449 MockStackTraceGetter* mock_os_stack_trace_getter =
new MockStackTraceGetter;
450 GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter);
456 std::string expected_trace =
458 std::string expected_message =
464 int skip_count = atoi(log.substr(expected_message.size()).c_str());
468 const int expected_skip_count = 0;
471 const int expected_skip_count = 100;
478 AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
481 GetUnitTestImpl()->set_os_stack_trace_getter(
nullptr);
486 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
493 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
500 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
507 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
508 TestLogWithSeverity(
"invalid",
kInfo,
false);
509 TestLogWithSeverity(
"invalid",
kWarning,
true);
514 std::string GrabOutput(
void(*logger)(),
const char* verbosity) {
515 const std::string saved_flag =
GMOCK_FLAG(verbose);
529 void ExpectCallLogger() {
536 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
538 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
543 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
549 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
553 void OnCallLogger() {
559 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
561 HasSubstr(
"ON_CALL(mock, TestMethod())"));
566 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
572 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
576 void OnCallAnyArgumentLogger() {
582 TEST(OnCallTest, LogsAnythingArgument) {
584 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
587 #endif // GTEST_HAS_STREAM_REDIRECTION
591 TEST(StlContainerViewTest, WorksForStlContainer) {
592 StaticAssertTypeEq<std::vector<int>,
593 StlContainerView<std::vector<int> >::type>();
594 StaticAssertTypeEq<const std::vector<double>&,
595 StlContainerView<std::vector<double> >::const_reference>();
597 typedef std::vector<char> Chars;
599 const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
607 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
608 StaticAssertTypeEq<NativeArray<int>,
609 StlContainerView<int[3]>::type>();
610 StaticAssertTypeEq<NativeArray<double>,
611 StlContainerView<const double[4]>::type>();
612 StaticAssertTypeEq<NativeArray<char[3]>,
613 StlContainerView<const char[2][3]>::type>();
615 StaticAssertTypeEq<const NativeArray<int>,
616 StlContainerView<int[2]>::const_reference>();
618 int a1[3] = { 0, 1, 2 };
634 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
635 StaticAssertTypeEq<NativeArray<int>,
636 StlContainerView<std::tuple<const int*, size_t> >::type>();
639 StlContainerView<std::tuple<std::shared_ptr<double>,
int> >::type>();
642 const NativeArray<int>,
643 StlContainerView<std::tuple<const int*, int> >::const_reference>();
645 int a1[3] = { 0, 1, 2 };
646 const int*
const p1 = a1;
647 NativeArray<int> a2 =
648 StlContainerView<std::tuple<const int*, int> >::ConstReference(
649 std::make_tuple(p1, 3));
653 const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
654 std::make_tuple(static_cast<int*>(a1), 3));
668 typedef Function<int()>
F;
674 EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::
value));
678 typedef Function<int(bool)>
F;
684 std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::
value));
687 F::MakeResultIgnoredValue>::
value));
691 typedef Function<int(bool, const long&)>
F;
696 EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>,
697 F::ArgumentTuple>::
value));
699 (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>,
700 F::ArgumentMatcherTuple>::
value));
702 F::MakeResultVoid>::
value));
703 EXPECT_TRUE((std::is_same<IgnoredValue(
bool,
const long&),
704 F::MakeResultIgnoredValue>::
value));
707 TEST(FunctionTest, LongArgumentList) {
708 typedef Function<char(bool, int, char*, int&, const long&)>
F;
717 (std::is_same<std::tuple<bool, int, char*, int&, const long&>,
718 F::ArgumentTuple>::
value));
721 std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
722 Matcher<const long&>>,
723 F::ArgumentMatcherTuple>::
value));
725 (std::is_same<
void(
bool,
int,
char*,
int&,
const long&),
726 F::MakeResultVoid>::
value));
728 std::is_same<IgnoredValue(
bool,
int,
char*,
int&,
const long&),
729 F::MakeResultIgnoredValue>::
value));
Sacado::Fad::DFad< double > F
#define GMOCK_KIND_OF_(type)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ std::string GetCapturedStdout()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
static const_reference ConstReference(const RawContainer &container)
#define MOCK_METHOD0(m,...)
::std::vector< ::std::string > Strings
#define ASSERT_EQ(val1, val2)
#define ON_CALL(obj, call)
GTEST_API_ void CaptureStdout()
const char kInfoVerbosity[]
const char kWarningVerbosity[]
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
TEST_F(ListenerTest, DoesFoo)
GTEST_API_ std::string JoinAsTuple(const Strings &fields)
#define EXPECT_STREQ(s1, s2)
const char * Binary(const char *input, short n)
#define MOCK_METHOD1(m,...)
GTEST_API_ bool LogIsVisible(LogSeverity severity)
#define EXPECT_THAT(value, matcher)
#define EXPECT_CALL(obj, call)
LosslessArithmeticConvertibleImpl< GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To > LosslessArithmeticConvertible
static type Copy(const RawContainer &container)
#define EXPECT_EQ(val1, val2)
void Assert(bool condition, const char *file, int line, const std::string &msg)
#define EXPECT_TRUE(condition)
constexpr bool StaticAssertTypeEq() noexcept
std::string original_verbose_
#define EXPECT_FALSE(condition)
const char kErrorVerbosity[]
const Pointer::element_type * GetRawPointer(const Pointer &p)
void Expect(bool condition, const char *file, int line, const std::string &msg)
#define GTEST_INTENTIONAL_CONST_COND_POP_()
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
TEST(IsXDigitTest, WorksForNarrowAscii)