gir_ffi 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/History.txt +6 -0
  2. data/lib/ffi-glib/array.rb +12 -3
  3. data/lib/ffi-glib/list_methods.rb +4 -0
  4. data/lib/ffi-glib/ptr_array.rb +4 -0
  5. data/lib/ffi-glib/sized_array.rb +4 -0
  6. data/lib/ffi-glib/strv.rb +4 -1
  7. data/lib/gir_ffi/arg_helper.rb +5 -27
  8. data/lib/gir_ffi/class_base.rb +8 -0
  9. data/lib/gir_ffi/enum_base.rb +8 -0
  10. data/lib/gir_ffi/ffi_ext/pointer.rb +12 -0
  11. data/lib/gir_ffi/in_out_pointer.rb +3 -13
  12. data/lib/gir_ffi/in_pointer.rb +19 -1
  13. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -2
  14. data/lib/gir_ffi/info_ext/i_object_info.rb +1 -1
  15. data/lib/gir_ffi/info_ext/i_type_info.rb +3 -14
  16. data/lib/gir_ffi/module_base.rb +1 -0
  17. data/lib/gir_ffi/type_map.rb +6 -8
  18. data/lib/gir_ffi/version.rb +1 -1
  19. data/lib/gir_ffi/zero_terminated.rb +5 -1
  20. data/tasks/test.rake +1 -0
  21. data/test/ffi-glib/array_test.rb +41 -7
  22. data/test/ffi-glib/hash_table_test.rb +3 -3
  23. data/test/ffi-glib/list_test.rb +31 -3
  24. data/test/ffi-glib/ptr_array_test.rb +28 -0
  25. data/test/ffi-glib/s_list_test.rb +28 -0
  26. data/test/ffi-glib/sized_array_test.rb +30 -3
  27. data/test/ffi-glib/strv_test.rb +31 -0
  28. data/test/ffi-gobject_test.rb +2 -2
  29. data/test/gir_ffi/arg_helper_test.rb +3 -2
  30. data/test/gir_ffi/class_base_test.rb +62 -4
  31. data/test/gir_ffi/function_builder_test.rb +1 -1
  32. data/test/gir_ffi/in_pointer_test.rb +17 -0
  33. data/test/gir_ffi/info_ext/i_object_info_test.rb +14 -0
  34. data/test/gir_ffi/info_ext/i_type_info_test.rb +79 -25
  35. data/test/gir_ffi/type_map_test.rb +15 -0
  36. data/test/gir_ffi/zero_terminated_test.rb +28 -0
  37. data/test/integration/generated_gimarshallingtests_test.rb +90 -75
  38. data/test/integration/generated_pango_test.rb +1 -1
  39. data/test/integration/generated_regress_test.rb +64 -39
  40. metadata +8 -18
@@ -84,6 +84,7 @@ namespace :test do
84
84
  sh %{cd test/lib && make}
85
85
  end
86
86
 
87
+ task :introspection => :lib
87
88
  task :main => :lib
88
89
  task :overrides => :lib
89
90
  task :integration => :lib
@@ -42,12 +42,18 @@ describe GLib::Array do
42
42
  assert_equal arr.to_a, arr2.to_a
43
43
  end
44
44
 
45
- it "raises an error if the element sizes don't match" do
45
+ it "warns the element sizes don't match" do
46
46
  arr = GLib::Array.new :gint32
47
47
  arr.append_vals [1, 2, 3]
48
- assert_raises RuntimeError do
49
- GLib::Array.wrap :gint8, arr.to_ptr
50
- end
48
+ proc { GLib::Array.wrap :gint8, arr.to_ptr }.must_output nil, /sizes do not match/
49
+ end
50
+
51
+ it "handles a struct as the element type" do
52
+ vals = [1, 2, 3].map {|i| GObject::EnumValue.new.tap {|ev| ev.value = i} }
53
+ arr = GLib::Array.new GObject::EnumValue
54
+ arr.append_vals vals
55
+ arr2 = GLib::Array.wrap GObject::EnumValue, arr.to_ptr
56
+ arr2.to_a.must_equal arr.to_a
51
57
  end
52
58
  end
53
59
 
@@ -71,7 +77,7 @@ describe GLib::Array do
71
77
  arr = GLib::Array.new :gint32
