Sha256: 807971cc263fd8f518480ee6e4e1dcee804c5b3880eaac0a6870c82e34886a9e

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require File.expand_path('../gir_ffi_test_helper.rb', File.dirname(__FILE__))

describe GirFFI::Builder::Type::Unintrospectable do
  describe "building the GLocalFile type" do
    before do
      # Ensure existence of GLocalFile type
      GirFFI.setup :Gio
      unless Gio::Lib.respond_to? :g_file_new_for_path
        Gio._setup_method "file_new_for_path"
      end
      ptr = GirFFI::InPointer.from :utf8, '/'
      Gio::Lib.g_file_new_for_path(ptr)

      @gtype = GObject.type_from_name 'GLocalFile'
      @bldr = GirFFI::Builder::Type::Unintrospectable.new(@gtype)
      @klass = @bldr.build_class
    end

    it "builds a class" do
      assert_instance_of Class, @klass
    end

    it "builds a class derived from GObject::Object" do
      assert_includes @klass.ancestors, GObject::Object
    end

    it "builds a class derived from Gio::File" do
      assert_includes @klass.ancestors, Gio::File
    end

    it "returns the same class when built again" do
      other_bldr = GirFFI::Builder::Type::Unintrospectable.new(@gtype)
      other_klass = other_bldr.build_class

      assert_equal @klass, other_klass
    end

    describe "its #find_signal method" do
      it "raises correct error for a signal that doesn't exist" do
        msg = nil
        begin
          @bldr.find_signal "foo"
        rescue RuntimeError => e
          msg = e.message
        end
        assert_match(/^Signal/, msg)
      end
    end
  end

  # FIXME: Testing a private method, and with rather a lot of
  # mocking, too.
  describe "#interfaces" do
    it "skips interfaces that have no introspection data" do
      bldr = GirFFI::Builder::Type::Unintrospectable.new(:some_type)

      mock(bldr).interface_gtypes { [:foo, :bar ] }
      mock(gir = Object.new).find_by_gtype(:foo) { :foo_info }
      mock(gir).find_by_gtype(:bar) { nil }
      bldr.instance_eval { @gir = gir }
      mock(GirFFI::Builder).build_class(:foo_info) { :foo_module }

      result = bldr.send :interfaces
      result.must_equal [:foo_module]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.4.0 test/unit/unintrospectable_type_builder_test.rb
gir_ffi-0.3.2 test/unit/unintrospectable_type_builder_test.rb
gir_ffi-0.3.1 test/unit/unintrospectable_type_builder_test.rb
gir_ffi-0.3.0 test/unit/unintrospectable_type_builder_test.rb