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_util.h"
9 #include "remoting/base/capabilities.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 struct HasCapabilityTestData {
15 const char* capabilities;
20 struct IntersectTestData {
30 TEST(CapabilitiesTest, Empty) {
31 // Expect that nothing can be found in an empty set.
32 EXPECT_FALSE(HasCapability("", "a"));
33 EXPECT_FALSE(HasCapability(" ", "a"));
34 EXPECT_FALSE(HasCapability(" ", "a"));
36 // Expect that nothing can be found in an empty set, event when the key is
38 EXPECT_FALSE(HasCapability("", ""));
39 EXPECT_FALSE(HasCapability(" ", ""));
40 EXPECT_FALSE(HasCapability(" ", ""));
43 TEST(CapabilitiesTest, HasCapability) {
44 HasCapabilityTestData data[] = {
50 { "a a", "z", false },
54 { "a b", "z", false },
55 { "a b c", "", false },
56 { "a b c", "a", true },
57 { "a b c", "b", true },
58 { "a b c", "z", false }
61 // Verify that HasCapability(|capabilities|, |key|) returns |result|.
63 for (size_t i = 0; i < arraysize(data); ++i) {
64 std::vector<std::string> caps;
65 Tokenize(data[i].capabilities, " ", &caps);
68 EXPECT_EQ(HasCapability(JoinString(caps, " "), data[i].key),
70 } while (std::next_permutation(caps.begin(), caps.end()));
74 TEST(CapabilitiesTest, Intersect) {
75 EXPECT_EQ(IntersectCapabilities("a", "a"), "a");
77 IntersectTestData data[] = {
86 { "a b c", "a", "a" },
87 { "a b c", "b", "b" },
88 { "a b c", "a b", "a b" },
89 { "a b c", "b a", "a b" },
93 // Verify that intersection of |right| with all permutations of |left| yields
95 for (size_t i = 0; i < arraysize(data); ++i) {
96 std::vector<std::string> caps;
97 Tokenize(data[i].left, " ", &caps);
100 EXPECT_EQ(IntersectCapabilities(JoinString(caps, " "), data[i].right),
102 } while (std::next_permutation(caps.begin(), caps.end()));
106 } // namespace remoting