ffi 1.9.5-x64-mingw32 → 1.9.6-x64-mingw32

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.

Files changed (44) hide show
  1. checksums.yaml +15 -7
  2. data/Rakefile +13 -6
  3. data/ext/ffi_c/extconf.rb +2 -2
  4. data/lib/2.0/ffi_c.so +0 -0
  5. data/lib/2.1/ffi_c.so +0 -0
  6. data/lib/ffi.rb +2 -0
  7. data/lib/ffi/version.rb +1 -1
  8. data/spec/ffi/async_callback_spec.rb +4 -5
  9. data/spec/ffi/bool_spec.rb +9 -8
  10. data/spec/ffi/buffer_spec.rb +64 -37
  11. data/spec/ffi/callback_spec.rb +195 -116
  12. data/spec/ffi/custom_param_type.rb +1 -1
  13. data/spec/ffi/custom_type_spec.rb +5 -6
  14. data/spec/ffi/dup_spec.rb +6 -8
  15. data/spec/ffi/enum_spec.rb +135 -129
  16. data/spec/ffi/errno_spec.rb +2 -2
  17. data/spec/ffi/ffi.log +5833 -0
  18. data/spec/ffi/ffi_spec.rb +4 -6
  19. data/spec/ffi/function_spec.rb +22 -11
  20. data/spec/ffi/io_spec.rb +0 -1
  21. data/spec/ffi/library_spec.rb +71 -36
  22. data/spec/ffi/long_double.rb +3 -4
  23. data/spec/ffi/managed_struct_spec.rb +14 -4
  24. data/spec/ffi/memorypointer_spec.rb +7 -1
  25. data/spec/ffi/number_spec.rb +43 -34
  26. data/spec/ffi/platform_spec.rb +76 -59
  27. data/spec/ffi/pointer_spec.rb +35 -31
  28. data/spec/ffi/rbx/attach_function_spec.rb +3 -4
  29. data/spec/ffi/rbx/memory_pointer_spec.rb +24 -22
  30. data/spec/ffi/rbx/spec_helper.rb +0 -1
  31. data/spec/ffi/rbx/struct_spec.rb +1 -2
  32. data/spec/ffi/spec_helper.rb +5 -2
  33. data/spec/ffi/string_spec.rb +22 -14
  34. data/spec/ffi/strptr_spec.rb +6 -7
  35. data/spec/ffi/struct_by_ref_spec.rb +4 -5
  36. data/spec/ffi/struct_by_ref_spec.rb.orig +43 -0
  37. data/spec/ffi/struct_callback_spec.rb +6 -7
  38. data/spec/ffi/struct_initialize_spec.rb +2 -3
  39. data/spec/ffi/struct_packed_spec.rb +12 -14
  40. data/spec/ffi/struct_spec.rb +203 -129
  41. data/spec/ffi/typedef_spec.rb +11 -10
  42. data/spec/ffi/union_spec.rb +8 -7
  43. data/spec/ffi/variadic_spec.rb +13 -10
  44. metadata +148 -137
@@ -4,7 +4,6 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- require 'ffi'
8
7
 
9
8
  MemoryPointer = FFI::MemoryPointer
10
9
 
@@ -12,15 +11,19 @@ describe "MemoryPointer#total" do
12
11
  it "MemoryPointer.new(:char, 1).total == 1" do
13
12
  expect(MemoryPointer.new(:char, 1).total).to eq 1
14
13
  end
14
+
15
15
  it "MemoryPointer.new(:short, 1).total == 2" do
16
16
  expect(MemoryPointer.new(:short, 1).total).to eq 2
17
17
  end
18
+
18
19
  it "MemoryPointer.new(:int, 1).total == 4" do
19
20
  expect(MemoryPointer.new(:int, 1).total).to eq 4
20
21
  end
22
+
21
23
  it "MemoryPointer.new(:long_long, 1).total == 8" do
22
24
  expect(MemoryPointer.new(:long_long, 1).total).to eq 8
23
25
  end
