Test eccdata directly without loading repository.

IsoToEccProtobufRepository is not used anymore. Change this test case
to verify eccdata integrity directly.

Bug: 114163622
Test: atest TeleServiceTests:EccDataTest#testEccDataContent
Change-Id: Ifd760e003cd4f468f261973eb979b254c05fdc78
diff --git a/ecc/README.md b/ecc/README.md
index b5dc538..304cdfb 100644
--- a/ecc/README.md
+++ b/ecc/README.md
@@ -30,4 +30,4 @@
 4. Make TeleService
 5. Push TeleService.apk to system/priv-app/TeleService
 6. Reboot device
-7. run 'atest TeleServiceTests:IsoToEccProtobufRepositoryTest#testEccDataContent'
+7. run 'atest TeleServiceTests:EccDataTest#testEccDataContent'
diff --git a/ecc/gen_eccdata.sh b/ecc/gen_eccdata.sh
index 4f3a097..e4dd745 100755
--- a/ecc/gen_eccdata.sh
+++ b/ecc/gen_eccdata.sh
@@ -57,4 +57,4 @@
 echo "  1. make TeleService"
 echo "  2. push TeleService.apk to system/priv-app/TeleService"
 echo "  3. reboot device"
-echo "  4. run 'atest TeleServiceTests:IsoToEccProtobufRepositoryTest#testEccDataContent'"
+echo "  4. run 'atest TeleServiceTests:EccDataTest#testEccDataContent'"
diff --git a/tests/src/com/android/phone/ecc/EccDataTest.java b/tests/src/com/android/phone/ecc/EccDataTest.java
new file mode 100644
index 0000000..8f4abc5
--- /dev/null
+++ b/tests/src/com/android/phone/ecc/EccDataTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.phone.ecc;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+
+import com.android.TelephonyTestBase;
+import com.android.phone.ecc.nano.ProtobufEccData;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * Unit tests for eccdata.
+ */
+@RunWith(AndroidJUnit4.class)
+public class EccDataTest extends TelephonyTestBase {
+    @Test
+    public void testEccDataContent() throws IOException {
+        InputStream eccData = new GZIPInputStream(new BufferedInputStream(
+                InstrumentationRegistry.getTargetContext().getAssets().open("eccdata")));
+        ProtobufEccData.AllInfo allEccMessages = ProtobufEccData.AllInfo.parseFrom(
+                readInputStreamToByteArray(eccData));
+        eccData.close();
+
+        HashSet loadedIsos = new HashSet(300);
+        HashSet loadedNumbers = new HashSet(5);
+
+        for (ProtobufEccData.CountryInfo countryInfo : allEccMessages.countries) {
+            assertThat(countryInfo.isoCode).isNotEmpty();
+            assertThat(countryInfo.isoCode).isEqualTo(countryInfo.isoCode.toUpperCase().trim());
+            assertThat(loadedIsos.contains(countryInfo.isoCode)).isFalse();
+            loadedIsos.add(countryInfo.isoCode);
+
+            loadedNumbers.clear();
+            for (ProtobufEccData.EccInfo eccInfo : countryInfo.eccs) {
+                assertThat(eccInfo.phoneNumber).isNotEmpty();
+                assertThat(eccInfo.phoneNumber).isEqualTo(eccInfo.phoneNumber.trim());
+                assertThat(loadedNumbers.contains(eccInfo.phoneNumber)).isFalse();
+                assertThat(eccInfo.types).isNotEmpty();
+                loadedNumbers.add(eccInfo.phoneNumber);
+            }
+        }
+    }
+
+    /**
+     * Util function to convert inputStream to byte array before parsing proto data.
+     */
+    private static byte[] readInputStreamToByteArray(InputStream inputStream) throws IOException {
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        int nRead;
+        byte[] data = new byte[16 * 1024]; // Read 16k chunks
+        while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
+            buffer.write(data, 0, nRead);
+        }
+        buffer.flush();
+        return buffer.toByteArray();
+    }
+}
diff --git a/tests/src/com/android/phone/ecc/IsoToEccProtobufRepositoryTest.java b/tests/src/com/android/phone/ecc/IsoToEccProtobufRepositoryTest.java
deleted file mode 100644
index f6e5ba2..0000000
--- a/tests/src/com/android/phone/ecc/IsoToEccProtobufRepositoryTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-
-package com.android.phone.ecc;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-import android.util.Log;
-
-import com.android.TelephonyTestBase;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.HashSet;
-import java.util.Map;
-
-/**
- * Unit tests for IsoToEccProtobufRepository.
- */
-
-@RunWith(AndroidJUnit4.class)
-public class IsoToEccProtobufRepositoryTest extends TelephonyTestBase {
-    private static final String LOG_TAG = "IsoToEccProtobufRepositoryTest";
-
-    @Test
-    public void testEccDataContent() {
-        IsoToEccProtobufRepository repository = IsoToEccProtobufRepository.getInstance();
-        repository.loadMappingTable(InstrumentationRegistry.getTargetContext());
-        Map<String, CountryEccInfo> eccTable = repository.getEccTable();
-        HashSet loadedIsos = new HashSet(300);
-        HashSet loadedNumbers = new HashSet(5);
-
-        assertThat(eccTable).isNotEmpty();
-        for (Map.Entry<String, CountryEccInfo> entry : eccTable.entrySet()) {
-            String countryIso = entry.getKey();
-            CountryEccInfo countryEccInfo = entry.getValue();
-            EccInfo[] eccInfoList = countryEccInfo.getEccInfoList();
-            if (eccInfoList.length > 0) {
-                Log.i(LOG_TAG, "Verifying country " + countryIso + " with "
-                        + eccInfoList.length + " ecc(s)");
-            } else {
-                Log.w(LOG_TAG, "Verifying country " + countryIso + " with no ecc");
-            }
-
-            assertThat(countryIso).isNotEmpty();
-            assertThat(countryIso).isEqualTo(countryIso.toUpperCase().trim());
-            assertThat(loadedIsos.contains(countryIso)).isFalse();
-            loadedIsos.add(countryIso);
-
-            assertThat(countryEccInfo.getFallbackEcc()).isNotEmpty();
-
-            if (eccInfoList.length != 0) {
-                loadedNumbers.clear();
-                for (EccInfo eccInfo : eccInfoList) {
-                    String eccNumber = eccInfo.getNumber();
-                    assertThat(eccNumber).isNotEmpty();
-                    assertThat(eccNumber).isEqualTo(eccNumber.trim());
-                    assertThat(eccInfo.getTypes()).isNotEmpty();
-                    assertThat(loadedNumbers.contains(eccNumber)).isFalse();
-                    loadedNumbers.add(eccNumber);
-                }
-            }
-        }
-    }
-}