diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 21:20:15 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 21:20:15 +0000 |
commit | 9b435be91a7f625b984dc4a49bee1f3c43cd6f87 (patch) | |
tree | 4be834f1a88aef4ba9ff356615043b97e4ee9442 /chrome/browser/autofill/phone_number_unittest.cc | |
parent | e0b421291b0644eebf04660d993995e638251bf0 (diff) | |
download | chromium_src-9b435be91a7f625b984dc4a49bee1f3c43cd6f87.zip chromium_src-9b435be91a7f625b984dc4a49bee1f3c43cd6f87.tar.gz chromium_src-9b435be91a7f625b984dc4a49bee1f3c43cd6f87.tar.bz2 |
AutoFill phone number parser changes.
Moved the PersonalDataManager::ParsePhoneNumber() method into the PhoneNumber class. Made some bug fixes to the parser. Extended its functionality to strip separator characters. Added unit tests to cover the parser.
BUG=none
TEST=PhoneNumberTest
Review URL: http://codereview.chromium.org/669026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/phone_number_unittest.cc')
-rw-r--r-- | chrome/browser/autofill/phone_number_unittest.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/autofill/phone_number_unittest.cc b/chrome/browser/autofill/phone_number_unittest.cc new file mode 100644 index 0000000..878031f --- /dev/null +++ b/chrome/browser/autofill/phone_number_unittest.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2010 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 "chrome/browser/autofill/phone_number.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +// Tests the phone number parser. +TEST(PhoneNumberTest, Parser) { + string16 number; + string16 city_code; + string16 country_code; + + // Test for empty string. Should give back empty strings. + string16 phone0; + PhoneNumber::ParsePhoneNumber(phone0, &number, &city_code, &country_code); + EXPECT_EQ(string16(), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with less than 7 digits. Should give back empty strings. + string16 phone1(ASCIIToUTF16("1234")); + PhoneNumber::ParsePhoneNumber(phone1, &number, &city_code, &country_code); + EXPECT_EQ(string16(), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with exactly 7 digits. Should give back only phone number. + string16 phone2(ASCIIToUTF16("1234567")); + PhoneNumber::ParsePhoneNumber(phone2, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("1234567"), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with exactly 7 digits and separators. Should give back + // only phone number. + string16 phone_separator2(ASCIIToUTF16("123-4567")); + PhoneNumber::ParsePhoneNumber(phone_separator2, + &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("1234567"), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with greater than 7 digits but less than 10 digits. + // Should give back only phone number. + string16 phone3(ASCIIToUTF16("123456789")); + PhoneNumber::ParsePhoneNumber(phone3, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("3456789"), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with greater than 7 digits but less than 10 digits and + // separators. + // Should give back only phone number. + string16 phone_separator3(ASCIIToUTF16("12.345-6789")); + PhoneNumber::ParsePhoneNumber(phone3, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("3456789"), number); + EXPECT_EQ(string16(), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with exactly 10 digits. + // Should give back phone number and city code. + string16 phone4(ASCIIToUTF16("1234567890")); + PhoneNumber::ParsePhoneNumber(phone4, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("4567890"), number); + EXPECT_EQ(ASCIIToUTF16("123"), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with exactly 10 digits and separators. + // Should give back phone number and city code. + string16 phone_separator4(ASCIIToUTF16("(123) 456-7890")); + PhoneNumber::ParsePhoneNumber(phone_separator4, + &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("4567890"), number); + EXPECT_EQ(ASCIIToUTF16("123"), city_code); + EXPECT_EQ(string16(), country_code); + + // Test for string with over 10 digits. + // Should give back phone number, city code, and country code. + string16 phone5(ASCIIToUTF16("011234567890")); + PhoneNumber::ParsePhoneNumber(phone5, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("4567890"), number); + EXPECT_EQ(ASCIIToUTF16("123"), city_code); + EXPECT_EQ(ASCIIToUTF16("01"), country_code); + + // Test for string with over 10 digits with separator characters. + // Should give back phone number, city code, and country code. + string16 phone6(ASCIIToUTF16("(01) 123-456.7890")); + PhoneNumber::ParsePhoneNumber(phone6, &number, &city_code, &country_code); + EXPECT_EQ(ASCIIToUTF16("4567890"), number); + EXPECT_EQ(ASCIIToUTF16("123"), city_code); + EXPECT_EQ(ASCIIToUTF16("01"), country_code); +} + +} // namespace + |