FML is no more. FML has ceased to be. FML's expired and gone to meet its maker. FML's a stiff! Bereft of life, FML rests in peace.

This commit is contained in:
cpw committed 2015-08-01 23:51:40 -04:00
1 parent 9a859f8d5c
commit 614bbcb0da
356 files changed
+2676 -235

No files matched your search

@@ -0,0 +1,29 @@
package net.minecraftforge.fml.debug;
import java.util.Map;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
public class FaultyCoreMod implements IFMLLoadingPlugin {
public static boolean enabled = false;
public String[] getASMTransformerClass()
{
return new String[] { FaultyTransformer.class.getName() };
}
public String getModContainerClass() { return null; }
public String getSetupClass() { return null; }
public void injectData(Map<String, Object> data) {}
public String getAccessTransformerClass() { return null; }
public static class FaultyTransformer implements IClassTransformer {
public byte[] transform(String name, String transformedName, byte[] basicClass)
{
if(enabled && name.equals("net.minecraft.client.gui.GuiMainMenu")) throw new RuntimeException("Faulty transformer test exception");
return basicClass;
}
}
}
@@ -0,0 +1,26 @@
/*package net.minecraftforge.fml.debug;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@Mod(modid = Java8Debug.MODID, version = Java8Debug.VERSION)
public class Java8Debug implements ITest
{
public static final String MODID = "Java8Debug";
public static final String VERSION = "1.0";
@EventHandler
public void init(FMLInitializationEvent event)
{
System.out.println("Java8Debug mod loaded");
}
}
interface ITest
{
default int test()
{
return 42;
}
}*/
@@ -0,0 +1,176 @@
package net.minecraftforge.fml.test;
import static org.junit.Assert.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import org.junit.Test;
import com.google.common.base.Strings;
public class TestNetStuff {
@Test
public void testByteBufUtilsByteCount()
{
assertEquals("length of 1 is 1", 1, ByteBufUtils.varIntByteCount(1));
assertEquals("length of 127 is 1", 1, ByteBufUtils.varIntByteCount(127));
assertEquals("length of 128 is 2", 2, ByteBufUtils.varIntByteCount(128));
assertEquals("length of 16383 is 2", 2, ByteBufUtils.varIntByteCount(16383));
assertEquals("length of 16384 is 3", 3, ByteBufUtils.varIntByteCount(16384));
assertEquals("length of 2097151 is 3", 3, ByteBufUtils.varIntByteCount(2097151));
assertEquals("length of 2097152 is 4", 4, ByteBufUtils.varIntByteCount(2097152));
assertEquals("length of 268435455 is 4", 4, ByteBufUtils.varIntByteCount(268435455));
assertEquals("length of 268435456 is 5", 5, ByteBufUtils.varIntByteCount(268435456));
assertEquals("length of MIN_VAL is 5", 5, ByteBufUtils.varIntByteCount(Integer.MIN_VALUE));
assertEquals("length of MAX_VAL is 5", 5, ByteBufUtils.varIntByteCount(Integer.MAX_VALUE));
assertEquals("length of -1 is 5", 5, ByteBufUtils.varIntByteCount(-1));
}
@Test
public void testByteBufUtilsByteArrays()
{
ByteBuf buf = Unpooled.buffer(5, 5);
ByteBufUtils.writeVarInt(buf, 1, 1);
assertArrayEquals("1 as byte[] is [1]", new byte[] { 1, 0, 0, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 127, 1);
assertArrayEquals("127 as byte[] is [127]", new byte[] { 127, 0, 0, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 128, 2);
assertArrayEquals("128 as byte[] is [-128, 1]", new byte[] { -128, 1, 0, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 16383, 2);
assertArrayEquals("16383 as byte[] is [-1, 127]", new byte[] { -1, 127, 0, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 16384, 3);
assertArrayEquals("16384 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, 1, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 2097151, 3);
assertArrayEquals("2097151 as byte[] is [-1, -1, 127]", new byte[] { -1, -1, 127, 0, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 2097152, 4);
assertArrayEquals("16384 as byte[] is [-128, -128, 1]", new byte[] { -128, -128, -128, 1, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 268435455, 4);
assertArrayEquals("268435455 as byte[] is [-1, -1, -1, 127]", new byte[] { -1, -1, -1, 127, 0 }, buf.array());
buf.clear();
ByteBufUtils.writeVarInt(buf, 268435456, 5);
assertArrayEquals("268435456 as byte[] is [-1, -128, 1]", new byte[] { -128, -128, -128, -128, 1 }, buf.array());
}
@Test
public void testByteBufUtilsByteReversals()
{
ByteBuf buf = Unpooled.buffer(5, 5);
ByteBufUtils.writeVarInt(buf, 1, 1);
assertEquals("1 is 1", 1, ByteBufUtils.readVarInt(buf, 1));
buf.clear();
ByteBufUtils.writeVarInt(buf, 127, 1);
assertEquals("127 is 127", 127, ByteBufUtils.readVarInt(buf, 1));
buf.clear();
ByteBufUtils.writeVarInt(buf, 128, 2);
assertEquals("128 is 128", 128, ByteBufUtils.readVarInt(buf, 2));
buf.clear();
ByteBufUtils.writeVarInt(buf, 16383, 2);
assertEquals("16383 is 16383", 16383, ByteBufUtils.readVarInt(buf, 2));
buf.clear();
ByteBufUtils.writeVarInt(buf, 16384, 3);
assertEquals("16384 is 16384", 16384, ByteBufUtils.readVarInt(buf, 3));
buf.clear();
ByteBufUtils.writeVarInt(buf, 2097151, 3);
assertEquals("2097151 is 2097151", 2097151, ByteBufUtils.readVarInt(buf, 3));
buf.clear();
ByteBufUtils.writeVarInt(buf, 2097152, 4);
assertEquals("2097152 is 2097152", 2097152, ByteBufUtils.readVarInt(buf, 4));
buf.clear();
ByteBufUtils.writeVarInt(buf, 268435455, 4);
assertEquals("268435455 is 268435455", 268435455, ByteBufUtils.readVarInt(buf, 4));
buf.clear();
ByteBufUtils.writeVarInt(buf, 268435456, 5);
assertEquals("268435456 is 268435456", 268435456, ByteBufUtils.readVarInt(buf, 5));
}
@Test
public void testByteBufUtilsStrings()
{
String test = new String("test");
ByteBuf buf = Unpooled.buffer(20, 20);
ByteBufUtils.writeUTF8String(buf, test);
assertArrayEquals("String bytes", new byte[] { 4, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buf.array());
String repeat = Strings.repeat("test", 100);
buf = Unpooled.buffer(420, 420);
ByteBufUtils.writeUTF8String(buf, repeat);
assertArrayEquals("String repeat bytes", new byte[] {-112, 3, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, buf.array());
}
@Test
public void testVarShort()
{
ByteBuf buf = Unpooled.buffer(3,3);
ByteBufUtils.writeVarShort(buf, 32766);
assertArrayEquals("Two byte short written", new byte[] { 127, -2, 0}, buf.array());
assertEquals("Two byte short written", 2, buf.readableBytes());
buf.clear();
buf.writeZero(3);
buf.clear();
buf.writeShort(32766);
assertArrayEquals("Two byte short written", new byte[] { 127, -2, 0}, buf.array());
int val = ByteBufUtils.readVarShort(buf);
assertEquals("Two byte short read correctly", 32766, val);
buf.clear();
buf.writeZero(3);
buf.clear();
ByteBufUtils.writeVarShort(buf, 32768);
assertArrayEquals("Three byte short written", new byte[] { -128, 0, 1}, buf.array());
assertEquals("Three byte short written", 3, buf.readableBytes());
buf.clear();
buf.writeZero(3);
buf.clear();
buf.writeShort(-32768);
buf.writeByte(1);
val = ByteBufUtils.readVarShort(buf);
assertEquals("Three byte short read correctly", 32768, val);
buf.clear();
buf.writeZero(3);
buf.clear();
ByteBufUtils.writeVarShort(buf, 8388607);
assertArrayEquals("Three byte short written", new byte[] { -1, -1, -1}, buf.array());
assertEquals("Three byte short written", 3, buf.readableBytes());
buf.clear();
buf.writeZero(3);
buf.clear();
buf.writeShort(-1);
buf.writeByte(-1);
val = ByteBufUtils.readVarShort(buf);
assertEquals("Three byte short read correctly", 8388607, val);
}
}
@@ -0,0 +1,14 @@
package net.minecraftforge.fml.test.simplenet;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class SimpleNetHandler1 implements IMessageHandler<SimpleNetTestMessage1, SimpleNetTestMessage2>
{
@Override
public SimpleNetTestMessage2 onMessage(SimpleNetTestMessage1 message, MessageContext context)
{
return null;
}
}
@@ -0,0 +1,14 @@
package net.minecraftforge.fml.test.simplenet;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class SimpleNetHandler2 implements IMessageHandler<SimpleNetTestMessage2, SimpleNetTestMessage1>
{
@Override
public SimpleNetTestMessage1 onMessage(SimpleNetTestMessage2 message, MessageContext context)
{
return null;
}
}
@@ -0,0 +1,17 @@
package net.minecraftforge.fml.test.simplenet;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import io.netty.buffer.ByteBuf;
public class SimpleNetTestMessage1 implements IMessage {
@Override
public void fromBytes(ByteBuf buf)
{
}
@Override
public void toBytes(ByteBuf buf)
{
}
}
@@ -0,0 +1,18 @@
package net.minecraftforge.fml.test.simplenet;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import io.netty.buffer.ByteBuf;
public class SimpleNetTestMessage2 implements IMessage {
@Override
public void fromBytes(ByteBuf buf)
{
}
@Override
public void toBytes(ByteBuf buf)
{
}
}
@@ -0,0 +1,21 @@
package net.minecraftforge.fml.test.simplenet;
import static org.junit.Assert.*;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import org.junit.Test;
public class SimpleNetTester {
@Test
public void test()
{
SimpleNetworkWrapper simpleChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TEST");
simpleChannel.registerMessage(SimpleNetHandler1.class, SimpleNetTestMessage1.class, 1, Side.SERVER);
simpleChannel.registerMessage(SimpleNetHandler2.class, SimpleNetTestMessage2.class, 2, Side.CLIENT);
assertTrue("Hello", true);
}
}