| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/history/snippet.h" | 5 #include "chrome/browser/history/snippet.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // A sample document to compute snippets of. | 14 // A sample document to compute snippets of. |
| 15 // The \x bits after the first "Google" are UTF-8 of U+2122 TRADE MARK SIGN, | 15 // The \x bits after the first "Google" are UTF-8 of U+2122 TRADE MARK SIGN, |
| 16 // and are useful for verifying we don't screw up in UTF-8/UTF-16 conversion. | 16 // and are useful for verifying we don't screw up in UTF-8/UTF-16 conversion. |
| 17 const char* kSampleDocument = "Google\xe2\x84\xa2 Terms of Service " | 17 const char* kSampleDocument = "Google\xe2\x84\xa2 Terms of Service " |
| 18 "Welcome to Google! " | 18 "Welcome to Google! " |
| 19 "1. Your relationship with Google " | 19 "1. Your relationship with Google " |
| 20 "1.1 Your use of Google's products, software, services and web sites " | 20 "1.1 Your use of Google's products, software, services and web sites " |
| 21 "(referred to collectively as the \"Services\" in this document and excluding " | 21 "(referred to collectively as the \"Services\" in this document and excluding " |
| 22 "any services provided to you by Google under a separate written agreement) " | 22 "any services provided to you by Google under a separate written agreement) " |
| 23 "is subject to the terms of a legal agreement between you and Google. " | 23 "is subject to the terms of a legal agreement between you and Google. " |
| 24 "\"Google\" means Google Inc., whose principal place of business is at 1600 " | 24 "\"Google\" means Google Inc., whose principal place of business is at 1600 " |
| 25 "Amphitheatre Parkway, Mountain View, CA 94043, United States. This document " | 25 "Amphitheatre Parkway, Mountain View, CA 94043, United States. This document " |
| 26 "explains how the agreement is made up, and sets out some of the terms of " | 26 "explains how the agreement is made up, and sets out some of the terms of " |
| 27 "that agreement."; | 27 "that agreement."; |
| 28 | |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 // Thai sample taken from http://www.google.co.th/intl/th/privacy.html | 30 // Thai sample taken from http://www.google.co.th/intl/th/privacy.html |
| 32 // TODO(jungshik) : Add more samples (e.g. Hindi) after porting | 31 // TODO(jungshik) : Add more samples (e.g. Hindi) after porting |
| 33 // ICU 4.0's character iterator changes to our copy of ICU 3.8 to get | 32 // ICU 4.0's character iterator changes to our copy of ICU 3.8 to get |
| 34 // grapheme clusters in Indic scripts handled more reasonably. | 33 // grapheme clusters in Indic scripts handled more reasonably. |
| 35 const char* kThaiSample = "Google \xE0\xB9\x80\xE0\xB8\x81\xE0\xB9\x87" | 34 const char* kThaiSample = "Google \xE0\xB9\x80\xE0\xB8\x81\xE0\xB9\x87" |
| 36 "\xE0\xB8\x9A\xE0\xB8\xA3\xE0\xB8\xA7\xE0\xB8\x9A\xE0\xB8\xA3\xE0\xB8\xA7" | 35 "\xE0\xB8\x9A\xE0\xB8\xA3\xE0\xB8\xA7\xE0\xB8\x9A\xE0\xB8\xA3\xE0\xB8\xA7" |
| 37 "\xE0\xB8\xA1 \xE0\xB8\x82\xE0\xB9\x89\xE0\xB8\xAD\xE0\xB8\xA1\xE0\xB8\xB9" | 36 "\xE0\xB8\xA1 \xE0\xB8\x82\xE0\xB9\x89\xE0\xB8\xAD\xE0\xB8\xA1\xE0\xB8\xB9" |
| 38 "\xE0\xB8\xA5\xE0\xB8\xAA\xE0\xB9\x88\xE0\xB8\xA7\xE0\xB8\x99\xE0\xB8\x9A" | 37 "\xE0\xB8\xA5\xE0\xB8\xAA\xE0\xB9\x88\xE0\xB8\xA7\xE0\xB8\x99\xE0\xB8\x9A" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 WideToUTF8(BuildSnippet(kThaiSample, | 220 WideToUTF8(BuildSnippet(kThaiSample, |
| 222 "\xE0\xB9\x83\xE0\xB8\xAB\xE0\xB9\x89"))); | 221 "\xE0\xB9\x83\xE0\xB8\xAB\xE0\xB9\x89"))); |
| 223 } | 222 } |
| 224 | 223 |
| 225 TEST(Snippets, ExtractMatchPositions) { | 224 TEST(Snippets, ExtractMatchPositions) { |
| 226 struct TestData { | 225 struct TestData { |
| 227 const std::string offsets_string; | 226 const std::string offsets_string; |
| 228 const size_t expected_match_count; | 227 const size_t expected_match_count; |
| 229 const size_t expected_matches[10]; | 228 const size_t expected_matches[10]; |
| 230 } data[] = { | 229 } data[] = { |
| 231 { "0 0 1 2 0 0 4 1 0 0 1 5", 1, { 1,6 } }, | 230 { "0 0 1 2 0 0 4 1 0 0 1 5", 1, { 1, 6 } }, |
| 232 { "0 0 1 4 0 0 2 1", 1, { 1,5 } }, | 231 { "0 0 1 4 0 0 2 1", 1, { 1, 5 } }, |
| 233 { "0 0 4 1 0 0 2 1", 2, { 2,3, 4,5 } }, | 232 { "0 0 4 1 0 0 2 1", 2, { 2, 3, 4, 5 } }, |
| 234 { "0 0 0 1", 1, { 0,1 } }, | 233 { "0 0 0 1", 1, { 0, 1 } }, |
| 235 { "0 0 0 1 0 0 0 2", 1, { 0,2 } }, | 234 { "0 0 0 1 0 0 0 2", 1, { 0, 2 } }, |
| 236 { "0 0 1 1 0 0 1 2", 1, { 1,3 } }, | 235 { "0 0 1 1 0 0 1 2", 1, { 1, 3 } }, |
| 237 { "0 0 1 2 0 0 4 3 0 0 3 1", 1, { 1,7 } }, | 236 { "0 0 1 2 0 0 4 3 0 0 3 1", 1, { 1, 7 } }, |
| 238 { "0 0 1 4 0 0 2 5", 1, { 1,7 } }, | 237 { "0 0 1 4 0 0 2 5", 1, { 1, 7 } }, |
| 239 { "0 0 1 2 0 0 1 1", 1, { 1,3 } }, | 238 { "0 0 1 2 0 0 1 1", 1, { 1, 3 } }, |
| 240 { "0 0 1 1 0 0 5 2 0 0 10 1 0 0 3 10", 2, { 1,2, 3,13 } }, | 239 { "0 0 1 1 0 0 5 2 0 0 10 1 0 0 3 10", 2, { 1, 2, 3, 13 } }, |
| 241 }; | 240 }; |
| 242 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 241 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 243 Snippet::MatchPositions matches; | 242 Snippet::MatchPositions matches; |
| 244 Snippet::ExtractMatchPositions(data[i].offsets_string, "0", &matches); | 243 Snippet::ExtractMatchPositions(data[i].offsets_string, "0", &matches); |
| 245 EXPECT_EQ(data[i].expected_match_count, matches.size()); | 244 EXPECT_EQ(data[i].expected_match_count, matches.size()); |
| 246 for (size_t j = 0; j < data[i].expected_match_count; ++j) { | 245 for (size_t j = 0; j < data[i].expected_match_count; ++j) { |
| 247 EXPECT_EQ(data[i].expected_matches[2 * j], matches[j].first); | 246 EXPECT_EQ(data[i].expected_matches[2 * j], matches[j].first); |
| 248 EXPECT_EQ(data[i].expected_matches[2 * j + 1], matches[j].second); | 247 EXPECT_EQ(data[i].expected_matches[2 * j + 1], matches[j].second); |
| 249 } | 248 } |
| 250 } | 249 } |
| 251 } | 250 } |
| OLD | NEW |