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,11 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # Test the signal handlers
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 SignalHandlerTest < Test::Unit::TestCase
8
- def setup
6
+ describe "SignalHandlerTest" 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")
@@ -18,7 +17,7 @@ class SignalHandlerTest < Test::Unit::TestCase
18
17
  end
19
18
 
20
19
  # testing for commit 017c83 (kkaempf)
21
- def test_overriding_a_handler
20
+ it "tests overriding a handler" do
22
21
  DBus.logger.debug "Inside test_overriding_a_handler"
23
22
  counter = 0
24
23
 
@@ -47,10 +46,10 @@ class SignalHandlerTest < Test::Unit::TestCase
47
46
  @loop.run
48
47
  quitter.join
49
48
 
50
- assert_equal 1, counter
49
+ expect(counter).to eq(1)
51
50
  end
52
51
 
53
- def test_on_signal_overload
52
+ it "tests on signal overload" do
54
53
  DBus.logger.debug "Inside test_on_signal_overload"
55
54
  counter = 0
56
55
  started = false
@@ -71,13 +70,13 @@ class SignalHandlerTest < Test::Unit::TestCase
71
70
  @loop.run
72
71
  quitter.join
73
72
 
74
- assert_equal true, started
75
- assert_equal 1, counter
76
- assert_raise(ArgumentError) {@intf.on_signal } # not enough
77
- assert_raise(ArgumentError) {@intf.on_signal 'to', 'many', 'yarrrrr!'}
73
+ expect(started).to eq(true)
74
+ expect(counter).to eq(1)
75
+ expect { @intf.on_signal }.to raise_error(ArgumentError) # not enough
76
+ expect { @intf.on_signal 'to', 'many', 'yarrrrr!' }.to raise_error(ArgumentError)
78
77
  end
79
78
 
80
- def test_too_many_rules
79
+ it "tests too many rules" do
81
80
  100.times do
82
81
  @obj.on_signal "Whichever" do
83
82
  puts "not called"
@@ -85,7 +84,7 @@ class SignalHandlerTest < Test::Unit::TestCase
85
84
  end
86
85
  end
87
86
 
88
- def test_removing_a_nonexistent_rule
87
+ it "tests removing a nonexistent rule" do
89
88
  @obj.on_signal "DoesNotExist"
90
89
  end
91
90
  end
@@ -0,0 +1,33 @@
1
+ if ENV["COVERAGE"]
2
+ coverage = ENV["COVERAGE"] == "true"
3
+ else
4
+ # heuristics: enable for interactive builds (but not in OBS) or in Travis
5
+ coverage = !!ENV["DISPLAY"] || ENV["TRAVIS"]
6
+ end
7
+
8
+ if coverage
9
+ require "simplecov"
10
+ SimpleCov.root File.expand_path("../..", __FILE__)
11
+
12
+ # do not cover specs
13
+ SimpleCov.add_filter "_spec.rb"
14
+ # do not cover the activesupport helpers
15
+ SimpleCov.add_filter "/core_ext/"
16
+
17
+ # use coveralls for on-line code coverage reporting at Travis CI
18
+ if ENV["TRAVIS"]
19
+ require "coveralls"
20
+ end
21
+ SimpleCov.start
22
+ end
23
+
24
+ $:.unshift File.expand_path("../../lib", __FILE__)
25
+
26
+ if Object.const_defined? "RSpec"
27
+ # http://betterspecs.org/#expect
28
+ RSpec.configure do |config|
29
+ config.expect_with :rspec do |c|
30
+ c.syntax = :expect
31
+ end
32
+ end
33
+ end
@@ -1,11 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # Test thread safety
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 ThreadSafetyTest < Test::Unit::TestCase
8
- def test_thread_competition
6
+ describe "ThreadSafetyTest" do
7
+ it "tests thread competition" do
9
8
  print "Thread competition: "
10
9
  jobs = []
11
10
  5.times do
@@ -22,7 +21,7 @@ class ThreadSafetyTest < Test::Unit::TestCase
22
21
  10.times do |i|
23
22
  print "#{i} "
24
23
  $stdout.flush
