Add unit tests for AgentRegisterRequest in ProtocolAgent 55/235455/10
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 4 Jun 2020 13:46:05 +0000 (15:46 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 4 Aug 2020 14:08:26 +0000 (16:08 +0200)
Change-Id: I66741df415ced3f8cae240b49aaf276c9097d952

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

index 7cfc9331f9f77f1fca169b18217c41bb0084d25d..6e8a1724054cfa6bfa5fc8cb88e5ad2005d54045 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/agentregisterrequest.cpp
     common/protocols/agent/protocolagent.cpp
     common/protocols/monitor/flushrequest.cpp
     common/protocols/monitor/getentriesrequest.cpp
index 227361ef29c2be7c5a00c6280a89d337f8f784ea..a8e486d1df6a6411ce550eafab7c7388d18ee5b5 100644 (file)
@@ -150,7 +150,11 @@ typedef NumericDataCollection<Cynara::AgentResponseType> ResponseType;
 
 namespace Type {
 
+const Cynara::AgentType empty = "";
 const Cynara::AgentType not_empty = "agent_type";
+const Cynara::AgentType all[] = {
+    empty, not_empty
+};
 
 } /* namespace Type */
 
diff --git a/test/common/protocols/agent/agentregisterrequest.cpp b/test/common/protocols/agent/agentregisterrequest.cpp
new file mode 100644 (file)
index 0000000..e955f86
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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/agentregisterrequest.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::AgentRegisterRequest usage in Cynara::ProtocolAgent
+ */
+
+#include <gtest/gtest.h>
+
+#include <cynara-limits.h>
+#include <exceptions/InvalidProtocolException.h>
+#include <protocol/ProtocolAgent.h>
+#include <request/AgentRegisterRequest.h>
+
+#include <NegativeTestHelper.h>
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::AgentRegisterRequest &req1,
+             const Cynara::AgentRegisterRequest &req2)
+{
+    EXPECT_EQ(req1.agentType(), req2.agentType());
+    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, AgentRegisterRequestPositive)
+{
+    for (auto &agentType : Agent::Type::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto request = std::make_shared<AgentRegisterRequest>(agentType, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolAgent>();
+            testRequest(request, protocol);
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentRegisterRequestBinaryPositive)
+{
+    for (auto &agentType : Agent::Type::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto request = std::make_shared<AgentRegisterRequest>(agentType, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolAgent>();
+            binaryTestRequest(request, protocol);
+        }
+    }
+}
+
+TEST(ProtocolAgent, AgentRegisterRequestTypeTooLongNegative)
+{
+    AgentType agentType(CYNARA_MAX_ID_LENGTH + 1, 'd');
+    for (auto &sequenceNumber : SN::all) {
+        testInvalidProtocol<ProtocolAgent, AgentRegisterRequest>(agentType, sequenceNumber);
+    }
+}