ruby-dbus 0.16.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +160 -0
  3. data/README.md +3 -5
  4. data/Rakefile +18 -8
  5. data/VERSION +1 -1
  6. data/doc/Reference.md +106 -7
  7. data/examples/doc/_extract_examples +7 -0
  8. data/examples/gdbus/gdbus +31 -24
  9. data/examples/no-introspect/nm-test.rb +2 -0
  10. data/examples/no-introspect/tracker-test.rb +3 -1
  11. data/examples/rhythmbox/playpause.rb +2 -1
  12. data/examples/service/call_service.rb +2 -1
  13. data/examples/service/complex-property.rb +21 -0
  14. data/examples/service/service_newapi.rb +1 -1
  15. data/examples/simple/call_introspect.rb +1 -0
  16. data/examples/simple/get_id.rb +2 -1
  17. data/examples/simple/properties.rb +2 -0
  18. data/examples/utils/listnames.rb +1 -0
  19. data/examples/utils/notify.rb +1 -0
  20. data/lib/dbus/api_options.rb +9 -0
  21. data/lib/dbus/auth.rb +20 -15
  22. data/lib/dbus/bus.rb +123 -75
  23. data/lib/dbus/bus_name.rb +12 -8
  24. data/lib/dbus/core_ext/class/attribute.rb +1 -1
  25. data/lib/dbus/data.rb +821 -0
  26. data/lib/dbus/emits_changed_signal.rb +83 -0
  27. data/lib/dbus/error.rb +4 -2
  28. data/lib/dbus/introspect.rb +132 -31
  29. data/lib/dbus/logger.rb +3 -1
  30. data/lib/dbus/marshall.rb +247 -296
  31. data/lib/dbus/matchrule.rb +16 -16
  32. data/lib/dbus/message.rb +44 -37
  33. data/lib/dbus/message_queue.rb +16 -10
  34. data/lib/dbus/object.rb +358 -24
  35. data/lib/dbus/object_path.rb +11 -6
  36. data/lib/dbus/proxy_object.rb +22 -1
  37. data/lib/dbus/proxy_object_factory.rb +13 -7
  38. data/lib/dbus/proxy_object_interface.rb +63 -30
  39. data/lib/dbus/raw_message.rb +91 -0
  40. data/lib/dbus/type.rb +318 -86
  41. data/lib/dbus/xml.rb +32 -17
  42. data/lib/dbus.rb +14 -7
  43. data/ruby-dbus.gemspec +7 -3
  44. data/spec/async_spec.rb +2 -0
  45. data/spec/binding_spec.rb +2 -0
  46. data/spec/bus_and_xml_backend_spec.rb +2 -0
  47. data/spec/bus_driver_spec.rb +2 -0
  48. data/spec/bus_name_spec.rb +3 -1
  49. data/spec/bus_spec.rb +2 -0
  50. data/spec/byte_array_spec.rb +2 -0
  51. data/spec/client_robustness_spec.rb +4 -2
  52. data/spec/data/marshall.yaml +1667 -0
  53. data/spec/data_spec.rb +673 -0
  54. data/spec/emits_changed_signal_spec.rb +58 -0
  55. data/spec/err_msg_spec.rb +2 -0
  56. data/spec/introspect_xml_parser_spec.rb +2 -0
  57. data/spec/introspection_spec.rb +2 -0
  58. data/spec/main_loop_spec.rb +3 -1
  59. data/spec/node_spec.rb +23 -0
  60. data/spec/object_path_spec.rb +3 -0
  61. data/spec/object_spec.rb +138 -0
  62. data/spec/packet_marshaller_spec.rb +41 -0
  63. data/spec/packet_unmarshaller_spec.rb +248 -0
  64. data/spec/property_spec.rb +192 -5
  65. data/spec/proxy_object_spec.rb +2 -0
  66. data/spec/server_robustness_spec.rb +2 -0
  67. data/spec/server_spec.rb +2 -0
  68. data/spec/service_newapi.rb +70 -70
  69. data/spec/session_bus_spec.rb +3 -1
  70. data/spec/session_bus_spec_manual.rb +2 -0
  71. data/spec/signal_spec.rb +5 -3
  72. data/spec/spec_helper.rb +37 -9
  73. data/spec/thread_safety_spec.rb +2 -0
  74. data/spec/tools/dbus-limited-session.conf +4 -0
  75. data/spec/type_spec.rb +214 -6
  76. data/spec/value_spec.rb +16 -1
  77. data/spec/variant_spec.rb +4 -2
  78. data/spec/zzz_quit_spec.rb +16 -0
  79. metadata +34 -8
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative "spec_helper"
3
5
  require "dbus"
