From: Marcin Niesluchowski Date: Wed, 10 Dec 2014 13:35:55 +0000 (+0100) Subject: Add api wrappers to security-manager tests X-Git-Tag: security-manager_5.5_testing~109^2~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=484833fd93c26fd10db4582995efde5a1bc8f44d;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add api wrappers to security-manager tests Change-Id: Ic558284e8d029b5450ff4126ef42c8029c38947d --- diff --git a/tests/security-manager-tests/CMakeLists.txt b/tests/security-manager-tests/CMakeLists.txt index dd8f0498..88890e67 100644 --- a/tests/security-manager-tests/CMakeLists.txt +++ b/tests/security-manager-tests/CMakeLists.txt @@ -36,6 +36,7 @@ SET(TARGET_SEC_MGR_TESTS "security-manager-tests") SET(SEC_MGR_SOURCES ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/security_manager_tests.cpp + ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_api.cpp ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_db.cpp ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_request.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client.cpp diff --git a/tests/security-manager-tests/common/sm_api.cpp b/tests/security-manager-tests/common/sm_api.cpp new file mode 100644 index 00000000..7ffe85b0 --- /dev/null +++ b/tests/security-manager-tests/common/sm_api.cpp @@ -0,0 +1,104 @@ +/* + * 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. + */ + +#include + +#include + +namespace SecurityManagerTest { + +namespace Api { + +void install(const InstallRequest &request, lib_retcode expectedResult) +{ + int result = security_manager_app_install(request.get()); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "installing app returned wrong value." + << " InstallRequest: [ " << request << "];" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +void uninstall(const InstallRequest &request, lib_retcode expectedResult) +{ + int result = security_manager_app_uninstall(request.get()); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "uninstalling app returned wrong value." + << " InstallRequest: [ " << request << "];" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +std::string getPkgId(const char *appId, lib_retcode expectedResult) +{ + char *pkgId = nullptr; + int result = security_manager_get_app_pkgid(&pkgId, appId); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "getting pkg id from app id returned wrong value." + << " App id: " << appId << ";" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); + if (expectedResult != SECURITY_MANAGER_SUCCESS) + return std::string(); + + RUNNER_ASSERT_MSG(pkgId != nullptr, "getting pkg id did not allocate memory"); + std::string str(pkgId); + free(pkgId); + return str; +} + +void setProcessLabel(const char *appId, lib_retcode expectedResult) +{ + int result = security_manager_set_process_label_from_appid(appId); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "setting process label from app id returned wrong value." + << " App id: " << appId << ";" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +void setProcessGroups(const char *appId, lib_retcode expectedResult) +{ + int result = security_manager_set_process_groups_from_appid(appId); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "setting process groups from app id returned wrong value." + << " App id: " << appId << ";" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +void dropProcessPrivileges(lib_retcode expectedResult) +{ + int result = security_manager_drop_process_privileges(); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "dropping process privileges returned wrong value." + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +void prepareApp(const char *appId, lib_retcode expectedResult) +{ + int result = security_manager_prepare_app(appId); + RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult, + "preparing app returned wrong value." + << " App id: " << appId << ";" + << " Result: " << result << ";" + << " Expected result: " << expectedResult); +} + +} // namespace Api + +} // namespace SecurityManagerTest diff --git a/tests/security-manager-tests/common/sm_api.h b/tests/security-manager-tests/common/sm_api.h new file mode 100644 index 00000000..49e40883 --- /dev/null +++ b/tests/security-manager-tests/common/sm_api.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef SECURITY_MANAGER_TEST_API +#define SECURITY_MANAGER_TEST_API + +#include + +#include + +namespace SecurityManagerTest { + +namespace Api { + +void install(const InstallRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +void uninstall(const InstallRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +std::string getPkgId(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +void setProcessLabel(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +void setProcessGroups(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +void dropProcessPrivileges(lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); +void prepareApp(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS); + +} // namespace Api + +} // namespace SecurityManagerTest + +#endif // SECURITY_MANAGER_TEST_API