From 2a4d1ac17610d15c65d6337306ffeda04ab29bef Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 19 Aug 2015 15:31:58 +0300 Subject: mock server --- src/gtest/rpc_test.cpp | 18 +++++++++--------- src/main.cpp | 13 ------------- src/rpc-server/src/trex_rpc_server_mock.cpp | 14 +++++++++++++- 3 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp index c616b7a6..068457f3 100644 --- a/src/gtest/rpc_test.cpp +++ b/src/gtest/rpc_test.cpp @@ -127,7 +127,7 @@ TEST_F(RpcTest, test_add_command) { string resp_str; /* simple add - missing paramters */ - req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"id\": 488}"; + req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"id\": 488}"; resp_str = send_msg(req_str); EXPECT_TRUE(reader.parse(resp_str, response, false)); @@ -136,7 +136,7 @@ TEST_F(RpcTest, test_add_command) { EXPECT_EQ(response["error"]["code"], -32602); /* simple add that works */ - req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": 17, \"y\": -13} , \"id\": \"itay\"}"; + req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": 17, \"y\": -13} , \"id\": \"itay\"}"; resp_str = send_msg(req_str); EXPECT_TRUE(reader.parse(resp_str, response, false)); @@ -145,7 +145,7 @@ TEST_F(RpcTest, test_add_command) { EXPECT_EQ(response["result"], 4); /* add with bad paratemers types */ - req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": \"blah\", \"y\": -13} , \"id\": 17}"; + req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": \"blah\", \"y\": -13} , \"id\": 17}"; resp_str = send_msg(req_str); EXPECT_TRUE(reader.parse(resp_str, response, false)); @@ -154,7 +154,7 @@ TEST_F(RpcTest, test_add_command) { EXPECT_EQ(response["error"]["code"], -32602); /* add with invalid count of parameters */ - req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"y\": -13} , \"id\": 17}"; + req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"y\": -13} , \"id\": 17}"; resp_str = send_msg(req_str); EXPECT_TRUE(reader.parse(resp_str, response, false)); @@ -164,7 +164,7 @@ TEST_F(RpcTest, test_add_command) { /* big numbers */ - req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": 4827371, \"y\": -39181273} , \"id\": \"itay\"}"; + req_str = "{\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": 4827371, \"y\": -39181273} , \"id\": \"itay\"}"; resp_str = send_msg(req_str); EXPECT_TRUE(reader.parse(resp_str, response, false)); @@ -183,12 +183,12 @@ TEST_F(RpcTest, batch_rpc_test) { string resp_str; req_str = "[ \ - {\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": 22, \"y\": 17}, \"id\": \"1\"}, \ - {\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_sub\", \"params\": {\"x\": 22, \"y\": 17}, \"id\": \"2\"}, \ - {\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": 22, \"y\": \"itay\"}, \"id\": \"2\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": 22, \"y\": 17}, \"id\": \"1\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_sub\", \"params\": {\"x\": 22, \"y\": 17}, \"id\": \"2\"}, \ + {\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": 22, \"y\": \"itay\"}, \"id\": \"2\"}, \ {\"foo\": \"boo\"}, \ {\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_sheker\", \"params\": {\"name\": \"myself\"}, \"id\": 5}, \ - {\"jsonrpc\": \"2.0\", \"method\": \"test_rpc_add\", \"params\": {\"x\": 22, \"y\": 17} } \ + {\"jsonrpc\": \"2.0\", \"method\": \"rpc_test_add\", \"params\": {\"x\": 22, \"y\": 17} } \ ]"; resp_str = send_msg(req_str); diff --git a/src/main.cpp b/src/main.cpp index ddcf81e2..96789cdd 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,19 +27,6 @@ limitations under the License. #include #include -/** - * on simulation this is not rebuild every version - * (improved stub) - * - */ -extern "C" const char * get_build_date(void){ - return (__DATE__); -} - -extern "C" const char * get_build_time(void){ - return (__TIME__ ); -} - // An enum for all the option types enum { OPT_HELP, OPT_CFG, OPT_NODE_DUMP, OP_STATS, OPT_FILE_OUT, OPT_UT, OPT_PCAP, OPT_IPV6, OPT_MAC_FILE}; diff --git a/src/rpc-server/src/trex_rpc_server_mock.cpp b/src/rpc-server/src/trex_rpc_server_mock.cpp index 3c63f74a..b01fff90 100644 --- a/src/rpc-server/src/trex_rpc_server_mock.cpp +++ b/src/rpc-server/src/trex_rpc_server_mock.cpp @@ -38,7 +38,19 @@ extern "C" const char * get_build_time(void){ return (__TIME__ ); } -int main() { +int gtest_main(int argc, char **argv); + +int main(int argc, char *argv[]) { + + // gtest ? + if (argc > 1) { + if ( (string(argv[1]) != "--ut") || (argc != 2) ) { + cout << "\n[Usage] " << argv[0] << ": " << " [--ut]\n\n"; + exit(-1); + } + return gtest_main(argc, argv); + } + cout << "\n-= Starting RPC Server Mock =-\n\n"; cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; -- cgit 1.2.3-korg