72
78
  arr.append_vals [3, 2, 1]
73
79
  arr2 = GLib::Array.from :foo, arr
74
- assert_equal arr, arr2
80
+ assert arr2.equal? arr
75
81
  end
76
82
 
77
83
  it "wraps its argument if given a pointer" do
@@ -81,8 +87,36 @@ describe GLib::Array do
81
87
  assert_instance_of FFI::Pointer, pointer
82
88
  arr2 = GLib::Array.from :gint32, pointer
83
89
  assert_instance_of GLib::Array, arr2
84
- refute_equal arr, arr2
85
- assert_equal arr.to_a, arr2.to_a
90
+ refute arr2.equal? arr
91
+ arr2.to_a.must_equal arr.to_a
92
+ end
93
+ end
94
+
95
+ describe "#==" do
96
+ it "returns true when comparing to an array with the same elements" do
97
+ arr = GLib::Array.from :gint32, [1, 2, 3]
98
+
99
+ arr.must_be :==, [1, 2, 3]
100
+ end
101
+
102
+ it "returns false when comparing to an array with different elements" do
103
+ arr = GLib::Array.from :gint32, [1, 2, 3]
104
+
105
+ arr.wont_be :==, [1, 2]
106
+ end
107
+
108
+ it "returns true when comparing to a GArray with the same elements" do
109
+ arr = GLib::Array.from :gint32, [1, 2, 3]
110
+ other = GLib::Array.from :gint32, [1, 2, 3]
111
+
112
+ arr.must_be :==, other
113
+ end
114
+
115
+ it "returns false when comparing to a GArray with different elements" do
116
+ arr = GLib::Array.from :gint32, [1, 2, 3]
117
+ other = GLib::Array.from :gint32, [1, 2]
118
+
119
+ arr.wont_be :==, other
86
120
  end
87
121
  end
88
122
  end
@@ -17,7 +17,7 @@ describe GLib::HashTable do
17
17
  it "return its argument if given a GHashTable" do
18
18
  hsh = GLib::HashTable.from [:utf8, :gint32], {"foo" => 23, "bar" => 32}
19
19
  hsh2 = GLib::HashTable.from [:utf8, :gint32], hsh
20
- assert_equal hsh, hsh2
20
+ assert hsh2.equal? hsh
21
21
  end
22
22
 
23
23
  it "wraps its argument if given a pointer" do
@@ -26,8 +26,8 @@ describe GLib::HashTable do
26
26
  assert_instance_of FFI::Pointer, pointer
27
27
  hsh2 = GLib::HashTable.from [:utf8, :gint32], pointer
28
28
  assert_instance_of GLib::HashTable, hsh2
29
- refute_equal hsh, hsh2
30
- assert_equal hsh.to_hash, hsh2.to_hash
29
+ refute hsh2.equal? hsh
30
+ hsh2.to_hash.must_equal hsh.to_hash
31
31
  end
32
32
  end
33
33
 
@@ -40,7 +40,7 @@ describe GLib::List do
40
40
  it "return its argument if given a GList" do
41
41
  lst = GLib::List.from :gint32, [3, 2, 1]
42
42
  lst2 = GLib::List.from :gint32, lst
43
- assert_equal lst, lst2
43
+ assert lst2.equal? lst
44
44
  end
45
45
 
46
46
  it "wraps its argument if given a pointer" do
@@ -49,8 +49,36 @@ describe GLib::List do
49
49
  assert_instance_of FFI::Pointer, pointer
50
50
  lst2 = GLib::List.from :gint32, pointer
51
51
  assert_instance_of GLib::List, lst2
52
- refute_equal lst, lst2
53
- assert_equal lst.to_a, lst2.to_a
52
+ refute lst2.equal? lst
53
+ lst2.to_a.must_equal lst.to_a
54
+ end
55
+ end
56
+
57
+ describe "#==" do
58
+ it "returns true when comparing to an array with the same elements" do
59
+ list = GLib::List.from :gint32, [1, 2, 3]
60
+
61
+ list.must_be :==, [1, 2, 3]
62
+ end
63
+
64
+ it "returns false when comparing to an array with different elements" do
65
+ list = GLib::List.from :gint32, [1, 2, 3]
66
+
67
+ list.wont_be :==, [1, 2]
68
+ end
69
+
70
+ it "returns true when comparing to a list with the same elements" do
71
+ list = GLib::List.from :gint32, [1, 2, 3]
72
+ other = GLib::List.from :gint32, [1, 2, 3]
73
+
74
+ list.must_be :==, other
75
+ end
76
+
77
+ it "returns false when comparing to a list with different elements" do
78
+ list = GLib::List.from :gint32, [1, 2, 3]
79
+ other = GLib::List.from :gint32, [1, 2]
80
+
81
+ list.wont_be :==, other
54
82
  end
