|
| 1 | +package tests.wurstscript.tests; |
| 2 | + |
| 3 | +import de.peeeq.wurstio.intermediateLang.interpreter.CompiletimeNatives; |
| 4 | +import de.peeeq.wurstscript.intermediatelang.ILconstString; |
| 5 | +import net.moonlightflower.wc3libs.bin.ObjMod; |
| 6 | +import net.moonlightflower.wc3libs.bin.app.objMod.W3A; |
| 7 | +import net.moonlightflower.wc3libs.dataTypes.DataType; |
| 8 | +import net.moonlightflower.wc3libs.dataTypes.app.War3Real; |
| 9 | +import net.moonlightflower.wc3libs.misc.MetaFieldId; |
| 10 | +import net.moonlightflower.wc3libs.misc.ObjId; |
| 11 | +import org.testng.annotations.Test; |
| 12 | + |
| 13 | +import java.lang.reflect.Method; |
| 14 | +import java.util.List; |
| 15 | +import java.util.Set; |
| 16 | +import java.util.stream.Collectors; |
| 17 | + |
| 18 | +import static org.testng.Assert.assertEquals; |
| 19 | +import static org.testng.Assert.assertTrue; |
| 20 | + |
| 21 | +public class CompiletimeNativesTest { |
| 22 | + |
| 23 | + @Test |
| 24 | + public void modifyObjectKeepsDifferentDataPointers() throws Exception { |
| 25 | + CompiletimeNatives natives = new CompiletimeNatives(null, null, false); |
| 26 | + W3A w3a = new W3A(); |
| 27 | + W3A.Obj obj = w3a.addObj(ObjId.valueOf("A001"), ObjId.valueOf("Abas")); |
| 28 | + |
| 29 | + Method modifyObject = CompiletimeNatives.class.getDeclaredMethod( |
| 30 | + "modifyObject", |
| 31 | + ObjMod.Obj.class, |
| 32 | + ILconstString.class, |
| 33 | + ObjMod.ValType.class, |
| 34 | + int.class, |
| 35 | + int.class, |
| 36 | + DataType.class); |
| 37 | + modifyObject.setAccessible(true); |
| 38 | + |
| 39 | + MetaFieldId unrealId = MetaFieldId.valueOf("unat"); |
| 40 | + modifyObject.invoke(natives, obj, new ILconstString(unrealId.getVal()), ObjMod.ValType.UNREAL, 1, 0, War3Real.valueOf(1.0)); |
| 41 | + modifyObject.invoke(natives, obj, new ILconstString(unrealId.getVal()), ObjMod.ValType.UNREAL, 1, 1, War3Real.valueOf(2.0)); |
| 42 | + |
| 43 | + List<ObjMod.Obj.ExtendedMod> unrealMods = obj.getMods().stream() |
| 44 | + .filter(m -> m instanceof ObjMod.Obj.ExtendedMod) |
| 45 | + .map(m -> (ObjMod.Obj.ExtendedMod) m) |
| 46 | + .filter(m -> unrealId.equals(m.getId()) && m.getLevel() == 1) |
| 47 | + .collect(Collectors.toList()); |
| 48 | + |
| 49 | + assertEquals(unrealMods.size(), 2, "Mods with distinct data pointers should both be kept"); |
| 50 | + Set<Integer> dataPointers = unrealMods.stream() |
| 51 | + .map(ObjMod.Obj.ExtendedMod::getDataPt) |
| 52 | + .collect(Collectors.toSet()); |
| 53 | + assertTrue(dataPointers.contains(0)); |
| 54 | + assertTrue(dataPointers.contains(1)); |
| 55 | + } |
| 56 | +} |
0 commit comments