Avoids unnecessary printing of call into to internal buffers;
Made the universal value printer safer when printing char[]; Removed duplicated code in InvokeWith; Improved gmock_doctor.py.
This commit is contained in:
@@ -494,6 +494,34 @@ TEST(ExpectTest, FailsNonfatallyOnFalse) {
|
||||
}, "Expectation failed");
|
||||
}
|
||||
|
||||
// Tests LogIsVisible().
|
||||
|
||||
class LogIsVisibleTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() { original_verbose_ = GMOCK_FLAG(verbose); }
|
||||
virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
|
||||
string original_verbose_;
|
||||
};
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
|
||||
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
||||
EXPECT_TRUE(LogIsVisible(INFO));
|
||||
EXPECT_TRUE(LogIsVisible(WARNING));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
|
||||
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
||||
EXPECT_FALSE(LogIsVisible(INFO));
|
||||
EXPECT_FALSE(LogIsVisible(WARNING));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
||||
GMOCK_FLAG(verbose) = kWarningVerbosity;
|
||||
EXPECT_FALSE(LogIsVisible(INFO));
|
||||
EXPECT_TRUE(LogIsVisible(WARNING));
|
||||
}
|
||||
|
||||
// TODO(wan@google.com): find a way to re-enable these tests.
|
||||
#if 0
|
||||
|
||||
|
||||
@@ -485,75 +485,58 @@ TEST(PrintPointerTest, MemberFunctionPointer) {
|
||||
|
||||
// Tests printing C arrays.
|
||||
|
||||
// One-dimensional array.
|
||||
|
||||
void ArrayHelper1(int (&a)[5]) { // NOLINT
|
||||
EXPECT_EQ("{ 1, 2, 3, 4, 5 }", Print(a));
|
||||
// The difference between this and Print() is that it ensures that the
|
||||
// argument is a reference to an array.
|
||||
template <typename T, size_t N>
|
||||
string PrintArrayHelper(T (&a)[N]) {
|
||||
return Print(a);
|
||||
}
|
||||
|
||||
// One-dimensional array.
|
||||
TEST(PrintArrayTest, OneDimensionalArray) {
|
||||
int a[5] = { 1, 2, 3, 4, 5 };
|
||||
ArrayHelper1(a);
|
||||
EXPECT_EQ("{ 1, 2, 3, 4, 5 }", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Two-dimensional array.
|
||||
|
||||
void ArrayHelper2(int (&a)[2][5]) { // NOLINT
|
||||
EXPECT_EQ("{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }", Print(a));
|
||||
}
|
||||
|
||||
TEST(PrintArrayTest, TwoDimensionalArray) {
|
||||
int a[2][5] = {
|
||||
{ 1, 2, 3, 4, 5 },
|
||||
{ 6, 7, 8, 9, 0 }
|
||||
};
|
||||
ArrayHelper2(a);
|
||||
EXPECT_EQ("{ { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 0 } }", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Array of const elements.
|
||||
|
||||
void ArrayHelper3(const bool (&a)[1]) { // NOLINT
|
||||
EXPECT_EQ("{ false }", Print(a));
|
||||
}
|
||||
|
||||
TEST(PrintArrayTest, ConstArray) {
|
||||
const bool a[1] = { false };
|
||||
ArrayHelper3(a);
|
||||
EXPECT_EQ("{ false }", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Char array.
|
||||
|
||||
void ArrayHelper4(char (&a)[3]) { // NOLINT
|
||||
EXPECT_EQ(PrintPointer(a) + " pointing to \"Hi\"", Print(a));
|
||||
}
|
||||
|
||||
TEST(PrintArrayTest, CharArray) {
|
||||
char a[3] = "Hi";
|
||||
ArrayHelper4(a);
|
||||
// Array a contains '\0' in the middle and doesn't end with '\0'.
|
||||
char a[3] = { 'H', '\0', 'i' };
|
||||
EXPECT_EQ("\"H\\0i\"", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Const char array.
|
||||
|
||||
void ArrayHelper5(const char (&a)[3]) { // NOLINT
|
||||
EXPECT_EQ(Print(a), PrintPointer(a) + " pointing to \"Hi\"");
|
||||
}
|
||||
|
||||
TEST(PrintArrayTest, ConstCharArray) {
|
||||
const char a[3] = "Hi";
|
||||
ArrayHelper5(a);
|
||||
const char a[4] = "\0Hi";
|
||||
EXPECT_EQ("\"\\0Hi\\0\"", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Array of objects.
|
||||
TEST(PrintArrayTest, ObjectArray) {
|
||||
string a[3] = { "Hi", "Hello", "Ni hao" };
|
||||
EXPECT_EQ("{ \"Hi\", \"Hello\", \"Ni hao\" }", Print(a));
|
||||
EXPECT_EQ("{ \"Hi\", \"Hello\", \"Ni hao\" }", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Array with many elements.
|
||||
TEST(PrintArrayTest, BigArray) {
|
||||
int a[100] = { 1, 2, 3 };
|
||||
EXPECT_EQ("{ 1, 2, 3, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0, 0, 0 }",
|
||||
Print(a));
|
||||
PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// Tests printing ::string and ::std::string.
|
||||
@@ -995,6 +978,11 @@ TEST(PrintToStringTest, WorksForReference) {
|
||||
UniversalPrinter<const int&>::PrintToString(n));
|
||||
}
|
||||
|
||||
TEST(PrintToStringTest, WorksForArray) {
|
||||
int n[3] = { 1, 2, 3 };
|
||||
EXPECT_EQ("{ 1, 2, 3 }", UniversalPrinter<int[3]>::PrintToString(n));
|
||||
}
|
||||
|
||||
TEST(UniversalTersePrintTest, WorksForNonReference) {
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(123, &ss);
|
||||
|
||||
@@ -1612,6 +1612,53 @@ TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
|
||||
|
||||
#endif // 0
|
||||
|
||||
// A helper class that generates a failure when printed. We use it to
|
||||
// ensure that Google Mock doesn't print a value (even to an internal
|
||||
// buffer) when it is not supposed to do so.
|
||||
class PrintMeNot {};
|
||||
|
||||
void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) {
|
||||
ADD_FAILURE() << "Google Mock is printing a value that shouldn't be "
|
||||
<< "printed even to an internal buffer.";
|
||||
}
|
||||
|
||||
class LogTestHelper {
|
||||
public:
|
||||
MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot));
|
||||
};
|
||||
|
||||
class GMockLogTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() { original_verbose_ = GMOCK_FLAG(verbose); }
|
||||
virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
|
||||
LogTestHelper helper_;
|
||||
string original_verbose_;
|
||||
};
|
||||
|
||||
TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
|
||||
GMOCK_FLAG(verbose) = kWarningVerbosity;
|
||||
EXPECT_CALL(helper_, Foo(_))
|
||||
.WillOnce(Return(PrintMeNot()));
|
||||
helper_.Foo(PrintMeNot()); // This is an expected call.
|
||||
}
|
||||
|
||||
TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
|
||||
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
||||
EXPECT_CALL(helper_, Foo(_))
|
||||
.WillOnce(Return(PrintMeNot()));
|
||||
helper_.Foo(PrintMeNot()); // This is an expected call.
|
||||
}
|
||||
|
||||
TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
|
||||
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
||||
ON_CALL(helper_, Foo(_))
|
||||
.WillByDefault(Return(PrintMeNot()));
|
||||
helper_.Foo(PrintMeNot()); // This should generate a warning.
|
||||
}
|
||||
|
||||
// Tests Mock::AllowLeak().
|
||||
|
||||
TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
|
||||
MockA* a = new MockA;
|
||||
Mock::AllowLeak(a);
|
||||
|
||||
Reference in New Issue
Block a user