1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h"
10 #include "remoting/base/capabilities.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 struct HasCapabilityTestData
{
16 const char* capabilities
;
21 struct IntersectTestData
{
31 TEST(CapabilitiesTest
, Empty
) {
32 // Expect that nothing can be found in an empty set.
33 EXPECT_FALSE(HasCapability("", "a"));
34 EXPECT_FALSE(HasCapability(" ", "a"));
35 EXPECT_FALSE(HasCapability(" ", "a"));
37 // Expect that nothing can be found in an empty set, event when the key is
39 EXPECT_FALSE(HasCapability("", ""));
40 EXPECT_FALSE(HasCapability(" ", ""));
41 EXPECT_FALSE(HasCapability(" ", ""));
44 TEST(CapabilitiesTest
, HasCapability
) {
45 HasCapabilityTestData data
[] = {
51 { "a a", "z", false },
55 { "a b", "z", false },
56 { "a b c", "", false },
57 { "a b c", "a", true },
58 { "a b c", "b", true },
59 { "a b c", "z", false }
62 // Verify that HasCapability(|capabilities|, |key|) returns |result|.
64 for (size_t i
= 0; i
< arraysize(data
); ++i
) {
65 std::vector
<std::string
> caps
= base::SplitString(
66 data
[i
].capabilities
, " ", base::KEEP_WHITESPACE
,
67 base::SPLIT_WANT_NONEMPTY
);
69 EXPECT_EQ(data
[i
].result
,
70 HasCapability(base::JoinString(caps
, " "), data
[i
].key
));
71 } while (std::next_permutation(caps
.begin(), caps
.end()));
75 TEST(CapabilitiesTest
, Intersect
) {
76 EXPECT_EQ(IntersectCapabilities("a", "a"), "a");
78 IntersectTestData data
[] = {
87 { "a b c", "a", "a" },
88 { "a b c", "b", "b" },
89 { "a b c", "a b", "a b" },
90 { "a b c", "b a", "a b" },
94 // Verify that intersection of |right| with all permutations of |left| yields
96 for (size_t i
= 0; i
< arraysize(data
); ++i
) {
97 std::vector
<std::string
> caps
= base::SplitString(
98 data
[i
].left
, " ", base::KEEP_WHITESPACE
, base::SPLIT_WANT_NONEMPTY
);
100 EXPECT_EQ(data
[i
].result
,
101 IntersectCapabilities(base::JoinString(caps
, " "),
103 } while (std::next_permutation(caps
.begin(), caps
.end()));
107 } // namespace remoting