Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
32c84be0
Unverified
Commit
32c84be0
authored
May 22, 2018
by
Gennadiy Civil
Committed by
GitHub
May 22, 2018
Browse files
Merge branch 'master' into unused-variable-fuchsia
parents
f91bf75c
8276dbae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
10 deletions
+65
-10
googlemock/include/gmock/gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+4
-4
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+2
-4
googletest/include/gtest/internal/gtest-type-util.h
googletest/include/gtest/internal/gtest-type-util.h
+17
-1
googletest/include/gtest/internal/gtest-type-util.h.pump
googletest/include/gtest/internal/gtest-type-util.h.pump
+17
-1
googletest/test/gtest_unittest.cc
googletest/test/gtest_unittest.cc
+25
-0
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
32c84be0
...
...
@@ -2371,6 +2371,7 @@ class PointeeMatcher {
GTEST_DISALLOW_ASSIGN_
(
PointeeMatcher
);
};
#if GTEST_HAS_RTTI
// Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
// reference that matches inner_matcher when dynamic_cast<T> is applied.
// The result of dynamic_cast<To> is forwarded to the inner matcher.
...
...
@@ -2397,11 +2398,7 @@ class WhenDynamicCastToMatcherBase {
const
Matcher
<
To
>
matcher_
;
static
std
::
string
GetToName
()
{
#if GTEST_HAS_RTTI
return
GetTypeName
<
To
>
();
#else // GTEST_HAS_RTTI
return
"the target type"
;
#endif // GTEST_HAS_RTTI
}
private:
...
...
@@ -2447,6 +2444,7 @@ class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
return
MatchPrintAndExplain
(
*
to
,
this
->
matcher_
,
listener
);
}
};
#endif // GTEST_HAS_RTTI
// Implements the Field() matcher for matching a field (i.e. member
// variable) of an object.
...
...
@@ -4441,6 +4439,7 @@ inline internal::PointeeMatcher<InnerMatcher> Pointee(
return
internal
::
PointeeMatcher
<
InnerMatcher
>
(
inner_matcher
);
}
#if GTEST_HAS_RTTI
// Creates a matcher that matches a pointer or reference that matches
// inner_matcher when dynamic_cast<To> is applied.
// The result of dynamic_cast<To> is forwarded to the inner matcher.
...
...
@@ -4453,6 +4452,7 @@ WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
return
MakePolymorphicMatcher
(
internal
::
WhenDynamicCastToMatcher
<
To
>
(
inner_matcher
));
}
#endif // GTEST_HAS_RTTI
// Creates a matcher that matches an object whose given field matches
// 'matcher'. For example,
...
...
googlemock/test/gmock-matchers_test.cc
View file @
32c84be0
...
...
@@ -3704,6 +3704,7 @@ MATCHER_P(FieldIIs, inner_matcher, "") {
return
ExplainMatchResult
(
inner_matcher
,
arg
.
i
,
result_listener
);
}
#if GTEST_HAS_RTTI
TEST
(
WhenDynamicCastToTest
,
SameType
)
{
Derived
derived
;
derived
.
i
=
4
;
...
...
@@ -3761,12 +3762,8 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) {
TEST
(
WhenDynamicCastToTest
,
Describe
)
{
Matcher
<
Base
*>
matcher
=
WhenDynamicCastTo
<
Derived
*>
(
Pointee
(
_
));
#if GTEST_HAS_RTTI
const
std
::
string
prefix
=
"when dynamic_cast to "
+
internal
::
GetTypeName
<
Derived
*>
()
+
", "
;
#else // GTEST_HAS_RTTI
const
std
::
string
prefix
=
"when dynamic_cast, "
;
#endif // GTEST_HAS_RTTI
EXPECT_EQ
(
prefix
+
"points to a value that is anything"
,
Describe
(
matcher
));
EXPECT_EQ
(
prefix
+
"does not point to a value that is anything"
,
DescribeNegation
(
matcher
));
...
...
@@ -3799,6 +3796,7 @@ TEST(WhenDynamicCastToTest, BadReference) {
Base
&
as_base_ref
=
derived
;
EXPECT_THAT
(
as_base_ref
,
Not
(
WhenDynamicCastTo
<
const
OtherDerived
&>
(
_
)));
}
#endif // GTEST_HAS_RTTI
// Minimal const-propagating pointer.
template
<
typename
T
>
...
...
googletest/include/gtest/internal/gtest-type-util.h
View file @
32c84be0
...
...
@@ -56,6 +56,22 @@
namespace
testing
{
namespace
internal
{
// Canonicalizes a given name with respect to the Standard C++ Library.
// This handles removing the inline namespace within `std` that is
// used by various standard libraries (e.g., `std::__1`). Names outside
// of namespace std are returned unmodified.
inline
std
::
string
CanonicalizeForStdLibVersioning
(
std
::
string
s
)
{
static
const
char
prefix
[]
=
"std::__"
;
if
(
s
.
compare
(
0
,
strlen
(
prefix
),
prefix
)
==
0
)
{
std
::
string
::
size_type
end
=
s
.
find
(
"::"
,
strlen
(
prefix
));
if
(
end
!=
s
.
npos
)
{
// Erase everything between the initial `std` and the second `::`.
s
.
erase
(
strlen
(
"std"
),
end
-
strlen
(
"std"
));
}
}
return
s
;
}
// GetTypeName<T>() returns a human-readable name of type T.
// NB: This function is also used in Google Mock, so don't move it inside of
...
...
@@ -75,7 +91,7 @@ std::string GetTypeName() {
char
*
const
readable_name
=
__cxa_demangle
(
name
,
0
,
0
,
&
status
);
const
std
::
string
name_str
(
status
==
0
?
readable_name
:
name
);
free
(
readable_name
);
return
name_str
;
return
CanonicalizeForStdLibVersioning
(
name_str
)
;
# else
return
name
;
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
...
...
googletest/include/gtest/internal/gtest-type-util.h.pump
View file @
32c84be0
...
...
@@ -54,6 +54,22 @@ $var n = 50 $$ Maximum length of type lists we want to support.
namespace
testing
{
namespace
internal
{
// Canonicalizes a given name with respect to the Standard C++ Library.
// This handles removing the inline namespace within `std` that is
// used by various standard libraries (e.g., `std::__1`). Names outside
// of namespace std are returned unmodified.
inline
std
::
string
CanonicalizeForStdLibVersioning
(
std
::
string
s
)
{
static
const
char
prefix
[]
=
"std::__"
;
if
(
s
.
compare
(
0
,
strlen
(
prefix
),
prefix
)
==
0
)
{
std
::
string
::
size_type
end
=
s
.
find
(
"::"
,
strlen
(
prefix
));
if
(
end
!=
s
.
npos
)
{
// Erase everything between the initial `std` and the second `::`.
s
.
erase
(
strlen
(
"std"
),
end
-
strlen
(
"std"
));
}
}
return
s
;
}
// GetTypeName<T>() returns a human-readable name of type T.
// NB: This function is also used in Google Mock, so don't move it inside of
...
...
@@ -73,7 +89,7 @@ std::string GetTypeName() {
char
*
const
readable_name
=
__cxa_demangle
(
name
,
0
,
0
,
&
status
);
const
std
::
string
name_str
(
status
==
0
?
readable_name
:
name
);
free
(
readable_name
);
return
name_str
;
return
CanonicalizeForStdLibVersioning
(
name_str
)
;
# else
return
name
;
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
...
...
googletest/test/gtest_unittest.cc
View file @
32c84be0
...
...
@@ -380,6 +380,31 @@ TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
EXPECT_EQ
(
kTestTypeIdInGoogleTest
,
GetTestTypeId
());
}
// Tests CanonicalizeForStdLibVersioning.
using
::
testing
::
internal
::
CanonicalizeForStdLibVersioning
;
TEST
(
CanonicalizeForStdLibVersioning
,
LeavesUnversionedNamesUnchanged
)
{
EXPECT_EQ
(
"std::bind"
,
CanonicalizeForStdLibVersioning
(
"std::bind"
));
EXPECT_EQ
(
"std::_"
,
CanonicalizeForStdLibVersioning
(
"std::_"
));
EXPECT_EQ
(
"std::__foo"
,
CanonicalizeForStdLibVersioning
(
"std::__foo"
));
EXPECT_EQ
(
"gtl::__1::x"
,
CanonicalizeForStdLibVersioning
(
"gtl::__1::x"
));
EXPECT_EQ
(
"__1::x"
,
CanonicalizeForStdLibVersioning
(
"__1::x"
));
EXPECT_EQ
(
"::__1::x"
,
CanonicalizeForStdLibVersioning
(
"::__1::x"
));
}
TEST
(
CanonicalizeForStdLibVersioning
,
ElidesDoubleUnderNames
)
{
EXPECT_EQ
(
"std::bind"
,
CanonicalizeForStdLibVersioning
(
"std::__1::bind"
));
EXPECT_EQ
(
"std::_"
,
CanonicalizeForStdLibVersioning
(
"std::__1::_"
));
EXPECT_EQ
(
"std::bind"
,
CanonicalizeForStdLibVersioning
(
"std::__g::bind"
));
EXPECT_EQ
(
"std::_"
,
CanonicalizeForStdLibVersioning
(
"std::__g::_"
));
EXPECT_EQ
(
"std::bind"
,
CanonicalizeForStdLibVersioning
(
"std::__google::bind"
));
EXPECT_EQ
(
"std::_"
,
CanonicalizeForStdLibVersioning
(
"std::__google::_"
));
}
// Tests FormatTimeInMillisAsSeconds().
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsZero
)
{
...
...
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