"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googlemock/test/gmock-more-actions_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-more-actions_test.cc  (googletest-release-1.11.0):gmock-more-actions_test.cc  (googletest-release-1.12.0)
skipping to change at line 148 skipping to change at line 148
class Foo { class Foo {
public: public:
Foo() : value_(123) {} Foo() : value_(123) {}
int Nullary() const { return value_; } int Nullary() const { return value_; }
short Unary(long x) { return static_cast<short>(value_ + x); } // NOLINT short Unary(long x) { return static_cast<short>(value_ + x); } // NOLINT
std::string Binary(const std::string& str, char c) const { return str + c; } std::string Binary(const std::string& str, char c) const { return str + c; }
int Ternary(int x, bool y, char z) { return value_ + x + y*z; } int Ternary(int x, bool y, char z) { return value_ + x + y * z; }
int SumOf4(int a, int b, int c, int d) const { int SumOf4(int a, int b, int c, int d) const {
return a + b + c + d + value_; return a + b + c + d + value_;
} }
int SumOfLast2(Unused, Unused, int a, int b) const { return a + b; } int SumOfLast2(Unused, Unused, int a, int b) const { return a + b; }
int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; } int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; }
int SumOf6(int a, int b, int c, int d, int e, int f) { int SumOf6(int a, int b, int c, int d, int e, int f) {
skipping to change at line 294 skipping to change at line 294
CharPtr("0")))); CharPtr("0"))));
} }
// Tests using Invoke() with functions with parameters declared as Unused. // Tests using Invoke() with functions with parameters declared as Unused.
TEST(InvokeTest, FunctionWithUnusedParameters) { TEST(InvokeTest, FunctionWithUnusedParameters) {
Action<int(int, int, double, const std::string&)> a1 = Invoke(SumOfFirst2); Action<int(int, int, double, const std::string&)> a1 = Invoke(SumOfFirst2);
std::tuple<int, int, double, std::string> dummy = std::tuple<int, int, double, std::string> dummy =
std::make_tuple(10, 2, 5.6, std::string("hi")); std::make_tuple(10, 2, 5.6, std::string("hi"));
EXPECT_EQ(12, a1.Perform(dummy)); EXPECT_EQ(12, a1.Perform(dummy));
Action<int(int, int, bool, int*)> a2 = Action<int(int, int, bool, int*)> a2 = Invoke(SumOfFirst2);
Invoke(SumOfFirst2);
EXPECT_EQ( EXPECT_EQ(
23, a2.Perform(std::make_tuple(20, 3, true, static_cast<int*>(nullptr)))); 23, a2.Perform(std::make_tuple(20, 3, true, static_cast<int*>(nullptr))));
} }
// Tests using Invoke() with methods with parameters declared as Unused. // Tests using Invoke() with methods with parameters declared as Unused.
TEST(InvokeTest, MethodWithUnusedParameters) { TEST(InvokeTest, MethodWithUnusedParameters) {
Foo foo; Foo foo;
Action<int(std::string, bool, int, int)> a1 = Invoke(&foo, &Foo::SumOfLast2); Action<int(std::string, bool, int, int)> a1 = Invoke(&foo, &Foo::SumOfLast2);
EXPECT_EQ(12, a1.Perform(std::make_tuple(CharPtr("hi"), true, 10, 2))); EXPECT_EQ(12, a1.Perform(std::make_tuple(CharPtr("hi"), true, 10, 2)));
Action<int(char, double, int, int)> a2 = Action<int(char, double, int, int)> a2 = Invoke(&foo, &Foo::SumOfLast2);
Invoke(&foo, &Foo::SumOfLast2);
EXPECT_EQ(23, a2.Perform(std::make_tuple('a', 2.5, 20, 3))); EXPECT_EQ(23, a2.Perform(std::make_tuple('a', 2.5, 20, 3)));
} }
// Tests using Invoke() with a functor. // Tests using Invoke() with a functor.
TEST(InvokeTest, Functor) { TEST(InvokeTest, Functor) {
Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT
EXPECT_EQ(3L, a.Perform(std::make_tuple(1, 2))); EXPECT_EQ(3L, a.Perform(std::make_tuple(1, 2)));
} }
// Tests using Invoke(f) as an action of a compatible type. // Tests using Invoke(f) as an action of a compatible type.
skipping to change at line 365 skipping to change at line 363
// Tests using Invoke() with a 4-argument method. // Tests using Invoke() with a 4-argument method.
TEST(InvokeMethodTest, MethodThatTakes4Arguments) { TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
Foo foo; Foo foo;
Action<int(int, int, int, int)> a = Invoke(&foo, &Foo::SumOf4); // NOLINT Action<int(int, int, int, int)> a = Invoke(&foo, &Foo::SumOf4); // NOLINT
EXPECT_EQ(1357, a.Perform(std::make_tuple(1000, 200, 30, 4))); EXPECT_EQ(1357, a.Perform(std::make_tuple(1000, 200, 30, 4)));
} }
// Tests using Invoke() with a 5-argument method. // Tests using Invoke() with a 5-argument method.
TEST(InvokeMethodTest, MethodThatTakes5Arguments) { TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
Foo foo; Foo foo;
Action<int(int, int, int, int, int)> a = Invoke(&foo, &Foo::SumOf5); // NOLIN Action<int(int, int, int, int, int)> a =
T Invoke(&foo, &Foo::SumOf5); // NOLINT
EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5))); EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
} }
// Tests using Invoke() with a 6-argument method. // Tests using Invoke() with a 6-argument method.
TEST(InvokeMethodTest, MethodThatTakes6Arguments) { TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
Foo foo; Foo foo;
Action<int(int, int, int, int, int, int)> a = // NOLINT Action<int(int, int, int, int, int, int)> a = // NOLINT
Invoke(&foo, &Foo::SumOf6); Invoke(&foo, &Foo::SumOf6);
EXPECT_EQ(123456, EXPECT_EQ(123456,
a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6))); a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
skipping to change at line 465 skipping to change at line 464
TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) { TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
const Action<bool(bool, bool, bool)> a = ReturnArg<0>(); const Action<bool(bool, bool, bool)> a = ReturnArg<0>();
EXPECT_TRUE(a.Perform(std::make_tuple(true, false, false))); EXPECT_TRUE(a.Perform(std::make_tuple(true, false, false)));
} }
TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) { TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
const Action<std::string(int, int, std::string, int)> a = ReturnArg<2>(); const Action<std::string(int, int, std::string, int)> a = ReturnArg<2>();
EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8))); EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8)));
} }
TEST(ReturnArgActionTest, WorksForNonConstRefArg0) {
const Action<std::string&(std::string&)> a = ReturnArg<0>();
std::string s = "12345";
EXPECT_EQ(&s, &a.Perform(std::forward_as_tuple(s)));
}
TEST(SaveArgActionTest, WorksForSameType) { TEST(SaveArgActionTest, WorksForSameType) {
int result = 0; int result = 0;
const Action<void(int n)> a1 = SaveArg<0>(&result); const Action<void(int n)> a1 = SaveArg<0>(&result);
a1.Perform(std::make_tuple(5)); a1.Perform(std::make_tuple(5));
EXPECT_EQ(5, result); EXPECT_EQ(5, result);
} }
TEST(SaveArgActionTest, WorksForCompatibleType) { TEST(SaveArgActionTest, WorksForCompatibleType) {
int result = 0; int result = 0;
const Action<void(bool, char)> a1 = SaveArg<1>(&result); const Action<void(bool, char)> a1 = SaveArg<1>(&result);
skipping to change at line 520 skipping to change at line 525
int value = 0; int value = 0;
const Action<void(bool, int, int&, const char*)> a1 = SetArgReferee<2>('a'); const Action<void(bool, int, int&, const char*)> a1 = SetArgReferee<2>('a');
a1.Perform(std::tuple<bool, int, int&, const char*>(true, 0, value, "hi")); a1.Perform(std::tuple<bool, int, int&, const char*>(true, 0, value, "hi"));
EXPECT_EQ('a', value); EXPECT_EQ('a', value);
} }
// A class that can be used to verify that its destructor is called: it will set // A class that can be used to verify that its destructor is called: it will set
// the bool provided to the constructor to true when destroyed. // the bool provided to the constructor to true when destroyed.
class DeletionTester { class DeletionTester {
public: public:
explicit DeletionTester(bool* is_deleted) explicit DeletionTester(bool* is_deleted) : is_deleted_(is_deleted) {
: is_deleted_(is_deleted) {
// Make sure the bit is set to false. // Make sure the bit is set to false.
*is_deleted_ = false; *is_deleted_ = false;
} }
~DeletionTester() { ~DeletionTester() { *is_deleted_ = true; }
*is_deleted_ = true;
}
private: private:
bool* is_deleted_; bool* is_deleted_;
}; };
TEST(DeleteArgActionTest, OneArg) { TEST(DeleteArgActionTest, OneArg) {
bool is_deleted = false; bool is_deleted = false;
DeletionTester* t = new DeletionTester(&is_deleted); DeletionTester* t = new DeletionTester(&is_deleted);
const Action<void(DeletionTester*)> a1 = DeleteArg<0>(); // NOLINT const Action<void(DeletionTester*)> a1 = DeleteArg<0>(); // NOLINT
EXPECT_FALSE(is_deleted); EXPECT_FALSE(is_deleted);
a1.Perform(std::make_tuple(t)); a1.Perform(std::make_tuple(t));
EXPECT_TRUE(is_deleted); EXPECT_TRUE(is_deleted);
} }
TEST(DeleteArgActionTest, TenArgs) { TEST(DeleteArgActionTest, TenArgs) {
bool is_deleted = false; bool is_deleted = false;
DeletionTester* t = new DeletionTester(&is_deleted); DeletionTester* t = new DeletionTester(&is_deleted);
const Action<void(bool, int, int, const char*, bool, const Action<void(bool, int, int, const char*, bool, int, int, int, int,
int, int, int, int, DeletionTester*)> a1 = DeleteArg<9>(); DeletionTester*)>
a1 = DeleteArg<9>();
EXPECT_FALSE(is_deleted); EXPECT_FALSE(is_deleted);
a1.Perform(std::make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t)); a1.Perform(std::make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t));
EXPECT_TRUE(is_deleted); EXPECT_TRUE(is_deleted);
} }
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) { TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
const Action<void(int n)> a = Throw('a'); const Action<void(int n)> a = Throw('a');
EXPECT_THROW(a.Perform(std::make_tuple(0)), char); EXPECT_THROW(a.Perform(std::make_tuple(0)), char);
skipping to change at line 605 skipping to change at line 608
}(), }(),
""); "");
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
// Tests that SetArrayArgument<N>(first, last) sets the elements of the array // Tests that SetArrayArgument<N>(first, last) sets the elements of the array
// pointed to by the N-th (0-based) argument to values in range [first, last). // pointed to by the N-th (0-based) argument to values in range [first, last).
TEST(SetArrayArgumentTest, SetsTheNthArray) { TEST(SetArrayArgumentTest, SetsTheNthArray) {
using MyFunction = void(bool, int*, char*); using MyFunction = void(bool, int*, char*);
int numbers[] = { 1, 2, 3 }; int numbers[] = {1, 2, 3};
Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers + 3); Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers + 3);
int n[4] = {}; int n[4] = {};
int* pn = n; int* pn = n;
char ch[4] = {}; char ch[4] = {};
char* pch = ch; char* pch = ch;
a.Perform(std::make_tuple(true, pn, pch)); a.Perform(std::make_tuple(true, pn, pch));
EXPECT_EQ(1, n[0]); EXPECT_EQ(1, n[0]);
EXPECT_EQ(2, n[1]); EXPECT_EQ(2, n[1]);
EXPECT_EQ(3, n[2]); EXPECT_EQ(3, n[2]);
skipping to change at line 641 skipping to change at line 644
EXPECT_EQ(0, n[3]); EXPECT_EQ(0, n[3]);
EXPECT_EQ('a', ch[0]); EXPECT_EQ('a', ch[0]);
EXPECT_EQ('b', ch[1]); EXPECT_EQ('b', ch[1]);
EXPECT_EQ('c', ch[2]); EXPECT_EQ('c', ch[2]);
EXPECT_EQ('\0', ch[3]); EXPECT_EQ('\0', ch[3]);
} }
// Tests SetArrayArgument<N>(first, last) where first == last. // Tests SetArrayArgument<N>(first, last) where first == last.
TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) { TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
using MyFunction = void(bool, int*); using MyFunction = void(bool, int*);
int numbers[] = { 1, 2, 3 }; int numbers[] = {1, 2, 3};
Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers); Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers);
int n[4] = {}; int n[4] = {};
int* pn = n; int* pn = n;
a.Perform(std::make_tuple(true, pn)); a.Perform(std::make_tuple(true, pn));
EXPECT_EQ(0, n[0]); EXPECT_EQ(0, n[0]);
EXPECT_EQ(0, n[1]); EXPECT_EQ(0, n[1]);
EXPECT_EQ(0, n[2]); EXPECT_EQ(0, n[2]);
EXPECT_EQ(0, n[3]); EXPECT_EQ(0, n[3]);
} }
// Tests SetArrayArgument<N>(first, last) where *first is convertible // Tests SetArrayArgument<N>(first, last) where *first is convertible
// (but not equal) to the argument type. // (but not equal) to the argument type.
TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) { TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
using MyFunction = void(bool, int*); using MyFunction = void(bool, int*);
char chars[] = { 97, 98, 99 }; char chars[] = {97, 98, 99};
Action<MyFunction> a = SetArrayArgument<1>(chars, chars + 3); Action<MyFunction> a = SetArrayArgument<1>(chars, chars + 3);
int codes[4] = { 111, 222, 333, 444 }; int codes[4] = {111, 222, 333, 444};
int* pcodes = codes; int* pcodes = codes;
a.Perform(std::make_tuple(true, pcodes)); a.Perform(std::make_tuple(true, pcodes));
EXPECT_EQ(97, codes[0]); EXPECT_EQ(97, codes[0]);
EXPECT_EQ(98, codes[1]); EXPECT_EQ(98, codes[1]);
EXPECT_EQ(99, codes[2]); EXPECT_EQ(99, codes[2]);
EXPECT_EQ(444, codes[3]); EXPECT_EQ(444, codes[3]);
} }
// Test SetArrayArgument<N>(first, last) with iterator as argument. // Test SetArrayArgument<N>(first, last) with iterator as argument.
TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) { TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
 End of changes. 13 change blocks. 
19 lines changed or deleted 21 lines changed or added

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