gir_ffi 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +13 -0
- data/Gemfile +9 -4
- data/README.md +3 -2
- data/Rakefile +2 -1
- data/lib/ffi-glib/byte_array.rb +1 -1
- data/lib/ffi-glib/main_loop.rb +2 -1
- data/lib/ffi-glib/strv.rb +5 -2
- data/lib/ffi-glib/variant.rb +3 -5
- data/lib/ffi-glib.rb +4 -0
- data/lib/ffi-gobject/closure.rb +8 -10
- data/lib/ffi-gobject/object.rb +9 -6
- data/lib/ffi-gobject/param_spec.rb +4 -0
- data/lib/ffi-gobject/value.rb +13 -16
- data/lib/ffi-gobject_introspection/gobject_type_init.rb +18 -0
- data/lib/ffi-gobject_introspection/i_callable_info.rb +1 -5
- data/lib/ffi-gobject_introspection/i_constant_info.rb +3 -3
- data/lib/ffi-gobject_introspection/i_repository.rb +3 -47
- data/lib/ffi-gobject_introspection/i_vfunc_info.rb +3 -11
- data/lib/ffi-gobject_introspection/lib.rb +8 -31
- data/lib/{gir_ffi-base/glib → ffi-gobject_introspection}/strv.rb +9 -13
- data/lib/ffi-gobject_introspection.rb +47 -2
- data/lib/gir_ffi/allocation_helper.rb +1 -19
- data/lib/gir_ffi/arg_helper.rb +36 -26
- data/lib/{gir_ffi-base/glib → gir_ffi}/boolean.rb +7 -5
- data/lib/gir_ffi/boxed_base.rb +5 -23
- data/lib/gir_ffi/builder.rb +3 -3
- data/lib/gir_ffi/builders/argument_builder.rb +7 -8
- data/lib/gir_ffi/builders/base_argument_builder.rb +0 -1
- data/lib/gir_ffi/builders/callback_argument_builder.rb +2 -2
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +21 -13
- data/lib/gir_ffi/builders/field_builder.rb +4 -10
- data/lib/gir_ffi/builders/module_builder.rb +6 -4
- data/lib/gir_ffi/builders/object_builder.rb +16 -16
- data/lib/gir_ffi/builders/struct_builder.rb +4 -6
- data/lib/gir_ffi/builders/struct_like.rb +1 -1
- data/lib/gir_ffi/builders/user_defined_builder.rb +83 -23
- data/lib/gir_ffi/builders/vfunc_argument_builder.rb +12 -17
- data/lib/gir_ffi/class_base.rb +0 -4
- data/lib/gir_ffi/core.rb +16 -13
- data/lib/gir_ffi/enum_base.rb +2 -41
- data/lib/gir_ffi/enum_like_base.rb +48 -0
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -1
- data/lib/gir_ffi/flags_base.rb +2 -41
- data/lib/gir_ffi/in_out_pointer.rb +1 -1
- data/lib/gir_ffi/in_pointer.rb +4 -4
- data/lib/gir_ffi/info_ext/i_type_info.rb +14 -5
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +8 -0
- data/lib/gir_ffi/module_base.rb +4 -0
- data/lib/gir_ffi/receiver_argument_info.rb +1 -1
- data/lib/gir_ffi/sized_array.rb +6 -6
- data/lib/gir_ffi/struct_base.rb +1 -6
- data/lib/gir_ffi/struct_like_base.rb +54 -45
- data/lib/gir_ffi/type_map.rb +6 -7
- data/lib/gir_ffi/union_base.rb +1 -1
- data/lib/gir_ffi/{user_defined_type_info.rb → user_defined_object_info.rb} +1 -2
- data/lib/gir_ffi/user_defined_property_info.rb +80 -2
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi-base/gobject/lib.rb +0 -1
- data/lib/gir_ffi-base/gobject.rb +3 -5
- data/lib/gir_ffi-base.rb +3 -8
- data/tasks/test.rake +17 -3
- data/test/base_test_helper.rb +39 -23
- data/test/ffi-glib/closure_test.rb +37 -0
- data/test/ffi-glib/main_loop_test.rb +24 -0
- data/test/ffi-glib/ruby_closure_test.rb +0 -5
- data/test/ffi-gobject/object_test.rb +6 -10
- data/test/ffi-gobject/param_spec_test.rb +17 -5
- data/test/ffi-gobject/value_test.rb +15 -6
- data/test/ffi-gobject_introspection/gobject_type_init_test.rb +25 -0
- data/test/ffi-gobject_introspection/i_base_info_test.rb +1 -1
- data/test/ffi-gobject_introspection/i_repository_test.rb +18 -0
- data/test/ffi-gobject_introspection/i_vfunc_info_test.rb +40 -0
- data/test/{gir_ffi-base/glib → ffi-gobject_introspection}/strv_test.rb +8 -8
- data/test/gir_ffi/allocation_helper_test.rb +35 -0
- data/test/gir_ffi/arg_helper_test.rb +102 -7
- data/test/gir_ffi/boolean_test.rb +34 -0
- data/test/gir_ffi/boxed_base_test.rb +46 -6
- data/test/gir_ffi/builder_test.rb +88 -29
- data/test/gir_ffi/builders/argument_builder_test.rb +19 -0
- data/test/gir_ffi/builders/callback_argument_builder_test.rb +17 -0
- data/test/gir_ffi/builders/callback_return_value_builder_test.rb +1 -1
- data/test/gir_ffi/builders/field_builder_test.rb +2 -1
- data/test/gir_ffi/builders/struct_builder_test.rb +42 -25
- data/test/gir_ffi/builders/user_defined_builder_test.rb +365 -17
- data/test/gir_ffi/builders/vfunc_argument_builder_test.rb +100 -0
- data/test/gir_ffi/builders/vfunc_builder_test.rb +5 -3
- data/test/{gir_ffi_test.rb → gir_ffi/core_test.rb} +8 -6
- data/test/gir_ffi/in_out_pointer_test.rb +1 -1
- data/test/gir_ffi/receiver_argument_info_test.rb +32 -0
- data/test/gir_ffi/sized_array_test.rb +34 -0
- data/test/gir_ffi/struct_base_test.rb +4 -32
- data/test/gir_ffi/struct_like_base_test.rb +164 -0
- data/test/gir_ffi/union_base_test.rb +4 -20
- data/test/gir_ffi/{user_defined_type_info_test.rb → user_defined_object_info_test.rb} +10 -10
- data/test/gir_ffi/user_defined_property_info_test.rb +22 -5
- data/test/gir_ffi/version_test.rb +1 -1
- data/test/integration/callback_exceptions_test.rb +2 -0
- data/test/integration/derived_classes_test.rb +2 -0
- data/test/integration/generated_everything_test.rb +22 -0
- data/test/integration/generated_gimarshallingtests_test.rb +23 -21
- data/test/integration/generated_gio_test.rb +2 -0
- data/test/integration/generated_glib_test.rb +2 -0
- data/test/integration/generated_gst_test.rb +2 -0
- data/test/integration/generated_gtop_test.rb +2 -0
- data/test/integration/generated_regress_test.rb +113 -29
- data/test/integration/generated_secret_test.rb +2 -0
- data/test/integration/generated_warnlib_test.rb +2 -0
- data/test/integration/method_lookup_test.rb +2 -0
- data/test/introspection_test_helper.rb +15 -0
- metadata +21 -27
- data/lib/gir_ffi-base/glib.rb +0 -8
- data/test/gir_ffi-base/glib/boolean_test.rb +0 -34
| @@ -4,6 +4,10 @@ require 'gir_ffi_test_helper' | |
| 4 4 | 
             
            GirFFI.setup :GIMarshallingTests
         | 
