ruby-dbus 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS +8 -0
  3. data/README.md +41 -4
  4. data/Rakefile +15 -16
  5. data/VERSION +1 -1
  6. data/lib/dbus.rb +18 -14
  7. data/lib/dbus/bus.rb +32 -168
  8. data/lib/dbus/error.rb +4 -2
  9. data/lib/dbus/export.rb +3 -2
  10. data/lib/dbus/introspect.rb +0 -294
  11. data/lib/dbus/marshall.rb +1 -1
  12. data/lib/dbus/message.rb +8 -0
  13. data/lib/dbus/message_queue.rb +166 -0
  14. data/lib/dbus/proxy_object.rb +149 -0
  15. data/lib/dbus/proxy_object_factory.rb +41 -0
  16. data/lib/dbus/proxy_object_interface.rb +128 -0
  17. data/ruby-dbus.gemspec +1 -0
  18. data/test/{async_test.rb → async_spec.rb} +10 -11
  19. data/test/{binding_test.rb → binding_spec.rb} +23 -25
  20. data/test/bus_and_xml_backend_spec.rb +39 -0
  21. data/test/bus_driver_spec.rb +20 -0
  22. data/test/{bus_test.rb → bus_spec.rb} +8 -7
  23. data/test/byte_array_spec.rb +38 -0
  24. data/test/err_msg_spec.rb +42 -0
  25. data/test/{introspect_xml_parser_test.rb → introspect_xml_parser_spec.rb} +5 -6
  26. data/test/introspection_spec.rb +32 -0
  27. data/test/{main_loop_test.rb → main_loop_spec.rb} +10 -7
  28. data/test/property_spec.rb +53 -0
  29. data/test/server_robustness_spec.rb +66 -0
  30. data/test/{server_test.rb → server_spec.rb} +10 -11
  31. data/test/service_newapi.rb +1 -1
  32. data/test/session_bus_spec_manual.rb +15 -0
  33. data/test/{signal_test.rb → signal_spec.rb} +13 -14
  34. data/test/spec_helper.rb +33 -0
  35. data/test/{thread_safety_test.rb → thread_safety_spec.rb} +5 -6
  36. data/test/type_spec.rb +19 -0
  37. data/test/{value_test.rb → value_spec.rb} +23 -24
  38. data/test/variant_spec.rb +66 -0
  39. metadata +40 -22
  40. data/test/bus_and_xml_backend_test.rb +0 -43
  41. data/test/bus_driver_test.rb +0 -19
  42. data/test/byte_array_test.rb +0 -42
  43. data/test/err_msg_test.rb +0 -59
  44. data/test/introspection_test.rb +0 -32
  45. data/test/property_test.rb +0 -65
  46. data/test/server_robustness_test.rb +0 -73
  47. data/test/session_bus_test_manual.rb +0 -17
  48. data/test/test_helper.rb +0 -14
  49. data/test/type_test.rb +0 -23
  50. data/test/variant_test.rb +0 -67
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rspec
2
+ # Test the bus class
3
+ require_relative "spec_helper"
4
+
5
+ require 'rubygems'
6
+ require 'nokogiri'
7
+ require "dbus"
8
+
9
+ describe "BusAndXmlBackendTest" do
10
+ before(:each) do
11
+ @bus = DBus::ASessionBus.new
12
+ end
13
+
14
+ it "tests introspection reading rexml" do
15
+ DBus::IntrospectXMLParser.backend = DBus::IntrospectXMLParser::REXMLParser
16
+ @svc = @bus.service("org.ruby.service")
17
+ obj = @svc.object("/org/ruby/MyInstance")
18
+ obj.default_iface = 'org.ruby.SampleInterface'
19
+ obj.introspect
20
+ # "should respond to :the_answer"
21
+ expect(obj.the_answer[0]).to eq(42)
22
+ # "should work with multiple interfaces"
23
+ expect(obj["org.ruby.AnotherInterface"].Reverse('foo')[0]).to eq("oof")
24
+ end
25
+
26
+ it "tests introspection reading nokogiri" do
27
+ # peek inside the object to see if a cleanup step worked or not
28
+ DBus::IntrospectXMLParser.backend = DBus::IntrospectXMLParser::NokogiriParser
29
+ @svc = @bus.service("org.ruby.service")
30
+ obj = @svc.object("/org/ruby/MyInstance")
31
+ obj.default_iface = 'org.ruby.SampleInterface'
32
+ obj.introspect
33
+ # "should respond to :the_answer"
34
+ expect(obj.the_answer[0]).to eq(42)
35
+ # "should work with multiple interfaces"
36
+ expect(obj["org.ruby.AnotherInterface"].Reverse('foo')[0]).to eq("oof")
37
+ end
38
+
39
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe DBus::Service do
6
+ let(:bus) { DBus::ASessionBus.new }
7
+
8
+ describe "#exists?" do
9
+ it "is true for an existing service" do
10
+ svc = bus.service("org.ruby.service")
11
+ svc.object("/").introspect # must activate the service first :-/
12
+ expect(svc.exists?).to be_true
13
+ end
14
+
15
+ it "is false for a nonexisting service" do
16
+ svc = bus.service("org.ruby.nosuchservice")
17
+ expect(svc.exists?).to be_false
18
+ end
19
+ end
20
+ end
@@ -1,19 +1,20 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # Test the bus class
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
3
+ require_relative "spec_helper"
4
+
5
5
  require "dbus"
