Add unit tests for AgentActionRequest in ProtocolAgent 54/235454/10
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 4 Jun 2020 12:18:41 +0000 (14:18 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 4 Aug 2020 13:47:44 +0000 (15:47 +0200)
Change-Id: If94172c87fa6fc6cac6f93ce17edf38e31e2c69f

test/CMakeLists.txt
test/common/protocols/CommonsTestHelper.h
test/common/protocols/NegativeTestHelper.h
test/common/protocols/TestDataCollection.h
test/common/protocols/agent/agentactionrequest.cpp [new file with mode: 0644]

index 0a97788236196283319f6aa1ccf48833a3e4573c..7cfc9331f9f77f1fca169b18217c41bb0084d25d 100644 (file)
@@ -146,6 +146,7 @@ SET(CYNARA_TESTS_SOURCES
     common/protocols/admin/removebucketrequest.cpp
     common/protocols/admin/setpoliciesrequest.cpp
     common/protocols/admin/protocoladmin.cpp
+    common/protocols/agent/agentactionrequest.cpp
     common/protocols/agent/protocolagent.cpp
     common/protocols/monitor/flushrequest.cpp
     common/protocols/monitor/getentriesrequest.cpp
index fcb6205b210d0d4cb0d5e516630c095b5dfa2a8f..6e52106159cf1b92b7c8421aabebd26f8c1a30c6 100644 (file)
 
 #include <gtest/gtest.h>
 
+#include <containers/RawBuffer.h>
+
+#include <TestDataCollection.h>
+
 namespace {
 
 template <typename R>
 void compare(const R &r1, const R &r2);
 
+inline Cynara::RawBuffer genBuffer(Cynara::RawBuffer::size_type size) {
+    Cynara::RawBuffer buffer;
+    auto &data = TestDataCollection::Buffer::Data::all;
+    auto dataSize = std::size(data);
+    for (unsigned int i = 0; i < size; i++) {
+        buffer.push_back(data[i % dataSize]);
+    }
+    return buffer;
+}
+
 } /* namespace anonymous */
 
 #endif /* TEST_COMMON_PROTOCOLS_COMMONSTESTHELPER_H_ */
index 6c3ad1cc1b613449abe22962b8a8b0b67cd48592..e99038cf0f21d55c32e9e0c9ca074516ff447e64 100644 (file)
@@ -66,6 +66,12 @@ void testNotImplemented(MessageArg&&...messageArg) {
         (std::forward<MessageArg>(messageArg)...);
 }
 
+template <class Protocol, class Message, class...MessageArg>
+void testInvalidProtocol(MessageArg&&...messageArg) {
+    testProtocolException<Protocol, Cynara::InvalidProtocolException, Message>
+        (std::forward<MessageArg>(messageArg)...);
+}
+
 
 inline Cynara::BinaryQueuePtr prepareWrongOpCode() {
     auto queue = std::make_shared<Cynara::BinaryQueue>();
index 34403ba2ac11fbe8bc878806f920bc252c818e7a..227361ef29c2be7c5a00c6280a89d337f8f784ea 100644 (file)
@@ -159,6 +159,7 @@ const Cynara::AgentType not_empty = "agent_type";
 namespace Buffer {
 
 typedef NumericDataCollection<Cynara::RawBuffer::size_type, 0, CYNARA_MAX_VECTOR_SIZE> Size;
+typedef NumericDataCollection<Cynara::RawBuffer::value_type> Data;
 
 } /* namespace Buffer */
 
diff --git a/test/common/protocols/agent/agentactionrequest.cpp b/test/common/protocols/agent/agentactionrequest.cpp
new file mode 100644 (file)
index 0000000..2eeedb6
--- /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/agentactionrequest.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::AgentActionRequest usage in Cynara::ProtocolAgent
+ */
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAgent.h>
+#include <request/AgentActionRequest.h>
+
+#include <CommonsTestHelper.h>
+#include <NegativeTestHelper.h>
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::AgentActionRequest &req1,
+             const Cynara::AgentActionRequest &req2)
+{
+    EXPECT_EQ(req1.type(), req2.type());
+    EXPECT_EQ(req1.data(), req2.data());
+    EXPECT_EQ(req1.sequenceNumber(), req2.sequenceNumber());
+}
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace NegativeTestHelper;
+using namespace RequestTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAgent, AgentActionRequestFullPositive) {
+    for (auto &size : Buffer::Size::all) {
+        const RawBuffer data = genBuffer(size);
+        for (auto &requestType : Agent::RequestType::all) {
+            for (auto &sequenceNumber : SN::all) {
+                auto request = std::make_shared<AgentActionRequest>(requestType, data,
+                                                                    sequenceNumber);
+                auto protocol = std::make_shared<ProtocolAgent>();
+                testRequest(request, protocol);
+            }
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentActionRequestFullBinaryPositive) {
+    for (auto &size : Buffer::Size::all) {
+        const RawBuffer data = genBuffer(size);
+        for (auto &requestType : Agent::RequestType::all) {
+            for (auto &sequenceNumber : SN::all) {
+                auto request = std::make_shared<AgentActionRequest>(requestType, data,
+                                                                    sequenceNumber);
+                auto protocol = std::make_shared<ProtocolAgent>();
+                binaryTestRequest(request, protocol);
+            }
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentActionRequestTooBigVectorNegative) {
+    const RawBuffer data = genBuffer(Buffer::Size::max + 1);
+    for (auto &requestType : Agent::RequestType::all) {
+        for (auto &sequenceNumber : SN::all) {
+            testInvalidProtocol<ProtocolAgent, AgentActionRequest>
+                (requestType, data, sequenceNumber);
+        }
+    }
+}