コード例 #1
0
        private static void RunParamTests(Test_FixedArrayInClass obj)
        {
            UClass unrealClass = obj.GetClass();

            // Using DynamicInvoke to simulate what would happen if called from C++. If we called these functions directly
            // it wouldn't give meaningful results as it would just exhibit pure C# behaviour of the struct

            Test_FixedArrayInStruct resultStruct = (Test_FixedArrayInStruct)UObject.DynamicInvoke(obj, "StructArrayFuncTestResult");

            AssertTestArrayFuncParam(resultStruct, unrealClass, 0);

            // Pass the struct over to a simple param function which will do the same check
            UObject.DynamicInvoke(obj, "StructArrayFuncTestParam", resultStruct);
            AssertTestArrayFuncParam(resultStruct, unrealClass, 2);

            object[] parameters = { resultStruct };
            UObject.DynamicInvoke(obj, "StructArrayFuncTestRefParam", parameters);
            resultStruct = (Test_FixedArrayInStruct)parameters[0];
            AssertTestArrayFuncParam(resultStruct, unrealClass, 4);

            // the 'out' call will set it back to the state similar to the first call
            parameters[0] = null;// null should be fine here? it will be overwritten since its an out param
            UObject.DynamicInvoke(obj, "StructArrayFuncTestOutParam", parameters);
            resultStruct = (Test_FixedArrayInStruct)parameters[0];
            AssertTestArrayFuncParam(resultStruct, unrealClass, 5);
        }
コード例 #2
0
        private static T TestResultFuncX <T>(Test_SimpleFuncs obj, int func, bool isNullResult)
        {
            string funcName = "ResultFunc" + func;

            if (isNullResult)
            {
                funcName += "_Null";
            }
            UFunction func1 = obj.GetClass().FindFunctionByName(new FName(funcName));

            Tests.AssertNotNull(func1, obj.GetClass(), funcName);

            return((T)UObject.DynamicInvoke(obj, funcName));
        }
コード例 #3
0
        private static void TestResultFuncXEquals <T>(T value, Test_SimpleFuncs obj, int func, bool isNullResult)
        {
            UClass unrealClass = obj.GetClass();
            string funcName    = "ResultFunc" + func;

            if (isNullResult)
            {
                funcName += "_Null";
            }
            UFunction func1 = unrealClass.FindFunctionByName(new FName(funcName));

            Tests.AssertNotNull(func1, unrealClass, funcName);

            Tests.AssertEqual((T)UObject.DynamicInvoke(obj, funcName), value, unrealClass, funcName);
        }
コード例 #4
0
        private static void TestVirtualFunc1(Test_SimpleClass1 obj, int type)
        {
            // Go through a full marshal of parameters and resolve the function from the UFunction
            object[] parameters = { 1, "inArg" };
            UObject.DynamicInvoke(obj, "VirtualFunc1", parameters);
            string arg = (string)parameters[1];

            string expectedOutArg = "Test_SimpleClass1_param2_out";

            switch (type)
            {
            case 1: expectedOutArg = "Test_SimpleClass2_param2_out"; break;

            case 2: expectedOutArg = "Test_SimpleClass3_param2_out"; break;
            }
            Tests.AssertEqual(arg, expectedOutArg, obj.GetClass(), "VirtualFunc1.parm2");
        }
コード例 #5
0
        private static void RunSetTests(Test_CollectionsFuncs obj, UClass unrealClass)
        {
            var p1 = new HashSet <long>();
            var p2 = new HashSet <UObject>();
            var p3 = new HashSet <Test_SimpleEnum>();
            var p4 = new HashSet <Test_SimpleBlittableStruct>();
            var p5 = new HashSet <TSoftClass <UObject> >();
            var p6 = new HashSet <string>();
            var p7 = new HashSet <FName>();

            Test_CollectionsFuncs.MakeSetTest(p1, p2, p3, p4, p5, p6, p7);

            // Normal
            {
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "SetFunc1", parameters);
            }

            // Ref
            {
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "SetFunc2", parameters);
            }

            // Ref (starting empty)
            {
                p1.Clear();
                p2.Clear();
                p3.Clear();
                p4.Clear();
                p5.Clear();
                p6.Clear();
                p7.Clear();
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "SetFunc3", parameters);
                p1 = (HashSet <long>)parameters[0];
                p2 = (HashSet <UObject>)parameters[1];
                p3 = (HashSet <Test_SimpleEnum>)parameters[2];
                p4 = (HashSet <Test_SimpleBlittableStruct>)parameters[3];
                p5 = (HashSet <TSoftClass <UObject> >)parameters[4];
                p6 = (HashSet <string>)parameters[5];
                p7 = (HashSet <FName>)parameters[6];
                Test_CollectionsFuncs.AssertSetTest(obj, p1, p2, p3, p4, p5, p6, p7);
            }

            // Out
            {
                object[] parameters = { null, null, null, null, null, null, null };
                UObject.DynamicInvoke(obj, "SetFunc4", parameters);
                p1 = (HashSet <long>)parameters[0];
                p2 = (HashSet <UObject>)parameters[1];
                p3 = (HashSet <Test_SimpleEnum>)parameters[2];
                p4 = (HashSet <Test_SimpleBlittableStruct>)parameters[3];
                p5 = (HashSet <TSoftClass <UObject> >)parameters[4];
                p6 = (HashSet <string>)parameters[5];
                p7 = (HashSet <FName>)parameters[6];
                Test_CollectionsFuncs.AssertSetTest(obj, p1, p2, p3, p4, p5, p6, p7);
            }

            // Result
            {
                object[] parameters = { "inStr" };
                var      setResult  = (HashSet <TSoftClass <UObject> >)UObject.DynamicInvoke(obj, "SetFunc5", parameters);
                Tests.Assert(setResult.Contains(TSoftClass <UObject> .Null), unrealClass, "SetFunc5");
                Tests.Assert(setResult.Contains(new TSoftClass <UObject>(Tests.ActorClass)), unrealClass, "SetFunc5");
                Tests.AssertEqual((string)parameters[0], "outStr", unrealClass, "SetFunc5.param1");
            }
        }
