Add unit tests for AgentActionResponse in ProtocolAgent 69/235569/9
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 5 Jun 2020 11:01:47 +0000 (13:01 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 4 Aug 2020 14:34:16 +0000 (16:34 +0200)
Change-Id: I88d7ffa5851727d0b0f7905258a40697399bfdfd

test/CMakeLists.txt
test/common/protocols/agent/agentactionresponse.cpp [new file with mode: 0644]

index 6e8a1724054cfa6bfa5fc8cb88e5ad2005d54045..6891029efaa97c1287e43eb816674de0e4dea6d5 100644 (file)
@@ -147,6 +147,7 @@ SET(CYNARA_TESTS_SOURCES
     common/protocols/admin/setpoliciesrequest.cpp
     common/protocols/admin/protocoladmin.cpp
     common/protocols/agent/agentactionrequest.cpp
+    common/protocols/agent/agentactionresponse.cpp
     common/protocols/agent/agentregisterrequest.cpp
     common/protocols/agent/protocolagent.cpp
     common/protocols/monitor/flushrequest.cpp
diff --git a/test/common/protocols/agent/agentactionresponse.cpp b/test/common/protocols/agent/agentactionresponse.cpp
new file mode 100644 (file)
index 0000000..f02a42d
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This file is licensed under the terms of MIT License or the Apache License
+ * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
+ * See the LICENSE file or the notice below for Apache License Version 2.0
+ * details.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file        test/common/protocols/agent/agentactionresponse.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::AgentActionResponse usage in Cynara::ProtocolAgent
+ */
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAgent.h>
+#include <response/AgentActionResponse.h>
+
+#include <CommonsTestHelper.h>
+#include <NegativeTestHelper.h>
+#include <ResponseTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::AgentActionResponse &resp1,
+             const Cynara::AgentActionResponse &resp2)
+{
+    EXPECT_EQ(resp1.type(), resp2.type());
+    EXPECT_EQ(resp1.data(), resp2.data());
+    EXPECT_EQ(resp1.sequenceNumber(), resp2.sequenceNumber());
+}
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace NegativeTestHelper;
+using namespace ResponseTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAgent, AgentActionResponseFullPositive) {
+    for (auto &size : Buffer::Size::all) {
+        const RawBuffer data = genBuffer(size);
+        for (auto &requestType : Agent::RequestType::all) {
+            for (auto &sequenceNumber : SN::all) {
+                auto response = std::make_shared<AgentActionResponse>(requestType, data,
+                                                                      sequenceNumber);
+                auto protocol = std::make_shared<ProtocolAgent>();
+                testResponse(response, protocol);
+            }
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentActionResponseFullBinaryPositive) {
+    for (auto &size : Buffer::Size::all) {
+        const RawBuffer data = genBuffer(size);
+        for (auto &requestType : Agent::RequestType::all) {
+            for (auto &sequenceNumber : SN::all) {
+                auto response = std::make_shared<AgentActionResponse>(requestType, data,
+                                                                      sequenceNumber);
+                auto protocol = std::make_shared<ProtocolAgent>();
+                binaryTestResponse(response, protocol);
+            }
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentActionResponseTooBigVectorNegative) {
+    const RawBuffer data(Buffer::Size::max + 1, 'd');
+    for (auto &requestType : Agent::RequestType::all) {
+        for (auto &sequenceNumber : SN::all) {
+            testInvalidProtocol<ProtocolAgent, AgentActionResponse>
+                (requestType, data, sequenceNumber);
+        }
+    }
+}