summaryrefslogtreecommitdiffstats
path: root/src/gtest/rpc_test.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-17 11:09:44 +0300
committerimarom <imarom@cisco.com>2015-09-17 11:09:44 +0300
commit1e723ff84bb6cdf6dd3a58650af059b6814b5331 (patch)
tree520ba430a286b2c50962b67d4c447edab8803e01 /src/gtest/rpc_test.cpp
parent3b372bbe45931b853f3f906352a0cbdc89952c41 (diff)
added more tests
Diffstat (limited to 'src/gtest/rpc_test.cpp')
-rw-r--r--src/gtest/rpc_test.cpp94
1 files changed, 82 insertions, 12 deletions
diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp
index 58197000..015da2f8 100644
--- a/src/gtest/rpc_test.cpp
+++ b/src/gtest/rpc_test.cpp
@@ -113,9 +113,11 @@ public:
class RpcTestOwned : public RpcTest {
public:
- void create_request(Json::Value &request, const string &method, int id = 1) {
+ void create_request(Json::Value &request, const string &method, int id = 1, bool owned = true) {
RpcTest::create_request(request, method, id);
- request["params"]["handler"] = m_ownership_handler;
+ if (owned) {
+ request["params"]["handler"] = m_ownership_handler;
+ }
}
protected:
@@ -212,7 +214,6 @@ TEST_F(RpcTest, basic_rpc_negative_cases) {
TEST_F(RpcTest, test_add_command) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* missing parameters */
create_request(request, "test_add");
@@ -305,7 +306,6 @@ TEST_F(RpcTest, batch_rpc_test) {
TEST_F(RpcTest, ping) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "ping");
send_request(request, response);
@@ -327,7 +327,6 @@ find_member_in_array(const Json::Value &array, const string &member) {
TEST_F(RpcTest, get_supported_cmds) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_supported_cmds");
send_request(request, response);
@@ -341,7 +340,6 @@ TEST_F(RpcTest, get_supported_cmds) {
TEST_F(RpcTest, get_version) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_version");
send_request(request, response);
@@ -355,7 +353,6 @@ TEST_F(RpcTest, get_version) {
TEST_F(RpcTest, get_system_info) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_system_info");
send_request(request, response);
@@ -383,7 +380,6 @@ TEST_F(RpcTest, get_system_info) {
TEST_F(RpcTest, get_owner_acquire_release) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* no user before acquring */
create_request(request, "get_owner");
@@ -465,7 +461,6 @@ compare_streams(const Json::Value &s1, const Json::Value &s2) {
TEST_F(RpcTestOwned, add_remove_stream) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* verify no such stream */
create_request(request, "get_stream", 1);
@@ -523,14 +518,11 @@ TEST_F(RpcTestOwned, add_remove_stream) {
TEST_F(RpcTestOwned, get_stream_id_list) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
-
/* add stream 1 */
create_request(request, "add_stream");
request["params"]["port_id"] = 1;
-
Json::Value stream;
create_simple_stream(stream);
@@ -579,3 +571,81 @@ TEST_F(RpcTestOwned, get_stream_id_list) {
EXPECT_TRUE(response["result"].isArray());
EXPECT_TRUE(response["result"].size() == 0);
}
+
+
+TEST_F(RpcTestOwned, start_stop_traffic) {
+ Json::Value request;
+ Json::Value response;
+
+ /* add stream #1 */
+ create_request(request, "add_stream");
+ request["params"]["port_id"] = 1;
+ request["params"]["stream_id"] = 5;
+
+ Json::Value stream;
+ create_simple_stream(stream);
+
+ request["params"]["stream"] = stream;
+
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* add stream #1 */
+ create_request(request, "add_stream");
+ request["params"]["port_id"] = 3;
+ request["params"]["stream_id"] = 12;
+ request["params"]["stream"] = stream;
+
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start port 1 */
+ create_request(request, "start_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+
+ /* start port 3 */
+ request["params"]["port_id"] = 3;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start not configured port */
+
+ request["params"]["port_id"] = 2;
+ send_request(request, response);
+ EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* stop port 1 */
+ create_request(request, "stop_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* stop port 3 */
+ request["params"]["port_id"] = 3;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start 1 again */
+ create_request(request, "start_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start 1 twice (error) */
+ send_request(request, response);
+ EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* make sure you cannot release while traffic is active */
+ //create_request(request, "release");
+ //send_request(request, response);
+ //EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* done */
+ create_request(request, "stop_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+}