ffi-struct_ex 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56f6bae584293791faa95b89f433bc4c507f102f
4
- data.tar.gz: 85b5c35bb1e4b3856f27471afe5a28b70d788fb4
3
+ metadata.gz: 4ac19c3923f1ad0b4d6fafbb45239e3033612d71
4
+ data.tar.gz: b06348fa797179ad6383242ca04ee1a9eb7993fb
5
5
  SHA512:
6
- metadata.gz: f16a542162f3f97513d5abf8a147beae7f0c17106f68c2ea4327098c72b44ab290ff0950c10601abb6097d02280ec30760a4c82c7f9048b2b491bbdff2b768af
7
- data.tar.gz: c9f4858659612519aece832f58cbcbd708a7596d0688016ee46be9646308fc22b88dad18bc58fcb92692499611251e05bc6469b2b35921a8e98268759c6e33dc
6
+ metadata.gz: 33f293223f2122c75b6535e2f0e8025f76dd239d47a2bad68b48afe198674246a7198f8debc5eddce9f8f365764c306f20b8ab91e29062bb5e80cc376174f325
7
+ data.tar.gz: f6f4a4a34bc5ee680742bb0d38fecc3cfeb1345b1964cd39a2c398c9e13ae572ecd810238737671ccc8b2a24813f628e353644ee66e2f0f25c489e505d8814f9
data/Rakefile CHANGED
@@ -4,5 +4,5 @@ require "bundler/gem_tasks"
4
4
  require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec) do |t|
7
- t.ruby_opts = "-w -I\"#{['lib', 'spec'].join(File::PATH_SEPARATOR)}\""
7
+ t.ruby_opts = "-I\"#{['lib', 'spec'].join(File::PATH_SEPARATOR)}\""
8
8
  end
@@ -141,7 +141,7 @@ module FFI
141
141
  if bits_unit && bits_unit[:ffi_type].size == ffi_type.size && bits_unit[:bits_size] + bits_size <= bits_unit[:ffi_type].size * 8
142
142
  bits_unit[:bits_size] += bits_size
143
143
  else
144
- offset = builder.send(:align, builder.size, [@min_alignment || 1, ffi_type.alignment].max)
144
+ offset = builder.send(:align, builder.size, @packed ? [@packed, ffi_type.alignment].min : [@min_alignment || 1, ffi_type.alignment].max)
145
145
  bits_unit = {ffi_type: ffi_type, bits_size: bits_size}
146
146
  end
147
147
 
@@ -1,5 +1,5 @@
1
1
  module Ffi
2
2
  module StructEx
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -121,6 +121,94 @@ describe FFI::StructEx do
121
121
  end
122
122
  end
123
123
 
124
+ describe "#size and #alignment with pack 1" do
125
+ def test_size_and_alignment(specs, size, alignment)
126
+ klass = Class.new(described_class) do
127
+ pack 1
128
+ layout(*specs)
129
+ end
130
+
131
+ klass.size.should == size
132
+ klass.alignment.should == alignment
133
+ end
134
+
135
+ it "should work by declaring ffi type" do
136
+ test_size_and_alignment([:f0, :short,
137
+ :f1, :char,
138
+ :f2, :char], 4, 1)
139
+
140
+ test_size_and_alignment([:f0, :short,
141
+ :f1, :char], 3, 1)
142
+ test_size_and_alignment([:f0, :char,
143
+ :f1, :short], 3, 1)
144
+ end
145
+
146
+ it "should work by only declaring bit field with default type" do
147
+ test_size_and_alignment([:f0, 31,
148
+ :f1, 31], 8, 1)
149
+
150
+ test_size_and_alignment([:f0, 8,
151
+ :f1, 16], 3, 1)
152
+ test_size_and_alignment([:f0, 16,
153
+ :f1, 8], 3, 1)
154
+
155
+ test_size_and_alignment([:f0, 1,
156
+ :f1, 16,
157
+ :f2, 1], 4, 1)
158
+ end
159
+
160
+ it "should work by declaring bit field and ffi type" do
161
+ test_size_and_alignment([:f0, 'uint32: 1',
162
+ :f1, :uint16], 6, 1)
163
+ end
164
+ let(:klass1) {
165
+
166
+ }
167
+
168
+ let(:klass1) {
169
+ klass = Class.new(FFI::StructEx) do
170
+ pack 1
171
+ layout :bits_0_2, 'uint16: 3',
172
+ :bit_3, 'uint16: 1',
173
+ :bit_4, 'uint16: 1',
174
+ :bits_5_7, 'uint16: 3',
175
+ :bits_8_15, :uint8
176
+ end
177
+ Class.new(FFI::StructEx) do
178
+ pack 1
179
+ layout :f0, klass,
180
+ :f1, :uint8,
181
+ :f2, :uint8,
182
+ :f3, :uint8
183
+ end
184
+ }
185
+
186
+ let(:klass2) {
187
+ klass = Class.new(FFI::StructEx) do
188
+ layout :bits_0_2, 'uint16: 3',
189
+ :bit_3, 'uint16: 1',
190
+ :bit_4, 'uint16: 1',
191
+ :bits_5_7, 'uint16: 3',
192
+ :bits_8_15, :uint8
193
+ end
194
+ Class.new(FFI::StructEx) do
195
+ pack 1
196
+ layout :f0, klass,
197
+ :f1, :uint8,
198
+ :f2, :uint8,
199
+ :f3, :uint8
200
+ end
201
+ }
202
+
203
+ it "should work by declaring embedded field" do
204
+ klass1.size.should == 6
205
+ klass1.offset_of(:f1).should == 3
206
+
207
+ klass2.size.should == 7
208
+ klass2.offset_of(:f1).should == 4
209
+ end
210
+ end
211
+
124
212
  describe "#==" do
125
213
  context "when given embedded struct" do
126
214
  let(:hash) { {f0: {bits_0_2: 0b001, bit_3: 0b1, bit_4: 0b0, bits_5_7: 0b011}, f1: 0x1} }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-struct_ex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruijia Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi