Skip to content

Commit

Permalink
Merge 667e23c into 33f108a
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Dec 26, 2019
2 parents 33f108a + 667e23c commit 630f9d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 157 deletions.
154 changes: 0 additions & 154 deletions test/gir_ffi/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,158 +165,4 @@
GirFFI::Builder.attach_ffi_function(lib, info)
end
end

#
# NOTE: Legacy tests below.
#

describe "looking at Regress.test_callback_destroy_notify" do
before do
save_module :GObject
save_module :Regress
GirFFI::Builder.build_module "GObject"
GirFFI::Builder.build_module "Regress"
@go = get_introspection_data "Regress", "test_callback_destroy_notify"
end

it "defines ffi callback types :Callback and :ClosureNotify" do
Regress.setup_method! "test_callback_destroy_notify"
tcud = Regress::Lib.find_type :TestCallbackUserData
dn = GLib::Lib.find_type :DestroyNotify

assert_equal FFI.find_type(:int32), tcud.result_type
assert_equal FFI.find_type(:void), dn.result_type
assert_equal [FFI.find_type(:pointer)], tcud.param_types
assert_equal [FFI.find_type(:pointer)], dn.param_types
end

after do
restore_module :Regress
restore_module :GObject
end
end

describe "building Regress::TestBoxed" do
before do
GirFFI::Builder.build_class get_introspection_data("Regress", "TestBoxed")
end

it "sets up #wrap" do
assert Regress::TestBoxed.respond_to? "wrap"
end

it "sets up #allocate" do
assert Regress::TestBoxed.respond_to? "allocate"
end
end

describe "built Regress module" do
before do
save_module :Regress
GirFFI::Builder.build_module "Regress"
end

it "autocreates singleton methods" do
refute_defines_singleton_method Regress, :test_uint
Regress.test_uint 31
assert_defines_singleton_method Regress, :test_uint
end

it "autocreates the TestObj class on first access" do
assert !Regress.const_defined?(:TestObj)
_(Regress::TestObj).must_be_instance_of Class
assert Regress.const_defined? :TestObj
end

it "knows its own module builder" do
_(Regress.gir_ffi_builder).must_be_instance_of GirFFI::Builders::ModuleBuilder
end

after do
restore_module :Regress
end
end

describe "having built Regress::TestObj" do
before do
GirFFI::Builder.build_class get_introspection_data("Regress", "TestObj")
end

it "C functions for called instance methods get attached to Regress::Lib" do
o = Regress::TestObj.new_from_file("foo")
o.instance_method
_(Regress::Lib).must_respond_to :regress_test_obj_instance_method
end

it "the built class knows its own GIR info" do
_(Regress::TestObj.gir_info.name).must_equal "TestObj"
end

it "the built class knows its own class builder" do
_(Regress::TestObj.gir_ffi_builder).must_be_instance_of GirFFI::Builders::ObjectBuilder
end
end

describe "built Regress::TestSubObj" do
it "inherits #set_bare from its superclass" do
o1 = Regress::TestSubObj.new
o1.set_bare(nil)
pass
end

it "overrides #instance_method" do
obj = Regress::TestObj.new_from_file("foo")
subobj = Regress::TestSubObj.new

_(obj.instance_method).must_equal(-1)
_(subobj.instance_method).must_equal 0
end
end

describe "building Regress::TestSubObj" do
before do
save_module :Regress
GirFFI::Builder.build_class get_introspection_data("Regress", "TestSubObj")
end

it "sets up the Regress namespace" do
assert Regress.const_defined? :Lib
assert Regress.respond_to? :gir_ffi_builder
assert Regress.const_defined? :GIR_FFI_BUILDER
end

it "creates the Regress::Lib module ready to attach functions from the shared library" do
expected = [gir.shared_library("Regress")]
assert_equal expected, Regress::Lib.ffi_libraries.map(&:name)
end

it "builds parent classes also" do
assert Regress.const_defined? :TestObj
assert Object.const_defined? :GObject
assert GObject.const_defined? :Object
end

it "sets up the inheritance chain" do
# Introduced in version 1.59.1
expected = if Regress::TestSubObj.find_property :boolean
[Regress::TestSubObj,
Regress::TestInterface,
Regress::TestObj,
GObject::Object]
else
[Regress::TestSubObj,
Regress::TestObj,
GObject::Object]
end
_(Regress::TestSubObj.registered_ancestors).must_equal expected
end

it "creates a Regress::TestSubObj#to_ptr method" do
assert Regress::TestSubObj.public_method_defined? :to_ptr
end

after do
restore_module :Regress
end
end
end
7 changes: 4 additions & 3 deletions test/gir_ffi/core_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
end

it "sets up dependencies" do
save_module :GObject
save_module :Utility
save_module :Regress
refute Object.const_defined?(:Utility)
GirFFI.setup :Regress
assert Object.const_defined?(:GObject)
assert Object.const_defined?(:Utility)
restore_module :Regress
restore_module :GObject
restore_module :Utility
end

describe ".setup" do
Expand Down

0 comments on commit 630f9d0

Please sign in to comment.