ffi 1.9.5 → 1.9.6

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +13 -6
  3. data/ext/ffi_c/extconf.rb +2 -2
  4. data/lib/ffi.rb +2 -0
  5. data/lib/ffi/version.rb +1 -1
  6. data/spec/ffi/async_callback_spec.rb +4 -5
  7. data/spec/ffi/bool_spec.rb +9 -8
  8. data/spec/ffi/buffer_spec.rb +64 -37
  9. data/spec/ffi/callback_spec.rb +195 -116
  10. data/spec/ffi/custom_param_type.rb +1 -1
  11. data/spec/ffi/custom_type_spec.rb +5 -6
  12. data/spec/ffi/dup_spec.rb +6 -8
  13. data/spec/ffi/enum_spec.rb +135 -129
  14. data/spec/ffi/errno_spec.rb +2 -2
  15. data/spec/ffi/ffi_spec.rb +4 -6
  16. data/spec/ffi/fixtures/EnumTest.o +0 -0
  17. data/spec/ffi/function_spec.rb +22 -11
  18. data/spec/ffi/io_spec.rb +0 -1
  19. data/spec/ffi/library_spec.rb +71 -36
  20. data/spec/ffi/long_double.rb +3 -4
  21. data/spec/ffi/managed_struct_spec.rb +14 -4
  22. data/spec/ffi/memorypointer_spec.rb +7 -1
  23. data/spec/ffi/number_spec.rb +43 -34
  24. data/spec/ffi/platform_spec.rb +76 -59
  25. data/spec/ffi/pointer_spec.rb +35 -31
  26. data/spec/ffi/rbx/attach_function_spec.rb +3 -4
  27. data/spec/ffi/rbx/memory_pointer_spec.rb +24 -22
  28. data/spec/ffi/rbx/spec_helper.rb +0 -1
  29. data/spec/ffi/rbx/struct_spec.rb +1 -2
  30. data/spec/ffi/spec_helper.rb +5 -2
  31. data/spec/ffi/string_spec.rb +22 -14
  32. data/spec/ffi/strptr_spec.rb +6 -7
  33. data/spec/ffi/struct_by_ref_spec.rb +4 -5
  34. data/spec/ffi/struct_callback_spec.rb +6 -7
  35. data/spec/ffi/struct_initialize_spec.rb +2 -3
  36. data/spec/ffi/struct_packed_spec.rb +12 -14
  37. data/spec/ffi/struct_spec.rb +203 -129
  38. data/spec/ffi/typedef_spec.rb +11 -10
  39. data/spec/ffi/union_spec.rb +8 -7
  40. data/spec/ffi/variadic_spec.rb +13 -10
  41. metadata +2 -2
@@ -4,8 +4,6 @@
4
4
  #
5
5
 
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
7
- require 'ffi'
8
-
9
7
  describe "Custom type definitions" do
10
8
  it "attach_function with custom typedef" do
11
9
  module CustomTypedef
@@ -14,8 +12,9 @@ describe "Custom type definitions" do
14
12
  typedef :uint, :fubar_t
15
13
  attach_function :ret_u32, [ :fubar_t ], :fubar_t
16
14
  end
17
- CustomTypedef.ret_u32(0x12345678).should == 0x12345678
15
+ expect(CustomTypedef.ret_u32(0x12345678)).to eq(0x12345678)
18
16
  end
17
+
19
18
  it "variadic invoker with custom typedef" do
20
19
  module VariadicCustomTypedef
21
20
  extend FFI::Library
@@ -25,8 +24,9 @@ describe "Custom type definitions" do
25
24
  end
26
25
  buf = FFI::Buffer.new :uint, 10
27
26
  VariadicCustomTypedef.pack_varargs(buf, "i", :fubar_t, 0x12345678)
28
- buf.get_int64(0).should == 0x12345678
27
+ expect(buf.get_int64(0)).to eq(0x12345678)
29
28
  end
