Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
2321b2a6
Commit
2321b2a6
authored
Oct 14, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds action SaveArgPointee.
parent
7dfbea49
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
gmock-more-actions.h
include/gmock/gmock-more-actions.h
+10
-0
gmock-more-actions_test.cc
test/gmock-more-actions_test.cc
+27
-0
No files found.
include/gmock/gmock-more-actions.h
View file @
2321b2a6
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#include <algorithm>
#include "gmock/gmock-generated-actions.h"
#include "gmock/gmock-generated-actions.h"
namespace
testing
{
namespace
testing
{
...
@@ -153,6 +155,14 @@ ACTION_TEMPLATE(SaveArg,
...
@@ -153,6 +155,14 @@ ACTION_TEMPLATE(SaveArg,
*
pointer
=
::
std
::
tr1
::
get
<
k
>
(
args
);
*
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
// Action SetArgReferee<k>(value) assigns 'value' to the variable
// referenced by the k-th (0-based) argument of the mock function.
// referenced by the k-th (0-based) argument of the mock function.
ACTION_TEMPLATE
(
SetArgReferee
,
ACTION_TEMPLATE
(
SetArgReferee
,
...
...
test/gmock-more-actions_test.cc
View file @
2321b2a6
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include <string>
#include <string>
#include "gmock/gmock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-linked_ptr.h"
namespace
testing
{
namespace
testing
{
namespace
gmock_more_actions_test
{
namespace
gmock_more_actions_test
{
...
@@ -59,11 +60,13 @@ using testing::Return;
...
@@ -59,11 +60,13 @@ using testing::Return;
using
testing
::
ReturnArg
;
using
testing
::
ReturnArg
;
using
testing
::
ReturnPointee
;
using
testing
::
ReturnPointee
;
using
testing
::
SaveArg
;
using
testing
::
SaveArg
;
using
testing
::
SaveArgPointee
;
using
testing
::
SetArgReferee
;
using
testing
::
SetArgReferee
;
using
testing
::
StaticAssertTypeEq
;
using
testing
::
StaticAssertTypeEq
;
using
testing
::
Unused
;
using
testing
::
Unused
;
using
testing
::
WithArg
;
using
testing
::
WithArg
;
using
testing
::
WithoutArgs
;
using
testing
::
WithoutArgs
;
using
testing
::
internal
::
linked_ptr
;
// For suppressing compiler warnings on conversion possibly losing precision.
// For suppressing compiler warnings on conversion possibly losing precision.
inline
short
Short
(
short
n
)
{
return
n
;
}
// NOLINT
inline
short
Short
(
short
n
)
{
return
n
;
}
// NOLINT
...
@@ -506,6 +509,30 @@ TEST(SaveArgActionTest, WorksForCompatibleType) {
...
@@ -506,6 +509,30 @@ TEST(SaveArgActionTest, WorksForCompatibleType) {
EXPECT_EQ
(
'a'
,
result
);
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
)
{
TEST
(
SetArgRefereeActionTest
,
WorksForSameType
)
{
int
value
=
0
;
int
value
=
0
;
const
Action
<
void
(
int
&
)
>
a1
=
SetArgReferee
<
0
>
(
1
);
const
Action
<
void
(
int
&
)
>
a1
=
SetArgReferee
<
0
>
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment