Skip to content
Snippets Groups Projects
Verified Commit f3825ad5 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

file testing

parent a631cabf
No related branches found
No related tags found
No related merge requests found
Pipeline #7936 passed
...@@ -6,8 +6,8 @@ import java.io.*; ...@@ -6,8 +6,8 @@ import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Base64;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
public class Main { public class Main {
...@@ -23,6 +23,10 @@ public class Main { ...@@ -23,6 +23,10 @@ public class Main {
return sb.toString(); return sb.toString();
} }
private static byte[] decodeB64(String input) {
return Base64.getDecoder().decode(input);
}
private static boolean runTest(String jarfile, String testName) throws FileNotFoundException { private static boolean runTest(String jarfile, String testName) throws FileNotFoundException {
System.out.printf("Running test \"%s\"\n", testName); System.out.printf("Running test \"%s\"\n", testName);
...@@ -97,8 +101,8 @@ public class Main { ...@@ -97,8 +101,8 @@ public class Main {
System.out.printf("File: %s\n", f); System.out.printf("File: %s\n", f);
System.out.println(); System.out.println();
try { try {
String got = fileToString(f); byte[] got = Files.readAllBytes(Paths.get(f));
boolean erro = compareStrings(got, e); boolean erro = compareFiles(got, decodeB64(e));
if (erro) { if (erro) {
error.set(true); error.set(true);
} else { } else {
...@@ -211,10 +215,19 @@ public class Main { ...@@ -211,10 +215,19 @@ public class Main {
return error; return error;
} }
private static String fileToString(String path) throws IOException { private static boolean compareFiles(byte[] got, byte[] expect) {
StringBuilder build = new StringBuilder(); if (got.length != expect.length) {
Stream<String> stream = Files.lines(Paths.get(path), StandardCharsets.UTF_8); System.out.println("❌ A fájlméretek különböznek");
stream.forEach(s -> build.append(s).append("\n")); return false;
return build.toString(); }
var err = false;
for (int i = 0; i < expect.length; i++) {
if (got[i] != expect[i]) {
System.out.printf("❌ A %d. byte (karakter) nem passzol\n", i);
err = true;
}
}
return err;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment