53#define GTEST_IMPLEMENTATION_ 1
55#undef GTEST_IMPLEMENTATION_
58# include <sys/types.h>
72TEST(JoinAsTupleTest, JoinsEmptyTuple) {
76TEST(JoinAsTupleTest, JoinsOneTuple) {
77 const char* fields[] = {
"1"};
81TEST(JoinAsTupleTest, JoinsTwoTuple) {
82 const char* fields[] = {
"1",
"a"};
86TEST(JoinAsTupleTest, JoinsTenTuple) {
87 const char* fields[] = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10"};
88 EXPECT_EQ(
"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
92TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
98TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
105TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
113TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
120TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
126TEST(PointeeOfTest, WorksForSmartPointers) {
127 CompileAssertTypesEqual<
const char,
128 PointeeOf<internal::linked_ptr<const char> >::type>();
129#if GTEST_HAS_STD_UNIQUE_PTR_
130 CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
132#if GTEST_HAS_STD_SHARED_PTR_
133 CompileAssertTypesEqual<std::string,
134 PointeeOf<std::shared_ptr<std::string> >::type>();
138TEST(PointeeOfTest, WorksForRawPointers) {
139 CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
140 CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
141 CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
144TEST(GetRawPointerTest, WorksForSmartPointers) {
145#if GTEST_HAS_STD_UNIQUE_PTR_
146 const char*
const raw_p1 =
new const char(
'a');
147 const std::unique_ptr<const char> p1(raw_p1);
150#if GTEST_HAS_STD_SHARED_PTR_
151 double*
const raw_p2 =
new double(2.5);
152 const std::shared_ptr<double> p2(raw_p2);
156 const char*
const raw_p4 =
new const char(
'a');
157 const internal::linked_ptr<const char> p4(raw_p4);
161TEST(GetRawPointerTest, WorksForRawPointers) {
172class Derived :
public Base {};
178TEST(KindOfTest, Integer) {
192#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
198TEST(KindOfTest, FloatingPoint) {
204TEST(KindOfTest, Other) {
212TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
213 EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value));
216TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
217 EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value));
218 EXPECT_TRUE((LosslessArithmeticConvertible<bool, int>::value));
220 (LosslessArithmeticConvertible<bool, unsigned long>::value));
223TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
224 EXPECT_TRUE((LosslessArithmeticConvertible<bool, float>::value));
225 EXPECT_TRUE((LosslessArithmeticConvertible<bool, double>::value));
228TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
229 EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value));
230 EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value));
233TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
235 EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
239 (LosslessArithmeticConvertible<unsigned short, UInt64>::value));
242 EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value));
244 signed char,
unsigned int>
::value));
248 unsigned char,
unsigned char>
::value));
249 EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
250 EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
252 unsigned long,
unsigned long>
::value));
256 unsigned char,
signed char>
::value));
257 EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
258 EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
261 EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value));
262 EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
263 EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
266TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
269 EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
270 EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
275TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
276 EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value));
277 EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value));
280TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
281 EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value));
282 EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
283 EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
286TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
288 EXPECT_TRUE((LosslessArithmeticConvertible<float, double>::value));
289 EXPECT_TRUE((LosslessArithmeticConvertible<float, long double>::value));
290 EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value));
293 EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value));
294 EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value));
297 EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
305 EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value));
311TEST(TupleMatchesTest, WorksForSize0) {
318TEST(TupleMatchesTest, WorksForSize1) {
319 tuple<Matcher<int> > matchers(
Eq(1));
320 tuple<int> values1(1),
327TEST(TupleMatchesTest, WorksForSize2) {
328 tuple<Matcher<int>, Matcher<char> > matchers(
Eq(1),
Eq(
'a'));
329 tuple<int, char> values1(1,
'a'),
340TEST(TupleMatchesTest, WorksForSize5) {
341 tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>,
342 Matcher<std::string> >
343 matchers(
Eq(1),
Eq(
'a'),
Eq(
true),
Eq(2L),
Eq(
"hi"));
344 tuple<int, char, bool, long, std::string>
345 values1(1,
'a',
true, 2L,
"hi"), values2(1,
'a',
true, 2L,
"hello"),
346 values3(2,
'a',
true, 2L,
"hi");
354TEST(AssertTest, SucceedsOnTrue) {
355 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
356 Assert(
true, __FILE__, __LINE__);
360TEST(AssertTest, FailsFatallyOnFalse) {
362 Assert(
false, __FILE__, __LINE__,
"This should fail.");
366 Assert(
false, __FILE__, __LINE__);
371TEST(ExpectTest, SucceedsOnTrue) {
372 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
373 Expect(
true, __FILE__, __LINE__);
377TEST(ExpectTest, FailsNonfatallyOnFalse) {
379 Expect(
false, __FILE__, __LINE__,
"This should fail.");
380 },
"This should fail");
383 Expect(
false, __FILE__, __LINE__);
384 },
"Expectation failed");
391 virtual void SetUp() {
400TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
406TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
412TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
418#if GTEST_HAS_STREAM_REDIRECTION
424void TestLogWithSeverity(
const std::string& verbosity,
LogSeverity severity,
426 const std::string old_flag =
GMOCK_FLAG(verbose);
429 Log(severity,
"Test log.\n", 0);
434 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
435 "^\nTest log\\.\nStack trace:\n"));
444TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
445 const std::string saved_flag =
GMOCK_FLAG(verbose);
454 virtual std::string CurrentStackTrace(
int max_depth,
int skip_count) {
458 virtual void UponLeavingGTest() {}
463TEST(LogTest, NoSkippingStackFrameInOptMode) {
464 MockStackTraceGetter* mock_os_stack_trace_getter =
new MockStackTraceGetter;
471 std::string expected_trace =
473 std::string expected_message =
479 int skip_count = atoi(log.substr(expected_message.size()).c_str());
483 const int expected_skip_count = 0;
486 const int expected_skip_count = 100;
493 AllOf(
Ge(expected_skip_count),
Le(expected_skip_count + 10)));
501TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
502 TestLogWithSeverity(kInfoVerbosity,
kInfo,
true);
503 TestLogWithSeverity(kInfoVerbosity,
kWarning,
true);
508TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
509 TestLogWithSeverity(kWarningVerbosity,
kInfo,
false);
510 TestLogWithSeverity(kWarningVerbosity,
kWarning,
true);
515TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
516 TestLogWithSeverity(kErrorVerbosity,
kInfo,
false);
517 TestLogWithSeverity(kErrorVerbosity,
kWarning,
false);
522TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
523 TestLogWithSeverity(
"invalid",
kInfo,
false);
524 TestLogWithSeverity(
"invalid",
kWarning,
true);
537TEST(TypeTraitsTest, is_reference) {
543TEST(TypeTraitsTest, is_pointer) {
549TEST(TypeTraitsTest, type_equals) {
556TEST(TypeTraitsTest, remove_reference) {
564#if GTEST_HAS_STREAM_REDIRECTION
568std::string GrabOutput(
void(*
logger)(),
const char* verbosity) {
569 const std::string saved_flag =
GMOCK_FLAG(verbose);
583void ExpectCallLogger() {
590TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
591 EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)),
592 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
597TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
598 EXPECT_STREQ(
"", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str());
603TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
604 EXPECT_STREQ(
"", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
613TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
614 EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)),
615 HasSubstr(
"ON_CALL(mock, TestMethod())"));
620TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
621 EXPECT_STREQ(
"", GrabOutput(OnCallLogger, kWarningVerbosity).c_str());
626TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
627 EXPECT_STREQ(
"", GrabOutput(OnCallLogger, kErrorVerbosity).c_str());
630void OnCallAnyArgumentLogger() {
632 ON_CALL(mock, TestMethodArg(_));
636TEST(OnCallTest, LogsAnythingArgument) {
637 EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)),
638 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
645TEST(StlContainerViewTest, WorksForStlContainer) {
646 StaticAssertTypeEq<std::vector<int>,
647 StlContainerView<std::vector<int> >::type>();
648 StaticAssertTypeEq<const std::vector<double>&,
649 StlContainerView<std::vector<double> >::const_reference>();
651 typedef std::vector<char> Chars;
661TEST(StlContainerViewTest, WorksForStaticNativeArray) {
662 StaticAssertTypeEq<NativeArray<int>,
664 StaticAssertTypeEq<NativeArray<double>,
666 StaticAssertTypeEq<NativeArray<char[3]>,
669 StaticAssertTypeEq<const NativeArray<int>,
672 int a1[3] = { 0, 1, 2 };
688TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
689 StaticAssertTypeEq<NativeArray<int>,
690 StlContainerView<tuple<const int*, size_t> >::type>();
691 StaticAssertTypeEq<NativeArray<double>,
692 StlContainerView<tuple<linked_ptr<double>,
int> >::type>();
694 StaticAssertTypeEq<const NativeArray<int>,
695 StlContainerView<tuple<const int*, int> >::const_reference>();
697 int a1[3] = { 0, 1, 2 };
698 const int*
const p1 = a1;
699 NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
700 ConstReference(make_tuple(p1, 3));
704 const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
705 Copy(make_tuple(
static_cast<int*
>(a1), 3));
static const_reference ConstReference(const RawContainer &container)
static type Copy(const RawContainer &container)
const type & const_reference
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
#define MOCK_METHOD0(m,...)
#define MOCK_METHOD1(m,...)
#define GMOCK_KIND_OF_(type)
std::string original_verbose_
#define EXPECT_THAT(value, matcher)
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define GTEST_INTENTIONAL_CONST_COND_PUSH_()
#define GTEST_INTENTIONAL_CONST_COND_POP_()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define TEST_F(test_fixture, test_name)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
GeneratorWrapper< T > values(std::initializer_list< T > values)
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
bool TupleMatches(const MatcherTuple &matcher_tuple, const ValueTuple &value_tuple)
TypeWithSize< 8 >::Int Int64
const char kErrorVerbosity[]
GTEST_API_ std::string JoinAsTuple(const Strings &fields)
::std::vector< ::std::string > Strings
bool_constant< true > true_type
GTEST_API_ bool LogIsVisible(LogSeverity severity)
void Assert(bool condition, const char *file, int line)
const char kInfoVerbosity[]
class UnitTestImpl * GetUnitTestImpl()
TypeWithSize< 8 >::UInt UInt64
bool_constant< false > false_type
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()
internal::Le2Matcher Le()
PolymorphicMatcher< internal::HasSubstrMatcher< std::string > > HasSubstr(const std::string &substring)
internal::AllOfResult2< M1, M2 >::type AllOf(M1 m1, M2 m2)
internal::Ge2Matcher Ge()
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
internal::Eq2Matcher Eq()
c_gkp_out sizeof(template))