summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2010-10-14 06:51:27 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2010-10-14 06:51:27 +0000
commitd567f690a1e82a2fcac554096c614b876e9ed04f (patch)
tree0e4466573cd7a188dc37658acc7b2653f2e67db7
parent6c1df9c6e722ea062c76507e98f22db45d4af400 (diff)
downloadgooglemock-d567f690a1e82a2fcac554096c614b876e9ed04f.tar.gz
Adds action SaveArgPointee.
git-svn-id: http://googlemock.googlecode.com/svn/trunk@344 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-more-actions.h10
-rw-r--r--test/gmock-more-actions_test.cc27
2 files changed, 37 insertions, 0 deletions
diff --git a/include/gmock/gmock-more-actions.h b/include/gmock/gmock-more-actions.h
index e418505..a547a64 100644
--- a/include/gmock/gmock-more-actions.h
+++ b/include/gmock/gmock-more-actions.h
@@ -36,6 +36,8 @@
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
+#include <algorithm>
+
#include "gmock/gmock-generated-actions.h"
namespace testing {
@@ -153,6 +155,14 @@ ACTION_TEMPLATE(SaveArg,
*pointer = ::std::tr1::get<k>(args);
}
+// Action SaveArgPointee<k>(pointer) saves the value pointed to
+// by the k-th (0-based) argument of the mock function to *pointer.
+ACTION_TEMPLATE(SaveArgPointee,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(pointer)) {
+ *pointer = *::std::tr1::get<k>(args);
+}
+
// Action SetArgReferee<k>(value) assigns 'value' to the variable
// referenced by the k-th (0-based) argument of the mock function.
ACTION_TEMPLATE(SetArgReferee,
diff --git a/test/gmock-more-actions_test.cc b/test/gmock-more-actions_test.cc
index 64c4e08..43ff55d 100644
--- a/test/gmock-more-actions_test.cc
+++ b/test/gmock-more-actions_test.cc
@@ -40,6 +40,7 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+#include "gtest/internal/gtest-linked_ptr.h"
namespace testing {
namespace gmock_more_actions_test {
@@ -59,11 +60,13 @@ using testing::Return;
using testing::ReturnArg;
using testing::ReturnPointee;
using testing::SaveArg;
+using testing::SaveArgPointee;
using testing::SetArgReferee;
using testing::StaticAssertTypeEq;
using testing::Unused;
using testing::WithArg;
using testing::WithoutArgs;
+using testing::internal::linked_ptr;
// For suppressing compiler warnings on conversion possibly losing precision.
inline short Short(short n) { return n; } // NOLINT
@@ -506,6 +509,30 @@ TEST(SaveArgActionTest, WorksForCompatibleType) {
EXPECT_EQ('a', result);
}
+TEST(SaveArgPointeeActionTest, WorksForSameType) {
+ int result = 0;
+ const int value = 5;
+ const Action<void(const int*)> a1 = SaveArgPointee<0>(&result);
+ a1.Perform(make_tuple(&value));
+ EXPECT_EQ(5, result);
+}
+
+TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
+ int result = 0;
+ char value = 'a';
+ const Action<void(bool, char*)> a1 = SaveArgPointee<1>(&result);
+ a1.Perform(make_tuple(true, &value));
+ EXPECT_EQ('a', result);
+}
+
+TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) {
+ int result = 0;
+ linked_ptr<int> value(new int(5));
+ const Action<void(linked_ptr<int>)> a1 = SaveArgPointee<0>(&result);
+ a1.Perform(make_tuple(value));
+ EXPECT_EQ(5, result);
+}
+
TEST(SetArgRefereeActionTest, WorksForSameType) {
int value = 0;
const Action<void(int&)> a1 = SetArgReferee<0>(1);