Пример #1
0
 public void MemberHiding()
 {
     TestDerivedClass tdc = new TestDerivedClass();
     dynamic d = tdc;
     d.Name = "test";
     Assert.Equal("test", tdc.Name);
     Assert.Null(((TestBaseClass)tdc).Name);
 }
Пример #2
0
        public void ByRef()
        {
            dynamic d = new TestDerivedClass();
            int     x;
            dynamic s = "21";

            Assert.True(d.TryParseInt(s, out x));
            Assert.Equal(21, x);
        }
Пример #3
0
        public void GenericMethod()
        {
            dynamic d = new TestDerivedClass();

            Assert.Equal(nameof(Int32), d.TellType(0));
            Assert.Equal(nameof(TestDerivedClass), d.TellType(d));
            // Explicit type selection.
            Assert.Equal(nameof(TestBaseClass), d.TellType <TestBaseClass>(d));
        }
Пример #4
0
        public void MemberHiding()
        {
            TestDerivedClass tdc = new TestDerivedClass();
            dynamic          d   = tdc;

            d.Name = "test";
            Assert.Equal("test", tdc.Name);
            Assert.Null(((TestBaseClass)tdc).Name);
        }
Пример #5
0
        public void TestDerivedIncludesBase()
        {
            TestDerivedClass            tc  = new TestDerivedClass();
            Accessor <TestDerivedClass> tca = tc;

            Assert.IsTrue(tca.ContainsKey("DerivedClassField"));
            Assert.IsTrue(tca.ContainsKey("PublicReadonlyField"));
            Assert.IsTrue(tca.ContainsKey("PublicField"));
            Assert.IsTrue(tca.ContainsKey("PublicAutoProperty"));
            Assert.IsTrue(tca.ContainsKey("PublicGetterProperty"));
        }
Пример #6
0
        public void IsValid_Should_Return_True_Object_When_T_Is_Base_Type()
        {
            // Arrange
            var validator = new ValidationHelper();
            var testClass = new TestDerivedClass();

            // Act
            var errors = validator.IsValid <TestBaseClass>(testClass);

            // Assert
            Assert.IsTrue(errors);
        }
Пример #7
0
        public void Test_Validate_Should_Return_Null_Object_When_T_Is_Base_Type()
        {
            // Arrange
            var ValidateService = new ValidateService();
            var testClass       = new TestDerivedClass();

            // Act
            var errors = ValidateService.Validate <TestBaseClass>(testClass);

            // Assert
            Assert.IsNull(errors);
        }
        public void _0001_ChangeTest()
        {
            var instance = new TestDerivedClass();

            instance.PropertyChanged += (sender, e) =>
                                        Console.WriteLine("Changed PropName:" + e.PropertyName);
            instance.FirstName = "Homer";
            instance.LastName  = "Simpson";
            instance.FirstName = "Bart";
            instance.LastName  = "Simpson";

            /*Changed PropName:FirstName
             * Changed PropName:LastName
             * Changed PropName:FirstName*/
        }
Пример #9
0
        public void ToDebugString_WithDerivedClass_AlsoOutputsBaseClassMembers()
        {
            const string baseCanary    = "esd4v689skrvtrgir rwor hg reakjh hljfd";
            const string derivedCanary = "pfnc9tj78fpm8 7l5rosdaaaaaaaa";

            var o = new TestDerivedClass
            {
                BaseString    = baseCanary,
                DerivedString = derivedCanary
            };

            var output = Helpers.Debug.ToDebugString(o);

            _logger.LogDebug(output);

            Assert.IsTrue(output.Contains(baseCanary));
            Assert.IsTrue(output.Contains(derivedCanary));
        }
Пример #10
0
        public void MemberHiding()
        {
            dynamic d = new TestDerivedClass();

            Assert.Equal(nameof(TestDerivedClass), d.Name);
        }