29
+
30
30
  it "Callback with custom typedef parameter" do
31
31
  module CallbackCustomTypedef
32
32
  extend FFI::Library
@@ -37,7 +37,7 @@ describe "Custom type definitions" do
37
37
  end
38
38
  i = 0
39
39
  CallbackCustomTypedef.testCallbackU32rV(0xdeadbeef) { |v| i = v }
40
- i.should == 0xdeadbeef
40
+ expect(i).to eq(0xdeadbeef)
41
41
  end
42
42
  module StructCustomTypedef
43
43
  extend FFI::Library
@@ -47,14 +47,15 @@ describe "Custom type definitions" do
47
47
  layout :a, :fubar3_t
48
48
  end
49
49
  end
50
+
50
51
  it "Struct with custom typedef field" do
51
52
  s = StructCustomTypedef::S.new
52
53
  s[:a] = 0x12345678
53
- s.pointer.get_uint(0).should == 0x12345678
54
+ expect(s.pointer.get_uint(0)).to eq(0x12345678)
54
55
  end
55
56
 
56
57
  it "attach_function after a typedef should not reject normal types" do
57
- lambda do
58
+ expect do
58
59
  Module.new do
59
60
  extend FFI::Library
60
61
  # enum() will insert a custom typedef called :foo for the enum
@@ -69,11 +70,11 @@ describe "Custom type definitions" do
69
70
  attach_function :ptr_ret_int32_t, :ptr_ret___int32_t, [ :string, :foo ], :bar
70
71
  end
71
72
  end
72
- end.should_not raise_error
73
+ end.not_to raise_error
73
74
  end
74
75
 
75
76
  it "detects the correct type for size_t" do
76
- lambda do
77
+ expect do
77
78
  Module.new do
78
79
  extend FFI::Library
79
80
  ffi_lib "c"
@@ -85,6 +86,6 @@ describe "Custom type definitions" do
85
86
  attach_function :read, [:int, :pointer, :size_t], :ssize_t
86
87
  end
87
88
  end
88
- end.should_not raise_error
89
+ end.not_to raise_error
89
90
  end
90
91
  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
 
9
8
  module LibTest
10
9
  Types = {
@@ -37,16 +36,17 @@ describe 'Union' do
37
36
  before do
38
37
  @u = LibTest::TestUnion.new
39
38
  end
39
+
40
40
  it 'should place all the fields at offset 0' do
41
- LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }.should be_true
41
+ expect(LibTest::TestUnion.members.all? { |m| LibTest::TestUnion.offset_of(m) == 0 }).to be true
42
42
  end
43
43
  LibTest::Types.each do |k, type|
44
44
  it "should correctly align/write a #{type[0]} value" do
45
45
  @u[type[1]] = type[2]
46
46
  if k == 'f32' or k == 'f64'
