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
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test the methods of the bus driver
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
5
- require "dbus"
6
-
7
- class BusDriverTest < Test::Unit::TestCase
8
- def setup
9
- @bus = DBus::ASessionBus.new
10
- @svc = @bus.service("org.ruby.service")
11
- @svc.object("/").introspect
12
- end
13
-
14
- def test_exists
15
- assert @svc.exists?, "could not find the service"
16
- nonsvc = @bus.service "org.ruby.nosuchservice"
17
- assert ! nonsvc.exists?, "found a service that should not exist"
18
- end
19
- end
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path("../test_helper", __FILE__)
3
- require "test/unit"
4
- require "dbus"
5
-
6
- class ByteArrayTest < Test::Unit::TestCase
7
- def setup
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
- def test_passing_byte_array
17
- data = [0, 77, 255]
18
- result = @obj.mirror_byte_array(data).first
19
- assert_equal data, result
20
- end
21
-
22
- def test_passing_byte_array_from_string
23
- data = "AAA"
24
- result = @obj.mirror_byte_array(data).first
25
- assert_equal [65, 65, 65], result
26
- end
27
-
28
- def test_passing_byte_array_from_hash
29
- # Hash is an Enumerable, but is caught earlier
30
- data = { "this will" => "fail" }
31
- assert_raises DBus::TypeException do
32
- @obj.mirror_byte_array(data).first
33
- end
34
- end
35
-
36
- def test_passing_byte_array_from_nonenumerable
37
- data = Time.now
38
- assert_raises DBus::TypeException do
39
- @obj.mirror_byte_array(data).first
40
- end
41
- end
42
- end
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # should report it missing on org.ruby.SampleInterface
3
- # (on object...) instead of on DBus::Proxy::ObjectInterface
4
- require File.expand_path("../test_helper", __FILE__)
5
- require "test/unit"
6
- require "dbus"
7
-
8
- class ErrMsgTest < Test::Unit::TestCase
9
- def setup
10
- session_bus = DBus::ASessionBus.new
11
- svc = session_bus.service("org.ruby.service")
12
- @obj = svc.object("/org/ruby/MyInstance")
13
- @obj.introspect # necessary
14
- @obj.default_iface = "org.ruby.SampleInterface"
15
- end
16
-
17
- def test_report_dbus_interface
18
- begin
19
- @obj.NoSuchMethod
20
- # a specific exception...
21
- rescue NameError => e
22
- # mentioning DBus and the interface
23
- assert_match(/DBus interface.*#{@obj.default_iface}/, e.to_s)
24
- end
25
- end
26
-
27
- def test_report_short_struct
28
- begin
29
- @obj.test_variant ["(ss)", ["too few"] ]
30
- rescue DBus::TypeException => e
31
- assert_match(/1 elements but type info for 2/, e.to_s)
32
- end
33
- end
34
-
35
- def test_report_long_struct
36
- begin
37
- @obj.test_variant ["(ss)", ["a", "b", "too many"] ]
38
- rescue DBus::TypeException => e
39
- assert_match(/3 elements but type info for 2/, e.to_s)
40
- end
41
- end
42
-
43
- def test_report_nil
44
- nils = [
45
- ["(s)", [nil] ], # would get disconnected
46
- ["i", nil ],
47
- ["a{ss}", {"foo" => nil} ],
48
- ]
49
- nils.each do |has_nil|
50
- begin
51
- @obj.test_variant has_nil
52
- rescue DBus::TypeException => e
53
- # TODO want backtrace from the perspective of the caller:
54
- # rescue/reraise in send_sync?
55
- assert_match(/Cannot send nil/, e.to_s)
56
- end
57
- end
58
- end
59
- end
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path("../test_helper", __FILE__)
3
- require "test/unit"
4
- require "dbus"
5
-
6
- class IntrospectionTest < Test::Unit::TestCase
7
- def setup
8
- session_bus = DBus::ASessionBus.new
9
- svc = session_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
- def test_wrong_number_of_arguments
16
- assert_raise(ArgumentError) { @obj.test_variant "too","many","args" }
17
- assert_raise(ArgumentError) { @obj.test_variant } # not enough
18
- end
19
-
20
- def test_shortcut_methods
21
- @obj.default_iface = nil
22
- assert_equal(["varargs"], @obj.bounce_variant("varargs"))
23
- # test for a duplicated method name
24
- assert_raise(NoMethodError) { @obj.the_answer }
25
- # ensure istance methods of ProxyObject aren't overwritten by remote
26
- # methods
27
- assert_nothing_raised { @obj.interfaces }
28
-
29
- @obj.default_iface = "org.ruby.SampleInterface"
30
- assert_equal [42], @obj.the_answer
31
- end
32
- end
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path("../test_helper", __FILE__)
3
- require "test/unit"
4
- require "dbus"
5
-
6
- class PropertyTest < Test::Unit::TestCase
7
- def setup
8
- session_bus = DBus::ASessionBus.new
9
- svc = session_bus.service("org.ruby.service")
10
- @obj = svc.object("/org/ruby/MyInstance")
11
- @obj.introspect
12
- @iface = @obj["org.ruby.SampleInterface"]
13
- end
14
-
15
- def test_property_reading
16
- assert_equal "READ ME", @iface["ReadMe"]
17
- end
18
-
19
- def test_property_nonreading
20
- e = assert_raises DBus::Error do
21
- @iface["WriteMe"]
22
- end
23
- assert_match(/not readable/, e.to_s)
24
- end
25
-
26
- def test_property_writing
27
- @iface["ReadOrWriteMe"] = "VALUE"
28
- assert_equal "VALUE", @iface["ReadOrWriteMe"]
29
- end
30
-
31
- # https://github.com/mvidner/ruby-dbus/pull/19
32
- def test_service_select_timeout
33
- @iface["ReadOrWriteMe"] = "VALUE"
34
- assert_equal "VALUE", @iface["ReadOrWriteMe"]
35
- # wait for the service to become idle
36
- sleep 6
37
- assert_equal "VALUE", @iface["ReadOrWriteMe"], "Property value changed; perhaps the service died and got restarted"
38
- end
39
-
40
- def test_property_nonwriting
41
- e = assert_raises DBus::Error do
42
- @iface["ReadMe"] = "WROTE"
43
- end
44
- assert_match(/not writable/, e.to_s)
45
- end
46
-
47
- def test_get_all
48
- all = @iface.all_properties
49
- assert_equal ["ReadMe", "ReadOrWriteMe"], all.keys.sort
50
- end
51
-
52
- def test_unknown_property_reading
53
- e = assert_raises DBus::Error do
54
- @iface["Spoon"]
55
- end
56
- assert_match(/not found/, e.to_s)
57
- end
58
-
59
- def test_unknown_property_writing
60
- e = assert_raises DBus::Error do
61
- @iface["Spoon"] = "FORK"
62
- end
63
- assert_match(/not found/, e.to_s)
64
- end
65
- end
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test that a server survives various error cases
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
5
- require "dbus"
6
-
7
- class ServerRobustnessTest < Test::Unit::TestCase
8
- def setup
9
- @bus = DBus::ASessionBus.new
10
- @svc = @bus.service("org.ruby.service")
11
- end
12
-
13
- # https://trac.luon.net/ruby-dbus/ticket/31
14
- # the server should not crash
15
- def test_no_such_path_with_introspection
16
- obj = @svc.object "/org/ruby/NotMyInstance"
17
- obj.introspect
18
- assert false, "should have raised"
19
- rescue DBus::Error => e
20
- assert_no_match(/timeout/, e.to_s)
21
- end
22
-
23
- def test_no_such_path_without_introspection
24
- obj = @svc.object "/org/ruby/NotMyInstance"
25
- ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
26
- ifc.define_method("the_answer", "out n:i")
27
- ifc.the_answer
28
- assert false, "should have raised"
29
- rescue DBus::Error => e
30
- assert_no_match(/timeout/, e.to_s)
31
- end
32
-
33
- def test_a_method_that_raises
34
- obj = @svc.object "/org/ruby/MyInstance"
35
- obj.introspect
36
- obj.default_iface = "org.ruby.SampleInterface"
37
- obj.will_raise
38
- assert false, "should have raised"
39
- rescue DBus::Error => e
40
- assert_no_match(/timeout/, e.to_s)
41
- end
42
-
43
- def test_a_method_that_raises_name_error
44
- obj = @svc.object "/org/ruby/MyInstance"
45
- obj.introspect
46
- obj.default_iface = "org.ruby.SampleInterface"
47
- obj.will_raise_name_error
48
- assert false, "should have raised"
49
- rescue DBus::Error => e
50
- assert_no_match(/timeout/, e.to_s)
51
- end
52
-
53
- # https://trac.luon.net/ruby-dbus/ticket/31#comment:3
54
- def test_no_such_method_without_introspection
55
- obj = @svc.object "/org/ruby/MyInstance"
56
- ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
57
- ifc.define_method("not_the_answer", "out n:i")
58
- ifc.not_the_answer
59
- assert false, "should have raised"
60
- rescue DBus::Error => e
61
- assert_no_match(/timeout/, e.to_s)
62
- end
63
-
64
- def test_no_such_interface_without_introspection
65
- obj = @svc.object "/org/ruby/MyInstance"
66
- ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.NoSuchInterface")
67
- ifc.define_method("the_answer", "out n:i")
68
- ifc.the_answer
69
- assert false, "should have raised"
70
- rescue DBus::Error => e
71
- assert_no_match(/timeout/, e.to_s)
72
- end
73
- end
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path("../test_helper", __FILE__)
3
- require "test/unit"
4
- require "dbus"
5
-
6
- class SessionBusAddressTest < Test::Unit::TestCase
7
- def setup
8
- # test getting the session bus address even if unset in ENV (Issue#4)
9
- ENV.delete "DBUS_SESSION_BUS_ADDRESS"
10
- @bus = DBus::ASessionBus.new
11
- @svc = @bus.service("org.freedesktop.DBus")
12
- end
13
-
14
- def test_connection
15
- assert @svc.exists?
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- if ENV["COVERAGE"]
2
- coverage = ENV["COVERAGE"] == "true"
3
- else
4
- # heuristics: enable for interactive builds but not in Travis or OBS
5
- coverage = !!ENV["DISPLAY"]
6
- end
7
-
8
- if coverage && RUBY_VERSION >= "1.9" # SimpleCov does not work with 1.8
9
- require 'simplecov'
10
- SimpleCov.root File.expand_path("../..", __FILE__)
11
- SimpleCov.start
12
- end
13
-
14
- $:.unshift File.expand_path("../../lib", __FILE__)
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test the type class
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
5
- require "dbus"
6
-
7
- class TypeTest < Test::Unit::TestCase
8
- def test_costants_are_defined
9
- assert_equal DBus::Type::BYTE, ?y
10
- assert_equal DBus::Type::BOOLEAN, ?b
11
- #etc..
12
- end
13
-
14
- def test_parsing
15
- %w{i ai a(ii) aai}.each do |s|
16
- assert_equal s, DBus::type(s).to_s
17
- end
18
-
19
- %w{aa (ii ii) hrmp}.each do |s|
20
- assert_raise(DBus::Type::SignatureException) { DBus::type(s) }
21
- end
22
- end
23
- end
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test marshalling variants according to ruby types
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
5
- require "dbus"
6
-
7
- class VariantTest < Test::Unit::TestCase
8
- def setup
9
- @bus = DBus::ASessionBus.new
10
- @svc = @bus.service("org.ruby.service")
11
- end
12
-
13
- def make_variant(a)
14
- DBus::PacketMarshaller.make_variant(a)
15
- end
16
-
17
- def test_make_variant_scalar
18
- # special case: do not fail immediately, marshaller will do that
19
- assert_equal ["b", nil], make_variant(nil)
20
-
21
- assert_equal ["b", true], make_variant(true)
22
- # Integers
23
- # no byte
24
- assert_equal ["i", 42], make_variant(42)
25
- # 3_000_000_000 can be u or x.
26
- # less specific test: just run it thru a loopback
27
- assert_equal ["x", 3_000_000_000], make_variant(3_000_000_000)
28
- assert_equal ["x", 5_000_000_000], make_variant(5_000_000_000)
29
-
30
- assert_equal ["d", 3.14], make_variant(3.14)
31
-
32
- assert_equal ["s", "foo"], make_variant("foo")
33
- assert_equal ["s", "bar"], make_variant(:bar)
34
-
35
- # left: strruct, array, dict
36
- # object path: detect exported objects?, signature
37
-
38
- # # by Ruby types
39
- # class Foo
40
- # end
41
- # make_variant(Foo.new)
42
- # if we don;t understand a class, the error should be informative -> new exception
43
- end
44
-
45
- def test_make_variant_array
46
- ai = [1, 2, 3]
47
- # as = ["one", "two", "three"]
48
- # which?
49
- # assert_equal ["ai", [1, 2, 3]], make_variant(ai)
50
- assert_equal ["av", [["i", 1],
51
- ["i", 2],
52
- ["i", 3]]], make_variant(ai)
53
- a0 = []
54
- assert_equal ["av", []], make_variant(a0)
55
-
56
- end
57
-
58
- def test_make_variant_hash
59
- h = {"k1" => "v1", "k2" => "v2"}
60
- assert_equal ["a{sv}", {
61
- "k1" => ["s", "v1"],
62
- "k2" => ["s", "v2"],
63
- }], make_variant(h)
64
- h0 = {}
65
- assert_equal ["a{sv}", {}], make_variant(h0)
66
- end
67
- end