mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
WiP: Implement first prototypes of all SOP commands for external binaries
This commit is contained in:
parent
efec4d9110
commit
a63b29fe80
21 changed files with 1473 additions and 146 deletions
53
external-sop/src/test/java/sop/external/JUtils.java
vendored
Normal file
53
external-sop/src/test/java/sop/external/JUtils.java
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class JUtils {
|
||||
|
||||
public static boolean arrayStartsWith(byte[] array, byte[] start) {
|
||||
return arrayStartsWith(array, start, 0);
|
||||
}
|
||||
|
||||
public static boolean arrayStartsWith(byte[] array, byte[] start, int offset) {
|
||||
if (offset < 0) {
|
||||
throw new IllegalArgumentException("Offset cannot be negative");
|
||||
}
|
||||
|
||||
if (start.length + offset > array.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < start.length; i++) {
|
||||
if (array[offset + i] != start[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void assertArrayStartsWith(byte[] array, byte[] start) {
|
||||
if (!arrayStartsWith(array, start)) {
|
||||
byte[] actual = new byte[Math.min(start.length, array.length)];
|
||||
System.arraycopy(array, 0, actual, 0, actual.length);
|
||||
fail("Array does not start with expected bytes.\n" +
|
||||
"Expected: <" + Arrays.toString(start) + ">\n" +
|
||||
"Actual: <" + Arrays.toString(actual) + ">");
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertArrayStartsWith(byte[] array, byte[] start, int offset) {
|
||||
if (!arrayStartsWith(array, start, offset)) {
|
||||
byte[] actual = new byte[Math.min(start.length, array.length - offset)];
|
||||
System.arraycopy(array, offset, actual, 0, actual.length);
|
||||
fail("Array does not start with expected bytes at offset " + offset + ".\n" +
|
||||
"Expected: <" + Arrays.toString(start) + ">\n" +
|
||||
"Actual: <" + Arrays.toString(actual) + ">");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue