Beispiel #1
0
        public void ExecuteTests()
        {
            int counter = 0;

            for (int i = 0; i < 10; ++i)
            {
                counter++;
            }

            tester.TestAssertion("Basic for loop", counter == 10);

            int[] ints = new[] { 1, 2, 3, 4, 5 };

            counter = 0;

            foreach (var val in ints)
            {
                counter += val;
            }

            tester.TestAssertion("Foreach loop", counter == 15);

            string helloStr = "hello!";
            string builtStr = "";

            foreach (char strChar in helloStr)
            {
                builtStr += strChar;
            }

            tester.TestAssertion("Foreach string loop", builtStr == helloStr);
        }
Beispiel #2
0
        // https://vrchat.canny.io/vrchat-udon-closed-alpha-bugs/p/vector3set-xyz-not-functioning
        // This has been fixed for a while
        void TestFieldSet()
        {
            Vector3 vector = new Vector3(1, 2, 3);

            vector.y = 4f;

            tester.TestAssertion("Vector3 Field Set", vector == new Vector3(1, 4, 3));
        }
Beispiel #3
0
        public void ExecuteTests()
        {
            int counter = 0;

            for (int i = 0; i < 10; ++i)
            {
                counter++;
            }

            tester.TestAssertion("Basic for loop", counter == 10);

            int[] ints = new[] { 1, 2, 3, 4, 5 };

            counter = 0;

            foreach (var val in ints)
            {
                counter += val;
            }

            tester.TestAssertion("Foreach loop", counter == 15);

            counter = 0;
            foreach (var child in transform)
            {
                ++counter;
            }

            foreach (Transform child in transform)
            {
                ++counter;
            }

            tester.TestAssertion("Foreach child Transform loop", counter == 6);

            string helloStr = "hello!";
            string builtStr = "";

            foreach (char strChar in helloStr)
            {
                builtStr += strChar;
            }

            tester.TestAssertion("Foreach string loop", builtStr == helloStr);

            GameObject[] gameObjects   = new GameObject[2000];
            int          gameObjectLen = gameObjects.Length;

            System.DateTime startTime = System.DateTime.UtcNow;
            for (int i = 0; i < gameObjectLen; ++i)
            {
                gameObjects[i] = gameObject;
            }

            tester.TestAssertion("Array indexer performance", (System.DateTime.UtcNow - startTime).TotalSeconds < 1f);
        }
Beispiel #4
0
        void TestHeapVariableGetComponent()
        {
            GameObject newObject = VRCInstantiate(referenceSpawnObject);

            InstantiatedObjectTesterScript testScript = newObject.GetComponent <InstantiatedObjectTesterScript>();

            // GetComponent<User T>() will fail immediately after instantiation because the script ID heap variable returns null, so U# has no way to determine the script type
            tester.TestAssertion("Instantiated Object GetComponent<T>()", testScript != null);

            Destroy(newObject);
        }
Beispiel #5
0
        public void ExecuteTests()
        {
            enabled = true ? true : val;
            enabled = false ? true : val;
            tester.TestAssertion("Ternary access COWing 'this' succeeded", true);

            x         = this;
            x.enabled = true ? true : val;
            x.enabled = false ? true : x.val;
            tester.TestAssertion("Ternary access COWing a field succeeded", true);
        }
        public void ExecuteTests()
        {
            ImplicitConversions selfRef = this;

            testStr = null;

            // https://github.com/Merlin-san/UdonSharp/issues/32
            tester.TestAssertion("Null public string is null", selfRef.testStr == null);

            testStr = "hello!";
            tester.TestAssertion("Non-null public string is valid", selfRef.testStr == "hello!");
        }
Beispiel #7
0
        void TestCustomEvents()
        {
            eventCounter = 0;

            SendCustomEvent("IncrementCounter");
            SendCustomEvent("IncrementCounter");
            SendCustomEvent("IncrementCounter");

            tester.TestAssertion("Custom Event Calls", eventCounter == 12);

            selfReference.SendCustomEvent("IncrementCounter");
            tester.TestAssertion("Reference Custom Event Calls", eventCounter == 16);
        }
Beispiel #8
0
        public void ExecuteTests()
        {
            tester.TestAssertion("GetComponent<Transform>()", GetComponent <Transform>() != null);

            BoxCollider[] colliders = GetComponentsInChildren <BoxCollider>();

            tester.TestAssertion("GetComponentsInChildren<BoxCollider>()", colliders.Length == 2);

            tester.TestAssertion("GetComponentInChildren<PlayerModSetter>()", GetComponentInChildren <NameOf>() != null);

            NameOf[] nameOfs = GetComponentsInChildren <NameOf>();

            tester.TestAssertion("GetComponentsInChildren<PlayerModSetter>()", nameOfs.Length == 3);

            tester.TestAssertion("GetComponentsInChildren<MeshRenderer>()", GetComponentsInChildren <MeshRenderer>().Length == 2);

            UdonSharpBehaviour getBehaviour = (UdonSharpBehaviour)modObject.GetComponent(typeof(UdonBehaviour));

            tester.TestAssertion("Get UdonBehaviour typeof(UdonBehaviour)", getBehaviour != null);

            long typeID = GetUdonTypeID <NameOf>();

            tester.TestAssertion("Type ID matches", typeID == getBehaviour.GetUdonTypeID());

            tester.TestAssertion("Correct number of UdonBehaviours on gameobject", modObject.GetComponents(typeof(UdonBehaviour)).Length == 4);

            //Debug.Log(getBehaviour.GetUdonTypeID());
            //Debug.Log(getBehaviour.GetUdonTypeName());

            //foreach (Component behaviour in modObject.GetComponents(typeof(UdonBehaviour)))
            //{
            //    Debug.Log("Component name: " + ((UdonSharpBehaviour)behaviour).GetUdonTypeName());
            //}
        }
        public void ExecuteTests()
        {
            string resultStr = "";

            foreach (var testInheritanceClassBase in testClasses)
            {
                resultStr += testInheritanceClassBase.GetClassName();
            }

            tester.TestAssertion("Inherited methods", resultStr == "ABBC");
            tester.TestAssertion("Inherited methods 2", testClasses[0].GetClassID() == 1);
            tester.TestAssertion("Inherited type field 1", testClasses[0].BaseClassField == 4);
            tester.TestAssertion("Inherited type field 2", testClasses[1].BaseClassField == 20);
            tester.TestAssertion("Inherited type field 3", testClasses[2].NonSerializedField == 5);
        }
Beispiel #10
0
        public void ExecuteTests()
        {
            if (behaviour != null)
            {
                // This just needs to compile
                byte[] data = (byte[])((UdonBehaviour)behaviour.GetProgramVariable("ABC")).GetProgramVariable("DEFG");
            }

            int castFloat = (int)5.4f;

            tester.TestAssertion("Int Cast", castFloat == 5);


            int testCastFloat = (int)(int)(float)(int)floatField;

            tester.TestAssertion("Int Cast 2", testCastFloat == 4);
        }
        public void ExecuteTests()
        {
            UserFieldTypeConversionTest self = this;

            int resultVal = Test(self.baz);

            tester.TestAssertion("User Field Type Conversion", resultVal == 5);
        }
Beispiel #12
0
        public void ExecuteTests()
        {
            float[] floatArray = { 1f, 2f };
            floatArray = floatArray.AddElement(3f);

            tester.TestAssertion("Generic variant 1", floatArray.Length == 3 &&
                                 floatArray[0] == 1f && floatArray[1] == 2f && floatArray[2] == 3f);

            int[] intArray = { 1, 2 };
            intArray = intArray.AddElement(3);

            tester.TestAssertion("Generic variant 2", intArray.Length == 3 &&
                                 intArray[0] == 1 && intArray[1] == 2 && intArray[2] == 3);

            UnityEngine.Object[] objects = { gameObject, transform };
            objects = objects.AddElement(this);

            tester.TestAssertion("Generic variant 3", objects.Length == 3 &&
                                 objects[0] == gameObject && objects[1] == transform && objects[2] == this);
        }
Beispiel #13
0
        // https://vrchat.canny.io/vrchat-udon-closed-alpha-bugs/p/quaterniontoangleaxis-broken
        void TestAngleAxis()
        {
            Quaternion rotation = Quaternion.AngleAxis(20f, new Vector3(1, 2, 3).normalized);

            float   angle = 0f;
            Vector3 axis  = Vector3.zero;

            rotation.ToAngleAxis(out angle, out axis);

            tester.TestAssertion("Angle Axis double out params", angle != 0f || axis != Vector3.zero);
        }
Beispiel #14
0
        public void ExecuteTests()
        {
            string testStr = string.Concat("a", "bc", "d", "e", "fg", "hij", "klmn", "opq", "rstuv", "wx", "yz");

            tester.TestAssertion("Params arrays", testStr == "abcdefghijklmnopqrstuvwxyz");

            string joinedStr  = string.Join(", ", new[] { "Hello", "test", "join" });
            string joinedStr2 = string.Join(", ", "Hello", "test", "join");

            tester.TestAssertion("Param parameter without expanding", joinedStr == "Hello, test, join");
            tester.TestAssertion("Param parameter with expanding", joinedStr2 == "Hello, test, join");

            string formatStr = string.Format("{0}, {1}", this, this);

            tester.TestAssertion("FormatStr 1", formatStr == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr2 = string.Format("{0}", this);

            tester.TestAssertion("FormatStr 2", formatStr2 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            var    objArr     = new object[] { this };
            string formatStr3 = string.Format("{0}", objArr);

            tester.TestAssertion("FormatStr 3", formatStr3 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            //Debug.Log(string.Join(", ", this, this, this, this)); // Runtime exception `Function '__Join__SystemString_SystemObjectArray__SystemString' is not implemented yet`
        }
Beispiel #15
0
#pragma warning restore CS0649

        // https://github.com/Merlin-san/UdonSharp/issues/41
        public void Method()
        {
            var obj1 = 123;

            // displayed 'Method1 type:System.Int32'
            udon.udon.Method1(obj1);
            // displayed 'Method1 type:System.Int32'
            obj1 = udon.udon.Method1(obj1);
            // displayed 'Method1 type:System.Int32'
            udon.udon.Method1(obj1);

            tester.TestAssertion("Int copy propagation test", obj1 == 123);

            var obj2 = (object)123;

            // displayed 'Method2 type:System.Int32'
            udon.udon.Method2(obj2);
            // Bug? displayed 'Method2 type:VRC.Udon.UdonBehaviour'
            obj2 = udon.udon.Method2(obj2);

            tester.TestAssertion("Object copy propagation test", obj2.GetType() == typeof(int) && (int)obj2 == 123);
        }
Beispiel #16
0
        void TestJaggedArray()
        {
            bool[][][] array = new bool[2][][];

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = new bool[2][];
                for (int i2 = 0; i2 < array.Length; i2++)
                {
                    array[i][i2] = new bool[] { true, false };
                }
            }

            bool[] arr2 = JaggedArrayCallTest(array);

            tester.TestAssertion("Jagged Array COW Leak Test", arr2[0] == true && arr2[1] == false);
        }
Beispiel #17
0
        public void ExecuteTests()
        {
            tester.TestAssertion("Single name nameof", nameof(ExecuteTests) == "ExecuteTests");
            tester.TestAssertion("Single type nameof", nameof(UdonSharpBehaviour) == "UdonSharpBehaviour");

            string functionName = nameof(NameOf.ExecuteTests);

            tester.TestAssertion("Function nameof", functionName == "ExecuteTests");

            tester.TestAssertion("Type nameof", nameof(System.String) == "String");

            int[] nums = new[] { 1, 2 };
            tester.TestAssertion("Property nameof", nameof(nums.Length) == "Length");

            tester.TestAssertion(">2 accesses nameof", nameof(UnityEngine.UI.Text) == "Text");
        }
Beispiel #18
0
 void TestPublicArray()
 {
     tester.TestAssertion("Default Public Array Initialized", defaultPublicArr != null && defaultPublicArr.Length == 0);
     tester.TestAssertion("Default UdonSharpBehaviour Public Array Initialized", emptyUdonBehaviourArray != null && emptyUdonBehaviourArray.Length == 0);
 }
Beispiel #19
0
 void TestPublicArray()
 {
     tester.TestAssertion("Default Public Array Initialized", defaultPublicArr != null && defaultPublicArr.Length == 0);
 }
Beispiel #20
0
        public void ExecuteTests()
        {
            SetProgramVariable("transformIn", transform);

            tester.TestAssertion("GetComponent on object strongbox", transformIn.GetComponent <Transform>().position != Vector3.one * 1000f); // Shouldn't throw

            tester.TestAssertion("GetComponent UdonSharp Type", transformIn.GetComponent <GetComponentTest>() != null);

            tester.TestAssertion("GetComponent on GameObject", transformIn.gameObject.GetComponent <Transform>() != null);

            tester.TestAssertion("GetComponent user type on GameObject", transformIn.gameObject.GetComponent <GetComponentTest>() != null);

            tester.TestAssertion("GetComponent on GameObject 2", GameObject.Find("GetComponents").GetComponent <GetComponentTest>() != null);

            transforms = new[] { transform, transform };

            // Udon StrongBox assignment test
            transforms[1].GetComponentInChildren <BoxCollider>().enabled = false;
            transforms[1].GetComponentInChildren <BoxCollider>().enabled = true;

            tester.TestAssertion("GetComponent<Transform>()", GetComponent <Transform>() != null);

            tester.TestAssertion("GetComponent(typeof(Transform))", GetComponent(typeof(Transform)) != null);

            BoxCollider[] colliders = GetComponentsInChildren <BoxCollider>();

            tester.TestAssertion("GetComponentsInChildren<BoxCollider>()", colliders.Length == 3);

            tester.TestAssertion("GetComponentInChildren<NameOf>()", GetComponentInChildren <NameOf>() != null);

            NameOf[] nameOfs = GetComponentsInChildren <NameOf>();

            tester.TestAssertion("GetComponentsInChildren<NameOf>()", nameOfs.Length == 3);

            tester.TestAssertion("GetComponentsInChildren<MeshRenderer>()", GetComponentsInChildren <MeshRenderer>().Length == 2);

#if COMPILER_UDONSHARP
            UdonSharpBehaviour getBehaviour = (UdonSharpBehaviour)modObject.GetComponent(typeof(UdonBehaviour));

            tester.TestAssertion("Get UdonBehaviour typeof(UdonBehaviour)", getBehaviour != null);

            long typeID = GetUdonTypeID <NameOf>();

            tester.TestAssertion("Type ID matches", typeID == getBehaviour.GetUdonTypeID());
#endif

            tester.TestAssertion("Correct number of UdonBehaviours on gameobject", modObject.GetComponents(typeof(UdonBehaviour)).Length == 4);

            videoPlayer      = (VRCUnityVideoPlayer)GetComponent(typeof(VRCUnityVideoPlayer));
            avProVideoPlayer = (VRCAVProVideoPlayer)GetComponent(typeof(VRCAVProVideoPlayer));
            baseVideoPlayer  = (BaseVRCVideoPlayer)GetComponent(typeof(BaseVRCVideoPlayer));

            VRCStation station;
            station = (VRCStation)GetComponent(typeof(VRCStation));

            // Should compile
            GetComponents <Collider>()[0].enabled = false;
            GetComponents <Collider>()[0].enabled = true;

            // U# inheritance
            tester.TestAssertion("Base type GetComponent", inheritContainer.GetComponents <TestInheritanceClassBase>().Length == 3);
            tester.TestAssertion("Inherited GetComponent 1", inheritContainer.GetComponents <ClassA>().Length == 1);
            tester.TestAssertion("Inherited GetComponent 2", inheritContainer.GetComponents <ClassB>().Length == 2);
            tester.TestAssertion("Inherited GetComponent 3", inheritContainer.GetComponents <ClassC>().Length == 1);

            tester.TestAssertion("Get UdonBehaviour", GetComponent <UdonBehaviour>());
            tester.TestAssertion("Get UdonBehaviours", GetComponents <UdonBehaviour>().Length == 2);
            tester.TestAssertion("Get UdonBehaviours 2", inheritContainer.GetComponents <UdonBehaviour>().Length == 5);
            tester.TestAssertion("Get VRC component 1", GetComponent <VRCObjectSync>());
            tester.TestAssertion("Get VRC component 2", GetComponent <VRCAvatarPedestal>());
            tester.TestAssertion("Get VRC component 3", GetComponent <VRC_AvatarPedestal>());
            tester.TestAssertion("Get VRC components 1", GetComponents <VRC_AvatarPedestal>().Length == 1 && GetComponents <VRC_AvatarPedestal>()[0] != null);
        }
Beispiel #21
0
        public void ExecuteTests()
        {
            GameObject newObject = Instantiate(objectToSpawn);

            tester.TestAssertion("Instantiation", newObject != null);
        }
Beispiel #22
0
        public void ExecuteTests()
        {
            int a = 1;
            int b;

            self = this;

            b = a + (a += 1) + a;
            tester.TestAssertion("Order of operations: Binary operations with postfix increment", b == 5);

            b = a + (++a * 10) + (a + (a++ *10)) * 100;
            tester.TestAssertion("Order of operations: Prefix and postfix", b == 3332);

            b = 3;
            int[] localArray = new int[] { b, b += 1, b };
            tester.TestAssertion("Array initializers with side effects", (localArray[0] == 3 && localArray[1] == 4 && localArray[2] == 4));

            a             = 1;
            localArray[a] = 1;
            tester.TestAssertion("Array index writes", (localArray[0] == 3 && localArray[1] == 1 && localArray[2] == 4));
            localArray[a] = (a += 1);
            tester.TestAssertion("Array index writes with side effects", (localArray[0] == 3 && localArray[1] == 2 && localArray[2] == 4));

            a = 1;
            tester.TestAssertion("String interpolation with side effects", $"{a} {a += 1}" == "1 2");

            string result = string.Format("{0} {1} {2} {3}", a, a++, a += 2, ++a);

            tester.TestAssertion("Variadic extern function invocation with side effects", result == "2 2 5 6");

            Vector3[] localVecArray = new Vector3[5];
            a = 0;
            localVecArray[a].x = (a += 1);

            tester.TestAssertion("Structure array write with side effects", localVecArray[0].x == 1);

            localVecArray[a].y += (a += 1);

            tester.TestAssertion("Structure array compound assignment with side effects", localVecArray[1].y == 2f);

            localVecArray[a++].y += 3f;

            tester.TestAssertion("Structure array compound assignment with index postfix increment", localVecArray[2].y == 3f);

            localVecArray[++a].y += 6f;
            tester.TestAssertion("Structure array compound assignment with index prefix increment", localVecArray[4].y == 6f);

            int testVal = 4;

            testVal += (testVal += 5);

            tester.TestAssertion("Nested compound assignment with side effects", testVal == 13);

            intArray = new int[4];

            // Should not exception
            intArray[1] = ((intArray = null) == null ? 1 : 0);
            tester.TestAssertion("Clearing array field while write is pending", true);
            localVecArray[0].x = ((localVecArray = null) == null ? 1 : 0);
            tester.TestAssertion("Clearing structure array field while write is pending", true);

            intArray = new int[3];
            // // should not exception
            intArray[0] = overwriteArrayFields(0);
            tester.TestAssertion("Clearing array field by local function while write is pending", true);

            self     = this;
            intArray = new int[3];

            // should not exception
            intArray[0] = self.overwriteArrayFields(0);
            tester.TestAssertion("Clearing array field by non-local function while write is pending", true);

            uint x = 3;

            tester.TestAssertion("Local function return values", (ROTRIGHT(x, 3) ^ ROTRIGHT(x, 18)) == 1610661888);
        }
Beispiel #23
0
        public void ExecuteTests()
        {
            string testStr = string.Concat("a", "bc", "d", "e", "fg", "hij", "klmn", "opq", "rstuv", "wx", "yz");

            tester.TestAssertion("Params arrays", testStr == "abcdefghijklmnopqrstuvwxyz");

            string joinedStr  = string.Join(", ", new[] { "Hello", "test", "join" });
            string joinedStr2 = string.Join(", ", "Hello", "test", "join");

            tester.TestAssertion("Param parameter without expanding", joinedStr == "Hello, test, join");
            tester.TestAssertion("Param parameter with expanding", joinedStr2 == "Hello, test, join");

            string formatStr = string.Format("{0}, {1}", this, this);

            tester.TestAssertion("FormatStr 1", formatStr == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr2 = string.Format("{0}", this);

            tester.TestAssertion("FormatStr 2", formatStr2 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            var    objArr     = new object[] { this };
            string formatStr3 = string.Format("{0}", objArr);

            tester.TestAssertion("FormatStr 3", formatStr3 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("String Join Objects params", string.Join(", ", this, this, this, this) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");
            tester.TestAssertion("String Join Objects array", string.Join(", ", new object[] { this, this, this, this }) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);

            enabled = false;
            tester.TestAssertion("UdonBehaviour enabled", enabled == false);
            enabled = true;

            UdonSharpBehaviour self = this;

            self.enabled = false;
            tester.TestAssertion("UdonSharpBehaviour ref enabled", self.enabled == false);
            self.enabled = true;

            UdonBehaviour selfUdon = (UdonBehaviour)(Component)this;

            selfUdon.enabled = false;
            tester.TestAssertion("UdonBehaviour ref enabled", selfUdon.enabled == false);
            selfUdon.enabled = true;

            string testStr2 = "hello";

            tester.TestAssertion("String indexer", testStr2[0] == 'h' && testStr2[1] == 'e' && testStr2[2] == 'l');

            tester.TestAssertion("Vector2 get indexer", new Vector2(1f, 2f)[1] == 2f);
            tester.TestAssertion("Vector3 get indexer", new Vector3(1f, 2f)[1] == 2f);
            tester.TestAssertion("Vector4 get indexer", new Vector4(1f, 2f)[1] == 2f);
            tester.TestAssertion("Matrix4x4 get indexer", Matrix4x4.identity[0] == 1f && Matrix4x4.identity[1] == 0f);

            Vector2 vec2Test = new Vector2(1f, 2f);

            vec2Test[0] = 4f;
            tester.TestAssertion("Vector2 set indexer", vec2Test[0] == 4f);

            Vector3 vec3Test = new Vector3(1f, 2f, 3f);

            vec3Test[0] = 4f;
            tester.TestAssertion("Vector3 set indexer", vec3Test[0] == 4f);

            Vector4 vec4Test = new Vector4(1f, 2f, 3f, 4f);

            vec4Test[0] = 4f;
            tester.TestAssertion("Vector4 set indexer", vec4Test[0] == 4f);

            Matrix4x4 mat4x4Test = Matrix4x4.identity;

            mat4x4Test[1] = 4f;
            tester.TestAssertion("Matrix4x4 set indexer", mat4x4Test[1] == 4f);

            mat4x4Test[0] += 2f;
            tester.TestAssertion("Matrix4x4 get and set in place", mat4x4Test[0] == 3f);

            tester.TestAssertion("U# Behaviour GetComponent", tester.GetComponent <IntegrationTestSuite>() != null);
            tester.TestAssertion("UdonBehaviour GetComponent", ((UdonBehaviour)(Component)tester).GetComponent <IntegrationTestSuite>() != null);

            RigidbodyConstraints constraints = (RigidbodyConstraints)126;

            tester.TestAssertion("Enum cast", constraints == RigidbodyConstraints.FreezeAll);

            constraints = RigidbodyConstraints.FreezePosition;

            tester.TestAssertion("Enum assignment after cast", constraints == RigidbodyConstraints.FreezePosition);
            tester.TestAssertion("Enum type after cast", (RigidbodyConstraints)126 == RigidbodyConstraints.FreezeAll);

            Transform currentParent = transform.parent;

            transform.SetParent(null);

            tester.TestAssertion("Transform detach parent (null parameter method finding)", transform.parent == null);

            transform.SetParent(currentParent);
        }
Beispiel #24
0
        public void ExecuteTests()
        {
            string testStr = string.Concat("a", "bc", "d", "e", "fg", "hij", "klmn", "opq", "rstuv", "wx", "yz");

            tester.TestAssertion("Params arrays", testStr == "abcdefghijklmnopqrstuvwxyz");

            string joinedStr  = string.Join(", ", new[] { "Hello", "test", "join" });
            string joinedStr2 = string.Join(", ", "Hello", "test", "join");

            tester.TestAssertion("Param parameter without expanding", joinedStr == "Hello, test, join");
            tester.TestAssertion("Param parameter with expanding", joinedStr2 == "Hello, test, join");

            string formatStr = string.Format("{0}, {1}", this, this);

            tester.TestAssertion("FormatStr 1", formatStr == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr2 = string.Format("{0}", this);

            tester.TestAssertion("FormatStr 2", formatStr2 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            var    objArr     = new object[] { this };
            string formatStr3 = string.Format("{0}", objArr);

            tester.TestAssertion("FormatStr 3", formatStr3 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("String Join Objects params", string.Join(", ", this, this, this, this) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");
            tester.TestAssertion("String Join Objects array", string.Join(", ", new object[] { this, this, this, this }) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);

            enabled = false;
            tester.TestAssertion("UdonBehaviour enabled", enabled == false);
            enabled = true;

            UdonSharpBehaviour self = this;

            self.enabled = false;
            tester.TestAssertion("UdonSharpBehaviour ref enabled", self.enabled == false);
            self.enabled = true;

            UdonBehaviour selfUdon = (UdonBehaviour)(Component)this;

            selfUdon.enabled = false;
            tester.TestAssertion("UdonBehaviour ref enabled", selfUdon.enabled == false);
            selfUdon.enabled = true;
        }
Beispiel #25
0
 public void ExecuteTests()
 {
     tester.TestAssertion("Negative SByte serialization", negativeSbyte == -1);
 }
Beispiel #26
0
        public void ExecuteTests()
        {
            tester.TestAssertion("Default value array", intDefaultValueArr[0] == 1 && intDefaultValueArr[1] == 2 && intDefaultValueArr[2] == 3);
            tester.TestAssertion("Const initialized array", intDefaultReadonlyArray[0] == 4 && intDefaultReadonlyArray[1] == 2);

            Vector3[] vecArray = new Vector3[] { new Vector2(4, 5f) };
            vecArray[0].x += 4;
            tester.TestAssertion("Struct array increment assignment", vecArray[0].x == 8f);

            tester.TestAssertion("Struct array increment assignment in place", (vecArray[0].x += 1f) == 9f);
            tester.TestAssertion("Struct array increment assignment in place after assignment", vecArray[0].x == 9f);

            float result = vecArray[0].x += 3f;

            tester.TestAssertion("Struct array increment assignment in place result", result == 12f);

            int[] intArray = new int[2];

            intArray[1] += 4;
            tester.TestAssertion("Int array increment assignment", intArray[1] == 4);
            tester.TestAssertion("Int array increment assignment in place", (intArray[1] += 4) == 8);

            ArrayTest[] selfArrayTest = new[] { this };

            testVal = 0;
            selfArrayTest[0].testVal = 5;
            tester.TestAssertion("User Field array set", testVal == 5);

            testVal = 0;
            selfArrayTest[0].SetTestVal(4);
            tester.TestAssertion("User Method array call", testVal == 4);

            long typeID = GetUdonTypeID <ArrayTest>();

            tester.TestAssertion("Udon Type ID array access", typeID == selfArrayTest[0].GetUdonTypeID());

            float[][] floatJaggedArray = new float[][] { new[] { 1f, 2f }, new[] { 3f, 4, 5 } };

            tester.TestAssertion("Jagged array access", floatJaggedArray[0][0] == 1f && floatJaggedArray[0][1] == 2f && floatJaggedArray[1][0] == 3f && floatJaggedArray[1][1] == 4f && floatJaggedArray[1][2] == 5f);

            tester.TestAssertion("Jagged array in-place increment", (floatJaggedArray[0][1] += 2f) == 4f);
            tester.TestAssertion("Jagged array in-place increment after assignment", floatJaggedArray[0][1] == 4f);

            ArrayTest[][] userTypeJaggedArray = new ArrayTest[][] { new ArrayTest[] { this, this }, new [] { this } };
            userTypeJaggedArray[1][0] = null;

            tester.TestAssertion("User type jagged array", userTypeJaggedArray[0][0] == this && userTypeJaggedArray[0][1] == this && userTypeJaggedArray[1][0] == null);
        }
Beispiel #27
0
        [RecursiveMethod] // Just here to test calling out to other types from recursive methods
        public void ExecuteTests()
        {
            tester.TestAssertion("Basic recursion 4!", Factorial(4) == 24);
            tester.TestAssertion("Basic recursion 5!", Factorial(5) == 120);
            tester.TestAssertion("Basic recursion 12!", Factorial(12) == 479001600);

            int arraySize = Random.Range(10000, 11000);

            int[] shuffleArray = InitTestArray(arraySize); // Fuzz a little

            ShuffleArray(shuffleArray);
            QuickSort(shuffleArray, 0, shuffleArray.Length - 1);

            bool sorted = IsSorted(shuffleArray);

            if (!sorted)
            {
                Debug.LogWarning($"Array size that failed {arraySize}");
            }

            tester.TestAssertion("Quicksort recursion", sorted);

            RecursionTest self = this;

            ShuffleArray(shuffleArray);
            self.QuickSort(shuffleArray, 0, shuffleArray.Length - 1);

            tester.TestAssertion("Quicksort external call", IsSorted(shuffleArray));

            tester.TestAssertion("Function parameter swap recursion", CombineStrings(6, "a", "b") == "abababababababababababababababababababababababababababababababa");

            tester.TestAssertion("Function parameter swap recursion external call", self.CombineStringsExtern(6, "a", "b") == "abababababababababababababababababababababababababababababababa");
            tester.TestAssertion("Params array recursion", CombineStringsParams(4, "a", "b", "c", "d", "e") == "aeaeaaaaeaeeeeeaeeeeeaeeeeeaeeeeaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaaaeaeeeeaeaaaaaeaaaaaeaaaaaeaaaa");
            tester.TestAssertion("Nested call recursion", CombineStringsNested(3, "a", "b") == "abaccbcccabccacccccbaccbccccccabccacccbaccbcccccabccaccccccc");

            tester.TestAssertion("Count children recursively foreach", CountChildren(transform) == 20);

            externChildCount = 0;
            CountChildrenExternalCount(transform);

            tester.TestAssertion("Count children recursively foreach external counter", externChildCount == 20);

            customEventCounter = 4;
            CustomEventExternRecursion();

            tester.TestAssertion("SendCustomEvent extern recursion", customEventCounter == 24);

            customEventCounter = 4;
            CustomEventRecursion();
            tester.TestAssertion("SendCustomEvent recursion", customEventCounter == 24);
        }
Beispiel #28
0
 public void ExecuteTests()
 {
     tester.TestAssertion("Video player valid", videoPlayer != null);
     tester.TestAssertion("Base Video player valid", baseVideoPlayer != null);
     tester.TestAssertion("Video player null", nullVideoPlayer == null);
 }
Beispiel #29
0
        public void ExecuteTests()
        {
            string testStr = string.Concat("a", "bc", "d", "e", "fg", "hij", "klmn", "opq", "rstuv", "wx", "yz");

            tester.TestAssertion("Params arrays", testStr == "abcdefghijklmnopqrstuvwxyz");

            string joinedStr  = string.Join(", ", new[] { "Hello", "test", "join" });
            string joinedStr2 = string.Join(", ", "Hello", "test", "join");
            string joinedStr3 = string.Join(", ", (object[])new GameObject[] { gameObject, gameObject });

            tester.TestAssertion("Param parameter without expanding", joinedStr == "Hello, test, join");
            tester.TestAssertion("Param parameter with expanding", joinedStr2 == "Hello, test, join");
            tester.TestAssertion("Param parameter without expanding, object array", joinedStr3 == "MethodCalls (UnityEngine.GameObject), MethodCalls (UnityEngine.GameObject)");

            int    intVal     = 20;
            string joinedStr4 = string.Join(", ", intVal.ToString());

            tester.TestAssertion("Param parameter single param", joinedStr4 == "20");

            tester.TestAssertion("User method params single parameter", MyParamsMethod(10, intVal.ToString()) == "1020");

            tester.TestAssertion("User method params array covariant conversion", MyParamsMethod(10, new [] { gameObject }) == "10MethodCalls (UnityEngine.GameObject)");
            tester.TestAssertion("User method params covariant conversion", MyParamsMethod(10, gameObject) == "10MethodCalls (UnityEngine.GameObject)");

            string formatStr = string.Format("{0}, {1}", this, this);

            tester.TestAssertion("FormatStr 1", formatStr == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr2 = string.Format("{0}", this);

            tester.TestAssertion("FormatStr 2", formatStr2 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            var    objArr     = new object[] { this };
            string formatStr3 = string.Format("{0}", objArr);

            tester.TestAssertion("FormatStr 3", formatStr3 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr4 = string.Format("{0}, {1}", new string[] { "a", "b" });

            tester.TestAssertion("FormatStr 4", formatStr4 == "a, b");

            string formatStr5 = string.Format("zero params");

            tester.TestAssertion("FormatStr 5", formatStr5 == "zero params");

            tester.TestAssertion("String Join Objects params", string.Join(", ", this, this, this, this) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");
            tester.TestAssertion("String Join Objects array", string.Join(", ", new object[] { this, this, this, this }) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);

            tester.TestAssertion("Default params 1", MyDefaultParamsMethod("a", "b", "c") == "abcD");
            tester.TestAssertion("Default params 2", MyDefaultParamsMethod("a") == "aBCD");

            tester.TestAssertion("Named args 1", MyDefaultParamsMethod(d: "d", a: "a", c: "c", b: "b") == "abcd");
            tester.TestAssertion("Named args 2", MyDefaultParamsMethod(a: "a", b: "b", c: "c", d: "d", "e", "f") == "abcdef");
            tester.TestAssertion("Named args 3", MyDefaultParamsMethod("a", b: "b", "c", d: "d", "e", "f") == "abcdef");

            tester.TestAssertion("Params array 0", MyDefaultParamsMethod("a", "b", "c", "d") == "abcd");
            tester.TestAssertion("Params array 1", MyDefaultParamsMethod("a", "b", "c", "d", "e") == "abcde");
            tester.TestAssertion("Params array 2", MyDefaultParamsMethod("a", "b", "c", "d", "e", "f") == "abcdef");

            tester.TestAssertion("Params array 3", MyDefaultParamsMethod("a", b: "b", c: "c", d: "d", new string[] { "e", "f" }) == "abcdef");
            tester.TestAssertion("Params array 4", MyDefaultParamsMethod("a", "b", "c", "d", new string[] { "e", "f" }) == "abcdef");

            tester.TestAssertion("Params array 5", MyDefaultParamsMethod("a", elements: new string[] { "e", "f" }, b: "b", d: "d") == "abCdef");

            enabled = false;
            tester.TestAssertion("UdonBehaviour enabled", enabled == false);
            enabled = true;

            UdonSharpBehaviour self = this;

            self.enabled = false;
            tester.TestAssertion("UdonSharpBehaviour ref enabled", self.enabled == false);
            self.enabled = true;

            UdonBehaviour selfUdon = (UdonBehaviour)(Component)this;

            selfUdon.enabled = false;
            tester.TestAssertion("UdonBehaviour ref enabled", selfUdon.enabled == false);
            selfUdon.enabled = true;

            string testStr2 = "hello";

            tester.TestAssertion("String indexer", testStr2[0] == 'h' && testStr2[1] == 'e' && testStr2[2] == 'l');

            tester.TestAssertion("Vector2 get indexer", new Vector2(1f, 2f)[1] == 2f);
            tester.TestAssertion("Vector3 get indexer", new Vector3(1f, 2f)[1] == 2f);
            tester.TestAssertion("Vector4 get indexer", new Vector4(1f, 2f)[1] == 2f);
            tester.TestAssertion("Matrix4x4 get indexer", Matrix4x4.identity[0] == 1f && Matrix4x4.identity[1] == 0f);

            // todo: Add VectorInt formatters to Odin because constant VectorInts don't serialize and will turn to 0's at runtime
            // tester.TestAssertion("Vector2Int get indexer", new Vector2Int(1, 2)[1] == 2);
            // tester.TestAssertion("Vector3Int get indexer", new Vector3Int(1, 2, 3)[1] == 2);

            Vector2 vec2Test = new Vector2(1f, 2f);

            vec2Test[0] = 4f;
            tester.TestAssertion("Vector2 set indexer", vec2Test[0] == 4f);

            Vector3 vec3Test = new Vector3(1f, 2f, 3f);

            vec3Test[0] = 4f;
            tester.TestAssertion("Vector3 set indexer", vec3Test[0] == 4f);

            Vector4 vec4Test = new Vector4(1f, 2f, 3f, 4f);

            vec4Test[0] = 4f;
            tester.TestAssertion("Vector4 set indexer", vec4Test[0] == 4f);

            Matrix4x4 mat4x4Test = Matrix4x4.identity;

            mat4x4Test[1] = 4f;
            tester.TestAssertion("Matrix4x4 set indexer", mat4x4Test[1] == 4f);

            mat4x4Test[0] += 2f;
            tester.TestAssertion("Matrix4x4 get and set in place", mat4x4Test[0] == 3f);

            Vector2Int vec2IntTest = new Vector2Int(1, 2);

            vec2IntTest[0] = 4;
            tester.TestAssertion("Vector2Int set indexer", vec2IntTest[0] == 4);

            Vector3Int vec3IntTest = new Vector3Int(1, 2, 3);

            vec3IntTest[0] = 4;
            tester.TestAssertion("Vector3Int set indexer", vec3IntTest[0] == 4);

            SphericalHarmonicsL2 harmonicsL2 = new SphericalHarmonicsL2();

            harmonicsL2[0, 1] = 4;

            tester.TestAssertion("Multi param indexer operator", harmonicsL2[0, 1] == 4f);

            // tester.TestAssertion("U# Behaviour GetComponent", tester.GetComponent<IntegrationTestSuite>() != null);
            // tester.TestAssertion("UdonBehaviour GetComponent", ((UdonBehaviour)(Component)tester).GetComponent<IntegrationTestSuite>() != null);
            //
            RigidbodyConstraints constraints = (RigidbodyConstraints)126;

            tester.TestAssertion("Enum cast", constraints == RigidbodyConstraints.FreezeAll);

            constraints = RigidbodyConstraints.FreezePosition;

            tester.TestAssertion("Enum assignment after cast", constraints == RigidbodyConstraints.FreezePosition);
            tester.TestAssertion("Enum type after cast", (RigidbodyConstraints)126 == RigidbodyConstraints.FreezeAll);

            Transform currentParent = transform.parent;

            transform.SetParent(null);

            tester.TestAssertion("Transform detach parent (null parameter method finding)", transform.parent == null);

            transform.SetParent(currentParent);

            selfUdon.DisableInteractive = true;

            tester.TestAssertion("DisableInteractive true", selfUdon.DisableInteractive);

            self.DisableInteractive = false;

            tester.TestAssertion("DisableInteractive false", !self.DisableInteractive);

            DisableInteractive = true;

            tester.TestAssertion("DisableInteractive true 2", DisableInteractive);

            DisableInteractive = false;
            tester.TestAssertion("DisableInteractive false 2", !DisableInteractive);

            VRCPlayerApi player = null;

            if (Utilities.IsValid(player))
            {
                player.GetPickupInHand(VRC_Pickup.PickupHand.Left);
            }
        }
Beispiel #30
0
        void IntBinaryOps()
        {
            int result = 4 + 6;

            tester.TestAssertion("Integer Addition", result == 10);

            result = 3 - 5;
            tester.TestAssertion("Integer Subtraction", result == -2);

            result = 20 / 3;
            tester.TestAssertion("Integer Division", result == 6);

            result = 5 % 2;
            tester.TestAssertion("Integer Remainder", result == 1);

            result = 2 | 8;
            tester.TestAssertion("Integer OR", result == 10);

            result = 2 & 10;
            tester.TestAssertion("Integer AND", result == 2);

            tester.TestAssertion("Integer Left Shift", 1 << 2 == 4);
            tester.TestAssertion("Integer Right Shift", 4 >> 2 == 1);
            tester.TestAssertion("Integer XOR", (0x499602D3 ^ 0x132C10CB) == 0x5ABA1218); // Randomly chosen numbers
        }