ffi 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

@@ -8,6 +8,6 @@ describe FFI::Struct do
8
8
  it "allows setting fields" do
9
9
  t = Timeval.new
10
10
  t[:tv_sec] = 12
11
- t[:tv_sec].should == 12
11
+ t[:tv_sec].should eq 12
12
12
  end
13
- end
13
+ end
@@ -21,7 +21,7 @@ if RUBY_PLATFORM =~/java/
21
21
  $:.reject! { |p| p == libdir }
22
22
  else
23
23
  $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib"),
24
- File.join(File.dirname(__FILE__), "..", "..", "build", "#{Config::CONFIG['host_cpu''arch']}", "ffi_c", RUBY_VERSION)
24
+ File.join(File.dirname(__FILE__), "..", "..", "build", "#{RbConfig::CONFIG['host_cpu''arch']}", "ffi_c", RUBY_VERSION)
25
25
  end
26
26
  # puts "loadpath=#{$:.join(':')}"
27
27
  require "ffi"
@@ -29,7 +29,7 @@ describe "String tests" do
29
29
  mp = FFI::MemoryPointer.new 1024
30
30
  mp.put_string(0, "test\0")
31
31
  str = mp.get_string(0)
32
- str.tainted?.should == true
32
+ str.tainted?.should eq true
33
33
  end
34
34
  it "String returned by a method is tainted" do
35
35
  mp = FFI::MemoryPointer.new :pointer
@@ -37,8 +37,8 @@ describe "String tests" do
37
37
  sp.put_string(0, "test")
38
38
  mp.put_pointer(0, sp)
39
39
  str = StrLibTest.ptr_ret_pointer(mp, 0)
40
- str.should == "test"
41
- str.tainted?.should == true
40
+ str.should eq "test"
41
+ str.tainted?.should eq true
42
42
  end
43
43
  it "Poison null byte raises error" do
44
44
  s = "123\0abc"
@@ -49,15 +49,15 @@ describe "String tests" do
49
49
  str = "test"
50
50
  str.taint
51
51
  begin
52
- LibTest.string_equals(str, str).should == false
53
- rescue SecurityError => e
52
+ LibTest.string_equals(str, str).should eq false
53
+ rescue SecurityError
54
54
  end
55
55
  end if false
56
56
  it "casts nil as NULL pointer" do
57
57
  StrLibTest.string_dummy(nil)
58
58
  end
59
59
  it "return nil for NULL char*" do
60
- StrLibTest.string_null.should == nil
60
+ StrLibTest.string_null.should eq nil
61
61
  end
62
62
  it "reads an array of strings until encountering a NULL pointer" do
63
63
  strings = ["foo", "bar", "baz", "testing", "ffi"]
@@ -69,7 +69,7 @@ describe "String tests" do
69
69
  end
70
70
  ary.insert(3, nil)
71
71
  ptrary.write_array_of_pointer(ary)
72
- ptrary.get_array_of_string(0).should == ["foo", "bar", "baz"]
72
+ ptrary.get_array_of_string(0).should eq ["foo", "bar", "baz"]
73
73
  end
74
74
  it "reads an array of strings of the size specified, substituting nil when a pointer is NULL" do
75
75
  strings = ["foo", "bar", "baz", "testing", "ffi"]
@@ -81,7 +81,7 @@ describe "String tests" do
81
81
  end
82
82
  ary.insert(2, nil)
83
83
  ptrary.write_array_of_pointer(ary)
84
- ptrary.get_array_of_string(0, 4).should == ["foo", "bar", nil, "baz"]
84
+ ptrary.get_array_of_string(0, 4).should eq ["foo", "bar", nil, "baz"]
85
85
  end
86
86
  it "reads an array of strings, taking a memory offset parameter" do
87
87
  strings = ["foo", "bar", "baz", "testing", "ffi"]
@@ -92,7 +92,7 @@ describe "String tests" do
92
92
  a << f
93
93
  end
94
94
  ptrary.write_array_of_pointer(ary)
95
- ptrary.get_array_of_string(2 * FFI.type_size(:pointer), 3).should == ["baz", "testing", "ffi"]
95
+ ptrary.get_array_of_string(2 * FFI.type_size(:pointer), 3).should eq ["baz", "testing", "ffi"]
96
96
  end
97
97
  it "raises an IndexError when trying to read an array of strings out of bounds" do
98
98
  strings = ["foo", "bar", "baz", "testing", "ffi"]
