ruby-dbus 0.18.0.beta4 → 0.18.0.beta7

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,7 +60,7 @@ describe "PropertyTest" do
60
60
 
61
61
  it "tests get all" do
62
62
  all = @iface.all_properties
63
- expect(all.keys.sort).to eq(["MyArray", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
63
+ expect(all.keys.sort).to eq(["MyArray", "MyByte", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
64
64
  end
65
65
 
66
66
  it "tests get all on a V1 object" do
@@ -68,7 +68,7 @@ describe "PropertyTest" do
68
68
  iface = obj["org.ruby.SampleInterface"]
69
69
 
70
70
  all = iface.all_properties
71
- expect(all.keys.sort).to eq(["MyArray", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
71
+ expect(all.keys.sort).to eq(["MyArray", "MyByte", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
72
72
  end
73
73
 
74
74
  it "tests unknown property reading" do
@@ -163,7 +163,7 @@ describe "PropertyTest" do
163
163
  end
164
164
  end
165
165
 
166
- context "an dict-typed property" do
166
+ context "a dict-typed property" do
167
167
  it "gets read as a hash" do
168
168
  val = @iface["MyDict"]
169
169
  expect(val).to eq({
@@ -172,6 +172,23 @@ describe "PropertyTest" do
172
172
  "three" => [3, 3, 3]
173
173
  })
174
174
  end
175
+
176
+ it "Get returns the correctly typed value (check with dbus-send)" do
177
+ cmd = "dbus-send --print-reply " \
178
+ "--dest=org.ruby.service " \
179
+ "/org/ruby/MyInstance " \
180
+ "org.freedesktop.DBus.Properties.Get " \
181
+ "string:org.ruby.SampleInterface " \
182
+ "string:MyDict"
183
+ reply = `#{cmd}`
184
+ # a bug about variant nesting lead to a "variant variant int32 1" value
185
+ match_rx = /variant \s+ array \s \[ \s+
186
+ dict \s entry\( \s+
187
+ string \s "one" \s+
188
+ variant \s+ int32 \s 1 \s+
189
+ \)/x
190
+ expect(reply).to match(match_rx)
191
+ end
175
192
  end
176
193
 
177
194
  context "a variant-typed property" do
@@ -183,6 +200,36 @@ describe "PropertyTest" do
183
200
  end
184
201
  end
185
202
 
203
+ context "a byte-typed property" do
204
+ # Slightly advanced RSpec:
205
+ # https://rspec.info/documentation/3.9/rspec-expectations/RSpec/Matchers.html#satisfy-instance_method
206
+ let(:a_byte_in_a_variant) do
207
+ satisfying { |x| x.is_a?(DBus::Data::Variant) && x.member_type.to_s == DBus::Type::BYTE }
208
+ # ^ This formatting keeps the matcher on a single line
209
+ # which enables RSpect to cite it if it fails, instead of saying "block".
210
+ end
211
+
212
+ let(:prop_iface) { @obj[DBus::PROPERTY_INTERFACE] }
213
+
214
+ it "gets set with a correct type (#108)" do
215
+ expect(prop_iface).to receive(:Set).with(
216
+ "org.ruby.SampleInterface",
217
+ "MyByte",
218
+ a_byte_in_a_variant
219
+ )
220
+ @iface["MyByte"] = 1
221
+ end
222
+
223
+ it "gets set with a correct type (#108), when using the DBus.variant workaround" do
224
+ expect(prop_iface).to receive(:Set).with(
225
+ "org.ruby.SampleInterface",
226
+ "MyByte",
227
+ a_byte_in_a_variant
228
+ )
229
+ @iface["MyByte"] = DBus.variant("y", 1)
230
+ end
231
+ end
232
+
186
233
  context "marshall.yaml round-trip via a VARIANT property" do
187
234
  marshall_yaml.each do |test|
188
235
  t = OpenStruct.new(test)
@@ -28,6 +28,8 @@ class Test < DBus::Object
28
28
  "three" => [3, 3, 3]
29
29
  }
30
30
  @my_variant = @my_array.dup
31
+ # 201 is a RET instruction for ZX Spectrum which has turned 40 recently
32
+ @my_byte = 201
31
33
  @main_loop = nil
32
34
  end
33
35
 
@@ -111,6 +113,8 @@ class Test < DBus::Object
111
113
  dbus_attr_accessor :my_array, "aq"
112
114
  dbus_attr_accessor :my_dict, "a{sv}"
113
115
  dbus_attr_accessor :my_variant, "v"
116
+
117
+ dbus_attr_accessor :my_byte, "y"
114
118
  end
115
119
 
116
120
  # closing and reopening the same interface
data/spec/type_spec.rb CHANGED
@@ -45,6 +45,7 @@ describe DBus do
45
45
  ["a{vs}", "DICT_ENTRY key must be basic (non-container)"],
46
46
  ["{sv}", "DICT_ENTRY not an immediate child of an ARRAY"],
47
47
  ["a({sv})", "DICT_ENTRY not an immediate child of an ARRAY"],
48
+ ["a{s", "DICT_ENTRY not closed"],
48
49
  ["a{sv", "DICT_ENTRY not closed"],
49
50
  ["}", "DICT_ENTRY unexpectedly closed"],
50
51
 
@@ -79,4 +80,148 @@ describe DBus do
79
80
  end
80
81
  end
81
82
  end
83
+
84
+ describe DBus::Type do
85
+ let(:as1) { DBus.type("as") }
86
+ let(:as2) { DBus.type("as") }
87
+ let(:aas) { DBus.type("aas") }
88
+
89
+ describe "#==" do
90
+ it "is true for same types" do
91
+ expect(as1).to eq(as2)
92
+ end
93
+
94
+ it "is true for a type and its string representation" do
95
+ expect(as1).to eq("as")
96
+ end
97
+
98
+ it "is false for different types" do
99
+ expect(as1).to_not eq(aas)
100
+ end
101
+
102
+ it "is false for a type and a different string" do
103
+ expect(as1).to_not eq("aas")
104
+ end
105
+ end
106
+
107
+ describe "#eql?" do
108
+ it "is true for same types" do
109
+ expect(as1).to eql(as2)
110
+ end
111
+
112
+ it "is false for a type and its string representation" do
113
+ expect(as1).to_not eql("as")
114
+ end
115
+
116
+ it "is false for different types" do
117
+ expect(as1).to_not eql(aas)
118
+ end
119
+
120
+ it "is false for a type and a different string" do
121
+ expect(as1).to_not eql("aas")
122
+ end
123
+ end
124
+
125
+ describe "#<<" do
126
+ it "raises if the argument is not a Type" do
127
+ t = DBus::Type.new(DBus::Type::ARRAY)
128
+ expect { t << "s" }.to raise_error(ArgumentError)
129
+ end
130
+
131
+ # TODO: the following raise checks do not occur in practice, as there are
132
+ # parallel checks in the parses. The code could be simplified?
133
+ it "raises if adding too much to an array" do
134
+ t = DBus::Type.new(DBus::Type::ARRAY)
135
+ b = DBus::Type.new(DBus::Type::BOOLEAN)
136
+ t << b
137
+ expect { t << b }.to raise_error(DBus::Type::SignatureException)
138
+ end
139
+
140
+ it "raises if adding too much to a dict_entry" do
141
+ t = DBus::Type.new(DBus::Type::DICT_ENTRY, abstract: true)
142
+ b = DBus::Type.new(DBus::Type::BOOLEAN)
143
+ t << b
144
+ t << b
145
+ expect { t << b }.to raise_error(DBus::Type::SignatureException)
146
+ end
147
+
148
+ it "raises if adding to a non-container" do
149
+ t = DBus::Type.new(DBus::Type::STRING)
150
+ b = DBus::Type.new(DBus::Type::BOOLEAN)
151
+ expect { t << b }.to raise_error(DBus::Type::SignatureException)
152
+
153
+ t = DBus::Type.new(DBus::Type::VARIANT)
154
+ expect { t << b }.to raise_error(DBus::Type::SignatureException)
155
+ end
156
+ end
157
+
158
+ describe DBus::Type::Array do
159
+ describe ".[]" do
160
+ it "takes Type argument" do
161
+ t = DBus::Type::Array[DBus::Type.new("s")]
162
+ expect(t.to_s).to eq "as"
163
+ end
164
+
165
+ it "takes 's':String argument" do
166
+ t = DBus::Type::Array["s"]
167
+ expect(t.to_s).to eq "as"
168
+ end
169
+
170
+ it "takes String:Class argument" do
171
+ t = DBus::Type::Array[String]
172
+ expect(t.to_s).to eq "as"
173
+ end
174
+
175
+ it "rejects Integer:Class argument" do
176
+ expect { DBus::Type::Array[Integer] }.to raise_error(ArgumentError)
177
+ end
178
+
179
+ it "rejects /./:Regexp argument" do
180
+ expect { DBus::Type::Array[/./] }.to raise_error(ArgumentError)
181
+ end
182
+ end
183
+ end
184
+
185
+ describe DBus::Type::Hash do
186
+ describe ".[]" do
187
+ it "takes Type arguments" do
188
+ t = DBus::Type::Hash[DBus::Type.new("s"), DBus::Type.new("v")]
189
+ expect(t.to_s).to eq "a{sv}"
190
+ end
191
+
192
+ it "takes 's':String arguments" do
193
+ t = DBus::Type::Hash["s", "v"]
194
+ expect(t.to_s).to eq "a{sv}"
195
+ end
196
+
197
+ it "takes String:Class argument" do
198
+ t = DBus::Type::Hash[String, DBus::Type::VARIANT]
199
+ expect(t.to_s).to eq "a{sv}"
200
+ end
201
+ end
202
+ end
203
+
204
+ describe DBus::Type::Struct do
205
+ describe ".[]" do
206
+ it "takes Type arguments" do
207
+ t = DBus::Type::Struct[DBus::Type.new("s"), DBus::Type.new("v")]
208
+ expect(t.to_s).to eq "(sv)"
209
+ end
210
+
211
+ it "takes 's':String arguments" do
212
+ t = DBus::Type::Struct["s", "v"]
213
+ expect(t.to_s).to eq "(sv)"
214
+ end
215
+
216
+ it "takes String:Class argument" do
217
+ t = DBus::Type::Struct[String, DBus::Type::VARIANT]
218
+ expect(t.to_s).to eq "(sv)"
219
+ end
220
+
221
+ it "raises on no arguments" do
222
+ expect { DBus::Type::Struct[] }.to raise_error(ArgumentError)
223
+ end
224
+ end
225
+ end
226
+ end
82
227
  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.beta4
4
+ version: 0.18.0.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby DBus Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rexml
@@ -202,7 +202,7 @@ homepage: https://github.com/mvidner/ruby-dbus
202
202
  licenses:
203
203
  - LGPL-2.1
204
204
  metadata: {}
205
- post_install_message:
205
+ post_install_message:
206
206
  rdoc_options: []
207
207
  require_paths:
208
208
  - lib
@@ -217,9 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  - !ruby/object:Gem::Version
218
218
  version: 1.3.1
219
219
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.7.6.3
222
- signing_key:
220
+ rubygems_version: 3.3.0.dev
221
+ signing_key:
223
222
  specification_version: 4
224
223
  summary: Ruby module for interaction with D-Bus
225
224
  test_files: []