Пример #11
0
    private static unsafe void Main(string[] args)
    {
        Add(1, 2);
        int tempInt = 0;

        (*(&tempInt)) = 9;
        if (tempInt == 9)
        {
            PrintLine("Hello from C#!");
        }

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        if (str2.second == 4)
        {
            PrintLine("value type int field test: Ok.");
        }

        staticInt = 5;
        if (staticInt == 5)
        {
            PrintLine("static int field test: Ok.");
        }

        if (threadStaticInt == 0)
        {
            PrintLine("thread static int initial value field test: Ok.");
        }

        threadStaticInt = 9;
        if (threadStaticInt == 9)
        {
            PrintLine("thread static int field test: Ok.");
        }

        StaticCtorTest();

        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PrintLine("box test: Ok.");
        }

        var boxedStruct = (object)new BoxStubTest {
            Value = "Boxed Stub Test: Ok."
        };

        PrintLine(boxedStruct.ToString());

        int subResult = tempInt - 1;

        if (subResult == 8)
        {
            PrintLine("Subtraction Test: Ok.");
        }

        int divResult = tempInt / 3;

        if (divResult == 3)
        {
            PrintLine("Division Test: Ok.");
        }

        var not = Not(0xFFFFFFFF) == 0x00000000;

        if (not)
        {
            PrintLine("not test: Ok.");
        }

        var negInt = Neg(42) == -42;

        if (negInt)
        {
            PrintLine("negInt test: Ok.");
        }

        var shiftLeft = ShiftLeft(1, 2) == 4;

        if (shiftLeft)
        {
            PrintLine("shiftLeft test: Ok.");
        }

        var shiftRight = ShiftRight(4, 2) == 1;

        if (shiftRight)
        {
            PrintLine("shiftRight test: Ok.");
        }

        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        if (unsignedShift)
        {
            PrintLine("unsignedShift test: Ok.");
        }

        var switchTest0 = SwitchOp(5, 5, 0);

        if (switchTest0 == 10)
        {
            PrintLine("SwitchOp0 test: Ok.");
        }

        var switchTest1 = SwitchOp(5, 5, 1);

        if (switchTest1 == 25)
        {
            PrintLine("SwitchOp1 test: Ok.");
        }

        var switchTestDefault = SwitchOp(5, 5, 20);

        if (switchTestDefault == 0)
        {
            PrintLine("SwitchOpDefault test: Ok.");
        }

#if PLATFORM_WINDOWS
        var cpObjTestA = new TestValue {
            Field = 1234
        };
        var cpObjTestB = new TestValue {
            Field = 5678
        };
        CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
        if (cpObjTestB.Field == 1234)
        {
            PrintLine("CpObj test: Ok.");
        }
#endif

        Func <int> staticDelegate = StaticDelegateTarget;
        if (staticDelegate() == 7)
        {
            PrintLine("Static delegate test: Ok.");
        }

        tempObj.TestInt = 8;
        Func <int> instanceDelegate = tempObj.InstanceDelegateTarget;
        if (instanceDelegate() == 8)
        {
            PrintLine("Instance delegate test: Ok.");
        }

        Action virtualDelegate = tempObj.VirtualDelegateTarget;
        virtualDelegate();

        var arrayTest = new BoxStubTest[] { new BoxStubTest {
                                                Value = "Hello"
                                            }, new BoxStubTest {
                                                Value = "Array"
                                            }, new BoxStubTest {
                                                Value = "Test"
                                            } };
        foreach (var element in arrayTest)
        {
            PrintLine(element.Value);
        }

        arrayTest[1].Value = "Array load/store test: Ok.";
        PrintLine(arrayTest[1].Value);

        var largeArrayTest = new long[] { Int64.MaxValue, 0, Int64.MinValue, 0 };
        if (largeArrayTest[0] == Int64.MaxValue &&
            largeArrayTest[1] == 0 &&
            largeArrayTest[2] == Int64.MinValue &&
            largeArrayTest[3] == 0)
        {
            PrintLine("Large array load/store test: Ok.");
        }

        var smallArrayTest = new long[] { Int16.MaxValue, 0, Int16.MinValue, 0 };
        if (smallArrayTest[0] == Int16.MaxValue &&
            smallArrayTest[1] == 0 &&
            smallArrayTest[2] == Int16.MinValue &&
            smallArrayTest[3] == 0)
        {
            PrintLine("Small array load/store test: Ok.");
        }

        IntPtr returnedIntPtr = NewobjValueType();
        if (returnedIntPtr.ToInt32() == 3)
        {
            PrintLine("Newobj value type test: Ok.");
        }

        StackallocTest();

        IntToStringTest();

        CastingTestClass castingTest = new DerivedCastingTestClass1();
        if (((DerivedCastingTestClass1)castingTest).GetValue() == 1 && !(castingTest is DerivedCastingTestClass2))
        {
            PrintLine("Type casting with isinst & castclass to class test: Ok.");
        }

        // Instead of checking the result of `GetValue`, we use null check by now until interface dispatch is implemented.
        if ((ICastingTest1)castingTest != null && !(castingTest is ICastingTest2))
        {
            PrintLine("Type casting with isinst & castclass to interface test: Ok.");
        }

        object arrayCastingTest = new BoxStubTest[] { new BoxStubTest {
                                                          Value = "Array"
                                                      }, new BoxStubTest {
                                                          Value = "Cast"
                                                      }, new BoxStubTest {
                                                          Value = "Test"
                                                      } };
        PrintLine(((BoxStubTest[])arrayCastingTest)[0].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[1].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[2].Value);
        if (!(arrayCastingTest is CastingTestClass[]))
        {
            PrintLine("Type casting with isinst & castclass to array test: Ok.");
        }

        ldindTest();

        InterfaceDispatchTest();

        var testRuntimeHelpersInitArray = new long[] { 1, 2, 3 };
        if (testRuntimeHelpersInitArray[0] == 1 &&
            testRuntimeHelpersInitArray[1] == 2 &&
            testRuntimeHelpersInitArray[2] == 3)
        {
            PrintLine("Runtime.Helpers array initialization test: Ok.");
        }

        // This test should remain last to get other results before stopping the debugger
        PrintLine("Debugger.Break() test: Ok if debugger is open and breaks.");
        System.Diagnostics.Debugger.Break();

        PrintLine("Done");
    }