4
6
 
7
+ # FIXME: factor out DBus::TestFixtures::Value in spec_helper
8
+ require "ostruct"
9
+ require "yaml"
10
+
11
+ data_dir = File.expand_path("data", __dir__)
12
+ marshall_yaml_s = File.read("#{data_dir}/marshall.yaml")
13
+ marshall_yaml = YAML.safe_load(marshall_yaml_s)
14
+
5
15
  describe "PropertyTest" do
6
16
  before(:each) do
7
- session_bus = DBus::ASessionBus.new
8
- @svc = session_bus.service("org.ruby.service")
17
+ @session_bus = DBus::ASessionBus.new
18
+ @svc = @session_bus.service("org.ruby.service")
9
19
  @obj = @svc.object("/org/ruby/MyInstance")
10
20
  @iface = @obj["org.ruby.SampleInterface"]
11
21
  end
@@ -21,6 +31,10 @@ describe "PropertyTest" do
21
31
  expect(iface["ReadMe"]).to eq("READ ME")
22
32
  end
23
33
 
34
+ it "gets an error when reading a property whose implementation raises" do
35
+ expect { @iface["Explosive"] }.to raise_error(DBus::Error, /Something failed/)
36
+ end
37
+
24
38
  it "tests property nonreading" do
25
39
  expect { @iface["WriteMe"] }.to raise_error(DBus::Error, /not readable/)
26
40
  end
@@ -31,7 +45,7 @@ describe "PropertyTest" do
31
45
  end
32
46
 
33
47
  # https://github.com/mvidner/ruby-dbus/pull/19
34
- it "tests service select timeout" do
48
+ it "tests service select timeout", slow: true do
35
49
  @iface["ReadOrWriteMe"] = "VALUE"
36
50
  expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
37
51
  # wait for the service to become idle
@@ -46,7 +60,7 @@ describe "PropertyTest" do
46
60
 
47
61
  it "tests get all" do
48
62
  all = @iface.all_properties
