Ejemplo n.º 1
0
        public unsafe void Dispose_Exceptions()
        {
            var t = new JniType("java/lang/Object");

            t.Dispose();
            Assert.Throws <ObjectDisposedException> (() => t.AllocObject());
            Assert.Throws <ObjectDisposedException> (() => t.NewObject(null, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetConstructor(null));
            Assert.Throws <ObjectDisposedException> (() => t.GetInstanceField(null, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetInstanceMethod(null, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetStaticField(null, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetStaticMethod(null, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetSuperclass());
            Assert.Throws <ObjectDisposedException> (() => t.IsAssignableFrom(null));
            Assert.Throws <ObjectDisposedException> (() => t.IsInstanceOfType(new JniObjectReference()));
            Assert.Throws <ObjectDisposedException> (() => t.RegisterWithRuntime());
            Assert.Throws <ObjectDisposedException> (() => t.RegisterNativeMethods(null));
            Assert.Throws <ObjectDisposedException> (() => t.UnregisterNativeMethods());

            JniFieldInfo jif = null;

            Assert.Throws <ObjectDisposedException> (() => t.GetCachedInstanceField(ref jif, null, null));
            JniMethodInfo jim = null;

            Assert.Throws <ObjectDisposedException> (() => t.GetCachedConstructor(ref jim, null));
            Assert.Throws <ObjectDisposedException> (() => t.GetCachedInstanceMethod(ref jim, null, null));
            JniFieldInfo jsf = null;

            Assert.Throws <ObjectDisposedException> (() => t.GetCachedStaticField(ref jsf, null, null));
            JniMethodInfo jsm = null;

            Assert.Throws <ObjectDisposedException> (() => t.GetCachedStaticMethod(ref jsm, null, null));
        }
Ejemplo n.º 2
0
        static void __RegisterNativeMembers(JniType type, string members)
        {
            var methods = JniEnvironment.Runtime.MarshalMemberBuilder
                          .GetExportedMemberRegistrations(typeof(ExportTest));

            type.RegisterNativeMethods(methods.ToArray());
        }
Ejemplo n.º 3
0
 public void RegisterNativeMethods()
 {
     using (var TestType_class = new JniType("com/xamarin/interop/CallNonvirtualBase")) {
         Assert.AreEqual(JniObjectReferenceType.Global, TestType_class.PeerReference.Type);
         TestType_class.RegisterNativeMethods();
         Assert.AreEqual(JniObjectReferenceType.Global, TestType_class.PeerReference.Type);
     }
 }
Ejemplo n.º 4
0
        static bool FastRegisterNativeMembers(JniType nativeClass, Type type, string?methods)
        {
            if (!MagicRegistrationMap.Filled)
            {
                return(false);
            }

            bool lockTaken = false;
            bool rv        = false;

            try {
                Monitor.TryEnter(sharedRegistrations, ref lockTaken);
                List <JniNativeMethodRegistration> registrations;
                if (lockTaken)
                {
                    sharedRegistrations.Clear();
                    registrations = sharedRegistrations;
                }
                else
                {
                    registrations = new List <JniNativeMethodRegistration> ();
                }
                JniNativeMethodRegistrationArguments arguments = new JniNativeMethodRegistrationArguments(registrations, methods);
                rv = MagicRegistrationMap.CallRegisterMethod(arguments, type.FullName !);

                if (registrations.Count > 0)
                {
                    nativeClass.RegisterNativeMethods(registrations.ToArray());
                }
            } finally {
                if (lockTaken)
                {
                    Monitor.Exit(sharedRegistrations);
                }
            }

            return(rv);
        }