Пример #12
0
    private static unsafe int Main(string[] args)
    {
        Success = true;
        PrintLine("Starting");

        Add(1, 2);
        PrintLine("Hello from C#!");
        int tempInt  = 0;
        int tempInt2 = 0;

        StartTest("Address/derefernce test");
        (*(&tempInt)) = 9;
        EndTest(tempInt == 9);

        int *targetAddr = (tempInt > 0) ? (&tempInt2) : (&tempInt);

        StartTest("basic block stack entry Test");
        (*targetAddr) = 1;
        EndTest(tempInt2 == 1 && tempInt == 9);

        StartTest("Inline assign byte Test");
        EndTest(ILHelpers.ILHelpersTest.InlineAssignByte() == 100);

        StartTest("dup test");
        int dupTestInt = 9;

        EndTest(ILHelpers.ILHelpersTest.DupTest(ref dupTestInt) == 209 && dupTestInt == 209);

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        StartTest("value type int field test");
        EndTest(str2.second == 4);

        StartTest("static int field test");
        staticInt = 5;
        EndTest(staticInt == 5);

        StartTest("thread static int initial value field test");
        EndTest(threadStaticInt == 0);

        StartTest("thread static int field test");
        threadStaticInt = 9;
        EndTest(threadStaticInt == 9);

        StaticCtorTest();

        StartTest("box test");
        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PassTest();
        }
        else
        {
            FailTest();
            PrintLine("Value:");
            PrintLine(boxedInt.ToString());
        }

        var boxedStruct = (object)new BoxStubTest {
            Value = "Boxed Stub Test: Ok."
        };

        PrintLine(boxedStruct.ToString());

        StartTest("Subtraction Test");
        int subResult = tempInt - 1;

        EndTest(subResult == 8);

        StartTest("Division Test");
        int divResult = tempInt / 3;

        EndTest(divResult == 3);

        StartTest("not test");
        var not = Not(0xFFFFFFFF) == 0x00000000;

        EndTest(not);

        StartTest("negInt test");
        var negInt = Neg(42) == -42;

        EndTest(negInt);

        StartTest("shiftLeft test");
        var shiftLeft = ShiftLeft(1, 2) == 4;

        EndTest(shiftLeft);

        StartTest("shiftRight test");
        var shiftRight = ShiftRight(4, 2) == 1;

        EndTest(shiftRight);

        StartTest("unsignedShift test");
        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        EndTest(unsignedShift);

        StartTest("SwitchOp0 test");
        var switchTest0 = SwitchOp(5, 5, 0);

        EndTest(switchTest0 == 10);

        StartTest("SwitchOp1 test");
        var switchTest1 = SwitchOp(5, 5, 1);

        EndTest(switchTest1 == 25);

        StartTest("SwitchOpDefault test");
        var switchTestDefault = SwitchOp(5, 5, 20);

        EndTest(switchTestDefault == 0);

#if PLATFORM_WINDOWS
        StartTest("CpObj test");
        var cpObjTestA = new TestValue {
            Field = 1234
        };
        var cpObjTestB = new TestValue {
            Field = 5678
        };
        CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
        EndTest(cpObjTestB.Field == 1234);
