diff options
author | imarom <imarom@cisco.com> | 2015-08-13 14:36:39 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2015-08-13 14:36:39 +0300 |
commit | 324dea63203a5f0f53612651a32003150443ac30 (patch) | |
tree | f4562b54c6d6f20f3e61094ea146e12e3f08ca42 /src/gtest/rpc_test.cpp | |
parent | 583ef32a82dcd52cce9c1320f5141f91e40a0056 (diff) |
draft - some fixes
Diffstat (limited to 'src/gtest/rpc_test.cpp')
-rw-r--r-- | src/gtest/rpc_test.cpp | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp index f1510ef2..f80ebd5d 100644 --- a/src/gtest/rpc_test.cpp +++ b/src/gtest/rpc_test.cpp @@ -97,38 +97,37 @@ TEST_F(RpcTest, basic_rpc_test) { EXPECT_TRUE(response["id"] == 482); EXPECT_TRUE(response["error"]["code"] == -32600); - #if 0 - - - - int id = 1; - request["jsonrpc"] = "2.0"; - //request["method"] = "test_func"; +} - Json::Value ¶ms = request["params"]; - params["num"] = 12; - params["msg"] = "hello, method test_func"; +TEST_F(RpcTest, batch_rpc_test) { + Json::Value request; + Json::Value response; + Json::Reader reader; - for (int request_nbr = 0; request_nbr != 1; request_nbr++) { - //request["id"] = "itay_id"; + string req_str; + string resp_str; - stringstream ss; - ss << request; + req_str = "[ \ + {\"jsonrpc\": \"2.0\", \"method\": \"sum\", \"params\": [1,2,4], \"id\": \"1\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"notify_hello\", \"params\": [7]}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [42,23], \"id\": \"2\"}, \ + {\"foo\": \"boo\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"foo.get\", \"params\": {\"name\": \"myself\"}, \"id\": \"5\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"get_data\", \"id\": \"9\"} \ + ]"; - cout << "Sending : '" << ss.str() << "'\n"; - - zmq_send (requester, ss.str().c_str(), ss.str().size(), 0); + resp_str = send_msg(req_str); + cout << resp_str; + EXPECT_TRUE(reader.parse(resp_str, response, false)); + EXPECT_TRUE(response.isArray()); - int len = zmq_recv (requester, buffer, 250, 0); - string resp(buffer, buffer + len); - cout << "Got: " << resp << "\n"; - } - zmq_close (requester); - zmq_ctx_destroy (context); + // message 1 + EXPECT_TRUE(response[0]["jsonrpc"] == "2.0"); + EXPECT_TRUE(response[0]["id"] == "1"); - sleep(1); + // message 2 + EXPECT_TRUE(response[1]["jsonrpc"] == "2.0"); + EXPECT_TRUE(response[1]["id"] == "2"); - rpc.stop(); - #endif + return; } - |