ruby-dbus 0.18.0.beta2 → 0.18.0.beta3

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
  SHA256:
3
- metadata.gz: 0c89eebb575c67de57670fdc2e8b70b4c08dcaf7fc3c1bad858f1d23869571c1
4
- data.tar.gz: 4a4793ed412ebd25a636bed4dafa5367800658eb5d52d853ef1b2c0df0e3e272
3
+ metadata.gz: aefe0e0b1ea07e4d659c568e496f0018e85ef0364d678169db736f967539175b
4
+ data.tar.gz: 44c64528e74823a45d318be92b6fc8838b988429c2f1205287682ee40b9a8f38
5
5
  SHA512:
6
- metadata.gz: c03aa469aebb197943266b9147fba6b55383a22248e0814b0c2f7799c2e95d43b555f80a919c236a437c90805cbd7647498c1f8b1cf901d4a298da0b2d81e50c
7
- data.tar.gz: f7906b8c2308909cb8974240f3d8de3bc3e10a481fc15c91acd7af5526f405fd314df8b1a424683009a64dfc52ebfa9fa2c73497f8215cb403d80ab02866d56a
6
+ metadata.gz: e6655ff88bcbda618eafc3ec62f74f4a2051a5f6327cd130fddd8a3aaff4b8e999fa2843edde8fd6de9cdb0df95fa6dfd56bf18c1e668ac92ffd1e131f58c9f6
7
+ data.tar.gz: 4c54cad54ea4833afff8290598c8717a30cb0b221b486378d06070e010b162e54a2dcaa08cb542b21f91cf7dd8ee215646c8461504b676e977b597e325a5b7ae
data/NEWS.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Ruby D-Bus 0.18.0.beta3 - 2022-04-10
6
+
7
+ Bug fixes:
8
+ * Service-side properties: Fix Properties.Get, Properties.GetAll for Array,
9
+ Dict, and Variant types ([#105][]).
10
+
11
+ [#105]: https://github.com/mvidner/ruby-dbus/pull/105
12
+
5
13
  ## Ruby D-Bus 0.18.0.beta2 - 2022-04-04
6
14
 
7
15
  API:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.0.beta2
1
+ 0.18.0.beta3
data/lib/dbus/data.rb CHANGED
@@ -165,6 +165,9 @@ module DBus
165
165
 
166
166
  # Represents integers
167
167
  class Int < Fixed
168
+ # @!method self.range
169
+ # @return [Range] the full range of allowed values
170
+
168
171
  # @param value [::Integer,DBus::Data::Int]
169
172
  # @raise RangeError
170
173
  def initialize(value)
@@ -174,10 +177,6 @@ module DBus
174
177
 
175
178
  super(value)
176
179
  end
177
-
178
- def self.range
179
- raise NotImplementedError, "Abstract"
180
- end
181
180
  end
182
181
 
183
182
  # Byte.
@@ -542,7 +541,7 @@ module DBus
542
541
  Data.make_typed(member_type, i)
543
542
  end
544
543
 
545
- new(items) # initialize(::Array<Data::Base>)
544
+ new(items, member_type: member_type) # initialize(::Array<Data::Base>)
546
545
  end
547
546
 
548
547
  # FIXME: should Data::Array be mutable?
@@ -603,8 +602,6 @@ module DBus
603
602
  # TODO: validation
604
603
  raise unless value.size == member_types.size
605
604
 
606
- @member_types = member_types
607
-
608
605
  items = member_types.zip(value).map do |item_type, item|
609
606
  Data.make_typed(item_type, item)
610
607
  end
@@ -643,14 +640,20 @@ module DBus
643
640
  # assert member_types.empty?
644
641
 
645
642
  # decide on type of value
646
- new(value)
643
+ new(value, member_type: nil)
647
644
  end
648
645
 
649
- # Note that for Variants type=="v",
646
+ # @return [Type]
647
+ def self.type
648
+ # memoize
649
+ @type ||= Type.new(type_code).freeze
650
+ end
651
+
652
+ # Note that for Variants type.to_s=="v",
650
653
  # for the specific see {Variant#member_type}
651
654
  # @return [Type] the exact type of this value
652
655
  def type
653
- "v"
656
+ self.class.type
654
657
  end
655
658
 
656
659
  # @return [Type]
@@ -708,6 +711,22 @@ module DBus
708
711
  value
709
712
  end
710
713
 
714
+ # @param value [::Object] (#size, #each)
715
+ # @param member_types [::Array<Type>]
716
+ # @return [DictEntry]
717
+ def self.from_typed(value, member_types:)
718
+ # assert member_types.size == 2
719
+ # TODO: duplicated from Struct. Inherit/delegate?
720
+ # TODO: validation
721
+ raise unless value.size == member_types.size
722
+
723
+ items = member_types.zip(value).map do |item_type, item|
724
+ Data.make_typed(item_type, item)
725
+ end
726
+
727
+ new(items, member_types: member_types) # initialize(::Array<Data::Base>)
728
+ end
729
+
711
730
  def initialize(value, member_types:)
712
731
  @member_types = member_types
713
732
  @type = nil
data/lib/dbus/marshall.rb CHANGED
@@ -102,6 +102,8 @@ module DBus
102
102
  packet = data_class.from_raw(value, mode: mode)
103
103
  elsif data_class.basic?
104
104
  size = aligned_read_value(data_class.size_class)
105
+ # @raw_msg.align(data_class.alignment)
106
+ # ^ is not necessary because we've just read a suitably-aligned *size*
105
107
  value = @raw_msg.read(size)
106
108
  nul = @raw_msg.read(1)
107
109
  if nul != "\u0000"
@@ -250,7 +252,7 @@ module DBus
250
252
  when Type::ARRAY
251
253
  append_array(type.child, val)
252
254
  when Type::STRUCT, Type::DICT_ENTRY
253
- val = val.value if val.is_a?(Data::Struct)
255
+ val = val.value if val.is_a?(Data::Struct) || val.is_a?(Data::DictEntry)
254
256
  unless val.is_a?(Array) || val.is_a?(Struct)
255
257
  type_name = Type::TYPE_MAPPING[type.sigtype].first
256
258
  raise TypeException, "#{type_name} expects an Array or Struct, seen #{val.class}"
data/spec/data_spec.rb CHANGED
@@ -183,6 +183,14 @@ describe DBus::Data do
183
183
 
184
184
  include_examples "constructor accepts plain or typed values", good
185
185
  include_examples "constructor rejects values from this list", bad
186
+
187
+ describe ".alignment" do
188
+ # this overly specific test avoids a redundant alignment call
189
+ # in the production code
190
+ it "returns the correct value" do
191
+ expect(described_class.alignment).to eq 4
192
+ end
193
+ end
186
194
  end
187
195
 
188
196
  describe DBus::Data::ObjectPath do
@@ -198,6 +206,14 @@ describe DBus::Data do
198
206
 
199
207
  include_examples "constructor accepts plain or typed values", good
200
208
  include_examples "constructor rejects values from this list", bad
209
+
210
+ describe ".alignment" do
211
+ # this overly specific test avoids a redundant alignment call
212
+ # in the production code
213
+ it "returns the correct value" do
214
+ expect(described_class.alignment).to eq 4
215
+ end
216
+ end
201
217
  end
202
218
 
203
219
  describe DBus::Data::Signature do
@@ -215,6 +231,14 @@ describe DBus::Data do
215
231
 
216
232
  include_examples "constructor accepts plain or typed values", good
217
233
  include_examples "constructor rejects values from this list", bad
234
+
235
+ describe ".alignment" do
236
+ # this overly specific test avoids a redundant alignment call
237
+ # in the production code
238
+ it "returns the correct value" do
239
+ expect(described_class.alignment).to eq 1
240
+ end
241
+ end
218
242
  end
219
243
  end
220
244
 
@@ -238,6 +262,13 @@ describe DBus::Data do
238
262
 
239
263
  include_examples "constructor (kwargs) accepts values", good
240
264
  include_examples "constructor (kwargs) rejects values", bad
265
+
266
+ describe ".from_typed" do
267
+ it "creates new instance from given object and type" do
268
+ type = DBus::Type.new("s")
269
+ expect(described_class.from_typed(["test", "lest"], member_types: [type])).to be_a(described_class)
270
+ end
271
+ end
241
272
  end
242
273
 
243
274
  describe DBus::Data::Struct do
@@ -287,9 +318,33 @@ describe DBus::Data do
287
318
 
288
319
  include_examples "constructor (kwargs) accepts values", good
289
320
  # include_examples "constructor (kwargs) rejects values", bad
321
+
322
+ describe ".from_typed" do
323
+ it "creates new instance from given object and type" do
324
+ type = DBus::Type.new("s")
325
+ expect(described_class.from_typed(["test", "lest"].freeze, member_types: [type, type]))
326
+ .to be_a(described_class)
327
+ end
328
+ end
290
329
  end
291
330
 
292
331
  describe DBus::Data::Variant do
332
+ describe ".from_typed" do
333
+ it "creates new instance from given object and type" do
334
+ type = DBus::Type.new("s")
335
+ expect(described_class.from_typed("test", member_types: [type])).to be_a(described_class)
336
+ end
337
+
338
+ it "ignores the member_types argument" do
339
+ type = DBus::Type.new("s")
340
+ # Base.from_typed is a generic interface with a fixed signature;
341
+ # So it must offer the member_types parameter, which is misleading
342
+ # for a Variant
343
+ value = described_class.from_typed("test", member_types: [type])
344
+ expect(value.type.to_s).to eq "v"
345
+ expect(value.member_type.to_s).to eq "s"
346
+ end
347
+ end
293
348
  end
294
349
 
295
350
  describe DBus::Data::DictEntry do
@@ -52,7 +52,7 @@ describe "PropertyTest" do
52
52
 
53
53
  it "tests get all" do
54
54
  all = @iface.all_properties
55
- expect(all.keys.sort).to eq(["MyStruct", "ReadMe", "ReadOrWriteMe"])
55
+ expect(all.keys.sort).to eq(["MyArray", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
56
56
  end
57
57
 
58
58
  it "tests get all on a V1 object" do
@@ -60,7 +60,7 @@ describe "PropertyTest" do
60
60
  iface = obj["org.ruby.SampleInterface"]
61
61
 
62
62
  all = iface.all_properties
63
- expect(all.keys.sort).to eq(["MyStruct", "ReadMe", "ReadOrWriteMe"])
63
+ expect(all.keys.sort).to eq(["MyArray", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
64
64
  end
65
65
 
66
66
  it "tests unknown property reading" do
@@ -147,4 +147,29 @@ describe "PropertyTest" do
147
147
  expect(reply).to match(/variant\s+struct {\s+string "three"\s+string "strings"\s+string "in a struct"\s+}/)
148
148
  end
149
149
  end
150
+
151
+ context "an array-typed property" do
152
+ it "gets read as an array" do
153
+ val = @iface["MyArray"]
154
+ expect(val).to eq([42, 43])
155
+ end
156
+ end
157
+
158
+ context "an dict-typed property" do
159
+ it "gets read as a hash" do
160
+ val = @iface["MyDict"]
161
+ expect(val).to eq({
162
+ "one" => 1,
163
+ "two" => "dva",
164
+ "three" => [3, 3, 3]
165
+ })
166
+ end
167
+ end
168
+
169
+ context "a variant-typed property" do
170
+ it "gets read at all" do
171
+ val = @iface["MyVariant"]
172
+ expect(val).to eq([42, 43])
173
+ end
174
+ end
150
175
  end
@@ -13,16 +13,30 @@ PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"
13
13
  class Test < DBus::Object
14
14
  Point2D = Struct.new(:x, :y)
15
15
 
16
+ attr_writer :main_loop
17
+
16
18
  INTERFACE = "org.ruby.SampleInterface"
17
19
  def initialize(path)
18
20
  super path
19
21
  @read_me = "READ ME"
20
22
  @read_or_write_me = "READ OR WRITE ME"
21
23
  @my_struct = ["three", "strings", "in a struct"].freeze
24
+ @my_array = [42, 43]
25
+ @my_dict = {
26
+ "one" => 1,
27
+ "two" => "dva",
28
+ "three" => [3, 3, 3]
29
+ }
30
+ @my_variant = @my_array.dup
31
+ @main_loop = nil
22
32
  end
23
33
 
24
34
  # Create an interface aggregating all upcoming dbus_method defines.
25
35
  dbus_interface INTERFACE do
36
+ dbus_method :quit, "" do
37
+ @main_loop&.quit
38
+ end
39
+
26
40
  dbus_method :hello, "in name:s, in name2:s" do |name, name2|
27
41
  puts "hello(#{name}, #{name2})"
28
42
  end
@@ -94,6 +108,9 @@ class Test < DBus::Object
94
108
  dbus_reader :explosive, "s"
95
109
 
96
110
  dbus_attr_reader :my_struct, "(sss)"
111
+ dbus_attr_reader :my_array, "aq"
112
+ dbus_attr_reader :my_dict, "a{sv}"
113
+ dbus_attr_reader :my_variant, "v"
97
114
  end
98
115
 
99
116
  # closing and reopening the same interface
@@ -193,6 +210,7 @@ end
193
210
  puts "listening, with ruby-#{RUBY_VERSION}"
194
211
  main = DBus::Main.new
195
212
  main << bus
213
+ myobj.main_loop = main
196
214
  begin
197
215
  main.run
198
216
  rescue SystemCallError
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,8 @@ if coverage
15
15
  SimpleCov.add_filter "_spec.rb"
16
16
  # do not cover the activesupport helpers
17
17
  SimpleCov.add_filter "/core_ext/"
18
+ # measure all if/else branches on a line
19
+ SimpleCov.enable_coverage :branch
18
20
 
19
21
  SimpleCov.start
20
22
 
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "spec_helper"
5
+ require "dbus"
6
+
7
+ describe "Quit the service" do
8
+ it "Tells the service to quit and waits, to collate coverage data" do
9
+ session_bus = DBus::ASessionBus.new
10
+ @svc = session_bus.service("org.ruby.service")
11
+ @obj = @svc.object("/org/ruby/MyInstance")
12
+ @obj.default_iface = "org.ruby.SampleInterface"
13
+ @obj.quit
14
+ sleep 3
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0.beta2
4
+ version: 0.18.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby DBus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rexml
@@ -197,6 +197,7 @@ files:
197
197
  - spec/type_spec.rb
198
198
  - spec/value_spec.rb
199
199
  - spec/variant_spec.rb
200
+ - spec/zzz_quit_spec.rb
200
201
  homepage: https://github.com/mvidner/ruby-dbus
201
202
  licenses:
202
203
  - LGPL-2.1