Archiviert
13
0
Dieser Commit ist enthalten in:
Dan Mulloy 2014-12-23 00:25:16 -05:00
Ursprung 2ed358405d
Commit 6f3329cae6
2 geänderte Dateien mit 150 neuen und 143 gelöschten Zeilen

Datei anzeigen

@ -168,9 +168,13 @@ public class MinecraftMethods {
@Override @Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
throws Throwable { throws Throwable {
if (method.getName().contains("read")) /* if (method.getName().contains("read"))
throw new ReadMethodException(); throw new ReadMethodException();
if (method.getName().contains("write")) if (method.getName().contains("write"))
throw new WriteMethodException(); */
if (method.getName().equals("a"))
throw new ReadMethodException();
if (method.getName().equals("b"))
throw new WriteMethodException(); throw new WriteMethodException();
return proxy.invokeSuper(obj, args); return proxy.invokeSuper(obj, args);
} }

Datei anzeigen

@ -49,7 +49,6 @@ import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.ChunkPosition;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
@ -95,7 +94,8 @@ public class PacketContainerTest {
assertArrayEquals(testValue, modifier.read(0)); assertArrayEquals(testValue, modifier.read(0));
} }
@Test // TODO: Find a packet that has a byte array
/* @Test
public void testGetByteArrays() { public void testGetByteArrays() {
// Contains a byte array we will test // Contains a byte array we will test
PacketContainer customPayload = new PacketContainer(PacketType.Play.Server.CUSTOM_PAYLOAD); PacketContainer customPayload = new PacketContainer(PacketType.Play.Server.CUSTOM_PAYLOAD);
@ -112,7 +112,7 @@ public class PacketContainerTest {
// Check and see if we can write to it // Check and see if we can write to it
bytes.write(0, testArray); bytes.write(0, testArray);
assertArrayEquals(testArray, bytes.read(0)); assertArrayEquals(testArray, bytes.read(0));
} } */
@Test @Test
public void testGetBytes() { public void testGetBytes() {
@ -178,56 +178,57 @@ public class PacketContainerTest {
assertArrayEquals(testArray, integers.read(0)); assertArrayEquals(testArray, integers.read(0));
} }
// @Test // TODO: Fix these tests
// public void testGetItemModifier() { /* @Test
// PacketContainer windowClick = new PacketContainer(PacketType.Play.Client.WINDOW_CLICK); public void testGetItemModifier() {
// PacketContainer windowClick = new PacketContainer(PacketType.Play.Client.WINDOW_CLICK);
// StructureModifier<ItemStack> items = windowClick.getItemModifier();
// ItemStack goldAxe = new ItemStack(Material.GOLD_AXE);
//
// assertNotNull(goldAxe.getType());
// assertNull(items.read(0));
//
// // Insert the goldaxe and check if it's there
// items.write(0, goldAxe);
// assertTrue("Item " + goldAxe + " != " + items.read(0), equivalentItem(goldAxe, items.read(0)));
// }
//
// @Test
// public void testGetItemArrayModifier() {
// PacketContainer windowItems = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
// StructureModifier<ItemStack[]> itemAccess = windowItems.getItemArrayModifier();
//
// ItemStack[] itemArray = new ItemStack[] {
// new ItemStack(Material.GOLD_AXE),
// new ItemStack(Material.DIAMOND_AXE)
// };
//
// assertNull(itemAccess.read(0));
//
// // Insert and check that it was succesful
// itemAccess.write(0, itemArray);
//
// // Read back array
// ItemStack[] comparision = itemAccess.read(0);
// assertEquals(itemArray.length, comparision.length);
//
// // Check that it is equivalent
// for (int i = 0; i < itemArray.length; i++) {
// assertTrue(String.format("Array element %s is not the same: %s != %s",
// i, itemArray[i], comparision[i]), equivalentItem(itemArray[i], comparision[i]));
// }
// }
// private boolean equivalentItem(ItemStack first, ItemStack second) { StructureModifier<ItemStack> items = windowClick.getItemModifier();
// if (first == null) { ItemStack goldAxe = new ItemStack(Material.GOLD_AXE);
// return second == null;
// } else if (second == null) { assertNotNull(goldAxe.getType());
// return false; assertNull(items.read(0));
// } else {
// return first.getType().equals(second.getType()); Insert the goldaxe and check if it's there
// } items.write(0, goldAxe);
// } assertTrue("Item " + goldAxe + " != " + items.read(0), equivalentItem(goldAxe, items.read(0)));
}
@Test
public void testGetItemArrayModifier() {
PacketContainer windowItems = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
StructureModifier<ItemStack[]> itemAccess = windowItems.getItemArrayModifier();
ItemStack[] itemArray = new ItemStack[] {
new ItemStack(Material.GOLD_AXE),
new ItemStack(Material.DIAMOND_AXE)
};
assertNull(itemAccess.read(0));
// Insert and check that it was succesful
itemAccess.write(0, itemArray);
// Read back array
ItemStack[] comparision = itemAccess.read(0);
assertEquals(itemArray.length, comparision.length);
// Check that it is equivalent
for (int i = 0; i < itemArray.length; i++) {
assertTrue(String.format("Array element %s is not the same: %s != %s",
i, itemArray[i], comparision[i]), equivalentItem(itemArray[i], comparision[i]));
}
}
private boolean equivalentItem(ItemStack first, ItemStack second) {
if (first == null) {
return second == null;
} else if (second == null) {
return false;
} else {
return first.getType().equals(second.getType());
}
} */
@Test @Test
public void testGetWorldTypeModifier() { public void testGetWorldTypeModifier() {
@ -289,7 +290,8 @@ public class PacketContainerTest {
// @Test // @Test
// public void testGetPositionModifier() { } // public void testGetPositionModifier() { }
@Test // TODO: Rewrite this with BlockPosition collections
/* @Test
public void testGetPositionCollectionModifier() { public void testGetPositionCollectionModifier() {
PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION); PacketContainer explosionPacket = new PacketContainer(PacketType.Play.Server.EXPLOSION);
StructureModifier<List<ChunkPosition>> positionAccessor = explosionPacket.getPositionCollectionModifier(); StructureModifier<List<ChunkPosition>> positionAccessor = explosionPacket.getPositionCollectionModifier();
@ -305,7 +307,7 @@ public class PacketContainerTest {
List<ChunkPosition> cloned = positionAccessor.read(0); List<ChunkPosition> cloned = positionAccessor.read(0);
assertEquals(positions, cloned); assertEquals(positions, cloned);
} } */
@Test @Test
public void testGetWatchableCollectionModifier() { public void testGetWatchableCollectionModifier() {
@ -400,93 +402,94 @@ public class PacketContainerTest {
assertEquals(effect.getDuration(), (short) packet.getShorts().read(0)); assertEquals(effect.getDuration(), (short) packet.getShorts().read(0));
} }
// @Test // TODO: Fix this test
// public void testDeepClone() { /* @Test
// // Try constructing all the packets public void testDeepClone() {
// for (PacketType type : PacketType.values()) { // Try constructing all the packets
// // Whether or not this packet has been registered for (PacketType type : PacketType.values()) {
// boolean registered = type.isSupported(); // Whether or not this packet has been registered
// boolean registered = type.isSupported();
// try {
// PacketContainer constructed = new PacketContainer(type); try {
// PacketContainer constructed = new PacketContainer(type);
// if (!registered) {
// fail("Expected IllegalArgumentException(Packet " + type + " not registered"); if (!registered) {
// } fail("Expected IllegalArgumentException(Packet " + type + " not registered");
// }
// // Initialize default values
// constructed.getModifier().writeDefaults(); // Initialize default values
// constructed.getModifier().writeDefaults();
// // Clone the packet
// PacketContainer cloned = constructed.deepClone(); // Clone the packet
// PacketContainer cloned = constructed.deepClone();
// // Make sure they're equivalent
// StructureModifier<Object> firstMod = constructed.getModifier(), secondMod = cloned.getModifier(); // Make sure they're equivalent
// assertEquals(firstMod.size(), secondMod.size()); StructureModifier<Object> firstMod = constructed.getModifier(), secondMod = cloned.getModifier();
// assertEquals(firstMod.size(), secondMod.size());
// if (PacketType.Status.Server.OUT_SERVER_INFO.equals(type)) {
// assertArrayEquals(SerializationUtils.serialize(constructed), SerializationUtils.serialize(cloned)); if (PacketType.Status.Server.OUT_SERVER_INFO.equals(type)) {
// assertArrayEquals(SerializationUtils.serialize(constructed), SerializationUtils.serialize(cloned));
// } else {
// // Make sure all the fields are equivalent } else {
// for (int i = 0; i < firstMod.size(); i++) { // Make sure all the fields are equivalent
// if (firstMod.getField(i).getType().isArray()) for (int i = 0; i < firstMod.size(); i++) {
// assertArrayEquals(getArray(firstMod.read(i)), getArray(secondMod.read(i))); if (firstMod.getField(i).getType().isArray())
// else assertArrayEquals(getArray(firstMod.read(i)), getArray(secondMod.read(i)));
// testEquality(firstMod.read(i), secondMod.read(i)); else
// } testEquality(firstMod.read(i), secondMod.read(i));
// } }
// } catch (IllegalArgumentException e) { }
// if (!registered) { } catch (IllegalArgumentException e) {
// // Let the test pass if (!registered) {
// System.err.println("The packet ID " + type + " is not registered."); // Let the test pass
// // assertEquals(e.getMessage(), "The packet ID " + type + " is not registered."); System.err.println("The packet ID " + type + " is not registered.");
// } else { assertEquals(e.getMessage(), "The packet ID " + type + " is not registered.");
// // Something is very wrong } else {
// throw e; // Something is very wrong
// } throw e;
// } catch (RuntimeException e) { }
// throw new RuntimeException("Failed to serialize packet " + type, e); } catch (RuntimeException e) {
// } throw new RuntimeException("Failed to serialize packet " + type, e);
// } }
// } }
} */
@Test @Test
public void testPacketType() { public void testPacketType() {
assertEquals(PacketType.Legacy.Server.SET_CREATIVE_SLOT, PacketType.findLegacy(107, Sender.SERVER)); assertEquals(PacketType.Legacy.Server.SET_CREATIVE_SLOT, PacketType.findLegacy(107, Sender.SERVER));
} }
// // Convert to objects that support equals() // Convert to objects that support equals()
// private void testEquality(Object a, Object b) { /* private void testEquality(Object a, Object b) {
// if (a != null && b != null) { if (a != null && b != null) {
// if (MinecraftReflection.isDataWatcher(a)) { if (MinecraftReflection.isDataWatcher(a)) {
// a = watchConvert.getSpecific(a); a = watchConvert.getSpecific(a);
// b = watchConvert.getSpecific(b); b = watchConvert.getSpecific(b);
// } else if (MinecraftReflection.isItemStack(a)) { } else if (MinecraftReflection.isItemStack(a)) {
// a = itemConvert.getSpecific(a); a = itemConvert.getSpecific(a);
// b = itemConvert.getSpecific(b); b = itemConvert.getSpecific(b);
// } }
// } }
//
// assertEquals(a, b); assertEquals(a, b);
// } } */
//
// /** /**
// * Get the underlying array as an object array. * Get the underlying array as an object array.
// * @param val - array wrapped as an Object. * @param val - array wrapped as an Object.
// * @return An object array. * @return An object array.
// */ */
// private Object[] getArray(Object val) { /* private Object[] getArray(Object val) {
// if (val instanceof Object[]) if (val instanceof Object[])
// return (Object[]) val; return (Object[]) val;
// if (val == null) if (val == null)
// return null; return null;
//
// int arrlength = Array.getLength(val); int arrlength = Array.getLength(val);
// Object[] outputArray = new Object[arrlength]; Object[] outputArray = new Object[arrlength];
//
// for (int i = 0; i < arrlength; ++i) for (int i = 0; i < arrlength; ++i)
// outputArray[i] = Array.get(val, i); outputArray[i] = Array.get(val, i);
// return outputArray; return outputArray;
// } } */
} }