| 5 5 |  | 
| 6 6 | 
             
            describe GirFFI::StructBase do
         | 
| 7 | 
            +
              it 'inherits from StructLikeBase' do
         | 
| 8 | 
            +
                GirFFI::StructBase.must_include GirFFI::StructLikeBase
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 7 11 | 
             
              describe 'new' do
         | 
| 8 12 | 
             
                it 'creates an instance with an owned struct' do
         | 
| 9 13 | 
             
                  instance = GIMarshallingTests::SimpleStruct.new
         | 
| @@ -15,36 +19,4 @@ describe GirFFI::StructBase do | |
| 15 19 | 
             
                  instance.to_ptr.wont_be :autorelease?
         | 
| 16 20 | 
             
                end
         | 
| 17 21 | 
             
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              describe 'wrap_copy' do
         | 
| 20 | 
            -
                it 'returns a wrapped owned copy' do
         | 
| 21 | 
            -
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 22 | 
            -
                  copy = GIMarshallingTests::SimpleStruct.wrap_copy(original.to_ptr)
         | 
| 23 | 
            -
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 24 | 
            -
                  copy.to_ptr.wont_be :autorelease?
         | 
| 25 | 
            -
                  copy.struct.must_be :owned?
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              describe 'copy_from' do
         | 
| 30 | 
            -
                it 'returns an unowned copy' do
         | 
| 31 | 
            -
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 32 | 
            -
                  copy = GIMarshallingTests::SimpleStruct.copy_from(original)
         | 
| 33 | 
            -
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 34 | 
            -
                  copy.to_ptr.wont_be :autorelease?
         | 
| 35 | 
            -
                  copy.struct.wont_be :owned?
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
              end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
              describe 'wrap_own' do
         | 
| 40 | 
            -
                it 'wraps and owns the supplied value' do
         | 
| 41 | 
            -
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 42 | 
            -
                  original.struct.owned = false
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                  copy = GIMarshallingTests::SimpleStruct.wrap_own(original.to_ptr)
         | 
| 45 | 
            -
                  copy.to_ptr.must_equal original.to_ptr
         | 
| 46 | 
            -
                  copy.to_ptr.wont_be :autorelease?
         | 
| 47 | 
            -
                  copy.struct.must_be :owned?
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
              end
         | 
| 50 22 | 
             
            end
         | 
| @@ -0,0 +1,164 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
            require 'gir_ffi_test_helper'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            GirFFI.setup :GIMarshallingTests
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            describe GirFFI::StructLikeBase do
         | 
| 7 | 
            +
              describe 'wrap_copy' do
         | 
| 8 | 
            +
                it 'returns a wrapped owned copy of structs' do
         | 
