Add unit tests for CodeResponse with ProtocolAdmin 11/234911/6
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 29 May 2020 14:23:28 +0000 (16:23 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Fri, 10 Jul 2020 12:44:46 +0000 (14:44 +0200)
Change-Id: I3aad98d36969b27908cca5a1833531808b0cb6bc

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

index 3fe948fa9ec35a32dc645106687622d6da56f51c..9bb7f937969efb376c9deb2fc7640c90d7201a67 100644 (file)
@@ -118,6 +118,7 @@ SET(CYNARA_TESTS_SOURCES
     common/exceptions/trycatch.cpp
     common/protocols/admin/admincheckrequest.cpp
     common/protocols/admin/admincheckresponse.cpp
+    common/protocols/admin/coderesponse.cpp
     common/protocols/admin/descriptionlistrequest.cpp
     common/protocols/admin/descriptionlistresponse.cpp
     common/protocols/admin/eraserequest.cpp
diff --git a/test/common/protocols/admin/coderesponse.cpp b/test/common/protocols/admin/coderesponse.cpp
new file mode 100644 (file)
index 0000000..3d8eb23
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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/admin/coderesponse.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::CodeResponse usage in Cynara::ProtocolAdmin
+ */
+
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAdmin.h>
+#include <response/CodeResponse.h>
+#include <types/Policy.h>
+
+#include <ResponseTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::CodeResponse &resp1, const Cynara::CodeResponse &resp2) {
+    EXPECT_EQ(resp1.m_code, resp2.m_code);
+    EXPECT_EQ(resp1.sequenceNumber(), resp2.sequenceNumber());
+}
+
+const std::vector<Cynara::CodeResponse::Code> ALL_CODES = {
+    Cynara::CodeResponse::DB_CORRUPTED, Cynara::CodeResponse::FAILED,
+    Cynara::CodeResponse::NOT_ALLOWED, Cynara::CodeResponse::NO_BUCKET,
+    Cynara::CodeResponse::NO_POLICY_TYPE, Cynara::CodeResponse::OK
+};
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace ResponseTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAdmin, CodeResponsePositive) {
+    for (auto &code : ALL_CODES) {
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<CodeResponse>(code, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolAdmin>();
+            testResponse(response, protocol);
+        }
+    }
+}
+
+TEST(ProtocolAdmin, CodeResponseBinaryPositive) {
+    for (auto &code : ALL_CODES) {
+        for (auto &sequenceNumber : SN::all) {
+            auto response = std::make_shared<CodeResponse>(code, sequenceNumber);
+            auto protocol = std::make_shared<ProtocolAdmin>();
+            binaryTestResponse(response, protocol);
+        }
+    }
+}