"Rewrite" PhoneNumberUtil so that it compares two phone strings using as many characters as possible, unlike the previous implementation.
Unlike the change 5480, this considers the NDD-problem mentioned in the internal issue 1949010.
This time, 1-650-555-1234 and 650-555-1234 match each other.

Added tests for the cases.

related internal issue: 1868702, 1949010
diff --git a/android/PhoneNumberUtilsTest.cpp b/android/PhoneNumberUtilsTest.cpp
new file mode 100644
index 0000000..6772fe5
--- /dev/null
+++ b/android/PhoneNumberUtilsTest.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * 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.
+ */
+/*
+ * Note that similar (or almost same) tests exist in Java side (See
+ * DatabaseGeneralTest.java in AndroidTests). The differences are:
+ * - this test is quite easy to do (You can do it in your Unix PC)
+ * - this test is not automatically executed by build servers
+ *
+ * You should also execute the test before submitting this.
+ */
+
+#include "PhoneNumberUtils.h"
+
+#include <stdio.h>
+#include <string.h>
+
+using namespace android;
+
+#define EXPECT(function, input1, input2, expected, total, error)        \
+    ({                                                                  \
+        const char *i1_cache = input1;                                  \
+        const char *i2_cache = input2;                                  \
+        (total)++;                                                      \
+        if ((expected) != (function)((i1_cache), (i2_cache))) {         \
+            if (expected) {                                             \
+                printf("%s != %s while we expect %s == %s\n",           \
+                       (i1_cache), (i2_cache), (i1_cache), (i2_cache)); \
+            } else {                                                    \
+                printf("%s == %s while we expect %s != %s\n",           \
+                       (i1_cache), (i2_cache), (i1_cache), (i2_cache)); \
+            }                                                           \
+            (error)++;                                                  \
+        }                                                               \
+    })
+
+#define EXPECT_EQ(input1, input2)                                       \
+    EXPECT(phone_number_compare, (input1), (input2), true,              \
+           (total), (error))
+
+
+#define EXPECT_NE(input1, input2)                                       \
+    EXPECT(phone_number_compare, (input1), (input2), false,             \
+           (total), (error))
+
+int main() {
+    int total = 0;
+    int error = 0;
+
+    EXPECT_EQ(NULL, NULL);
+    EXPECT_EQ("", NULL);
+    EXPECT_EQ(NULL, "");
+    EXPECT_EQ("", "");
+
+    EXPECT_EQ("999", "999");
+    EXPECT_EQ("119", "119");
+
+    EXPECT_NE("123456789", "923456789");
+    EXPECT_NE("123456789", "123456781");
+    EXPECT_NE("123456789", "1234567890");
+    EXPECT_NE("123456789", "0123456789");
+
+    // Google, Inc.
+    EXPECT_EQ("650-253-0000", "6502530000");
+    EXPECT_EQ("650-253-0000", "650 253 0000");
+    EXPECT_EQ("650 253 0000", "6502530000");
+
+    // trunk (NDD) prefix must be properly handled in US
+    EXPECT_EQ("650-253-0000", "1-650-253-0000");
+    EXPECT_EQ("650-253-0000", "   1-650-253-0000");
+    EXPECT_NE("650-253-0000", "11-650-253-0000");
+    EXPECT_NE("650-253-0000", "0-650-253-0000");
+
+    EXPECT_EQ("+1 650-253-0000", "6502530000");
+    EXPECT_EQ("001 650-253-0000", "6502530000");
+    EXPECT_EQ("0111 650-253-0000", "6502530000");
+
+    // Country code is different.
+    EXPECT_NE("+19012345678", "+819012345678");
+
+    // Russian trunk digit
+    EXPECT_EQ("+79161234567", "89161234567");
+
+    // French trunk digit
+    EXPECT_EQ("+33123456789", "0123456789");
+
+    // Trunk digit for city codes in the Netherlands
+    EXPECT_EQ("+31771234567", "0771234567");
+
+    // Japanese dial
+    EXPECT_EQ("090-1234-5678", "+819012345678");
+    EXPECT_EQ("090(1234)5678", "+819012345678");
+    EXPECT_EQ("090-1234-5678", "+81-90-1234-5678");
+
+    // Trunk prefix must not be ignored in Japan
+    EXPECT_NE("090-1234-5678", "90-1234-5678");
+
+    EXPECT_NE("090-1234-5678", "080-1234-5678");
+    EXPECT_NE("090-1234-5678", "190-1234-5678");
+    EXPECT_NE("090-1234-5678", "890-1234-5678");
+    EXPECT_NE("+81-90-1234-5678", "+81-090-1234-5678");
+
+    EXPECT_EQ("+593(800)123-1234", "8001231234");
+
+    // Two continuous 0 at the beginieng of the phone string should not be
+    // treated as trunk prefix.
+    EXPECT_NE("008001231234", "8001231234");
+
+    // Test broken caller ID seen on call from Thailand to the US
+    EXPECT_EQ("+66811234567", "166811234567");
+
+    // Confirm that the bug found before does not re-appear.
+    EXPECT_NE("080-1234-5678", "+819012345678");
+
+    // Currently we cannot get this test through (Japanese trunk prefix is 0,
+    // but there is no sensible way to know it now (as of 2009-6-12)...
+    // EXPECT_NE("290-1234-5678", "+819012345678");
+
+    printf("total: %d, error: %d\n\n", total, error);
+    if (error == 0) {
+        printf("Success!\n");
+    } else {
+        printf("Failure... :(\n");
+    }
+}