Esempio n. 1
0
        private static void ValidateSetMessageSendPendingExceptionImpl(MessageSendFunction msgSend)
        {
            if (!LibObjC.SupportedOnPlatform(msgSend))
            {
                return;
            }

            IntPtr func = msgSend switch
            {
                MessageSendFunction.MsgSend => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSend,
                MessageSendFunction.MsgSendFpret => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSendFpret,
                MessageSendFunction.MsgSendStret => (IntPtr)(delegate * unmanaged <IntPtr *, IntPtr, IntPtr, void>) & MsgSendStret,
                MessageSendFunction.MsgSendSuper => (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr>) & MsgSendSuper,
                MessageSendFunction.MsgSendSuperStret => (IntPtr)(delegate * unmanaged <IntPtr *, IntPtr, IntPtr, void>) & MsgSendSuperStret,
                _ => throw new Exception($"Unknown {nameof(MessageSendFunction)}"),
            };

            // Override message send function
            //
            // We are using the overriding mechanism to enable validating in the Libraries test suite.
            // Technically any Objective-C code that is entered via msgSend could call the managed SetMessageSendPendingException()
            // and it would be thrown when returning from the P/Invoke. This approach avoids us having to
            // create a pure Objective-C library for testing this behavior.
            ObjectiveCMarshal.SetMessageSendCallback(msgSend, func);

            // Call message send function through P/Invoke
            IntPtr inst = IntPtr.Zero;
            IntPtr sel  = IntPtr.Zero;

            Exception ex = Assert.Throws <PendingException>(() => LibObjC.CallPInvoke(msgSend, inst, sel));

            Assert.Equal(msgSend.ToString(), ex.Message);
        }
Esempio n. 2
0
        public void ValidateSetMessageSendPendingException(MessageSendFunction func)
        {
            // Pass functions to override as a string for remote execution
            RemoteExecutor.Invoke((string funcToOverrideAsStr) =>
            {
                MessageSendFunction msgSend = Enum.Parse <MessageSendFunction>(funcToOverrideAsStr);
                Assert.True(Enum.IsDefined <MessageSendFunction>(msgSend));

                ValidateSetMessageSendPendingExceptionImpl(msgSend);
            }, func.ToString()).Dispose();
        }
Esempio n. 3
0
        public void ValidateSetMessageSendPendingException(MessageSendFunction func)
        {
            // Pass functions to override as a string for remote execution
            RemoteExecutor.Invoke((string funcToOverrideAsStr) =>
            {
                MessageSendFunction msgSend = Enum.Parse <MessageSendFunction>(funcToOverrideAsStr);
                Assert.True(Enum.IsDefined <MessageSendFunction>(msgSend));

                ValidateSetMessageSendPendingExceptionImpl(msgSend);

                // TODO: Remove once https://github.com/dotnet/arcade/issues/5865 is resolved
                // RemoteExecutor currently only checks the expected exit code if the invoked function returns an int.
                // Check the exit code to ensure the test will fail if there was a crash that could not be caught by the executor.
                return(RemoteExecutor.SuccessExitCode);
            }, func.ToString()).Dispose();
        }