From: Lukasz Wojciechowski Date: Sun, 28 Dec 2014 00:38:33 +0000 (+0100) Subject: Add serialization tests for DescriptionList X-Git-Tag: accepted/tizen/common/20150119.084431~39 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4f69ad41c30dee9e313e65a2dcb1f263deef5fe;p=platform%2Fcore%2Fsecurity%2Fcynara.git Add serialization tests for DescriptionList Add tests checking serialization/deserialization of DescriptionListRequest and DescriptionListResponse implementation in ProtocolAdmin. Change-Id: Ic3579436f361cbf9a9d60393de733c800c52181d --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f0c3736..6f8ef37 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 index 0000000..e34008f --- /dev/null +++ b/test/common/protocols/admin/descriptionlistrequest.cpp @@ -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 + * @version 1.0 + * @brief Tests for Cynara::DescriptionListRequest usage in Cynara::ProtocolAdmin + */ + +#include + +#include +#include + +#include +#include + +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(SN::min); + auto protocol = std::make_shared(); + testRequest(request, protocol); +} + +/* *** compare by serialized data test cases *** */ + +TEST(ProtocolAdmin, DescriptionListRequestBinary01) { + auto request = std::make_shared(SN::min); + auto protocol = std::make_shared(); + binaryTestRequest(request, protocol); +} diff --git a/test/common/protocols/admin/descriptionlistresponse.cpp b/test/common/protocols/admin/descriptionlistresponse.cpp new file mode 100644 index 0000000..43acbaa --- /dev/null +++ b/test/common/protocols/admin/descriptionlistresponse.cpp @@ -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 + * @version 1.0 + * @brief Tests for Cynara::DescriptionListResponse usage in Cynara::ProtocolAdmin + */ + +#include + +#include + +#include +#include +#include + +#include +#include + +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 descriptions = { + PolicyDescription(Types::allow, "allow"), + }; + + auto response = std::make_shared(descriptions, SN::min); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponse02) { + std::vector descriptions = { + PolicyDescription(Types::bucket, "bucket"), + }; + + auto response = std::make_shared(descriptions, SN::min_1); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponse03) { + std::vector descriptions = { + PolicyDescription(Types::deny, "deny"), + }; + + auto response = std::make_shared(descriptions, SN::max); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponse04) { + std::vector descriptions = { + PolicyDescription(Types::none, "none"), + }; + + auto response = std::make_shared(descriptions, SN::max_1); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponse05) { + std::vector descriptions = { + PolicyDescription(Types::plugin_type, "plugin"), + }; + + auto response = std::make_shared(descriptions, SN::mid); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseMultipleDescriptions) { + std::vector 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(descriptions, SN::max_2); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseEmptyDescriptions) { + std::vector descriptions; + + auto response = std::make_shared(descriptions, SN::min_2); + auto protocol = std::make_shared(); + testResponse(response, protocol); +} + +/* *** compare by serialized data test cases *** */ + +TEST(ProtocolAdmin, DescriptionListResponseBinary01) { + std::vector descriptions = { + PolicyDescription(Types::allow, "allow"), + }; + + auto response = std::make_shared(descriptions, SN::min); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinary02) { + std::vector descriptions = { + PolicyDescription(Types::bucket, "bucket"), + }; + + auto response = std::make_shared(descriptions, SN::min_1); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinary03) { + std::vector descriptions = { + PolicyDescription(Types::deny, "deny"), + }; + + auto response = std::make_shared(descriptions, SN::max); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinary04) { + std::vector descriptions = { + PolicyDescription(Types::none, "none"), + }; + + auto response = std::make_shared(descriptions, SN::max_1); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinary05) { + std::vector descriptions = { + PolicyDescription(Types::plugin_type, "plugin"), + }; + + auto response = std::make_shared(descriptions, SN::mid); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinaryMultipleDescriptions) { + std::vector 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(descriptions, SN::max_2); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +} + +TEST(ProtocolAdmin, DescriptionListResponseBinaryEmptyDescriptions) { + std::vector descriptions; + + auto response = std::make_shared(descriptions, SN::min_2); + auto protocol = std::make_shared(); + binaryTestResponse(response, protocol); +}