Use new officially supported way for local unit tests, many dependencies upgraded for this, temporary disabled separate debug builds

This commit is contained in:
Dominik Schürmann 2015-06-11 00:05:13 +02:00
parent 05fcbcae7b
commit d16b09b2a6
131 changed files with 151 additions and 234 deletions

View File

@ -1,121 +0,0 @@
buildscript {
repositories {
jcenter()
}
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.novoda:gradle-android-test-plugin:0.10.4'
}
}
apply plugin: 'java'
apply plugin: 'android-test'
apply plugin: 'jacoco'
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'com.google.android:android:4.1.1.4'
testCompile('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' }
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile ('org.robolectric:robolectric:2.4') {
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'
}
}
test {
exclude '**/*$*'
}
android {
projectUnderTest ':OpenKeychain'
}
jacoco {
toolVersion = "0.7.2.201409121644"
}
def coverageSourceDirs = [
'../OpenKeychain/src/main/java',
'../OpenKeychain/src/gen',
'../OpenKeychain/build/source/apt/debug',
'../OpenKeychain/build/source/generated/buildConfig/debug',
'../OpenKeychain/build/source/generated/r/debug'
]
jacocoTestReport {
reports {
xml.enabled = true
html.destination "${buildDir}/jacocoHtml"
}
// class R is used, but usage will not be covered, so ignore this class from report
classDirectories = fileTree(dir: '../OpenKeychain/build/intermediates/classes/debug/org/sufficientlysecure/keychain', exclude: [ 'R*.class' ])
additionalSourceDirs = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebug.exec')
}
// 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)
}

View File

