Add unit tests for SimpleCheckRequest in ProtocolClient 72/235672/10
authorZofia Abramowska <z.abramowska@samsung.com>
Mon, 8 Jun 2020 16:55:24 +0000 (18:55 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 4 Aug 2020 15:14:35 +0000 (17:14 +0200)
Change-Id: Ia797842b01e843f3273d3c436f6d3b38b857cf92

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

index 002c49f5aeac0e726154a8b97be31bded78d8c91..b122e6f1455bb6d67cc0dffc8241863fff68eb2b 100644 (file)
@@ -155,6 +155,7 @@ SET(CYNARA_TESTS_SOURCES
     common/protocols/client/cancelrequest.cpp
     common/protocols/client/checkrequest.cpp
     common/protocols/client/protocolclient.cpp
+    common/protocols/client/simplecheckrequest.cpp
     common/protocols/monitor/flushrequest.cpp
     common/protocols/monitor/getentriesrequest.cpp
     common/protocols/monitor/getentriesresponse.cpp
diff --git a/test/common/protocols/client/simplecheckrequest.cpp b/test/common/protocols/client/simplecheckrequest.cpp
new file mode 100644 (file)
index 0000000..42e3b12
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * 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/client/simplecheckrequest.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::SimpleCheckRequest usage in Cynara::ProtocolClient
+ */
+
+#include <gtest/gtest.h>
+
+#include <cynara-limits.h>
+#include <exceptions/InvalidProtocolException.h>
+#include <protocol/ProtocolClient.h>
+#include <request/SimpleCheckRequest.h>
+
+#include <NegativeTestHelper.h>
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::SimpleCheckRequest &req1, const Cynara::SimpleCheckRequest &req2) {
+    EXPECT_EQ(req1.key(), req2.key());
+    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(ProtocolClient, SimpleCheckRequestPositive) {
+    for (auto &key : Keys::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto request = std::make_shared<SimpleCheckRequest>(key, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolClient>();
+            testRequest(request, protocol);
+        }
+    }
+}
+
+TEST(ProtocolClient, SimpleCheckRequestBinaryPositive) {
+    for (auto &key : Keys::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto request = std::make_shared<SimpleCheckRequest>(key, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolClient>();
+            binaryTestRequest(request, protocol);
+        }
+    }
+}
+
+TEST(ProtocolClient, SimpleCheckRequestTooLongClientNegative) {
+    PKF tooLongClient = PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'c'));
+    PolicyKey key(tooLongClient, Keys::k_cup.user(), Keys::k_cup2.privilege());
+    for (auto &sequenceNumber : SN::all) {
+        testInvalidProtocol<ProtocolClient, SimpleCheckRequest>(key, sequenceNumber);
+    }
+}
+
+TEST(ProtocolClient, SimpleCheckRequestTooLongUserNegative) {
+    PKF tooLongUser = PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'u'));
+    PolicyKey key(Keys::k_cup.client(), tooLongUser, Keys::k_cup2.privilege());
+    for (auto &sequenceNumber : SN::all) {
+        testInvalidProtocol<ProtocolClient, SimpleCheckRequest>(key, sequenceNumber);
+    }
+}
+
+TEST(ProtocolClient, SimpleCheckRequestTooLongPrivilegeNegative) {
+    PKF tooLongPrivilege = PKF::create(std::string(CYNARA_MAX_ID_LENGTH + 1, 'p'));
+    PolicyKey key(Keys::k_cup2.client(), Keys::k_cup.user(), tooLongPrivilege);
+    for (auto &sequenceNumber : SN::all) {
+        testInvalidProtocol<ProtocolClient, SimpleCheckRequest>(key, sequenceNumber);
+    }
+}