Sha256: 1626397bf614aa53e26b6cd46a77632903d6935255433bc99741a65c7982db66

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require "gir_ffi_test_helper"

GirFFI.setup :Regress

class CallbackTestException < RuntimeError; end

describe "An exception in a callback" do
  describe "for signals" do
    let(:object) { Regress::TestSubObj.new }

    before do
      object.signal_connect "test" do
        raise CallbackTestException, "Boom"
      end
    end

    describe "when the signal is emitted synchronously" do
      it "raises an error" do
        _(proc { GObject.signal_emit object, "test" }).must_raise CallbackTestException
      end
    end

    describe "when the signal is emitted during an event loop" do
      it "causes loop run to be terminated with an exception" do
        main_loop = GLib::MainLoop.new nil, false

        GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
          GObject.signal_emit object, "test"
          false
        end
        # Guard against runaway loop
        GLib.timeout_add GLib::PRIORITY_DEFAULT, 500 do
          main_loop.quit
        end
        _(proc { main_loop.run }).must_raise CallbackTestException
      end
    end
  end

  describe "for other callbacks" do
    describe "when the callback occurs during an event loop" do
      it "causes loop run to be terminated with an exception" do
        main_loop = GLib::MainLoop.new nil, false

        GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
          raise CallbackTestException, "Boom"
        end
        # Guard against runaway loop
        GLib.timeout_add GLib::PRIORITY_DEFAULT, 500 do
          main_loop.quit
        end

        _(proc { main_loop.run }).must_raise CallbackTestException
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.15.3 test/integration/callback_exceptions_test.rb
gir_ffi-0.15.2 test/integration/callback_exceptions_test.rb
gir_ffi-0.15.1 test/integration/callback_exceptions_test.rb
gir_ffi-0.15.0 test/integration/callback_exceptions_test.rb