26
+
24
27
  it "MemoryPointer.new(1024).total == 1024" do
25
28
  expect(MemoryPointer.new(1024).total).to eq 1024
26
29
  end
@@ -42,11 +45,13 @@ describe "MemoryPointer argument" do
42
45
  attach_function :memset, [ :pointer, :int, :ulong ], :pointer
43
46
  attach_function :memcpy, [ :pointer, :pointer, :ulong ], :pointer
44
47
  end
48
+
45
49
  it "Pointer passed correctly" do
46
50
  p = MemoryPointer.new :int, 1
47
51
  ret = Ptr.memset(p, 0, p.total)
48
52
  expect(ret).to eq p
49
53
  end
54
+
50
55
  it "Data passed to native function" do
51
56
  p = MemoryPointer.new :int, 1
52
57
  p2 = MemoryPointer.new :int, 1
@@ -64,6 +69,7 @@ describe "MemoryPointer return value" do
64
69
  attach_function :fclose, [ :pointer ], :int
65
70
  attach_function :fwrite, [ :pointer, :ulong, :ulong, :string ], :ulong
66
71
  end
72
+
67
73
  it "fopen returns non-nil" do
68
74
  fp = Stdio.fopen("/dev/null", "w")
69
75
  expect(fp).to_not be_nil
@@ -4,7 +4,6 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- require 'ffi'
8
7
 
9
8
  describe "Function with primitive integer arguments" do
10
9
  module LibTest
@@ -27,108 +26,118 @@ describe "Function with primitive integer arguments" do
27
26
  attach_function :set_double, [ :double ], :void
28
27
  attach_function :get_double, [ ], :double
29
28
  end
29
+
30
30
  it "int8.size" do
31
- FFI::TYPE_INT8.size.should == 1
31
+ expect(FFI::TYPE_INT8.size).to eq(1)
32
32
  end
33
+
33
34
  it "uint8.size" do
34
- FFI::TYPE_UINT8.size.should == 1
35
+ expect(FFI::TYPE_UINT8.size).to eq(1)
35
36
  end
37
+
36
38
  it "int16.size" do
37
- FFI::TYPE_INT16.size.should == 2
39
+ expect(FFI::TYPE_INT16.size).to eq(2)
38
40
  end
41
+
39
42
  it "uint16.size" do
40
- FFI::TYPE_UINT16.size.should == 2
43
+ expect(FFI::TYPE_UINT16.size).to eq(2)
41
44
  end
45
+
42
46
  it "int32.size" do
43
- FFI::TYPE_INT32.size.should == 4
47
+ expect(FFI::TYPE_INT32.size).to eq(4)
44
48
  end
49
+
45
50
  it "uint32.size" do
46
- FFI::TYPE_UINT32.size.should == 4
51
+ expect(FFI::TYPE_UINT32.size).to eq(4)
47
52
  end
53
+
48
54
  it "int64.size" do
49
- FFI::TYPE_INT64.size.should == 8
55
+ expect(FFI::TYPE_INT64.size).to eq(8)
50
56
  end
57
+
51
58
  it "uint64.size" do
52
- FFI::TYPE_UINT64.size.should == 8
59
+ expect(FFI::TYPE_UINT64.size).to eq(8)
53
60
  end
61
+
54
62
  it "float.size" do
55
- FFI::TYPE_FLOAT32.size.should == 4
63
+ expect(FFI::TYPE_FLOAT32.size).to eq(4)
56
64
  end
65
+
57
66
  it "double.size" do
58
- FFI::TYPE_FLOAT64.size.should == 8
67
+ expect(FFI::TYPE_FLOAT64.size).to eq(8)
59
68
  end
60
69
  [ 0, 127, -128, -1 ].each do |i|
61
70
  it ":char call(:char (#{i}))" do
62
- LibTest.ret_s8(i).should == i
71
+ expect(LibTest.ret_s8(i)).to eq(i)
63
72
  end
64
73
  end
65
74
  [ 0, 0x7f, 0x80, 0xff ].each do |i|
