Exemplo n.º 1
0
        public void DeallocationThrowOnSet()
        {
            AutoRegisteredClass proxy = null;

            using (AutoreleaseScope.New())
                proxy = Runtime.CreateInstance <AutoRegisteredClass>("init");

            Assert.AreEqual(RuntimeObject.Null, proxy.Handle);

            proxy._int = 10;
        }
Exemplo n.º 2
0
        public void InheritanceTest()
        {
            HierarchyBase    @base;
            HierarchyDerived derived;

            using (AutoreleaseScope.New())
            {
                @base   = Runtime.CreateInstance <HierarchyBase>("init");
                derived = Runtime.CreateInstance <HierarchyDerived>("init");

                HierarchyBase derivedCastedToBase = derived;

                var test = new
                {
                    _int    = 7,
                    _uint   = 8,
                    _long   = 9,
                    _ulong  = 10,
                    _float  = 11,
                    _double = 12
                };

                foreach (var item in test.GetType().GetFields())
                {
                    derived.GetType().GetProperty(item.Name).SetValue(derived, item.GetValue(test), null);
                }

                foreach (var item in test.GetType().GetFields())
                {
                    Assert.AreEqual(item.GetValue(test), derived.GetType().GetProperty(item.Name).GetValue(derived, null));
                }

                Assert.AreEqual(@base.ToString(), derived.ToString());
                Assert.AreEqual(@base.FloatingPointReturn(), derived.FloatingPointReturn());
                Assert.AreEqual(@base.IntReturn(), derived.IntReturn());
                Assert.AreEqual(@base.ShortReturn(), derived.ShortReturn());

                // override by name
                Assert.AreEqual(@base.Supercall(), derived.Handle.SuperInvokeInt32("Supercall"));
                Assert.AreEqual(@base.Supercall(), Runtime.SendMessageToBase(derived.Handle, derived.Handle.Class.BaseClass, "Supercall").ToInt32());

                // C#-like override
                Assert.IsTrue(derivedCastedToBase.VirtualMethod() == derived.Handle.InvokeUInt32("VirtualMethod"));
            }

            Assert.AreEqual(true, @base.IsDeallocCalledForBase);
            Assert.AreEqual(true, derived.IsDeallocCalledForBase, "dealloc implementation of base class not called");
            Assert.AreEqual(true, derived.IsDeallocCalledForChild, "dealloc implementation of derived class not called");

            Assert.AreEqual(RuntimeObject.Null, @base.Handle, "Handle not set to Null in base class");
            Assert.AreEqual(RuntimeObject.Null, derived.Handle, "Handle not set to Null in derived class");
        }
Exemplo n.º 3
0
        private static void Test(string name, Action <int> test)
        {
            using (AutoreleaseScope.New())
                test(20000);

            using (AutoreleaseScope.New())
            {
                _timer.Start();
                test(20000);
                _timer.Stop();

                System.Console.WriteLine("{0}: {1}ms", name, _timer.Elapsed.TotalMilliseconds);
                _timer.Reset();
            }
        }
Exemplo n.º 4
0
 public void SetUp()
 {
     _autoreleasePool = new AutoreleaseScope();
 }