Sha256: bdcbecab24f5576f71ff7f0bdba9d7a9c1af8707f84805a88fbac4422ed38696

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require 'gir_ffi_test_helper'

describe GObject::RubyClosure do
  should "have a constructor with a mandatory block argument" do
    assert_raises ArgumentError do
      GObject::RubyClosure.new
    end
  end

  should "be a kind of Closure" do
    c = GObject::RubyClosure.new {}
    assert_kind_of GObject::Closure, c
  end

  should "be able to retrieve its block from its struct" do
    a = 0
    c = GObject::RubyClosure.new { a = 2 }
    c2 = GObject::RubyClosure.wrap(c.to_ptr)
    c2.block.call
    assert_equal 2, a
  end

  describe "its #marshaller singleton method" do
    should "invoke its closure argument's block" do
      a = 0
      c = GObject::RubyClosure.new { a = 2 }
      GObject::RubyClosure.marshaller(c, nil, 0, nil, nil, nil)
      assert_equal 2, a
    end

    should "work when its closure argument is a GObject::Closure" do
      a = 0
      c = GObject::RubyClosure.new { a = 2 }
      c2 = GObject::Closure.wrap(c.to_ptr)
      GObject::RubyClosure.marshaller(c2, nil, 0, nil, nil, nil)
      assert_equal 2, a
    end

    should "store the closure's return value in the proper gvalue" do
      c = GObject::RubyClosure.new { 2 }
      gv = GObject::Value.new
      GObject::RubyClosure.marshaller(c, gv, 0, nil, nil, nil)
      assert_equal 2, gv.ruby_value
    end
  end

  should "have GObject::Closure#invoke call its block" do
    a = 0
    c = GObject::RubyClosure.new { a = 2 }
    c2 = GObject::Closure.wrap(c.to_ptr)
    c2.invoke nil, nil, nil
    assert_equal 2, a
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gir_ffi-0.6.3 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.6.2 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.6.1 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.6.0 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.5.2 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.5.1 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.5.0 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.4.3 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.4.2 test/ffi-glib/ruby_closure_test.rb
gir_ffi-0.4.1 test/ffi-glib/ruby_closure_test.rb