ruby-dbus 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/COPYING +504 -0
  2. data/NEWS +137 -0
  3. data/README +53 -0
  4. data/Rakefile +54 -0
  5. data/VERSION +1 -0
  6. data/doc/tutorial/index.html +356 -0
  7. data/doc/tutorial/index.markdown +467 -0
  8. data/examples/gdbus/gdbus +255 -0
  9. data/examples/gdbus/gdbus.glade +184 -0
  10. data/examples/gdbus/launch.sh +4 -0
  11. data/examples/no-introspect/nm-test.rb +21 -0
  12. data/examples/no-introspect/tracker-test.rb +16 -0
  13. data/examples/rhythmbox/playpause.rb +25 -0
  14. data/examples/service/call_service.rb +25 -0
  15. data/examples/service/service_newapi.rb +51 -0
  16. data/examples/simple/call_introspect.rb +34 -0
  17. data/examples/utils/listnames.rb +11 -0
  18. data/examples/utils/notify.rb +19 -0
  19. data/lib/dbus.rb +91 -0
  20. data/lib/dbus/auth.rb +258 -0
  21. data/lib/dbus/bus.rb +816 -0
  22. data/lib/dbus/core_ext/class/attribute.rb +91 -0
  23. data/lib/dbus/core_ext/kernel/singleton_class.rb +14 -0
  24. data/lib/dbus/core_ext/module/remove_method.rb +12 -0
  25. data/lib/dbus/error.rb +44 -0
  26. data/lib/dbus/export.rb +132 -0
  27. data/lib/dbus/introspect.rb +553 -0
  28. data/lib/dbus/marshall.rb +443 -0
  29. data/lib/dbus/matchrule.rb +100 -0
  30. data/lib/dbus/message.rb +310 -0
  31. data/lib/dbus/type.rb +222 -0
  32. data/ruby-dbus.gemspec +18 -0
  33. data/test/binding_test.rb +56 -0
  34. data/test/bus_driver_test.rb +22 -0
  35. data/test/dbus-launch-simple +35 -0
  36. data/test/dbus-limited-session.conf +28 -0
  37. data/test/server_robustness_test.rb +41 -0
  38. data/test/server_test.rb +53 -0
  39. data/test/service_newapi.rb +129 -0
  40. data/test/session_bus_test_manual.rb +20 -0
  41. data/test/signal_test.rb +64 -0
  42. data/test/t1 +4 -0
  43. data/test/t2.rb +66 -0
  44. data/test/t3-ticket27.rb +18 -0
  45. data/test/t5-report-dbus-interface.rb +58 -0
  46. data/test/t6-loop.rb +82 -0
  47. data/test/test_env +13 -0
  48. data/test/test_server +39 -0
  49. data/test/variant_test.rb +66 -0
  50. metadata +117 -0
