1 // Copyright (C) 2011 The Libphonenumber Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Author: Tao Huang
16 //
17 // Basic test cases for PhoneNumberMatch.
18
19 #include "phonenumbers/phonenumber.h"
20 #include "phonenumbers/phonenumbermatch.h"
21
22 #include <gtest/gtest.h>
23
24 #include "phonenumbers/phonenumber.pb.h"
25
26 namespace i18n {
27 namespace phonenumbers {
28
TEST(PhoneNumberMatch,TestGetterMethods)29 TEST(PhoneNumberMatch, TestGetterMethods) {
30 PhoneNumber number;
31 const int start_index = 10;
32 const string raw_phone_number("1 800 234 45 67");
33 PhoneNumberMatch match1(start_index, raw_phone_number, number);
34
35 EXPECT_EQ(start_index, match1.start());
36 EXPECT_EQ(start_index + static_cast<int>(raw_phone_number.length()),
37 match1.end());
38 EXPECT_EQ(static_cast<int>(raw_phone_number.length()), match1.length());
39 EXPECT_EQ(raw_phone_number, match1.raw_string());
40
41 EXPECT_EQ("PhoneNumberMatch [10,25) 1 800 234 45 67", match1.ToString());
42 }
43
TEST(PhoneNumberMatch,TestEquals)44 TEST(PhoneNumberMatch, TestEquals) {
45 PhoneNumber number;
46 PhoneNumberMatch match1(10, "1 800 234 45 67", number);
47 PhoneNumberMatch match2(10, "1 800 234 45 67", number);
48
49 match2.set_start(11);
50 ASSERT_FALSE(match1.Equals(match2));
51 match2.set_start(match1.start());
52 EXPECT_TRUE(match1.Equals(match2));
53
54 PhoneNumber number2;
55 number2.set_raw_input("123");
56 match2.set_number(number2);
57 ASSERT_FALSE(match1.Equals(match2));
58 match2.set_number(match1.number());
59 EXPECT_TRUE(ExactlySameAs(match1.number(), match2.number()));
60 EXPECT_TRUE(match1.Equals(match2));
61
62 match2.set_raw_string("123");
63 ASSERT_FALSE(match1.Equals(match2));
64 }
65
TEST(PhoneNumberMatch,TestAssignmentOverload)66 TEST(PhoneNumberMatch, TestAssignmentOverload) {
67 PhoneNumber number;
68 PhoneNumberMatch match1(10, "1 800 234 45 67", number);
69 PhoneNumberMatch match2;
70 ASSERT_FALSE(match1.Equals(match2));
71
72 match2.CopyFrom(match1);
73 ASSERT_TRUE(match1.Equals(match2));
74
75 PhoneNumberMatch match3;
76 PhoneNumberMatch match4;
77 match4.CopyFrom(match2);
78 match3.CopyFrom(match2);
79 ASSERT_TRUE(match3.Equals(match4));
80 ASSERT_TRUE(match4.Equals(match2));
81 }
82
TEST(PhoneNumberMatch,TestCopyConstructor)83 TEST(PhoneNumberMatch, TestCopyConstructor) {
84 PhoneNumber number;
85 PhoneNumberMatch match1(10, "1 800 234 45 67", number);
86 PhoneNumberMatch match2;
87 match2.CopyFrom(match1);
88 ASSERT_TRUE(match1.Equals(match2));
89 }
90
91 } // namespace phonenumbers
92 } // namespace i18n
93