@ -11,7 +11,17 @@ dependencies {
compile 'com.android.support:recyclerview-v7:22.1.0' compile 'com.android.support:recyclerview-v7:22.1.0'
compile 'com.android.support:cardview-v7:22.1.0' compile 'com.android.support:cardview-v7:22.1.0'
// UI testing libs // Local Unit tests with Robolectric
// https://developer.android.com/training/testing/unit-testing/local-unit-tests.html#run
// https://github.com/nenick/AndroidStudioAndRobolectric
// http://www.vogella.com/tutorials/Robolectric/article.html
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
testCompile "org.robolectric:robolectric:3.0-rc3"
// UI testing with Espresso
androidTestCompile 'com.android.support.test:runner:0.2' androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2' androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
@ -137,7 +147,7 @@ android {
resValue "string", "tempstorage_authority", "org.sufficientlysecure.keychain.tempstorage" resValue "string", "tempstorage_authority", "org.sufficientlysecure.keychain.tempstorage"
} }
extra { /*extra {
applicationIdSuffix ".debug" applicationIdSuffix ".debug"
// Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE. // Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.
@ -149,7 +159,7 @@ android {
resValue "string", "account_type", "org.sufficientlysecure.keychain.debug.account" resValue "string", "account_type", "org.sufficientlysecure.keychain.debug.account"
resValue "string", "provider_authority", "org.sufficientlysecure.keychain.debug.provider" resValue "string", "provider_authority", "org.sufficientlysecure.keychain.debug.provider"
resValue "string", "tempstorage_authority", "org.sufficientlysecure.keychain.debug.tempstorage" resValue "string", "tempstorage_authority", "org.sufficientlysecure.keychain.debug.tempstorage"
} }*/
} }
/* /*

View File

@ -22,22 +22,19 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.CertifyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.ExportResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -47,23 +44,17 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
import org.sufficientlysecure.keychain.util.TestingUtils; import org.sufficientlysecure.keychain.util.TestingUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.security.Security; import java.security.Security;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
@RunWith(RobolectricGradleTestRunner.class)
@RunWith(RobolectricTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19
public class CertifyOperationTest { public class CertifyOperationTest {
static UncachedKeyRing mStaticRing1, mStaticRing2; static UncachedKeyRing mStaticRing1, mStaticRing2;
@ -128,7 +119,7 @@ public class CertifyOperationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ProviderHelper providerHelper = new ProviderHelper(Robolectric.application); ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@ -143,7 +134,7 @@ public class CertifyOperationTest {
@Test @Test
public void testSelfCertifyFlag() throws Exception { public void testSelfCertifyFlag() throws Exception {
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId());
Assert.assertEquals("secret key must be marked self-certified in database", Assert.assertEquals("secret key must be marked self-certified in database",
// TODO this should be more correctly be VERIFIED_SELF at some point! // TODO this should be more correctly be VERIFIED_SELF at some point!
@ -153,11 +144,11 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifyId() throws Exception { public void testCertifyId() throws Exception {
CertifyOperation op = new CertifyOperation(Robolectric.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
{ {
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification", Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified()); Certs.UNVERIFIED, ring.getVerified());
@ -171,7 +162,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success()); Assert.assertTrue("certification must succeed", result.success());
{ {
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now", Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified()); Certs.VERIFIED_SECRET, ring.getVerified());
@ -181,11 +172,11 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifyAttribute() throws Exception { public void testCertifyAttribute() throws Exception {
CertifyOperation op = new CertifyOperation(Robolectric.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
{ {
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("public key must not be marked verified prior to certification", Assert.assertEquals("public key must not be marked verified prior to certification",
Certs.UNVERIFIED, ring.getVerified()); Certs.UNVERIFIED, ring.getVerified());
@ -199,7 +190,7 @@ public class CertifyOperationTest {
Assert.assertTrue("certification must succeed", result.success()); Assert.assertTrue("certification must succeed", result.success());
{ {
CanonicalizedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId());
Assert.assertEquals("new key must be verified now", Assert.assertEquals("new key must be verified now",
Certs.VERIFIED_SECRET, ring.getVerified()); Certs.VERIFIED_SECRET, ring.getVerified());
@ -210,8 +201,8 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifySelf() throws Exception { public void testCertifySelf() throws Exception {
CertifyOperation op = new CertifyOperation(Robolectric.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());
actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(),
@ -227,8 +218,8 @@ public class CertifyOperationTest {
@Test @Test
public void testCertifyNonexistent() throws Exception { public void testCertifyNonexistent() throws Exception {
CertifyOperation op = new CertifyOperation(Robolectric.application, CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
{ {
CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId());

View File

@ -23,10 +23,14 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.ExportResult; import org.sufficientlysecure.keychain.operations.results.ExportResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
@ -48,8 +52,8 @@ import java.io.PrintStream;
import java.security.Security; import java.security.Security;
import java.util.Iterator; import java.util.Iterator;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class ExportTest { public class ExportTest {
static Passphrase mPassphrase = TestingUtils.genPassphrase(true); static Passphrase mPassphrase = TestingUtils.genPassphrase(true);
@ -108,7 +112,7 @@ public class ExportTest {
@Before @Before
public void setUp() { public void setUp() {
ProviderHelper providerHelper = new ProviderHelper(Robolectric.application); ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@ -122,8 +126,8 @@ public class ExportTest {
@Test @Test
public void testExportAll() throws Exception { public void testExportAll() throws Exception {
ImportExportOperation op = new ImportExportOperation(Robolectric.application, ImportExportOperation op = new ImportExportOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
// make sure there is a local cert (so the later checks that there are none are meaningful) // make sure there is a local cert (so the later checks that there are none are meaningful)
Assert.assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); Assert.assertTrue("second keyring has local certification", checkForLocal(mStaticRing2));

View File

@ -23,11 +23,15 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult; import org.sufficientlysecure.keychain.operations.results.PromoteKeyResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
@ -50,8 +54,8 @@ import java.io.PrintStream;
import java.security.Security; import java.security.Security;
import java.util.Iterator; import java.util.Iterator;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class PromoteKeyOperationTest { public class PromoteKeyOperationTest {
static UncachedKeyRing mStaticRing; static UncachedKeyRing mStaticRing;
@ -89,7 +93,7 @@ public class PromoteKeyOperationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ProviderHelper providerHelper = new ProviderHelper(Robolectric.application); ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@ -102,15 +106,15 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromote() throws Exception { public void testPromote() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(Robolectric.application, PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), null, null); PromoteKeyResult result = op.execute(mStaticRing.getMasterKeyId(), null, null);
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CachedPublicKeyRing ring = new ProviderHelper(Robolectric.application) CachedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); .getCachedPublicKeyRing(mStaticRing.getMasterKeyId());
Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret());
@ -126,8 +130,8 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromoteDivert() throws Exception { public void testPromoteDivert() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(Robolectric.application, PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000"); byte[] aid = Hex.decode("D2760001240102000000012345670000");
@ -136,7 +140,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CanonicalizedSecretKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
@ -151,8 +155,8 @@ public class PromoteKeyOperationTest {
@Test @Test
public void testPromoteDivertSpecific() throws Exception { public void testPromoteDivertSpecific() throws Exception {
PromoteKeyOperation op = new PromoteKeyOperation(Robolectric.application, PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null, null); new ProviderHelper(RuntimeEnvironment.application), null, null);
byte[] aid = Hex.decode("D2760001240102000000012345670000"); byte[] aid = Hex.decode("D2760001240102000000012345670000");
@ -166,7 +170,7 @@ public class PromoteKeyOperationTest {
Assert.assertTrue("promotion must succeed", result.success()); Assert.assertTrue("promotion must succeed", result.success());
{ {
CanonicalizedSecretKeyRing ring = new ProviderHelper(Robolectric.application) CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application)
.getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());
for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {

View File

@ -20,10 +20,13 @@ package org.sufficientlysecure.keychain.pgp;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.sufficientlysecure.keychain.BuildConfig;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class KeyRingTest { public class KeyRingTest {
@Test @Test

View File

@ -25,10 +25,12 @@ import org.junit.runner.RunWith;
import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.robolectric.*; import org.robolectric.*;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
@ -52,8 +54,8 @@ import java.io.PrintStream;
import java.security.Security; import java.security.Security;
import java.util.HashSet; import java.util.HashSet;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class PgpEncryptDecryptTest { public class PgpEncryptDecryptTest {
static Passphrase mPassphrase = TestingUtils.genPassphrase(true); static Passphrase mPassphrase = TestingUtils.genPassphrase(true);
@ -112,7 +114,7 @@ public class PgpEncryptDecryptTest {
@Before @Before
public void setUp() { public void setUp() {
ProviderHelper providerHelper = new ProviderHelper(Robolectric.application); ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application);
// don't log verbosely here, we're not here to test imports // don't log verbosely here, we're not here to test imports
ShadowLog.stream = oldShadowStream; ShadowLog.stream = oldShadowStream;
@ -134,8 +136,8 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@ -156,8 +158,8 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerify op = new PgpDecryptVerify(Robolectric.application, PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute( DecryptVerifyResult result = op.execute(
@ -179,8 +181,8 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerify op = new PgpDecryptVerify(Robolectric.application, PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@ -198,8 +200,8 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerify op = new PgpDecryptVerify(Robolectric.application, PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(true); input.setAllowSymmetricDecryption(true);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@ -216,8 +218,8 @@ public class PgpEncryptDecryptTest {
ByteArrayInputStream in = new ByteArrayInputStream(ciphertext); ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpDecryptVerify op = new PgpDecryptVerify(Robolectric.application, PgpDecryptVerify op = new PgpDecryptVerify(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel();
input.setAllowSymmetricDecryption(false); input.setAllowSymmetricDecryption(false);
DecryptVerifyResult result = op.execute(input, DecryptVerifyResult result = op.execute(input,
@ -240,8 +242,8 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel(); PgpSignEncryptInputParcel input = new PgpSignEncryptInputParcel();
@ -321,8 +323,8 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
@ -406,7 +408,7 @@ public class PgpEncryptDecryptTest {
{ // decryption with passphrase cached should succeed for the other key if first is gone { // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database // delete first key from database
new ProviderHelper(Robolectric.application).getContentResolver().delete( new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
); );
@ -437,8 +439,8 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes());
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(); PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
@ -482,7 +484,7 @@ public class PgpEncryptDecryptTest {
{ // decryption with passphrase cached should succeed for the other key if first is gone { // decryption with passphrase cached should succeed for the other key if first is gone
// delete first key from database // delete first key from database
new ProviderHelper(Robolectric.application).getContentResolver().delete( new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null
); );
@ -520,8 +522,8 @@ public class PgpEncryptDecryptTest {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(plaindata); ByteArrayInputStream in = new ByteArrayInputStream(plaindata);
PgpSignEncryptOperation op = new PgpSignEncryptOperation(Robolectric.application, PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null); new ProviderHelper(RuntimeEnvironment.application), null);
InputData data = new InputData(in, in.available()); InputData data = new InputData(in, in.available());
PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel(); PgpSignEncryptInputParcel b = new PgpSignEncryptInputParcel();
@ -562,8 +564,8 @@ public class PgpEncryptDecryptTest {
private PgpDecryptVerify operationWithFakePassphraseCache( private PgpDecryptVerify operationWithFakePassphraseCache(
final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) {
return new PgpDecryptVerify(Robolectric.application, return new PgpDecryptVerify(RuntimeEnvironment.application,
new ProviderHelper(Robolectric.application), null) { new ProviderHelper(RuntimeEnvironment.application), null) {
@Override @Override
public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId)
throws NoSecretKeyException { throws NoSecretKeyException {

View File

@ -26,6 +26,7 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.*; import org.robolectric.*;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.BCPGInputStream; import org.spongycastle.bcpg.BCPGInputStream;
import org.spongycastle.bcpg.Packet; import org.spongycastle.bcpg.Packet;
@ -40,6 +41,7 @@ import org.spongycastle.bcpg.UserIDPacket;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.openpgp.PGPSignature; import org.spongycastle.openpgp.PGPSignature;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
@ -70,8 +72,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class PgpKeyOperationTest { public class PgpKeyOperationTest {
static UncachedKeyRing staticRing; static UncachedKeyRing staticRing;

View File

@ -23,7 +23,9 @@ import org.junit.runner.RunWith;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.Before; import org.junit.Before;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.BCPGInputStream; import org.spongycastle.bcpg.BCPGInputStream;
import org.spongycastle.bcpg.HashAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags;
@ -51,6 +53,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBu
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.spongycastle.util.Strings; import org.spongycastle.util.Strings;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
@ -78,8 +81,8 @@ import java.util.Iterator;
* Test cases are made for all its assertions. * Test cases are made for all its assertions.
*/ */
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class UncachedKeyringCanonicalizeTest { public class UncachedKeyringCanonicalizeTest {
static UncachedKeyRing staticRing; static UncachedKeyRing staticRing;

View File

@ -23,7 +23,9 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.BCPGInputStream; import org.spongycastle.bcpg.BCPGInputStream;
import org.spongycastle.bcpg.PacketTags; import org.spongycastle.bcpg.PacketTags;
@ -32,6 +34,7 @@ import org.spongycastle.bcpg.SecretKeyPacket;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.util.Strings; import org.spongycastle.util.Strings;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
@ -77,8 +80,8 @@ import java.util.Random;
* packet will be copied regardless. Filtering out bad packets is done with canonicalization. * packet will be copied regardless. Filtering out bad packets is done with canonicalization.
* *
*/ */
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class UncachedKeyringMergeTest { public class UncachedKeyringMergeTest {
static UncachedKeyRing staticRingA, staticRingB; static UncachedKeyRing staticRingA, staticRingB;

View File

@ -23,9 +23,12 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@ -40,8 +43,8 @@ import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class UncachedKeyringTest { public class UncachedKeyringTest {
static UncachedKeyRing staticRing, staticPubRing; static UncachedKeyRing staticRing, staticPubRing;

View File

@ -26,22 +26,24 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.*; import org.robolectric.*;
import org.robolectric.annotation.Config;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.support.KeyringTestingHelper; import org.sufficientlysecure.keychain.support.KeyringTestingHelper;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class ProviderHelperKeyringTest { public class ProviderHelperKeyringTest {
@Test @Test
public void testSavePublicKeyring() throws Exception { public void testSavePublicKeyring() throws Exception {
Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(Collections.singleton( Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(Collections.singleton(
"/public-key-for-sample.blob" "/public-key-for-sample.blob"
))); )));
} }
// @Test // @Test
public void testSavePublicKeyringRsa() throws Exception { public void testSavePublicKeyringRsa() throws Exception {
Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList( Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
"000001-006.public_key", "000001-006.public_key",
"000002-013.user_id", "000002-013.user_id",
"000003-002.sig", "000003-002.sig",
@ -62,7 +64,7 @@ public class ProviderHelperKeyringTest {
// @Test // @Test
public void testSavePublicKeyringDsa() throws Exception { public void testSavePublicKeyringDsa() throws Exception {
Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList( Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
"000016-006.public_key", "000016-006.public_key",
"000017-002.sig", "000017-002.sig",
"000018-012.ring_trust", "000018-012.ring_trust",
@ -79,7 +81,7 @@ public class ProviderHelperKeyringTest {
// @Test // @Test
public void testSavePublicKeyringDsa2() throws Exception { public void testSavePublicKeyringDsa2() throws Exception {
Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList( Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
"000027-006.public_key", "000027-006.public_key",
"000028-002.sig", "000028-002.sig",
"000029-012.ring_trust", "000029-012.ring_trust",

View File

@ -23,10 +23,14 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
@ -40,11 +44,11 @@ import org.sufficientlysecure.keychain.util.ProgressScaler;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class ProviderHelperSaveTest { public class ProviderHelperSaveTest {
ProviderHelper mProviderHelper = new ProviderHelper(Robolectric.application); ProviderHelper mProviderHelper = new ProviderHelper(RuntimeEnvironment.application);
@BeforeClass @BeforeClass
public static void setUpOnce() throws Exception { public static void setUpOnce() throws Exception {
@ -62,17 +66,17 @@ public class ProviderHelperSaveTest {
SaveKeyringResult result; SaveKeyringResult result;
// insert both keys, second should fail // insert both keys, second should fail
result = new ProviderHelper(Robolectric.application).savePublicKeyRing(first); result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first);
Assert.assertTrue("first keyring import should succeed", result.success()); Assert.assertTrue("first keyring import should succeed", result.success());
result = new ProviderHelper(Robolectric.application).savePublicKeyRing(second); result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertFalse("second keyring import should fail", result.success()); Assert.assertFalse("second keyring import should fail", result.success());
new KeychainDatabase(Robolectric.application).clearDatabase(); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase();
// and the other way around // and the other way around
result = new ProviderHelper(Robolectric.application).savePublicKeyRing(second); result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second);
Assert.assertTrue("first keyring import should succeed", result.success()); Assert.assertTrue("first keyring import should succeed", result.success());
result = new ProviderHelper(Robolectric.application).savePublicKeyRing(first); result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first);
Assert.assertFalse("second keyring import should fail", result.success()); Assert.assertFalse("second keyring import should fail", result.success());
} }
@ -91,13 +95,13 @@ public class ProviderHelperSaveTest {
SaveKeyringResult result; SaveKeyringResult result;
// insert secret, this should fail because of missing self-cert // insert secret, this should fail because of missing self-cert
result = new ProviderHelper(Robolectric.application).saveSecretKeyRing(seckey, new ProgressScaler()); result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler());
Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success());
// insert pubkey, then seckey - both should succeed // insert pubkey, then seckey - both should succeed
result = new ProviderHelper(Robolectric.application).savePublicKeyRing(pubkey); result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(pubkey);
Assert.assertTrue("public keyring import should succeed", result.success()); Assert.assertTrue("public keyring import should succeed", result.success());
result = new ProviderHelper(Robolectric.application).saveSecretKeyRing(seckey, new ProgressScaler()); result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler());
Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success());
} }

View File

@ -19,13 +19,16 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.util.Iso7816TLV.Iso7816CompositeTLV; import org.sufficientlysecure.keychain.util.Iso7816TLV.Iso7816CompositeTLV;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class Iso7816TLVTest { public class Iso7816TLVTest {
@Before @Before

View File

@ -25,16 +25,20 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog; import org.robolectric.shadows.ShadowLog;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 @Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class ParcelableFileCacheTest { public class ParcelableFileCacheTest {
@Before @Before
@ -45,7 +49,7 @@ public class ParcelableFileCacheTest {
@Test @Test
public void testInputOutput() throws Exception { public void testInputOutput() throws Exception {
ParcelableFileCache<Bundle> cache = new ParcelableFileCache<Bundle>(Robolectric.application, "test.pcl"); ParcelableFileCache<Bundle> cache = new ParcelableFileCache<Bundle>(RuntimeEnvironment.application, "test.pcl");
ArrayList<Bundle> list = new ArrayList<Bundle>(); ArrayList<Bundle> list = new ArrayList<Bundle>();

Some files were not shown because too many files have changed in this diff Show More