| 9 | 
            +
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 10 | 
            +
                  copy = GIMarshallingTests::SimpleStruct.wrap_copy(original.to_ptr)
         | 
| 11 | 
            +
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 12 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 13 | 
            +
                  copy.struct.must_be :owned?
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                it 'returns a wrapped owned copy of unions' do
         | 
| 17 | 
            +
                  original = GIMarshallingTests::Union.new
         | 
| 18 | 
            +
                  copy = GIMarshallingTests::Union.wrap_copy(original.to_ptr)
         | 
| 19 | 
            +
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 20 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 21 | 
            +
                  copy.struct.must_be :owned?
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                it 'returns a wrapped owned copy of boxed types' do
         | 
| 25 | 
            +
                  original = GIMarshallingTests::BoxedStruct.new
         | 
| 26 | 
            +
                  copy = GIMarshallingTests::BoxedStruct.wrap_copy(original.to_ptr)
         | 
| 27 | 
            +
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 28 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 29 | 
            +
                  copy.struct.must_be :owned?
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it 'returns nil when passed nil' do
         | 
| 33 | 
            +
                  GIMarshallingTests::SimpleStruct.wrap_copy(nil).must_be_nil
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              describe 'copy_from' do
         | 
| 38 | 
            +
                it 'returns an unowned copy of unions' do
         | 
| 39 | 
            +
                  original = GIMarshallingTests::Union.new
         | 
| 40 | 
            +
                  original.long_ = 42
         | 
| 41 | 
            +
                  copy = GIMarshallingTests::Union.copy_from(original)
         | 
| 42 | 
            +
                  copy.long_.must_equal 42
         | 
| 43 | 
            +
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 44 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 45 | 
            +
                  copy.struct.wont_be :owned?
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it 'returns an unowned copy of structs' do
         | 
| 49 | 
            +
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 50 | 
            +
                  copy = GIMarshallingTests::SimpleStruct.copy_from(original)
         | 
| 51 | 
            +
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 52 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 53 | 
            +
                  copy.struct.wont_be :owned?
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it 'returns nil when passed nil' do
         | 
| 57 | 
            +
                  GIMarshallingTests::SimpleStruct.copy_from(nil).must_be_nil
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                it 'converts its argument if that is possible' do
         | 
| 61 | 
            +
                  GObject::Value.copy_from(4).must_be_instance_of GObject::Value
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              describe 'wrap_own' do
         | 
| 66 | 
            +
                it 'wraps and owns the supplied pointer for structs' do
         | 
| 67 | 
            +
                  original = GIMarshallingTests::SimpleStruct.new
         | 
| 68 | 
            +
                  original.struct.owned = false
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  copy = GIMarshallingTests::SimpleStruct.wrap_own(original.to_ptr)
         | 
| 71 | 
            +
                  copy.to_ptr.must_equal original.to_ptr
         | 
| 72 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 73 | 
            +
                  copy.struct.must_be :owned?
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                it 'wraps and owns the supplied pointer for unions' do
         | 
| 77 | 
            +
                  original = GIMarshallingTests::Union.new
         | 
| 78 | 
            +
                  original.struct.owned = false
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  copy = GIMarshallingTests::Union.wrap_own(original.to_ptr)
         | 
| 81 | 
            +
                  copy.to_ptr.must_equal original.to_ptr
         | 
| 82 | 
            +
                  copy.to_ptr.wont_be :autorelease?
         | 
| 83 | 
            +
                  copy.struct.must_be :owned?
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                it 'returns nil when passed nil' do
         | 
| 87 | 
            +
                  GIMarshallingTests::SimpleStruct.wrap_own(nil).must_be_nil
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              describe '.native_type' do
         | 
| 92 | 
            +
                let(:type) { GIMarshallingTests::SimpleStruct.native_type }
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                it 'is a struct by value' do
         | 
| 95 | 
            +
                  type.must_be_instance_of FFI::StructByValue
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                it 'wraps the types nested struct class' do
         | 
| 99 | 
            +
                  type.struct_class.must_equal GIMarshallingTests::SimpleStruct::Struct
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              describe '.to_native' do
         | 
| 104 | 
            +
                it "returns the supplied value's struct" do
         | 
| 105 | 
            +
                  object = GIMarshallingTests::SimpleStruct.new
         | 
| 106 | 
            +
                  result = object.class.to_native(object, 'some-context')
         | 
| 107 | 
            +
                  result.must_equal object.struct
         | 
| 108 | 
            +
                end
         | 
| 109 | 
            +
              end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
              describe '.to_ffi_type' do
         | 
| 112 | 
            +
                it 'returns the class itself' do
         | 
| 113 | 
            +
                  klass = GIMarshallingTests::SimpleStruct
         | 
| 114 | 
            +
                  ffi_type = klass.to_ffi_type
         | 
| 115 | 
            +
                  ffi_type.must_equal klass
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
              describe '.get_value_from_pointer' do
         | 
| 120 | 
            +
                let(:klass) { GIMarshallingTests::SimpleStruct }
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                it 'returns just a pointer' do
         | 
| 123 | 
            +
                  object = klass.new
         | 
| 124 | 
            +
                  ptr = object.to_ptr
         | 
| 125 | 
            +
                  klass.get_value_from_pointer(ptr, 0).must_equal ptr
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                it 'uses offset correctly' do
         | 
