Add unit tests for CheckResponse in ProtocolClient 24/238624/6
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 15 Jul 2020 16:34:25 +0000 (18:34 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 12 Aug 2020 08:59:32 +0000 (10:59 +0200)
Change-Id: Ibfb00e00db21ca10ba18c6fdcfa5b76fd64ea4f1

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

index 5bfa9532691065686d9539c8d3b4c8e0e196ccc1..840956a7c6e8a0b851eda1a6c84d565ad43d9407 100644 (file)
@@ -154,6 +154,7 @@ SET(CYNARA_TESTS_SOURCES
     common/protocols/agent/protocolagent.cpp
     common/protocols/client/cancelrequest.cpp
     common/protocols/client/checkrequest.cpp
+    common/protocols/client/checkresponse.cpp
     common/protocols/client/monitorentriesputrequest.cpp
     common/protocols/client/monitorentryputrequest.cpp
     common/protocols/client/protocolclient.cpp
diff --git a/test/common/protocols/client/checkresponse.cpp b/test/common/protocols/client/checkresponse.cpp
new file mode 100644 (file)
index 0000000..d828e33
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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/checkresponse.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::CheckResponse usage in Cynara::ProtocolAdmin
+ */
+
+#include <gtest/gtest.h>
+
+#include <cynara-limits.h>
+#include <protocol/ProtocolClient.h>
+#include <response/CheckResponse.h>
+
+#include <NegativeTestHelper.h>
+#include <ResponseTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::CheckResponse &resp1, const Cynara::CheckResponse &resp2) {
+    EXPECT_EQ(resp1.m_resultRef, resp2.m_resultRef);
+    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(ProtocolClient, CheckResponsePositive) {
+    for (auto &result : Results::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<CheckResponse>(result, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolClient>();
+            testResponse(response, protocol);
+        }
+    }
+}
+
+TEST(ProtocolClient, CheckResponseBinaryPositive) {
+    for (auto &result : Results::all) {
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<CheckResponse>(result, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolClient>();
+            binaryTestResponse(response, protocol);
+        }
+    }
+}
+
+TEST(ProtocolClient, CheckResponseTooLongMetadataNegative) {
+    PolicyResult result(PredefinedPolicyType::BUCKET, std::string(CYNARA_MAX_ID_LENGTH + 1, 'm'));
+    for (auto &sequenceNumber : SN::all) {
+        testInvalidProtocol<ProtocolClient, CheckResponse>(result, sequenceNumber);
+    }
+}
+