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
d0726821
Commit
d0726821
authored
Oct 24, 2019
by
Piotr Nycz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests simplified and names corrected (POD->scalar)
Issue 2527
parent
37590da6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
49 deletions
+18
-49
gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+18
-49
No files found.
googlemock/test/gmock-actions_test.cc
View file @
d0726821
...
@@ -651,65 +651,34 @@ template <typename T, typename = decltype(ReturnRef(std::declval<T&&>()))>
...
@@ -651,65 +651,34 @@ template <typename T, typename = decltype(ReturnRef(std::declval<T&&>()))>
bool
CanCallReturnRef
(
T
&&
)
{
return
true
;
}
bool
CanCallReturnRef
(
T
&&
)
{
return
true
;
}
bool
CanCallReturnRef
(
Unused
)
{
return
false
;
}
bool
CanCallReturnRef
(
Unused
)
{
return
false
;
}
// Defined here, because gmock has to work with C++11 (std::void_t is from C++17)
template
<
typename
...
Ts
>
struct
precpp17_make_void
{
typedef
void
type
;};
template
<
typename
...
Ts
>
using
precpp17_void_t
=
typename
precpp17_make_void
<
Ts
...
>::
type
;
template
<
typename
T
,
typename
=
void
>
struct
HasReturnRefAction
:
std
::
false_type
{};
template
<
typename
T
>
struct
HasReturnRefAction
<
T
,
precpp17_void_t
<
decltype
(
ReturnRef
(
std
::
declval
<
T
>
()))
>>
:
std
::
true_type
{};
// Just an example of non-POD type
class
MyNonPodType
{
public
:
MyNonPodType
(
int
a_value
)
:
value_
(
a_value
)
{}
private
:
int
value_
;
};
// Just an example of POD type
using
MyPodType
=
int
;
// Tests that ReturnRef(v) is working with non-temporaries (T&)
// Tests that ReturnRef(v) is working with non-temporaries (T&)
TEST
(
ReturnRefTest
,
IsAcceptingNonTemporary
)
{
TEST
(
ReturnRefTest
,
WorksForNonTemporary
)
{
EXPECT_TRUE
(
HasReturnRefAction
<
MyPodType
&>::
value
);
int
scalarValue
=
123
;
EXPECT_TRUE
(
HasReturnRefAction
<
const
MyPodType
&>::
value
);
EXPECT_TRUE
(
CanCallReturnRef
(
scalarValue
));
EXPECT_TRUE
(
HasReturnRefAction
<
MyNonPodType
&>::
value
);
EXPECT_TRUE
(
HasReturnRefAction
<
const
MyNonPodType
&>::
value
);
MyNonPodType
nonPodValue
{
123
}
;
std
::
string
nonScalarValue
(
"ABC"
)
;
EXPECT_TRUE
(
CanCallReturnRef
(
non
Pod
Value
));
EXPECT_TRUE
(
CanCallReturnRef
(
non
Scalar
Value
));
MyPodType
pod
Value
{
321
};
const
int
constScalar
Value
{
321
};
EXPECT_TRUE
(
CanCallReturnRef
(
pod
Value
));
EXPECT_TRUE
(
CanCallReturnRef
(
constScalar
Value
));
const
MyNonPodType
constNonPodValue
{
123
};
const
std
::
string
constNonScalarValue
(
"CBA"
);
EXPECT_TRUE
(
CanCallReturnRef
(
constNonPodValue
));
EXPECT_TRUE
(
CanCallReturnRef
(
constNonScalarValue
));
const
MyPodType
constPodValue
{
321
};
EXPECT_TRUE
(
CanCallReturnRef
(
constPodValue
));
}
}
// Tests that ReturnRef(v) is not working with temporaries (T&&)
// Tests that ReturnRef(v) is not working with temporaries (T&&)
TEST
(
ReturnRefTest
,
IsNotAcceptingTemporary
)
{
TEST
(
ReturnRefTest
,
DoesNotWorkForTemporary
)
{
EXPECT_FALSE
(
HasReturnRefAction
<
MyPodType
&&>::
value
);
auto
scalarValue
=
[]()
->
int
{
return
123
;
};
EXPECT_FALSE
(
HasReturnRefAction
<
const
MyPodType
&&>::
value
);
EXPECT_FALSE
(
CanCallReturnRef
(
scalarValue
()));
EXPECT_FALSE
(
HasReturnRefAction
<
MyNonPodType
&&>::
value
);
EXPECT_FALSE
(
HasReturnRefAction
<
const
MyNonPodType
&&>::
value
);
auto
nonPodValue
=
[]()
->
MyNonPodType
{
return
MyNonPodType
{
123
};
};
EXPECT_FALSE
(
CanCallReturnRef
(
nonPodValue
()));
auto
podValue
=
[]()
->
MyPodType
{
return
MyPodType
{
321
}
;
};
auto
nonScalarValue
=
[]()
->
std
::
string
{
return
"ABC"
;
};
EXPECT_FALSE
(
CanCallReturnRef
(
pod
Value
()));
EXPECT_FALSE
(
CanCallReturnRef
(
nonScalar
Value
()));
auto
constNonPodValue
=
[]()
->
const
MyNonPodType
{
return
MyNonPodType
{
123
};
};
// cannot use here callable returning "const scalar type" because C++ ignores such const for scalar return type, so the static_cast
EXPECT_FALSE
(
CanCallReturnRef
(
constNonPodValue
(
)));
EXPECT_FALSE
(
CanCallReturnRef
(
static_cast
<
const
int
>
(
321
)));
// cannot use here callable returning "const POD" because C++ ignores such const for POD return type, so the static_cast
auto
constNonScalarValue
=
[]()
->
const
std
::
string
{
return
"CBA"
;
};
EXPECT_FALSE
(
CanCallReturnRef
(
static_cast
<
const
MyPodType
>
(
42
)));
EXPECT_FALSE
(
CanCallReturnRef
(
constNonScalarValue
(
)));
}
}
// Tests that ReturnRefOfCopy(v) works for reference types.
// Tests that ReturnRefOfCopy(v) works for reference types.
...
...
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