25
- assert_equal 42, obj.the_answer[0]
24
+ expect(obj.the_answer[0]).to eq(42)
26
25
  sleep 0.1 * rand
27
26
  end
28
27
  end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rspec
2
+ require_relative "spec_helper"
3
+ require "dbus"
4
+
5
+ describe DBus do
6
+ describe ".type" do
7
+ %w{i ai a(ii) aai}.each do |s|
8
+ it "parses some type #{s}" do
9
+ expect(DBus::type(s).to_s).to be_eql s
10
+ end
11
+ end
12
+
13
+ %w{aa (ii ii) hrmp}.each do |s|
14
+ it "raises exception for invalid type #{s}" do
15
+ expect {DBus::type(s).to_s}.to raise_error DBus::Type::SignatureException
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,11 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
  # -*- coding: utf-8 -*-
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 ValueTest < Test::Unit::TestCase
8
- def setup
6
+ describe "ValueTest" 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")
@@ -13,7 +12,7 @@ class ValueTest < Test::Unit::TestCase
13
12
  @obj.default_iface = "org.ruby.SampleInterface"
14
13
  end
15
14
 
16
- def test_passing_an_array_of_structs_through_a_variant
15
+ it "tests passing an array of structs through a variant" do
17
16
  triple = ['a(uuu)', []]
18
17
  @obj.test_variant(triple)
19
18
  quadruple = ['a(uuuu)', []] # a(uuu) works fine
@@ -22,7 +21,7 @@ class ValueTest < Test::Unit::TestCase
22
21
  @obj.test_variant(quadruple)
23
22
  end
24
23
 
25
- def test_passing_an_array_through_a_variant
24
+ it "tests passing an array through a variant" do
26
25
  # old explicit typing
27
26
  @obj.test_variant(["as", ["coucou", "kuku"]])
28
27
  # automatic typing
@@ -30,53 +29,53 @@ class ValueTest < Test::Unit::TestCase
30
29
  @obj.test_variant(["saint", "was that a word or a signature?"])
31
30
  end
32
31
 
33
- def test_bouncing_a_variant
34
- assert_equal "cuckoo", @obj.bounce_variant("cuckoo")[0]
35
- assert_equal ["coucou", "kuku"], @obj.bounce_variant(["coucou", "kuku"])[0]
36
- assert_equal [], @obj.bounce_variant([])[0]
32
+ it "tests bouncing a variant" do
33
+ expect(@obj.bounce_variant("cuckoo")[0]).to eq("cuckoo")
34
+ expect(@obj.bounce_variant(["coucou", "kuku"])[0]).to eq(["coucou", "kuku"])
35
+ expect(@obj.bounce_variant([])[0]).to eq([])
37
36
  empty_hash = {}
38
- assert_equal empty_hash, @obj.bounce_variant(empty_hash)[0]
37
+ expect(@obj.bounce_variant(empty_hash)[0]).to eq(empty_hash)
39
38
  end
40
39
 
41
40
  # these are ambiguous
42
- def test_pairs_with_a_string
41
+ it "tests pairs with a string" do
43
42
 
44
43
  # deprecated
45
- assert_equal "foo", @obj.bounce_variant(["s", "foo"])[0]
44
+ expect(@obj.bounce_variant(["s", "foo"])[0]).to eq("foo")
46
45
 
47
- assert_equal "foo", @obj.bounce_variant(DBus.variant("s", "foo"))[0]
48
- assert_equal "foo", @obj.bounce_variant([DBus.type("s"), "foo"])[0]
46
+ expect(@obj.bounce_variant(DBus.variant("s", "foo"))[0]).to eq("foo")
47
+ expect(@obj.bounce_variant([DBus.type("s"), "foo"])[0]).to eq("foo")
49
48
 
50
49
  # does not work, because the server side forgets the explicit typing
51
50
  # assert_equal ["s", "foo"], @obj.bounce_variant(["av", ["s", "foo"]])[0]
52
51
  # assert_equal ["s", "foo"], @obj.bounce_variant(["as", ["s", "foo"]])[0]
53
52
 
54
53
  # instead, use this to demonstrate that the variant is passed as expected