| 129 | 
            +
                  struct1 = klass.new.tap { |it| it.long_ = 42 }
         | 
| 130 | 
            +
                  struct2 = klass.new.tap { |it| it.long_ = 24 }
         | 
| 131 | 
            +
                  array_ptr = GirFFI::InPointer.from_array(klass, [struct1, struct2])
         | 
| 132 | 
            +
                  ptr = klass.get_value_from_pointer(array_ptr, klass.size)
         | 
| 133 | 
            +
                  result = klass.wrap(ptr)
         | 
| 134 | 
            +
                  result.long_.must_equal 24
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
              describe '.copy_value_to_pointer' do
         | 
| 139 | 
            +
                let(:klass) { GIMarshallingTests::SimpleStruct }
         | 
| 140 | 
            +
                let(:struct) { klass.new }
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                it 'copies data correctly' do
         | 
| 143 | 
            +
                  struct.long_ = 42
         | 
| 144 | 
            +
                  target = FFI::MemoryPointer.new klass.size
         | 
| 145 | 
            +
                  klass.copy_value_to_pointer(struct, target)
         | 
| 146 | 
            +
                  result = klass.wrap(target)
         | 
| 147 | 
            +
                  result.long_.must_equal 42
         | 
| 148 | 
            +
                end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                it 'uses offset correctly' do
         | 
| 151 | 
            +
                  struct.long_ = 42
         | 
| 152 | 
            +
                  target = FFI::MemoryPointer.new klass.size + 10
         | 
| 153 | 
            +
                  klass.copy_value_to_pointer(struct, target, 10)
         | 
| 154 | 
            +
                  result = klass.wrap(target + 10)
         | 
| 155 | 
            +
                  result.long_.must_equal 42
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
              end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
              it 'adds its class methods to classes that include it' do
         | 
| 160 | 
            +
                klass = Class.new
         | 
| 161 | 
            +
                klass.send :include, GirFFI::StructLikeBase
         | 
| 162 | 
            +
                klass.singleton_class.must_include GirFFI::StructLikeBase::ClassMethods
         | 
| 163 | 
            +
              end
         | 
| 164 | 
            +
            end
         | 
| @@ -4,6 +4,10 @@ require 'gir_ffi_test_helper' | |
| 4 4 | 
             
            GirFFI.setup :GIMarshallingTests
         | 
| 5 5 |  | 
| 6 6 | 
             
            describe GirFFI::UnionBase do
         | 
| 7 | 
            +
              it 'inherits from StructLikeBase' do
         | 
| 8 | 
            +
                GirFFI::StructBase.must_include GirFFI::StructLikeBase
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 7 11 | 
             
              describe 'new' do
         | 
| 8 12 | 
             
                it 'creates an instance with an owned struct' do
         | 
| 9 13 | 
             
                  instance = GIMarshallingTests::Union.new
         | 
| @@ -15,24 +19,4 @@ describe GirFFI::UnionBase do | |
| 15 19 | 
             
                  instance.to_ptr.wont_be :autorelease?
         | 
| 16 20 | 
             
                end
         | 
| 17 21 | 
             
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              describe 'wrap_copy' do
         | 
| 20 | 
            -
                it 'returns a wrapped owned copy' do
         | 
| 21 | 
            -
                  original = GIMarshallingTests::Union.new
         | 
| 22 | 
            -
                  copy = GIMarshallingTests::Union.wrap_copy(original.to_ptr)
         | 
| 23 | 
            -
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 24 | 
            -
                  copy.to_ptr.wont_be :autorelease?
         | 
| 25 | 
            -
                  copy.struct.must_be :owned?
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              describe 'copy_from' do
         | 
| 30 | 
            -
                it 'returns an unowned copy' do
         | 
| 31 | 
            -
                  original = GIMarshallingTests::Union.new
         | 
| 32 | 
            -
                  copy = GIMarshallingTests::Union.copy_from(original)
         | 
| 33 | 
            -
                  copy.to_ptr.wont_equal original.to_ptr
         | 
| 34 | 
            -
                  copy.to_ptr.wont_be :autorelease?
         | 
| 35 | 
            -
                  copy.struct.wont_be :owned?
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
              end
         | 
| 38 22 | 
             
            end
         | 
| @@ -1,12 +1,12 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 | 
             
            require 'gir_ffi_test_helper'
         | 
| 3 | 
            -
            require 'gir_ffi/ | 
| 3 | 
            +
            require 'gir_ffi/user_defined_object_info'
         | 
| 4 4 |  | 
| 5 5 | 
             
            GirFFI.setup :GIMarshallingTests
         | 
| 6 6 |  | 
| 7 | 
            -
            describe GirFFI:: | 
| 7 | 
            +
            describe GirFFI::UserDefinedObjectInfo do
         | 
| 8 8 | 
             
              describe '#described_class' do
         | 
| 9 | 
            -
                let(:info) { GirFFI:: | 
| 9 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new :some_class }
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'returns the class passed to #initialize' do
         | 
| 12 12 | 
             
                  info.described_class.must_equal :some_class
         | 
| @@ -14,7 +14,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 14 14 | 
             
              end
         | 
| 15 15 |  | 
| 16 16 | 
             
              describe '#install_property' do
         | 
