Fixup some registry tests, dummies are now persisted across syncing.

This commit is contained in:
LexManos committed 2017-06-23 16:59:57 -05:00
1 parent dee84dc1e4
commit e805b12df8
8 files changed
+100 -37

No files matched your search

@@ -70,9 +70,9 @@ public class DummyBlockReplacementTest
fnd = blockRegistry.getValue(myDirt);
assertNotEquals("Did not find my block", fnd, testDirtBlock);
assertTrue("Found a dummy air block", fnd.getClass().getName().endsWith("BlockDummyAir"));
assertTrue("Did not find a dummy air block", fnd.getClass().getName().endsWith("BlockDummyAir"));
final Set<ResourceLocation> dummied = RegistryManager.ACTIVE.takeSnapshot(false).get(GameData.BLOCKS).dummied;
assertTrue("Found my block in the dummy list", dummied.contains(myDirt));
assertTrue("Did not find my block in the dummy list", dummied.contains(myDirt));
GameData.revertToFrozen();
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
@@ -80,6 +80,7 @@ public class DummyBlockReplacementTest
assertNotEquals("Did not find my block", fnd, testDirtBlock);
assertEquals("Found a default air block", fnd, Blocks.AIR);
((ForgeRegistry<Block>)RegistryManager.ACTIVE.getRegistry(Block.class)).unfreeze();
RegistryManager.ACTIVE.getRegistry(Block.class).register(testDirtBlock.setRegistryName(myDirt));
fnd = blockRegistry.getValue(myDirt);
assertEquals("Found my block", fnd, testDirtBlock);
@@ -76,6 +76,7 @@ public class ForgeTestRunner extends Runner
{
try
{
System.setProperty("forge.disableVanillaGameData", "false");
innerRunnerClass.getMethod("run", RunNotifier.class).invoke(innerRunner, notifier);
}
catch (Exception e)
@@ -43,9 +43,13 @@ public class FreezingTests
{
setRegistryName(name);
}
@Override
public String toString()
{
return this.getRegistryName().toString();
}
}
public static IForgeRegistry<RTest> registry;
public static ResourceLocation resloc = new ResourceLocation("fmltest:test");
@BeforeClass
@@ -53,27 +57,33 @@ public class FreezingTests
{
Loader.instance();
System.setProperty("fml.queryResult", "confirm");
System.setProperty("fml.doNotBackup", "true");
System.setProperty("forge.disableVanillaGameData", "true");
registry = new RegistryBuilder<RTest>().setName(resloc).setType(RTest.class).setIDRange(0, 255).create();
new RegistryBuilder<RTest>().setName(resloc).setType(RTest.class).setIDRange(0, 255).create();
new RegistryBuilder<Block>().setName(GameData.BLOCKS).setType(Block.class).setIDRange(0, 255).create();
new RegistryBuilder<Item>().setName(GameData.ITEMS).setType(Item.class).setIDRange(0, 255).create();
r1 = new RTest("test1");
r2 = new RTest("test2");
r3 = new RTest("test3");
r4 = new RTest("test4");
r5 = new RTest("test5");
r6 = new RTest("test6");
ss = Maps.newHashMap();
ss.put(GameData.BLOCKS, new ForgeRegistry.Snapshot());
ss.put(GameData.ITEMS, new ForgeRegistry.Snapshot());
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r1);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r2);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r3);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r4);
ss.put(resloc, ((ForgeRegistry<?>)RegistryManager.ACTIVE.getRegistry(RTest.class)).makeSnapshot());
RegistryManager.ACTIVE.clean();
RegistryManager.FROZEN.clean();
registry = new RegistryBuilder<RTest>().setName(resloc).setType(RTest.class).setIDRange(0, 255).create();
new RegistryBuilder<RTest>().setName(resloc).setType(RTest.class).setIDRange(0, 255).create();
new RegistryBuilder<Block>().setName(GameData.BLOCKS).setType(Block.class).setIDRange(0, 255).create();
new RegistryBuilder<Item>().setName(GameData.ITEMS).setType(Item.class).setIDRange(0, 255).create();
}
@@ -81,30 +91,43 @@ public class FreezingTests
@Test
public void testFreezeCycle()
{
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r6);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r5);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r4);
RegistryManager.ACTIVE.getRegistry(RTest.class).register(r3);
ForgeRegistry<RTest> r = (ForgeRegistry<RTest>)RegistryManager.ACTIVE.getRegistry(r3.getRegistryType());
int r3id = r.getID(r3);
ResourceLocation name = new ResourceLocation("test3");
ForgeRegistry<RTest> active = (ForgeRegistry<RTest>)RegistryManager.ACTIVE.getRegistry(RTest.class);
active.register(r6);
active.register(r5);
active.register(r4);
active.register(r3);
int r3id = active.getID(r3);
GameData.freezeData();
assertEquals("Frozen object is the same", r3, RegistryManager.FROZEN.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("Active object is the same", r3, RegistryManager.ACTIVE.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
GameData.injectSnapshot(ss, false, false);
assertNotEquals("IDs don't match", r3id, r.getID(r3));
assertEquals("Frozen object is the same", r3, RegistryManager.FROZEN.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("Active object is the same", r3, RegistryManager.ACTIVE.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
//Frozen data should be the same, as there are no replacement
ForgeRegistry<RTest> frozen = (ForgeRegistry<RTest>)RegistryManager.ACTIVE.getRegistry(RTest.class);
assertEquals("Frozen object not the same", r3, frozen.getValue(name));
assertEquals("Active object not the same", r3, active.getValue(name));
// r3 is in the snapshot, so the ID SHOULD change to whats in the snapshot.
GameData.injectSnapshot(ss, false, true); //Unlike the old system we die on missing mappings for custom registries. So we need to tell it to continue loading as if we're local
assertNotEquals("IDs match", r3id, active.getID(r3));
assertEquals("Frozen object not the same", r3, frozen.getValue(name));
assertEquals("Active object not the same", r3, active.getValue(name));
// Frozen has the original ID
GameData.revertToFrozen();
assertEquals("IDs match", r3id, r.getID(r3));
assertEquals("Frozen object is the same", r3, RegistryManager.FROZEN.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("Active object is the same", r3, RegistryManager.ACTIVE.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("IDs don't match", r3id, active.getID(r3));
assertEquals("Frozen object not the same", r3, frozen.getValue(name));
assertEquals("Active object not the same", r3, active.getValue(name));
// Make sure we have snapshot ID again
GameData.injectSnapshot(ss, true, true);
assertNotEquals("IDs don't match", r3id, r.getID(r3));
assertEquals("Frozen object is the same", r3, RegistryManager.FROZEN.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("Active object is the same", r3, RegistryManager.ACTIVE.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertNotEquals("IDs match", r3id, active.getID(r3));
assertEquals("Frozen object not the same", r3, frozen.getValue(name));
assertEquals("Active object not the same", r3, active.getValue(name));
//And back to the frozen ID
GameData.revertToFrozen();
assertEquals("IDs match", r3id, r.getID(r3));
assertEquals("Frozen object is the same", r3, RegistryManager.FROZEN.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("Active object is the same", r3, RegistryManager.ACTIVE.getRegistry(RTest.class).getValue(new ResourceLocation("test3")));
assertEquals("IDs don't match", r3id, active.getID(r3));
assertEquals("Frozen object not the same", r3, frozen.getValue(name));
assertEquals("Active object not the same", r3, active.getValue(name));
}
}
@@ -86,11 +86,11 @@ public class ItemBlockSubstitutionRemoveRestoreTest
snapshot.get(GameData.ITEMS).substitutions.clear();
GameData.injectSnapshot(snapshot, false, false);
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
*/
dirtitem = (ItemBlock) itemRegistry.getValue(myDirt);
assertEquals("ItemBlock points at vanilla block", originalDirt, dirtitem);
assertNotEquals("ItemBlock points at my block", myDirtInstance, dirtitem);
*/
// TEST 3: Does the substitute get restored when reverting to frozen state? The substitute should be found in the registry again
GameData.revertToFrozen();
@@ -18,6 +18,8 @@ import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import java.lang.reflect.Field;
/**
* Vanilla registry tests
*/
@@ -42,7 +44,7 @@ public class VanillaRegistryTests
// Our lookups find the same stuff vanilla sees
final IForgeRegistry<Block> blocks = RegistryManager.ACTIVE.getRegistry(Block.class);
assertEquals("We have the right blocks for a block", blocks, Block.REGISTRY);
assertEquals("We have a different block registry then vanilla", blocks, getDelegate(Block.REGISTRY));
// We can look up stuff through our APIs
Block bl = blocks.getValue(new ResourceLocation("minecraft:air"));
@@ -54,7 +56,7 @@ public class VanillaRegistryTests
// Our lookups find the same stuff vanilla sees
final IForgeRegistry<Item> items = RegistryManager.ACTIVE.getRegistry(Item.class);
assertEquals("We have the right items for an item", items, Item.REGISTRY);
assertEquals("We have a different item registry then vanilla", items, getDelegate(Item.REGISTRY));
// We can look up stuff through our APIs
Item it = items.getValue(new ResourceLocation("minecraft:bed"));
@@ -65,6 +67,20 @@ public class VanillaRegistryTests
assertEquals("We got nothing (items) when we asked for cheese", null, none);
}
private Object getDelegate(Object obj)
{
try
{
Field f = obj.getClass().getDeclaredField("delegate");
f.setAccessible(true);
return f.get(obj);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
@Test
public void testRegistration()
{
@@ -74,7 +90,7 @@ public class VanillaRegistryTests
assertNotNull("Registered my block", myBlock);
// Our lookups find the same stuff vanilla sees
assertEquals("We have the right blocks for a block", blocks, Block.REGISTRY);
assertEquals("We have a different block registry then vanilla", blocks, getDelegate(Block.REGISTRY));
Block found = blocks.getValue(new ResourceLocation("minecraft:testy"));
assertEquals("Registry lookup works", myBlock, found);