55
83
  end
56
84
  end
@@ -66,4 +66,32 @@ describe GLib::PtrArray do
66
66
  arr.add "test1"
67
67
  assert_equal ["test1"], arr.to_a
68
68
  end
69
+
70
+ describe "#==" do
71
+ it "returns true when comparing to an array with the same elements" do
72
+ arr = GLib::PtrArray.from :utf8, ["1", "2", "3"]
73
+
74
+ arr.must_be :==, ["1", "2", "3"]
75
+ end
76
+
77
+ it "returns false when comparing to an array with different elements" do
78
+ arr = GLib::PtrArray.from :utf8, ["1", "2", "3"]
79
+
80
+ arr.wont_be :==, ["1", "2"]
81
+ end
82
+
83
+ it "returns true when comparing to a GPtrArray with the same elements" do
84
+ arr = GLib::PtrArray.from :utf8, ["1", "2", "3"]
85
+ other = GLib::PtrArray.from :utf8, ["1", "2", "3"]
86
+
87
+ arr.must_be :==, other
88
+ end
89
+
90
+ it "returns false when comparing to a GPtrArray with different elements" do
91
+ arr = GLib::PtrArray.from :utf8, ["1", "2", "3"]
92
+ other = GLib::PtrArray.from :utf8, ["1", "2"]
93
+
94
+ arr.wont_be :==, other
95
+ end
96
+ end
69
97
  end
@@ -43,4 +43,32 @@ describe GLib::SList do
43
43
  assert_equal lst, lst2
44
44
  end
45
45
  end
46
+
47
+ describe "#==" do
48
+ it "returns true when comparing to an array with the same elements" do
49
+ list = GLib::SList.from :gint32, [1, 2, 3]
50
+
51
+ list.must_be :==, [1, 2, 3]
52
+ end
53
+
54
+ it "returns false when comparing to an array with different elements" do
55
+ list = GLib::SList.from :gint32, [1, 2, 3]
56
+
57
+ list.wont_be :==, [1, 2]
58
+ end
59
+
60
+ it "returns true when comparing to a list with the same elements" do
61
+ list = GLib::SList.from :gint32, [1, 2, 3]
62
+ other = GLib::SList.from :gint32, [1, 2, 3]
63
+
64
+ list.must_be :==, other
65
+ end
66
+
67
+ it "returns false when comparing to a list with different elements" do
68
+ list = GLib::SList.from :gint32, [1, 2, 3]
69
+ other = GLib::SList.from :gint32, [1, 2]
70
+
71
+ list.wont_be :==, other
72
+ end
73
+ end
46
74
  end
@@ -75,8 +75,36 @@ describe GLib::SizedArray do
75
75
  arr = GLib::SizedArray.from :gint32, 3, [3, 2, 1]
76
76
  arr2 = GLib::SizedArray.from :gint32, 3, arr.to_ptr
77
77
  assert_instance_of GLib::SizedArray, arr2
78
- refute_equal arr, arr2
79
- assert_equal arr.to_a, arr2.to_a
78
+ refute arr2.equal? arr
79
+ arr2.to_ptr.must_equal arr.to_ptr
80
+ end
81
+ end
82
+
83
+ describe "#==" do
84
+ it "returns true when comparing to an array with the same elements" do
85
+ sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
86
+
87
+ sized.must_be :==, [1, 2, 3]
88
+ end
89
+
90
+ it "returns false when comparing to an array with different elements" do
91
+ sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
92
+
93
+ sized.wont_be :==, [1, 2]
94
+ end
95
+
96
+ it "returns true when comparing to a sized array with the same elements" do
97
+ sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
98
+ other = GLib::SizedArray.from :int32, 3, [1, 2, 3]
99
+
100
+ sized.must_be :==, other
101
+ end
102
+
103
+ it "returns false when comparing to a sized array with different elements" do
104
+ sized = GLib::SizedArray.from :int32, 3, [1, 2, 3]
105
+ other = GLib::SizedArray.from :int32, 2, [1, 2]
106
+
107
+ sized.wont_be :==, other
80
108
  end