@@ -20,7 +20,7 @@ describe "functions returning :strptr" do
20
20
 
21
21
  it "can attach function with :strptr return type" do
22
22
  lambda do
23
- m = Module.new do
23
+ Module.new do
24
24
  extend FFI::Library
25
25
  ffi_lib FFI::Library::LIBC
26
26
  if !FFI::Platform.windows?
@@ -51,11 +51,11 @@ describe "functions returning :strptr" do
51
51
 
52
52
  it "should return the correct value" do
53
53
  result = StrPtr.strdup("test")
54
- result[0].should == "test"
54
+ result[0].should eq "test"
55
55
  end
56
56
 
57
57
  it "should return non-NULL pointer" do
58
58
  result = StrPtr.strdup("test")
59
59
  result[1].null?.should be_false
60
60
  end
61
- end
61
+ end
@@ -18,7 +18,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
18
18
 
19
19
  describe FFI::Struct, ' with inline callback functions' do
20
20
  it 'should be able to define inline callback field' do
21
- module CallbackMember
21
+ module CallbackMember1
22
22
  extend FFI::Library
23
23
  ffi_lib TestLibrary::PATH
24
24
  DUMMY_CB = callback :dummy_cb, [ :int ], :int
@@ -33,7 +33,7 @@ describe FFI::Struct, ' with inline callback functions' do
33
33
  end
34
34
  end
35
35
  it 'should take methods as callbacks' do
36
- module CallbackMember
36
+ module CallbackMember2
37
37
  extend FFI::Library
38
38
  ffi_lib TestLibrary::PATH
39
39
  class TestStruct < FFI::Struct
@@ -50,14 +50,14 @@ describe FFI::Struct, ' with inline callback functions' do
50
50
  end
51
51
  end
52
52
 
53
- ts = CallbackMember::TestStruct.new
53
+ ts = CallbackMember2::TestStruct.new
54
54
  ts[:add] = StructCallbacks.method(:add)
55
55
 
56
- CallbackMember.struct_call_add_cb(ts, 1, 2).should == 3
56
+ CallbackMember2.struct_call_add_cb(ts, 1, 2).should eq 3
57
57
  end
58
58
 
59
59
  it 'should return callable object from []' do
60
- module CallbackMember
60
+ module CallbackMember3
61
61
  extend FFI::Library
62
62
  ffi_lib TestLibrary::PATH
63
63
  class TestStruct < FFI::Struct
@@ -69,12 +69,12 @@ describe FFI::Struct, ' with inline callback functions' do
69
69
  attach_function :struct_call_sub_cb, [TestStruct, :int, :int], :int
70
70
  end
71
71
 
72
- s = CallbackMember::TestStruct.new
72
+ s = CallbackMember3::TestStruct.new
73
73
  add = Proc.new { |a,b| a+b}
74
74
  s[:add] = add
75
75
  fn = s[:add]
76
76
  fn.respond_to?(:call).should be_true
77
- fn.call(1, 2).should == 3
77
+ fn.call(1, 2).should eq 3
78
78
  end
79
79
  end
80
80
 
@@ -26,7 +26,7 @@ describe FFI::Struct, ' with an initialize function' do
26
26
  self.magic = 42
27
27
  end
28
28
  end
29
- StructWithInitialize.new.magic.should == 42
29
+ StructWithInitialize.new.magic.should eq 42
30
30
  end
31
31
  end
32
32
 
@@ -41,6 +41,6 @@ describe FFI::ManagedStruct, ' with an initialize function' do
41
41
  end
42
42
  def self.release;end
43
43
  end
44
- ManagedStructWithInitialize.new.magic.should == 42
44
+ ManagedStructWithInitialize.new.magic.should eq 42
45
45
  end
46
46
  end
@@ -21,42 +21,42 @@ describe FFI::Struct do
21
21
  Class.new(FFI::Struct) do
22
22
  packed
23
23
  layout :c, :char, :i, :int
24
- end.size.should == 5
24
+ end.size.should eq 5
25
25
  end
26
26
 
27
27
  it "packed :char followed by :int should have alignment of 1" do
28
28
  Class.new(FFI::Struct) do
29
29
  packed
30
30
  layout :c, :char, :i, :int
31
- end.alignment.should == 1
31
+ end.alignment.should eq 1
32
32
  end
33
33
 
34
34
  it "packed(2) :char followed by :int should have size of 6" do
35
35
  Class.new(FFI::Struct) do
36
36
  packed 2
