test/xmlrpc/tc_unix.rb in xmlrpcs-0.1 vs test/xmlrpc/tc_unix.rb in xmlrpcs-0.1.1

- old
+ new

@@ -1,14 +1,15 @@ #! /usr/bin/ruby # Author: Dario Meloni <mellon85@gmail.com> +require 'rubygems' require 'test/unit' -require 'xmlrpcs' +require 'xmlrpc/xmlrpcs' require 'xmlrpc/server' require 'socket' -$socket_path="test.sock" +$socket_path="/tmp/test.sock" class UnixXMLClient < XMLRPC::ClientS def new_socket(info,async) UNIXSocket.new(info) end @@ -24,12 +25,19 @@ end end class UnixXMLServer < XMLRPC::BasicServer - def serve() + attr_reader :path + + def initialize( path ) + super() + @path = path @server = UNIXServer.new(@path) + end + + def serve() catch (:exit_serve) { while(true) @server.listen(5) client, client_addr = @server.accept l = client.readline @@ -39,19 +47,17 @@ client.write(pdata) client.close end } end - - attr_accessor :path end class TC_xmlrpcs_unix < Test::Unit::TestCase def setup - @s = UnixXMLServer.new() - @s.path=$socket_path + @s = UnixXMLServer.new($socket_path) @s.add_introspection + @s.add_multicall @s.add_handler("test.add") do |a,b| a+b end @t = Thread.new do @s.serve @@ -62,10 +68,14 @@ Thread.kill(@t) File.unlink($socket_path) end def test_create - c = UnixXMLClient.new($socket_path) - assert(c.call("test.add",2,3) == 5, "Failed calling test.add") - assert(c.call("system.listMethods"),"Failed system.listMethods") + client = UnixXMLClient.new($socket_path) + assert(client.call("test.add",2,3) == 5, "Failed calling add") + proxy = client.proxy "test" + assert(proxy.add(1,4) == 5,"Failed using the proxy") + a, b = client.multicall(["test.add",3,2],["test.add",4,1]) + assert( a == 5 && b == 5, "Failed multicall") + assert(client.call("system.listMethods"),"Failed system.listMethods") end end