mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-17 02:55:21 +00:00
test: characterize MultiPartRegistry
Splits the characterization across both layers, because part registration needs FML's active mod container and throws without one, so it cannot run headless at all. Plain JVM covers what is reachable: converters are dispatched per block, a converter returning null does not stop the scan, converters registered for another block are never consulted, a converter claiming several blocks is registered for each, and an unknown mod container throws rather than returning null. The Forge server suite covers registration itself, and deliberately exercises both overloads downstream depends on. Content registers through the deprecated IPartFactory array form that seven jars use, and each microblock class registers through the IPartFactory2 varargs form that ProjRed uses, so resolving mc_torch and mcr_face proves both paths. Part ids also round trip through the shared IDWriter carrier. 78 plain-JVM tests and 5 server tests, all passing against the untouched Scala.
This commit is contained in:
1 parent
9f454042b4
commit
ff380ee3bc
2 files changed
+181
No files matched your search
@@ -7,17 +7,28 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.data.MCDataOutputWrapper;
|
||||
import codechicken.microblock.FaceMicroClass$;
|
||||
import codechicken.microblock.HollowMicroClass$;
|
||||
import codechicken.microblock.Microblock;
|
||||
import codechicken.microblock.MicroblockGenerator;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.TFacePart;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import codechicken.multipart.asm.MultipartMixinFactory;
|
||||
import codechicken.multipart.scalatraits.TSlottedTile;
|
||||
@@ -65,6 +76,63 @@ class ForgeEnvironmentSmokeTest {
|
||||
assertFalse(((TFacePart) hollow).solid(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Part registration needs FML's active mod container, so none of this is reachable from a plain JVM test. Startup
|
||||
* exercises both overloads downstream depends on: Content registers through the deprecated IPartFactory array form,
|
||||
* and each microblock class registers through the IPartFactory2 varargs form.
|
||||
*/
|
||||
@Test
|
||||
void registryResolvesPartsRegisteredThroughBothFactoryOverloads() throws Exception {
|
||||
assertTrue(MultiPartRegistry.loaded(), "Registration must be closed once the server has started");
|
||||
|
||||
// mc_torch comes from the deprecated IPartFactory array overload.
|
||||
TMultiPart torch = MultiPartRegistry.loadPart("mc_torch", null);
|
||||
assertNotNull(torch);
|
||||
assertEquals("mc_torch", torch.getType());
|
||||
|
||||
// mcr_face comes from the IPartFactory2 varargs overload. Its factory reads the tag, so it needs a real one;
|
||||
// an absent material name resolves to the missing-material placeholder rather than failing.
|
||||
TMultiPart face = MultiPartRegistry.loadPart("mcr_face", new NBTTagCompound());
|
||||
assertNotNull(face);
|
||||
assertEquals("mcr_face", face.getType());
|
||||
|
||||
assertNotNull(MultiPartRegistry.getModContainer("mc_torch"));
|
||||
assertNotNull(MultiPartRegistry.getModContainer("mcr_face"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partIdsRoundTripThroughTheRegistryCarrier() {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
MCDataOutput output = new MCDataOutputWrapper(new DataOutputStream(bytes));
|
||||
TMultiPart torch = MultiPartRegistry.loadPart("mc_torch", null);
|
||||
MultiPartRegistry.writePartID(output, torch);
|
||||
|
||||
TMultiPart read = MultiPartRegistry.readPart(input(bytes.toByteArray()));
|
||||
|
||||
assertNotNull(read);
|
||||
assertEquals("mc_torch", read.getType());
|
||||
}
|
||||
|
||||
/** CodeChickenLib has no stream-backed MCDataInput, so the carrier reads are proxied. */
|
||||
private static MCDataInput input(byte[] bytes) {
|
||||
DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytes));
|
||||
return (MCDataInput) Proxy.newProxyInstance(
|
||||
MCDataInput.class.getClassLoader(),
|
||||
new Class<?>[] { MCDataInput.class },
|
||||
(proxy, method, arguments) -> {
|
||||
switch (method.getName()) {
|
||||
case "readUByte":
|
||||
return (short) data.readUnsignedByte();
|
||||
case "readUShort":
|
||||
return data.readUnsignedShort();
|
||||
case "readInt":
|
||||
return data.readInt();
|
||||
default:
|
||||
throw new AssertionError("Unexpected read method: " + method.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatesAndCachesSlottedTileClass() {
|
||||
int traitId = MultipartMixinFactory.getId(TSlottedTile.class.getName().replace('.', '/'));
|
||||
|
||||
Reference in new issue
Block a user