summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.mk15
-rw-r--r--tests/AndroidManifest.xml28
-rw-r--r--tests/src/com/android/carrierconfig/CarrierConfigTest.java103
3 files changed, 146 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
new file mode 100644
index 0000000..bb3bd18
--- /dev/null
+++ b/tests/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CarrierConfigTests
+LOCAL_CERTIFICATE := platform
+
+LOCAL_INSTRUMENTATION_FOR := CarrierConfig
+
+include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
new file mode 100644
index 0000000..42ea2b7
--- /dev/null
+++ b/tests/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.carrierconfig.tests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.carrierconfig"
+ android:label="Tests for CarrierConfig">
+ </instrumentation>
+</manifest>
diff --git a/tests/src/com/android/carrierconfig/CarrierConfigTest.java b/tests/src/com/android/carrierconfig/CarrierConfigTest.java
new file mode 100644
index 0000000..5a29ea1
--- /dev/null
+++ b/tests/src/com/android/carrierconfig/CarrierConfigTest.java
@@ -0,0 +1,103 @@
+package com.android.carrierconfig;
+
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.os.PersistableBundle;
+import android.service.carrier.CarrierIdentifier;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.AssertionFailedError;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlPullParserFactory;
+
+public class CarrierConfigTest extends InstrumentationTestCase {
+
+ /**
+ * Iterate over all XML files in assets/ and ensure they parse without error.
+ */
+ public void testAllFilesParse() {
+ forEachConfigXml(new ParserChecker() {
+ public void check(XmlPullParser parser) throws XmlPullParserException, IOException {
+ PersistableBundle b = DefaultCarrierConfigService.readConfigFromXml(parser,
+ new CarrierIdentifier("001", "001", "Test", "", "", ""));
+ assertNotNull("got null bundle", b);
+ assertTrue("got empty bundle", b.size() > 0);
+ }
+ });
+ }
+
+ /**
+ * Check that the config bundles in XML files have valid filter attributes.
+ * This checks the attribute names only.
+ */
+ public void testFilterValidAttributes() {
+ forEachConfigXml(new ParserChecker() {
+ public void check(XmlPullParser parser) throws XmlPullParserException, IOException {
+ int event;
+ while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) {
+ if (event == XmlPullParser.START_TAG && "carrier_config".equals(parser.getName())) {
+ for (int i = 0; i < parser.getAttributeCount(); ++i) {
+ String attribute = parser.getAttributeName(i);
+ switch (attribute) {
+ case "mcc":
+ case "mnc":
+ case "gid1":
+ case "gid2":
+ case "spn":
+ case "device":
+ break;
+ default:
+ fail("Unknown attribute '" + attribute + "'");
+ break;
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Utility for iterating over each XML document in the assets folder.
+ *
+ * This can be used with {@link #forEachConfigXml} to run checks on each XML document.
+ * {@link #check} should {@link #fail} if the test does not pass.
+ */
+ private interface ParserChecker {
+ void check(XmlPullParser parser) throws XmlPullParserException, IOException;
+ }
+
+ /**
+ * Utility for iterating over each XML document in the assets folder.
+ */
+ private void forEachConfigXml(ParserChecker checker) {
+ AssetManager assetMgr = getInstrumentation().getTargetContext().getAssets();
+ try {
+ String[] files = assetMgr.list("");
+ assertNotNull("failed to list files", files);
+ assertTrue("no files", files.length > 0);
+ for (String fileName : files) {
+ try {
+ if (!fileName.startsWith("carrier_config_")) continue;
+
+ XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
+ XmlPullParser parser = factory.newPullParser();
+ parser.setInput(assetMgr.open(fileName), "utf-8");
+
+ checker.check(parser);
+
+ } catch (Throwable e) {
+ throw new AssertionError("Problem in " + fileName + ": " + e.getMessage(), e);
+ }
+ }
+ } catch (IOException e) {
+ fail(e.toString());
+ }
+ }
+}