1. Tim van der Linden
  2. json-rpc

Commits

Tim van der Linden  committed 8b7c160

Fixed tests and chaned version keyword to an optional argument.

  • Participants
  • Parent commits e0454b4
  • Branches default

Comments (0)

Files changed (2)

File json-rpc-client.scm

View file
  • Ignore whitespace
 ;; - input: input port of the JSON-RPC server
 ;; - ouptput: ouput port of the JSON-RPC server
 ;; - version: the JSON-RPC version in which we want to communicate
-(define (json-rpc-server input output #!key (version "2.0"))
+(define (json-rpc-server input output #!optional (version "2.0"))
     (cond ((not (input-port? input)) (server-setup-arguments-error "input port" "input-port" (get-type input)))
 	  ((not (output-port? output)) (server-setup-arguments-error "output port" "ouput-port" (get-type output)))
 	  ((not (is-valid-version? version)) (server-setup-arguments-error "version" "2.0" version))

File tests/run.scm

View file
  • Ignore whitespace
 (define xbmc (json-rpc-server input output "2.0"))
 
 ; Setup own test procedure with locally scoped output ports
-(define (test-server message expected method params)
+(define (test-server message expected method . params)
   (let ((output (open-output-string)))
-    (if (null? params)
-	 ((json-rpc-server input output "2.0") method)
-	 ((json-rpc-server input output "2.0") method params))
+    (apply (json-rpc-server input output "2.0") method params)
     (test
      message
      expected
      (get-output-string output))))
 
 (test-group "JSON-RPC string output checks"
-	    (test-server "Call with only a method" "{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"id\":\"1\"}" "Player.PlayPause" '())
-	    (test-server "Call with a method and a one dimensional params" "{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"params\":[\"playerid:0\"],\"id\":\"1\"}" "Player.PlayPause" 'playerid:0))
+	    (test-server "Call with only a method" "{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"id\":\"1\"}" "Player.PlayPause")
+	    (test-server "Call with a method and a one dimensional params" "{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"params\":{\"playerid\":0},\"id\":\"1\"}" "Player.PlayPause" playerid: 0))
 
 ; Do some actual error testing
 (test-group "Non-port or non-version calls"
-	    (test-error "Non port call on input" (define xbmc0 (json-rpc-server "input" output "2.0")))
-	    (test-error "Non port call on output" (define xbmc1 (json-rpc-server input "output" "2.0"))))
+	    (test-error "Non port call on input" (json-rpc-server "input" output "2.0"))
+	    (test-error "Non port call on output" (json-rpc-server input "output" "2.0"))
+	    (test-error "Non correct version number call" (json-rpc-server input output "3.0")))
 
 (test-group "Non-string method calls"
 	    (test-error "Call method as symbol" (xbmc 'foo))
 	    (test-error "Call method as number" (xbmc 1))
 	    (test-error "Call method as list" (xbmc '(1 2)))
 	    (test-error "Call method as vector" (xbmc '#()))
-	    (test-error "Call method as boolean" (xbmc 1)))
+	    (test-error "Call method as boolean" (xbmc #f)))
 
 (test-group "Non-keyword param calls"
 	    (test-error "Call params as a list" (xbmc "foo" '(a b c)))