AT_BANNER([JSON-RPC - C])

AT_SETUP([JSON-RPC request and successful reply])
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile listen punix:socket])
on_exit 'kill `cat test-jsonrpc.pid`'
AT_CHECK(
  [[ovstest test-jsonrpc request unix:socket echo '[{"a": "b", "x": null}]']], [0],
  [[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
]])
AT_CLEANUP

AT_SETUP([JSON-RPC request and error reply])
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile listen punix:socket])
on_exit 'kill `cat test-jsonrpc.pid`'
AT_CHECK(
  [[ovstest test-jsonrpc request unix:socket bad-request '[]']], [0],
  [[{"error":{"error":"unknown method"},"id":0,"result":null}
]])
AT_CLEANUP

AT_SETUP([JSON-RPC notification])
AT_CHECK([ovstest test-jsonrpc --detach --no-chdir --pidfile listen punix:socket])
on_exit 'kill `cat test-jsonrpc.pid`'
# Check that the pidfile got created.
AT_CHECK([test -e test-jsonrpc.pid])
AT_CHECK([[ovstest test-jsonrpc notify unix:socket shutdown '[]']])
# Wait for test-jsonrpc to die, based on its pidfile disappearing
OVS_WAIT_WHILE([test -e test-jsonrpc.pid])
AT_CLEANUP