47
- (@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs.should < 0.00001
47
+ expect((@u[type[1]] - LibTest.send("union_align_#{k}", @u.to_ptr)).abs).to be < 0.00001
48
48
  else
49
- @u[type[1]].should == LibTest.send("union_align_#{k}", @u.to_ptr)
49
+ expect(@u[type[1]]).to eq(LibTest.send("union_align_#{k}", @u.to_ptr))
50
50
  end
51
51
  end
52
52
  end
@@ -54,13 +54,14 @@ describe 'Union' do
54
54
  it "should read a #{type[0]} value from memory" do
55
55
  @u = LibTest::TestUnion.new(LibTest.send("union_make_union_with_#{k}", type[2]))
56
56
  if k == 'f32' or k == 'f64'
57
- (@u[type[1]] - type[2]).abs.should < 0.00001
57
+ expect((@u[type[1]] - type[2]).abs).to be < 0.00001
58
58
  else
59
- @u[type[1]].should == type[2]
59
+ expect(@u[type[1]]).to eq(type[2])
60
60
  end
61
61
  end
62
62
  end
63
+
63
64
  it 'should return a size equals to the size of the biggest field' do
64
- LibTest::TestUnion.size.should == LibTest.union_size
65
+ expect(LibTest::TestUnion.size).to eq(LibTest.union_size)
65
66
  end
66
67
  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
 
9
8
  describe "Function with variadic arguments" do
10
9
  module LibTest
@@ -19,41 +18,44 @@ describe "Function with variadic arguments" do
19
18
  it "takes enum arguments" do
20
19
  buf = FFI::Buffer.new :long_long, 2
21
20
  LibTest.pack_varargs(buf, "ii", :int, :c3, :int, :c4)
22
- buf.get_int64(0).should == 42
23
- buf.get_int64(8).should == 43
21
+ expect(buf.get_int64(0)).to eq(42)
22
+ expect(buf.get_int64(8)).to eq(43)
24
23
  end
25
24
 
26
25
  it "returns symbols for enums" do
27
26
  buf = FFI::Buffer.new :long_long, 2
28
- LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4).should eql(:c2)
27
+ expect(LibTest.pack_varargs2(buf, :c1, "ii", :int, :c3, :int, :c4)).to eq(:c2)
29
28
  end
30
29
 
31
30
  [ 0, 127, -128, -1 ].each do |i|
32
31
  it "call variadic with (:char (#{i})) argument" do
33
32
  buf = FFI::Buffer.new :long_long
34
33
  LibTest.pack_varargs(buf, "c", :char, i)
35
- buf.get_int64(0).should == i
34
+ expect(buf.get_int64(0)).to eq(i)
36
35
  end
37
36
  end
37
+
38
38
  [ 0, 0x7f, 0x80, 0xff ].each do |i|
39
39
  it "call variadic with (:uchar (#{i})) argument" do
40
40
  buf = FFI::Buffer.new :long_long
41
41
  LibTest.pack_varargs(buf, "C", :uchar, i)
42
- buf.get_int64(0).should == i
42
+ expect(buf.get_int64(0)).to eq(i)
43
43
  end
44
44
  end
45
+
45
46
  [ 0, 1.234567, 9.87654321 ].each do |v|
46
47
  it "call variadic with (:float (#{v})) argument" do
47
48
  buf = FFI::Buffer.new :long_long
48
49
  LibTest.pack_varargs(buf, "f", :float, v.to_f)
49
- buf.get_float64(0).should == v
50
+ expect(buf.get_float64(0)).to eq(v)
50
51
  end
51
52
  end
53
+
52
54
  [ 0, 1.234567, 9.87654321 ].each do |v|
53
55
  it "call variadic with (:double (#{v})) argument" do
54
56
  buf = FFI::Buffer.new :long_long
55
57
  LibTest.pack_varargs(buf, "f", :double, v.to_f)
56
- buf.get_float64(0).should == v
58
+ expect(buf.get_float64(0)).to eq(v)
57
59
  end
58
60
  end
59
61
 
@@ -71,6 +73,7 @@ describe "Function with variadic arguments" do
71
73
  'f' => [ 1.23456789 ],
72
74
  'd' => [ 9.87654321 ]
73
75
  }
76
+
74
77
  TYPE_MAP = {
75
78
  'c' => :char, 'C' => :uchar, 's' => :short, 'S' => :ushort,
76
79
  'i' => :int, 'I' => :uint, 'j' => :long_long, 'J' => :ulong_long,
@@ -80,9 +83,9 @@ describe "Function with variadic arguments" do
80
83
 
81
84
  def verify(p, off, v)
82
85
  if v.kind_of?(Float)
83
- p.get_float64(off).should == v
86
+ expect(p.get_float64(off)).to eq(v)
84
87
  else
85
- p.get_int64(off).should == v
88
+ expect(p.get_int64(off)).to eq(v)
86
89
  end
87
90
  end
88
91
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.5
4
+ version: 1.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Meissner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake