Browse Source

AdapterTestUtils: diff now returns new obj DiffResult

JNI-147
heck 4 years ago
parent
commit
b7b8103b8e
  1. 25
      test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java
  2. 46
      test/java/foundation/pEp/jniadapter/test/utils/DiffResult.java

25
test/java/foundation/pEp/jniadapter/test/utils/AdapterTestUtils.java

@ -343,26 +343,31 @@ public class AdapterTestUtils {
return msg; return msg;
} }
public static String diff(byte[] left, byte[] right, boolean verbose) {
String ret = "";
public static DiffResult diff(byte[] left, byte[] right) {
DiffResult ret = new DiffResult();
String diffString = ""; String diffString = "";
int diffCount = 0; int diffCount = 0;
int firstDiff = 0;
boolean firstDiffHappened = false;
for (int i = 0; i < left.length; i++) { for (int i = 0; i < left.length; i++) {
byte bLeft = left[i]; byte bLeft = left[i];
byte bRight = right[i]; byte bRight = right[i];
String diffIndicator = ""; String diffIndicator = "";
if (bLeft != bRight) { if (bLeft != bRight) {
if(!firstDiffHappened) {
firstDiff = i;
firstDiffHappened = true;
}
diffCount++; diffCount++;
diffString += "Byte[" + i + "]:\t\t " + bLeft + "\t" + bRight + "\t" + "\n"; diffString += "Byte[" + i + "]:\t\t " + bLeft + "\t" + bRight + "\t" + "\n";
} }
} }
if (verbose) { ret.setDiff(diffString);
ret = diffString + "\n"; ret.setCount(diffCount);
ret += Integer.toString(diffCount) + "\t Different bytes"; ret.setFirstDiffByte(firstDiff);
} else {
ret = Integer.toString(diffCount);
}
return ret; return ret;
} }
} }

46
test/java/foundation/pEp/jniadapter/test/utils/DiffResult.java

@ -0,0 +1,46 @@
package foundation.pEp.jniadapter.test.utils;
public class DiffResult {
private String diff = "";
private int count = 0;
private int firstDiffByte = 0;
DiffResult() {
}
public String getDiff() {
return diff;
}
public void setDiff(String diff) {
this.diff = diff;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getFirstDiffByte() {
return firstDiffByte;
}
public void setFirstDiffByte(int firstDiffByte) {
this.firstDiffByte = firstDiffByte;
}
public String toString() {
String ret = "";
ret += "Nr bytes differ\t: " + getCount() + "\n";
ret += "first byte\t: " + getFirstDiffByte() + "\n";
ret += "diff:\n";
ret += getDiff();
ret += "\n";
return ret;
}
}
Loading…
Cancel
Save