37
37
  layout :c, :char, :i, :int
38
- end.size.should == 6
38
+ end.size.should eq 6
39
39
  end
40
40
 
41
41
  it "packed(2) :char followed by :int should have alignment of 2" do
42
42
  Class.new(FFI::Struct) do
43
43
  packed 2
44
44
  layout :c, :char, :i, :int
45
- end.alignment.should == 2
45
+ end.alignment.should eq 2
46
46
  end
47
47
 
48
48
  it "packed :short followed by int should have size of 6" do
49
49
  Class.new(FFI::Struct) do
50
50
  packed
51
51
  layout :s, :short, :i, :int
52
- end.size.should == 6
52
+ end.size.should eq 6
53
53
  end
54
54
 
55
55
  it "packed :short followed by int should have alignment of 1" do
56
56
  Class.new(FFI::Struct) do
57
57
  packed
58
58
  layout :s, :short, :i, :int
59
- end.alignment.should == 1
59
+ end.alignment.should eq 1
60
60
  end
61
61
 
62
62
  end
@@ -49,7 +49,7 @@ describe "Struct tests" do
49
49
  smp = FFI::MemoryPointer.new :pointer
50
50
  smp.put_pointer(0, mp)
51
51
  s = PointerMember.new smp
52
- s[:pointer].should == mp
52
+ s[:pointer].should eq mp
53
53
  end
54
54
  it "Struct#[:pointer].nil? for NULL value" do
55
55
  magic = 0x12345678
@@ -58,7 +58,7 @@ describe "Struct tests" do
58
58
  smp = FFI::MemoryPointer.new :pointer
59
59
  smp.put_pointer(0, nil)
60
60
  s = PointerMember.new smp
61
- s[:pointer].null?.should == true
61
+ s[:pointer].null?.should eq true
62
62
  end
63
63
  it "Struct#[:pointer]=" do
64
64
  magic = 0x12345678
@@ -67,10 +67,9 @@ describe "Struct tests" do
67
67
  smp = FFI::MemoryPointer.new :pointer
68
68
  s = PointerMember.new smp
69
69
  s[:pointer] = mp
70
- smp.get_pointer(0).should == mp
70
+ smp.get_pointer(0).should eq mp
71
71
  end
72
72
  it "Struct#[:pointer]=struct" do
73
- magic = 0x12345678
74
73
  smp = FFI::MemoryPointer.new :pointer
75
74
  s = PointerMember.new smp
76
75
  lambda { s[:pointer] = s }.should_not raise_error
@@ -79,7 +78,7 @@ describe "Struct tests" do
79
78
  smp = FFI::MemoryPointer.new :pointer
80
79
  s = PointerMember.new smp
81
80
  s[:pointer] = nil
82
- smp.get_pointer(0).null?.should == true
81
+ smp.get_pointer(0).null?.should eq true
83
82
  end
84
83
  it "Struct#[:string]" do
85
84
  magic = "test"
@@ -88,50 +87,50 @@ describe "Struct tests" do
88
87
  smp = FFI::MemoryPointer.new :pointer
89
88
  smp.put_pointer(0, mp)
90
89
  s = StringMember.new smp
91
- s[:string].should == magic
90
+ s[:string].should eq magic
92
91
  end
93
92
  it "Struct#[:string].nil? for NULL value" do
94
93
  smp = FFI::MemoryPointer.new :pointer
95
94
  smp.put_pointer(0, nil)
96
95
  s = StringMember.new smp
97
- s[:string].nil?.should == true
96
+ s[:string].nil?.should eq true
98
97
  end
99
98
  it "Struct#layout works with :name, :type pairs" do
100
99
  class PairLayout < FFI::Struct
101
100
  layout :a, :int, :b, :long_long
102
101
  end
103
102
  ll_off = (FFI::TYPE_UINT64.alignment == 4 ? 4 : 8)
104
- PairLayout.size.should == (ll_off + 8)
103
+ PairLayout.size.should eq(ll_off + 8)
105
104
  mp = FFI::MemoryPointer.new(PairLayout.size)
106
105
  s = PairLayout.new mp
107
106
  s[:a] = 0x12345678
108
- mp.get_int(0).should == 0x12345678
107
+ mp.get_int(0).should eq 0x12345678
109
108
  s[:b] = 0xfee1deadbeef
110
- mp.get_int64(ll_off).should == 0xfee1deadbeef
109
+ mp.get_int64(ll_off).should eq 0xfee1deadbeef
111
110
  end
