summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2010-08-21 14:09:54 -0700
committerDaisuke Miyakawa <dmiyakawa@google.com>2010-08-21 14:15:44 -0700
commit237dd947f2e22d34f490bf35ef4b850d05cfffa9 (patch)
tree1aef8dd8ddefc05a47f81201c1377aaabb49f229
parent4560bdde6dd75cca49fc55b58aafb5d416b88ca3 (diff)
downloadvcard-237dd947f2e22d34f490bf35ef4b850d05cfffa9.tar.gz
Misc fix for vCard testing.
- Add VCardTestRunner - Make AndroidManifest aware of newly added VCardTestRunner - Move VCardTestBase to test_utils as it is part of testing utility - Add VCardTestUtilsTests, confirming test utility correctly fails when the test should fail. Change-Id: I593912ce9e664e9346d6f567ccf75f8afc47f9a5
-rw-r--r--tests/AndroidManifest.xml8
-rw-r--r--tests/src/com/android/vcard/tests/VCardExporterTests.java1
-rw-r--r--tests/src/com/android/vcard/tests/VCardImporterTests.java3
-rw-r--r--tests/src/com/android/vcard/tests/VCardJapanizationTests.java1
-rw-r--r--tests/src/com/android/vcard/tests/VCardTestRunner.java42
-rw-r--r--tests/src/com/android/vcard/tests/VCardTestUtilsTests.java98
-rw-r--r--tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java (renamed from tests/src/com/android/vcard/tests/VCardTestsBase.java)2
7 files changed, 149 insertions, 6 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index fcbf767..acca57f 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -22,9 +22,11 @@
<uses-library android:name="android.test.runner" />
</application>
- <!-- Run tests with "runtest common" -->
- <instrumentation android:name="android.test.InstrumentationTestRunner"
+ <instrumentation android:name=".VCardTestRunner"
android:targetPackage="com.android.vcard.tests"
- android:label="Android vCard Library Tests" />
+ android:label="TestRunner running all Android vCard Library Tests" />
+ <instrumentation android:name="com.android.InstrumentationTestRunner"
+ android:targetPackage="com.android.vcard.tests"
+ android:label="TestRunner letting users run each test including new one" />
</manifest>
diff --git a/tests/src/com/android/vcard/tests/VCardExporterTests.java b/tests/src/com/android/vcard/tests/VCardExporterTests.java
index 701bc28..b8a692b 100644
--- a/tests/src/com/android/vcard/tests/VCardExporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardExporterTests.java
@@ -34,6 +34,7 @@ import com.android.vcard.VCardConfig;
import com.android.vcard.tests.test_utils.ContactEntry;
import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem;
import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
+import com.android.vcard.tests.test_utils.VCardTestsBase;
import java.util.Arrays;
diff --git a/tests/src/com/android/vcard/tests/VCardImporterTests.java b/tests/src/com/android/vcard/tests/VCardImporterTests.java
index 1148e57..bbaf5fc 100644
--- a/tests/src/com/android/vcard/tests/VCardImporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardImporterTests.java
@@ -31,8 +31,7 @@ import com.android.vcard.VCardConfig;
import com.android.vcard.tests.test_utils.ContentValuesVerifier;
import com.android.vcard.tests.test_utils.ContentValuesVerifierElem;
import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
-
-import junit.framework.TestCase;
+import com.android.vcard.tests.test_utils.VCardTestsBase;
import java.util.Arrays;
diff --git a/tests/src/com/android/vcard/tests/VCardJapanizationTests.java b/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
index 92cc2d9..f9433de 100644
--- a/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
+++ b/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
@@ -27,6 +27,7 @@ import com.android.vcard.tests.test_utils.ContactEntry;
import com.android.vcard.tests.test_utils.ContentValuesBuilder;
import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem;
import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
+import com.android.vcard.tests.test_utils.VCardTestsBase;
import java.util.Arrays;
diff --git a/tests/src/com/android/vcard/tests/VCardTestRunner.java b/tests/src/com/android/vcard/tests/VCardTestRunner.java
new file mode 100644
index 0000000..a1f594a
--- /dev/null
+++ b/tests/src/com/android/vcard/tests/VCardTestRunner.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 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.vcard.tests;
+
+import android.test.InstrumentationTestRunner;
+import android.test.InstrumentationTestSuite;
+
+import junit.framework.TestSuite;
+
+/**
+ * Usage: adb shell am instrument -w com.android.vcard.tests/.VCardTestRunnerTestRunner
+ */
+public class VCardTestRunner extends InstrumentationTestRunner {
+ @Override
+ public TestSuite getAllTests() {
+ TestSuite suite = new InstrumentationTestSuite(this);
+ suite.addTestSuite(VCardUtilsTests.class);
+ suite.addTestSuite(VCardTestUtilsTests.class);
+ suite.addTestSuite(VCardImporterTests.class);
+ suite.addTestSuite(VCardExporterTests.class);
+ suite.addTestSuite(VCardJapanizationTests.class);
+ return suite;
+ }
+
+ @Override
+ public ClassLoader getLoader() {
+ return VCardTestRunner.class.getClassLoader();
+ }
+} \ No newline at end of file
diff --git a/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java b/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java
new file mode 100644
index 0000000..fc46561
--- /dev/null
+++ b/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2010 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.vcard.tests;
+
+import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.test.AndroidTestCase;
+
+import com.android.vcard.VCardConfig;
+import com.android.vcard.tests.test_utils.VCardVerifier;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+
+/**
+ * Tests confirming utilities for vCard tests work fine.
+ *
+ * Now that the foundation classes for vCard test cases became too complicated to
+ * rely on without testing itself.
+ */
+public class VCardTestUtilsTests extends AndroidTestCase {
+ public void testShouldFailAtPropertyNodeVerification() {
+ boolean failureDetected = false;
+ try {
+ final VCardVerifier verifier = new VCardVerifier(this);
+ verifier.initForImportTest(VCardConfig.VCARD_TYPE_V21_GENERIC, R.raw.v21_backslash);
+ verifier.addPropertyNodesVerifierElem()
+ .addExpectedNodeWithOrder("N", ";A;B\\;C\\;;D;:E;\\\\;--", // wrong
+ Arrays.asList("", "A;B\\", "C\\;", "D", ":E", "\\\\", ""))
+ .addExpectedNodeWithOrder("FN", "A;B\\C\\;D:E\\\\");
+ verifier.verify();
+ } catch (AssertionFailedError e) {
+ failureDetected = true;
+ }
+ if (!failureDetected) {
+ TestCase.fail("Test case that should fail actually succeeded.");
+ }
+ }
+
+ public void testShouldFailAtContentValueVerification() {
+ boolean failureDetected = false;
+ try {
+ final VCardVerifier verifier = new VCardVerifier(this);
+ verifier.initForImportTest(VCardConfig.VCARD_TYPE_V21_GENERIC, R.raw.v21_backslash);
+ verifier.addContentValuesVerifierElem()
+ .addExpected(StructuredName.CONTENT_ITEM_TYPE)
+ .put(StructuredName.GIVEN_NAME, "A;B\\")
+ .put(StructuredName.MIDDLE_NAME, "C\\;")
+ .put(StructuredName.PREFIX, "D")
+ .put(StructuredName.SUFFIX, ":E");
+ // DISPLAY_NAME is missing.
+ verifier.verify();
+ } catch (AssertionFailedError e) {
+ failureDetected = true;
+ }
+ if (!failureDetected) {
+ TestCase.fail("Test case that should fail actually succeeded.");
+ }
+ }
+
+ public void testShouldFailAtLineVerification() {
+ boolean failureDetected = false;
+ try {
+ final VCardVerifier verifier = new VCardVerifier(this);
+ verifier.initForExportTest(VCardConfig.VCARD_TYPE_V30_GENERIC);
+ verifier.addInputEntry().addContentValues(StructuredName.CONTENT_ITEM_TYPE)
+ .put(StructuredName.FAMILY_NAME, "\\")
+ .put(StructuredName.GIVEN_NAME, ";")
+ .put(StructuredName.MIDDLE_NAME, ",")
+ .put(StructuredName.PREFIX, "\n")
+ .put(StructuredName.DISPLAY_NAME, "[<{Unescaped:Asciis}>]");
+ verifier.addLineVerifierElem()
+ .addExpected("TEL:1") // wrong
+ .addExpected("FN:[<{Unescaped:Asciis}>]");
+ verifier.verify();
+ } catch (AssertionFailedError e) {
+ failureDetected = true;
+ }
+ if (!failureDetected) {
+ TestCase.fail("Test case that should fail actually succeeded.");
+ }
+ }
+
+}
diff --git a/tests/src/com/android/vcard/tests/VCardTestsBase.java b/tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java
index dbb409f..8a84e22 100644
--- a/tests/src/com/android/vcard/tests/VCardTestsBase.java
+++ b/tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests;
+package com.android.vcard.tests.test_utils;
import android.content.ContentValues;
import android.test.AndroidTestCase;