Пример #1
0
        public void MultiClassInheritance()
        {
            Variable c = DefaultModule.GetVariable("multiClassInheritanceTest");

            Assert.Equal(42, (double)c.GetField("c"));
            Assert.Equal(42, (int)c.GetField("b"));
            Assert.Equal(42, (float)c.GetField("a"));
            Variable a = c.GetBaseClass("MultiClassInheritanceA");

            Assert.Equal(42, (float)a.GetField("a"));
            Variable b = c.GetBaseClass("MultiClassInheritanceB");

            Assert.Equal(42, (int)b.GetField("b"));
            Assert.Equal(c.GetPointerAddress(), a.DowncastInterface().GetPointerAddress());
            Assert.Equal(c.GetPointerAddress(), b.DowncastInterface().GetPointerAddress());

            if (ExecuteCodeGen)
            {
                InterpretInteractive($@"
Variable global = Process.Current.GetGlobal(""{DefaultModuleName}!multiClassInheritanceTest"");
var c = new MultiClassInheritanceC(global);
var a = c.BaseClass_MultiClassInheritanceA;
var b = c.BaseClass_MultiClassInheritanceB;
AreEqual(42, c.c);
AreEqual(42, a.a);
AreEqual(42, b.b);
IsTrue(a.GetDowncast() is MultiClassInheritanceC);
IsTrue(b.GetDowncast() is MultiClassInheritanceC);
AreEqual(42, a.As<MultiClassInheritanceB>().b);
                    ");
            }
        }
Пример #2
0
        public void SimpleMultiClassInheritance()
        {
            Variable c = DefaultModule.GetVariable("simpleMultiClassInheritanceTest");

            Assert.Equal(42.0f, (float)c.GetField("c"));
            Assert.Equal(42.0, (double)c.GetField("b"));
            Assert.Equal(42, (byte)c.GetField("a"));
            Variable a = c.GetBaseClass("SimpleMultiClassInheritanceA");

            Assert.Equal(42, (byte)a.GetField("a"));
            Variable b = c.GetBaseClass("SimpleMultiClassInheritanceB");

            Assert.Equal(42.0, (double)b.GetField("b"));

            if (ExecuteCodeGen)
            {
                InterpretInteractive($@"
Variable global = Process.Current.GetGlobal(""{DefaultModuleName}!simpleMultiClassInheritanceTest"");
var c = new SimpleMultiClassInheritanceC(global);
AreEqual(42.0f, c.c);
AreEqual(42, c.BaseClass_SimpleMultiClassInheritanceA.a);
AreEqual(42.0, c.BaseClass_SimpleMultiClassInheritanceB.b);
                    ");
            }
        }
Пример #3
0
        public void VirtualMultiClassInheritance2()
        {
            Variable e = DefaultModule.GetVariable("virtualMultiClassInheritanceTest2");

            Assert.Equal(42, (int)e.GetField("e"));
            Assert.Equal(42, (double)e.GetField("b"));
            Assert.Equal(42, (float)e.GetField("c"));
            Assert.Equal(42, (sbyte)e.GetField("a"));
            Variable a = e.GetBaseClass("VirtualMultiClassInheritanceA");

            Assert.Equal(42, (sbyte)a.GetField("a"));
            Variable b = e.GetBaseClass("VirtualMultiClassInheritanceB");

            Assert.Equal(42, (double)b.GetField("b"));
            Variable ba = b.GetBaseClass("VirtualMultiClassInheritanceA");

            Assert.Equal(42, (sbyte)ba.GetField("a"));
            Variable c = e.GetBaseClass("VirtualMultiClassInheritanceC");

            Assert.Equal(42, (float)c.GetField("c"));
            Variable ca = c.GetBaseClass("VirtualMultiClassInheritanceA");

            Assert.Equal(42, (sbyte)ca.GetField("a"));
            Assert.Equal(a.GetPointerAddress(), ba.GetPointerAddress());
            Assert.Equal(ca.GetPointerAddress(), ba.GetPointerAddress());
            Assert.Equal(e.GetPointerAddress(), b.DowncastInterface().GetPointerAddress());
            Assert.Equal(ba.GetPointerAddress(), ba.DowncastInterface().GetPointerAddress());
            Assert.Equal(e.GetPointerAddress(), c.DowncastInterface().GetPointerAddress());
            Assert.Equal(ca.GetPointerAddress(), ca.DowncastInterface().GetPointerAddress());

            if (ExecuteCodeGen)
            {
                InterpretInteractive($@"
Variable global = Process.Current.GetGlobal(""{DefaultModuleName}!virtualMultiClassInheritanceTest2"");
var e = new VirtualMultiClassInheritanceE(global);
var a = e.BaseClass_VirtualMultiClassInheritanceA;
var b = e.BaseClass_VirtualMultiClassInheritanceB;
var ba = b.BaseClass;
var c = e.BaseClass_VirtualMultiClassInheritanceC;
var ca = c.BaseClass;
AreEqual(42, e.e);
AreEqual(42, a.a);
AreEqual(42, b.b);
AreEqual(42, ba.a);
AreEqual(42, c.c);
AreEqual(42, ca.a);
IsTrue(a.GetDowncast() is VirtualMultiClassInheritanceE);
IsTrue(b.GetDowncast() is VirtualMultiClassInheritanceE);
IsTrue(ba.GetDowncast() is VirtualMultiClassInheritanceE);
IsTrue(c.GetDowncast() is VirtualMultiClassInheritanceE);
IsTrue(ca.GetDowncast() is VirtualMultiClassInheritanceE);
AreEqual(42, b.As<VirtualMultiClassInheritanceC>().c);
AreEqual(42, a.As<VirtualMultiClassInheritanceB>().b);
AreEqual(42, ba.As<VirtualMultiClassInheritanceC>().c);
AreEqual(42, ca.As<VirtualMultiClassInheritanceB>().b);
                    ");
            }
        }
Пример #4
0
        public void ReadingFloatPointTypes()
        {
            Variable doubleTest = DefaultModule.GetVariable("doubleTest");

            Assert.Equal(3.5, (double)doubleTest.GetField("d"));
            Assert.Equal(2.5, (float)doubleTest.GetField("f"));
            Assert.Equal(5, (int)doubleTest.GetField("i"));

            Variable doubleTest2 = Process.Current.GetGlobal($"{DefaultModuleName}!doubleTest");

            Assert.Equal(doubleTest.GetPointerAddress(), doubleTest2.GetPointerAddress());
            Assert.Equal(doubleTest.GetCodeType(), doubleTest2.GetCodeType());
        }
Пример #5
0
        public void UserTypeAutoCast()
        {
            Execute_AutoCast(() =>
            {
                Variable doubleTestVariable = DefaultModule.GetVariable("doubleTest");

                Assert.IsType <DoubleTest>(doubleTestVariable);

                DoubleTest doubleTest = (DoubleTest)doubleTestVariable;

                Assert.Equal(3.5, doubleTest.d);
                Assert.Equal(2.5, doubleTest.f);
                Assert.Equal(5, doubleTest.i);
            });
        }
Пример #6
0
        public void TestReadingBuiltinTypes()
        {
            Variable var = DefaultModule.GetVariable("builtinTypesTest");

            TestReading <bool>(var.GetField("b"), false);
            TestReading <sbyte>(var.GetField("i8"), 42);
            TestReading <short>(var.GetField("i16"), 42);
            TestReading <int>(var.GetField("i32"), 42);
            TestReading <long>(var.GetField("i64"), 42);
            TestReading <byte>(var.GetField("u8"), 42);
            TestReading <ushort>(var.GetField("u16"), 42);
            TestReading <uint>(var.GetField("u32"), 42);
            TestReading <ulong>(var.GetField("u64"), 42);
            TestReading <float>(var.GetField("f32"), 42);
            TestReading <double>(var.GetField("f64"), 42);
        }
Пример #7
0
        public void CheckCodeFunction()
        {
            StackFrame   defaultTestCaseFrame    = GetFrame($"{DefaultModuleName}!DefaultTestCase");
            CodeFunction defaultTestCaseFunction = new CodeFunction(defaultTestCaseFrame.InstructionOffset);

            Assert.NotEqual(0U, defaultTestCaseFunction.Address);
            Assert.NotEqual(0U, defaultTestCaseFunction.FunctionDisplacement);
            Assert.Equal($"{DefaultModuleName}!DefaultTestCase", defaultTestCaseFunction.FunctionName);
            Assert.Equal($"DefaultTestCase", defaultTestCaseFunction.FunctionNameWithoutModule);
            Assert.Equal(Process.Current, defaultTestCaseFunction.Process);
            Assert.Contains(MainSourceFileName, defaultTestCaseFunction.SourceFileName.ToLower());
            Assert.NotEqual(0U, defaultTestCaseFunction.SourceFileLine);
            Console.WriteLine("SourceFileDisplacement: {0}", defaultTestCaseFunction.SourceFileDisplacement);

            Variable codeFunctionVariable = DefaultModule.GetVariable($"{DefaultModuleName}!defaultTestCaseAddress");

            Assert.True(codeFunctionVariable.GetCodeType().IsPointer);

            CodeFunction codeFunction = new CodePointer <CodeFunction>(new NakedPointer(codeFunctionVariable)).Element;

            Assert.Equal($"{DefaultModuleName}!DefaultTestCase", codeFunction.FunctionName);
        }
Пример #8
0
        public void GettingClassStaticMember()
        {
            Variable staticVariable = DefaultModule.GetVariable("MyTestClass::staticVariable");

            Assert.Equal(1212121212, (int)staticVariable);
        }