56 #define GTEST_IMPLEMENTATION_ 1
58 #undef GTEST_IMPLEMENTATION_
60 #ifdef GTEST_OS_CYGWIN
61 #include <sys/types.h>
73 TEST(JoinAsKeyValueTupleTest, JoinsEmptyTuple) {
77 TEST(JoinAsKeyValueTupleTest, JoinsOneTuple) {
81 TEST(JoinAsKeyValueTupleTest, JoinsTwoTuple) {
85 TEST(JoinAsKeyValueTupleTest, JoinsTenTuple) {
87 "(a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10)",
88 JoinAsKeyValueTuple({
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j"},
89 {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10"}));
92 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
98 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
105 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
113 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
120 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
126 TEST(GetRawPointerTest, WorksForSmartPointers) {
127 const char*
const raw_p1 =
new const char(
'a');
128 const std::unique_ptr<const char> p1(raw_p1);
130 double*
const raw_p2 =
new double(2.5);
131 const std::shared_ptr<double> p2(raw_p2);
135 TEST(GetRawPointerTest, WorksForRawPointers) {
142 TEST(GetRawPointerTest, WorksForStdReferenceWrapper) {
151 class Derived :
public Base {};
157 TEST(KindOfTest, Integer) {
171 #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || defined(GTEST_OS_CYGWIN)
177 TEST(KindOfTest, FloatingPoint) {
183 TEST(KindOfTest, Other) {
191 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
195 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
202 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
207 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
212 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
224 unsigned int>::
value));
232 unsigned long>::
value));
246 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
255 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
260 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
266 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
279 if (sizeof(
double) == sizeof(
long double)) {
291 TEST(TupleMatchesTest, WorksForSize0) {
292 std::tuple<> matchers;
298 TEST(TupleMatchesTest, WorksForSize1) {
299 std::tuple<Matcher<int>> matchers(Eq(1));
300 std::tuple<int> values1(1), values2(2);
306 TEST(TupleMatchesTest, WorksForSize2) {
307 std::tuple<Matcher<int>, Matcher<char>> matchers(Eq(1), Eq(
'a'));
308 std::tuple<int, char> values1(1,
'a'), values2(1,
'b'), values3(2,
'a'),
317 TEST(TupleMatchesTest, WorksForSize5) {
318 std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
320 Matcher<std::string>>
321 matchers(Eq(1), Eq(
'a'), Eq(
true), Eq(2L), Eq(
"hi"));
322 std::tuple<int, char, bool, long, std::string>
323 values1(1,
'a',
true, 2L,
"hi"), values2(1,
'a',
true, 2L,
"hello"),
324 values3(2,
'a',
true, 2L,
"hi");
332 TEST(AssertTest, SucceedsOnTrue) {
333 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
334 Assert(
true, __FILE__, __LINE__);
338 TEST(AssertTest, FailsFatallyOnFalse) {
340 {
Assert(
false, __FILE__, __LINE__,
"This should fail."); },
"");
346 TEST(ExpectTest, SucceedsOnTrue) {
347 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
348 Expect(
true, __FILE__, __LINE__);
352 TEST(ExpectTest, FailsNonfatallyOnFalse) {
355 Expect(
false, __FILE__, __LINE__,
"This should fail.");
361 Expect(
false, __FILE__, __LINE__);
363 "Expectation failed");
377 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
383 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
389 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
395 #if GTEST_HAS_STREAM_REDIRECTION
401 void TestLogWithSeverity(
const std::string& verbosity,
LogSeverity severity,
406 Log(severity,
"Test log.\n", 0);
411 ?
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n"
412 :
"^\nTest log\\.\nStack trace:\n"));
421 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
431 std::string CurrentStackTrace(
int max_depth,
int skip_count)
override {
435 void UponLeavingGTest()
override {}
440 TEST(LogTest, NoSkippingStackFrameInOptMode) {
441 MockStackTraceGetter* mock_os_stack_trace_getter =
new MockStackTraceGetter;
448 std::string expected_trace =
451 std::string expected_message =
457 int skip_count = atoi(log.substr(expected_message.size()).c_str());
461 const int expected_skip_count = 0;
464 const int expected_skip_count = 100;
471 AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
479 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
486 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
493 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
500 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
501 TestLogWithSeverity(
"invalid",
kInfo,
false);
502 TestLogWithSeverity(
"invalid",
kWarning,
true);
507 std::string GrabOutput(
void (*logger)(),
const char* verbosity) {
522 void ExpectCallLogger() {
529 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
531 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
536 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
542 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
546 void OnCallLogger() {
552 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
554 HasSubstr(
"ON_CALL(mock, TestMethod())"));
559 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
565 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
569 void OnCallAnyArgumentLogger() {
575 TEST(OnCallTest, LogsAnythingArgument) {
577 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
580 #endif // GTEST_HAS_STREAM_REDIRECTION
584 TEST(StlContainerViewTest, WorksForStlContainer) {
585 StaticAssertTypeEq<std::vector<int>,
586 StlContainerView<std::vector<int>>::type>();
587 StaticAssertTypeEq<const std::vector<double>&,
588 StlContainerView<std::vector<double>>::const_reference>();
590 typedef std::vector<char> Chars;
592 const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
600 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
601 StaticAssertTypeEq<NativeArray<int>, StlContainerView<int[3]>::type>();
602 StaticAssertTypeEq<NativeArray<double>,
603 StlContainerView<const double[4]>::type>();
604 StaticAssertTypeEq<NativeArray<char[3]>,
605 StlContainerView<const char[2][3]>::type>();
607 StaticAssertTypeEq<const NativeArray<int>,
608 StlContainerView<int[2]>::const_reference>();
610 int a1[3] = {0, 1, 2};
626 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
627 StaticAssertTypeEq<NativeArray<int>,
628 StlContainerView<std::tuple<const int*, size_t>>::type>();
631 StlContainerView<std::tuple<std::shared_ptr<double>,
int>>::type>();
634 const NativeArray<int>,
635 StlContainerView<std::tuple<const int*, int>>::const_reference>();
637 int a1[3] = {0, 1, 2};
638 const int*
const p1 = a1;
639 NativeArray<int> a2 =
640 StlContainerView<std::tuple<const int*, int>>::ConstReference(
641 std::make_tuple(p1, 3));
645 const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t>>::Copy(
646 std::make_tuple(static_cast<int*>(a1), 3));
660 typedef Function<int()>
F;
666 EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::
value));
670 typedef Function<int(bool)>
F;
676 std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::
value));
679 F::MakeResultIgnoredValue>::
value));
683 typedef Function<int(bool, const long&)>
F;
688 EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>,
689 F::ArgumentTuple>::
value));
691 (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>,
692 F::ArgumentMatcherTuple>::
value));
694 F::MakeResultVoid>::
value));
695 EXPECT_TRUE((std::is_same<IgnoredValue(
bool,
const long&),
696 F::MakeResultIgnoredValue>::
value));
699 TEST(FunctionTest, LongArgumentList) {
700 typedef Function<char(bool, int, char*, int&, const long&)>
F;
709 (std::is_same<std::tuple<bool, int, char*, int&, const long&>,
710 F::ArgumentTuple>::
value));
713 std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
714 Matcher<const long&>>,
715 F::ArgumentMatcherTuple>::
value));
717 (std::is_same<
void(
bool,
int,
char*,
int&,
const long&),
718 F::MakeResultVoid>::
value));
720 std::is_same<IgnoredValue(
bool,
int,
char*,
int&,
const long&),
721 F::MakeResultIgnoredValue>::
value));
725 std::string unescaped;
730 std::string unescaped;
736 std::string unescaped;
742 std::string unescaped;
748 std::string escaped =
749 R
"(TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=)";
751 "Man is distinguished, not only by his reason, but by this singular "
752 "passion from other animals, which is a lust of the mind, that by a "
753 "perseverance of delight in the continued and indefatigable generation "
754 "of knowledge, exceeds the short vehemence of any carnal pleasure.";
755 std::string unescaped;
763 Sacado::Fad::DFad< double > F
class UnitTestImpl * GetUnitTestImpl()
#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,...)
#define ASSERT_EQ(val1, val2)
#define ON_CALL(obj, call)
::std::vector<::std::string > Strings
GTEST_API_ void CaptureStdout()
const char kInfoVerbosity[]
bool Base64Unescape(const std::string &encoded, std::string *decoded)
const char kWarningVerbosity[]
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
TEST_F(ListenerTest, DoesFoo)
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
#define GMOCK_FLAG_GET(name)
#define EXPECT_STREQ(s1, s2)
#define MOCK_METHOD1(m,...)
#define GTEST_FLAG_GET(name)
#define GMOCK_FLAG_SET(name, value)
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[]
GTEST_API_ std::string JoinAsKeyValueTuple(const std::vector< const char * > &names, const Strings &values)
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_()
const char * Binary(const char *input, short n)
GTEST_API_ void Log(LogSeverity severity, const std::string &message, int stack_frames_to_skip)
TEST(IsXDigitTest, WorksForNarrowAscii)
static ExpectedAnswer expected[4]