81
109
  end
82
110
 
@@ -84,4 +112,3 @@ describe GLib::SizedArray do
84
112
  GLib::SizedArray.must_include Enumerable
85
113
  end
86
114
  end
87
-
@@ -0,0 +1,31 @@
1
+ require 'base_test_helper'
2
+
3
+ describe GLib::Strv do
4
+ describe "#==" do
5
+ it "returns true when comparing to an array with the same elements" do
6
+ strv = GLib::Strv.from ["1", "2", "3"]
7
+
8
+ strv.must_be :==, ["1", "2", "3"]
9
+ end
10
+
11
+ it "returns false when comparing to an array with different elements" do
12
+ strv = GLib::Strv.from ["1", "2", "3"]
13
+
14
+ strv.wont_be :==, ["1", "2"]
15
+ end
16
+
17
+ it "returns true when comparing to a strv with the same elements" do
18
+ strv = GLib::Strv.from ["1", "2", "3"]
19
+ other = GLib::Strv.from ["1", "2", "3"]
20
+
21
+ strv.must_be :==, other
22
+ end
23
+
24
+ it "returns false when comparing to a strv with different elements" do
25
+ strv = GLib::Strv.from ["1", "2", "3"]
26
+ other = GLib::Strv.from ["1", "2"]
27
+
28
+ strv.wont_be :==, other
29
+ end
30
+ end
31
+ end
@@ -22,7 +22,7 @@ describe GObject do
22
22
  callback = FFI::Function.new(:bool, argtypes) { |a,b,c,d| true }
23
23
  ::GObject::Lib.g_signal_connect_data s, "incoming", callback, nil, nil, 0
24
24
  rv = GObject.signal_emit s, "incoming"
25
- assert_equal true, rv.get_boolean
25
+ assert_equal true, rv.get_value
26
26
  end
27
27
 
28
28
  should "pass in extra arguments" do
@@ -94,7 +94,7 @@ describe GObject do
94
94
  s = Gio::SocketService.new
95
95
  GObject.signal_connect(s, "incoming") { true }
96
96
  rv = GObject.signal_emit s, "incoming"
97
- assert_equal true, rv.get_boolean
97
+ assert_equal true, rv.get_value
98
98
  end
99
99
 
100
100
  should "require a block" do
@@ -52,7 +52,9 @@ describe GirFFI::ArgHelper do
52
52
  end
53
53
 
54
54
  describe "for pointers to arrays of enums" do
55
- let(:enum) { FFI::Enum.new([:foo, 1, :bar, 2]) }
55
+ let(:enum) { Module.new {
56
+ extend GirFFI::EnumBase
57
+ self::Enum = FFI::Enum.new([:foo, 1, :bar, 2]) } }
56
58
  it "returns an empty array when passed a null pointer" do
57
59
  result = GirFFI::ArgHelper.ptr_to_typed_array enum, FFI::Pointer.new(0), 0
58
60
  result.must_equal []
@@ -69,7 +71,6 @@ describe GirFFI::ArgHelper do
69
71
  result = GirFFI::ArgHelper.ptr_to_typed_array enum, block, 2
70
72
  result.must_equal [:foo, :bar]
71
73
  end
72
-
73
74
  end
74
75
 
75
76
  describe "for pointers to arrays of base types" do
@@ -2,14 +2,72 @@ require 'gir_ffi_test_helper'
2
2
 
3
3
  describe GirFFI::ClassBase do
4
4
  describe "a simple descendant" do
5
- before do
6
- @klass = Class.new GirFFI::ClassBase
7
- end
5
+ let(:klass) {
6
+ Class.new(GirFFI::ClassBase) do
7
+ self::Struct = Class.new(FFI::Struct) do
8
+ layout :foo, :int32
9
+ end
10
+ end
11
+ }
12
+ let(:object) { klass.wrap FFI::MemoryPointer.new(:int32) }
8
13
 
9
14
  it "has #from as a pass-through method" do
10
- result = @klass.from :foo
15
+ result = klass.from :foo
11
16
  result.must_equal :foo