| 17 | 
            -
                let(:info) { GirFFI:: | 
| 17 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new :some_class }
         | 
| 18 18 | 
             
                let(:foo_spec) { Object.new }
         | 
| 19 19 |  | 
| 20 20 | 
             
                it 'adds the passed in property to the list of properties' do
         | 
| @@ -26,7 +26,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 26 26 | 
             
              end
         | 
| 27 27 |  | 
| 28 28 | 
             
              describe '#install_vfunc_implementation' do
         | 
| 29 | 
            -
                let(:info) { GirFFI:: | 
| 29 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new :some_class }
         | 
| 30 30 | 
             
                let(:implementation) { Object.new }
         | 
| 31 31 |  | 
| 32 32 | 
             
                it 'adds to the list of vfunc implementations' do
         | 
| @@ -46,7 +46,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 46 46 | 
             
                let(:foo_spec) { Object.new }
         | 
| 47 47 | 
             
                let(:bar_spec) { Object.new }
         | 
| 48 48 | 
             
                let(:info) do
         | 
| 49 | 
            -
                  GirFFI:: | 
| 49 | 
            +
                  GirFFI::UserDefinedObjectInfo.new :some_class do |inf|
         | 
| 50 50 | 
             
                    inf.install_property foo_spec
         | 
| 51 51 | 
             
                    inf.install_property bar_spec
         | 
| 52 52 | 
             
                  end
         | 
| @@ -64,7 +64,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 64 64 |  | 
| 65 65 | 
             
              describe '#g_name' do
         | 
| 66 66 | 
             
                let(:klass) { Object.new }
         | 
