[Sync] Test Android passphrase creation UI
[chromium-blink-merge.git] / remoting / base / capabilities_unittest.cc
blob162c96d7f5c0b64de854df5d41e70b7718e38a13
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_util.h"
9 #include "remoting/base/capabilities.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace {
14 struct HasCapabilityTestData {
15 const char* capabilities;
16 const char* key;
17 bool result;
20 struct IntersectTestData {
21 const char* left;
22 const char* right;
23 const char* result;
26 } // namespace
28 namespace remoting {
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
37 // empty.
38 EXPECT_FALSE(HasCapability("", ""));
39 EXPECT_FALSE(HasCapability(" ", ""));
40 EXPECT_FALSE(HasCapability(" ", ""));
43 TEST(CapabilitiesTest, HasCapability) {
44 HasCapabilityTestData data[] = {
45 { "", "", false },
46 { "a", "", false },
47 { "a", "a", true },
48 { "a a", "", false },
49 { "a a", "a", true },
50 { "a a", "z", false },
51 { "a b", "", false },
52 { "a b", "a", true },
53 { "a b", "b", true },
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|.
62 // |result|.
63 for (size_t i = 0; i < arraysize(data); ++i) {
64 std::vector<std::string> caps;
65 Tokenize(data[i].capabilities, " ", &caps);
67 do {
68 EXPECT_EQ(data[i].result,
69 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[] = {
78 { "", "", "" },
79 { "a", "", "" },
80 { "a", "a", "a" },
81 { "a", "b", "" },
82 { "a b", "", "" },
83 { "a b", "a", "a" },
84 { "a b", "b", "b" },
85 { "a b", "z", "" },
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" },
90 { "a b c", "z", "" }
93 // Verify that intersection of |right| with all permutations of |left| yields
94 // |result|.
95 for (size_t i = 0; i < arraysize(data); ++i) {
96 std::vector<std::string> caps;
97 Tokenize(data[i].left, " ", &caps);
99 do {
100 EXPECT_EQ(data[i].result,
101 IntersectCapabilities(JoinString(caps, " "), data[i].right));
102 } while (std::next_permutation(caps.begin(), caps.end()));
106 } // namespace remoting