diff --git a/.gitignore b/.gitignore index 05b1bfc97..32258774f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ !/gradle/wrapper !/src !/api +!/test # files !/.gitignore diff --git a/build.gradle b/build.gradle index 4c6dda3ea..52424bc14 100755 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ buildscript { apply plugin: 'forge' apply plugin: 'maven' +apply plugin: 'java' loadProperties() @@ -74,6 +75,7 @@ configurations { dependencies { api 'net.industrial-craft:industrialcraft-2:2.2.713-experimental:api' api name: "buildcraft", version: "6.4.10", classifier: "dev" + testCompile 'junit:junit:4.12' } processResources { diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index bd865d45b..4bde750e6 100644 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -97,6 +97,10 @@ public class PluginManager { PLANTMEGAPACK(new PluginPlantMegaPack()), WITCHERY(new PluginWitchery()); + static { + ForestryAPI.enabledPlugins = new HashSet(); + } + private final ForestryPlugin instance; private final boolean canBeDisabled; @@ -220,7 +224,6 @@ public class PluginManager { unloadedModules.removeAll(toLoad); loadedModules.addAll(toLoad); - ForestryAPI.enabledPlugins = new HashSet(); for (Module m : loadedModules) { ForestryAPI.enabledPlugins.add(m.toString()); } diff --git a/test/ItemStackTest.java b/test/ItemStackTest.java new file mode 100644 index 000000000..8b858e2d7 --- /dev/null +++ b/test/ItemStackTest.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ + +import net.minecraft.item.ItemFirework; +import net.minecraft.item.ItemStack; + +import forestry.apiculture.items.ItemHoneycomb; +import forestry.core.utils.StackUtils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ItemStackTest { + + private ItemStack comb1; + private ItemStack comb2; + private ItemStack firework; + + @Before + public void setup() { + comb1 = new ItemStack(new ItemHoneycomb(), 32, 1); + comb2 = new ItemStack(new ItemHoneycomb(), 32, 2); + firework = new ItemStack(new ItemFirework(), 1, 0); + } + + @Test + public void testEquality() { + Assert.assertTrue("Equal ItemStacks are identical.", StackUtils.isIdenticalItem(comb1, comb1)); + Assert.assertTrue("Equal ItemStacks are identical.", StackUtils.isIdenticalItem(comb2, comb2)); + Assert.assertFalse("Unequal ItemStacks are not identical.", StackUtils.isIdenticalItem(comb1, comb2)); + + // OreDict crashes when minecraft hasn't loaded +// Assert.assertTrue("Different combs are crafting equivalent with Ore Dictionary.", StackUtils.isCraftingEquivalent(comb1, comb2, true, false)); +// Assert.assertFalse("Different combs are not crafting equivalent without Ore Dictionary.", StackUtils.isCraftingEquivalent(comb1, comb2, false, false)); +// +// Assert.assertFalse("Different items are not crafting equivalent with Ore Dictionary.", StackUtils.isCraftingEquivalent(firework, comb1, true, false)); +// Assert.assertFalse("Different items are not crafting equivalent without Ore Dictionary.", StackUtils.isCraftingEquivalent(firework, comb1, false, false)); + } +} diff --git a/test/NetworkTest.java b/test/NetworkTest.java new file mode 100644 index 000000000..92ec7c4f1 --- /dev/null +++ b/test/NetworkTest.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; + +import org.junit.Assert; +import org.junit.Test; + +public class NetworkTest { + @Test + public void testVarInt() { + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + DataOutputStreamForestry dataOutput = new DataOutputStreamForestry(bytesOut); + + final int oneByteThreshold = (int) Math.pow(2, 7); + final int twoByteThreshold = (int) Math.pow(2, 14); + final int threeByteThreshold = (int) Math.pow(2, 21); + final int fourByteThreshold = (int) Math.pow(2, 28); + + try { + int prevSize = 0; + for (int i = 0; i < Integer.MAX_VALUE; i = (i * 2) + 1) { + dataOutput.writeVarInt(i); + + int sizeGained = dataOutput.size() - prevSize; + prevSize = dataOutput.size(); + if (i < oneByteThreshold) { + Assert.assertEquals(1, sizeGained); + } else if (i < twoByteThreshold) { + Assert.assertEquals(2, sizeGained); + } else if (i < threeByteThreshold) { + Assert.assertEquals(3, sizeGained); + } else if (i < fourByteThreshold) { + Assert.assertEquals(4, sizeGained); + } else { + Assert.assertEquals(5, sizeGained); + } + } + } catch (IOException e) { + Assert.fail("Writing var int threw an exception."); + } + + ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesOut.toByteArray()); + DataInputStreamForestry dataInput = new DataInputStreamForestry(bytesIn); + + try { + for (int i = 0; i < Integer.MAX_VALUE; i = (i * 2) + 1) { + int varInt = dataInput.readVarInt(); + Assert.assertEquals("Var int didn't read back correctly", i, varInt); + } + } catch (IOException e) { + Assert.fail("Reading var int threw an exception."); + } + } +}