#endif

        StartTest("Static delegate test");
        Func <int> staticDelegate = StaticDelegateTarget;
        EndTest(staticDelegate() == 7);

        StartTest("Instance delegate test");
        tempObj.TestInt = 8;
        Func <int> instanceDelegate = tempObj.InstanceDelegateTarget;
        EndTest(instanceDelegate() == 8);

        StartTest("Virtual Delegate Test");
        Action virtualDelegate = tempObj.VirtualDelegateTarget;
        virtualDelegate();

        var arrayTest = new BoxStubTest[] { new BoxStubTest {
                                                Value = "Hello"
                                            }, new BoxStubTest {
                                                Value = "Array"
                                            }, new BoxStubTest {
                                                Value = "Test"
                                            } };
        foreach (var element in arrayTest)
        {
            PrintLine(element.Value);
        }

        arrayTest[1].Value = "Array load/store test: Ok.";
        PrintLine(arrayTest[1].Value);

        int ii = 0;
        arrayTest[ii++].Value = "dup ref test: Ok.";
        PrintLine(arrayTest[0].Value);

        StartTest("Large array load/store test");
        var largeArrayTest = new long[] { Int64.MaxValue, 0, Int64.MinValue, 0 };
        EndTest(largeArrayTest[0] == Int64.MaxValue &&
                largeArrayTest[1] == 0 &&
                largeArrayTest[2] == Int64.MinValue &&
                largeArrayTest[3] == 0);

        StartTest("Small array load/store test");
        var smallArrayTest = new long[] { Int16.MaxValue, 0, Int16.MinValue, 0 };
        EndTest(smallArrayTest[0] == Int16.MaxValue &&
                smallArrayTest[1] == 0 &&
                smallArrayTest[2] == Int16.MinValue &&
                smallArrayTest[3] == 0);

        StartTest("Newobj value type test");
        IntPtr returnedIntPtr = NewobjValueType();
        EndTest(returnedIntPtr.ToInt32() == 3);

        StackallocTest();

        IntToStringTest();

        CastingTestClass castingTest = new DerivedCastingTestClass1();

        PrintLine("interface call test: Ok " + (castingTest as ICastingTest1).GetValue().ToString());

        StartTest("Type casting with isinst & castclass to class test");
        EndTest(((DerivedCastingTestClass1)castingTest).GetValue() == 1 && !(castingTest is DerivedCastingTestClass2));

        StartTest("Type casting with isinst & castclass to interface test");
        // Instead of checking the result of `GetValue`, we use null check by now until interface dispatch is implemented.
        EndTest((ICastingTest1)castingTest != null && !(castingTest is ICastingTest2));

        StartTest("Type casting with isinst & castclass to array test");
        object arrayCastingTest = new BoxStubTest[] { new BoxStubTest {
                                                          Value = "Array"
                                                      }, new BoxStubTest {
                                                          Value = "Cast"
                                                      }, new BoxStubTest {
                                                          Value = "Test"
                                                      } };
        PrintLine(((BoxStubTest[])arrayCastingTest)[0].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[1].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[2].Value);
        EndTest(!(arrayCastingTest is CastingTestClass[]));

        ldindTest();

        InterfaceDispatchTest();

        StartTest("Runtime.Helpers array initialization test");
        var testRuntimeHelpersInitArray = new long[] { 1, 2, 3 };
        EndTest(testRuntimeHelpersInitArray[0] == 1 &&
                testRuntimeHelpersInitArray[1] == 2 &&
                testRuntimeHelpersInitArray[2] == 3);

        StartTest("Multi-dimension array instantiation test");
        var testMdArrayInstantiation = new int[2, 2];
        EndTest(testMdArrayInstantiation != null && testMdArrayInstantiation.GetLength(0) == 2 && testMdArrayInstantiation.GetLength(1) == 2);

        StartTest("Multi-dimension array get/set test");
        testMdArrayInstantiation[0, 0] = 1;
        testMdArrayInstantiation[0, 1] = 2;
        testMdArrayInstantiation[1, 0] = 3;
        testMdArrayInstantiation[1, 1] = 4;
        EndTest(testMdArrayInstantiation[0, 0] == 1 &&
                testMdArrayInstantiation[0, 1] == 2 &&
                testMdArrayInstantiation[1, 0] == 3 &&
                testMdArrayInstantiation[1, 1] == 4);


        FloatDoubleTest();

        StartTest("long comparison");
        long l = 0x1;
        EndTest(l < 0x7FF0000000000000);

        // Create a ByReference<char> through the ReadOnlySpan ctor and call the ByReference.Value via the indexer.
        StartTest("ByReference intrinsics exercise via ReadOnlySpan");
        var span = "123".AsSpan();
        if (span[0] != '1' ||
            span[1] != '2' ||
            span[2] != '3')
        {
            FailTest();
            PrintLine(span[0].ToString());
            PrintLine(span[1].ToString());
            PrintLine(span[2].ToString());
        }
        else
        {
            PassTest();
        }

        TestConstrainedClassCalls();

        TestValueTypeElementIndexing();

        TestArrayItfDispatch();

        TestMetaData();

        TestTryFinally();

        StartTest("RVA static field test");
        int rvaFieldValue = ILHelpers.ILHelpersTest.StaticInitedInt;
        if (rvaFieldValue == 0x78563412)
        {
            PassTest();
        }
        else
        {
            FailTest(rvaFieldValue.ToString());
        }

        TestNativeCallback();

        TestArgsWithMixedTypesAndExceptionRegions();

        TestThreadStaticsForSingleThread();

        TestDispose();

        // This test should remain last to get other results before stopping the debugger
        PrintLine("Debugger.Break() test: Ok if debugger is open and breaks.");
        System.Diagnostics.Debugger.Break();

        PrintLine("Done");
        return(Success ? 100 : -1);
    }
