Index: third_party/libaddressinput/chromium/trie_unittest.cc |
diff --git a/third_party/libaddressinput/chromium/cpp/test/util/trie_test.cc b/third_party/libaddressinput/chromium/trie_unittest.cc |
similarity index 50% |
copy from third_party/libaddressinput/chromium/cpp/test/util/trie_test.cc |
copy to third_party/libaddressinput/chromium/trie_unittest.cc |
index 0baa0b4fb8c4a50c34861a2e3b187c9e67ecde17..32b0bb1d3ab93b35523075a221f1559927c21c18 100644 |
--- a/third_party/libaddressinput/chromium/cpp/test/util/trie_test.cc |
+++ b/third_party/libaddressinput/chromium/trie_unittest.cc |
@@ -1,41 +1,39 @@ |
-// Copyright (C) 2014 Google Inc. |
-// |
-// Licensed under the Apache License, Version 2.0 (the "License"); |
-// you may not use this file except in compliance with the License. |
-// You may obtain a copy of the License at |
-// |
-// http://www.apache.org/licenses/LICENSE-2.0 |
-// |
-// Unless required by applicable law or agreed to in writing, software |
-// distributed under the License is distributed on an "AS IS" BASIS, |
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
-// See the License for the specific language governing permissions and |
-// limitations under the License. |
- |
-#include "util/trie.h" |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+#include "third_party/libaddressinput/chromium/trie.h" |
+ |
+#include <stdint.h> |
#include <set> |
#include <string> |
-#include <gtest/gtest.h> |
+#include "testing/gtest/include/gtest/gtest.h" |
-namespace i18n { |
-namespace addressinput { |
+namespace autofill { |
namespace { |
+std::vector<uint8_t> ToByteArray(const std::string& text) { |
+ std::vector<uint8_t> result(text.length() + 1, 0); |
+ result.assign(text.begin(), text.end()); |
+ return result; |
+} |
+ |
+} // namespace |
+ |
TEST(TrieTest, EmptyTrieHasNoData) { |
Trie<std::string> trie; |
std::set<std::string> result; |
- trie.FindDataForKeyPrefix("key", &result); |
+ trie.FindDataForKeyPrefix(ToByteArray("key"), &result); |
EXPECT_TRUE(result.empty()); |
} |
TEST(TrieTest, CanGetDataByExactKey) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
std::set<std::string> result; |
- trie.FindDataForKeyPrefix("hello", &result); |
+ trie.FindDataForKeyPrefix(ToByteArray("hello"), &result); |
std::set<std::string> expected; |
expected.insert("world"); |
EXPECT_EQ(expected, result); |
@@ -43,9 +41,9 @@ TEST(TrieTest, CanGetDataByExactKey) { |
TEST(TrieTest, CanGetDataByPrefix) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
std::set<std::string> result; |
- trie.FindDataForKeyPrefix("he", &result); |
+ trie.FindDataForKeyPrefix(ToByteArray("he"), &result); |
std::set<std::string> expected; |
expected.insert("world"); |
EXPECT_EQ(expected, result); |
@@ -53,19 +51,19 @@ TEST(TrieTest, CanGetDataByPrefix) { |
TEST(TrieTest, KeyTooLongNoData) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
std::set<std::string> result; |
- trie.FindDataForKeyPrefix("helloo", &result); |
+ trie.FindDataForKeyPrefix(ToByteArray("helloo"), &result); |
EXPECT_TRUE(result.empty()); |
} |
TEST(TrieTest, CommonPrefixFindsMultipleData) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
- trie.AddDataForKey("howdy", "buddy"); |
- trie.AddDataForKey("foo", "bar"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
+ trie.AddDataForKey(ToByteArray("howdy"), "buddy"); |
+ trie.AddDataForKey(ToByteArray("foo"), "bar"); |
std::set<std::string> results; |
- trie.FindDataForKeyPrefix("h", &results); |
+ trie.FindDataForKeyPrefix(ToByteArray("h"), &results); |
std::set<std::string> expected; |
expected.insert("world"); |
expected.insert("buddy"); |
@@ -74,11 +72,11 @@ TEST(TrieTest, CommonPrefixFindsMultipleData) { |
TEST(TrieTest, KeyCanBePrefixOfOtherKey) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
- trie.AddDataForKey("helloo", "woorld"); |
- trie.AddDataForKey("hella", "warld"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
+ trie.AddDataForKey(ToByteArray("helloo"), "woorld"); |
+ trie.AddDataForKey(ToByteArray("hella"), "warld"); |
std::set<std::string> results; |
- trie.FindDataForKeyPrefix("hello", &results); |
+ trie.FindDataForKeyPrefix(ToByteArray("hello"), &results); |
std::set<std::string> expected; |
expected.insert("world"); |
expected.insert("woorld"); |
@@ -87,10 +85,10 @@ TEST(TrieTest, KeyCanBePrefixOfOtherKey) { |
TEST(TrieTest, AllowMutlipleKeys) { |
Trie<std::string> trie; |
- trie.AddDataForKey("hello", "world"); |
- trie.AddDataForKey("hello", "woorld"); |
+ trie.AddDataForKey(ToByteArray("hello"), "world"); |
+ trie.AddDataForKey(ToByteArray("hello"), "woorld"); |
std::set<std::string> results; |
- trie.FindDataForKeyPrefix("hello", &results); |
+ trie.FindDataForKeyPrefix(ToByteArray("hello"), &results); |
std::set<std::string> expected; |
expected.insert("world"); |
expected.insert("woorld"); |
@@ -100,15 +98,12 @@ TEST(TrieTest, AllowMutlipleKeys) { |
TEST(TrieTest, CanFindVeryLongKey) { |
Trie<std::string> trie; |
static const char kVeryLongKey[] = "1234567890qwertyuioasdfghj"; |
- trie.AddDataForKey(kVeryLongKey, "world"); |
+ trie.AddDataForKey(ToByteArray(kVeryLongKey), "world"); |
std::set<std::string> result; |
- trie.FindDataForKeyPrefix(kVeryLongKey, &result); |
+ trie.FindDataForKeyPrefix(ToByteArray(kVeryLongKey), &result); |
std::set<std::string> expected; |
expected.insert("world"); |
EXPECT_EQ(expected, result); |
} |
-} // namespace |
- |
-} // namespace addressinput |
-} // namespace i18n |
+} // namespace autofill |