mvidner-ruby-dbus 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ check:
2
+ ./test_all
3
+ test: check
4
+ .PHONY: test check
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the methods of the bus driver
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts msg if $DEBUG
8
+ end
9
+
10
+ class BusDriverTest < Test::Unit::TestCase
11
+ def setup
12
+ @bus = DBus::SessionBus.instance
13
+ @svc = @bus.service("org.ruby.service")
14
+ end
15
+
16
+ def test_exists
17
+ assert @svc.exists?
18
+ nonsvc = @bus.service "org.ruby.nosuchservice"
19
+ assert ! nonsvc.exists?
20
+ end
21
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dbus'
4
+
5
+ def d(msg)
6
+ puts "#{$$} #{msg}" if $DEBUG
7
+ end
8
+
9
+ class Test < DBus::Object
10
+ # Create an interface aggregating all upcoming dbus_method defines.
11
+ dbus_interface "org.ruby.SampleInterface" do
12
+ dbus_method :hello, "in name:s, in name2:s" do |name, name2|
13
+ puts "hello(#{name}, #{name2})"
14
+ end
15
+
16
+ dbus_method :test_variant, "in stuff:v" do |variant|
17
+ p variant
18
+ end
19
+
20
+ dbus_method :the_answer, "out answer:i" do
21
+ 42
22
+ end
23
+
24
+ dbus_signal :SomethingJustHappened, "toto:s, tutu:u"
25
+ end
26
+
27
+ dbus_interface "org.ruby.AnotherInterface" do
28
+ dbus_method :ThatsALongMethodNameIThink do
29
+ puts "ThatsALongMethodNameIThink"
30
+ end
31
+ dbus_method :Reverse, "in instr:s, out outstr:s" do |instr|
32
+ outstr = instr.split(//).reverse.join
33
+ puts "got: #{instr}, replying: #{outstr}"
34
+ [outstr]
35
+ end
36
+ end
37
+
38
+ dbus_interface "org.ruby.Ticket30" do
39
+ dbus_method :Sybilla, 'in choices:av, out advice:s' do |choices|
40
+ ["Do #{choices[0]}"]
41
+ end
42
+ end
43
+
44
+ dbus_interface "org.ruby.Loop" do
45
+ # starts doing something long, but returns immediately
46
+ # and sends a signal when done
47
+ dbus_method :LongTaskBegin, 'in delay:i' do |delay|
48
+ # FIXME did not complain about mismatch between signature and block args
49
+ d "Long task began"
50
+ task = Thread.new do
51
+ d "Long task thread started (#{delay}s)"
52
+ sleep delay
53
+ d "Long task will signal end"
54
+ self.LongTaskEnd
55
+ end
56
+ task.abort_on_exception = true # protect from test case bugs
57
+ end
58
+
59
+ dbus_signal :LongTaskEnd
60
+ end
61
+ end
62
+
63
+ bus = DBus::SessionBus.instance
64
+ service = bus.request_service("org.ruby.service")
65
+ myobj = Test.new("/org/ruby/MyInstance")
66
+ service.export(myobj)
67
+
68
+ puts "listening"
69
+ main = DBus::Main.new
70
+ main << bus
71
+ main.run
72
+
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
data/test/t2.rb ADDED
@@ -0,0 +1,31 @@
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
+ @obj.test_variant(["as", ["coucou", "kuku"]])
16
+ end
17
+
18
+ def test_marshalling_an_array_of_variants
19
+ # https://trac.luon.net/ruby-dbus/ticket/30
20
+ choices = []
21
+ choices << ['s', 'Plan A']
22
+ choices << ['s', 'Plan B']
23
+ @obj.default_iface = "org.ruby.Ticket30"
24
+ p @obj.Sybilla(choices)
25
+ end
26
+
27
+ def test_service_returning_nonarray
28
+ # "warning: default `to_a' will be obsolete"
29
+ @obj.the_answer
30
+ end
31
+ 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,26 @@
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
+ end
26
+
data/test/t6-loop.rb ADDED
@@ -0,0 +1,85 @@
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
+ def teardown
23
+ # workaround for nonexisting remove_match
24
+ @session_bus.instance_variable_set(:@signal_matchrules, [])
25
+ end
26
+
27
+ # Hack the library internals so that there is a delay between
28
+ # sending a DBus call and listening for its reply, so that
29
+ # the bus has a chance to join the server messages and a race is reproducible
30
+ def call_lazily
31
+ class << @session_bus
32
+ alias :wait_for_message_orig :wait_for_message
33
+ def wait_for_message_lazy
34
+ d "I am so lazy"
35
+ sleep 1 # Give the server+bus a chance to join the messages
36
+ wait_for_message_orig
37
+ end
38
+ alias :wait_for_message :wait_for_message_lazy
39
+ end
40
+
41
+ yield
42
+
43
+ # undo
44
+ class << @session_bus
45
+ remove_method :wait_for_message
46
+ remove_method :wait_for_message_lazy
47
+ alias :wait_for_message :wait_for_message_orig
48
+ end
49
+ end
50
+
51
+ def test_loop_quit(delay = 1)
52
+ @obj.on_signal "LongTaskEnd" do
53
+ d "Telling loop to quit"
54
+ @loop.quit
55
+ end
56
+
57
+ call_lazily do
58
+ # The method will sleep the requested amount of seconds
59
+ # (in another thread) before signalling LongTaskEnd
60
+ @obj.LongTaskBegin delay
61
+ end
62
+
63
+ # this thread will make the test fail if @loop.run does not return
64
+ dynamite = Thread.new do
65
+ d "Dynamite burning"
66
+ sleep 2
67
+ d "Dynamite explodes"
68
+ # We need to raise in the main thread.
69
+ # Simply raising here means the exception is ignored
70
+ # (until dynamite.join which we don't call) or
71
+ # (if abort_on_exception is set) it terminates the whole script.
72
+ Thread.main.raise RuntimeError, "The main loop did not quit in time"
73
+ end
74
+
75
+ @loop.run
76
+ d "Defusing dynamite"
77
+ # if we get here, defuse the bomb
78
+ dynamite.exit
79
+ end
80
+
81
+ # https://bugzilla.novell.com/show_bug.cgi?id=537401
82
+ def test_loop_drained_socket
83
+ test_loop_quit 0
84
+ end
85
+ end
data/test/test_all ADDED
@@ -0,0 +1,26 @@
1
+ #! /bin/sh
2
+ # run all applicable test cases with proper setup
3
+ # $0 [-a: all, even failing]
4
+ # $0 ./a_single_testcase
5
+ if [ "$1" = "" ]; then
6
+ : ${CASES:=./t[01234-9]* ./*_test.rb}
7
+ elif [ "$1" = "-a" ]; then
8
+ : ${CASES:=./t? ./t*-* ./*_test.rb}
9
+ OPTS=-k
10
+ else
11
+ : ${CASES:=$@}
12
+ fi
13
+ CASES_A=($CASES) # make array
14
+ CASES_A=(${CASES_A[@]/*~/}) # exclude backup files
15
+ if ! which python >/dev/null; then
16
+ echo >&2 "Python not found, skipping those tests"
17
+ CASES_A=(${CASES_A[@]/*.py/}) # exclude python files
18
+ fi
19
+
20
+ #export DBUS_VERBOSE=1
21
+ #export RUBYOPT="-d"
22
+ export RUBYOPT="$RUBYOPT -w"
23
+ RUBYLIB=../lib ./test_server $OPTS \
24
+ ./service_newapi.rb \
25
+ -- \
26
+ ${CASES_A[@]}
data/test/test_server ADDED
@@ -0,0 +1,47 @@
1
+ #! /bin/sh
2
+ # A wrapper for DBus tests
3
+ # Sets up a private session bus and calls all its arguments in turn
4
+ # exiting on first failure
5
+ # $0 server [-k] [arg1 arg2...] -- test1 test2...
6
+ set -o errexit
7
+
8
+ KEEP_GOING=false
9
+ if [ "$1" = "-k" ]; then
10
+ KEEP_GOING=true
11
+ shift
12
+ fi
13
+
14
+ while [ "$1" != "--" ]; do
15
+ SERVER="$SERVER $1"
16
+ shift
17
+ done
18
+ shift # --
19
+
20
+ # This launches the bus daemon,
21
+ # exports DBUS_SESSION_BUS_ADDRESS and sets DBUS_SESSION_BUS_PID
22
+ my_dbus_launch () {
23
+ # reimplementing dbus-launch because it is in dbus-1-x11.rpm
24
+ PF=`mktemp --tmpdir dbus.pid.XXXXXX` || exit
25
+ AF=`mktemp --tmpdir dbus.addr.XXXXXX` || exit
26
+
27
+ dbus-daemon --session --print-address=3 3>$AF --print-pid=4 4>$PF &
28
+ # wait for the daemon to print the info
29
+ while [ ! -s $AF -a ! -s $PF ]; do sleep 0.1; done
30
+ DBUS_SESSION_BUS_PID=$(cat $PF)
31
+ export DBUS_SESSION_BUS_ADDRESS=$(cat $AF)
32
+ # Clean up at exit. This will also kill the server.
33
+ trap "kill $DBUS_SESSION_BUS_PID; rm $AF $PF" EXIT TERM INT
34
+ }
35
+
36
+ my_dbus_launch
37
+ echo -n "Hey, server, get on da bus... "
38
+ # start the server
39
+ $SERVER & sleep 3
40
+ echo "off we go!"
41
+
42
+ while [ -n "$1" ]; do
43
+ echo Running $1
44
+ $1 || $KEEP_GOING
45
+ shift
46
+ done
47
+ echo Done
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mvidner-ruby-dbus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.10
5
+ platform: ruby
6
+ authors:
7
+ - Ruby DBus Team
8
+ autorequire: dbus
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ruby-dbus-devel@lists.luon.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - ChangeLog
24
+ - COPYING
25
+ - README
26
+ - NEWS
27
+ files:
28
+ - doc/tutorial
29
+ - doc/tutorial/src
30
+ - doc/tutorial/src/00.index.page
31
+ - doc/tutorial/src/10.intro.page
32
+ - doc/tutorial/src/20.basic_client.page
33
+ - doc/tutorial/src/30.service.page
34
+ - doc/tutorial/src/default.css
35
+ - doc/tutorial/src/default.template
36
+ - examples/gdbus
37
+ - examples/gdbus/gdbus
38
+ - examples/gdbus/gdbus.glade
39
+ - examples/gdbus/launch.sh
40
+ - examples/no-introspect
41
+ - examples/no-introspect/nm-test.rb
42
+ - examples/no-introspect/tracker-test.rb
43
+ - examples/rhythmbox
44
+ - examples/rhythmbox/playpause.rb
45
+ - examples/service
46
+ - examples/service/call_service.rb
47
+ - examples/service/service_newapi.rb
48
+ - examples/simple
49
+ - examples/simple/call_introspect.rb
50
+ - examples/utils
51
+ - examples/utils/listnames.rb
52
+ - examples/utils/notify.rb
53
+ - lib/dbus
54
+ - lib/dbus.rb
55
+ - lib/dbus/auth.rb
56
+ - lib/dbus/bus.rb
57
+ - lib/dbus/export.rb
58
+ - lib/dbus/introspect.rb
59
+ - lib/dbus/marshall.rb
60
+ - lib/dbus/matchrule.rb
61
+ - lib/dbus/message.rb
62
+ - lib/dbus/type.rb
63
+ - setup.rb
64
+ - test/Makefile
65
+ - test/bus_driver_test.rb
66
+ - test/service_newapi.rb
67
+ - test/t1
68
+ - test/t2.rb
69
+ - test/t3-ticket27.rb
70
+ - test/t5-report-dbus-interface.rb
71
+ - test/t6-loop.rb
72
+ - test/test_all
73
+ - test/test_server
74
+ - ChangeLog
75
+ - COPYING
76
+ - README
77
+ - NEWS
78
+ has_rdoc: true
79
+ homepage: http://trac.luon.net/data/ruby-dbus/
80
+ licenses:
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.5
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: Ruby module for interaction with DBus
105
+ test_files: []
106
+