112
111
  it "Struct#layout works with :name, :type, offset tuples" do
113
112
  class PairLayout < FFI::Struct
114
113
  layout :a, :int, 0, :b, :long_long, 4
115
114
  end
116
- PairLayout.size.should == (FFI::TYPE_UINT64.alignment == 4 ? 12 : 16)
115
+ PairLayout.size.should eq(FFI::TYPE_UINT64.alignment == 4 ? 12 : 16)
117
116
  mp = FFI::MemoryPointer.new(PairLayout.size)
118
117
  s = PairLayout.new mp
119
118
  s[:a] = 0x12345678
120
- mp.get_int(0).should == 0x12345678
119
+ mp.get_int(0).should eq 0x12345678
121
120
  s[:b] = 0xfee1deadbeef
122
- mp.get_int64(4).should == 0xfee1deadbeef
121
+ mp.get_int64(4).should eq 0xfee1deadbeef
123
122
  end
124
123
  it "Struct#layout works with mixed :name,:type and :name,:type,offset" do
125
124
  class MixedLayout < FFI::Struct
126
125
  layout :a, :int, :b, :long_long, 4
127
126
  end
128
- MixedLayout.size.should == (FFI::TYPE_UINT64.alignment == 4 ? 12 : 16)
127
+ MixedLayout.size.should eq(FFI::TYPE_UINT64.alignment == 4 ? 12 : 16)
129
128
  mp = FFI::MemoryPointer.new(MixedLayout.size)
130
129
  s = MixedLayout.new mp
131
130
  s[:a] = 0x12345678
132
- mp.get_int(0).should == 0x12345678
131
+ mp.get_int(0).should eq 0x12345678
133
132
  s[:b] = 0xfee1deadbeef
134
- mp.get_int64(4).should == 0xfee1deadbeef
133
+ mp.get_int64(4).should eq 0xfee1deadbeef
135
134
  end
136
135
  rb_maj, rb_min = RUBY_VERSION.split('.')
137
136
  if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/
@@ -140,13 +139,13 @@ describe "Struct tests" do
140
139
  layout :a => :int, :b => :long_long
141
140
  end
142
141
  ll_off = (FFI::TYPE_UINT64.alignment == 4? 4 : 8)
143
- HashLayout.size.should == (ll_off + 8)
142
+ HashLayout.size.should eq(ll_off + 8)
144
143
  mp = FFI::MemoryPointer.new(HashLayout.size)
145
144
  s = HashLayout.new mp
146
145
  s[:a] = 0x12345678
147
- mp.get_int(0).should == 0x12345678
146
+ mp.get_int(0).should eq 0x12345678
148
147
  s[:b] = 0xfee1deadbeef
149
- mp.get_int64(ll_off).should == 0xfee1deadbeef
148
+ mp.get_int64(ll_off).should eq 0xfee1deadbeef
150
149
  end
151
150
  end
152
151
 
@@ -163,8 +162,8 @@ describe "Struct tests" do
163
162
 
164
163
  end
165
164
  s = InitializeWithoutSuper.new(0x1eefbeef, 0xdeadcafebabe)
166
- s[:a].should == 0x1eefbeef
167
- s[:b].should == 0xdeadcafebabe
165
+ s[:a].should eq 0x1eefbeef
166
+ s[:b].should eq 0xdeadcafebabe
168
167
  end
169
168
 
170
169
  it "Can use Struct subclass as parameter type" do
@@ -178,7 +177,7 @@ describe "Struct tests" do
178
177
  end
179
178
  end
180
179
  it "Can use Struct subclass as IN parameter type" do
181
- module StructParam
180
+ module StructParam2
182
181
  extend FFI::Library
183
182
  ffi_lib TestLibrary::PATH
184
183
  class TestStruct < FFI::Struct
@@ -188,7 +187,7 @@ describe "Struct tests" do
188
187
  end
189
188
  end
190
189
  it "Can use Struct subclass as OUT parameter type" do
191
- module StructParam
190
+ module StructParam3
192
191
  extend FFI::Library
193
192
  ffi_lib TestLibrary::PATH
194
193
  class TestStruct < FFI::Struct
@@ -203,7 +202,7 @@ describe "Struct tests" do
203
202
  end
204
203
  s = TestStruct.new
205
204
  s[:i] = 0x12
206
- LibTest.ptr_ret_int32_t(s, 0).should == 0x12
205
+ LibTest.ptr_ret_int32_t(s, 0).should eq 0x12
207
206
  end
