public void CreateMarshalToManagedExpression_DirectMethod() { Action <IntPtr, IntPtr> a = DirectInvocation; var e = new JavaCallableAttribute() { Signature = "()V", }; CheckCreateMarshalToManagedExpression(e, a.Method.DeclaringType, a.Method, typeof(Action <IntPtr, IntPtr>), @"void (IntPtr jnienv, IntPtr context) { JniTransition __envp; JniRuntime __jvm; __envp = new JniTransition(jnienv); try { __jvm = JniEnvironment.Runtime; __jvm.ValueManager.WaitForGCBridgeProcessing(); MarshalMemberBuilderTest.DirectInvocation(jnienv, context); } catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e)) { __envp.SetPendingException(__e); } finally { __envp.Dispose(); } }"); }
public void CreateMarshalFromJniMethodExpression_StaticActionInt32String() { var t = typeof(ExportTest); var m = ((Action <int, string>)ExportTest.StaticActionInt32String); var e = new JavaCallableAttribute() { Signature = "(ILjava/lang/String;)V", }; CheckCreateMarshalToManagedExpression(e, t, m.Method, typeof(Action <IntPtr, IntPtr, int, IntPtr>), @"void (IntPtr __jnienv, IntPtr __class, int i, IntPtr v) { JniTransition __envp; JniRuntime __jvm; string v_val; __envp = new JniTransition(__jnienv); try { __jvm = JniEnvironment.Runtime; __jvm.ValueManager.WaitForGCBridgeProcessing(); v_val = Strings.ToString(v); ExportTest.StaticActionInt32String(i, v_val); } catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e)) { __envp.SetPendingException(__e); } finally { __envp.Dispose(); } }"); }
static void CheckCreateMarshalToManagedExpression(JavaCallableAttribute export, Type type, MethodInfo method, Type expectedDelegateType, string expectedBody) { export = export ?? new JavaCallableAttribute(); var b = CreateBuilder(); var l = b.CreateMarshalToManagedExpression(method, export, type); CheckExpression(l, method.Name, expectedDelegateType, expectedBody); }
public void CreateMarshalFromJniMethodExpression_FuncIJavaObject() { var t = typeof(ExportTest); var m = t.GetMethod("FuncIJavaObject"); var e = new JavaCallableAttribute() { Signature = "()Ljava/lang/Object;", }; CheckCreateMarshalToManagedExpression(e, t, m, typeof(Func <IntPtr, IntPtr, IntPtr>), @"IntPtr (IntPtr __jnienv, IntPtr __this) { JniTransition __envp; JniRuntime __jvm; JniValueManager __vm; JavaObject __mret; ExportTest __this_val; JniObjectReference __mret_ref; IntPtr __mret_handle; IntPtr __mret_rtn; __envp = new JniTransition(__jnienv); try { __jvm = JniEnvironment.Runtime; __vm = __jvm.ValueManager; __vm.WaitForGCBridgeProcessing(); __this_val = __vm.GetValue<ExportTest>(__this); __mret = __this_val.FuncIJavaObject(); if (null == __mret) { return __mret_ref = new JniObjectReference(); } else { return __mret_ref = __mret.PeerReference; } __mret_handle = __mret_ref.Handle; __mret_rtn = References.NewReturnToJniRef(__mret_ref); return __mret_rtn; } catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e)) { __envp.SetPendingException(__e); return default(IntPtr); } finally { JniObjectReference.Dispose(__mret_ref); __envp.Dispose(); } }"); }
public void GetJniMethodSignature() { var builder = CreateBuilder(); Action a = () => {}; var export = new JavaCallableAttribute() { Signature = "(I)V", }; // Note: no validation between actual MethodInfo & existing signature // Validation would be done by CreateMarshalFromJniMethodRegistration(). Assert.AreEqual("(I)V", builder.GetJniMethodSignature(export, a.Method)); Assert.AreEqual("(I)V", export.Signature); export = new JavaCallableAttribute() { Signature = null, }; Assert.AreEqual("()V", builder.GetJniMethodSignature(export, a.Method)); // Note: export.Signature updated Assert.AreEqual("()V", export.Signature); Action <string> s = v => {}; Assert.AreEqual("(Ljava/lang/String;)V", builder.GetJniMethodSignature(new JavaCallableAttribute(), s.Method)); Action <IntPtr, IntPtr, string> ds = (e, c, v) => {}; Assert.AreEqual("(Ljava/lang/String;)V", builder.GetJniMethodSignature(new JavaCallableAttribute(), ds.Method)); Func <string> fs = () => null; Assert.AreEqual("()Ljava/lang/String;", builder.GetJniMethodSignature(new JavaCallableAttribute(), fs.Method)); Func <IntPtr, IntPtr, string> dfs = (e, c) => null; Assert.AreEqual("()Ljava/lang/String;", builder.GetJniMethodSignature(new JavaCallableAttribute(), dfs.Method)); // Note: AppDomain currently has no builtin marshaling defaults // TODO: but should it? We could default wrap to JavaProxyObject...? Action <AppDomain> aad = v => {}; Assert.Throws <NotSupportedException> (() => builder.GetJniMethodSignature(new JavaCallableAttribute(), aad.Method)); Func <AppDomain> fad = () => null; Assert.Throws <NotSupportedException> (() => builder.GetJniMethodSignature(new JavaCallableAttribute(), fad.Method)); }
public void CreateMarshalFromJniMethodExpression_StaticFuncMyLegacyColorMyColor_MyColor() { var t = typeof(ExportTest); var m = ((Func <MyLegacyColor, MyColor, MyColor>)ExportTest.StaticFuncMyLegacyColorMyColor_MyColor); var e = new JavaCallableAttribute() { Signature = "(II)I", }; CheckCreateMarshalToManagedExpression(e, t, m.Method, typeof(Func <IntPtr, IntPtr, int, int, int>), @"int (IntPtr __jnienv, IntPtr __class, int color1, int color2) { JniTransition __envp; JniRuntime __jvm; MyColor __mret; MyLegacyColor color1_val; MyColor color2_val; int __mret_p; __envp = new JniTransition(__jnienv); try { __jvm = JniEnvironment.Runtime; __jvm.ValueManager.WaitForGCBridgeProcessing(); color1_val = new MyLegacyColor(color1); color2_val = new MyColor(color2); __mret = ExportTest.StaticFuncMyLegacyColorMyColor_MyColor(color1_val, color2_val); __mret_p = __mret.Value; return __mret_p; } catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e)) { __envp.SetPendingException(__e); return default(int); } finally { __envp.Dispose(); } }"); }
public void CreateMarshalFromJniMethodExpression_FuncInt64() { var t = typeof(ExportTest); var m = t.GetMethod("FuncInt64"); var e = new JavaCallableAttribute() { Signature = "()J", }; CheckCreateMarshalToManagedExpression(e, t, m, typeof(Func <IntPtr, IntPtr, long>), @"long (IntPtr __jnienv, IntPtr __this) { JniTransition __envp; JniRuntime __jvm; JniValueManager __vm; long __mret; ExportTest __this_val; __envp = new JniTransition(__jnienv); try { __jvm = JniEnvironment.Runtime; __vm = __jvm.ValueManager; __vm.WaitForGCBridgeProcessing(); __this_val = __vm.GetValue<ExportTest>(__this); __mret = __this_val.FuncInt64(); return __mret; } catch (Exception __e) if (__jvm.ExceptionShouldTransitionToJni(__e)) { __envp.SetPendingException(__e); return default(long); } finally { __envp.Dispose(); } }"); }