6
6
 
7
- class BusTest < Test::Unit::TestCase
8
- def setup
7
+ describe "BusTest" do
8
+ before(:each) do
9
9
  @bus = DBus::ASessionBus.new
10
10
  @svc = @bus.service("org.ruby.service")
11
11
  @svc.object("/").introspect
12
12
  end
13
13
 
14
- def test_introspection_not_leaking
14
+ it "tests introspection not leaking" do
15
15
  # peek inside the object to see if a cleanup step worked or not
16
16
  some_hash = @bus.instance_eval { @method_call_replies || Hash.new }
17
- assert_equal 0, some_hash.size, "there are leftover method handlers"
17
+ # fail: "there are leftover method handlers"
18
+ expect(some_hash.size).to eq(0)
18
19
  end
19
20
  end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+
4
+ require "dbus"
5
+
6
+ describe "ByteArrayTest" do
7
+ before(:each) do
8
+ @bus = DBus::ASessionBus.new
9
+ @svc = @bus.service("org.ruby.service")
10
+ @obj = @svc.object("/org/ruby/MyInstance")
11
+ @obj.introspect
12
+ @obj.default_iface = "org.ruby.SampleInterface"
13
+ end
14
+
15
+
16
+ it "tests passing byte array" do
17
+ data = [0, 77, 255]
18
+ result = @obj.mirror_byte_array(data).first
19
+ expect(result).to eq(data)
20
+ end
21
+
22
+ it "tests passing byte array from string" do
23
+ data = "AAA"
24
+ result = @obj.mirror_byte_array(data).first
25
+ expect(result).to eq([65, 65, 65])
26
+ end
27
+
28
+ it "tests passing byte array from hash" do
29
+ # Hash is an Enumerable, but is caught earlier
30
+ data = { "this will" => "fail" }
31
+ expect { @obj.mirror_byte_array(data).first }.to raise_error(DBus::TypeException)
32
+ end
33
+
34
+ it "tests passing byte array from nonenumerable" do
35
+ data = Time.now
36
+ expect { @obj.mirror_byte_array(data).first }.to raise_error(DBus::TypeException)
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env rspec
2
+ # should report it missing on org.ruby.SampleInterface
3
+ # (on object...) instead of on DBus::Proxy::ObjectInterface
4
+ require_relative "spec_helper"
5
+ require "dbus"
6
+
7
+ describe "ErrMsgTest" do
8
+ before(:each) do
9
+ session_bus = DBus::ASessionBus.new
10
+ svc = session_bus.service("org.ruby.service")
11
+ @obj = svc.object("/org/ruby/MyInstance")
12
+ @obj.introspect # necessary
13
+ @obj.default_iface = "org.ruby.SampleInterface"
14
+ end
15
+
16
+ it "tests report dbus interface" do
17
+ # a specific exception...
18
+ # mentioning DBus and the interface
19
+ expect { @obj.NoSuchMethod }.to raise_error(NameError, /DBus interface.*#{@obj.default_iface}/)
20
+ end
21
+
22
+ it "tests report short struct" do
23
+ expect { @obj.test_variant ["(ss)", ["too few"] ] }.to raise_error(DBus::TypeException, /1 elements but type info for 2/)
24
+ end
25
+
26
+ it "tests report long struct" do
27
+ expect { @obj.test_variant ["(ss)", ["a", "b", "too many"] ] }.to raise_error(DBus::TypeException, /3 elements but type info for 2/)
28
+ end
29
+
30
+ it "tests report nil" do
31
+ nils = [
32
+ ["(s)", [nil] ], # would get disconnected
33
+ ["i", nil ],
34
+ ["a{ss}", {"foo" => nil} ],
35
+ ]
36
+ nils.each do |has_nil|
37
+ # TODO want backtrace from the perspective of the caller:
38
+ # rescue/reraise in send_sync?
39
+ expect { @obj.test_variant has_nil }.to raise_error(DBus::TypeException, /Cannot send nil/)
40
+ end
41
+ end
42
+ end
@@ -1,10 +1,9 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path("../test_helper", __FILE__)
3
- require "test/unit"
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
4
3
  require "dbus"
5
4
 
6
- class IntrospectXMLParserTest < Test::Unit::TestCase
7
- def test_split_interfaces
5
+ describe "IntrospectXMLParserTest" do
6
+ it "tests split interfaces" do
8
7
  xml = <<EOS
9
8
  <node>
10
9
  <interface name="org.example.Foo">
@@ -22,6 +21,6 @@ EOS
22
21
  interfaces, _ = DBus::IntrospectXMLParser.new(xml).parse
23
22
 
24
23
  foo = interfaces.find {|i| i.name == "org.example.Foo" }
25
- assert_equal 2, foo.methods.keys.size
24
+ expect(foo.methods.keys.size).to eq(2)
26
25
  end
27
26
  end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe "IntrospectionTest" do
6
+ before(:each) do
7
+ session_bus = DBus::ASessionBus.new
8
+ svc = session_bus.service("org.ruby.service")
9
+ @obj = svc.object("/org/ruby/MyInstance")
10
+ @obj.introspect
11
+ @obj.default_iface = "org.ruby.SampleInterface"
12
+ end
13
+
14
+ it "tests wrong number of arguments" do
15
+ expect { @obj.test_variant "too","many","args" }.to raise_error(ArgumentError)
16
+ # not enough
17
+ expect { @obj.test_variant }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it "tests shortcut methods" do
21
+ @obj.default_iface = nil
22
+ expect(@obj.bounce_variant("varargs")).to eq(["varargs"])
23
+ # test for a duplicated method name
24
+ expect { @obj.the_answer }.to raise_error(NoMethodError)
25
+ # ensure istance methods of ProxyObject aren't overwritten by remote
26
+ # methods
27
+ expect { @obj.interfaces }.not_to raise_error
28
+
29
+ @obj.default_iface = "org.ruby.SampleInterface"
30
+ expect(@obj.the_answer).to eq([42])
31
+ end
32
+ end
@@ -1,11 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # Test the main loop
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
3
+ require_relative "spec_helper"
5
4
  require "dbus"
6
5
 
7
- class MainLoopTest < Test::Unit::TestCase
8
- def setup
6
+ describe "MainLoopTest" do
7
+ before(:each) do
9
8
  @session_bus = DBus::ASessionBus.new
10
9
  svc = @session_bus.service("org.ruby.service")
11
10
  @obj = svc.object("/org/ruby/MyInstance")
@@ -40,7 +39,7 @@ class MainLoopTest < Test::Unit::TestCase
40
39
  end
41
40
  end
42
41
 
43
- def test_loop_quit(delay = 1)
42
+ def test_loop_quit(delay)
44
43
  @obj.on_signal "LongTaskEnd" do
45
44
  DBus.logger.debug "Telling loop to quit"
46
45
  @loop.quit
@@ -72,8 +71,12 @@ class MainLoopTest < Test::Unit::TestCase
72
71
  @obj.on_signal "LongTaskEnd"
73
72
  end
74
73
 
74
+ it "tests loop quit" do
75
+ test_loop_quit 1
76
+ end
77
+
75
78
  # https://bugzilla.novell.com/show_bug.cgi?id=537401
76
- def test_loop_drained_socket
79
+ it "tests loop drained socket" do
77
80
  test_loop_quit 0
78
81
  end
79
82
  end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe "PropertyTest" do
6
+ before(:each) do
7
+ session_bus = DBus::ASessionBus.new
8
+ svc = session_bus.service("org.ruby.service")
9
+ @obj = svc.object("/org/ruby/MyInstance")
10
+ @obj.introspect
11
+ @iface = @obj["org.ruby.SampleInterface"]
12
+ end
13
+
14
+ it "tests property reading" do
15
+ expect(@iface["ReadMe"]).to eq("READ ME")
16
+ end
17
+
18
+ it "tests property nonreading" do
19
+ expect { @iface["WriteMe"] }.to raise_error(DBus::Error, /not readable/)
20
+ end
21
+
22
+ it "tests property writing" do
23
+ @iface["ReadOrWriteMe"] = "VALUE"
24
+ expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
25
+ end
26
+
27
+ # https://github.com/mvidner/ruby-dbus/pull/19
28
+ it "tests service select timeout" do
29
+ @iface["ReadOrWriteMe"] = "VALUE"
30
+ expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
31
+ # wait for the service to become idle
32
+ sleep 6
33
+ # fail: "Property value changed; perhaps the service died and got restarted"
34
+ expect(@iface["ReadOrWriteMe"]).to eq("VALUE")
35
+ end
36
+
37
+ it "tests property nonwriting" do
38
+ expect { @iface["ReadMe"] = "WROTE" }.to raise_error(DBus::Error, /not writable/)
39
+ end
40
+
41
+ it "tests get all" do
42
+ all = @iface.all_properties
43
+ expect(all.keys.sort).to eq(["ReadMe", "ReadOrWriteMe"])
44
+ end
45
+
46
+ it "tests unknown property reading" do
47
+ expect { @iface["Spoon"] }.to raise_error(DBus::Error, /not found/)
48
+ end
49
+
50
+ it "tests unknown property writing" do
51
+ expect { @iface["Spoon"] = "FPRK" }.to raise_error(DBus::Error, /not found/)
52
+ end
53
+ end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env rspec
2
+ # Test that a server survives various error cases
3
+ require_relative "spec_helper"
4
+ require "dbus"
5
+
6
+ describe "ServerRobustnessTest" do
7
+ before(:each) do
8
+ @bus = DBus::ASessionBus.new
9
+ @svc = @bus.service("org.ruby.service")
10
+ end
11
+
12
+ # https://trac.luon.net/ruby-dbus/ticket/31
13
+ # the server should not crash
14
+ it "tests no such path with introspection" do
15
+ obj = @svc.object "/org/ruby/NotMyInstance"
16
+ expect { obj.introspect }.to raise_error(DBus::Error) do |e|
17
+ expect(e).to_not match(/timeout/)
18
+ end
19
+ end
20
+
21
+ it "tests no such path without introspection" do
22
+ obj = @svc.object "/org/ruby/NotMyInstance"
23
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
24
+ ifc.define_method("the_answer", "out n:i")
25
+ expect { ifc.the_answer }.to raise_error(DBus::Error) do |e|
26
+ expect(e).to_not match(/timeout/)
27
+ end
28
+ end
29
+
30
+ it "tests a method that raises" do
31
+ obj = @svc.object "/org/ruby/MyInstance"
32
+ obj.introspect
33
+ obj.default_iface = "org.ruby.SampleInterface"
34
+ expect { obj.will_raise }.to raise_error(DBus::Error) do |e|
35
+ expect(e).to_not match(/timeout/)
36
+ end
37
+ end
38
+
39
+ it "tests a method that raises name error" do
40
+ obj = @svc.object "/org/ruby/MyInstance"
41
+ obj.introspect
42
+ obj.default_iface = "org.ruby.SampleInterface"
43
+ expect { obj.will_raise_name_error }.to raise_error(DBus::Error) do |e|
44
+ expect(e).to_not match(/timeout/)
45
+ end
46
+ end
47
+
48
+ # https://trac.luon.net/ruby-dbus/ticket/31#comment:3
49
+ it "tests no such method without introspection" do
50
+ obj = @svc.object "/org/ruby/MyInstance"
51
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
52
+ ifc.define_method("not_the_answer", "out n:i")
53
+ expect { ifc.not_the_answer }.to raise_error(DBus::Error) do |e|
54
+ expect(e).to_not match(/timeout/)
55
+ end
56
+ end
57
+
58
+ it "tests no such interface without introspection" do
59
+ obj = @svc.object "/org/ruby/MyInstance"
60
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.NoSuchInterface")
61
+ ifc.define_method("the_answer", "out n:i")
62
+ expect { ifc.the_answer }.to raise_error(DBus::Error) do |e|
63
+ expect(e).to_not match(/timeout/)
64
+ end
65
+ end
66
+ end
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # Test that a server survives various error cases
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
3
+ require_relative "spec_helper"
5
4
  require "dbus"
6
5
 
7
6
  class Foo < DBus::Object
@@ -24,28 +23,28 @@ rescue DBus::InvalidMethodName
24
23
  # raised by the preceding signal declaration
25
24
  end
26
25
 
27
- class ServerTest < Test::Unit::TestCase
28
- def setup
26
+ describe "ServerTest" do
27
+ before(:each) do
29
28
  @bus = DBus::ASessionBus.new
30
29
  @svc = @bus.request_service "org.ruby.server-test"
31
30
  end
32
31
 
33
- def teardown
32
+ after(:each) do
34
33
  @bus.proxy.ReleaseName "org.ruby.server-test"
35
34
  end
36
35
 
37
- def test_unexporting_an_object
36
+ it "tests unexporting an object" do
38
37
  obj = Foo.new "/org/ruby/Foo"
39
38
  @svc.export obj
40
- assert @svc.unexport(obj)
39
+ expect(@svc.unexport(obj)).to be_true
41
40
  end
42
41
 
43
- def test_unexporting_an_object_not_exported
42
+ it "tests unexporting an object not exported" do
44
43
  obj = Foo.new "/org/ruby/Foo"
45
- assert !@svc.unexport(obj)
44
+ expect(@svc.unexport(obj)).to be_false
46
45
  end
47
46
 
48
- def test_emiting_signals
47
+ it "tests emiting signals" do
49
48
  obj = Foo.new "/org/ruby/Foo"
50
49
  @svc.export obj
51
50
  obj.signal_without_arguments
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require File.expand_path("../test_helper", __FILE__)
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
7
  $:.unshift File.expand_path("../../lib", __FILE__)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe DBus::ASessionBus do
6
+ context "when DBUS_SESSION_BUS_ADDRESS is unset in ENV (Issue#4)" do
7
+ ENV.delete "DBUS_SESSION_BUS_ADDRESS"
8
+
9
+ it "can connect" do
10
+ bus = DBus::ASessionBus.new
11
+ svc = bus.service("org.freedesktop.DBus")
12
+ expect(svc.exists?).to be_true
13
+ end
14
+ end
15
+ end