コード例 #6
0
        private static void RunMapTest(Test_CollectionsFuncs obj, UClass unrealClass)
        {
            var p1 = new Dictionary <long, string>();
            var p2 = new Dictionary <UObject, string>();
            var p3 = new Dictionary <Test_SimpleEnum, string>();
            var p4 = new Dictionary <Test_SimpleBlittableStruct, UObject>();
            var p5 = new Dictionary <TSoftClass <UObject>, TSoftClass <UObject> >();
            var p6 = new Dictionary <string, string>();
            var p7 = new Dictionary <FName, string>();

            Test_CollectionsFuncs.MakeMapTest(p1, p2, p3, p4, p5, p6, p7);

            // Normal
            {
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "MapFunc1", parameters);
            }

            // Ref
            {
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "MapFunc2", parameters);
            }

            // Ref (starting empty)
            {
                p1.Clear();
                p2.Clear();
                p3.Clear();
                p4.Clear();
                p5.Clear();
                p6.Clear();
                p7.Clear();
                object[] parameters = { p1, p2, p3, p4, p5, p6, p7 };
                UObject.DynamicInvoke(obj, "MapFunc3", parameters);
                p1 = (Dictionary <long, string>)parameters[0];
                p2 = (Dictionary <UObject, string>)parameters[1];
                p3 = (Dictionary <Test_SimpleEnum, string>)parameters[2];
                p4 = (Dictionary <Test_SimpleBlittableStruct, UObject>)parameters[3];
                p5 = (Dictionary <TSoftClass <UObject>, TSoftClass <UObject> >)parameters[4];
                p6 = (Dictionary <string, string>)parameters[5];
                p7 = (Dictionary <FName, string>)parameters[6];
                Test_CollectionsFuncs.AssertMapTest(obj, p1, p2, p3, p4, p5, p6, p7);
            }

            // Out
            {
                object[] parameters = { null, null, null, null, null, null, null };
                UObject.DynamicInvoke(obj, "MapFunc4", parameters);
                p1 = (Dictionary <long, string>)parameters[0];
                p2 = (Dictionary <UObject, string>)parameters[1];
                p3 = (Dictionary <Test_SimpleEnum, string>)parameters[2];
                p4 = (Dictionary <Test_SimpleBlittableStruct, UObject>)parameters[3];
                p5 = (Dictionary <TSoftClass <UObject>, TSoftClass <UObject> >)parameters[4];
                p6 = (Dictionary <string, string>)parameters[5];
                p7 = (Dictionary <FName, string>)parameters[6];
                Test_CollectionsFuncs.AssertMapTest(obj, p1, p2, p3, p4, p5, p6, p7);
            }

            // Result
            {
                object[] parameters = { "inStr" };
                var      mapResult  = (Dictionary <TSoftClass <UObject>, TSoftClass <UObject> >)UObject.DynamicInvoke(obj, "MapFunc5", parameters);
                Tests.AssertEqual(mapResult[TSoftClass <UObject> .Null], new TSoftClass <UObject>(Tests.ActorClass), unrealClass, "MapFunc5");
                Tests.AssertEqual(mapResult[new TSoftClass <UObject>(Tests.ActorClass)], TSoftClass <UObject> .Null, unrealClass, "MapFunc5");
                Tests.AssertEqual((string)parameters[0], "outStr", unrealClass, "MapFunc5.param1");
            }
        }