208
207
  it ":char member aligned correctly" do
209
208
  class AlignChar < FFI::Struct
@@ -211,7 +210,7 @@ describe "Struct tests" do
211
210
  end
212
211
  s = AlignChar.new
213
212
  s[:v] = 0x12
214
- LibTest.struct_align_s8(s.pointer).should == 0x12
213
+ LibTest.struct_align_s8(s.pointer).should eq 0x12
215
214
  end
216
215
  it ":short member aligned correctly" do
217
216
  class AlignShort < FFI::Struct
@@ -219,7 +218,7 @@ describe "Struct tests" do
219
218
  end
220
219
  s = AlignShort.alloc_in
221
220
  s[:v] = 0x1234
222
- LibTest.struct_align_s16(s.pointer).should == 0x1234
221
+ LibTest.struct_align_s16(s.pointer).should eq 0x1234
223
222
  end
224
223
  it ":int member aligned correctly" do
225
224
  class AlignInt < FFI::Struct
@@ -227,7 +226,7 @@ describe "Struct tests" do
227
226
  end
228
227
  s = AlignInt.alloc_in
229
228
  s[:v] = 0x12345678
230
- LibTest.struct_align_s32(s.pointer).should == 0x12345678
229
+ LibTest.struct_align_s32(s.pointer).should eq 0x12345678
231
230
  end
232
231
  it ":long_long member aligned correctly" do
233
232
  class AlignLongLong < FFI::Struct
@@ -235,7 +234,7 @@ describe "Struct tests" do
235
234
  end
236
235
  s = AlignLongLong.alloc_in
237
236
  s[:v] = 0x123456789abcdef0
238
- LibTest.struct_align_s64(s.pointer).should == 0x123456789abcdef0
237
+ LibTest.struct_align_s64(s.pointer).should eq 0x123456789abcdef0
239
238
  end
240
239
  it ":long member aligned correctly" do
241
240
  class AlignLong < FFI::Struct
@@ -243,7 +242,7 @@ describe "Struct tests" do
243
242
  end
244
243
  s = AlignLong.alloc_in
245
244
  s[:v] = 0x12345678
246
- LibTest.struct_align_long(s.pointer).should == 0x12345678
245
+ LibTest.struct_align_long(s.pointer).should eq 0x12345678
247
246
  end
248
247
  it ":float member aligned correctly" do
249
248
  class AlignFloat < FFI::Struct
@@ -268,7 +267,7 @@ describe "Struct tests" do
268
267
  s = ULPStruct.alloc_in
269
268
  s[:ul] = 0xdeadbeef
270
269
  s[:p] = LibTest.ptr_from_address(0x12345678)
271
- s.pointer.get_ulong(0).should == 0xdeadbeef
270
+ s.pointer.get_ulong(0).should eq 0xdeadbeef
272
271
  end
273
272
  def test_num_field(type, v)
274
273
  klass = Class.new(FFI::Struct)
@@ -276,9 +275,9 @@ describe "Struct tests" do
276
275
 
277
276
  s = klass.new
278
277
  s[:v] = v
279
- s.pointer.send("get_#{type.to_s}", 0).should == v
278
+ s.pointer.send("get_#{type.to_s}", 0).should eq v
280
279
  s.pointer.send("put_#{type.to_s}", 0, 0)
281
- s[:v].should == 0
280
+ s[:v].should eq 0
282
281
  end
283
282
  def self.int_field_test(type, values)
284
283
  values.each do |v|
@@ -333,8 +332,8 @@ describe "Struct tests" do
333
332
  s = EnumFields::TestStruct.new
334
333
  s[:c] = :c3
335
334
 
336
- s.pointer.get_uint(FFI::Type::INT32.size).should == 30
337
- s[:c].should == :c3
335
+ s.pointer.get_uint(FFI::Type::INT32.size).should eq 30
336
+ s[:c].should eq :c3
338
337
  end
339
338
 
340
339
  it "array of :enum field" do
@@ -344,11 +343,11 @@ describe "Struct tests" do
344
343
  end
345
344
 
346
345
  EnumFields::TestEnum.symbols.each_with_index do |val, i|
347
- s.pointer.get_uint(FFI::Type::INT32.size * (2 + i)).should == EnumFields::TestEnum[val]
346
+ s.pointer.get_uint(FFI::Type::INT32.size * (2 + i)).should eq EnumFields::TestEnum[val]
348
347
  end
349
348
 
