diff --git a/build.gradle b/build.gradle index 34131f2..5efb5cb 100644 --- a/build.gradle +++ b/build.gradle @@ -17,17 +17,6 @@ repositories { mavenCentral() } -loom { - runs { - testServer { - server() - ideConfigGenerated project.rootProject == project - name = "Testmod Server" - source sourceSets.test - } - } -} - dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" diff --git a/src/main/java/net/szum123321/textile_backup/TextileBackup.java b/src/main/java/net/szum123321/textile_backup/TextileBackup.java index f4b97b8..853aa3e 100644 --- a/src/main/java/net/szum123321/textile_backup/TextileBackup.java +++ b/src/main/java/net/szum123321/textile_backup/TextileBackup.java @@ -27,7 +27,6 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.Version; import net.minecraft.server.command.ServerCommandSource; import net.szum123321.textile_backup.commands.create.CleanupCommand; import net.szum123321.textile_backup.commands.create.StartBackupCommand; @@ -43,11 +42,11 @@ import net.szum123321.textile_backup.core.ActionInitiator; import net.szum123321.textile_backup.core.create.BackupContext; import net.szum123321.textile_backup.core.create.BackupScheduler; import net.szum123321.textile_backup.core.create.MakeBackupRunnableFactory; +import net.szum123321.textile_backup.test.BalticHashTest; public class TextileBackup implements ModInitializer { public static final String MOD_NAME = "Textile Backup"; public static final String MOD_ID = "textile_backup"; - public static final Version VERSION; private final static TextileLogger log = new TextileLogger(MOD_NAME); private final static ConfigHelper config = ConfigHelper.INSTANCE; @@ -62,6 +61,11 @@ public class TextileBackup implements ModInitializer { log.info("Starting Textile Backup {} by Szum123321", Globals.INSTANCE.getCombinedVersionString()); + if(FabricLoader.getInstance().isDevelopmentEnvironment()) { + //Run the tests + BalticHashTest.run(); + } + ConfigHelper.updateInstance(AutoConfig.register(ConfigPOJO.class, JanksonConfigSerializer::new)); ServerTickEvents.END_SERVER_TICK.register(BackupScheduler::tick); @@ -114,9 +118,4 @@ public class TextileBackup implements ModInitializer { .then(KillRestoreCommand.register()) )); } - - static { - VERSION = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().getMetadata().getVersion(); - FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion(); - } } diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java index b1892b9..2be911e 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java @@ -51,10 +51,10 @@ public class BalticHash implements Hash { } public void update(byte[] data, int off, int len) { - int pos = off; + int pos = 0; while(pos < len) { int n = Math.min(len - pos, buffer_limit - buffer.position()); - System.arraycopy(data, pos, _byte_buffer, buffer.position(), n); + System.arraycopy(data, off + pos, _byte_buffer, buffer.position(), n); pos += n; buffer.position(buffer.position() + n); if(buffer.position() >= buffer_limit) round(); diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHashSIMD.java b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHashSIMD.java index 2e15c56..5bd5753 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHashSIMD.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHashSIMD.java @@ -51,9 +51,10 @@ public class BalticHashSIMD extends BalticHash {/* return xorshift64star(result); } +//This is wrong. will have to correct ( @Override public void update(byte[] data, int off, int len) { - int pos = off; + int pos = off; //should be = 0 while (pos < len) { int n = Math.min(len - pos, buffer_limit - buffer.position()); if (n == 32) { diff --git a/src/main/java/net/szum123321/textile_backup/test/BalticHashTest.java b/src/main/java/net/szum123321/textile_backup/test/BalticHashTest.java new file mode 100644 index 0000000..55300fd --- /dev/null +++ b/src/main/java/net/szum123321/textile_backup/test/BalticHashTest.java @@ -0,0 +1,63 @@ +/* + * A simple backup mod for Fabric + * Copyright (C) 2022 Szum123321 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.szum123321.textile_backup.test; + +import net.minecraft.util.math.random.Random; +import net.szum123321.textile_backup.TextileBackup; +import net.szum123321.textile_backup.TextileLogger; +import net.szum123321.textile_backup.core.digest.BalticHash; + +public class BalticHashTest { + private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); + final static int TEST_LEN = 21377; //simple prime + public static void run() throws RuntimeException { + log.info("Running hash test"); + Random r = Random.create(2137); + long x = 0; + + byte[] data = new byte[TEST_LEN]; + + for(int i = 0; i < TEST_LEN; i++) data[i] = (byte)r.nextInt(); + + //Test block mode + for(int i = 0; i < 5*2; i++) x ^= randomHash(data, r); + if(x != 0) throw new RuntimeException("Hash mismatch!"); + + log.info("Test passed"); + } + + static long randomHash(byte[] data, Random r) { + int n = data.length; + + BalticHash h = new BalticHash(); + + int m = r.nextBetween(1, n); + + int nn = n, p = 0; + + for(int i = 0; i < m; i++) { + int k = r.nextBetween(1, nn - (m - i - 1)); + h.update(data, p, k); + p += k; + nn -= k; + } + + return h.getValue(); + } +} diff --git a/src/test/java/net/szum123321/test/textile_backup/TextileBackupTest.java b/src/test/java/net/szum123321/test/textile_backup/TextileBackupTest.java deleted file mode 100644 index bd646f2..0000000 --- a/src/test/java/net/szum123321/test/textile_backup/TextileBackupTest.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.szum123321.test.textile_backup; - -import net.fabricmc.api.ModInitializer; - -public class TextileBackupTest implements ModInitializer { - @Override - public void onInitialize() { - - } -} diff --git a/src/test/resources/fabric.mod.json b/src/test/resources/fabric.mod.json deleted file mode 100644 index 809dace..0000000 --- a/src/test/resources/fabric.mod.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "schemaVersion": 1, - "id": "textile_backup", - "version": "${version}", - - "name": "Textile Backup Test", - "authors": [ - "Szum123321" - ], - "contact": { - "homepage": "https://www.curseforge.com/minecraft/mc-mods/textile-backup", - "issues": "https://github.com/Szum123321/textile_backup/issues", - "sources": "https://github.com/Szum123321/textile_backup" - }, - - "license": "GPLv3", - - "environment": "*", - "entrypoints": { - "main": [ - "net.szum123321.test.textile_backup.TextileBackupTest" - ] - }, - "mixins": [ - ], - - "depends": { - "fabricloader": ">=0.14.6", - "fabric": "*", - "minecraft": ">=1.19.1", - "cloth-config2": "*", - "java": ">=16", - "textile_backup": "*" - } -} \ No newline at end of file diff --git a/src/test/resources/textile_backup-test.mixins.json b/src/test/resources/textile_backup-test.mixins.json deleted file mode 100644 index f858f63..0000000 --- a/src/test/resources/textile_backup-test.mixins.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required": true, - "package": "net.szum123321.test.textile_backup.mixin", - "compatibilityLevel": "JAVA_16", - "mixins": [ - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -}