Add serialization tests for DescriptionList 44/32844/2
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Sun, 28 Dec 2014 00:38:33 +0000 (01:38 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 29 Dec 2014 08:16:40 +0000 (09:16 +0100)
Add tests checking serialization/deserialization of DescriptionListRequest
and DescriptionListResponse implementation in ProtocolAdmin.

Change-Id: Ic3579436f361cbf9a9d60393de733c800c52181d

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

index f0c3736..6f8ef37 100644 (file)
@@ -63,6 +63,8 @@ SET(CYNARA_TESTS_SOURCES
     common/exceptions/bucketrecordcorrupted.cpp
     common/protocols/admin/admincheckrequest.cpp
     common/protocols/admin/admincheckresponse.cpp
+    common/protocols/admin/descriptionlistrequest.cpp
+    common/protocols/admin/descriptionlistresponse.cpp
     common/protocols/admin/eraserequest.cpp
     common/protocols/admin/listrequest.cpp
     common/protocols/admin/listresponse.cpp
diff --git a/test/common/protocols/admin/descriptionlistrequest.cpp b/test/common/protocols/admin/descriptionlistrequest.cpp
new file mode 100644 (file)
index 0000000..e34008f
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 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/descriptionlistrequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::DescriptionListRequest usage in Cynara::ProtocolAdmin
+ */
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAdmin.h>
+#include <request/DescriptionListRequest.h>
+
+#include <RequestTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::DescriptionListRequest &req1, const Cynara::DescriptionListRequest &req2)
+{
+    EXPECT_EQ(req1.sequenceNumber(), req2.sequenceNumber());
+}
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace RequestTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAdmin, DescriptionListRequest01) {
+    auto request = std::make_shared<DescriptionListRequest>(SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testRequest(request, protocol);
+}
+
+/* *** compare by serialized data test cases *** */
+
+TEST(ProtocolAdmin, DescriptionListRequestBinary01) {
+    auto request = std::make_shared<DescriptionListRequest>(SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestRequest(request, protocol);
+}
diff --git a/test/common/protocols/admin/descriptionlistresponse.cpp b/test/common/protocols/admin/descriptionlistresponse.cpp
new file mode 100644 (file)
index 0000000..43acbaa
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2014 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/descriptionlistresponse.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Tests for Cynara::DescriptionListResponse usage in Cynara::ProtocolAdmin
+ */
+
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include <protocol/ProtocolAdmin.h>
+#include <response/DescriptionListResponse.h>
+#include <types/PolicyDescription.h>
+
+#include <ResponseTestHelper.h>
+#include <TestDataCollection.h>
+
+namespace {
+
+template<>
+void compare(const Cynara::DescriptionListResponse &resp1,
+             const Cynara::DescriptionListResponse &resp2) {
+    ASSERT_EQ(resp1.descriptions().size(), resp2.descriptions().size());
+    for (size_t i = 0U; i < resp1.descriptions().size(); ++i) {
+        SCOPED_TRACE(std::to_string(i));
+        EXPECT_EQ(resp1.descriptions()[i].name, resp2.descriptions()[i].name);
+        EXPECT_EQ(resp1.descriptions()[i].type, resp2.descriptions()[i].type);
+    }
+}
+
+} /* namespace anonymous */
+
+using namespace Cynara;
+using namespace ResponseTestHelper;
+using namespace TestDataCollection;
+
+/* *** compare by objects test cases *** */
+
+TEST(ProtocolAdmin, DescriptionListResponse01) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponse02) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::bucket, "bucket"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponse03) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::deny, "deny"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponse04) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::none, "none"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponse05) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::plugin_type, "plugin"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseMultipleDescriptions) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+        PolicyDescription(Types::bucket, "bucket"),
+        PolicyDescription(Types::deny, "deny"),
+        PolicyDescription(Types::none, "none"),
+        PolicyDescription(Types::plugin_type, ""),
+        PolicyDescription(Types::plugin_type, "plugin"),
+        PolicyDescription(Types::plugin_type, "plugin"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseEmptyDescriptions) {
+    std::vector<PolicyDescription> descriptions;
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    testResponse(response, protocol);
+}
+
+/* *** compare by serialized data test cases *** */
+
+TEST(ProtocolAdmin, DescriptionListResponseBinary01) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinary02) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::bucket, "bucket"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinary03) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::deny, "deny"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinary04) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::none, "none"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_1);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinary05) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::plugin_type, "plugin"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::mid);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinaryMultipleDescriptions) {
+    std::vector<PolicyDescription> descriptions = {
+        PolicyDescription(Types::allow, "allow"),
+        PolicyDescription(Types::bucket, "bucket"),
+        PolicyDescription(Types::deny, "deny"),
+        PolicyDescription(Types::none, "none"),
+        PolicyDescription(Types::plugin_type, ""),
+        PolicyDescription(Types::plugin_type, "plugin"),
+        PolicyDescription(Types::plugin_type, "plugin"),
+    };
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::max_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}
+
+TEST(ProtocolAdmin, DescriptionListResponseBinaryEmptyDescriptions) {
+    std::vector<PolicyDescription> descriptions;
+
+    auto response = std::make_shared<DescriptionListResponse>(descriptions, SN::min_2);
+    auto protocol = std::make_shared<ProtocolAdmin>();
+    binaryTestResponse(response, protocol);
+}