mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 09:12:16 -05:00
put unit tests into external module (CAVEAT)
this requires a more up to date version of gradle-android-test-plugin than is currently in the repositories. it must be added to the local maven repo using ./install-custom-gradle-test-plugin.sh before compiling.
This commit is contained in:
parent
9320d2d8a2
commit
718acbf954
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
80
OpenKeychain-Test/build.gradle
Normal file
80
OpenKeychain-Test/build.gradle
Normal file
@ -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)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package tests;
|
||||
package org.sufficientlysecure.keychain.tests;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
@ -1,4 +1,4 @@
|
||||
package tests;
|
||||
package org.sufficientlysecure.keychain.tests;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
@ -9,9 +9,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;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
|
@ -1,15 +1,23 @@
|
||||
package tests;
|
||||
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.testsupport.*;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.testsupport.KeyringBuilder;
|
||||
import org.sufficientlysecure.keychain.testsupport.KeyringTestingHelper;
|
||||
import org.sufficientlysecure.keychain.testsupport.TestDataUtil;
|
||||
import org.sufficientlysecure.keychain.ui.KeyListActivity;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@ -17,6 +25,38 @@ import java.util.HashSet;
|
||||
@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.ring2();
|
||||
@ -33,7 +73,7 @@ public class UncachedKeyringTest {
|
||||
HashSet onlyA = new HashSet<KeyringTestingHelper.Packet>();
|
||||
HashSet onlyB = new HashSet<KeyringTestingHelper.Packet>();
|
||||
Assert.assertTrue(KeyringTestingHelper.diffKeyrings(
|
||||
canonicalizedRing.getEncoded(), expectedKeyRing.getEncoded(), onlyA, onlyB));
|
||||
expectedKeyRing.getEncoded(), expectedKeyRing.getEncoded(), onlyA, onlyB));
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
|
15
install-custom-gradle-test-plugin.sh
Executable file
15
install-custom-gradle-test-plugin.sh
Executable file
@ -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 ..
|
@ -1,4 +1,5 @@
|
||||
include ':OpenKeychain'
|
||||
include ':OpenKeychain-Test'
|
||||
include ':extern:openpgp-api-lib'
|
||||
include ':extern:openkeychain-api-lib'
|
||||
include ':extern:html-textview'
|
||||
|
Loading…
Reference in New Issue
Block a user