66
75
  it ":uchar call(:uchar (#{i}))" do
67
- LibTest.ret_u8(i).should == i
76
+ expect(LibTest.ret_u8(i)).to eq(i)
68
77
  end
69
78
  end
70
79
  [ 0, 0x7fff, -0x8000, -1 ].each do |i|
71
80
  it ":short call(:short (#{i}))" do
72
- LibTest.ret_s16(i).should == i
81
+ expect(LibTest.ret_s16(i)).to eq(i)
73
82
  end
74
83
  end
75
84
  [ 0, 0x7fff, 0x8000, 0xffff ].each do |i|
76
85
  it ":ushort call(:ushort (#{i}))" do
77
- LibTest.ret_u16(i).should == i
86
+ expect(LibTest.ret_u16(i)).to eq(i)
78
87
  end
79
88
  end
80
89
  [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
81
90
  it ":int call(:int (#{i}))" do
82
- LibTest.ret_s32(i).should == i
91
+ expect(LibTest.ret_s32(i)).to eq(i)
83
92
  end
84
93
  end
85
94
  [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
86
95
  it ":uint call(:uint (#{i}))" do
87
- LibTest.ret_u32(i).should == i
96
+ expect(LibTest.ret_u32(i)).to eq(i)
88
97
  end
89
98
  end
90
99
  [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
91
100
  it ":long_long call(:long_long (#{i}))" do
92
- LibTest.ret_s64(i).should == i
101
+ expect(LibTest.ret_s64(i)).to eq(i)
93
102
  end
94
103
  end
95
104
  [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
96
105
  it ":ulong_long call(:ulong_long (#{i}))" do
97
- LibTest.ret_u64(i).should == i
106
+ expect(LibTest.ret_u64(i)).to eq(i)
98
107
  end
99
108
  end
100
109
  if FFI::Platform::LONG_SIZE == 32
101
110
  [ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
102
111
  it ":long call(:long (#{i}))" do
103
- LibTest.ret_long(i).should == i
112
+ expect(LibTest.ret_long(i)).to eq(i)
104
113
  end
105
114
  end
106
115
  [ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
107
116
  it ":ulong call(:ulong (#{i}))" do
108
- LibTest.ret_ulong(i).should == i
117
+ expect(LibTest.ret_ulong(i)).to eq(i)
109
118
  end
110
119
  end
111
120
  else
112
121
  [ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
113
122
  it ":long call(:long (#{i}))" do
114
- LibTest.ret_long(i).should == i
123
+ expect(LibTest.ret_long(i)).to eq(i)
115
124
  end
116
125
  end
117
126
  [ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
118
127
  it ":ulong call(:ulong (#{i}))" do
119
- LibTest.ret_ulong(i).should == i
128
+ expect(LibTest.ret_ulong(i)).to eq(i)
120
129
  end
121
130
  end
122
131
  [ 0.0, 0.1, 1.1, 1.23 ].each do |f|
123
132
  it ":float call(:double (#{f}))" do
124
133
  LibTest.set_float(f)
125
- (LibTest.get_float - f).abs.should < 0.001
134
+ expect((LibTest.get_float - f).abs).to be < 0.001
126
135
  end
127
136
  end
128
137
  [ 0.0, 0.1, 1.1, 1.23 ].each do |f|
129
138
  it ":double call(:double (#{f}))" do
130
139
  LibTest.set_double(f)
131
- (LibTest.get_double - f).abs.should < 0.001
140
+ expect((LibTest.get_double - f).abs).to be < 0.001
132
141
  end
133
142
  end
134
143
  end
@@ -136,32 +145,32 @@ end
136
145
  describe "Integer parameter range checking" do
137
146
  [ 128, -129 ].each do |i|
138
147
  it ":char call(:char (#{i}))" do
139
- lambda { LibTest.ret_int8_t(i).should == i }.should raise_error
148
+ expect { expect(LibTest.ret_int8_t(i)).to eq(i) }.to raise_error
140
149
  end
141
150
  end
142
151
  [ -1, 256 ].each do |i|
143
152
  it ":uchar call(:uchar (#{i}))" do
144
- lambda { LibTest.ret_u_int8_t(i).should == i }.should raise_error
153
+ expect { expect(LibTest.ret_u_int8_t(i)).to eq(i) }.to raise_error
145
154
  end
146
155
  end
147
156
  [ 0x8000, -0x8001 ].each do |i|
148
157
  it ":short call(:short (#{i}))" do
149
- lambda { LibTest.ret_int16_t(i).should == i }.should raise_error
158
+ expect { expect(LibTest.ret_int16_t(i)).to eq(i) }.to raise_error
150
159
  end
151
160
  end
152
161
  [ -1, 0x10000 ].each do |i|
153
162
  it ":ushort call(:ushort (#{i}))" do
154
- lambda { LibTest.ret_u_int16_t(i).should == i }.should raise_error
163
+ expect { expect(LibTest.ret_u_int16_t(i)).to eq(i) }.to raise_error
155
164
  end
156
165
  end
157
166
  [ 0x80000000, -0x80000001 ].each do |i|
158
167
  it ":int call(:int (#{i}))" do
159
- lambda { LibTest.ret_int32_t(i).should == i }.should raise_error
168
+ expect { expect(LibTest.ret_int32_t(i)).to eq(i) }.to raise_error
160
169
  end
161
170
  end
162
171
  [ -1, 0x100000000 ].each do |i|
163
172
  it ":ushort call(:ushort (#{i}))" do
164
- lambda { LibTest.ret_u_int32_t(i).should == i }.should raise_error
173
+ expect { expect(LibTest.ret_u_int32_t(i)).to eq(i) }.to raise_error
165
174
  end
166
175
  end
167
176
  end
@@ -208,11 +217,11 @@ describe "Three different size Integer arguments" do
208
217
 
209
218
  def verify(p, off, t, v)
210
219
  if t == 'f32'
211
- p.get_float32(off).should == v
220
+ expect(p.get_float32(off)).to eq(v)
212
221
  elsif t == 'f64'
213
- p.get_float64(off).should == v
222
+ expect(p.get_float64(off)).to eq(v)
214
223
  else
215
- p.get_int64(off).should == v
224
+ expect(p.get_int64(off)).to eq(v)
216
225
  end
217
226
  end
218
227
 
@@ -4,94 +4,111 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- require 'ffi'
8
7
 
9
8
  describe "FFI::Platform::LIBSUFFIX" do
10
- it "returns 'so'", if: RbConfig::CONFIG['host_os'].match('linux') do
11
- FFI::Platform::LIBSUFFIX.should == 'so'
12
- end
13
-
14
- it "returns 'dll'", if: RbConfig::CONFIG['host_os'].match('windows') do
15
- FFI::Platform::LIBSUFFIX.should == 'dll'
16
- end
17
-
18
- it "returns 'dylib'", if: RbConfig::CONFIG['host_os'].match('darwin') do
19
- FFI::Platform::LIBSUFFIX.should == 'dylib'
9
+ case OS
10
+ when "linux"
11
+ it "returns 'so'" do
12
+ expect(FFI::Platform::LIBSUFFIX).to eq('so')
13
+ end
14
+ when "windows"
15
+ it "returns 'dll'" do
16
+ expect(FFI::Platform::LIBSUFFIX).to eq('dll')
17
+ end
18
+ when "darwin"
19
+ it "returns 'dylib'" do
20
+ expect(FFI::Platform::LIBSUFFIX).to eq('dylib')
21
+ end
20
22
  end
21
23
  end
22
24
 
23
25
  describe "FFI::Platform::IS_WINDOWS" do
24
- it "returns false", if: RbConfig::CONFIG['host_os'].match('linux') do
25
- FFI::Platform::IS_WINDOWS.should == false
26
- end
27
-
28
- it "returns true", if: RbConfig::CONFIG['host_os'].match('windows') do
29
- FFI::Platform::IS_WINDOWS.should == true
30
- end
31
-
32
- it "returns false", if: RbConfig::CONFIG['host_os'].match('darwin') do
33
- FFI::Platform::IS_WINDOWS.should == false
26
+ case OS
27
+ when "linux"
28
+ it "returns false" do
29
+ expect(FFI::Platform::IS_WINDOWS).to be false
30
+ end
31
+ when "windows"
32
+ it "returns true" do
33
+ expect(FFI::Platform::IS_WINDOWS).to be true
34
+ end
35
+ when "darwin"
36
+ it "returns false" do
37
+ expect(FFI::Platform::IS_WINDOWS).to be false
38
+ end
34
39
  end
35
40
  end
36
41
 
37
42
  describe "FFI::Platform::ARCH" do
38
43
  it "returns the architecture type" do
39
- FFI::Platform::ARCH.should == RbConfig::CONFIG["target_cpu"]
44
+ expect(FFI::Platform::ARCH).to eq(CPU)
40
45
  end
41
46
  end
42
47
 
43
48
  describe "FFI::Platform::OS" do
44
- it "returns 'linux' as a string", if: RbConfig::CONFIG['host_os'].match('linux') do
45
- FFI::Platform::OS.should == 'linux'
46
- end
47
-
48
- it "returns 'windows' as a string", if: RbConfig::CONFIG['host_os'].match('windows') do
49
- FFI::Platform::OS.should == 'windows'
50
- end
51
-
52
- it "returns 'darwin' as a string", if: RbConfig::CONFIG['host_os'].match('darwin') do
53
- FFI::Platform::OS.should == 'darwin'
49
+ case OS
50
+ when "linux"
51
+ it "returns 'linux' as a string" do
52
+ expect(FFI::Platform::OS).to eq('linux')
53
+ end
54
+ when "windows"
55
+ it "returns 'windows' as a string" do
56
+ expect(FFI::Platform::OS).to eq('windows')
57
+ end
58
+ when "darwin"
59
+ it "returns 'darwin' as a string" do
60
+ expect(FFI::Platform::OS).to eq('darwin')
61
+ end
54
62
  end
63
+ end
55
64
 
56
- describe "FFI::Platform.windows?" do
57
- it "returns false", if: RbConfig::CONFIG['host_os'].match('linux') do
58
- FFI::Platform.windows?.should == false
65
+ describe "FFI::Platform.windows?" do
66
+ case OS
67
+ when "linux"
68
+ it "returns false" do
69
+ expect(FFI::Platform.windows?).to be false
59
70
  end
60
-
61
- it "returns true", if: RbConfig::CONFIG['host_os'].match('windows') do
62
- FFI::Platform.windows?.should == true
71
+ when "windows"
72
+ it "returns true" do
73
+ expect(FFI::Platform.windows?).to be true
63
74
  end
64
-
65
- it "returns false", if: RbConfig::CONFIG['host_os'].match('darwin') do
66
- FFI::Platform.windows?.should == false
75
+ when "darwin"
76
+ it "returns false" do
77
+ expect(FFI::Platform.windows?).to be false
67
78
  end
68
79
  end
80
+ end
69
81
 
70
- describe "FFI::Platform.mac?" do
71
- it "returns false", if: RbConfig::CONFIG['host_os'].match('linux') do
72
- FFI::Platform.mac?.should == false
82
+ describe "FFI::Platform.mac?" do
83
+ case OS
84
+ when "linux"
85
+ it "returns false" do
86
+ expect(FFI::Platform.mac?).to be false
73
87
  end
74
-
75
- it "returns false", if: RbConfig::CONFIG['host_os'].match('windows') do
76
- FFI::Platform.mac?.should == false
88
+ when "windows"
89
+ it "returns false" do
90
+ expect(FFI::Platform.mac?).to be false
77
91
  end
78
-
79
- it "returns true", if: RbConfig::CONFIG['host_os'].match('darwin') do
80
- FFI::Platform.mac?.should == true
92
+ when "darwin"
93
+ it "returns true" do
94
+ expect(FFI::Platform.mac?).to be true
81
95
  end
82
96
  end
97
+ end
83
98
 
84
- describe "FFI::Platform.unix?" do
85
- it "returns true", if: RbConfig::CONFIG['host_os'].match('linux') do
86
- FFI::Platform.unix?.should == true
99
+ describe "FFI::Platform.unix?" do
100
+ case OS
101
+ when "linux"
102
+ it "returns true" do
103
+ expect(FFI::Platform.unix?).to be true
87
104
  end
88
-
89
- it "returns false", if: RbConfig::CONFIG['host_os'].match('windows') do
90
- FFI::Platform.unix?.should == false
105
+ when "windows"
106
+ it "returns false" do
107
+ expect(FFI::Platform.unix?).to be false
91
108
  end
92
-
93
- it "returns true", if: RbConfig::CONFIG['host_os'].match('darwin') do
94
- FFI::Platform.unix?.should == true
109
+ when "darwin"
110
+ it "returns true" do
111
+ expect(FFI::Platform.unix?).to be true
95
112
  end
96
113
  end
97
114
  end
@@ -4,7 +4,6 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- require 'ffi'
8
7
  require 'delegate'
9
8
 
10
9
  module PointerTestLib
@@ -30,12 +29,13 @@ describe "Pointer" do
30
29
  @ptr
31
30
  end
32
31
  end
32
+
33
33
  it "Any object implementing #to_ptr can be passed as a :pointer parameter" do
34
34
  memory = FFI::MemoryPointer.new :long_long
35
35
  magic = 0x12345678
36
36
  memory.put_int32(0, magic)
37
37
  tp = ToPtrTest.new(memory)
38
- PointerTestLib.ptr_ret_int32_t(tp, 0).should == magic
38
+ expect(PointerTestLib.ptr_ret_int32_t(tp, 0)).to eq(magic)
39
39
  end
40
40
  class PointerDelegate < DelegateClass(FFI::Pointer)
41
41
  def initialize(ptr)
@@ -45,18 +45,21 @@ describe "Pointer" do
45
45
  @ptr
46
46
  end
47
47
  end
48
+
48
49
  it "A DelegateClass(Pointer) can be passed as a :pointer parameter" do
49
50
  memory = FFI::MemoryPointer.new :long_long
50
51
  magic = 0x12345678
51
52
  memory.put_int32(0, magic)
52
53
  ptr = PointerDelegate.new(memory)
53
- PointerTestLib.ptr_ret_int32_t(ptr, 0).should == magic
54
+ expect(PointerTestLib.ptr_ret_int32_t(ptr, 0)).to eq(magic)
54
55
  end
56
+
55
57
  it "Fixnum cannot be used as a Pointer argument" do
56
- lambda { PointerTestLib.ptr_ret_int32(0, 0) }.should raise_error
58
+ expect { PointerTestLib.ptr_ret_int32(0, 0) }.to raise_error
57
59
  end
60
+
58
61
  it "Bignum cannot be used as a Pointer argument" do
59
- lambda { PointerTestLib.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.should raise_error
62
+ expect { PointerTestLib.ptr_ret_int32(0xfee1deadbeefcafebabe, 0) }.to raise_error
60
63
  end
61
64
 
62
65
  describe "pointer type methods" do
@@ -64,13 +67,13 @@ describe "Pointer" do
64
67
  it "#read_pointer" do
65
68
  memory = FFI::MemoryPointer.new :pointer
66
69
  PointerTestLib.ptr_set_pointer(memory, 0, PointerTestLib.ptr_from_address(0xdeadbeef))
67
- memory.read_pointer.address.should == 0xdeadbeef
70
+ expect(memory.read_pointer.address).to eq(0xdeadbeef)
68
71
  end
69
72
 
70
73
  it "#write_pointer" do
71
74
  memory = FFI::MemoryPointer.new :pointer
72
75
  memory.write_pointer(PointerTestLib.ptr_from_address(0xdeadbeef))
73
- PointerTestLib.ptr_ret_pointer(memory, 0).address.should == 0xdeadbeef
76
+ expect(PointerTestLib.ptr_ret_pointer(memory, 0).address).to eq(0xdeadbeef)
74
77
  end
75
78
 
76
79
  it "#read_array_of_pointer" do
@@ -81,7 +84,7 @@ describe "Pointer" do
81
84
  end
82
85
  array = memory.read_array_of_pointer(values.size)
83
86
  values.each_with_index do |address, j|
84
- array[j].address.should == address
87
+ expect(array[j].address).to eq(address)
85
88
  end
86
89
  end
87
90
 
@@ -90,23 +93,23 @@ describe "Pointer" do
90
93
  describe 'NULL' do
91
94
  it 'should be obtained using Pointer::NULL constant' do
92
95
  null_ptr = FFI::Pointer::NULL
93
- null_ptr.null?.should be_true
96
+ expect(null_ptr).to be_null
94
97
  end
95
98
  it 'should be obtained passing address 0 to constructor' do
96
- FFI::Pointer.new(0).null?.should be_true
99
+ expect(FFI::Pointer.new(0)).to be_null
97
100
  end
98
101
  it 'should raise an error when attempting read/write operations on it' do
99
102
  null_ptr = FFI::Pointer::NULL
100
- lambda { null_ptr.read_int }.should raise_error(FFI::NullPointerError)
101
- lambda { null_ptr.write_int(0xff1) }.should raise_error(FFI::NullPointerError)
103
+ expect { null_ptr.read_int }.to raise_error(FFI::NullPointerError)
104
+ expect { null_ptr.write_int(0xff1) }.to raise_error(FFI::NullPointerError)
102
105
  end
103
106
  it 'returns true when compared with nil' do
104
- (FFI::Pointer::NULL == nil).should be_true
107
+ expect((FFI::Pointer::NULL == nil)).to be true
105
108
  end
106
109
  end
107
110
 
108
111
  it "Pointer.size returns sizeof pointer on platform" do
109
- FFI::Pointer.size.should == (FFI::Platform::ADDRESS_SIZE / 8)
112
+ expect(FFI::Pointer.size).to eq((FFI::Platform::ADDRESS_SIZE / 8))
110
113
  end
111
114
 
112
115
  describe "#slice" do
@@ -117,22 +120,22 @@ describe "Pointer" do
117
120
  end
118
121
 
119
122
  it "contents of sliced pointer matches original pointer at offset" do
120
- @mptr.slice(4, 4).get_uint(0).should == 0xdeadbeef
123
+ expect(@mptr.slice(4, 4).get_uint(0)).to eq(0xdeadbeef)
121
124
  end
122
125
 
123
126
  it "modifying sliced pointer is reflected in original pointer" do
124
127
  @mptr.slice(4, 4).put_uint(0, 0xfee1dead)
125
- @mptr.get_uint(4).should == 0xfee1dead
128
+ expect(@mptr.get_uint(4)).to eq(0xfee1dead)
126
129
  end
127
130
 
128
131
  it "access beyond bounds should raise IndexError" do
129
- lambda { @mptr.slice(4, 4).get_int(4) }.should raise_error(IndexError)
132
+ expect { @mptr.slice(4, 4).get_int(4) }.to raise_error(IndexError)
130
133
  end
131
134
  end
132
135
 
133
136
  describe "#type_size" do
134
137
  it "should be same as FFI.type_size(type)" do
135
- FFI::MemoryPointer.new(:int, 1).type_size.should == FFI.type_size(:int)
138
+ expect(FFI::MemoryPointer.new(:int, 1).type_size).to eq(FFI.type_size(:int))
136
139
  end
137
140
  end
138
141
  end
@@ -166,8 +169,9 @@ describe "AutoPointer" do
166
169
  class AutoPointerSubclass < FFI::AutoPointer
167
170
  def self.release(ptr); end
168
171
  end
172
+
169
173
  it "cleanup via default release method" do
170
- AutoPointerSubclass.should_receive(:release).at_least(loop_count-wiggle_room).times
174
+ expect(AutoPointerSubclass).to receive(:release).at_least(loop_count-wiggle_room).times
171
175
  AutoPointerTestHelper.reset
172
176
  loop_count.times do
173
177
  # note that if we called
@@ -187,7 +191,7 @@ describe "AutoPointer" do
187
191
  #
188
192
  # we'd have a reference to the pointer and it would
189
193
  # never get GC'd.
190
- AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
194
+ expect(AutoPointerTestHelper).to receive(:release).at_least(loop_count-wiggle_room).times
191
195
  AutoPointerTestHelper.reset
192
196
  loop_count.times do
193
197
  FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
@@ -197,7 +201,7 @@ describe "AutoPointer" do
197
201
  end
198
202
 
199
203
  it "cleanup when passed a method" do
200
- AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
204
+ expect(AutoPointerTestHelper).to receive(:release).at_least(loop_count-wiggle_room).times
201
205
  AutoPointerTestHelper.reset
202
206
  loop_count.times do
203
207
  FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
@@ -207,7 +211,7 @@ describe "AutoPointer" do
207
211
  end
208
212
 
209
213
  it "can be used as the return type of a function" do
210
- lambda do
214
+ expect do
211
215
  Module.new do
212
216
  extend FFI::Library
213
217
  ffi_lib TestLibrary::PATH
@@ -216,18 +220,18 @@ describe "AutoPointer" do
216
220
  end
217
221
  attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], CustomAutoPointer
218
222
  end
219
- end.should_not raise_error
223
+ end.not_to raise_error
220
224
  end
221
225
 
222
226
  describe "#new" do
223
227
  it "MemoryPointer argument raises TypeError" do
224
- lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError)
228
+ expect { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.to raise_error(::TypeError)
225
229
  end
226
230
  it "AutoPointer argument raises TypeError" do
227
- lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError)
231
+ expect { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.to raise_error(::TypeError)
228
232
  end
229
233
  it "Buffer argument raises TypeError" do
230
- lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError)
234
+ expect { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.to raise_error(::TypeError)
231
235
  end
232
236
 
233
237
  end
@@ -238,13 +242,13 @@ describe "AutoPointer" do
238
242
  end
239
243
 
240
244
  it "should be true by default" do
241
- ptr_class.new(FFI::Pointer.new(0xdeadbeef)).autorelease?.should be_true
245
+ expect(ptr_class.new(FFI::Pointer.new(0xdeadbeef)).autorelease?).to be true
242
246
  end
243
247
 
244
248
  it "should return false when autorelease=(false)" do
245
249
  ptr = ptr_class.new(FFI::Pointer.new(0xdeadbeef))
246
250
  ptr.autorelease = false
247
- ptr.autorelease?.should be_false
251
+ expect(ptr.autorelease?).to be false
248
252
  end
249
253
  end
250
254
 
@@ -255,7 +259,7 @@ describe "AutoPointer" do
255
259
 
256
260
  it "type_size of AutoPointer should match wrapped Pointer" do
257
261
  aptr = ptr_class.new(FFI::Pointer.new(:int, 0xdeadbeef))
258
- aptr.type_size.should == FFI.type_size(:int)
262
+ expect(aptr.type_size).to eq(FFI.type_size(:int))
259
263
  end
260
264
 
261
265
  it "[] offset should match wrapped Pointer" do
@@ -263,8 +267,8 @@ describe "AutoPointer" do
263
267
  aptr = ptr_class.new(FFI::Pointer.new(:int, mptr))
264
268
  aptr[0].write_uint(0xfee1dead)
265
269
  aptr[1].write_uint(0xcafebabe)
266
- mptr[0].read_uint.should == 0xfee1dead
267
- mptr[1].read_uint.should == 0xcafebabe
270
+ expect(mptr[0].read_uint).to eq(0xfee1dead)
271
+ expect(mptr[1].read_uint).to eq(0xcafebabe)
268
272
  end
269
273
  end
270
274
  end