aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules4
-rw-r--r--.travis.yml1
-rw-r--r--OpenKeychain-Test/build.gradle80
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringBuilder.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringBuilder.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/PgpVerifyTestingHelper.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/PgpVerifyTestingHelper.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/ProviderHelperStub.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/TestDataUtil.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/UncachedKeyringTestingHelper.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/UncachedKeyringTestingHelper.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java (renamed from OpenKeychain/src/test/java/tests/PgpDecryptVerifyTest.java)2
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/ProviderHelperKeyringTest.java (renamed from OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java)4
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java90
m---------OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell (renamed from OpenKeychain/src/test/resources/extern/OpenPGP-Haskell)0
-rw-r--r--OpenKeychain-Test/src/test/resources/public-key-canonicalize.blob (renamed from OpenKeychain/src/test/resources/public-key-canonicalize.blob)bin1224 -> 1224 bytes
-rw-r--r--OpenKeychain-Test/src/test/resources/public-key-for-sample.blob (renamed from OpenKeychain/src/test/resources/public-key-for-sample.blob)bin35198 -> 35198 bytes
-rw-r--r--OpenKeychain-Test/src/test/resources/sample-altered.txt (renamed from OpenKeychain/src/test/resources/sample-altered.txt)0
-rw-r--r--OpenKeychain-Test/src/test/resources/sample.txt (renamed from OpenKeychain/src/test/resources/sample.txt)0
-rw-r--r--OpenKeychain/build.gradle7
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java1
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/package-info.java7
-rw-r--r--OpenKeychain/src/test/java/tests/UncachedKeyringTest.java91
-rw-r--r--build.gradle4
-rwxr-xr-xinstall-custom-gradle-test-plugin.sh15
-rw-r--r--settings.gradle1
24 files changed, 202 insertions, 117 deletions
diff --git a/.gitmodules b/.gitmodules
index b7b0e1173..956362d4b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -31,6 +31,6 @@
[submodule "extern/minidns"]
path = extern/minidns
url = https://github.com/open-keychain/minidns.git
-[submodule "OpenKeychain/src/test/resources/extern/OpenPGP-Haskell"]
- path = OpenKeychain/src/test/resources/extern/OpenPGP-Haskell
+[submodule "OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell"]
+ path = OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell
url = https://github.com/singpolyma/OpenPGP-Haskell.git
diff --git a/.travis.yml b/.travis.yml
index 5da831e61..2e86699f3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,6 +12,7 @@ before_install:
# Install required Android components.
#- echo "y" | android update sdk -a --filter build-tools-19.1.0,android-19,platform-tools,extra-android-support,extra-android-m2repository --no-ui --force
- ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --all --force --filter build-tools-19.1.0,android-19,platform-tools,extra-android-support,extra-android-m2repository
+ - ./install-custom-gradle-test-plugin.sh
install: echo "Installation done"
script: gradle assemble -S -q
diff --git a/OpenKeychain-Test/build.gradle b/OpenKeychain-Test/build.gradle
new file mode 100644
index 000000000..d795ace3d
--- /dev/null
+++ b/OpenKeychain-Test/build.gradle
@@ -0,0 +1,80 @@
+apply plugin: 'java'
+apply plugin: 'android-test'
+
+dependencies {
+ testCompile 'junit:junit:4.11'
+ testCompile 'com.google.android:android:4.1.1.4'
+ testCompile('com.squareup:fest-android:1.0.+') { exclude module: 'support-v4' }
+ testCompile ('org.robolectric:robolectric:2.3') {
+ exclude module: 'classworlds'
+ exclude module: 'maven-artifact'
+ exclude module: 'maven-artifact-manager'
+ exclude module: 'maven-error-diagnostics'
+ exclude module: 'maven-model'
+ exclude module: 'maven-plugin-registry'
+ exclude module: 'maven-profile'
+ exclude module: 'maven-project'
+ exclude module: 'maven-settings'
+ exclude module: 'nekohtml'
+ exclude module: 'plexus-container-default'
+ exclude module: 'plexus-interpolation'
+ exclude module: 'plexus-utils'
+ exclude module: 'support-v4' // crazy but my android studio don't like this dependency and to fix it remove .idea and re import project
+ exclude module: 'wagon-file'
+ exclude module: 'wagon-http-lightweight'
+ exclude module: 'wagon-http-shared'
+ exclude module: 'wagon-provider-api'
+ }
+}
+
+android {
+ projectUnderTest ':OpenKeychain'
+}
+
+// new workaround to force add custom output dirs for android studio
+task addTest {
+ def file = file(project.name + ".iml")
+ doLast {
+ try {
+ def parsedXml = (new XmlParser()).parse(file)
+ def node = parsedXml.component[1]
+ def outputNode = parsedXml.component[1].output[0]
+ def outputTestNode = parsedXml.component[1].'output-test'[0]
+ def rewrite = false
+
+ new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])
+
+ if(outputNode == null) {
+ new Node(node, 'output', ['url': 'file://$MODULE_DIR$/build/resources/testDebug'])
+ } else {
+ if(outputNode.attributes['url'] != 'file://$MODULE_DIR$/build/resources/testDebug') {
+ outputNode.attributes = ['url': 'file://$MODULE_DIR$/build/resources/testDebug']
+ rewrite = true
+ }
+ }
+
+ if(outputTestNode == null) {
+ new Node(node, 'output-test', ['url': 'file://$MODULE_DIR$/build/test-classes/debug'])
+ } else {
+ if(outputTestNode.attributes['url'] != 'file://$MODULE_DIR$/build/test-classes/debug') {
+ outputTestNode.attributes = ['url': 'file://$MODULE_DIR$/build/test-classes/debug']
+ rewrite = true
+ }
+ }
+
+ if(rewrite) {
+ def writer = new StringWriter()
+ new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
+ file.text = writer.toString()
+ }
+ } catch (FileNotFoundException e) {
+ // iml not found, common on command line only builds
+ }
+
+ }
+}
+
+// always do the addtest on prebuild
+gradle.projectsEvaluated {
+ testDebugClasses.dependsOn(addTest)
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringBuilder.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringBuilder.java
index 1672e9c81..94193bbcb 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringBuilder.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringBuilder.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.spongycastle.bcpg.ContainedPacket;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
index d2a945185..4c779d2b7 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
import android.content.Context;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/PgpVerifyTestingHelper.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/PgpVerifyTestingHelper.java
index 19c125319..dd5786512 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/PgpVerifyTestingHelper.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/PgpVerifyTestingHelper.java
@@ -1,4 +1,4 @@
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
/*
* Copyright (C) Art O Cathain
*
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/ProviderHelperStub.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java
index 0f73d4264..f06fe0072 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/ProviderHelperStub.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
import android.content.Context;
import android.net.Uri;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/TestDataUtil.java
index e823c10fd..f2b3c0996 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/TestDataUtil.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
import org.spongycastle.bcpg.ContainedPacket;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/UncachedKeyringTestingHelper.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/UncachedKeyringTestingHelper.java
index 7a493ecf6..6467d3f32 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/UncachedKeyringTestingHelper.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/UncachedKeyringTestingHelper.java
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sufficientlysecure.keychain.testsupport;
+package org.sufficientlysecure.keychain.support;
import org.spongycastle.bcpg.BCPGKey;
import org.spongycastle.bcpg.PublicKeyPacket;
diff --git a/OpenKeychain/src/test/java/tests/PgpDecryptVerifyTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java
index 0353e03f5..158650012 100644
--- a/OpenKeychain/src/test/java/tests/PgpDecryptVerifyTest.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java
@@ -22,7 +22,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.*;
import org.openintents.openpgp.OpenPgpSignatureResult;
-import org.sufficientlysecure.keychain.testsupport.PgpVerifyTestingHelper;
+import org.sufficientlysecure.keychain.support.PgpVerifyTestingHelper;
@RunWith(RobolectricTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
diff --git a/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/ProviderHelperKeyringTest.java
index 830ec1266..1bcb5a4ff 100644
--- a/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/ProviderHelperKeyringTest.java
@@ -26,9 +26,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.*;
-import org.openintents.openpgp.OpenPgpSignatureResult;
-import org.sufficientlysecure.keychain.testsupport.KeyringTestingHelper;
-import org.sufficientlysecure.keychain.testsupport.PgpVerifyTestingHelper;
+import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
@RunWith(RobolectricTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java
new file mode 100644
index 000000000..8ec6312e3
--- /dev/null
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java
@@ -0,0 +1,90 @@
+package org.sufficientlysecure.keychain.tests;
+
+import android.app.Activity;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.robolectric.*;
+import org.robolectric.shadows.ShadowLog;
+import org.spongycastle.bcpg.sig.KeyFlags;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
+import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
+import org.sufficientlysecure.keychain.service.OperationResultParcel;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
+import org.sufficientlysecure.keychain.support.KeyringBuilder;
+import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
+import org.sufficientlysecure.keychain.support.TestDataUtil;
+import org.sufficientlysecure.keychain.ui.KeyListActivity;
+
+import java.util.HashSet;
+
+@RunWith(RobolectricTestRunner.class)
+@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
+public class UncachedKeyringTest {
+
+ @Before
+ public void setUp() throws Exception {
+ ShadowLog.stream = System.out;
+ }
+
+ @Test
+ public void testCreateKey() throws Exception {
+ Activity activity = Robolectric.buildActivity(KeyListActivity.class).create().get();
+
+ SaveKeyringParcel parcel = new SaveKeyringParcel();
+ parcel.addSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
+ Constants.choice.algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
+ // parcel.addSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
+ parcel.addUserIds.add("swagerinho");
+ parcel.newPassphrase = "swag";
+ PgpKeyOperation op = new PgpKeyOperation(null);
+
+ OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
+ UncachedKeyRing ring = op.createSecretKeyRing(parcel, log, 0);
+
+ if (ring == null) {
+ log.print(activity);
+ throw new AssertionError("oh no");
+ }
+
+ if (!"swagerinho".equals(ring.getMasterKeyId())) {
+ log.print(activity);
+ throw new AssertionError("oh noo");
+ }
+
+ }
+
+ @Test
+ public void testVerifySuccess() throws Exception {
+ UncachedKeyRing expectedKeyRing = KeyringBuilder.correctRing();
+ UncachedKeyRing inputKeyRing = KeyringBuilder.ringWithExtraIncorrectSignature();
+
+ OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
+ UncachedKeyRing canonicalizedRing = inputKeyRing.canonicalize(log, 0);
+
+ if (canonicalizedRing == null) {
+ throw new AssertionError("Canonicalization failed; messages: [" + log.toString() + "]");
+ }
+
+ HashSet onlyA = new HashSet<KeyringTestingHelper.Packet>();
+ HashSet onlyB = new HashSet<KeyringTestingHelper.Packet>();
+ Assert.assertTrue(KeyringTestingHelper.diffKeyrings(
+ expectedKeyRing.getEncoded(), expectedKeyRing.getEncoded(), onlyA, onlyB));
+
+ }
+
+ /**
+ * Just testing my own test code. Should really be using a library for this.
+ */
+ @Test
+ public void testConcat() throws Exception {
+ byte[] actual = TestDataUtil.concatAll(new byte[]{1}, new byte[]{2,-2}, new byte[]{5},new byte[]{3});
+ byte[] expected = new byte[]{1,2,-2,5,3};
+ Assert.assertEquals(java.util.Arrays.toString(expected), java.util.Arrays.toString(actual));
+ }
+
+
+}
diff --git a/OpenKeychain/src/test/resources/extern/OpenPGP-Haskell b/OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell
-Subproject eba7e4fdce3de6622b4ec3862b405b0acd01637
+Subproject eba7e4fdce3de6622b4ec3862b405b0acd01637
diff --git a/OpenKeychain/src/test/resources/public-key-canonicalize.blob b/OpenKeychain-Test/src/test/resources/public-key-canonicalize.blob
index 3450824c1..3450824c1 100644
--- a/OpenKeychain/src/test/resources/public-key-canonicalize.blob
+++ b/OpenKeychain-Test/src/test/resources/public-key-canonicalize.blob
Binary files differ
diff --git a/OpenKeychain/src/test/resources/public-key-for-sample.blob b/OpenKeychain-Test/src/test/resources/public-key-for-sample.blob
index 4aa91510b..4aa91510b 100644
--- a/OpenKeychain/src/test/resources/public-key-for-sample.blob
+++ b/OpenKeychain-Test/src/test/resources/public-key-for-sample.blob
Binary files differ
diff --git a/OpenKeychain/src/test/resources/sample-altered.txt b/OpenKeychain-Test/src/test/resources/sample-altered.txt
index 458821f81..458821f81 100644
--- a/OpenKeychain/src/test/resources/sample-altered.txt
+++ b/OpenKeychain-Test/src/test/resources/sample-altered.txt
diff --git a/OpenKeychain/src/test/resources/sample.txt b/OpenKeychain-Test/src/test/resources/sample.txt
index c0065f78d..c0065f78d 100644
--- a/OpenKeychain/src/test/resources/sample.txt
+++ b/OpenKeychain-Test/src/test/resources/sample.txt
diff --git a/OpenKeychain/build.gradle b/OpenKeychain/build.gradle
index f419141b4..749a7f9ab 100644
--- a/OpenKeychain/build.gradle
+++ b/OpenKeychain/build.gradle
@@ -21,13 +21,6 @@ dependencies {
compile project(':extern:minidns')
compile project(':extern:KeybaseLib:Lib')
-
- // Unit tests are run with Robolectric
- testCompile 'junit:junit:4.11'
- testCompile 'org.robolectric:robolectric:2.3'
- testCompile 'com.squareup:fest-android:1.0.8'
- testCompile 'com.google.android:android:4.1.1.4'
- // compile dependencies are automatically also included in testCompile
}
android {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java
index babd251c4..5a778a19d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java
@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Arrays;
/** Represent the result of an operation.
*
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/package-info.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/package-info.java
deleted file mode 100644
index 1cc0f9a95..000000000
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * Test support classes.
- * This is only in main code because of gradle-Android Studio-robolectric issues. Having
- * classes in main code means IDE autocomplete, class detection, etc., all works.
- * TODO Move into test package when possible
- */
-package org.sufficientlysecure.keychain.testsupport;
diff --git a/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java b/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java
deleted file mode 100644
index b3f78f22d..000000000
--- a/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) Art O Cathain, Vincent Breitmoser
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package tests;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.*;
-import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
-import org.sufficientlysecure.keychain.service.OperationResultParcel;
-import org.sufficientlysecure.keychain.testsupport.*;
-import org.sufficientlysecure.keychain.testsupport.KeyringBuilder;
-import org.sufficientlysecure.keychain.testsupport.KeyringTestingHelper;
-import org.sufficientlysecure.keychain.testsupport.TestDataUtil;
-
-import java.util.*;
-import java.io.*;
-
-@RunWith(RobolectricTestRunner.class)
-@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
-public class UncachedKeyringTest {
-
- @Test
- public void testCanonicalizeNoChanges() throws Exception {
- UncachedKeyRing expectedKeyRing = KeyringBuilder.correctRing();
- UncachedKeyRing inputKeyRing = KeyringBuilder.correctRing();
-// Uncomment to dump the encoded key for manual inspection
-// TestDataUtil.appendToOutput(new ByteArrayInputStream(inputKeyRing.getEncoded()), new FileOutputStream(new File("/tmp/key-encoded")));
- new UncachedKeyringTestingHelper().doTestCanonicalize(inputKeyRing, expectedKeyRing);
-
- OperationResultParcel.OperationLog log = new OperationResultParcel.OperationLog();
- UncachedKeyRing canonicalizedRing = inputKeyRing.canonicalize(log, 0);
-
- if (canonicalizedRing == null) {
- throw new AssertionError("Canonicalization failed; messages: [" + log.toString() + "]");
- }
-
- HashSet onlyA = new HashSet<KeyringTestingHelper.Packet>();
- HashSet onlyB = new HashSet<KeyringTestingHelper.Packet>();
- Assert.assertTrue(KeyringTestingHelper.diffKeyrings(
- canonicalizedRing.getEncoded(), expectedKeyRing.getEncoded(), onlyA, onlyB));
-
-
- }
-
-
- @Test
- public void testCanonicalizeExtraIncorrectSignature() throws Exception {
- UncachedKeyRing expectedKeyRing = KeyringBuilder.correctRing();
- UncachedKeyRing inputKeyRing = KeyringBuilder.ringWithExtraIncorrectSignature();
- new UncachedKeyringTestingHelper().doTestCanonicalize(inputKeyRing, expectedKeyRing);
- }
-
- /**
- * Check the original GnuPG-generated public key is OK
- */
- @Test
- public void testCanonicalizeOriginalGpg() throws Exception {
- byte[] data = TestDataUtil.readAllFully(Collections.singleton("/public-key-canonicalize.blob"));
- UncachedKeyRing inputKeyRing = UncachedKeyRing.decodeFromData(data);
- new UncachedKeyringTestingHelper().doTestCanonicalize(inputKeyRing, KeyringBuilder.correctRing());
- }
-
-
- /**
- * Just testing my own test code. Should really be using a library for this.
- */
- @Test
- public void testConcat() throws Exception {
- byte[] actual = TestDataUtil.concatAll(new byte[]{1}, new byte[]{2, -2}, new byte[]{5}, new byte[]{3});
- byte[] expected = new byte[]{1, 2, -2, 5, 3};
- Assert.assertEquals(java.util.Arrays.toString(expected), java.util.Arrays.toString(actual));
- }
-
-
-}
diff --git a/build.gradle b/build.gradle
index ceb963cd8..06036785b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,12 +1,16 @@
buildscript {
repositories {
mavenCentral()
+ // need this for com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT below (0.9.3 in repos doesn't work!)
+ // run ./install-custom-gradle-test-plugin.sh to pull the thing into the local repository
+ mavenLocal()
}
dependencies {
// NOTE: Always use fixed version codes not dynamic ones, e.g. 0.7.3 instead of 0.7.+, see README for more information
classpath 'com.android.tools.build:gradle:0.12.0'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.0'
+ classpath 'com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT'
}
}
diff --git a/install-custom-gradle-test-plugin.sh b/install-custom-gradle-test-plugin.sh
new file mode 100755
index 000000000..85c13d959
--- /dev/null
+++ b/install-custom-gradle-test-plugin.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+mkdir temp
+cd temp
+
+ git clone https://github.com/nenick/gradle-android-test-plugin.git
+ cd gradle-android-test-plugin
+
+ echo "rootProject.name = 'gradle-android-test-plugin-parent'" > settings.gradle
+ echo "include ':gradle-android-test-plugin'" >> settings.gradle
+
+ ./gradlew :gradle-android-test-plugin:install
+
+ cd ..
+cd .. \ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index d8802320c..86088e04a 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,4 +1,5 @@
include ':OpenKeychain'
+include ':OpenKeychain-Test'
include ':extern:openpgp-api-lib'
include ':extern:openkeychain-api-lib'
include ':extern:html-textview'