mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
test: fix RawPacket comparator
This commit is contained in:
parent
fa00a5b23c
commit
d0ff2c9f28
@ -28,8 +28,10 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.SortedSet;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for tests of the Keyring import in ProviderHelper.
|
* Helper for tests of the Keyring import in ProviderHelper.
|
||||||
@ -66,16 +68,12 @@ public class KeyringTestingHelper {
|
|||||||
return saveSuccess;
|
return saveSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RawPacket implements Comparable<RawPacket> {
|
public static class RawPacket {
|
||||||
public int position;
|
public int position;
|
||||||
public int tag;
|
public int tag;
|
||||||
public int length;
|
public int length;
|
||||||
public byte[] buf;
|
public byte[] buf;
|
||||||
|
|
||||||
public int compareTo(RawPacket other) {
|
|
||||||
return Integer.compare(position, other.position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof RawPacket && Arrays.areEqual(this.buf, ((RawPacket) other).buf);
|
return other instanceof RawPacket && Arrays.areEqual(this.buf, ((RawPacket) other).buf);
|
||||||
}
|
}
|
||||||
@ -86,8 +84,14 @@ public class KeyringTestingHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Comparator<RawPacket> packetOrder = new Comparator<RawPacket>() {
|
||||||
|
public int compare(RawPacket left, RawPacket right) {
|
||||||
|
return Integer.compare(left.position, right.position);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static boolean diffKeyrings(byte[] ringA, byte[] ringB,
|
public static boolean diffKeyrings(byte[] ringA, byte[] ringB,
|
||||||
SortedSet<RawPacket> onlyA, SortedSet<RawPacket> onlyB)
|
List<RawPacket> onlyA, List<RawPacket> onlyB)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
InputStream streamA = new ByteArrayInputStream(ringA);
|
InputStream streamA = new ByteArrayInputStream(ringA);
|
||||||
InputStream streamB = new ByteArrayInputStream(ringB);
|
InputStream streamB = new ByteArrayInputStream(ringB);
|
||||||
@ -119,6 +123,9 @@ public class KeyringTestingHelper {
|
|||||||
onlyB.addAll(b);
|
onlyB.addAll(b);
|
||||||
onlyB.removeAll(a);
|
onlyB.removeAll(a);
|
||||||
|
|
||||||
|
Collections.sort(onlyA, packetOrder);
|
||||||
|
Collections.sort(onlyB, packetOrder);
|
||||||
|
|
||||||
return !onlyA.isEmpty() || !onlyB.isEmpty();
|
return !onlyA.isEmpty() || !onlyB.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user