|
| 1 | +/* |
| 2 | + * Hello Minecraft! Launcher |
| 3 | + * Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package org.glavo.nbt.io; |
| 19 | + |
| 20 | +import org.glavo.nbt.internal.ChunkUtils; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import java.nio.file.Path; |
| 24 | + |
| 25 | +import static org.junit.jupiter.api.Assertions.*; |
| 26 | + |
| 27 | +public final class OversizedChunkLocatorTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + void testEmptyLocator() { |
| 31 | + OversizedChunkLocator<Path> locator = OversizedChunkLocator.emptyLocator(); |
| 32 | + |
| 33 | + Path source = Path.of("r.0.0.mca"); |
| 34 | + for (int i = 0; i < ChunkUtils.CHUNKS_PER_REGION_SIDE; i++) { |
| 35 | + for (int j = 0; j < ChunkUtils.CHUNKS_PER_REGION_SIDE; j++) { |
| 36 | + assertNull(locator.locate(source, i, j)); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + assertThrows(IndexOutOfBoundsException.class, () -> locator.locate(source, -1, 0)); |
| 41 | + assertThrows(IndexOutOfBoundsException.class, () -> locator.locate(source, 0, -1)); |
| 42 | + assertThrows(IndexOutOfBoundsException.class, () -> locator.locate(source, ChunkUtils.CHUNKS_PER_REGION_SIDE, 0)); |
| 43 | + assertThrows(IndexOutOfBoundsException.class, () -> locator.locate(source, 32, 0)); |
| 44 | + assertThrows(IndexOutOfBoundsException.class, () -> locator.locate(source, 0, 32)); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void testDefaultLocator() { |
| 49 | + OversizedChunkLocator<Path> locator = OversizedChunkLocator.defaultLocator(); |
| 50 | + |
| 51 | + assertEquals(Path.of("c.0.0.mcc"), locator.locate(Path.of("r.0.0.mca"), 0, 0)); |
| 52 | + assertEquals(Path.of("c.31.31.mcc"), locator.locate(Path.of("r.0.0.mca"), 31, 31)); |
| 53 | + assertEquals(Path.of("c.37.70.mcc"), locator.locate(Path.of("r.1.2.mca"), 5, 6)); |
| 54 | + assertEquals(Path.of("c.-27.70.mcc"), locator.locate(Path.of("r.-1.2.mca"), 5, 6)); |
| 55 | + } |
| 56 | +} |
0 commit comments