"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googlemock/test/gmock-internal-utils_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gmock-internal-utils_test.cc  (googletest-release-1.11.0):gmock-internal-utils_test.cc  (googletest-release-1.12.0)
skipping to change at line 60 skipping to change at line 60
// Indicates that this translation unit is part of Google Test's // Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is // implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to // included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in // prevent a user from accidentally including gtest-internal-inl.h in
// their code. // their code.
#define GTEST_IMPLEMENTATION_ 1 #define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_ #undef GTEST_IMPLEMENTATION_
#if GTEST_OS_CYGWIN #if GTEST_OS_CYGWIN
# include <sys/types.h> // For ssize_t. NOLINT #include <sys/types.h> // For ssize_t. NOLINT
#endif #endif
namespace proto2 { namespace proto2 {
class Message; class Message;
} // namespace proto2 } // namespace proto2
namespace testing { namespace testing {
namespace internal { namespace internal {
namespace { namespace {
TEST(JoinAsTupleTest, JoinsEmptyTuple) { TEST(JoinAsKeyValueTupleTest, JoinsEmptyTuple) {
EXPECT_EQ("", JoinAsTuple(Strings())); EXPECT_EQ("", JoinAsKeyValueTuple({}, Strings()));
} }
TEST(JoinAsTupleTest, JoinsOneTuple) { TEST(JoinAsKeyValueTupleTest, JoinsOneTuple) {
const char* fields[] = {"1"}; EXPECT_EQ("(a: 1)", JoinAsKeyValueTuple({"a"}, {"1"}));
EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1)));
} }
TEST(JoinAsTupleTest, JoinsTwoTuple) { TEST(JoinAsKeyValueTupleTest, JoinsTwoTuple) {
const char* fields[] = {"1", "a"}; EXPECT_EQ("(a: 1, b: 2)", JoinAsKeyValueTuple({"a", "b"}, {"1", "2"}));
EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2)));
} }
TEST(JoinAsTupleTest, JoinsTenTuple) { TEST(JoinAsKeyValueTupleTest, JoinsTenTuple) {
const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; EXPECT_EQ(
EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", "(a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10)",
JoinAsTuple(Strings(fields, fields + 10))); JoinAsKeyValueTuple({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));
} }
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) { TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
EXPECT_EQ("", ConvertIdentifierNameToWords("")); EXPECT_EQ("", ConvertIdentifierNameToWords(""));
EXPECT_EQ("", ConvertIdentifierNameToWords("_")); EXPECT_EQ("", ConvertIdentifierNameToWords("_"));
EXPECT_EQ("", ConvertIdentifierNameToWords("__")); EXPECT_EQ("", ConvertIdentifierNameToWords("__"));
} }
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) { TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
EXPECT_EQ("1", ConvertIdentifierNameToWords("_1")); EXPECT_EQ("1", ConvertIdentifierNameToWords("_1"));
skipping to change at line 142 skipping to change at line 141
EXPECT_EQ(raw_p2, GetRawPointer(p2)); EXPECT_EQ(raw_p2, GetRawPointer(p2));
} }
TEST(GetRawPointerTest, WorksForRawPointers) { TEST(GetRawPointerTest, WorksForRawPointers) {
int* p = nullptr; int* p = nullptr;
EXPECT_TRUE(nullptr == GetRawPointer(p)); EXPECT_TRUE(nullptr == GetRawPointer(p));
int n = 1; int n = 1;
EXPECT_EQ(&n, GetRawPointer(&n)); EXPECT_EQ(&n, GetRawPointer(&n));
} }
TEST(GetRawPointerTest, WorksForStdReferenceWrapper) {
int n = 1;
EXPECT_EQ(&n, GetRawPointer(std::ref(n)));
EXPECT_EQ(&n, GetRawPointer(std::cref(n)));
}
// Tests KindOf<T>. // Tests KindOf<T>.
class Base {}; class Base {};
class Derived : public Base {}; class Derived : public Base {};
TEST(KindOfTest, Bool) { TEST(KindOfTest, Bool) {
EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT
} }
TEST(KindOfTest, Integer) { TEST(KindOfTest, Integer) {
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
// ssize_t is not defined on Windows and possibly some other OSes. // ssize_t is not defined on Windows and possibly some other OSes.
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT
#endif #endif
} }
TEST(KindOfTest, FloatingPoint) { TEST(KindOfTest, FloatingPoint) {
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT
} }
TEST(KindOfTest, Other) { TEST(KindOfTest, Other) {
EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT
EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT
EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT
} }
// Tests LosslessArithmeticConvertible<T, U>. // Tests LosslessArithmeticConvertible<T, U>.
TEST(LosslessArithmeticConvertibleTest, BoolToBool) { TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value));
} }
TEST(LosslessArithmeticConvertibleTest, BoolToInteger) { TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value));
skipping to change at line 211 skipping to change at line 216
TEST(LosslessArithmeticConvertibleTest, IntegerToBool) { TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value));
} }
TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) { TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
// Unsigned => larger signed is fine. // Unsigned => larger signed is fine.
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
// Unsigned => larger unsigned is fine. // Unsigned => larger unsigned is fine.
EXPECT_TRUE((LosslessArithmeticConvertible< EXPECT_TRUE((LosslessArithmeticConvertible<unsigned short,
unsigned short, uint64_t>::value)); // NOLINT uint64_t>::value)); // NOLINT
// Signed => unsigned is not fine. // Signed => unsigned is not fine.
EXPECT_FALSE((LosslessArithmeticConvertible< EXPECT_FALSE(
short, uint64_t>::value)); // NOLINT (LosslessArithmeticConvertible<short, uint64_t>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible< EXPECT_FALSE((LosslessArithmeticConvertible<signed char,
signed char, unsigned int>::value)); // NOLINT unsigned int>::value)); // NOLINT
// Same size and same signedness: fine too. // Same size and same signedness: fine too.
EXPECT_TRUE((LosslessArithmeticConvertible< EXPECT_TRUE(
unsigned char, unsigned char>::value)); (LosslessArithmeticConvertible<unsigned char, unsigned char>::value));
EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
EXPECT_TRUE((LosslessArithmeticConvertible< EXPECT_TRUE((LosslessArithmeticConvertible<unsigned long,
unsigned long, unsigned long>::value)); // NOLINT unsigned long>::value)); // NOLINT
// Same size, different signedness: not fine. // Same size, different signedness: not fine.
EXPECT_FALSE((LosslessArithmeticConvertible< EXPECT_FALSE(
unsigned char, signed char>::value)); (LosslessArithmeticConvertible<unsigned char, signed char>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::value));
// Larger size => smaller size is not fine. // Larger size => smaller size is not fine.
EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int64_t, unsigned int>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<int64_t, unsigned int>::value));
} }
TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) { TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
// Integers cannot be losslessly converted to floating-points, as // Integers cannot be losslessly converted to floating-points, as
// the format of the latter is implementation-defined. // the format of the latter is implementation-defined.
EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
EXPECT_FALSE((LosslessArithmeticConvertible< EXPECT_FALSE(
short, long double>::value)); // NOLINT (LosslessArithmeticConvertible<short, long double>::value)); // NOLINT
} }
TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) { TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value));
} }
TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) { TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<double, int64_t>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<double, int64_t>::value));
skipping to change at line 274 skipping to change at line 279
EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value));
// Same size: fine. // Same size: fine.
EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value));
EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value));
// Larger size => smaller size is not fine. // Larger size => smaller size is not fine.
EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
GTEST_INTENTIONAL_CONST_COND_PUSH_() GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (sizeof(double) == sizeof(long double)) { // NOLINT if (sizeof(double) == sizeof(long double)) { // NOLINT
GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_INTENTIONAL_CONST_COND_POP_()
// In some implementations (e.g. MSVC), double and long double // In some implementations (e.g. MSVC), double and long double
// have the same size. // have the same size.
EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value)); EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
} else { } else {
EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value)); EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value));
} }
} }
// Tests the TupleMatches() template function. // Tests the TupleMatches() template function.
TEST(TupleMatchesTest, WorksForSize0) { TEST(TupleMatchesTest, WorksForSize0) {
std::tuple<> matchers; std::tuple<> matchers;
std::tuple<> values; std::tuple<> values;
EXPECT_TRUE(TupleMatches(matchers, values)); EXPECT_TRUE(TupleMatches(matchers, values));
} }
TEST(TupleMatchesTest, WorksForSize1) { TEST(TupleMatchesTest, WorksForSize1) {
std::tuple<Matcher<int> > matchers(Eq(1)); std::tuple<Matcher<int>> matchers(Eq(1));
std::tuple<int> values1(1), values2(2); std::tuple<int> values1(1), values2(2);
EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_TRUE(TupleMatches(matchers, values1));
EXPECT_FALSE(TupleMatches(matchers, values2)); EXPECT_FALSE(TupleMatches(matchers, values2));
} }
TEST(TupleMatchesTest, WorksForSize2) { TEST(TupleMatchesTest, WorksForSize2) {
std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a')); std::tuple<Matcher<int>, Matcher<char>> matchers(Eq(1), Eq('a'));
std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'), std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
values4(2, 'b'); values4(2, 'b');
EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_TRUE(TupleMatches(matchers, values1));
EXPECT_FALSE(TupleMatches(matchers, values2)); EXPECT_FALSE(TupleMatches(matchers, values2));
EXPECT_FALSE(TupleMatches(matchers, values3)); EXPECT_FALSE(TupleMatches(matchers, values3));
EXPECT_FALSE(TupleMatches(matchers, values4)); EXPECT_FALSE(TupleMatches(matchers, values4));
} }
TEST(TupleMatchesTest, WorksForSize5) { TEST(TupleMatchesTest, WorksForSize5) {
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>, std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
Matcher<long>, // NOLINT Matcher<long>, // NOLINT
Matcher<std::string> > Matcher<std::string>>
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
std::tuple<int, char, bool, long, std::string> // NOLINT std::tuple<int, char, bool, long, std::string> // NOLINT
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"), values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
values3(2, 'a', true, 2L, "hi"); values3(2, 'a', true, 2L, "hi");
EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_TRUE(TupleMatches(matchers, values1));
EXPECT_FALSE(TupleMatches(matchers, values2)); EXPECT_FALSE(TupleMatches(matchers, values2));
EXPECT_FALSE(TupleMatches(matchers, values3)); EXPECT_FALSE(TupleMatches(matchers, values3));
} }
// Tests that Assert(true, ...) succeeds. // Tests that Assert(true, ...) succeeds.
TEST(AssertTest, SucceedsOnTrue) { TEST(AssertTest, SucceedsOnTrue) {
Assert(true, __FILE__, __LINE__, "This should succeed."); Assert(true, __FILE__, __LINE__, "This should succeed.");
Assert(true, __FILE__, __LINE__); // This should succeed too. Assert(true, __FILE__, __LINE__); // This should succeed too.
} }
// Tests that Assert(false, ...) generates a fatal failure. // Tests that Assert(false, ...) generates a fatal failure.
TEST(AssertTest, FailsFatallyOnFalse) { TEST(AssertTest, FailsFatallyOnFalse) {
EXPECT_DEATH_IF_SUPPORTED({ EXPECT_DEATH_IF_SUPPORTED(
Assert(false, __FILE__, __LINE__, "This should fail."); { Assert(false, __FILE__, __LINE__, "This should fail."); }, "");
}, "");
EXPECT_DEATH_IF_SUPPORTED({ Assert(false, __FILE__, __LINE__); }, "");
EXPECT_DEATH_IF_SUPPORTED({
Assert(false, __FILE__, __LINE__);
}, "");
} }
// Tests that Expect(true, ...) succeeds. // Tests that Expect(true, ...) succeeds.
TEST(ExpectTest, SucceedsOnTrue) { TEST(ExpectTest, SucceedsOnTrue) {
Expect(true, __FILE__, __LINE__, "This should succeed."); Expect(true, __FILE__, __LINE__, "This should succeed.");
Expect(true, __FILE__, __LINE__); // This should succeed too. Expect(true, __FILE__, __LINE__); // This should succeed too.
} }
// Tests that Expect(false, ...) generates a non-fatal failure. // Tests that Expect(false, ...) generates a non-fatal failure.
TEST(ExpectTest, FailsNonfatallyOnFalse) { TEST(ExpectTest, FailsNonfatallyOnFalse) {
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
Expect(false, __FILE__, __LINE__, "This should fail."); { // NOLINT
}, "This should fail"); Expect(false, __FILE__, __LINE__, "This should fail.");
},
EXPECT_NONFATAL_FAILURE({ // NOLINT "This should fail");
Expect(false, __FILE__, __LINE__);
}, "Expectation failed"); EXPECT_NONFATAL_FAILURE(
{ // NOLINT
Expect(false, __FILE__, __LINE__);
},
"Expectation failed");
} }
// Tests LogIsVisible(). // Tests LogIsVisible().
class LogIsVisibleTest : public ::testing::Test { class LogIsVisibleTest : public ::testing::Test {
protected: protected:
void SetUp() override { original_verbose_ = GMOCK_FLAG(verbose); } void SetUp() override { original_verbose_ = GMOCK_FLAG_GET(verbose); }
void TearDown() override { GMOCK_FLAG(verbose) = original_verbose_; } void TearDown() override { GMOCK_FLAG_SET(verbose, original_verbose_); }
std::string original_verbose_; std::string original_verbose_;
}; };
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) { TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
GMOCK_FLAG(verbose) = kInfoVerbosity; GMOCK_FLAG_SET(verbose, kInfoVerbosity);
EXPECT_TRUE(LogIsVisible(kInfo)); EXPECT_TRUE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(kWarning)); EXPECT_TRUE(LogIsVisible(kWarning));
} }
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) { TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
GMOCK_FLAG(verbose) = kErrorVerbosity; GMOCK_FLAG_SET(verbose, kErrorVerbosity);
EXPECT_FALSE(LogIsVisible(kInfo)); EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_FALSE(LogIsVisible(kWarning)); EXPECT_FALSE(LogIsVisible(kWarning));
} }
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
GMOCK_FLAG(verbose) = kWarningVerbosity; GMOCK_FLAG_SET(verbose, kWarningVerbosity);
EXPECT_FALSE(LogIsVisible(kInfo)); EXPECT_FALSE(LogIsVisible(kInfo));
EXPECT_TRUE(LogIsVisible(kWarning)); EXPECT_TRUE(LogIsVisible(kWarning));
} }
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Tests the Log() function. // Tests the Log() function.
// Verifies that Log() behaves correctly for the given verbosity level // Verifies that Log() behaves correctly for the given verbosity level
// and log severity. // and log severity.
void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity, void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
bool should_print) { bool should_print) {
const std::string old_flag = GMOCK_FLAG(verbose); const std::string old_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = verbosity; GMOCK_FLAG_SET(verbose, verbosity);
CaptureStdout(); CaptureStdout();
Log(severity, "Test log.\n", 0); Log(severity, "Test log.\n", 0);
if (should_print) { if (should_print) {
EXPECT_THAT(GetCapturedStdout().c_str(), EXPECT_THAT(
ContainsRegex( GetCapturedStdout().c_str(),
severity == kWarning ? ContainsRegex(severity == kWarning
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" : ? "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n"
"^\nTest log\\.\nStack trace:\n")); : "^\nTest log\\.\nStack trace:\n"));
} else { } else {
EXPECT_STREQ("", GetCapturedStdout().c_str()); EXPECT_STREQ("", GetCapturedStdout().c_str());
} }
GMOCK_FLAG(verbose) = old_flag; GMOCK_FLAG_SET(verbose, old_flag);
} }
// Tests that when the stack_frames_to_skip parameter is negative, // Tests that when the stack_frames_to_skip parameter is negative,
// Log() doesn't include the stack trace in the output. // Log() doesn't include the stack trace in the output.
TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = kInfoVerbosity; GMOCK_FLAG_SET(verbose, kInfoVerbosity);
CaptureStdout(); CaptureStdout();
Log(kInfo, "Test log.\n", -1); Log(kInfo, "Test log.\n", -1);
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str()); EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface { struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
std::string CurrentStackTrace(int max_depth, int skip_count) override { std::string CurrentStackTrace(int max_depth, int skip_count) override {
return (testing::Message() << max_depth << "::" << skip_count << "\n") return (testing::Message() << max_depth << "::" << skip_count << "\n")
.GetString(); .GetString();
} }
void UponLeavingGTest() override {} void UponLeavingGTest() override {}
}; };
skipping to change at line 442 skipping to change at line 448
// treated as 0. // treated as 0.
TEST(LogTest, NoSkippingStackFrameInOptMode) { TEST(LogTest, NoSkippingStackFrameInOptMode) {
MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter; MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter;
GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter); GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter);
CaptureStdout(); CaptureStdout();
Log(kWarning, "Test log.\n", 100); Log(kWarning, "Test log.\n", 100);
const std::string log = GetCapturedStdout(); const std::string log = GetCapturedStdout();
std::string expected_trace = std::string expected_trace =
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString(); (testing::Message() << GTEST_FLAG_GET(stack_trace_depth) << "::")
.GetString();
std::string expected_message = std::string expected_message =
"\nGMOCK WARNING:\n" "\nGMOCK WARNING:\n"
"Test log.\n" "Test log.\n"
"Stack trace:\n" + "Stack trace:\n" +
expected_trace; expected_trace;
EXPECT_THAT(log, HasSubstr(expected_message)); EXPECT_THAT(log, HasSubstr(expected_message));
int skip_count = atoi(log.substr(expected_message.size()).c_str()); int skip_count = atoi(log.substr(expected_message.size()).c_str());
# if defined(NDEBUG) #if defined(NDEBUG)
// In opt mode, no stack frame should be skipped. // In opt mode, no stack frame should be skipped.
const int expected_skip_count = 0; const int expected_skip_count = 0;
# else #else
// In dbg mode, the stack frames should be skipped. // In dbg mode, the stack frames should be skipped.
const int expected_skip_count = 100; const int expected_skip_count = 100;
# endif #endif
// Note that each inner implementation layer will +1 the number to remove // Note that each inner implementation layer will +1 the number to remove
// itself from the trace. This means that the value is a little higher than // itself from the trace. This means that the value is a little higher than
// expected, but close enough. // expected, but close enough.
EXPECT_THAT(skip_count, EXPECT_THAT(skip_count,
AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10))); AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
// Restores the default OS stack trace getter. // Restores the default OS stack trace getter.
GetUnitTestImpl()->set_os_stack_trace_getter(nullptr); GetUnitTestImpl()->set_os_stack_trace_getter(nullptr);
} }
skipping to change at line 499 skipping to change at line 506
// Tests that only warnings are printed when the value of the // Tests that only warnings are printed when the value of the
// --gmock_verbose flag is invalid. // --gmock_verbose flag is invalid.
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
TestLogWithSeverity("invalid", kInfo, false); TestLogWithSeverity("invalid", kInfo, false);
TestLogWithSeverity("invalid", kWarning, true); TestLogWithSeverity("invalid", kWarning, true);
} }
// Verifies that Log() behaves correctly for the given verbosity level // Verifies that Log() behaves correctly for the given verbosity level
// and log severity. // and log severity.
std::string GrabOutput(void(*logger)(), const char* verbosity) { std::string GrabOutput(void (*logger)(), const char* verbosity) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = verbosity; GMOCK_FLAG_SET(verbose, verbosity);
CaptureStdout(); CaptureStdout();
logger(); logger();
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
return GetCapturedStdout(); return GetCapturedStdout();
} }
class DummyMock { class DummyMock {
public: public:
MOCK_METHOD0(TestMethod, void()); MOCK_METHOD0(TestMethod, void());
MOCK_METHOD1(TestMethodArg, void(int dummy)); MOCK_METHOD1(TestMethodArg, void(int dummy));
}; };
void ExpectCallLogger() { void ExpectCallLogger() {
skipping to change at line 534 skipping to change at line 541
} }
// Verifies that EXPECT_CALL doesn't log // Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "warning". // if the --gmock_verbose flag is set to "warning".
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) { TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str()); EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str());
} }
// Verifies that EXPECT_CALL doesn't log // Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "error". // if the --gmock_verbose flag is set to "error".
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) { TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str()); EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
} }
void OnCallLogger() { void OnCallLogger() {
DummyMock mock; DummyMock mock;
ON_CALL(mock, TestMethod()); ON_CALL(mock, TestMethod());
} }
// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info". // Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
TEST(OnCallTest, LogsWhenVerbosityIsInfo) { TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
skipping to change at line 578 skipping to change at line 585
EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)), EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)),
HasSubstr("ON_CALL(mock, TestMethodArg(_)")); HasSubstr("ON_CALL(mock, TestMethodArg(_)"));
} }
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Tests StlContainerView. // Tests StlContainerView.
TEST(StlContainerViewTest, WorksForStlContainer) { TEST(StlContainerViewTest, WorksForStlContainer) {
StaticAssertTypeEq<std::vector<int>, StaticAssertTypeEq<std::vector<int>,
StlContainerView<std::vector<int> >::type>(); StlContainerView<std::vector<int>>::type>();
StaticAssertTypeEq<const std::vector<double>&, StaticAssertTypeEq<const std::vector<double>&,
StlContainerView<std::vector<double> >::const_reference>(); StlContainerView<std::vector<double>>::const_reference>();
typedef std::vector<char> Chars; typedef std::vector<char> Chars;
Chars v1; Chars v1;
const Chars& v2(StlContainerView<Chars>::ConstReference(v1)); const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
EXPECT_EQ(&v1, &v2); EXPECT_EQ(&v1, &v2);
v1.push_back('a'); v1.push_back('a');
Chars v3 = StlContainerView<Chars>::Copy(v1); Chars v3 = StlContainerView<Chars>::Copy(v1);
EXPECT_THAT(v3, Eq(v3)); EXPECT_THAT(v3, Eq(v3));
} }
TEST(StlContainerViewTest, WorksForStaticNativeArray) { TEST(StlContainerViewTest, WorksForStaticNativeArray) {
StaticAssertTypeEq<NativeArray<int>, StaticAssertTypeEq<NativeArray<int>, StlContainerView<int[3]>::type>();
StlContainerView<int[3]>::type>();
StaticAssertTypeEq<NativeArray<double>, StaticAssertTypeEq<NativeArray<double>,
StlContainerView<const double[4]>::type>(); StlContainerView<const double[4]>::type>();
StaticAssertTypeEq<NativeArray<char[3]>, StaticAssertTypeEq<NativeArray<char[3]>,
StlContainerView<const char[2][3]>::type>(); StlContainerView<const char[2][3]>::type>();
StaticAssertTypeEq<const NativeArray<int>, StaticAssertTypeEq<const NativeArray<int>,
StlContainerView<int[2]>::const_reference>(); StlContainerView<int[2]>::const_reference>();
int a1[3] = { 0, 1, 2 }; int a1[3] = {0, 1, 2};
NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1); NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
EXPECT_EQ(3U, a2.size()); EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin()); EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1); const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
ASSERT_EQ(3U, a3.size()); ASSERT_EQ(3U, a3.size());
EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]); EXPECT_EQ(2, a3.begin()[2]);
// Makes sure a1 and a3 aren't aliases. // Makes sure a1 and a3 aren't aliases.
a1[0] = 3; a1[0] = 3;
EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(0, a3.begin()[0]);
} }
TEST(StlContainerViewTest, WorksForDynamicNativeArray) { TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
StaticAssertTypeEq<NativeArray<int>, StaticAssertTypeEq<NativeArray<int>,
StlContainerView<std::tuple<const int*, size_t> >::type>(); StlContainerView<std::tuple<const int*, size_t>>::type>();
StaticAssertTypeEq< StaticAssertTypeEq<
NativeArray<double>, NativeArray<double>,
StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>(); StlContainerView<std::tuple<std::shared_ptr<double>, int>>::type>();
StaticAssertTypeEq< StaticAssertTypeEq<
const NativeArray<int>, const NativeArray<int>,
StlContainerView<std::tuple<const int*, int> >::const_reference>(); StlContainerView<std::tuple<const int*, int>>::const_reference>();
int a1[3] = { 0, 1, 2 }; int a1[3] = {0, 1, 2};
const int* const p1 = a1; const int* const p1 = a1;
NativeArray<int> a2 = NativeArray<int> a2 =
StlContainerView<std::tuple<const int*, int> >::ConstReference( StlContainerView<std::tuple<const int*, int>>::ConstReference(
std::make_tuple(p1, 3)); std::make_tuple(p1, 3));
EXPECT_EQ(3U, a2.size()); EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin()); EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy( const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t>>::Copy(
std::make_tuple(static_cast<int*>(a1), 3)); std::make_tuple(static_cast<int*>(a1), 3));
ASSERT_EQ(3U, a3.size()); ASSERT_EQ(3U, a3.size());
EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]); EXPECT_EQ(2, a3.begin()[2]);
// Makes sure a1 and a3 aren't aliases. // Makes sure a1 and a3 aren't aliases.
a1[0] = 3; a1[0] = 3;
EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(0, a3.begin()[0]);
} }
skipping to change at line 717 skipping to change at line 723
Matcher<const long&>>, // NOLINT Matcher<const long&>>, // NOLINT
F::ArgumentMatcherTuple>::value)); F::ArgumentMatcherTuple>::value));
EXPECT_TRUE( EXPECT_TRUE(
(std::is_same<void(bool, int, char*, int&, const long&), // NOLINT (std::is_same<void(bool, int, char*, int&, const long&), // NOLINT
F::MakeResultVoid>::value)); F::MakeResultVoid>::value));
EXPECT_TRUE(( EXPECT_TRUE((
std::is_same<IgnoredValue(bool, int, char*, int&, const long&), // NOLINT std::is_same<IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
F::MakeResultIgnoredValue>::value)); F::MakeResultIgnoredValue>::value));
} }
TEST(Base64Unescape, InvalidString) {
std::string unescaped;
EXPECT_FALSE(Base64Unescape("(invalid)", &unescaped));
}
TEST(Base64Unescape, ShortString) {
std::string unescaped;
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQh", &unescaped));
EXPECT_EQ("Hello world!", unescaped);
}
TEST(Base64Unescape, ShortStringWithPadding) {
std::string unescaped;
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ=", &unescaped));
EXPECT_EQ("Hello world", unescaped);
}
TEST(Base64Unescape, ShortStringWithoutPadding) {
std::string unescaped;
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ", &unescaped));
EXPECT_EQ("Hello world", unescaped);
}
TEST(Base64Unescape, LongStringWithWhiteSpaces) {
std::string escaped =
R"(TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB
0aGlz
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=)";
std::string expected =
"Man is distinguished, not only by his reason, but by this singular "
"passion from other animals, which is a lust of the mind, that by a "
"perseverance of delight in the continued and indefatigable generation "
"of knowledge, exceeds the short vehemence of any carnal pleasure.";
std::string unescaped;
EXPECT_TRUE(Base64Unescape(escaped, &unescaped));
EXPECT_EQ(expected, unescaped);
}
} // namespace } // namespace
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
 End of changes. 54 change blocks. 
100 lines changed or deleted 147 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)