Пример #13
0
    private static unsafe void Main(string[] args)
    {
        Add(1, 2);
        int tempInt = 0;

        (*(&tempInt)) = 9;
        if (tempInt == 9)
        {
            PrintLine("Hello from C#!");
        }

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        if (str2.second == 4)
        {
            PrintLine("value type int field test: Ok.");
        }

        staticInt = 5;
        if (staticInt == 5)
        {
            PrintLine("static int field test: Ok.");
        }

        if (threadStaticInt == 0)
        {
            PrintLine("thread static int initial value field test: Ok.");
        }

        threadStaticInt = 9;
        if (threadStaticInt == 9)
        {
            PrintLine("thread static int field test: Ok.");
        }

        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PrintLine("box test: Ok.");
        }

        var boxedStruct = (object)new BoxStubTest {
            Value = "Boxed Stub Test: Ok."
        };

        PrintLine(boxedStruct.ToString());

        var not = Not(0xFFFFFFFF) == 0x00000000;

        if (not)
        {
            PrintLine("not test: Ok.");
        }

        var negInt = Neg(42) == -42;

        if (negInt)
        {
            PrintLine("negInt test: Ok.");
        }

        var shiftLeft = ShiftLeft(1, 2) == 4;

        if (shiftLeft)
        {
            PrintLine("shiftLeft test: Ok.");
        }

        var shiftRight = ShiftRight(4, 2) == 1;

        if (shiftRight)
        {
            PrintLine("shiftRight test: Ok.");
        }

        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        if (unsignedShift)
        {
            PrintLine("unsignedShift test: Ok.");
        }

        var switchTest0 = SwitchOp(5, 5, 0);

        if (switchTest0 == 10)
        {
            PrintLine("SwitchOp0 test: Ok.");
        }

        var switchTest1 = SwitchOp(5, 5, 1);

        if (switchTest1 == 25)
        {
            PrintLine("SwitchOp1 test: Ok.");
        }

        var switchTestDefault = SwitchOp(5, 5, 20);

        if (switchTestDefault == 0)
        {
            PrintLine("SwitchOpDefault test: Ok.");
        }

        var cpObjTestA = new TestValue {
            Field = 1234
        };
        var cpObjTestB = new TestValue {
            Field = 5678
        };

        CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
        if (cpObjTestB.Field == 1234)
        {
            PrintLine("CpObj test: Ok.");
        }

        Func <int> staticDelegate = StaticDelegateTarget;

        if (staticDelegate() == 7)
        {
            PrintLine("Static delegate test: Ok.");
        }

        tempObj.TestInt = 8;
        Func <int> instanceDelegate = tempObj.InstanceDelegateTarget;

        if (instanceDelegate() == 8)
        {
            PrintLine("Instance delegate test: Ok.");
        }

        Action virtualDelegate = tempObj.VirtualDelegateTarget;

        virtualDelegate();

        var arrayTest = new BoxStubTest[] { new BoxStubTest {
                                                Value = "Hello"
                                            }, new BoxStubTest {
                                                Value = "Array"
                                            }, new BoxStubTest {
                                                Value = "Test"
                                            } };

        foreach (var element in arrayTest)
        {
            PrintLine(element.Value);
        }

        arrayTest[1].Value = "Array load/store test: Ok.";
        PrintLine(arrayTest[1].Value);

        var largeArrayTest = new long[] { Int64.MaxValue, 0, Int64.MinValue, 0 };

        if (largeArrayTest[0] == Int64.MaxValue &&
            largeArrayTest[1] == 0 &&
            largeArrayTest[2] == Int64.MinValue &&
            largeArrayTest[3] == 0)
        {
            PrintLine("Large array load/store test: Ok.");
        }

        var smallArrayTest = new long[] { Int16.MaxValue, 0, Int16.MinValue, 0 };

        if (smallArrayTest[0] == Int16.MaxValue &&
            smallArrayTest[1] == 0 &&
            smallArrayTest[2] == Int16.MinValue &&
            smallArrayTest[3] == 0)
        {
            PrintLine("Small array load/store test: Ok.");
        }

        PrintLine("Done");
    }
Пример #14
0
        public void MethodHiding()
        {
            dynamic d = new TestDerivedClass();

            Assert.Equal("Hiding", d.Method(1, 2));
        }
Пример #15
0
        public void NoArgumentMatch()
        {
            dynamic d = new TestDerivedClass();

            Assert.Throws <RuntimeBinderException>(() => d.Method());
        }
