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
9b704069
Commit
9b704069
authored
Aug 15, 2019
by
Gennadiy Civil
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2399 from kuzkry:custom-type-traits-is_same
PiperOrigin-RevId: 263568712
parents
6aba4a5c
ec49fbca
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
33 additions
and
56 deletions
+33
-56
gmock-spec-builders.h
googlemock/include/gmock/gmock-spec-builders.h
+3
-3
gmock-internal-utils.h
googlemock/include/gmock/internal/gmock-internal-utils.h
+0
-4
gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+6
-12
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+1
-1
gtest-matchers.h
googletest/include/gtest/gtest-matchers.h
+7
-5
gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+3
-3
gtest-port.h
googletest/include/gtest/internal/gtest-port.h
+0
-16
googletest-output-test_.cc
googletest/test/googletest-output-test_.cc
+4
-4
gtest-typed-test_test.cc
googletest/test/gtest-typed-test_test.cc
+9
-8
No files found.
googlemock/include/gmock/gmock-spec-builders.h
View file @
9b704069
...
...
@@ -67,6 +67,7 @@
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "gmock/gmock-actions.h"
...
...
@@ -1653,9 +1654,8 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase {
const
OnCallSpec
<
F
>*
const
spec
=
FindOnCallSpec
(
args
);
if
(
spec
==
nullptr
)
{
*
os
<<
(
internal
::
type_equals
<
Result
,
void
>::
value
?
"returning directly.
\n
"
:
"returning default value.
\n
"
);
*
os
<<
(
std
::
is_void
<
Result
>::
value
?
"returning directly.
\n
"
:
"returning default value.
\n
"
);
}
else
{
*
os
<<
"taking default action specified at:
\n
"
<<
FormatFileLocation
(
spec
->
file
(),
spec
->
line
())
<<
"
\n
"
;
...
...
googlemock/include/gmock/internal/gmock-internal-utils.h
View file @
9b704069
...
...
@@ -359,10 +359,6 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers();
template
<
typename
T
>
struct
is_reference
:
public
false_type
{};
template
<
typename
T
>
struct
is_reference
<
T
&>
:
public
true_type
{};
// type_equals<T1, T2>::value is non-zero if T1 and T2 are the same type.
template
<
typename
T1
,
typename
T2
>
struct
type_equals
:
public
false_type
{};
template
<
typename
T
>
struct
type_equals
<
T
,
T
>
:
public
true_type
{};
// remove_reference<T>::type removes the reference from type T, if any.
template
<
typename
T
>
struct
remove_reference
{
typedef
T
type
;
};
// NOLINT
template
<
typename
T
>
struct
remove_reference
<
T
&>
{
typedef
T
type
;
};
// NOLINT
...
...
googlemock/test/gmock-internal-utils_test.cc
View file @
9b704069
...
...
@@ -38,6 +38,7 @@
#include <memory>
#include <string>
#include <sstream>
#include <type_traits>
#include <vector>
#include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h"
...
...
@@ -518,19 +519,12 @@ TEST(TypeTraitsTest, is_reference) {
EXPECT_TRUE
(
is_reference
<
const
int
&>::
value
);
}
TEST
(
TypeTraitsTest
,
type_equals
)
{
EXPECT_FALSE
((
type_equals
<
int
,
const
int
>::
value
));
EXPECT_FALSE
((
type_equals
<
int
,
int
&>::
value
));
EXPECT_FALSE
((
type_equals
<
int
,
double
>::
value
));
EXPECT_TRUE
((
type_equals
<
char
,
char
>::
value
));
}
TEST
(
TypeTraitsTest
,
remove_reference
)
{
EXPECT_TRUE
((
type_equals
<
char
,
remove_reference
<
char
&>::
type
>::
value
));
EXPECT_TRUE
(
(
type_equals
<
const
int
,
remove_reference
<
const
int
&>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
int
,
remove_reference
<
int
>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
char
,
remove_reference
<
char
&>::
type
>::
value
));
EXPECT_TRUE
(
(
std
::
is_same
<
const
int
,
remove_reference
<
const
int
&>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
int
,
remove_reference
<
int
>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
}
#if GTEST_HAS_STREAM_REDIRECTION
...
...
googlemock/test/gmock-matchers_test.cc
View file @
9b704069
...
...
@@ -6434,7 +6434,7 @@ class SampleVariantIntString {
template
<
typename
T
>
friend
bool
holds_alternative
(
const
SampleVariantIntString
&
value
)
{
return
value
.
has_int_
==
internal
::
IsS
ame
<
T
,
int
>::
value
;
return
value
.
has_int_
==
std
::
is_s
ame
<
T
,
int
>::
value
;
}
template
<
typename
T
>
...
...
googletest/include/gtest/gtest-matchers.h
View file @
9b704069
...
...
@@ -42,6 +42,7 @@
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>
#include "gtest/gtest-printers.h"
#include "gtest/internal/gtest-internal.h"
...
...
@@ -299,8 +300,8 @@ class MatcherBase {
template
<
typename
U
>
explicit
MatcherBase
(
const
MatcherInterface
<
U
>*
impl
,
typename
internal
::
EnableIf
<
!
internal
::
IsSame
<
U
,
const
U
&>::
value
>::
type
*
=
nullptr
)
typename
internal
::
EnableIf
<
!
std
::
is_same
<
U
,
const
U
&>::
value
>::
type
*
=
nullptr
)
:
impl_
(
new
internal
::
MatcherInterfaceAdapter
<
U
>
(
impl
))
{}
MatcherBase
(
const
MatcherBase
&
)
=
default
;
...
...
@@ -333,9 +334,10 @@ class Matcher : public internal::MatcherBase<T> {
:
internal
::
MatcherBase
<
T
>
(
impl
)
{}
template
<
typename
U
>
explicit
Matcher
(
const
MatcherInterface
<
U
>*
impl
,
typename
internal
::
EnableIf
<
!
internal
::
IsSame
<
U
,
const
U
&>::
value
>::
type
*
=
nullptr
)
explicit
Matcher
(
const
MatcherInterface
<
U
>*
impl
,
typename
internal
::
EnableIf
<!
std
::
is_same
<
U
,
const
U
&>::
value
>::
type
*
=
nullptr
)
:
internal
::
MatcherBase
<
T
>
(
impl
)
{}
// Implicit constructor here allows people to write
...
...
googletest/include/gtest/internal/gtest-internal.h
View file @
9b704069
...
...
@@ -977,9 +977,9 @@ template <typename C>
struct
IsRecursiveContainerImpl
<
C
,
true
>
{
using
value_type
=
decltype
(
*
std
::
declval
<
typename
C
::
const_iterator
>
());
using
type
=
is_same
<
typename
std
::
remove_const
<
typename
std
::
remove_reference
<
value_type
>::
type
>::
type
,
C
>
;
std
::
is_same
<
typename
std
::
remove_const
<
typename
std
::
remove_reference
<
value_type
>::
type
>::
type
,
C
>
;
};
// IsRecursiveContainer<Type> is a unary compile-time predicate that
...
...
googletest/include/gtest/internal/gtest-port.h
View file @
9b704069
...
...
@@ -869,16 +869,6 @@ struct StaticAssertTypeEqHelper<T, T> {
enum
{
value
=
true
};
};
// Same as std::is_same<>.
template
<
typename
T
,
typename
U
>
struct
IsSame
{
enum
{
value
=
false
};
};
template
<
typename
T
>
struct
IsSame
<
T
,
T
>
{
enum
{
value
=
true
};
};
// Evaluates to the number of elements in 'array'.
#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
...
...
@@ -1931,12 +1921,6 @@ template <bool bool_value> const bool bool_constant<bool_value>::value;
typedef
bool_constant
<
false
>
false_type
;
typedef
bool_constant
<
true
>
true_type
;
template
<
typename
T
,
typename
U
>
struct
is_same
:
public
false_type
{};
template
<
typename
T
>
struct
is_same
<
T
,
T
>
:
public
true_type
{};
template
<
typename
Iterator
>
struct
IteratorTraits
{
typedef
typename
Iterator
::
value_type
value_type
;
...
...
googletest/test/googletest-output-test_.cc
View file @
9b704069
...
...
@@ -816,9 +816,9 @@ class TypedTestNames {
public
:
template
<
typename
T
>
static
std
::
string
GetName
(
int
i
)
{
if
(
testing
::
internal
::
IsS
ame
<
T
,
char
>::
value
)
if
(
std
::
is_s
ame
<
T
,
char
>::
value
)
return
std
::
string
(
"char"
)
+
::
testing
::
PrintToString
(
i
);
if
(
testing
::
internal
::
IsS
ame
<
T
,
int
>::
value
)
if
(
std
::
is_s
ame
<
T
,
int
>::
value
)
return
std
::
string
(
"int"
)
+
::
testing
::
PrintToString
(
i
);
}
};
...
...
@@ -857,10 +857,10 @@ class TypedTestPNames {
public
:
template
<
typename
T
>
static
std
::
string
GetName
(
int
i
)
{
if
(
testing
::
internal
::
IsS
ame
<
T
,
unsigned
char
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
unsigned
char
>::
value
)
{
return
std
::
string
(
"unsignedChar"
)
+
::
testing
::
PrintToString
(
i
);
}
if
(
testing
::
internal
::
IsS
ame
<
T
,
unsigned
int
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
unsigned
int
>::
value
)
{
return
std
::
string
(
"unsignedInt"
)
+
::
testing
::
PrintToString
(
i
);
}
}
...
...
googletest/test/gtest-typed-test_test.cc
View file @
9b704069
...
...
@@ -31,6 +31,7 @@
#include "test/gtest-typed-test_test.h"
#include <set>
#include <type_traits>
#include <vector>
#include "gtest/gtest.h"
...
...
@@ -177,10 +178,10 @@ class TypedTestNames {
public
:
template
<
typename
T
>
static
std
::
string
GetName
(
int
i
)
{
if
(
testing
::
internal
::
IsS
ame
<
T
,
char
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
char
>::
value
)
{
return
std
::
string
(
"char"
)
+
::
testing
::
PrintToString
(
i
);
}
if
(
testing
::
internal
::
IsS
ame
<
T
,
int
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
int
>::
value
)
{
return
std
::
string
(
"int"
)
+
::
testing
::
PrintToString
(
i
);
}
}
...
...
@@ -189,13 +190,13 @@ class TypedTestNames {
TYPED_TEST_SUITE
(
TypedTestWithNames
,
TwoTypes
,
TypedTestNames
);
TYPED_TEST
(
TypedTestWithNames
,
TestSuiteName
)
{
if
(
testing
::
internal
::
IsS
ame
<
TypeParam
,
char
>::
value
)
{
if
(
std
::
is_s
ame
<
TypeParam
,
char
>::
value
)
{
EXPECT_STREQ
(
::
testing
::
UnitTest
::
GetInstance
()
->
current_test_info
()
->
test_case_name
(),
"TypedTestWithNames/char0"
);
}
if
(
testing
::
internal
::
IsS
ame
<
TypeParam
,
int
>::
value
)
{
if
(
std
::
is_s
ame
<
TypeParam
,
int
>::
value
)
{
EXPECT_STREQ
(
::
testing
::
UnitTest
::
GetInstance
()
->
current_test_info
()
->
test_case_name
(),
...
...
@@ -311,13 +312,13 @@ class TypeParametrizedTestWithNames : public Test {};
TYPED_TEST_SUITE_P
(
TypeParametrizedTestWithNames
);
TYPED_TEST_P
(
TypeParametrizedTestWithNames
,
TestSuiteName
)
{
if
(
testing
::
internal
::
IsS
ame
<
TypeParam
,
char
>::
value
)
{
if
(
std
::
is_s
ame
<
TypeParam
,
char
>::
value
)
{
EXPECT_STREQ
(
::
testing
::
UnitTest
::
GetInstance
()
->
current_test_info
()
->
test_case_name
(),
"CustomName/TypeParametrizedTestWithNames/parChar0"
);
}
if
(
testing
::
internal
::
IsS
ame
<
TypeParam
,
int
>::
value
)
{
if
(
std
::
is_s
ame
<
TypeParam
,
int
>::
value
)
{
EXPECT_STREQ
(
::
testing
::
UnitTest
::
GetInstance
()
->
current_test_info
()
->
test_case_name
(),
...
...
@@ -331,10 +332,10 @@ class TypeParametrizedTestNames {
public
:
template
<
typename
T
>
static
std
::
string
GetName
(
int
i
)
{
if
(
testing
::
internal
::
IsS
ame
<
T
,
char
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
char
>::
value
)
{
return
std
::
string
(
"parChar"
)
+
::
testing
::
PrintToString
(
i
);
}
if
(
testing
::
internal
::
IsS
ame
<
T
,
int
>::
value
)
{
if
(
std
::
is_s
ame
<
T
,
int
>::
value
)
{
return
std
::
string
(
"parInt"
)
+
::
testing
::
PrintToString
(
i
);
}
}
...
...
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