ruby-dbus 0.9.1 → 0.9.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.2
data/doc/Reference.md CHANGED
@@ -108,7 +108,11 @@ Variants are simply unpacked to become their contained type.
108
108
 
109
109
  D-Bus has stricter typing than Ruby, so the library must decide
110
110
  which D-Bus type to choose. Most of the time the choice is dictated
111
- by the D-Bus signature. However if the signature expects a Variant
111
+ by the D-Bus signature.
112
+
113
+ ##### Variants
114
+
115
+ If the signature expects a Variant
112
116
  (which is the case for all Properties!) then an explicit mechanism is needed.
113
117
 
114
118
  1. A pair [{DBus::Type::Type}, value] specifies to marshall *value* as
@@ -119,6 +123,8 @@ by the D-Bus signature. However if the signature expects a Variant
119
123
  ISSUE: using something else than cryptic signatures is even more painful
120
124
  than remembering the signatures!
121
125
 
126
+ foo_i['Bar'] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
127
+
122
128
  2. Other values are tried to fit one of these:
123
129
  Boolean, Double, Array of Variants, Hash of String keyed Variants,
124
130
  String, Int32, Int64.
@@ -128,12 +134,17 @@ by the D-Bus signature. However if the signature expects a Variant
128
134
  type. This will hit you when you rely on method (2) but happen to have
129
135
  a particular string value in an array.
130
136
 