49
- expect(all.keys.sort).to eq(["ReadMe", "ReadOrWriteMe"])
63
+ expect(all.keys.sort).to eq(["MyArray", "MyByte", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
50
64
  end
51
65
 
52
66
  it "tests get all on a V1 object" do
@@ -54,7 +68,7 @@ describe "PropertyTest" do
54
68
  iface = obj["org.ruby.SampleInterface"]
55
69
 
56
70
  all = iface.all_properties
57
- expect(all.keys.sort).to eq(["ReadMe", "ReadOrWriteMe"])
71
+ expect(all.keys.sort).to eq(["MyArray", "MyByte", "MyDict", "MyStruct", "MyVariant", "ReadMe", "ReadOrWriteMe"])
58
72
  end
59
73
 
60
74
  it "tests unknown property reading" do
@@ -64,4 +78,177 @@ describe "PropertyTest" do
64
78
  it "tests unknown property writing" do
65
79
  expect { @iface["Spoon"] = "FPRK" }.to raise_error(DBus::Error, /not found/)
66
80
  end
81
+
82
+ it "errors for a property on an unknown interface" do
83
+ # our idiomatic way would error out on interface lookup already,
84
+ # so do it the low level way
85
+ prop_if = @obj[DBus::PROPERTY_INTERFACE]
86
+ expect { prop_if.Get("org.ruby.NoSuchInterface", "SomeProperty") }.to raise_error(DBus::Error) do |e|
87
+ expect(e.name).to match(/UnknownProperty/)
88
+ expect(e.message).to match(/no such interface/)
89
+ end
90
+ end
91
+
92
+ it "errors for GetAll on an unknown interface" do
93
+ # no idiomatic way?
94
+ # so do it the low level way
95
+ prop_if = @obj[DBus::PROPERTY_INTERFACE]
96
+ expect { prop_if.GetAll("org.ruby.NoSuchInterface") }.to raise_error(DBus::Error) do |e|
97
+ expect(e.name).to match(/UnknownProperty/)
98
+ expect(e.message).to match(/no such interface/)
99
+ end
100
+ end
101
+
102
+ it "receives a PropertiesChanged signal", slow: true do
103
+ received = {}
104
+
105
+ # TODO: for client side, provide a helper on_properties_changed,
106
+ # or automate it even more in ProxyObject, ProxyObjectInterface
107
+ prop_if = @obj[DBus::PROPERTY_INTERFACE]
108
+ prop_if.on_signal("PropertiesChanged") do |_interface_name, changed_props, _invalidated_props|
109
+ received.merge!(changed_props)
110
+ end
111
+
112
+ @iface["ReadOrWriteMe"] = "VALUE"
113
+ @iface.SetTwoProperties("REAMDE", 255)
114
+
115
+ # loop to process the signal. complicated :-( see signal_spec.rb
116
+ loop = DBus::Main.new
117
+ loop << @session_bus
118
+ quitter = Thread.new do
119
+ sleep 1
120
+ loop.quit
121
+ end
122
+ loop.run
123
+ # quitter has told loop.run to quit
124
+ quitter.join
125
+
126
+ expect(received["ReadOrWriteMe"]).to eq("VALUE")
127
+ expect(received["ReadMe"]).to eq("REAMDE")
128
+ expect(received["MyByte"]).to eq(255)
129
+ end
130
+
131
+ context "a struct-typed property" do
132
+ it "gets read as a struct, not an array (#97)" do
133
+ struct = @iface["MyStruct"]
134
+ expect(struct).to be_frozen
135
+ end
136
+
137
+ it "Get returns the correctly typed value (check with dbus-send)" do
138
+ # As big as the DBus::Data branch is,
139
+ # it still does not handle the :exact mode on the client/proxy side.
140
+ # So we resort to parsing dbus-send output.
141
+ cmd = "dbus-send --print-reply " \
142
+ "--dest=org.ruby.service " \
143
+ "/org/ruby/MyInstance " \
144
+ "org.freedesktop.DBus.Properties.Get " \
145
+ "string:org.ruby.SampleInterface " \
146
+ "string:MyStruct"
147
+ reply = `#{cmd}`
148
+ expect(reply).to match(/variant\s+struct {\s+string "three"\s+string "strings"\s+string "in a struct"\s+}/)
149
+ end
150
+
151
+ it "GetAll returns the correctly typed value (check with dbus-send)" do
152
+ cmd = "dbus-send --print-reply " \
153
+ "--dest=org.ruby.service " \
154
+ "/org/ruby/MyInstance " \
155
+ "org.freedesktop.DBus.Properties.GetAll " \
156
+ "string:org.ruby.SampleInterface "
157
+ reply = `#{cmd}`
158
+ expect(reply).to match(/variant\s+struct {\s+string "three"\s+string "strings"\s+string "in a struct"\s+}/)
159
+ end
160
+ end
161
+
162
+ context "an array-typed property" do
163
+ it "gets read as an array" do
164
+ val = @iface["MyArray"]
165
+ expect(val).to eq([42, 43])
166
+ end
167
+ end
168
+
169
+ context "a dict-typed property" do
170
+ it "gets read as a hash" do
171
+ val = @iface["MyDict"]
172
+ expect(val).to eq({
173
+ "one" => 1,
174
+ "two" => "dva",
175
+ "three" => [3, 3, 3]
176
+ })
177
+ end
178
+
179
+ it "Get returns the correctly typed value (check with dbus-send)" do
180
+ cmd = "dbus-send --print-reply " \
181
+ "--dest=org.ruby.service " \
182
+ "/org/ruby/MyInstance " \
183
+ "org.freedesktop.DBus.Properties.Get " \
184
+ "string:org.ruby.SampleInterface " \
185
+ "string:MyDict"
186
+ reply = `#{cmd}`
187
+ # a bug about variant nesting lead to a "variant variant int32 1" value
188
+ match_rx = /variant \s+ array \s \[ \s+
189
+ dict \s entry\( \s+
190
+ string \s "one" \s+
191
+ variant \s+ int32 \s 1 \s+
192
+ \)/x
193
+ expect(reply).to match(match_rx)
194
+ end
195
+ end
196
+
197
+ context "a variant-typed property" do
198
+ it "gets read at all" do
199
+ obj = @svc.object("/org/ruby/MyDerivedInstance")
200
+ iface = obj["org.ruby.SampleInterface"]
201
+ val = iface["MyVariant"]
202
+ expect(val).to eq([42, 43])
203
+ end
204
+ end
205
+
206
+ context "a byte-typed property" do
207
+ # Slightly advanced RSpec:
208
+ # https://rspec.info/documentation/3.9/rspec-expectations/RSpec/Matchers.html#satisfy-instance_method
209
+ let(:a_byte_in_a_variant) do
210
+ satisfying { |x| x.is_a?(DBus::Data::Variant) && x.member_type.to_s == DBus::Type::BYTE }
211
+ # ^ This formatting keeps the matcher on a single line
212
+ # which enables RSpec to cite it if it fails, instead of saying "block".
213
+ end
214
+
215
+ let(:prop_iface) { @obj[DBus::PROPERTY_INTERFACE] }
216
+
217
+ it "gets set with a correct type (#108)" do
218
+ expect(prop_iface).to receive(:Set).with(
219
+ "org.ruby.SampleInterface",
220
+ "MyByte",
221
+ a_byte_in_a_variant
222
+ )
223
+ @iface["MyByte"] = 1
224
+ end
225
+
226
+ it "gets set with a correct type (#108), when using the DBus.variant workaround" do
227
+ expect(prop_iface).to receive(:Set).with(
228
+ "org.ruby.SampleInterface",
229
+ "MyByte",
230
+ a_byte_in_a_variant
231
+ )
232
+ @iface["MyByte"] = DBus.variant("y", 1)
233
+ end
234
+ end
235
+
236
+ context "marshall.yaml round-trip via a VARIANT property" do
237
+ marshall_yaml.each do |test|
238
+ t = OpenStruct.new(test)
239
+ next if t.val.nil?
240
+
241
+ # Round trips do not work yet because the properties
242
+ # must present a plain Ruby value so the exact D-Bus type is lost.
243
+ # Round trips will work once users can declare accepting DBus::Data
244
+ # in properties and method arguments.
245
+ it "Sets #{t.sig.inspect}:#{t.val.inspect} and Gets something back" do
246
+ before = DBus::Data.make_typed(t.sig, t.val)
247
+ expect { @iface["MyVariant"] = before }.to_not raise_error
248
+ expect { _after = @iface["MyVariant"] }.to_not raise_error
249
+ # round-trip:
250
+ # expect(after).to eq(before.value)
251
+ end
252
+ end
253
+ end
67
254
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative "spec_helper"
3
5
  require "dbus"
4
6
 
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  # Test that a server survives various error cases
3
5
  require_relative "spec_helper"
4
6
  require "dbus"
data/spec/server_spec.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  # Test that a server survives various error cases
3
5
  require_relative "spec_helper"
4
6
  require "dbus"
@@ -1,25 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "spec_helper"
5
5
  SimpleCov.command_name "Service Tests" if Object.const_defined? "SimpleCov"
6
6
  # find the library without external help
7
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
7
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
8
8
 
9
9
  require "dbus"
10
10
 
11
- PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties".freeze
11
+ PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"
12
12
 
13
13
  class Test < DBus::Object
14
- INTERFACE = "org.ruby.SampleInterface".freeze
14
+ Point2D = Struct.new(:x, :y)
15
+
16
+ attr_writer :main_loop
17
+
18
+ INTERFACE = "org.ruby.SampleInterface"
15
19
  def initialize(path)
16
20
  super path
17
21
  @read_me = "READ ME"
18
22
  @read_or_write_me = "READ OR WRITE ME"
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
+ # 201 is a RET instruction for ZX Spectrum which has turned 40 recently
32
+ @my_byte = 201
33
+ @main_loop = nil
19
34
  end
20
35
 
21
36
  # Create an interface aggregating all upcoming dbus_method defines.
22
37
  dbus_interface INTERFACE do
38
+ dbus_method :quit, "" do
39
+ @main_loop&.quit
40
+ end
41
+
23
42
  dbus_method :hello, "in name:s, in name2:s" do |name, name2|
24
43
  puts "hello(#{name}, #{name2})"
25
44
  end
@@ -59,6 +78,52 @@ class Test < DBus::Object
59
78
  dbus_method :mirror_byte_array, "in bytes:ay, out mirrored:ay" do |bytes|
60
79
  [bytes]
61
80
  end
81
+
82
+ dbus_method :Coordinates, "out coords:(dd)" do
83
+ coords = [3.0, 4.0].freeze
84
+ [coords]
85
+ end
86
+
87
+ dbus_method :Coordinates2, "out coords:(dd)" do
88
+ coords = Point2D.new(5.0, 12.0)
89
+ [coords]
90
+ end
91
+
92
+ # Properties:
93
+ # ReadMe:string, returns "READ ME" at first, then what WriteMe received
94
+ # WriteMe:string
95
+ # ReadOrWriteMe:string, returns "READ OR WRITE ME" at first
96
+ dbus_attr_accessor :read_or_write_me, "s"
97
+ dbus_attr_reader :read_me, "s"
98
+
99
+ def write_me=(value)
100
+ @read_me = value
101
+ end
102
+ dbus_writer :write_me, "s"
103
+
104
+ dbus_attr_writer :password, "s"
105
+
106
+ # a property that raises when client tries to read it
107
+ def explosive
108
+ raise "Something failed"
109
+ end
110
+ dbus_reader :explosive, "s"
111
+
112
+ dbus_attr_accessor :my_struct, "(sss)"
113
+ dbus_attr_accessor :my_array, "aq"
114
+ dbus_attr_accessor :my_dict, "a{sv}"
115
+ dbus_attr_accessor :my_variant, "v"
116
+
117
+ dbus_attr_accessor :my_byte, "y"
118
+
119
+ # to test dbus_properties_changed
120
+ dbus_method :SetTwoProperties, "in read_me:s, in byte:y" do |read_me, byte|
121
+ @read_me = read_me
122
+ @my_byte = byte
123
+ dbus_properties_changed(INTERFACE,
124
+ { "ReadMe" => read_me, "MyByte" => byte },
125
+ [])
126
+ end
62
127
  end
63
128
 
64
129
  # closing and reopening the same interface
@@ -118,72 +183,6 @@ class Test < DBus::Object
118
183
  dbus_signal :LongTaskStart
119
184
  dbus_signal :LongTaskEnd
120
185
  end
121
-
122
- # Properties:
123
- # ReadMe:string, returns "READ ME" at first, then what WriteMe received
124
- # WriteMe:string
125
- # ReadOrWriteMe:string, returns "READ OR WRITE ME" at first
126
- dbus_interface PROPERTY_INTERFACE do
127
- dbus_method :Get, "in interface:s, in propname:s, out value:v" do |interface, propname|
128
- unless interface == INTERFACE
129
- raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"),
130
- "Interface '#{interface}' not found on object '#{@path}'"
131
- end
132
-
133
- case propname
134
- when "ReadMe"
135
- [@read_me]
136
- when "ReadOrWriteMe"
137
- [@read_or_write_me]
138
- when "WriteMe"
139
- raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"),
140
- "Property '#{interface}.#{propname}' (on object '#{@path}') is not readable"
141
- else
142
- # what should happen for unknown properties
143
- # plasma: InvalidArgs (propname), UnknownInterface (interface)
144
- raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"),
145
- "Property '#{interface}.#{propname}' not found on object '#{@path}'"
146
- end
147
- end
148
-
149
- dbus_method :Set, "in interface:s, in propname:s, in value:v" do |interface, propname, value|
150
- unless interface == INTERFACE
151
- raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"),
152
- "Interface '#{interface}' not found on object '#{@path}'"
153
- end
154
-
155
- case propname
156
- when "ReadMe"
157
- raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"),
158
- "Property '#{interface}.#{propname}' (on object '#{@path}') is not writable"
159
- when "ReadOrWriteMe"
160
- @read_or_write_me = value
161
- self.PropertiesChanged(interface, { propname => value }, [])
162
- when "WriteMe"
163
- @read_me = value
164
- self.PropertiesChanged(interface, { "ReadMe" => value }, [])
165
- else
166
- raise DBus.error("org.freedesktop.DBus.Error.InvalidArgs"),
167
- "Property '#{interface}.#{propname}' not found on object '#{@path}'"
168
- end
169
- end
170
-
171
- dbus_method :GetAll, "in interface:s, out value:a{sv}" do |interface|
172
- unless interface == INTERFACE
173
- raise DBus.error("org.freedesktop.DBus.Error.UnknownInterface"),
174
- "Interface '#{interface}' not found on object '#{@path}'"
175
- end
176
-
177
- [
178
- {
179
- "ReadMe" => @read_me,
180
- "ReadOrWriteMe" => @read_or_write_me
181
- }
182
- ]
183
- end
184
-
185
- dbus_signal :PropertiesChanged, "interface:s, changed_properties:a{sv}, invalidated_properties:as"
186
- end
187
186
  end
188
187
 
189
188
  class Derived < Test
@@ -224,6 +223,7 @@ end
224
223
  puts "listening, with ruby-#{RUBY_VERSION}"
225
224
  main = DBus::Main.new
226
225
  main << bus
226
+ myobj.main_loop = main
227
227
  begin
228
228
  main.run
229
229
  rescue SystemCallError
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative "spec_helper"
3
5
  require "dbus"
4
6
 
@@ -23,7 +25,7 @@ describe DBus::ASessionBus do
23
25
 
24
26
  before do
25
27
  # mocks of files for address_from_file method
26
- machine_id_path = File.expand_path("/etc/machine-id", __FILE__)
28
+ machine_id_path = File.expand_path("/etc/machine-id", __dir__)
27
29
  expect(Dir).to receive(:[]).with(any_args) { [machine_id_path] }
28
30
  expect(File).to receive(:read).with(machine_id_path) { "baz" }
29
31
  expect(File).to receive(:exist?).with(session_bus_file_path) { true }
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative "spec_helper"
3
5
  require "dbus"
4
6
 
data/spec/signal_spec.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  # Test the signal handlers
3
5
  require_relative "spec_helper"
4
6
  require "dbus"
@@ -29,7 +31,7 @@ describe "SignalHandlerTest" do
29
31
  end
30
32
 
31
33
  # testing for commit 017c83 (kkaempf)
32
- it "tests overriding a handler" do
34
+ it "tests overriding a handler", slow: true do
33
35
  DBus.logger.debug "Inside test_overriding_a_handler"
34
36
  counter = 0
35
37
 
@@ -52,7 +54,7 @@ describe "SignalHandlerTest" do
52
54
  expect(counter).to eq(1)
53
55
  end
54
56
 
55
- it "tests on signal overload" do
57
+ it "tests on signal overload", slow: true do
56
58
  DBus.logger.debug "Inside test_on_signal_overload"
57
59
  counter = 0
58
60
  started = false
@@ -74,7 +76,7 @@ describe "SignalHandlerTest" do
74
76
  expect { @intf.on_signal "to", "many", "yarrrrr!" }.to raise_error(ArgumentError)
75
77
  end
76
78
 
77
- it "is possible to add signal handlers from within handlers" do
79
+ it "is possible to add signal handlers from within handlers", slow: true do
78
80
  ended = false
79
81
  @intf.on_signal "LongTaskStart" do
80
82
  @intf.on_signal "LongTaskEnd" do
data/spec/spec_helper.rb CHANGED
@@ -1,28 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  coverage = if ENV["COVERAGE"]
2
4
  ENV["COVERAGE"] == "true"
3
5
  else
4
6
  # heuristics: enable for interactive builds (but not in OBS)
5
- # or in Travis
6
- ENV["DISPLAY"] || ENV["TRAVIS"]
7
+ ENV["DISPLAY"]
7
8
  end
8
9
 
9
10
  if coverage
10
11
  require "simplecov"
11
- SimpleCov.root File.expand_path("../..", __FILE__)
12
+ SimpleCov.root File.expand_path("..", __dir__)
12
13
 
13
14
  # do not cover specs
14
15
  SimpleCov.add_filter "_spec.rb"
15
16
  # do not cover the activesupport helpers
16
17
  SimpleCov.add_filter "/core_ext/"
18
+ # measure all if/else branches on a line
19
+ SimpleCov.enable_coverage :branch
17
20
 
18
- # use coveralls for on-line code coverage reporting at Travis CI
19
- if ENV["TRAVIS"]
20
- require "coveralls"
21
- end
22
21
  SimpleCov.start
22
+
23
+ # additionally use the LCOV format for on-line code coverage reporting at CI
24
+ if ENV["COVERAGE_LCOV"] == "true"
25
+ require "simplecov-lcov"
26
+
27
+ SimpleCov::Formatter::LcovFormatter.config do |c|
28
+ c.report_with_single_file = true
29
+ # this is the default Coveralls GitHub Action location
30
+ # https://github.com/marketplace/actions/coveralls-github-action
31
+ c.single_report_path = "coverage/lcov.info"
32
+ end
33
+
34
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
35
+ SimpleCov::Formatter::HTMLFormatter,
36
+ SimpleCov::Formatter::LcovFormatter
37
+ ]
38
+ end
23
39
  end
24
40
 
25
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
41
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
26
42
 
27
43
  if Object.const_defined? "RSpec"
28
44
  # http://betterspecs.org/#expect
@@ -36,7 +52,7 @@ end
36
52
  require "tempfile"
37
53
  require "timeout"
38
54
 
39
- TOPDIR = File.expand_path("../..", __FILE__)
55
+ TOPDIR = File.expand_path("..", __dir__)
40
56
 
41
57
  # path of config file for a private bus
42
58
  def config_file_path
@@ -104,3 +120,15 @@ def with_service_by_activation(&block)
104
120
 
105
121
  system "pkill -f #{exec}"
106
122
  end
123
+
124
+ # Make a binary string from readable YAML pieces; see data/marshall.yaml
125
+ def buffer_from_yaml(parts)
126
+ strings = parts.flatten.map do |part|
127
+ if part.is_a? Integer
128
+ part.chr
129
+ else
130
+ part
131
+ end
132
+ end
133
+ strings.join.force_encoding(Encoding::BINARY)
134
+ end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rspec
2
+ # frozen_string_literal: true
3
+
2
4
  # Test thread safety
3
5
  require_relative "spec_helper"
4
6
  require "dbus"
@@ -25,4 +25,8 @@
25
25
  Instead, lower some so that we can test resource leaks. -->
26
26
  <limit name="max_match_rules_per_connection">50</limit><!-- was 512 -->
27
27
 
28
+ <!--
29
+ dbus-daemon[1700]: [session uid=1001 pid=1700] Unable to set up new connection: Failed to get AppArmor confinement information of socket peer: Protocol not available
30
+ -->
31
+ <apparmor mode="disabled"/>
28
32
  </busconfig>