コード例 #7
0
        private static void TestFuncX(Test_SimpleFuncs obj, UClass unrealClass, int func)
        {
            string    funcName = "Func" + func;
            UFunction func1    = unrealClass.FindFunctionByName(new FName(funcName));

            Tests.AssertNotNull(func1, unrealClass, funcName);

            Test_SimpleDelegate simpleDelegate = new Test_SimpleDelegate();

            simpleDelegate.Bind(obj.BindMe);

            Test_SimpleMulticastDelegate multicastDelegate = new Test_SimpleMulticastDelegate();

            multicastDelegate.Bind(obj.BindMeMulti1);
            multicastDelegate.Bind(obj.BindMeMulti2);

            // Use dynamic invoke so that all parameters go through a full marshal between C#/native code
            object[] parameters =
            {
                (sbyte)2,          //sbyte
                (byte)3,           //byte,
                (short)4,          //short
                (ushort)5,         //ushort
                (int)6,            //int
                (uint)7,           //uint
                (long)8,           //long
                (ulong)9,          //ulong
                (float)10.2f,      //float
                (double)11.5,      //double
                simpleDelegate,    //delegate
                multicastDelegate, //multicast delegate
                obj,
                Test_SimpleEnum.Val3,
                new Test_FixedArrayInStruct()
                {
                    Array1 = new sbyte[2] {
                        2, 5
                    }
                },
                new TSubclassOf <UObject>(obj.GetClass()),
                new TLazyObject <UObject>(obj),
                TWeakObject <UObject> .Null,
                new TSoftClass <UObject>(obj.GetClass()),
                new TSoftObject <UObject>(obj),
                "Test123",
                new FName("321Test")
            };
            long result = (long)UObject.DynamicInvoke(obj, funcName, parameters);

            Tests.AssertEqual(result, 13232, unrealClass, funcName + " result");

            if (func > 1)
            {
                sbyte  p1  = (sbyte)parameters[0];
                byte   p2  = (byte)parameters[1];
                short  p3  = (short)parameters[2];
                ushort p4  = (ushort)parameters[3];
                int    p5  = (int)parameters[4];
                uint   p6  = (uint)parameters[5];
                long   p7  = (long)parameters[6];
                ulong  p8  = (ulong)parameters[7];
                float  p9  = (float)parameters[8];
                double p10 = (double)parameters[9];
                Test_SimpleDelegate          p11 = (Test_SimpleDelegate)parameters[10];
                Test_SimpleMulticastDelegate p12 = (Test_SimpleMulticastDelegate)parameters[11];
                UObject                 p13      = (UObject)parameters[12];
                Test_SimpleEnum         p14      = (Test_SimpleEnum)parameters[13];
                Test_FixedArrayInStruct p15      = (Test_FixedArrayInStruct)parameters[14];
                TSubclassOf <UObject>   p16      = (TSubclassOf <UObject>)parameters[15];
                TLazyObject <UObject>   p17      = (TLazyObject <UObject>)parameters[16];
                TWeakObject <UObject>   p18      = (TWeakObject <UObject>)parameters[17];
                TSoftClass <UObject>    p19      = (TSoftClass <UObject>)parameters[18];
                TSoftObject <UObject>   p20      = (TSoftObject <UObject>)parameters[19];
                string p21 = (string)parameters[20];
                FName  p22 = (FName)parameters[21];

                UClass actorClass = GetActorClass();

                Tests.AssertEqual(p1, 3, unrealClass, funcName + ".p1");
                Tests.AssertEqual(p2, 4, unrealClass, funcName + ".p2");
                Tests.AssertEqual(p3, 5, unrealClass, funcName + ".p3");
                Tests.AssertEqual(p4, 6, unrealClass, funcName + ".p4");
                Tests.AssertEqual(p5, 7, unrealClass, funcName + ".p5");
                Tests.AssertEqual(p6, 8u, unrealClass, funcName + ".p6");
                Tests.AssertEqual(p7, 9, unrealClass, funcName + ".p7");
                Tests.AssertEqual(p8, 10u, unrealClass, funcName + ".p8");
                Tests.AssertEqual(p9, 11.2f, unrealClass, funcName + ".p9");
                Tests.AssertEqual(p10, 12.5, unrealClass, funcName + ".p10");
                Tests.Assert(!p11.IsBound, unrealClass, funcName + ".p11");
                Tests.Assert(p12.IsBound, unrealClass, funcName + ".p12");
                Tests.AssertEqual(p12.Count, 3, unrealClass, funcName + ".p12");
                Tests.AssertEqual(p13, actorClass, unrealClass, funcName + ".p13");
                Tests.AssertEqual(p14, Test_SimpleEnum.Val2, unrealClass, funcName + ".p14");
                Tests.AssertEqual(p15.Array1[0], 2, unrealClass, funcName + ".p15");
                Tests.AssertEqual(p15.Array1[1], 5, unrealClass, funcName + ".p15");
                Tests.AssertEqual(p15.Array1[2], 100, unrealClass, funcName + ".p15");
                Tests.AssertEqual(p16.Value, actorClass, unrealClass, funcName + ".p16");
                Tests.AssertEqual(p17.Value, actorClass, unrealClass, funcName + ".p17");
                Tests.AssertEqual(p18.Value, actorClass, unrealClass, funcName + ".p18");
                Tests.AssertEqual(p19.Value, actorClass, unrealClass, funcName + ".p19");
                Tests.AssertEqual(p20.Value, actorClass, unrealClass, funcName + ".p20");
                Tests.AssertEqual(p21, "changed123", unrealClass, funcName + ".p21");
                Tests.AssertEqual(p22, new FName("321changed"), unrealClass, funcName + ".p22");
            }
        }