use KeyringTestHelper.diffKeyrings method for unit test

Conflicts:
	OpenKeychain/src/test/java/tests/UncachedKeyringTest.java
This commit is contained in:
Vincent Breitmoser 2014-07-07 18:53:41 +02:00 committed by Art O Cathain
parent 83e5a3d341
commit 9971f9ad4c
2 changed files with 19 additions and 1 deletions

View File

@ -60,7 +60,7 @@ public class KeyringTestingHelper {
} }
public int hashCode() { 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); return Arrays.hashCode(buf);
} }
} }

View File

@ -5,7 +5,11 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.*; import org.robolectric.*;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.testsupport.*; 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.util.*;
import java.io.*; import java.io.*;
@ -21,6 +25,20 @@ public class UncachedKeyringTest {
// Uncomment to dump the encoded key for manual inspection // Uncomment to dump the encoded key for manual inspection
// TestDataUtil.appendToOutput(new ByteArrayInputStream(inputKeyRing.getEncoded()), new FileOutputStream(new File("/tmp/key-encoded"))); // TestDataUtil.appendToOutput(new ByteArrayInputStream(inputKeyRing.getEncoded()), new FileOutputStream(new File("/tmp/key-encoded")));
new UncachedKeyringTestingHelper().doTestCanonicalize(inputKeyRing, expectedKeyRing); 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));
} }