350
349
  s[:d].each_with_index do |val, i|
351
- val.should == EnumFields::TestEnum.symbols[i]
350
+ val.should eq EnumFields::TestEnum.symbols[i]
352
351
  end
353
352
  end
354
353
 
@@ -370,8 +369,8 @@ describe "Struct tests" do
370
369
  sub_proc = lambda { |a, b| a-b }
371
370
  s[:add] = add_proc
372
371
  s[:sub] = sub_proc
373
- CallbackMember.struct_call_add_cb(s, 40, 2).should == 42
374
- CallbackMember.struct_call_sub_cb(s, 44, 2).should == 42
372
+ CallbackMember.struct_call_add_cb(s, 40, 2).should eq 42
373
+ CallbackMember.struct_call_sub_cb(s, 44, 2).should eq 42
375
374
  end
376
375
  it "Can return its members as a list" do
377
376
  class TestStruct < FFI::Struct
@@ -395,16 +394,16 @@ describe "Struct tests" do
395
394
  layout :a, :int, :b, :int, :c, :int
396
395
  end
397
396
  s = TestStruct.new
398
- s.offsets.should == [[:a, 0], [:b, 4], [:c, 8]]
399
- TestStruct.offsets.should == [[:a, 0], [:b, 4], [:c, 8]]
397
+ s.offsets.should eq [[:a, 0], [:b, 4], [:c, 8]]
398
+ TestStruct.offsets.should eq [[:a, 0], [:b, 4], [:c, 8]]
400
399
  end
401
400
  it "Struct#offset_of returns offset of field within struct" do
402
401
  class TestStruct < FFI::Struct
403
402
  layout :a, :int, :b, :int, :c, :int
404
403
  end
405
- TestStruct.offset_of(:a).should == 0
406
- TestStruct.offset_of(:b).should == 4
407
- TestStruct.offset_of(:c).should == 8
404
+ TestStruct.offset_of(:a).should eq 0
405
+ TestStruct.offset_of(:b).should eq 4
406
+ TestStruct.offset_of(:c).should eq 8
408
407
  end
409
408
  end
410
409
 
@@ -426,22 +425,22 @@ describe FFI::Struct, ' with a nested struct field' do
426
425
  end
427
426
  it 'should align correctly nested struct field' do
428
427
  @cs[:ns][:i] = 123
429
- LibTest.struct_align_nested_struct(@cs.to_ptr).should == 123
428
+ LibTest.struct_align_nested_struct(@cs.to_ptr).should eq 123
430
429
  end
431
430
  it 'should correctly calculate Container size (in bytes)' do
432
- LibTest::ContainerStruct.size.should == 8
431
+ LibTest::ContainerStruct.size.should eq 8
433
432
  end
434
433
  it 'should return a Struct object when the field is accessed' do
435
434
  @cs[:ns].is_a?(FFI::Struct).should be_true
436
435
  end
437
436
  it 'should read a value from memory' do
438
437
  @cs = LibTest::ContainerStruct.new(LibTest.struct_make_container_struct(123))
439
- @cs[:ns][:i].should == 123
438
+ @cs[:ns][:i].should eq 123
440
439
  end
441
440
  it 'should write a value to memory' do
442
441
  @cs = LibTest::ContainerStruct.new(LibTest.struct_make_container_struct(123))
443
442
  @cs[:ns][:i] = 456
444
- LibTest.struct_align_nested_struct(@cs.to_ptr).should == 456
443
+ LibTest.struct_align_nested_struct(@cs.to_ptr).should eq 456
445
444
  end
446
445
  end
447
446
 
@@ -465,11 +464,11 @@ describe FFI::Struct, ' with a nested array of structs' do
465
464
 
466
465
  it 'should align correctly nested struct field' do
467
466
  @cs[:ns][0][:i] = 123
468
- InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should == 123
467
+ InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should eq 123
469
468
  end
470
469
 
471
470
  it 'should correctly calculate Container size (in bytes)' do
472
- InlineArrayOfStructs::ContainerStruct.size.should == 8
471
+ InlineArrayOfStructs::ContainerStruct.size.should eq 8
473
472
  end
474
473
 
475
474
  it 'should return a Struct object when the field is accessed' do
@@ -478,20 +477,20 @@ describe FFI::Struct, ' with a nested array of structs' do
478
477
 
479
478
  it 'should read a value from memory' do
480
479
  @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123))
481
- @cs[:ns][0][:i].should == 123
480
+ @cs[:ns][0][:i].should eq 123
482
481
  end
