| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_piece.h" |
| 11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "remoting/base/capabilities.h" | 14 #include "remoting/base/capabilities.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 struct HasCapabilityTestData { | 19 struct HasCapabilityTestData { |
| 19 const char* capabilities; | 20 const char* capabilities; |
| 20 const char* key; | 21 const char* key; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 { "a b", "z", false }, | 59 { "a b", "z", false }, |
| 59 { "a b c", "", false }, | 60 { "a b c", "", false }, |
| 60 { "a b c", "a", true }, | 61 { "a b c", "a", true }, |
| 61 { "a b c", "b", true }, | 62 { "a b c", "b", true }, |
| 62 { "a b c", "z", false } | 63 { "a b c", "z", false } |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 // Verify that HasCapability(|capabilities|, |key|) returns |result|. | 66 // Verify that HasCapability(|capabilities|, |key|) returns |result|. |
| 66 // |result|. | 67 // |result|. |
| 67 for (size_t i = 0; i < arraysize(data); ++i) { | 68 for (size_t i = 0; i < arraysize(data); ++i) { |
| 68 std::vector<std::string> caps = base::SplitString( | 69 std::vector<base::StringPiece> caps = |
| 69 data[i].capabilities, " ", base::KEEP_WHITESPACE, | 70 base::SplitStringPiece(data[i].capabilities, " ", base::KEEP_WHITESPACE, |
| 70 base::SPLIT_WANT_NONEMPTY); | 71 base::SPLIT_WANT_NONEMPTY); |
| 71 do { | 72 do { |
| 72 EXPECT_EQ(data[i].result, | 73 EXPECT_EQ(data[i].result, |
| 73 HasCapability(base::JoinString(caps, " "), data[i].key)); | 74 HasCapability(base::JoinString(caps, " "), data[i].key)); |
| 74 } while (std::next_permutation(caps.begin(), caps.end())); | 75 } while (std::next_permutation(caps.begin(), caps.end())); |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 78 TEST(CapabilitiesTest, Intersect) { | 79 TEST(CapabilitiesTest, Intersect) { |
| 79 EXPECT_EQ(IntersectCapabilities("a", "a"), "a"); | 80 EXPECT_EQ(IntersectCapabilities("a", "a"), "a"); |
| 80 | 81 |
| 81 IntersectTestData data[] = { | 82 IntersectTestData data[] = { |
| 82 { "", "", "" }, | 83 { "", "", "" }, |
| 83 { "a", "", "" }, | 84 { "a", "", "" }, |
| 84 { "a", "a", "a" }, | 85 { "a", "a", "a" }, |
| 85 { "a", "b", "" }, | 86 { "a", "b", "" }, |
| 86 { "a b", "", "" }, | 87 { "a b", "", "" }, |
| 87 { "a b", "a", "a" }, | 88 { "a b", "a", "a" }, |
| 88 { "a b", "b", "b" }, | 89 { "a b", "b", "b" }, |
| 89 { "a b", "z", "" }, | 90 { "a b", "z", "" }, |
| 90 { "a b c", "a", "a" }, | 91 { "a b c", "a", "a" }, |
| 91 { "a b c", "b", "b" }, | 92 { "a b c", "b", "b" }, |
| 92 { "a b c", "a b", "a b" }, | 93 { "a b c", "a b", "a b" }, |
| 93 { "a b c", "b a", "a b" }, | 94 { "a b c", "b a", "a b" }, |
| 94 { "a b c", "z", "" } | 95 { "a b c", "z", "" } |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 // Verify that intersection of |right| with all permutations of |left| yields | 98 // Verify that intersection of |right| with all permutations of |left| yields |
| 98 // |result|. | 99 // |result|. |
| 99 for (size_t i = 0; i < arraysize(data); ++i) { | 100 for (size_t i = 0; i < arraysize(data); ++i) { |
| 100 std::vector<std::string> caps = base::SplitString( | 101 std::vector<base::StringPiece> caps = base::SplitStringPiece( |
| 101 data[i].left, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 102 data[i].left, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 102 do { | 103 do { |
| 103 EXPECT_EQ(data[i].result, | 104 EXPECT_EQ(data[i].result, |
| 104 IntersectCapabilities(base::JoinString(caps, " "), | 105 IntersectCapabilities(base::JoinString(caps, " "), |
| 105 data[i].right)); | 106 data[i].right)); |
| 106 } while (std::next_permutation(caps.begin(), caps.end())); | 107 } while (std::next_permutation(caps.begin(), caps.end())); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace remoting | 111 } // namespace remoting |
| OLD | NEW |