diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-01 17:54:10 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-01 17:54:10 +0200 |
commit | f72a07690c257fefb28aed6645ad898fded63a78 (patch) | |
tree | b9380105194eef2d79440b33e9f3d9ad047cbb36 /OpenKeychain-Test/src/test | |
parent | aa5856bcb8f04116b3a08bbb8450ee1183553e01 (diff) | |
parent | f555447011a4d975e87d99ddc5f512c3205c2211 (diff) | |
download | open-keychain-f72a07690c257fefb28aed6645ad898fded63a78.tar.gz open-keychain-f72a07690c257fefb28aed6645ad898fded63a78.tar.bz2 open-keychain-f72a07690c257fefb28aed6645ad898fded63a78.zip |
Merge branch 'master' of github.com:open-keychain/open-keychain
Diffstat (limited to 'OpenKeychain-Test/src/test')
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java) | 0 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java) | 26 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringCanonicalizeTest.java) | 7 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringMergeTest.java) | 9 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java) | 8 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java (renamed from OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/ProviderHelperKeyringTest.java) | 2 | ||||
-rw-r--r-- | OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/util/FileImportCacheTest.java | 54 |
7 files changed, 67 insertions, 39 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyTest.java index 158650012..158650012 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpDecryptVerifyTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyTest.java diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index 4f6694049..0e0ec7ee2 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -1,4 +1,4 @@ -package org.sufficientlysecure.keychain.tests; +package org.sufficientlysecure.keychain.pgp; import junit.framework.AssertionFailedError; @@ -19,12 +19,6 @@ import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.openpgp.PGPSignature; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.choice.algorithm; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; -import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd; @@ -40,6 +34,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; +import java.util.List; import java.util.Random; @RunWith(RobolectricTestRunner.class) @@ -208,8 +203,8 @@ public class PgpKeyOperationTest { Assert.assertEquals("number of user ids must be two", 2, ring.getPublicKey().getUnorderedUserIds().size()); - Assert.assertEquals("number of subkeys must be three", - 3, KeyringTestingHelper.itToList(ring.getPublicKeys()).size()); + List<UncachedPublicKey> subkeys = KeyringTestingHelper.itToList(ring.getPublicKeys()); + Assert.assertEquals("number of subkeys must be three", 3, subkeys.size()); Assert.assertTrue("key ring should have been created in the last 120 seconds", ring.getPublicKey().getCreationTime().after(new Date(new Date().getTime()-1000*120))); @@ -217,24 +212,21 @@ public class PgpKeyOperationTest { Assert.assertNull("key ring should not expire", ring.getPublicKey().getExpiryTime()); - Iterator<UncachedPublicKey> it = ring.getPublicKeys(); - Assert.assertEquals("first (master) key can certify", - KeyFlags.CERTIFY_OTHER, it.next().getKeyUsage()); + KeyFlags.CERTIFY_OTHER, subkeys.get(0).getKeyUsage()); - UncachedPublicKey signingKey = it.next(); Assert.assertEquals("second key can sign", - KeyFlags.SIGN_DATA, signingKey.getKeyUsage()); - ArrayList<WrappedSignature> sigs = signingKey.getSignatures().next().getEmbeddedSignatures(); + KeyFlags.SIGN_DATA, subkeys.get(1).getKeyUsage()); + ArrayList<WrappedSignature> sigs = subkeys.get(1).getSignatures().next().getEmbeddedSignatures(); Assert.assertEquals("signing key signature should have one embedded signature", 1, sigs.size()); Assert.assertEquals("embedded signature should be of primary key binding type", PGPSignature.PRIMARYKEY_BINDING, sigs.get(0).getSignatureType()); Assert.assertEquals("primary key binding signature issuer should be signing subkey", - signingKey.getKeyId(), sigs.get(0).getKeyId()); + subkeys.get(1).getKeyId(), sigs.get(0).getKeyId()); Assert.assertEquals("third key can encrypt", - KeyFlags.ENCRYPT_COMMS, it.next().getKeyUsage()); + KeyFlags.ENCRYPT_COMMS, subkeys.get(2).getKeyUsage()); } diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringCanonicalizeTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java index 97e0d8a68..24b9a3fb6 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringCanonicalizeTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java @@ -1,4 +1,4 @@ -package org.sufficientlysecure.keychain.tests; +package org.sufficientlysecure.keychain.pgp; import org.junit.BeforeClass; import org.junit.runner.RunWith; @@ -26,11 +26,6 @@ import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; -import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; -import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringMergeTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java index 977ddfc52..6b19e3c55 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringMergeTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java @@ -1,4 +1,4 @@ -package org.sufficientlysecure.keychain.tests; +package org.sufficientlysecure.keychain.pgp; import org.junit.Assert; import org.junit.Before; @@ -10,13 +10,6 @@ import org.robolectric.shadows.ShadowLog; import org.spongycastle.bcpg.PacketTags; import org.spongycastle.bcpg.sig.KeyFlags; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; -import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java index 15aaa4c5d..e0772a7dc 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/UncachedKeyringTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java @@ -1,4 +1,4 @@ -package org.sufficientlysecure.keychain.tests; +package org.sufficientlysecure.keychain.pgp; import org.junit.Assert; import org.junit.Before; @@ -9,21 +9,15 @@ import org.robolectric.RobolectricTestRunner; 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.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket; -import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Iterator; -import java.util.List; @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/ProviderHelperKeyringTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java index 665e8ef2b..b0f47af29 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/tests/ProviderHelperKeyringTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java @@ -15,7 +15,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package tests; +package org.sufficientlysecure.keychain.provider; import java.util.Collections; import java.util.Arrays; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/util/FileImportCacheTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/util/FileImportCacheTest.java new file mode 100644 index 000000000..b5708b46f --- /dev/null +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/util/FileImportCacheTest.java @@ -0,0 +1,54 @@ +package org.sufficientlysecure.keychain.util; + +import android.os.Bundle; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.shadows.ShadowLog; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +@org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 +public class FileImportCacheTest { + + @Before + public void setUp() throws Exception { + ShadowLog.stream = System.out; + } + + @Test + public void testInputOutput() throws Exception { + + FileImportCache<Bundle> cache = new FileImportCache<Bundle>(Robolectric.application); + + ArrayList<Bundle> list = new ArrayList<Bundle>(); + + for (int i = 0; i < 50; i++) { + Bundle b = new Bundle(); + b.putInt("key1", i); + b.putString("key2", Integer.toString(i)); + list.add(b); + } + + // write to cache file + cache.writeCache(list); + + // read back + List<Bundle> last = cache.readCacheIntoList(); + + for (int i = 0; i < list.size(); i++) { + Assert.assertEquals("input values should be equal to output values", + list.get(i).getInt("key1"), last.get(i).getInt("key1")); + Assert.assertEquals("input values should be equal to output values", + list.get(i).getString("key2"), last.get(i).getString("key2")); + } + + } + +} |