Пример #16
0
    private static unsafe void Main(string[] args)
    {
        Add(1, 2);
        int tempInt = 0;

        (*(&tempInt)) = 9;
        if (tempInt == 9)
        {
            PrintLine("Hello from C#!");
        }

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        if (str2.second == 4)
        {
            PrintLine("value type int field test: Ok.");
        }

        staticInt = 5;
        if (staticInt == 5)
        {
            PrintLine("static int field test: Ok.");
        }

        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PrintLine("box test: Ok.");
        }

        var not = Not(0xFFFFFFFF) == 0x00000000;

        if (not)
        {
            PrintLine("not test: Ok.");
        }

        var negInt = Neg(42) == -42;

        if (negInt)
        {
            PrintLine("negInt test: Ok.");
        }

        var shiftLeft = ShiftLeft(1, 2) == 4;

        if (shiftLeft)
        {
            PrintLine("shiftLeft test: Ok.");
        }

        var shiftRight = ShiftRight(4, 2) == 1;

        if (shiftRight)
        {
            PrintLine("shiftRight test: Ok.");
        }

        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        if (unsignedShift)
        {
            PrintLine("unsignedShift test: Ok.");
        }

        var switchTest0 = SwitchOp(5, 5, 0);

        if (switchTest0 == 10)
        {
            PrintLine("SwitchOp0 test: Ok.");
        }

        var switchTest1 = SwitchOp(5, 5, 1);

        if (switchTest1 == 25)
        {
            PrintLine("SwitchOp1 test: Ok.");
        }

        var switchTestDefault = SwitchOp(5, 5, 20);

        if (switchTestDefault == 0)
        {
            PrintLine("SwitchOpDefault test: Ok.");
        }
    }
Пример #17
0
    private static unsafe int Main(string[] args)
    {
        Add(1, 2);
        int tempInt  = 0;
        int tempInt2 = 0;

        (*(&tempInt)) = 9;
        if (tempInt == 9)
        {
            PrintLine("Hello from C#!");
        }

        int *targetAddr = (tempInt > 0) ? (&tempInt2) : (&tempInt);

        (*targetAddr) = 1;
        if (tempInt2 == 1 && tempInt == 9)
        {
            PrintLine("basic block stack entry Test: Ok.");
        }

        if (ILHelpers.ILHelpersTest.InlineAssignByte() == 100)
        {
            PrintLine("Inline assign byte Test: Ok.");
        }

        if (ILHelpers.ILHelpersTest.DupTest(ref tempInt) == 209 && tempInt == 209)
        {
            PrintLine("dup test: Ok.");
        }

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        if (str2.second == 4)
        {
            PrintLine("value type int field test: Ok.");
        }

        staticInt = 5;
        if (staticInt == 5)
        {
            PrintLine("static int field test: Ok.");
        }

        if (threadStaticInt == 0)
        {
            PrintLine("thread static int initial value field test: Ok.");
        }

        threadStaticInt = 9;
        if (threadStaticInt == 9)
        {
            PrintLine("thread static int field test: Ok.");
        }

        StaticCtorTest();

        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PrintLine("box test: Ok.");
        }

        var boxedStruct = (object)new BoxStubTest {
            Value = "Boxed Stub Test: Ok."
        };

        PrintLine(boxedStruct.ToString());

        int subResult = tempInt - 1;

        if (subResult == 8)
        {
            PrintLine("Subtraction Test: Ok.");
        }

        int divResult = tempInt / 3;

        if (divResult == 3)
        {
            PrintLine("Division Test: Ok.");
        }

        var not = Not(0xFFFFFFFF) == 0x00000000;

        if (not)
        {
            PrintLine("not test: Ok.");
        }

        var negInt = Neg(42) == -42;

        if (negInt)
        {
            PrintLine("negInt test: Ok.");
        }

        var shiftLeft = ShiftLeft(1, 2) == 4;

        if (shiftLeft)
        {
            PrintLine("shiftLeft test: Ok.");
        }

        var shiftRight = ShiftRight(4, 2) == 1;

        if (shiftRight)
        {
            PrintLine("shiftRight test: Ok.");
        }

        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        if (unsignedShift)
        {
            PrintLine("unsignedShift test: Ok.");
        }

        var switchTest0 = SwitchOp(5, 5, 0);

        if (switchTest0 == 10)
        {
            PrintLine("SwitchOp0 test: Ok.");
        }

        var switchTest1 = SwitchOp(5, 5, 1);

        if (switchTest1 == 25)
        {
            PrintLine("SwitchOp1 test: Ok.");
        }

        var switchTestDefault = SwitchOp(5, 5, 20);

        if (switchTestDefault == 0)
        {
            PrintLine("SwitchOpDefault test: Ok.");
        }

