json-rpc / tests / run.scm

(require-extension test)
(use json-rpc-client)

; Setup global string ports and server for testing
(define input (open-input-string "some-string"))
(define output (open-output-string))
(define xbmc (json-rpc-server input output "2.0"))

; Setup own test procedure with locally scoped output ports
(define (test-server description expected method . params)
  (let ((output (open-output-string)))
    (apply (json-rpc-server input output "2.0") method params)
    (test
     description
     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))

; Do some actual error testing
(test-group "Non-port or non-version calls"
	    (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 #f)))

(test-group "Non-keyword param calls"
	    (test-error "Call params as a list" (xbmc "foo" '(a b c)))
	    (test-error "Call params as a string" (xbmc "foo" "bar"))
	    (test-error "Call params as a number" (xbmc "foo" 1)))

(test-exit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.