data/test/t1 ADDED
@@ -0,0 +1,4 @@
1
+ #! /bin/sh
2
+ SEND0="dbus-send --session --dest=org.ruby.service"
3
+ CALL="$SEND0 --type=method_call --print-reply"
4
+ $CALL /org/ruby/MyInstance org.ruby.AnotherInterface.Reverse string:Hello
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "dbus"
4
+
5
+ class ValueTest < Test::Unit::TestCase
6
+ def setup
7
+ session_bus = DBus::SessionBus.instance
8
+ svc = session_bus.service("org.ruby.service")
9
+ @obj = svc.object("/org/ruby/MyInstance")
10
+ @obj.introspect # necessary
11
+ @obj.default_iface = "org.ruby.SampleInterface"
12
+ end
13
+
14
+ def test_passing_an_array_through_a_variant
15
+ # old explicit typing
16
+ @obj.test_variant(["as", ["coucou", "kuku"]])
17
+ # automatic typing
18
+ @obj.test_variant(["coucou", "kuku"])
19
+ @obj.test_variant(["saint", "was that a word or a signature?"])
20
+ end
21
+
22
+ def test_bouncing_a_variant
23
+ assert_equal "cuckoo", @obj.bounce_variant("cuckoo")[0]
24
+ assert_equal ["coucou", "kuku"], @obj.bounce_variant(["coucou", "kuku"])[0]
25
+ assert_equal [], @obj.bounce_variant([])[0]
26
+ empty_hash = {}
27
+ assert_equal empty_hash, @obj.bounce_variant(empty_hash)[0]
28
+ end
29
+
30
+ # these are ambiguous
31
+ def test_pairs_with_a_string
32
+
33
+ # deprecated
34
+ assert_equal "foo", @obj.bounce_variant(["s", "foo"])[0]
35
+
36
+ assert_equal "foo", @obj.bounce_variant(DBus.variant("s", "foo"))[0]
37
+ assert_equal "foo", @obj.bounce_variant([DBus.type("s"), "foo"])[0]
38
+
39
+ # does not work, because the server side forgets the explicit typing
40
+ # assert_equal ["s", "foo"], @obj.bounce_variant(["av", ["s", "foo"]])[0]
41
+ # assert_equal ["s", "foo"], @obj.bounce_variant(["as", ["s", "foo"]])[0]
42
+
43
+ # instead, use this to demonstrate that the variant is passed as expected
44
+ assert_equal 4, @obj.variant_size(["s", "four"])[0]
45
+ # "av" is the simplest thing that will work,
46
+ # shifting the heuristic from a pair to the individual items
47
+ assert_equal 2, @obj.variant_size(["av", ["s", "four"]])[0]
48
+ end
49
+
50
+ def test_marshalling_an_array_of_variants
51
+ # https://trac.luon.net/ruby-dbus/ticket/30
52
+ @obj.default_iface = "org.ruby.Ticket30"
53
+ choices = []
54
+ choices << ['s', 'Plan A']
55
+ choices << ['s', 'Plan B']
56
+ # old explicit typing
57
+ assert_equal "Do Plan A", @obj.Sybilla(choices)[0]
58
+ # automatic typing
59
+ assert_equal "Do Plan A", @obj.Sybilla(["Plan A", "Plan B"])[0]
60
+ end
61
+
62
+ def test_service_returning_nonarray
63
+ # "warning: default `to_a' will be obsolete"
64
+ @obj.the_answer
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # Test passing a particular struct array through a variant
3
+ # https://trac.luon.net/ruby-dbus/ticket/27
4
+ require "dbus"
5
+ session_bus = DBus::SessionBus.instance
6
+ svc = session_bus.service("org.ruby.service")
7
+ obj = svc.object("/org/ruby/MyInstance")
8
+ obj.introspect # necessary
9
+ obj.default_iface = "org.ruby.SampleInterface"
10
+ # The bug is probably alignment related so whether it triggers
11
+ # depends also on the combined length of service, interface,
12
+ # and method names. Luckily here it works out.
13
+ triple = ['a(uuu)', []]
14
+ obj.test_variant(triple)
15
+ quadruple = ['a(uuuu)', []] # a(uuu) works fine
16
+ # The bus disconnects us because of malformed message,
17
+ # code 12: DBUS_INVALID_TOO_MUCH_DATA
18
+ obj.test_variant(quadruple)
@@ -0,0 +1,58 @@
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 "test/unit"
5
+ require "dbus"
6
+
7
+ class ErrMsgTest < Test::Unit::TestCase
8
+ def setup
9
+ session_bus = DBus::SessionBus.instance
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
+ def test_report_dbus_interface
17
+ begin
18
+ @obj.NoSuchMethod
19
+ # a specific exception...
20
+ rescue NameError => e
21
+ # mentioning DBus and the interface
22
+ assert_match(/DBus interface.*#{@obj.default_iface}/, e.to_s)
23
+ end
24
+ end
25
+
26
+ def test_report_short_struct
27
+ begin
28
+ @obj.test_variant ["(ss)", ["too few"] ]
29
+ rescue DBus::TypeException => e
30
+ assert_match(/1 elements but type info for 2/, e.to_s)
31
+ end
32
+ end
33
+
34
+ def test_report_long_struct
35
+ begin
36
+ @obj.test_variant ["(ss)", ["a", "b", "too many"] ]
37
+ rescue DBus::TypeException => e
38
+ assert_match(/3 elements but type info for 2/, e.to_s)
39
+ end
40
+ end
41
+
42
+ def test_report_nil
43
+ nils = [
44
+ ["(s)", [nil] ], # would get disconnected
45
+ ["i", nil ],
46
+ ["a{ss}", {"foo" => nil} ],
47
+ ]
48
+ nils.each do |has_nil|
49
+ begin
50
+ @obj.test_variant has_nil
51
+ rescue DBus::TypeException => e
52
+ # TODO want backtrace from the perspective of the caller:
53
+ # rescue/reraise in send_sync?
54
+ assert_match(/Cannot send nil/, e.to_s)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the main loop
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts "#{$$} #{msg}" if $DEBUG
8
+ end
9
+
10
+ class MainLoopTest < Test::Unit::TestCase
11
+ def setup
12
+ @session_bus = DBus::SessionBus.instance
13
+ svc = @session_bus.service("org.ruby.service")
14
+ @obj = svc.object("/org/ruby/MyInstance")
15
+ @obj.introspect # necessary
16
+ @obj.default_iface = "org.ruby.Loop"
17
+
18
+ @loop = DBus::Main.new
19
+ @loop << @session_bus
20
+ end
21
+
22
+ # Hack the library internals so that there is a delay between
23
+ # sending a DBus call and listening for its reply, so that
24
+ # the bus has a chance to join the server messages and a race is reproducible
25
+ def call_lazily
26
+ class << @session_bus
27
+ alias :wait_for_message_orig :wait_for_message
28
+ def wait_for_message_lazy
29
+ d "I am so lazy"
30
+ sleep 1 # Give the server+bus a chance to join the messages
31
+ wait_for_message_orig
32
+ end
33
+ alias :wait_for_message :wait_for_message_lazy
34
+ end
35
+
36
+ yield
37
+
38
+ # undo
39
+ class << @session_bus
40
+ remove_method :wait_for_message
41
+ remove_method :wait_for_message_lazy
42
+ alias :wait_for_message :wait_for_message_orig
43
+ end
44
+ end
45
+
46
+ def test_loop_quit(delay = 1)
47
+ @obj.on_signal "LongTaskEnd" do
48
+ d "Telling loop to quit"
49
+ @loop.quit
50
+ end
51
+
52
+ call_lazily do
53
+ # The method will sleep the requested amount of seconds
54
+ # (in another thread) before signalling LongTaskEnd
55
+ @obj.LongTaskBegin delay
56
+ end
57
+
58
+ # this thread will make the test fail if @loop.run does not return
59
+ dynamite = Thread.new do
60
+ d "Dynamite burning"
61
+ sleep 2
62
+ d "Dynamite explodes"
63
+ # We need to raise in the main thread.
64
+ # Simply raising here means the exception is ignored
65
+ # (until dynamite.join which we don't call) or
66
+ # (if abort_on_exception is set) it terminates the whole script.
67
+ Thread.main.raise RuntimeError, "The main loop did not quit in time"
68
+ end
69
+
70
+ @loop.run
71
+ d "Defusing dynamite"
72
+ # if we get here, defuse the bomb
73
+ dynamite.exit
74
+ # remove signal handler
75
+ @obj.on_signal "LongTaskEnd"
76
+ end
77
+
78
+ # https://bugzilla.novell.com/show_bug.cgi?id=537401
79
+ def test_loop_drained_socket
80
+ test_loop_quit 0
81
+ end
82
+ end
@@ -0,0 +1,13 @@
1
+ #! /bin/bash
2
+ # test_env: set up the environment needed to run tests:
3
+ # - set up a private bus
4
+ # - run a test server on it
5
+
6
+ #export DBUS_VERBOSE=1
7
+ #export RUBYOPT="-d"
8
+ export RUBYOPT="$RUBYOPT -w"
9
+ ./test_server \
10
+ ./service_newapi.rb \
11
+ -- \
12
+ ./dbus-launch-simple \
13
+ "$@"
@@ -0,0 +1,39 @@
1
+ #! /bin/sh
2
+ # A wrapper for DBus tests
3
+ # Run a server (directly or by dbus activation) and then the test
4
+ # $0 server [args...] -- test [args...]
5
+ set -o errexit
6
+
7
+ while [ "$1" != "--" ]; do
8
+ SERVER="$SERVER $1"
9
+ shift
10
+ done
11
+ shift # --
12
+
13
+ setup_activation () {
14
+ SDIR=$XDG_DATA_DIRS/dbus-1/services
15
+ mkdir -p $SDIR
16
+ # FIXME Name is hardcoded
17
+ cat <<EOF > $SDIR/test.service
18
+ [D-BUS Service]
19
+ Name=org.ruby.service
20
+ Exec=$SERVER
21
+ EOF
22
+ }
23
+
24
+ run_server () {
25
+ echo -n "Hey, server, get on da bus... "
26
+ # start the server
27
+ $SERVER & sleep 3
28
+ echo "off we go!"
29
+ }
30
+
31
+ export XDG_DATA_DIRS=`mktemp -d dbus.activation.XXXXXX`
32
+ RM_FILES="$RM_FILES $XDG_DATA_DIRS"
33
+ setup_activation
34
+ #run_server
35
+
36
+ # Clean up at exit.
37
+ trap "rm -rf \$RM_FILES" EXIT TERM INT
38
+
39
+ "$@"
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # Test marshalling variants according to ruby types
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class VariantTest < Test::Unit::TestCase
7
+ def setup
8
+ @bus = DBus::SessionBus.instance
9
+ @svc = @bus.service("org.ruby.service")
10
+ end
11
+
12
+ def make_variant(a)
13
+ DBus::PacketMarshaller.make_variant(a)
14
+ end
15
+
16
+ def test_make_variant_scalar
17
+ # special case: do not fail immediately, marshaller will do that
18
+ assert_equal ["b", nil], make_variant(nil)
19
+
20
+ assert_equal ["b", true], make_variant(true)
21
+ # Integers
22
+ # no byte
23
+ assert_equal ["i", 42], make_variant(42)
24
+ # 3_000_000_000 can be u or x.
25
+ # less specific test: just run it thru a loopback
26
+ assert_equal ["x", 3_000_000_000], make_variant(3_000_000_000)
27
+ assert_equal ["x", 5_000_000_000], make_variant(5_000_000_000)
28
+
29
+ assert_equal ["d", 3.14], make_variant(3.14)
30
+
31
+ assert_equal ["s", "foo"], make_variant("foo")
32
+ assert_equal ["s", "bar"], make_variant(:bar)
33
+
34
+ # left: strruct, array, dict
35
+ # object path: detect exported objects?, signature
36
+
37
+ # # by Ruby types
38
+ # class Foo
39
+ # end
40
+ # make_variant(Foo.new)
41
+ # if we don;t understand a class, the error should be informative -> new exception
42
+ end
43
+
44
+ def test_make_variant_array
45
+ ai = [1, 2, 3]
46
+ # as = ["one", "two", "three"]
47
+ # which?
48
+ # assert_equal ["ai", [1, 2, 3]], make_variant(ai)
49
+ assert_equal ["av", [["i", 1],
50
+ ["i", 2],
51
+ ["i", 3]]], make_variant(ai)
52
+ a0 = []
53
+ assert_equal ["av", []], make_variant(a0)
54
+
55
+ end
56
+
57
+ def test_make_variant_hash
58
+ h = {"k1" => "v1", "k2" => "v2"}
59
+ assert_equal ["a{sv}", {
60
+ "k1" => ["s", "v1"],
61
+ "k2" => ["s", "v2"],
62
+ }], make_variant(h)
63
+ h0 = {}
64
+ assert_equal ["a{sv}", {}], make_variant(h0)
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-dbus
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Ruby DBus Team
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-07 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: ruby-dbus-devel@lists.luon.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - COPYING
30
+ - README
31
+ - NEWS
32
+ files:
33
+ - Rakefile
34
+ - VERSION
35
+ - doc/tutorial/index.html
36
+ - doc/tutorial/index.markdown
37
+ - examples/gdbus/gdbus
38
+ - examples/gdbus/gdbus.glade
39
+ - examples/gdbus/launch.sh
40
+ - examples/no-introspect/nm-test.rb
41
+ - examples/no-introspect/tracker-test.rb
42
+ - examples/rhythmbox/playpause.rb
43
+ - examples/service/call_service.rb
44
+ - examples/service/service_newapi.rb
45
+ - examples/simple/call_introspect.rb
46
+ - examples/utils/listnames.rb
47
+ - examples/utils/notify.rb
48
+ - lib/dbus.rb
49
+ - lib/dbus/auth.rb
50
+ - lib/dbus/bus.rb
51
+ - lib/dbus/core_ext/class/attribute.rb
52
+ - lib/dbus/core_ext/kernel/singleton_class.rb
53
+ - lib/dbus/core_ext/module/remove_method.rb
54
+ - lib/dbus/error.rb
55
+ - lib/dbus/export.rb
56
+ - lib/dbus/introspect.rb
57
+ - lib/dbus/marshall.rb
58
+ - lib/dbus/matchrule.rb
59
+ - lib/dbus/message.rb
60
+ - lib/dbus/type.rb
61
+ - ruby-dbus.gemspec
62
+ - test/binding_test.rb
63
+ - test/bus_driver_test.rb
64
+ - test/dbus-launch-simple
65
+ - test/dbus-limited-session.conf
66
+ - test/server_robustness_test.rb
67
+ - test/server_test.rb
68
+ - test/service_newapi.rb
69
+ - test/session_bus_test_manual.rb
70
+ - test/signal_test.rb
71
+ - test/t1
72
+ - test/t2.rb
73
+ - test/t3-ticket27.rb
74
+ - test/t5-report-dbus-interface.rb
75
+ - test/t6-loop.rb
76
+ - test/test_env
77
+ - test/test_server
78
+ - test/variant_test.rb
79
+ - COPYING
80
+ - README
81
+ - NEWS
82
+ has_rdoc: true
83
+ homepage: http://trac.luon.net/data/ruby-dbus/
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.3.7
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Ruby module for interaction with D-Bus
116
+ test_files: []
117
+