Example #1
0
        public void ValidateCrashIsSentForGLibExceptions()
        {
            var old           = GLibLogging.Enabled;
            var crashReporter = new CapturingCrashReporter();

            try {
                GLibLogging.Enabled = true;

                LoggingService.RegisterCrashReporter(crashReporter);

                GLib.Log.Write("Gtk", GLib.LogLevelFlags.Warning, "{0}", "should not be captured");
                Assert.IsNull(crashReporter.LastException);

                GLib.Log.Write("Gtk", GLib.LogLevelFlags.Critical, "{0}", "critical should be captured");
                Assert.That(crashReporter.LastException.Message, Contains.Substring("critical should be captured"));
                Assert.That(crashReporter.LastException.Source, Is.Not.Null);

                var stacktrace = crashReporter.LastException.StackTrace;
                AssertGLibStackTrace(stacktrace);

                // Error will cause the application to exit, so we can't test for that, but it follows the same code as Critical.
            } finally {
                LoggingService.UnregisterCrashReporter(crashReporter);
                GLibLogging.Enabled = old;
            }
        }
        public void TestNSExceptionLogging()
        {
            var crashReporter = new CapturingCrashReporter();

            try {
                LoggingService.RegisterCrashReporter(crashReporter);

                var x        = new NSException("Test", "should be captured", null);
                var selector = ObjCRuntime.Selector.GetHandle("raise");

                Assert.Throws <ObjCException> (() => void_objc_msgSend(x.Handle, selector));

                Assert.That(crashReporter.LastException.Message, Contains.Substring("should be captured"));
            } finally {
                LoggingService.UnregisterCrashReporter(crashReporter);
            }
        }