Sha256: 33289710abd48e634061b20b6f4082808cfc06d42ef136cb667495d20eb4b898

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 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 do
          main_loop.run
        end.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 do
          main_loop.run
        end.must_raise CallbackTestException
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gir_ffi-0.14.1 test/integration/callback_exceptions_test.rb
gir_ffi-0.14.0 test/integration/callback_exceptions_test.rb
gir_ffi-0.13.1 test/integration/callback_exceptions_test.rb
gir_ffi-0.13.0 test/integration/callback_exceptions_test.rb
gir_ffi-0.12.1 test/integration/callback_exceptions_test.rb
gir_ffi-0.12.0 test/integration/callback_exceptions_test.rb
gir_ffi-0.11.4 test/integration/callback_exceptions_test.rb
gir_ffi-0.11.3 test/integration/callback_exceptions_test.rb
gir_ffi-0.11.2 test/integration/callback_exceptions_test.rb