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
06678924
Commit
06678924
authored
Jul 28, 2014
by
kosak
Browse files
Allows {Unordered,}ElementsAreArray() to accept any STL-style container as the parameter.
parent
a9e02a91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
11 deletions
+37
-11
include/gmock/gmock-matchers.h
include/gmock/gmock-matchers.h
+11
-10
test/gmock-matchers_test.cc
test/gmock-matchers_test.cc
+26
-1
No files found.
include/gmock/gmock-matchers.h
View file @
06678924
...
@@ -3444,7 +3444,7 @@ GTEST_API_ string FormatMatcherDescription(bool negation,
...
@@ -3444,7 +3444,7 @@ GTEST_API_ string FormatMatcherDescription(bool negation,
// ElementsAreArray(first, last)
// ElementsAreArray(first, last)
// ElementsAreArray(pointer, count)
// ElementsAreArray(pointer, count)
// ElementsAreArray(array)
// ElementsAreArray(array)
// ElementsAreArray(
vecto
r)
// ElementsAreArray(
containe
r)
// ElementsAreArray({ e1, e2, ..., en })
// ElementsAreArray({ e1, e2, ..., en })
//
//
// The ElementsAreArray() functions are like ElementsAre(...), except
// The ElementsAreArray() functions are like ElementsAre(...), except
...
@@ -3476,10 +3476,10 @@ inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
...
@@ -3476,10 +3476,10 @@ inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
return
ElementsAreArray
(
array
,
N
);
return
ElementsAreArray
(
array
,
N
);
}
}
template
<
typename
T
,
typename
A
>
template
<
typename
Container
>
inline
internal
::
ElementsAreArrayMatcher
<
T
>
ElementsAreArray
(
inline
internal
::
ElementsAreArrayMatcher
<
typename
Container
::
value_type
>
const
::
std
::
vector
<
T
,
A
>&
vec
)
{
ElementsAreArray
(
const
Container
&
container
)
{
return
ElementsAreArray
(
vec
.
begin
(),
vec
.
end
());
return
ElementsAreArray
(
container
.
begin
(),
container
.
end
());
}
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
#if GTEST_HAS_STD_INITIALIZER_LIST_
...
@@ -3493,7 +3493,7 @@ ElementsAreArray(::std::initializer_list<T> xs) {
...
@@ -3493,7 +3493,7 @@ ElementsAreArray(::std::initializer_list<T> xs) {
// UnorderedElementsAreArray(first, last)
// UnorderedElementsAreArray(first, last)
// UnorderedElementsAreArray(pointer, count)
// UnorderedElementsAreArray(pointer, count)
// UnorderedElementsAreArray(array)
// UnorderedElementsAreArray(array)
// UnorderedElementsAreArray(
vecto
r)
// UnorderedElementsAreArray(
containe
r)
// UnorderedElementsAreArray({ e1, e2, ..., en })
// UnorderedElementsAreArray({ e1, e2, ..., en })
//
//
// The UnorderedElementsAreArray() functions are like
// The UnorderedElementsAreArray() functions are like
...
@@ -3518,10 +3518,11 @@ UnorderedElementsAreArray(const T (&array)[N]) {
...
@@ -3518,10 +3518,11 @@ UnorderedElementsAreArray(const T (&array)[N]) {
return
UnorderedElementsAreArray
(
array
,
N
);
return
UnorderedElementsAreArray
(
array
,
N
);
}
}
template
<
typename
T
,
typename
A
>
template
<
typename
Container
>
inline
internal
::
UnorderedElementsAreArrayMatcher
<
T
>
inline
internal
::
UnorderedElementsAreArrayMatcher
<
UnorderedElementsAreArray
(
const
::
std
::
vector
<
T
,
A
>&
vec
)
{
typename
Container
::
value_type
>
return
UnorderedElementsAreArray
(
vec
.
begin
(),
vec
.
end
());
UnorderedElementsAreArray
(
const
Container
&
container
)
{
return
UnorderedElementsAreArray
(
container
.
begin
(),
container
.
end
());
}
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
#if GTEST_HAS_STD_INITIALIZER_LIST_
...
...
test/gmock-matchers_test.cc
View file @
06678924
...
@@ -4651,6 +4651,19 @@ TEST(ElementsAreTest, WorksWithUncopyable) {
...
@@ -4651,6 +4651,19 @@ TEST(ElementsAreTest, WorksWithUncopyable) {
EXPECT_THAT
(
objs
,
ElementsAre
(
UncopyableIs
(
-
3
),
Truly
(
ValueIsPositive
)));
EXPECT_THAT
(
objs
,
ElementsAre
(
UncopyableIs
(
-
3
),
Truly
(
ValueIsPositive
)));
}
}
TEST
(
ElementsAreTest
,
TakesStlContainer
)
{
const
int
actual
[]
=
{
3
,
1
,
2
};
::
std
::
list
<
int
>
expected
;
expected
.
push_back
(
3
);
expected
.
push_back
(
1
);
expected
.
push_back
(
2
);
EXPECT_THAT
(
actual
,
ElementsAreArray
(
expected
));
expected
.
push_back
(
4
);
EXPECT_THAT
(
actual
,
Not
(
ElementsAreArray
(
expected
)));
}
// Tests for UnorderedElementsAreArray()
// Tests for UnorderedElementsAreArray()
TEST
(
UnorderedElementsAreArrayTest
,
SucceedsWhenExpected
)
{
TEST
(
UnorderedElementsAreArrayTest
,
SucceedsWhenExpected
)
{
...
@@ -4692,6 +4705,19 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
...
@@ -4692,6 +4705,19 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
EXPECT_THAT
(
s
,
Not
(
UnorderedElementsAreArray
(
expected
)));
EXPECT_THAT
(
s
,
Not
(
UnorderedElementsAreArray
(
expected
)));
}
}
TEST
(
UnorderedElementsAreArrayTest
,
TakesStlContainer
)
{
const
int
actual
[]
=
{
3
,
1
,
2
};
::
std
::
list
<
int
>
expected
;
expected
.
push_back
(
1
);
expected
.
push_back
(
2
);
expected
.
push_back
(
3
);
EXPECT_THAT
(
actual
,
UnorderedElementsAreArray
(
expected
));
expected
.
push_back
(
4
);
EXPECT_THAT
(
actual
,
Not
(
UnorderedElementsAreArray
(
expected
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerList
)
{
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerList
)
{
...
@@ -5464,4 +5490,3 @@ TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
...
@@ -5464,4 +5490,3 @@ TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
}
// namespace gmock_matchers_test
}
// namespace gmock_matchers_test
}
// namespace testing
}
// namespace testing
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