483
482
 
484
483
  it 'should write a value to memory' do
485
484
  @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123))
486
485
  @cs[:ns][0][:i] = 456
487
- InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should == 456
486
+ InlineArrayOfStructs.struct_align_nested_struct(@cs.to_ptr).should eq 456
488
487
  end
489
488
 
490
489
  it 'should support Enumerable#each' do
491
490
  @cs = InlineArrayOfStructs::ContainerStruct.new(InlineArrayOfStructs.struct_make_container_struct(123))
492
491
  ints = []
493
492
  @cs[:ns].each { |s| ints << s[:i] }
494
- ints[0].should == 123
493
+ ints[0].should eq 123
495
494
  end
496
495
  end
497
496
 
@@ -519,22 +518,22 @@ describe FFI::Struct, ' by value' do
519
518
 
520
519
  it 'return using pre-set values' do
521
520
  s = LibTest.struct_return_s8s32
522
- s[:s8].should == 0x7f
523
- s[:s32].should == 0x12345678
521
+ s[:s8].should eq 0x7f
522
+ s[:s32].should eq 0x12345678
524
523
  end
525
524
 
526
525
  it 'return using passed in values' do
527
526
  s = LibTest.struct_s8s32_set(123, 456789)
528
- s[:s8].should == 123
529
- s[:s32].should == 456789
527
+ s[:s8].should eq 123
528
+ s[:s32].should eq 456789
530
529
  end
531
530
 
532
531
  it 'parameter' do
533
532
  s = LibTest::S8S32.new
534
533
  s[:s8] = 0x12
535
534
  s[:s32] = 0x34567890
536
- LibTest.struct_s8s32_get_s8(s).should == 0x12
537
- LibTest.struct_s8s32_get_s32(s).should == 0x34567890
535
+ LibTest.struct_s8s32_get_s8(s).should eq 0x12
536
+ LibTest.struct_s8s32_get_s32(s).should eq 0x34567890
538
537
  end
539
538
 
540
539
  it 'parameter with following s32' do
@@ -542,7 +541,7 @@ describe FFI::Struct, ' by value' do
542
541
  s[:s8] = 0x12
543
542
  s[:s32] = 0x34567890
544
543
 
545
- LibTest.struct_s8s32_s32_ret_s32(s, 0x1eefdead).should == 0x1eefdead
544
+ LibTest.struct_s8s32_s32_ret_s32(s, 0x1eefdead).should eq 0x1eefdead
546
545
  end
547
546
 
548
547
  it 'parameter with following s64' do
@@ -550,14 +549,14 @@ describe FFI::Struct, ' by value' do
550
549
  s[:s8] = 0x12
551
550
  s[:s32] = 0x34567890
552
551
 
553
- LibTest.struct_s8s32_s64_ret_s64(s, 0xdeadcafebabe).should == 0xdeadcafebabe
552
+ LibTest.struct_s8s32_s64_ret_s64(s, 0xdeadcafebabe).should eq 0xdeadcafebabe
554
553
  end
555
554
 
556
555
  it 'varargs returning a struct' do
557
556
  string = "test"
558
557
  s = LibTest.struct_varargs_ret_struct_string(4, :string, string)
559
- s[:len].should == string.length
560
- s[:bytes].should == string
558
+ s[:len].should eq string.length
559
+ s[:bytes].should eq string
561
560
  end
562
561
  end
563
562
 
@@ -575,26 +574,26 @@ describe FFI::Struct, ' with an array field' do
575
574
  @s = LibTest::StructWithArray.new
576
575
  end
577
576
  it 'should correctly calculate StructWithArray size (in bytes)' do
578
- LibTest::StructWithArray.size.should == 24
577
+ LibTest::StructWithArray.size.should eq 24
579
578
  end
580
579
  it 'should read values from memory' do
581
580
  @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4))
582
- @s[:a].to_a.should == [0, 1, 2, 3, 4]
581
+ @s[:a].to_a.should eq [0, 1, 2, 3, 4]
583
582
  end
584
583
  # it 'should cache array object for successive calls' do
585
- # @s[:a].object_id.should == @s[:a].object_id
584
+ # @s[:a].object_id.should eq @s[:a].object_id
586
585
  # end
587
586
  it 'should return the number of elements in the array field' do
588
587
  @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4))
589
- @s[:a].size.should == 5
588
+ @s[:a].size.should eq 5
590
589
  end