55
- assert_equal 4, @obj.variant_size(["s", "four"])[0]
54
+ expect(@obj.variant_size(["s", "four"])[0]).to eq(4)
56
55
  # "av" is the simplest thing that will work,
57
56
  # shifting the heuristic from a pair to the individual items
58
- assert_equal 2, @obj.variant_size(["av", ["s", "four"]])[0]
57
+ expect(@obj.variant_size(["av", ["s", "four"]])[0]).to eq(2)
59
58
  end
60
59
 
61
- def test_marshalling_an_array_of_variants
60
+ it "tests marshalling an array of variants" do
62
61
  # https://trac.luon.net/ruby-dbus/ticket/30
63
62
  @obj.default_iface = "org.ruby.Ticket30"
64
63
  choices = []
65
64
  choices << ['s', 'Plan A']
66
65
  choices << ['s', 'Plan B']
67
66
  # old explicit typing
68
- assert_equal "Do Plan A", @obj.Sybilla(choices)[0]
67
+ expect(@obj.Sybilla(choices)[0]).to eq("Do Plan A")
69
68
  # automatic typing
70
- assert_equal "Do Plan A", @obj.Sybilla(["Plan A", "Plan B"])[0]
69
+ expect(@obj.Sybilla(["Plan A", "Plan B"])[0]).to eq("Do Plan A")
71
70
  end
72
71
 
73
- def test_service_returning_nonarray
72
+ it "tests service returning nonarray" do
74
73
  # "warning: default `to_a' will be obsolete"
75
74
  @obj.the_answer
76
75
  end
77
76
 
78
- def test_multibyte_string
77
+ it "tests multibyte string" do
79
78
  str = @obj.multibyte_string[0]
80
- assert_equal "あいうえお", str
79
+ expect(str).to eq("あいうえお")
81
80
  end
82
81
  end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env rspec
