File: phonenumbermatch_test.cc

package info (click to toggle)
libphonenumber 8.12.57%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 99,276 kB
  • sloc: cpp: 52,362; xml: 48,242; javascript: 31,137; java: 29,151; ansic: 482; jsp: 228; sh: 44; makefile: 24
file content (92 lines) | stat: -rw-r--r-- 2,801 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) 2011 The Libphonenumber Authors
//
// 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.
//
// Author: Tao Huang
//
// Basic test cases for PhoneNumberMatch.

#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumbermatch.h"

#include <gtest/gtest.h>

#include "phonenumbers/phonenumber.pb.h"

namespace i18n {
namespace phonenumbers {

TEST(PhoneNumberMatch, TestGetterMethods) {
  PhoneNumber number;
  const int start_index = 10;
  const string raw_phone_number("1 800 234 45 67");
  PhoneNumberMatch match1(start_index, raw_phone_number, number);

  EXPECT_EQ(start_index, match1.start());
  EXPECT_EQ(start_index + static_cast<int>(raw_phone_number.length()),
            match1.end());
  EXPECT_EQ(static_cast<int>(raw_phone_number.length()), match1.length());
  EXPECT_EQ(raw_phone_number, match1.raw_string());

  EXPECT_EQ("PhoneNumberMatch [10,25) 1 800 234 45 67", match1.ToString());
}

TEST(PhoneNumberMatch, TestEquals) {
  PhoneNumber number;
  PhoneNumberMatch match1(10, "1 800 234 45 67", number);
  PhoneNumberMatch match2(10, "1 800 234 45 67", number);

  match2.set_start(11);
  ASSERT_FALSE(match1.Equals(match2));
  match2.set_start(match1.start());
  EXPECT_TRUE(match1.Equals(match2));

  PhoneNumber number2;
  number2.set_raw_input("123");
  match2.set_number(number2);
  ASSERT_FALSE(match1.Equals(match2));
  match2.set_number(match1.number());
  EXPECT_TRUE(ExactlySameAs(match1.number(), match2.number()));
  EXPECT_TRUE(match1.Equals(match2));

  match2.set_raw_string("123");
  ASSERT_FALSE(match1.Equals(match2));
}

TEST(PhoneNumberMatch, TestAssignmentOverload) {
  PhoneNumber number;
  PhoneNumberMatch match1(10, "1 800 234 45 67", number);
  PhoneNumberMatch match2;
  ASSERT_FALSE(match1.Equals(match2));

  match2.CopyFrom(match1);
  ASSERT_TRUE(match1.Equals(match2));

  PhoneNumberMatch match3;
  PhoneNumberMatch match4;
  match4.CopyFrom(match2);
  match3.CopyFrom(match2);
  ASSERT_TRUE(match3.Equals(match4));
  ASSERT_TRUE(match4.Equals(match2));
}

TEST(PhoneNumberMatch, TestCopyConstructor) {
  PhoneNumber number;
  PhoneNumberMatch match1(10, "1 800 234 45 67", number);
  PhoneNumberMatch match2;
  match2.CopyFrom(match1);
  ASSERT_TRUE(match1.Equals(match2));
}

}  // namespace phonenumbers
}  // namespace i18n