blob: 34456524a56658d17a80e1c18e9f6371a2bda8e6 [file] [log] [blame]
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +09001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/*
17 * Note that similar (or almost same) tests exist in Java side (See
18 * DatabaseGeneralTest.java in AndroidTests). The differences are:
19 * - this test is quite easy to do (You can do it in your Unix PC)
20 * - this test is not automatically executed by build servers
21 *
22 * You should also execute the test before submitting this.
23 */
24
25#include "PhoneNumberUtils.h"
26
27#include <stdio.h>
28#include <string.h>
29
30using namespace android;
31
32#define EXPECT(function, input1, input2, expected, total, error) \
33 ({ \
34 const char *i1_cache = input1; \
35 const char *i2_cache = input2; \
36 (total)++; \
37 if ((expected) != (function)((i1_cache), (i2_cache))) { \
38 if (expected) { \
39 printf("%s != %s while we expect %s == %s\n", \
40 (i1_cache), (i2_cache), (i1_cache), (i2_cache)); \
41 } else { \
42 printf("%s == %s while we expect %s != %s\n", \
43 (i1_cache), (i2_cache), (i1_cache), (i2_cache)); \
44 } \
45 (error)++; \
46 } \
47 })
48
49#define EXPECT_EQ(input1, input2) \
Daisuke Miyakawa948a1192009-09-19 19:19:53 -070050 EXPECT(phone_number_compare_strict, (input1), (input2), true, \
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +090051 (total), (error))
52
53
54#define EXPECT_NE(input1, input2) \
Daisuke Miyakawa948a1192009-09-19 19:19:53 -070055 EXPECT(phone_number_compare_strict, (input1), (input2), false, \
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +090056 (total), (error))
57
58int main() {
59 int total = 0;
60 int error = 0;
61
62 EXPECT_EQ(NULL, NULL);
63 EXPECT_EQ("", NULL);
64 EXPECT_EQ(NULL, "");
65 EXPECT_EQ("", "");
66
67 EXPECT_EQ("999", "999");
68 EXPECT_EQ("119", "119");
69
70 EXPECT_NE("123456789", "923456789");
71 EXPECT_NE("123456789", "123456781");
72 EXPECT_NE("123456789", "1234567890");
73 EXPECT_NE("123456789", "0123456789");
74
75 // Google, Inc.
76 EXPECT_EQ("650-253-0000", "6502530000");
77 EXPECT_EQ("650-253-0000", "650 253 0000");
78 EXPECT_EQ("650 253 0000", "6502530000");
79
80 // trunk (NDD) prefix must be properly handled in US
81 EXPECT_EQ("650-253-0000", "1-650-253-0000");
82 EXPECT_EQ("650-253-0000", " 1-650-253-0000");
83 EXPECT_NE("650-253-0000", "11-650-253-0000");
84 EXPECT_NE("650-253-0000", "0-650-253-0000");
Wei Huang468ecb92009-09-21 10:16:24 -070085 EXPECT_NE("555-4141", "+1-700-555-4141");
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +090086
87 EXPECT_EQ("+1 650-253-0000", "6502530000");
88 EXPECT_EQ("001 650-253-0000", "6502530000");
89 EXPECT_EQ("0111 650-253-0000", "6502530000");
90
91 // Country code is different.
92 EXPECT_NE("+19012345678", "+819012345678");
93
94 // Russian trunk digit
95 EXPECT_EQ("+79161234567", "89161234567");
96
97 // French trunk digit
98 EXPECT_EQ("+33123456789", "0123456789");
99
100 // Trunk digit for city codes in the Netherlands
101 EXPECT_EQ("+31771234567", "0771234567");
102
103 // Japanese dial
104 EXPECT_EQ("090-1234-5678", "+819012345678");
105 EXPECT_EQ("090(1234)5678", "+819012345678");
106 EXPECT_EQ("090-1234-5678", "+81-90-1234-5678");
107
108 // Trunk prefix must not be ignored in Japan
109 EXPECT_NE("090-1234-5678", "90-1234-5678");
110
111 EXPECT_NE("090-1234-5678", "080-1234-5678");
112 EXPECT_NE("090-1234-5678", "190-1234-5678");
113 EXPECT_NE("090-1234-5678", "890-1234-5678");
114 EXPECT_NE("+81-90-1234-5678", "+81-090-1234-5678");
115
116 EXPECT_EQ("+593(800)123-1234", "8001231234");
117
118 // Two continuous 0 at the beginieng of the phone string should not be
119 // treated as trunk prefix.
120 EXPECT_NE("008001231234", "8001231234");
121
122 // Test broken caller ID seen on call from Thailand to the US
123 EXPECT_EQ("+66811234567", "166811234567");
124
125 // Confirm that the bug found before does not re-appear.
126 EXPECT_NE("080-1234-5678", "+819012345678");
Daisuke Miyakawacfdd4a72009-07-20 18:28:54 -0700127 EXPECT_EQ("650-000-3456", "16500003456");
Daisuke Miyakawab3b8a9d2009-09-01 22:07:18 +0900128 EXPECT_EQ("011 1 7005554141", "+17005554141");
129 EXPECT_NE("011 11 7005554141", "+17005554141");
130 EXPECT_NE("+44 207 792 3490", "00 207 792 3490");
131 // This is not related to Thailand case. NAMP "1" + region code "661".
Daisuke Miyakawab020ccd2009-07-20 19:05:06 -0700132 EXPECT_EQ("16610001234", "6610001234");
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +0900133
Wei Huang0d04c4c2009-08-31 19:18:23 -0700134 // We also need to compare two alpha addresses to make sure two different strings
135 // aren't treated as the same addresses. This is relevant to SMS as SMS sender may
136 // contain all alpha chars.
137 EXPECT_NE("abcd", "bcde");
138
139 // in the U.S. people often use alpha in the phone number to easily remember it
140 // (e.g. 800-flowers would be dialed as 800-356-9377). Since we accept this form of
141 // phone number in Contacts and others, we should make sure the comparison method
142 // handle them.
143 EXPECT_EQ("1-800-flowers", "800-flowers");
144
145 // TODO: we currently do not support this comparison. It maybe nice to support this
146 // TODO: in the future.
147 // EXPECT_EQ("1-800-flowers", "1-800-356-9377")
148
149 EXPECT_NE("1-800-flowers", "1-800-abcdefg");
150
Daisuke Miyakawaf06f5fa2009-07-07 11:11:34 +0900151 // Currently we cannot get this test through (Japanese trunk prefix is 0,
152 // but there is no sensible way to know it now (as of 2009-6-12)...
153 // EXPECT_NE("290-1234-5678", "+819012345678");
154
155 printf("total: %d, error: %d\n\n", total, error);
156 if (error == 0) {
157 printf("Success!\n");
158 } else {
159 printf("Failure... :(\n");
160 }
161}