42 #include "gmock/gmock.h" 44 #include "gtest/gtest.h" 45 #include "gtest/gtest-spi.h" 48 # include <sys/types.h> 51 class ProtocolMessage;
63 using ::std::tr1::tuple;
65 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
71 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
78 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
86 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
93 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
99 TEST(PointeeOfTest, WorksForSmartPointers) {
100 CompileAssertTypesEqual<
const char,
101 PointeeOf<internal::linked_ptr<const char> >::type>();
104 TEST(PointeeOfTest, WorksForRawPointers) {
105 CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
106 CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
107 CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
110 TEST(GetRawPointerTest, WorksForSmartPointers) {
111 const char*
const raw_p4 =
new const char(
'a');
112 const internal::linked_ptr<const char> p4(raw_p4);
116 TEST(GetRawPointerTest, WorksForRawPointers) {
127 class Derived :
public Base {};
133 TEST(KindOfTest, Integer) {
147 #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN 153 TEST(KindOfTest, FloatingPoint) {
159 TEST(KindOfTest, Other) {
167 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
168 EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value));
171 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
172 EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value));
173 EXPECT_TRUE((LosslessArithmeticConvertible<bool, int>::value));
175 (LosslessArithmeticConvertible<bool, unsigned long>::value));
178 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
179 EXPECT_TRUE((LosslessArithmeticConvertible<bool, float>::value));
180 EXPECT_TRUE((LosslessArithmeticConvertible<bool, double>::value));
183 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
184 EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value));
185 EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value));
188 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
190 EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
194 (LosslessArithmeticConvertible<unsigned short, UInt64>::value));
197 EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value));
199 signed char,
unsigned int>::value));
203 unsigned char,
unsigned char>::value));
204 EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
205 EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
207 unsigned long,
unsigned long>::value));
211 unsigned char,
signed char>::value));
212 EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
213 EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
216 EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value));
217 EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
218 EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
221 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
224 EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
225 EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
227 short,
long double>::value));
230 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
231 EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value));
232 EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value));
235 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
236 EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value));
237 EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
238 EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
241 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
243 EXPECT_TRUE((LosslessArithmeticConvertible<float, double>::value));
244 EXPECT_TRUE((LosslessArithmeticConvertible<float, long double>::value));
245 EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value));
248 EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value));
249 EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value));
252 EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
253 if (
sizeof(
double) ==
sizeof(
long double)) {
256 EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
258 EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value));
264 TEST(TupleMatchesTest, WorksForSize0) {
271 TEST(TupleMatchesTest, WorksForSize1) {
272 tuple<Matcher<int> > matchers(
Eq(1));
273 tuple<int> values1(1),
280 TEST(TupleMatchesTest, WorksForSize2) {
281 tuple<Matcher<int>, Matcher<char> > matchers(
Eq(1),
Eq(
'a'));
282 tuple<int, char> values1(1,
'a'),
293 TEST(TupleMatchesTest, WorksForSize5) {
294 tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>,
296 matchers(
Eq(1),
Eq(
'a'),
Eq(
true),
Eq(2L),
Eq(
"hi"));
297 tuple<int, char, bool, long, string>
298 values1(1,
'a',
true, 2L,
"hi"),
299 values2(1,
'a',
true, 2L,
"hello"),
300 values3(2,
'a',
true, 2L,
"hi");
308 TEST(AssertTest, SucceedsOnTrue) {
309 Assert(
true, __FILE__, __LINE__,
"This should succeed.");
310 Assert(
true, __FILE__, __LINE__);
314 TEST(AssertTest, FailsFatallyOnFalse) {
316 Assert(
false, __FILE__, __LINE__,
"This should fail.");
320 Assert(
false, __FILE__, __LINE__);
325 TEST(ExpectTest, SucceedsOnTrue) {
326 Expect(
true, __FILE__, __LINE__,
"This should succeed.");
327 Expect(
true, __FILE__, __LINE__);
331 TEST(ExpectTest, FailsNonfatallyOnFalse) {
333 Expect(
false, __FILE__, __LINE__,
"This should fail.");
334 },
"This should fail");
337 Expect(
false, __FILE__, __LINE__);
338 },
"Expectation failed");
345 virtual void SetUp() {
354 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
360 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
366 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
372 #if GTEST_HAS_STREAM_REDIRECTION 383 Log(severity,
"Test log.\n", 0);
388 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
389 "^\nTest log\\.\nStack trace:\n"));
398 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
399 const string saved_flag =
GMOCK_FLAG(verbose);
402 Log(
kInfo,
"Test log.\n", -1);
409 TEST(LogTest, NoSkippingStackFrameInOptMode) {
414 # if defined(NDEBUG) && GTEST_GOOGLE3_MODE_ 426 "Stack trace:\n", log.c_str());
432 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
439 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
446 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
453 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
454 TestLogWithSeverity(
"invalid",
kInfo,
false);
455 TestLogWithSeverity(
"invalid",
kWarning,
true);
458 #endif // GTEST_HAS_STREAM_REDIRECTION 468 TEST(TypeTraitsTest, is_reference) {
474 TEST(TypeTraitsTest, is_pointer) {
480 TEST(TypeTraitsTest, type_equals) {
487 TEST(TypeTraitsTest, remove_reference) {
488 EXPECT_TRUE((type_equals<
char, remove_reference<char&>::type>::value));
490 remove_reference<const int&>::type>::value));
491 EXPECT_TRUE((type_equals<
int, remove_reference<int>::type>::value));
492 EXPECT_TRUE((type_equals<
double*, remove_reference<double*>::type>::value));
495 #if GTEST_HAS_STREAM_REDIRECTION 499 std::string GrabOutput(
void(*logger)(),
const char* verbosity) {
500 const string saved_flag =
GMOCK_FLAG(verbose);
514 void ExpectCallLogger() {
521 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
523 HasSubstr(
"EXPECT_CALL(mock, TestMethod())"));
528 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
534 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
538 void OnCallLogger() {
544 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
546 HasSubstr(
"ON_CALL(mock, TestMethod())"));
551 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
557 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
561 void OnCallAnyArgumentLogger() {
567 TEST(OnCallTest, LogsAnythingArgument) {
569 HasSubstr(
"ON_CALL(mock, TestMethodArg(_)"));
572 #endif // GTEST_HAS_STREAM_REDIRECTION 576 TEST(StlContainerViewTest, WorksForStlContainer) {
577 StaticAssertTypeEq<std::vector<int>,
578 StlContainerView<std::vector<int> >::type>();
579 StaticAssertTypeEq<const std::vector<double>&,
580 StlContainerView<std::vector<double> >::const_reference>();
582 typedef std::vector<char> Chars;
584 const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
588 Chars v3 = StlContainerView<Chars>::Copy(v1);
592 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
593 StaticAssertTypeEq<NativeArray<int>,
594 StlContainerView<int[3]>::type>();
595 StaticAssertTypeEq<NativeArray<double>,
596 StlContainerView<const double[4]>::type>();
597 StaticAssertTypeEq<NativeArray<char[3]>,
598 StlContainerView<const char[2][3]>::type>();
600 StaticAssertTypeEq<const NativeArray<int>,
601 StlContainerView<int[2]>::const_reference>();
603 int a1[3] = { 0, 1, 2 };
604 NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
608 const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
619 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
620 StaticAssertTypeEq<NativeArray<int>,
621 StlContainerView<tuple<const int*, size_t> >::type>();
622 StaticAssertTypeEq<NativeArray<double>,
623 StlContainerView<tuple<linked_ptr<double>,
int> >::type>();
625 StaticAssertTypeEq<const NativeArray<int>,
626 StlContainerView<tuple<const int*, int> >::const_reference>();
628 int a1[3] = { 0, 1, 2 };
629 const int*
const p1 = a1;
630 NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
635 const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
std::string GetCapturedStdout()
#define MOCK_METHOD0(m,...)
GTEST_API_ string ConvertIdentifierNameToWords(const char *id_name)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
internal::EqMatcher< T > Eq(T x)
const char kErrorVerbosity[]
#define EXPECT_THAT(value, matcher)
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
bool TupleMatches(const MatcherTuple &matcher_tuple, const ValueTuple &value_tuple)
#define EXPECT_TRUE(condition)
#define ON_CALL(obj, call)
#define EXPECT_STREQ(expected, actual)
bool_constant< true > true_type
const char kInfoVerbosity[]
#define TEST_F(test_fixture, test_name)
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)
#define EXPECT_FALSE(condition)
#define TEST(test_case_name, test_name)
#define ASSERT_EQ(val1, val2)
GTEST_API_ bool LogIsVisible(LogSeverity severity)
#define MOCK_METHOD1(m,...)
#define GMOCK_KIND_OF_(type)
void Assert(bool condition, const char *file, int line)
#define EXPECT_CALL(obj, call)
const Pointer::element_type * GetRawPointer(const Pointer &p)
bool_constant< false > false_type
const internal::AnythingMatcher _
#define EXPECT_EQ(expected, actual)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)