Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / base / capabilities_unittest.cc
blob90c12a0785088aa2c54745fea44bde7c6c17309e
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.
5 #include <algorithm>
6 #include <vector>
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"
13 namespace {
15 struct HasCapabilityTestData {
16 const char* capabilities;
17 const char* key;
18 bool result;
21 struct IntersectTestData {
22 const char* left;
23 const char* right;
24 const char* result;
27 } // namespace
29 namespace remoting {
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
38 // empty.
39 EXPECT_FALSE(HasCapability("", ""));
40 EXPECT_FALSE(HasCapability(" ", ""));
41 EXPECT_FALSE(HasCapability(" ", ""));
44 TEST(CapabilitiesTest, HasCapability) {
45 HasCapabilityTestData data[] = {
46 { "", "", false },
47 { "a", "", false },
48 { "a", "a", true },
49 { "a a", "", false },
50 { "a a", "a", true },
51 { "a a", "z", false },
52 { "a b", "", false },
53 { "a b", "a", true },
54 { "a b", "b", true },
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|.
63 // |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);
68 do {
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[] = {
79 { "", "", "" },
80 { "a", "", "" },
81 { "a", "a", "a" },
82 { "a", "b", "" },
83 { "a b", "", "" },
84 { "a b", "a", "a" },
85 { "a b", "b", "b" },
86 { "a b", "z", "" },
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" },
91 { "a b c", "z", "" }
94 // Verify that intersection of |right| with all permutations of |left| yields
95 // |result|.
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);
99 do {
100 EXPECT_EQ(data[i].result,
101 IntersectCapabilities(base::JoinString(caps, " "),
102 data[i].right));
103 } while (std::next_permutation(caps.begin(), caps.end()));
107 } // namespace remoting