Exemplo n.º 1
0
        public void Compile_Add_OvfTest()
        {
            var madd = ILMethodBuilder.Compile_Add_Ovf();

            Assert.IsNotNull(madd);
            try
            {
                var actual = madd.Invoke(null, Type.EmptyTypes);
            }
            catch (System.Reflection.TargetInvocationException refEx)
            {
                throw refEx.InnerException;
            }
        }
Exemplo n.º 2
0
        public void Compile_Add_OvfTest1()
        {
            var madd = ILMethodBuilder.Compile_Add_Ovf(typeof(long), new[] { typeof(long), typeof(long) });

            Assert.IsNotNull(madd);
            try
            {
                var actual   = madd.Invoke(null, new object[] { 1L, 1L });
                var expected = 2L;
                Assert.IsTrue((long)actual == expected, $"Actual: {actual}\r\n:Expected: {expected}");

                actual = madd.Invoke(null, new object[] { long.MaxValue, long.MaxValue });
            }
            catch (System.Reflection.TargetInvocationException refEx)
            {
                throw refEx.InnerException;
            }
        }
Exemplo n.º 3
0
        public void CompileBinaryTest()
        {
            var madd = ILMethodBuilder.Compile_Add(typeof(uint), typeof(uint), typeof(uint));

            Assert.IsNotNull(madd);
            var actual   = madd.Invoke(null, new object[] { uint.MaxValue, 2u });
            var expected = 1u;

            Assert.IsTrue((uint)actual == expected, $"Actual: {actual}\r\n:Expected: {expected}");


            var test_Add   = ILMethodBuilder.Compile_Add(typeof(uint), typeof(uint), typeof(uint));
            var result_Add = test_Add.Invoke(null, new object[] { uint.MaxValue, 2u });

            Assert.IsTrue((uint)result_Add == expected, $"Actual: {actual}\r\n:Expected: {expected}");

            var test_clt        = ILMethodBuilder.CompileBinary(ILEngine.ILOpCodeValues.Clt, typeof(bool), typeof(uint), typeof(uint));
            var result_test_clt = test_clt.Invoke(null, new object[] { uint.MaxValue, 2u });

            Assert.IsTrue((bool)result_test_clt);
            var result_test_clt2 = test_clt.Invoke(null, new object[] { 2u, uint.MaxValue });

            Assert.IsFalse((bool)result_test_clt2);


            var test_cgt        = ILMethodBuilder.CompileBinary(ILEngine.ILOpCodeValues.Cgt, typeof(bool), typeof(uint), typeof(uint));
            var result_test_cgt = test_cgt.Invoke(null, new object[] { uint.MaxValue, 2u });

            Assert.IsFalse((bool)result_test_cgt);
            var result_test_cgt2 = test_cgt.Invoke(null, new object[] { 2u, uint.MaxValue });

            Assert.IsTrue((bool)result_test_cgt2);

            var test_cgt_un        = ILMethodBuilder.CompileBinary(ILEngine.ILOpCodeValues.Cgt_Un, typeof(bool), typeof(uint), typeof(uint));
            var result_test_cgt_un = test_cgt_un.Invoke(null, new object[] { uint.MaxValue, 2u });

            Assert.IsTrue((bool)result_test_cgt_un);
            var result_test_cgt2_un = test_cgt_un.Invoke(null, new object[] { 2u, uint.MaxValue });

            Assert.IsFalse((bool)result_test_cgt2_un);

            var test_Add_Ovf = ILMethodBuilder.Compile_Add_Ovf(typeof(int), typeof(int), typeof(int));

            Assert.IsNotNull(test_Add_Ovf);
            Exception ex = null;

            try
            {
                var result_Add_Ovf = test_Add_Ovf.Invoke(null, new object[] { int.MaxValue, 1 });
            }
            catch (Exception c)
            {
                ex = c;
            }
            Assert.IsNotNull(ex);
            Assert.IsInstanceOfType(ex, typeof(System.Reflection.TargetInvocationException));
            Assert.IsNotNull(ex.InnerException);
            Assert.IsInstanceOfType(ex.InnerException, typeof(OverflowException));

            var test_Add_Ovf_Un = ILMethodBuilder.Compile_Add_Ovf_Un(typeof(uint), typeof(uint), typeof(uint));

            Assert.IsNotNull(test_Add_Ovf_Un);
            ex = null;

            try
            {
                var result_Add_Ovf_Un = test_Add_Ovf_Un.Invoke(null, new object[] { uint.MaxValue, 2u });
            }
            catch (Exception c)
            {
                ex = c;
            }
            Assert.IsNotNull(ex);
            Assert.IsInstanceOfType(ex, typeof(System.Reflection.TargetInvocationException));
            Assert.IsNotNull(ex.InnerException);
            Assert.IsInstanceOfType(ex.InnerException, typeof(OverflowException));
        }