From 9971f9ad4cf0c06bb6ab22f9cee16f1a91370365 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 7 Jul 2014 18:53:41 +0200 Subject: [PATCH] use KeyringTestHelper.diffKeyrings method for unit test Conflicts: OpenKeychain/src/test/java/tests/UncachedKeyringTest.java --- .../testsupport/KeyringTestingHelper.java | 2 +- .../test/java/tests/UncachedKeyringTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java index da0f47e99..768f2f6c4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java @@ -60,7 +60,7 @@ public class KeyringTestingHelper { } public int hashCode() { - System.out.println("tag: " + tag + ", code: " + Arrays.hashCode(buf)); + // System.out.println("tag: " + tag + ", code: " + Arrays.hashCode(buf)); return Arrays.hashCode(buf); } } diff --git a/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java b/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java index 1f5bb82bd..c0f7bf17e 100644 --- a/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java +++ b/OpenKeychain/src/test/java/tests/UncachedKeyringTest.java @@ -5,7 +5,11 @@ 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.*; @@ -21,6 +25,20 @@ public class UncachedKeyringTest { // 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(); + HashSet onlyB = new HashSet(); + Assert.assertTrue(KeyringTestingHelper.diffKeyrings( + canonicalizedRing.getEncoded(), expectedKeyRing.getEncoded(), onlyA, onlyB)); + + }