Add tests for AliasSupport class 90/258690/4
authorMichał Szaknis <m.szaknis@samsung.com>
Thu, 20 May 2021 15:16:14 +0000 (17:16 +0200)
committerMichał Szaknis <m.szaknis@samsung.com>
Tue, 25 May 2021 10:42:13 +0000 (12:42 +0200)
Change-Id: I509160e10ca4ac00418d3ee408c32915c6aa5511

unit-tests/CMakeLists.txt
unit-tests/test_client-common.cpp [new file with mode: 0644]

index 23813f6..643ae55 100644 (file)
@@ -68,6 +68,7 @@ SET(UNIT_TESTS_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/test_base64.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/test_binary-queue.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/test_certificate.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/test_client-common.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/test_comm-manager.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/test_crypto-logic.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/test_data-type.cpp
diff --git a/unit-tests/test_client-common.cpp b/unit-tests/test_client-common.cpp
new file mode 100644 (file)
index 0000000..9c306bf
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (c) 2021 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
+ */
+
+#include <boost_macros_wrapper.h>
+#include <string>
+#include "client-common.h"
+
+namespace {
+const std::string OWNER_ID = "some_id";
+const std::string NAME = "some_name";
+
+const std::string EMPTY_OWNER_ID = "";
+}
+
+BOOST_AUTO_TEST_SUITE(CLIENT_COMMON)
+
+POSITIVE_TEST_CASE(AliasTest) {
+    const auto alias = CKM::AliasSupport::merge(OWNER_ID, NAME);
+    const auto alias_support = CKM::AliasSupport(alias);
+
+    BOOST_REQUIRE(!alias_support.isOwnerEmpty());
+    BOOST_REQUIRE(alias_support.getName() == NAME);
+    BOOST_REQUIRE(alias_support.getOwner() == OWNER_ID);
+
+    const auto empty_owner_alias = CKM::AliasSupport::merge(EMPTY_OWNER_ID, NAME);
+    const auto empty_owner_alias_support = CKM::AliasSupport(empty_owner_alias);
+
+    BOOST_REQUIRE(empty_owner_alias_support.isOwnerEmpty());
+    BOOST_REQUIRE(empty_owner_alias_support.getName() == NAME);
+    BOOST_REQUIRE(empty_owner_alias_support.getOwner() == EMPTY_OWNER_ID);
+}
+
+NEGATIVE_TEST_CASE(AliasTest) {
+    const auto empty_alias = CKM::AliasSupport::merge("", "");
+    const auto empty_alias_support = CKM::AliasSupport(empty_alias);
+    BOOST_REQUIRE(empty_alias_support.isOwnerEmpty());
+    BOOST_REQUIRE(empty_alias_support.getName() == "");
+    BOOST_REQUIRE(empty_alias_support.getOwner() == "");
+}
+
+BOOST_AUTO_TEST_SUITE_END()