#if PLATFORM_WINDOWS
        var cpObjTestA = new TestValue {
            Field = 1234
        };
        var cpObjTestB = new TestValue {
            Field = 5678
        };
        CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
        if (cpObjTestB.Field == 1234)
        {
            PrintLine("CpObj test: Ok.");
        }
#endif

        Func <int> staticDelegate = StaticDelegateTarget;
        if (staticDelegate() == 7)
        {
            PrintLine("Static delegate test: Ok.");
        }

        tempObj.TestInt = 8;
        Func <int> instanceDelegate = tempObj.InstanceDelegateTarget;
        if (instanceDelegate() == 8)
        {
            PrintLine("Instance delegate test: Ok.");
        }

        Action virtualDelegate = tempObj.VirtualDelegateTarget;
        virtualDelegate();

        var arrayTest = new BoxStubTest[] { new BoxStubTest {
                                                Value = "Hello"
                                            }, new BoxStubTest {
                                                Value = "Array"
                                            }, new BoxStubTest {
                                                Value = "Test"
                                            } };
        foreach (var element in arrayTest)
        {
            PrintLine(element.Value);
        }

        arrayTest[1].Value = "Array load/store test: Ok.";
        PrintLine(arrayTest[1].Value);

        int ii = 0;
        arrayTest[ii++].Value = "dup ref test: Ok.";
        PrintLine(arrayTest[0].Value);

        var largeArrayTest = new long[] { Int64.MaxValue, 0, Int64.MinValue, 0 };
        if (largeArrayTest[0] == Int64.MaxValue &&
            largeArrayTest[1] == 0 &&
            largeArrayTest[2] == Int64.MinValue &&
            largeArrayTest[3] == 0)
        {
            PrintLine("Large array load/store test: Ok.");
        }

        var smallArrayTest = new long[] { Int16.MaxValue, 0, Int16.MinValue, 0 };
        if (smallArrayTest[0] == Int16.MaxValue &&
            smallArrayTest[1] == 0 &&
            smallArrayTest[2] == Int16.MinValue &&
            smallArrayTest[3] == 0)
        {
            PrintLine("Small array load/store test: Ok.");
        }

        IntPtr returnedIntPtr = NewobjValueType();
        if (returnedIntPtr.ToInt32() == 3)
        {
            PrintLine("Newobj value type test: Ok.");
        }

        StackallocTest();

        IntToStringTest();

        CastingTestClass castingTest = new DerivedCastingTestClass1();

        PrintLine("interface call test: Ok " + (castingTest as ICastingTest1).GetValue().ToString());

        if (((DerivedCastingTestClass1)castingTest).GetValue() == 1 && !(castingTest is DerivedCastingTestClass2))
        {
            PrintLine("Type casting with isinst & castclass to class test: Ok.");
        }

        // Instead of checking the result of `GetValue`, we use null check by now until interface dispatch is implemented.
        if ((ICastingTest1)castingTest != null && !(castingTest is ICastingTest2))
        {
            PrintLine("Type casting with isinst & castclass to interface test: Ok.");
        }

        object arrayCastingTest = new BoxStubTest[] { new BoxStubTest {
                                                          Value = "Array"
                                                      }, new BoxStubTest {
                                                          Value = "Cast"
                                                      }, new BoxStubTest {
                                                          Value = "Test"
                                                      } };
        PrintLine(((BoxStubTest[])arrayCastingTest)[0].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[1].Value);
        PrintLine(((BoxStubTest[])arrayCastingTest)[2].Value);
        if (!(arrayCastingTest is CastingTestClass[]))
        {
            PrintLine("Type casting with isinst & castclass to array test: Ok.");
        }

        ldindTest();

        InterfaceDispatchTest();

        var testRuntimeHelpersInitArray = new long[] { 1, 2, 3 };
        if (testRuntimeHelpersInitArray[0] == 1 &&
            testRuntimeHelpersInitArray[1] == 2 &&
            testRuntimeHelpersInitArray[2] == 3)
        {
            PrintLine("Runtime.Helpers array initialization test: Ok.");
        }

        int    intToCast    = 1;
        double castedDouble = (double)intToCast;
        if (castedDouble == 1d)
        {
            PrintLine("(double) cast test: Ok.");
        }
        else
        {
            var toInt = (int)castedDouble;
//            PrintLine("expected 1m, but was " + castedDouble.ToString());  // double.ToString is not compiling at the time of writing, but this would be better output
            PrintLine($"(double) cast test : Failed. Back to int on next line");
            PrintLine(toInt.ToString());
        }

        if (1f < 2d && 1d < 2f && 1f == 1d)
        {
            PrintLine("different width float comparisons: Ok.");
        }

        // floats are 7 digits precision, so check some double more precise to make sure there is no loss occurring through some inadvertent cast to float
        if (10.23456789d != 10.234567891d)
        {
            PrintLine("double precision comparison: Ok.");
        }

        if (12.34567f == 12.34567f && 12.34567f != 12.34568f)
        {
            PrintLine("float comparison: Ok.");
        }

        // This test should remain last to get other results before stopping the debugger
        PrintLine("Debugger.Break() test: Ok if debugger is open and breaks.");
        System.Diagnostics.Debugger.Break();

        PrintLine("Done");
        return(100);
    }