2
+ # Test marshalling variants according to ruby types
3
+ require_relative "spec_helper"
4
+ require "dbus"
5
+
6
+ describe "VariantTest" do
7
+ before(:each) do
8
+ @bus = DBus::ASessionBus.new
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
+ it "tests make variant scalar" do
17
+ # special case: do not fail immediately, marshaller will do that
18
+ expect(make_variant(nil)).to eq(["b", nil])
19
+
20
+ expect(make_variant(true)).to eq(["b", true])
21
+ # Integers
22
+ # no byte
23
+ expect(make_variant(42)).to eq(["i", 42])
24
+ # 3_000_000_000 can be u or x.
25
+ # less specific test: just run it thru a loopback
26
+ expect(make_variant(3_000_000_000)).to eq(["x", 3_000_000_000])
27
+ expect(make_variant(5_000_000_000)).to eq(["x", 5_000_000_000])
28
+
29
+ expect(make_variant(3.14)).to eq(["d", 3.14])
30
+
31
+ expect(make_variant("foo")).to eq(["s", "foo"])
32
+ expect(make_variant(:bar)).to eq(["s", "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
+ it "tests make variant array" do
45
+ ai = [1, 2, 3]
46
+ # as = ["one", "two", "three"]
47
+ # which?
48
+ # expect(make_variant(ai)).to eq(["ai", [1, 2, 3]])
49
+ expect(make_variant(ai)).to eq(["av", [["i", 1],
50
+ ["i", 2],
51
+ ["i", 3]]])
52
+ a0 = []
53
+ expect(make_variant(a0)).to eq(["av", []])
54
+
55
+ end
56
+
57
+ it "tests make variant hash" do
58
+ h = {"k1" => "v1", "k2" => "v2"}
59
+ expect(make_variant(h)).to eq(["a{sv}", {
60
+ "k1" => ["s", "v1"],
61
+ "k2" => ["s", "v2"],
62
+ }])
63
+ h0 = {}
64
+ expect(make_variant(h0)).to eq(["a{sv}", {}])
65
+ end
66
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby DBus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: packaging_rake_tasks
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Pure Ruby module for interaction with D-Bus IPC system
28
42
  email: ruby-dbus-devel@lists.luon.net
29
43
  executables: []
@@ -71,34 +85,38 @@ files:
71
85
  - lib/dbus/marshall.rb
72
86
  - lib/dbus/matchrule.rb
73
87
  - lib/dbus/message.rb
88
+ - lib/dbus/message_queue.rb
89
+ - lib/dbus/proxy_object.rb
90
+ - lib/dbus/proxy_object_factory.rb
91
+ - lib/dbus/proxy_object_interface.rb
74
92
  - lib/dbus/type.rb
75
93
  - lib/dbus/xml.rb
76
94
  - ruby-dbus.gemspec
77
- - test/async_test.rb
78
- - test/binding_test.rb
79
- - test/bus_and_xml_backend_test.rb
80
- - test/bus_driver_test.rb
81
- - test/bus_test.rb
82
- - test/byte_array_test.rb
83
- - test/err_msg_test.rb
84
- - test/introspect_xml_parser_test.rb
85
- - test/introspection_test.rb
86
- - test/main_loop_test.rb
87
- - test/property_test.rb
88
- - test/server_robustness_test.rb
89
- - test/server_test.rb
95
+ - test/async_spec.rb
96
+ - test/binding_spec.rb
97
+ - test/bus_and_xml_backend_spec.rb
98
+ - test/bus_driver_spec.rb
99
+ - test/bus_spec.rb
100
+ - test/byte_array_spec.rb
101
+ - test/err_msg_spec.rb
102
+ - test/introspect_xml_parser_spec.rb
103
+ - test/introspection_spec.rb
104
+ - test/main_loop_spec.rb
105
+ - test/property_spec.rb
106
+ - test/server_robustness_spec.rb
107
+ - test/server_spec.rb
90
108
  - test/service_newapi.rb
91
- - test/session_bus_test_manual.rb
92
- - test/signal_test.rb
93
- - test/test_helper.rb
94
- - test/thread_safety_test.rb
109
+ - test/session_bus_spec_manual.rb
110
+ - test/signal_spec.rb
111
+ - test/spec_helper.rb
112
+ - test/thread_safety_spec.rb
95
113
  - test/tools/dbus-launch-simple
96
114
  - test/tools/dbus-limited-session.conf
97
115
  - test/tools/test_env
98
116
  - test/tools/test_server
99
- - test/type_test.rb
100
- - test/value_test.rb
101
- - test/variant_test.rb
117
+ - test/type_spec.rb
118
+ - test/value_spec.rb
119
+ - test/variant_spec.rb
102
120
  homepage: https://trac.luon.net/ruby-dbus
103
121
  licenses:
104
122
  - LGPL v2.1
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test the bus class
3
- require File.expand_path("../test_helper", __FILE__)
4
- require "test/unit"
5
- require 'rubygems'
6
- require 'nokogiri'
7
- require "dbus"
8
-
9
- class BusAndXmlBackendTest < Test::Unit::TestCase
10
- def setup
11
- @bus = DBus::ASessionBus.new
12
- end
13
-
14
- def test_introspection_reading_rexml
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
- assert_nothing_raised do
21
- assert_equal 42, obj.the_answer[0], "should respond to :the_answer"
22
- end
23
- assert_nothing_raised do
24
- assert_equal "oof", obj["org.ruby.AnotherInterface"].Reverse('foo')[0], "should work with multiple interfaces"
25
- end
26
- end
27
-
28
- def test_introspection_reading_nokogiri
29
- # peek inside the object to see if a cleanup step worked or not
30
- DBus::IntrospectXMLParser.backend = DBus::IntrospectXMLParser::NokogiriParser
31
- @svc = @bus.service("org.ruby.service")
32
- obj = @svc.object("/org/ruby/MyInstance")
33
- obj.default_iface = 'org.ruby.SampleInterface'
34
- obj.introspect
35
- assert_nothing_raised do
36
- assert_equal 42, obj.the_answer[0], "should respond to :the_answer"
37
- end
38
- assert_nothing_raised do
39
- assert_equal "oof", obj["org.ruby.AnotherInterface"].Reverse('foo')[0], "should work with multiple interfaces"
40
- end
41
- end
42
-
43
- end