1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/env rspec
# Test that a server survives various error cases
require_relative "spec_helper"
require "dbus"
describe "ServerRobustnessTest" do
before(:each) do
@bus = DBus::ASessionBus.new
@svc = @bus.service("org.ruby.service")
end
# https://trac.luon.net/ruby-dbus/ticket/31
# the server should not crash
it "tests no such path with introspection" do
obj = @svc.object "/org/ruby/NotMyInstance"
expect { obj.introspect }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
it "tests no such path without introspection" do
obj = @svc.object "/org/ruby/NotMyInstance"
ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
ifc.define_method("the_answer", "out n:i")
expect { ifc.the_answer }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
it "tests a method that raises" do
obj = @svc.object "/org/ruby/MyInstance"
obj.default_iface = "org.ruby.SampleInterface"
expect { obj.will_raise }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
it "tests a method that raises name error" do
obj = @svc.object "/org/ruby/MyInstance"
obj.default_iface = "org.ruby.SampleInterface"
expect { obj.will_raise_name_error }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
# https://trac.luon.net/ruby-dbus/ticket/31#comment:3
it "tests no such method without introspection" do
obj = @svc.object "/org/ruby/MyInstance"
ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
ifc.define_method("not_the_answer", "out n:i")
expect { ifc.not_the_answer }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
it "tests no such interface without introspection" do
obj = @svc.object "/org/ruby/MyInstance"
ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.NoSuchInterface")
ifc.define_method("the_answer", "out n:i")
expect { ifc.the_answer }.to raise_error(DBus::Error) do |e|
expect(e).to_not match(/timeout/)
end
end
end
|