Пример #18
0
        public void Validate_Should_Return_Null_Object_When_T_Is_Base_Type()
        {
            // Arrange
            var validator = new Validator();
            var testClass = new TestDerivedClass();

            // Act
            var errors = validator.Validate<TestBaseClass>(testClass);

            // Assert
            Assert.IsNull(errors);
        }
Пример #19
0
 public void TestDerivedIncludesBase()
 {
     TestDerivedClass tc = new TestDerivedClass();
     Accessor<TestDerivedClass> tca = tc;
     Assert.IsTrue(tca.ContainsKey("DerivedClassField"));
     Assert.IsTrue(tca.ContainsKey("PublicReadonlyField"));
     Assert.IsTrue(tca.ContainsKey("PublicField"));
     Assert.IsTrue(tca.ContainsKey("PublicAutoProperty"));
     Assert.IsTrue(tca.ContainsKey("PublicGetterProperty"));
 }
Пример #20
0
 public void MemberHiding()
 {
     dynamic d = new TestDerivedClass();
     Assert.Equal(nameof(TestDerivedClass), d.Name);
 }
Пример #21
0
    private static unsafe void Main(string[] args)
    {
        Add(1, 2);
        int tempInt = 0;

        (*(&tempInt)) = 9;
        if (tempInt == 9)
        {
            PrintLine("Hello from C#!");
        }

        TestClass tempObj = new TestDerivedClass(1337);

        tempObj.TestMethod("Hello");
        tempObj.TestVirtualMethod("Hello");
        tempObj.TestVirtualMethod2("Hello");

        TwoByteStr str = new TwoByteStr()
        {
            first = 1, second = 2
        };
        TwoByteStr str2 = new TwoByteStr()
        {
            first = 3, second = 4
        };

        *(&str) = str2;
        str2    = *(&str);

        if (str2.second == 4)
        {
            PrintLine("value type int field test: Ok.");
        }

        staticInt = 5;
        if (staticInt == 5)
        {
            PrintLine("static int field test: Ok.");
        }

        if (threadStaticInt == 0)
        {
            PrintLine("thread static int initial value field test: Ok.");
        }

        threadStaticInt = 9;
        if (threadStaticInt == 9)
        {
            PrintLine("thread static int field test: Ok.");
        }

        var boxedInt = (object)tempInt;

        if (((int)boxedInt) == 9)
        {
            PrintLine("box test: Ok.");
        }

        var boxedStruct = (object)new BoxStubTest {
            Value = "Boxed Stub Test: Ok."
        };

        PrintLine(boxedStruct.ToString());

        var not = Not(0xFFFFFFFF) == 0x00000000;

        if (not)
        {
            PrintLine("not test: Ok.");
        }

        var negInt = Neg(42) == -42;

        if (negInt)
        {
            PrintLine("negInt test: Ok.");
        }

        var shiftLeft = ShiftLeft(1, 2) == 4;

        if (shiftLeft)
        {
            PrintLine("shiftLeft test: Ok.");
        }

        var shiftRight = ShiftRight(4, 2) == 1;

        if (shiftRight)
        {
            PrintLine("shiftRight test: Ok.");
        }

        var unsignedShift = UnsignedShift(0xFFFFFFFFu, 4) == 0x0FFFFFFFu;

        if (unsignedShift)
        {
            PrintLine("unsignedShift test: Ok.");
        }

        var switchTest0 = SwitchOp(5, 5, 0);

        if (switchTest0 == 10)
        {
            PrintLine("SwitchOp0 test: Ok.");
        }

        var switchTest1 = SwitchOp(5, 5, 1);

        if (switchTest1 == 25)
        {
            PrintLine("SwitchOp1 test: Ok.");
        }

        var switchTestDefault = SwitchOp(5, 5, 20);

        if (switchTestDefault == 0)
        {
            PrintLine("SwitchOpDefault test: Ok.");
        }

        var cpObjTestA = new TestValue {
            Field = 1234
        };
        var cpObjTestB = new TestValue {
            Field = 5678
        };

        CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
        if (cpObjTestB.Field == 1234)
        {
            PrintLine("CpObj test: Ok.");
        }
    }