12
17
  end
18
+
19
+ describe "#==" do
20
+ it "returns true when comparing to an object of the same class and pointer" do
21
+ other = klass.wrap object.to_ptr
22
+
23
+ object.must_be :==, other
24
+ end
25
+
26
+ it "returns false when comparing to an object of the same class and different pointer" do
27
+ other = klass.wrap FFI::MemoryPointer.new(:int32)
28
+
29
+ object.wont_be :==, other
30
+ end
31
+
32
+ it "returns false when comparing to an object of a different class" do
33
+ other = Object.new
34
+
35
+ object.wont_be :==, other
36
+ end
37
+
38
+ it "returns true when comparing to an object of a subclass and the same pointer" do
39
+ subclass = Class.new(klass)
40
+ other = subclass.wrap object.to_ptr
41
+
42
+ object.must_be :==, other
43
+ end
44
+ end
45
+
46
+ describe "#eql?" do
47
+ it "returns true when comparing to an object of the same class and pointer" do
48
+ other = klass.wrap object.to_ptr
49
+
50
+ object.must_equal other
51
+ end
52
+
53
+ it "returns false when comparing to an object of the same class and different pointer" do
54
+ other = klass.wrap FFI::MemoryPointer.new(:int32)
55
+
56
+ object.wont_equal other
57
+ end
58
+
59
+ it "returns true when comparing to an object of a different class and same pointer" do
60
+ stub(other = Object.new).to_ptr { object.to_ptr }
61
+
62
+ object.wont_equal other
63
+ end
64
+
65
+ it "returns false when comparing to an object of a different class and different pointer" do
66
+ stub(other = Object.new).to_ptr { FFI::MemoryPointer.new(:int32) }
67
+
68
+ object.wont_equal other
69
+ end
70
+ end
13
71
  end
14
72
 
15
73
  describe "a descendant with multiple builders" do
@@ -11,7 +11,7 @@ describe GirFFI::FunctionBuilder do
11
11
  def self.test_array_fixed_out_objects
12
12
  _v1 = GirFFI::InOutPointer.for :c
13
13
  DummyLib.regress_test_array_fixed_out_objects _v1
14
- _v2 = GLib::SizedArray.wrap([:pointer, ::Regress::TestObj], 2, _v1.to_value)
14
+ _v2 = GLib::SizedArray.wrap([:pointer, Regress::TestObj], 2, _v1.to_value)
15
15
  return _v2
16
16
  end
17
17
  CODE
@@ -15,12 +15,29 @@ describe GirFFI::InPointer do
15
15
 
16
16
  it "handles enum types" do
17
17
  e = Module.new do
18
+ extend GirFFI::EnumBase
18
19
  self::Enum = FFI::Enum.new [:foo, :bar, :baz]
19
20
  end
20
21
  ptr = GirFFI::InPointer.from_array e, [:bar, :foo, :baz]
21
22
  ptr.read_array_of_int32(3).must_equal [1, 0, 2]
22
23
  end
23
24
 
25
+ it "handles struct types" do
26
+ e = Class.new do
27
+ self::Struct = Class.new(FFI::Struct) do
28
+ layout :foo, :int32, :bar, :int32
29
+ end
30
+ end
31
+ struct = e::Struct.allocate
32
+ struct[:foo] = 42
33
+ struct[:bar] = 24
34
+ ptr = GirFFI::InPointer.from_array e, [struct]
35
+ ptr.wont_equal struct.to_ptr
36
+ new_struct = e::Struct.new ptr
37
+ new_struct[:foo].must_equal 42
38
+ new_struct[:bar].must_equal 24
39
+ end
40
+
24
41
  it "handles typed pointers" do
25
42
  p1 = GirFFI::InPointer.from :gint32, 42
26
43
  p2 = GirFFI::InPointer.from :gint32, 24
@@ -0,0 +1,14 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::InfoExt::IObjectInfo do
4
+ let(:klass) { Class.new do
5
+ include GirFFI::InfoExt::IObjectInfo
6
+ end }
7
+ let(:object_info) { klass.new }
8
+
9
+ describe "#to_ffitype" do
10
+ it "returns :pointer" do
11
+ object_info.to_ffitype.must_equal :pointer
12
+ end
13
+ end
14
+ end