591
590
  it 'should allow iteration through the array elements' do
592
591
  @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4))
593
- @s[:a].each_with_index { |elem, i| elem.should == i }
592
+ @s[:a].each_with_index { |elem, i| elem.should eq i }
594
593
  end
595
594
  it 'should return the pointer to the array' do
596
595
  @s = LibTest::StructWithArray.new(LibTest.struct_make_struct_with_array(0, 1, 2, 3, 4))
597
- @s[:a].to_ptr.should == LibTest::struct_field_array(@s.to_ptr)
596
+ @s[:a].to_ptr.should eq LibTest::struct_field_array(@s.to_ptr)
598
597
  end
599
598
  end
600
599
 
@@ -614,21 +613,21 @@ describe 'BuggedStruct' do
614
613
  attach_function :bugged_struct_size, [], :uint
615
614
  end
616
615
  it 'should return its correct size' do
617
- LibTest::BuggedStruct.size.should == LibTest.bugged_struct_size
616
+ LibTest::BuggedStruct.size.should eq LibTest.bugged_struct_size
618
617
  end
619
618
  it "offsets within struct should be correct" do
620
- LibTest::BuggedStruct.offset_of(:visible).should == 0
621
- LibTest::BuggedStruct.offset_of(:x).should == 4
622
- LibTest::BuggedStruct.offset_of(:y).should == 8
623
- LibTest::BuggedStruct.offset_of(:rx).should == 12
624
- LibTest::BuggedStruct.offset_of(:ry).should == 14
625
- LibTest::BuggedStruct.offset_of(:order).should == 16
626
- LibTest::BuggedStruct.offset_of(:size).should == 17
619
+ LibTest::BuggedStruct.offset_of(:visible).should eq 0
620
+ LibTest::BuggedStruct.offset_of(:x).should eq 4
621
+ LibTest::BuggedStruct.offset_of(:y).should eq 8
622
+ LibTest::BuggedStruct.offset_of(:rx).should eq 12
623
+ LibTest::BuggedStruct.offset_of(:ry).should eq 14
624
+ LibTest::BuggedStruct.offset_of(:order).should eq 16
625
+ LibTest::BuggedStruct.offset_of(:size).should eq 17
627
626
  end
628
627
  it 'should return correct field/offset pairs' do
629
628
  LibTest::BuggedStruct.offsets.sort do |a, b|
630
629
  a[1] <=> b[1]
631
- end.should == [[:visible, 0], [:x, 4], [:y, 8], [:rx, 12], [:ry, 14], [:order, 16], [:size, 17]]
630
+ end.should eq [[:visible, 0], [:x, 4], [:y, 8], [:rx, 12], [:ry, 14], [:order, 16], [:size, 17]]
632
631
  end
633
632
  end
634
633
 
@@ -638,11 +637,11 @@ describe "Struct allocation" do
638
637
  layout :i, :uint
639
638
  end
640
639
  p = FFI::MemoryPointer.new(S, 2)
641
- p.total.should == 8
642
- p.type_size.should == 4
640
+ p.total.should eq 8
641
+ p.type_size.should eq 4
643
642
  p.put_uint(4, 0xdeadbeef)
644
- S.new(p[1])[:i].should == 0xdeadbeef
645
- p[1].address.should == (p[0].address + 4)
643
+ S.new(p[1])[:i].should eq 0xdeadbeef
644
+ p[1].address.should eq(p[0].address + 4)
646
645
  end
647
646
 
648
647
  it "Buffer.new(Struct, 2)" do
@@ -650,10 +649,10 @@ describe "Struct allocation" do
650
649
  layout :i, :uint
651
650
  end
652
651
  p = FFI::Buffer.new(S, 2)
653
- p.total.should == 8
654
- p.type_size.should == 4
652
+ p.total.should eq 8
653
+ p.type_size.should eq 4
655
654
  p.put_uint(4, 0xdeadbeef)
656
- S.new(p[1])[:i].should == 0xdeadbeef
655
+ S.new(p[1])[:i].should eq 0xdeadbeef
657
656
  end
658
657
 
659
658
  it "null? should be true when initialized with NULL pointer" do
@@ -675,7 +674,8 @@ describe "Struct allocation" do
675
674
  c = Class.new(FFI::Struct) do
676
675
  layout :b, :bool
677
676
  end
678
- c.new
677
+ struct = c.new
678
+ struct[:b] = ! struct[:b]
679
679
  end.should_not raise_error
680
680
  end
681
681