137
+ ##### Byte Arrays
138
+
139
+ If a byte array (`ay`) is expected you can pass a String too.
140
+ The bytes sent are according to the string's
141
+ [encoding](http://ruby-doc.org/core-1.9.3/Encoding.html).
142
+
143
+ ##### nil
131
144
 
132
145
  `nil` is not allowed by D-Bus and attempting to send it raises an exception
133
146
  (but see [I#16](https://github.com/mvidner/ruby-dbus/issues/16)).
134
147
 
135
- foo_i['Bar'] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
136
-
137
148
 
138
149
  #### Errors
139
150
 
data/lib/dbus/marshall.rb CHANGED
@@ -382,8 +382,12 @@ module DBus
382
382
  # Damn ruby rocks here
383
383
  val = val.to_a
384
384
  end
385
- if not val.kind_of?(Array)
386
- raise TypeException, "Expected an Array but got a #{val.class}"
385
+ # If string is recieved and ay is expected, explode the string
386
+ if val.kind_of?(String) && type.child.sigtype == Type::BYTE
387
+ val = val.bytes
388
+ end
389
+ if not val.kind_of?(Enumerable)
390
+ raise TypeException, "Expected an Enumerable of #{type.child.inspect} but got a #{val.class}"
387
391
  end
388
392
  array(type.child) do
389
393
  val.each do |elem|
data/lib/dbus/xml.rb CHANGED
@@ -97,8 +97,12 @@ module DBus
97
97
 
98
98
  # return a pair: [list of Interfaces, list of direct subnode names]
99
99
  def parse
100
- interfaces = Array.new
101
- subnodes = Array.new
100
+ # Using a Hash instead of a list helps merge split-up interfaces,
101
+ # a quirk observed in ModemManager (I#41).
102
+ interfaces = Hash.new do |hash, missing_key|
103
+ hash[missing_key] = Interface.new(missing_key)
104
+ end
105
+ subnodes = []
102
106
  t = Time.now
103
107
 
104
108
 
@@ -107,7 +111,7 @@ module DBus
107
111
  subnodes << e["name"]
108
112
  end
109
113
  d.each("node/interface") do |e|
110
- i = Interface.new(e["name"])
114
+ i = interfaces[e["name"]]
111
115
  e.each("method") do |me|
112
116
  m = Method.new(me["name"])
113
117
  parse_methsig(me, m)
@@ -118,13 +122,12 @@ module DBus
118
122
  parse_methsig(se, s)
119
123
  i << s
120
124
  end
121
- interfaces << i
122
125
  end
123
126
  d = Time.now - t
124
127
  if d > 2
125
128
  DBus.logger.debug "Some XML took more that two secs to parse. Optimize me!"
126
129
  end
127
- [interfaces, subnodes]
130
+ [interfaces.values, subnodes]
128
131
  end
129
132
 
130
133
  ######################################################################
data/test/async_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the binding of dbus concepts to ruby concepts
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/binding_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the binding of dbus concepts to ruby concepts
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the bus class
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require 'rubygems'
5
6
  require 'nokogiri'
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the methods of the bus driver
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/bus_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the bus class
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
@@ -0,0 +1,42 @@
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
@@ -8,7 +8,7 @@
8
8
  <type>session</type>
9
9
 
10
10
  <listen>unix:tmpdir=/tmp</listen>
11
- <listen>tcp:host=127.0.0.1,port=0,family=ipv4</listen>
11
+ <listen>tcp:host=127.0.0.1</listen>
12
12
 
13
13
  <standard_session_servicedirs />
14
14
 
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class IntrospectXMLParserTest < Test::Unit::TestCase
7
+ def test_split_interfaces
8
+ xml = <<EOS
9
+ <node>
10
+ <interface name="org.example.Foo">
11
+ <method name="Dwim"/>
12
+ </interface>
13
+ <interface name="org.example.Bar">
14
+ <method name="Drink"/>
15
+ </interface>
16
+ <interface name="org.example.Foo">
17
+ <method name="Smurf"/>
18
+ </interface>
19
+ </node>
20
+ EOS
21
+
22
+ interfaces, _ = DBus::IntrospectXMLParser.new(xml).parse
23
+
24
+ foo = interfaces.find {|i| i.name == "org.example.Foo" }
25
+ assert_equal 2, foo.methods.keys.size
26
+ end
27
+ end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
2
3
  require "test/unit"
3
4
  require "dbus"
4
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
2
3
  require "test/unit"
3
4
  require "dbus"
4
5
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test that a server survives various error cases
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/server_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test that a server survives various error cases
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require File.expand_path("../test_helper", __FILE__)
5
+ SimpleCov.command_name "Service Tests" if Object.const_defined? "SimpleCov"
4
6
  # find the library without external help
5
7
  $:.unshift File.expand_path("../../lib", __FILE__)
6
8
 
@@ -23,7 +25,7 @@ class Test < DBus::Object
23
25
  end
24
26
 
25
27
  dbus_method :test_variant, "in stuff:v" do |variant|
26
- p variant
28
+ DBus.logger.debug variant.inspect
27
29
  end
28
30
 
29
31
  dbus_method :bounce_variant, "in stuff:v, out chaff:v" do |variant|
@@ -53,6 +55,10 @@ class Test < DBus::Object
53
55
  dbus_method :Error, "in name:s, in description:s" do |name, description|
54
56
  raise DBus.error(name), description
55
57
  end
58
+
59
+ dbus_method :mirror_byte_array, "in bytes:ay, out mirrored:ay" do |bytes|
60
+ [bytes]
61
+ end
56
62
  end
57
63
 
58
64
  # closing and reopening the same interface
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
2
3
  require "test/unit"
3
4
  require "dbus"
4
5
 
data/test/signal_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the signal handlers
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/t2.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/t3-ticket27.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test passing a particular struct array through a variant
3
3
  # https://trac.luon.net/ruby-dbus/ticket/27
4
+ require File.expand_path("../test_helper", __FILE__)
4
5
  require "dbus"
5
6
  session_bus = DBus::ASessionBus.new
6
7
  svc = session_bus.service("org.ruby.service")
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # should report it missing on org.ruby.SampleInterface
3
3
  # (on object...) instead of on DBus::Proxy::ObjectInterface
4
+ require File.expand_path("../test_helper", __FILE__)
4
5
  require "test/unit"
5
6
  require "dbus"
6
7
 
data/test/t6-loop.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the main loop
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
@@ -0,0 +1,14 @@
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,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test thread safety
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/type_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test the type class
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
data/test/variant_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Test marshalling variants according to ruby types
3
+ require File.expand_path("../test_helper", __FILE__)
3
4
  require "test/unit"
4
5
  require "dbus"
5
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-23 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Pure Ruby module for interaction with D-Bus IPC system
15
15
  email: ruby-dbus-devel@lists.luon.net
@@ -59,8 +59,10 @@ files:
59
59
  - test/bus_and_xml_backend_test.rb
60
60
  - test/bus_driver_test.rb
61
61
  - test/bus_test.rb
62
+ - test/byte_array_test.rb
62
63
  - test/dbus-launch-simple
63
64
  - test/dbus-limited-session.conf
65
+ - test/introspect_xml_parser_test.rb
64
66
  - test/introspection_test.rb
65
67
  - test/property_test.rb
66
68
  - test/server_robustness_test.rb
@@ -74,6 +76,7 @@ files:
74
76
  - test/t5-report-dbus-interface.rb
75
77
  - test/t6-loop.rb
76
78
  - test/test_env
79
+ - test/test_helper.rb
77
80
  - test/test_server
78
81
  - test/thread_safety_test.rb
79
82
  - test/type_test.rb