aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-07-10 01:38:57 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-07-10 01:38:57 +0200
commit90f546a4e877972d6686745aabfac1fca1178b8c (patch)
tree67ea73808bc4577009ff8d2f9bd9a8e3e7e46ae5 /OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
parent0afd979665ca17ece970df5a5f0b466346be72f1 (diff)
downloadopen-keychain-90f546a4e877972d6686745aabfac1fca1178b8c.tar.gz
open-keychain-90f546a4e877972d6686745aabfac1fca1178b8c.tar.bz2
open-keychain-90f546a4e877972d6686745aabfac1fca1178b8c.zip
tests: add testSubkeyAdd
Diffstat (limited to 'OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java')
-rw-r--r--OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java23
1 files changed, 17 insertions, 6 deletions
diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
index 4c779d2b7..ac9bed898 100644
--- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
+++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java
@@ -30,6 +30,7 @@ import java.io.InputStream;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.SortedSet;
/**
* Helper for tests of the Keyring import in ProviderHelper.
@@ -66,10 +67,15 @@ public class KeyringTestingHelper {
return saveSuccess;
}
- public static class Packet {
- int tag;
- int length;
- byte[] buf;
+ public static class Packet implements Comparable<Packet> {
+ public int position;
+ public int tag;
+ public int length;
+ public byte[] buf;
+
+ public int compareTo(Packet other) {
+ return Integer.compare(position, other.position);
+ }
public boolean equals(Object other) {
return other instanceof Packet && Arrays.areEqual(this.buf, ((Packet) other).buf);
@@ -81,7 +87,8 @@ public class KeyringTestingHelper {
}
}
- public static boolean diffKeyrings(byte[] ringA, byte[] ringB, Set<Packet> onlyA, Set<Packet> onlyB)
+ public static boolean diffKeyrings(byte[] ringA, byte[] ringB,
+ SortedSet<Packet> onlyA, SortedSet<Packet> onlyB)
throws IOException {
InputStream streamA = new ByteArrayInputStream(ringA);
InputStream streamB = new ByteArrayInputStream(ringB);
@@ -89,18 +96,22 @@ public class KeyringTestingHelper {
HashSet<Packet> a = new HashSet<Packet>(), b = new HashSet<Packet>();
Packet p;
+ int pos = 0;
while(true) {
p = readPacket(streamA);
if (p == null) {
break;
}
+ p.position = pos++;
a.add(p);
}
+ pos = 0;
while(true) {
p = readPacket(streamB);
if (p == null) {
break;
}
+ p.position = pos++;
b.add(p);
}
@@ -109,7 +120,7 @@ public class KeyringTestingHelper {
onlyB.addAll(b);
onlyB.removeAll(a);
- return onlyA.isEmpty() && onlyB.isEmpty();
+ return !onlyA.isEmpty() || !onlyB.isEmpty();
}
private static Packet readPacket(InputStream in) throws IOException {