| 67 | 
            -
                let(:info) { GirFFI:: | 
| 67 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
         | 
| 68 68 |  | 
| 69 69 | 
             
                before do
         | 
| 70 70 | 
             
                  allow(klass).to receive(:name).and_return 'foo'
         | 
| @@ -82,7 +82,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 82 82 |  | 
| 83 83 | 
             
              describe '#find_method' do
         | 
| 84 84 | 
             
                let(:klass) { Object.new }
         | 
| 85 | 
            -
                let(:info) { GirFFI:: | 
| 85 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
         | 
| 86 86 |  | 
| 87 87 | 
             
                it 'finds no methods' do
         | 
| 88 88 | 
             
                  info.find_method('foo').must_equal nil
         | 
| @@ -91,7 +91,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 91 91 |  | 
| 92 92 | 
             
              describe '#find_signal' do
         | 
| 93 93 | 
             
                let(:klass) { Object.new }
         | 
| 94 | 
            -
                let(:info) { GirFFI:: | 
| 94 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
         | 
| 95 95 |  | 
| 96 96 | 
             
                it 'finds no signals' do
         | 
| 97 97 | 
             
                  info.find_signal('foo').must_equal nil
         | 
| @@ -101,7 +101,7 @@ describe GirFFI::UserDefinedTypeInfo do | |
| 101 101 | 
             
              describe '#interfaces' do
         | 
| 102 102 | 
             
                let(:modul) { GIMarshallingTests::Interface }
         | 
| 103 103 | 
             
                let(:klass) { Class.new GIMarshallingTests::Object }
         | 
| 104 | 
            -
                let(:info) { GirFFI:: | 
| 104 | 
            +
                let(:info) { GirFFI::UserDefinedObjectInfo.new klass }
         | 
| 105 105 |  | 
| 106 106 | 
             
                before do
         | 
| 107 107 | 
             
                  klass.send :include, modul
         | 
| @@ -3,18 +3,35 @@ require 'gir_ffi_test_helper' | |
| 3 3 | 
             
            require 'gir_ffi/user_defined_property_info'
         | 
| 4 4 |  | 
| 5 5 | 
             
            describe GirFFI::UserDefinedPropertyInfo do
         | 
| 6 | 
            +
              let(:pspec) do
         | 
| 7 | 
            +
                GObject.param_spec_int('foo-bar', 'foo bar',
         | 
| 8 | 
            +
                                       'Foo Bar',
         | 
| 9 | 
            +
                                       1, 3, 2,
         | 
| 10 | 
            +
                                       readable: true, writable: true)
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
              let(:info) { GirFFI::UserDefinedPropertyInfo.new pspec }
         | 
| 13 | 
            +
             | 
| 6 14 | 
             
              describe '#param_spec' do
         | 
| 7 15 | 
             
                it 'returns the passed in parameter specification' do
         | 
| 8 | 
            -
                  info | 
| 9 | 
            -
                  info.param_spec.must_equal :some_param_spec
         | 
| 16 | 
            +
                  info.param_spec.must_equal pspec
         | 
| 10 17 | 
             
                end
         | 
| 11 18 | 
             
              end
         | 
| 12 19 |  | 
| 13 20 | 
             
              describe '#name' do
         | 
| 14 21 | 
             
                it 'returns the name retrieved from the parameter specification' do
         | 
| 15 | 
            -
                   | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 22 | 
            +
                  info.name.must_equal 'foo-bar'
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              describe '#ffi_type' do
         | 
| 27 | 
            +
                it 'returns the ffi type corresponding to the type tag' do
         | 
| 28 | 
            +
                  info.ffi_type.must_equal :int
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              describe '#type_tag' do
         | 
| 33 | 
            +
                it 'returns the mapped type symbol' do
         | 
| 34 | 
            +
                  info.type_tag.must_equal :gint
         | 
| 18 35 | 
             
                end
         | 
| 19 36 | 
             
              end
         | 
| 20 37 | 
             
            end
         | 
| @@ -56,6 +56,11 @@ describe Everything do | |
| 56 56 | 
             
                Everything.const_return_glong.must_equal 0
         | 
| 57 57 | 
             
              end
         | 
| 58 58 |  | 
| 59 | 
            +
              it 'has a working function #const_return_gpointer' do
         | 
| 60 | 
            +
                skip unless get_introspection_data 'Everything', 'const_return_gpointer'
         | 
| 61 | 
            +
                Everything.const_return_gpointer.must_be :null?
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 59 64 | 
             
              it 'has a working function #const_return_gshort' do
         | 
| 60 65 | 
             
                Everything.const_return_gshort.must_equal 0
         | 
| 61 66 | 
             
              end
         | 
| @@ -166,6 +171,11 @@ describe Everything do | |
| 166 171 | 
             
                Everything.one_outparam_glong.must_equal 0
         | 
| 167 172 | 
             
              end
         | 
| 168 173 |  | 
| 174 | 
            +
              it 'has a working function #one_outparam_gpointer' do
         | 
| 175 | 
            +
                skip unless get_introspection_data 'Everything', 'one_outparam_gpointer'
         | 
| 176 | 
            +
                Everything.one_outparam_gpointer.must_be :null?
         | 
| 177 | 
            +
              end
         | 
| 178 | 
            +
             | 
| 169 179 | 
             
              it 'has a working function #one_outparam_gshort' do
         | 
| 170 180 | 
             
                Everything.one_outparam_gshort.must_equal 0
         | 
| 171 181 | 
             
              end
         | 
| @@ -271,6 +281,11 @@ describe Everything do | |
| 271 281 | 
             
                Everything.oneparam_glong(0).must_be_nil
         | 
| 272 282 | 
             
              end
         | 
| 273 283 |  | 
| 284 | 
            +
              it 'has a working function #oneparam_gpointer' do
         | 
| 285 | 
            +
                skip unless get_introspection_data 'Everything', 'oneparam_gpointer'
         | 
| 286 | 
            +
                Everything.oneparam_gpointer(FFI::MemoryPointer.new(:int)).must_be_nil
         | 
| 287 | 
            +
              end
         | 
| 288 | 
            +
             | 
| 274 289 | 
             
              it 'has a working function #oneparam_gshort' do
         | 
| 275 290 | 
             
                Everything.oneparam_gshort(0).must_be_nil
         | 
| 276 291 | 
             
              end
         | 
| @@ -375,6 +390,13 @@ describe Everything do | |
| 375 390 | 
             
                Everything.passthrough_one_glong(42).must_equal 42
         | 
| 376 391 | 
             
              end
         | 
| 377 392 |  | 
| 393 | 
            +
              it 'has a working function #passthrough_one_gpointer' do
         | 
| 394 | 
            +
                skip unless get_introspection_data 'Everything', 'passthrough_one_gpointer'
         | 
| 395 | 
            +
                ptr = FFI::MemoryPointer.new(:int)
         | 
| 396 | 
            +
                result = Everything.passthrough_one_gpointer(ptr)
         | 
| 397 | 
            +
                result.must_equal ptr
         | 
| 398 | 
            +
              end
         | 
| 399 | 
            +
             | 
| 378 400 | 
             
              it 'has a working function #passthrough_one_gshort' do
         | 
| 379 401 | 
             
                Everything.passthrough_one_gshort(42).must_equal 42
         | 
| 380 402 | 
             
              end
         | 
| @@ -221,7 +221,7 @@ describe GIMarshallingTests do | |
| 221 221 | 
             
                  skip unless get_introspection_data 'GIMarshallingTests', 'Interface3'
         | 
| 222 222 | 
             
                  derived_klass.class_eval { include GIMarshallingTests::Interface3 }
         | 
| 223 223 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 224 | 
            -
                    info.install_vfunc_implementation :test_variant_array_in, proc {|obj, in_|
         | 
| 224 | 
            +
                    info.install_vfunc_implementation :test_variant_array_in, proc { |obj, in_|
         | 
| 225 225 | 
             
                      obj.int = in_.to_a.first.get_byte
         | 
| 226 226 | 
             
                    }
         | 
| 227 227 | 
             
                  end
         | 
| @@ -325,10 +325,6 @@ describe GIMarshallingTests do | |
| 325 325 | 
             
                  res.ref_count.must_equal 1
         | 
| 326 326 | 
             
                end
         | 
| 327 327 |  | 
| 328 | 
            -
                it 'has a working function #inout_same' do
         | 
| 329 | 
            -
                  skip 'This function is defined in the header but not implemented'
         | 
| 330 | 
            -
                end
         | 
| 331 | 
            -
             | 
| 332 328 | 
             
                it 'has a working function #none_inout' do
         | 
| 333 329 | 
             
                  ob = GIMarshallingTests::Object.new 42
         | 
| 334 330 | 
             
                  ob.ref_count.must_equal 1
         | 
| @@ -394,7 +390,7 @@ describe GIMarshallingTests do | |
| 394 390 | 
             
                                                           'vfunc_in_object_transfer_full')
         | 
| 395 391 | 
             
                  obj = nil
         | 
| 396 392 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 397 | 
            -
                    info.install_vfunc_implementation :vfunc_in_object_transfer_full, proc {|_this, object|
         | 
| 393 | 
            +
                    info.install_vfunc_implementation :vfunc_in_object_transfer_full, proc { |_this, object|
         | 
| 398 394 | 
             
                      obj = object
         | 
| 399 395 | 
             
                    }
         | 
| 400 396 | 
             
                  end
         | 
| @@ -409,7 +405,7 @@ describe GIMarshallingTests do | |
| 409 405 | 
             
                                                           'vfunc_in_object_transfer_none')
         | 
| 410 406 | 
             
                  obj = nil
         | 
| 411 407 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 412 | 
            -
                    info.install_vfunc_implementation :vfunc_in_object_transfer_none, proc {|_this, object|
         | 
| 408 | 
            +
                    info.install_vfunc_implementation :vfunc_in_object_transfer_none, proc { |_this, object|
         | 
| 413 409 | 
             
                      obj = object
         | 
| 414 410 | 
             
                    }
         | 
| 415 411 | 
             
                  end
         | 
| @@ -425,7 +421,7 @@ describe GIMarshallingTests do | |
| 425 421 | 
             
                                                           'vfunc_out_object_transfer_full')
         | 
| 426 422 | 
             
                  obj = nil
         | 
| 427 423 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 428 | 
            -
                    info.install_vfunc_implementation :vfunc_out_object_transfer_full, proc {|_obj|
         | 
| 424 | 
            +
                    info.install_vfunc_implementation :vfunc_out_object_transfer_full, proc { |_obj|
         | 
| 429 425 | 
             
                      obj = GIMarshallingTests::Object.new(42)
         | 
| 430 426 | 
             
                    }
         | 
| 431 427 | 
             
                  end
         | 
| @@ -439,7 +435,7 @@ describe GIMarshallingTests do | |
| 439 435 | 
             
                  skip unless get_vfunc_introspection_data('GIMarshallingTests', 'Object',
         | 
| 440 436 | 
             
                                                           'vfunc_out_object_transfer_none')
         | 
| 441 437 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 442 | 
            -
                    info.install_vfunc_implementation :vfunc_out_object_transfer_none, proc {|_obj|
         | 
| 438 | 
            +
                    info.install_vfunc_implementation :vfunc_out_object_transfer_none, proc { |_obj|
         | 
| 443 439 | 
             
                      GIMarshallingTests::Object.new 42
         | 
| 444 440 | 
             
                    }
         | 
| 445 441 | 
             
                  end
         | 
| @@ -451,7 +447,7 @@ describe GIMarshallingTests do | |
| 451 447 | 
             
                  skip unless get_vfunc_introspection_data('GIMarshallingTests', 'Object',
         | 
| 452 448 | 
             
                                                           'vfunc_return_object_transfer_full')
         | 
| 453 449 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 454 | 
            -
                    info.install_vfunc_implementation :vfunc_return_object_transfer_full, proc {|_obj|
         | 
| 450 | 
            +
                    info.install_vfunc_implementation :vfunc_return_object_transfer_full, proc { |_obj|
         | 
| 455 451 | 
             
                      GIMarshallingTests::Object.new 42
         | 
| 456 452 | 
             
                    }
         | 
| 457 453 | 
             
                  end
         | 
| @@ -463,7 +459,7 @@ describe GIMarshallingTests do | |
| 463 459 | 
             
                  skip unless get_vfunc_introspection_data('GIMarshallingTests', 'Object',
         | 
| 464 460 | 
             
                                                           'vfunc_return_object_transfer_none')
         | 
| 465 461 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 466 | 
            -
                    info.install_vfunc_implementation :vfunc_return_object_transfer_none, proc {|_obj|
         | 
| 462 | 
            +
                    info.install_vfunc_implementation :vfunc_return_object_transfer_none, proc { |_obj|
         | 
| 467 463 | 
             
                      GIMarshallingTests::Object.new 42
         | 
| 468 464 | 
             
                    }
         | 
| 469 465 | 
             
                  end
         | 
| @@ -479,10 +475,15 @@ describe GIMarshallingTests do | |
| 479 475 | 
             
                  derived_instance.int.must_equal 23
         | 
| 480 476 | 
             
                end
         | 
| 481 477 |  | 
| 482 | 
            -
                # TODO: Check if this is fixed
         | 
| 483 | 
            -
                # See https://bugzilla.gnome.org/show_bug.cgi?id=727665
         | 
| 484 478 | 
             
                it 'has a working method #int8_out' do
         | 
| 485 | 
            -
                   | 
| 479 | 
            +
                  # GLib minor version and GObjectIntrospection minor version should be in sync
         | 
| 480 | 
            +
                  skip 'Introspection data is not generated correctly' if GLib::MINOR_VERSION < 42
         | 
| 481 | 
            +
             | 
| 482 | 
            +
                  derived_instance = make_derived_instance do |info|
         | 
| 483 | 
            +
                    info.install_vfunc_implementation :method_int8_out, proc { |_obj| 42 }
         | 
| 484 | 
            +
                  end
         | 
| 485 | 
            +
             | 
| 486 | 
            +
                  derived_instance.int8_out.must_equal 42
         | 
| 486 487 | 
             
                end
         | 
| 487 488 |  | 
| 488 489 | 
             
                it 'has a working method #method' do
         | 
| @@ -582,7 +583,7 @@ describe GIMarshallingTests do | |
| 582 583 | 
             
                  skip unless get_vfunc_introspection_data('GIMarshallingTests', 'Object',
         | 
| 583 584 | 
             
                                                           'vfunc_array_out_parameter')
         | 
| 584 585 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 585 | 
            -
                    info.install_vfunc_implementation :vfunc_array_out_parameter, proc {|_obj|
         | 
| 586 | 
            +
                    info.install_vfunc_implementation :vfunc_array_out_parameter, proc { |_obj|
         | 
| 586 587 | 
             
                      [1.1, 2.2, 3.3]
         | 
| 587 588 | 
             
                    }
         | 
| 588 589 | 
             
                  end
         | 
| @@ -598,7 +599,7 @@ describe GIMarshallingTests do | |
| 598 599 | 
             
                  skip unless get_vfunc_introspection_data('GIMarshallingTests', 'Object',
         | 
| 599 600 | 
             
                                                           'vfunc_caller_allocated_out_parameter')
         | 
| 600 601 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 601 | 
            -
                    info.install_vfunc_implementation :vfunc_caller_allocated_out_parameter, proc {|_obj|
         | 
| 602 | 
            +
                    info.install_vfunc_implementation :vfunc_caller_allocated_out_parameter, proc { |_obj|
         | 
| 602 603 | 
             
                      'Hello!'
         | 
| 603 604 | 
             
                    }
         | 
| 604 605 | 
             
                  end
         | 
| @@ -608,7 +609,7 @@ describe GIMarshallingTests do | |
| 608 609 |  | 
| 609 610 | 
             
                it 'has a working method #vfunc_meth_with_error' do
         | 
| 610 611 | 
             
                  derived_instance = make_derived_instance do |info|
         | 
| 611 | 
            -
                    info.install_vfunc_implementation :vfunc_meth_with_err, proc {|_object, x|
         | 
| 612 | 
            +
                    info.install_vfunc_implementation :vfunc_meth_with_err, proc { |_object, x|
         | 
| 612 613 | 
             
                      raise 'This is not the answer!' unless x == 42
         | 
| 613 614 | 
             
                      true
         | 
| 614 615 | 
             
                    }
         | 
| @@ -1841,7 +1842,7 @@ describe GIMarshallingTests do | |
| 1841 1842 | 
             
              it 'has a working function #gclosure_return' do
         | 
| 1842 1843 | 
             
                cl = GIMarshallingTests.gclosure_return
         | 
| 1843 1844 | 
             
                gv = GObject::Value.wrap_ruby_value 0
         | 
| 1844 | 
            -
                result = cl.invoke gv,  | 
| 1845 | 
            +
                result = cl.invoke gv, []
         | 
| 1845 1846 | 
             
                assert_equal 42, gv.get_value
         | 
| 1846 1847 | 
             
                result.must_equal 42
         | 
| 1847 1848 | 
             
              end
         | 
| @@ -2610,12 +2611,13 @@ describe GIMarshallingTests do | |
| 2610 2611 | 
             
                res.must_be_instance_of GIMarshallingTests::OverridesStruct
         | 
| 2611 2612 | 
             
              end
         | 
| 2612 2613 |  | 
| 2613 | 
            -
              # TODO: Wait for fixed version of param_spec_in_bool to land in Debian/Ubuntu
         | 
| 2614 | 
            -
              # See https://bugzilla.gnome.org/show_bug.cgi?id=728409
         | 
| 2615 2614 | 
             
              it 'has a working function #param_spec_in_bool' do
         | 
| 2616 | 
            -
                 | 
| 2615 | 
            +
                # GLib minor version and GObjectIntrospection minor version should be in sync
         | 
| 2616 | 
            +
                skip 'param_spec_in_bool tests the wrong type' if GLib::MINOR_VERSION < 42
         | 
| 2617 | 
            +
             | 
| 2617 2618 | 
             
                ps = GObject.param_spec_boolean 'mybool', 'nick', 'blurb', true, :readable
         | 
| 2618 2619 | 
             
                GIMarshallingTests.param_spec_in_bool ps
         | 
| 2620 | 
            +
                pass
         | 
| 2619 2621 | 
             
              end
         | 
| 2620 2622 |  | 
| 2621 2623 | 
             
              it 'has a working function #param_spec_out' do
         | 
| @@ -5,6 +5,8 @@ GirFFI.setup :Gio | |
| 5 5 |  | 
| 6 6 | 
             
            # Tests generated methods and functions in the Gio namespace.
         | 
| 7 7 | 
             
            describe 'The generated Gio module' do
         | 
| 8 | 
            +
              cover 'Gio'
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
              describe 'File#new_for_path, a method returning an interface,' do
         | 
| 9 11 | 
             
                it 'returns an object of a more specific class' do
         | 
| 10 12 | 
             
                  file = Gio::File.new_for_path('/')
         |