示例#1
0
 public void RegisterWithVM_PermitsAliases()
 {
     using (var original = new JavaObject()) {
         var p     = original.PeerReference;
         var alias = new JavaObject(ref p, JniObjectReferenceOptions.Copy);
         alias.Dispose();
     }
 }
        public void GetJniTypeName_Exceptions()
        {
            IJavaPeerable o = null;

            Assert.Throws <ArgumentNullException> (() => o.GetJniTypeName());
            o = new JavaObject();
            o.Dispose();
            Assert.Throws <ObjectDisposedException> (() => o.GetJniTypeName());
        }
示例#3
0
        public void ObjectDisposed()
        {
            var o = new JavaObject();

            o.Dispose();

            // These should not throw
            var h = o.PeerReference;
            var p = o.JniPeerMembers;

            // These should throw
            Assert.Throws <ObjectDisposedException> (() => o.GetHashCode());
            Assert.Throws <ObjectDisposedException> (() => o.UnregisterFromRuntime());
            Assert.Throws <ObjectDisposedException> (() => o.ToString());
            Assert.Throws <ObjectDisposedException> (() => o.Equals(o));
        }
示例#4
0
        public void GetValue_ReturnsAlias()
        {
            var local = new JavaObject();

            local.UnregisterFromRuntime();
            Assert.IsNull(JniRuntime.CurrentRuntime.ValueManager.PeekValue(local.PeerReference));
            // GetObject must always return a value (unless handle is null, etc.).
            // However, since we called local.UnregisterFromRuntime(),
            // JniRuntime.PeekObject() is null (asserted above), but GetObject() must
            // **still** return _something_.
            // In this case, it returns an _alias_.
            // TODO: "most derived type" alias generation. (Not relevant here, but...)
            var p     = local.PeerReference;
            var alias = JniRuntime.CurrentRuntime.ValueManager.GetValue <IJavaPeerable> (ref p, JniObjectReferenceOptions.Copy);

            Assert.AreNotSame(local, alias);
            alias.Dispose();
            local.Dispose();
        }