2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <sm_request.h>
19 #include <dpl/test/test_runner.h>
21 namespace SecurityManagerTest {
23 InstallRequest::InstallRequest()
29 int result = security_manager_app_inst_req_new(&m_req);
30 RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
31 "creation of new request failed. Result: " << result);
32 RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
35 InstallRequest::~InstallRequest()
37 security_manager_app_inst_req_free(m_req);
40 void InstallRequest::setAppId(const char *appId, lib_retcode expectedResult)
42 int result = security_manager_app_inst_req_set_app_id(m_req, appId);
43 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
44 "setting app id returned wrong value."
45 << " App id: " << appId << ";"
46 << " Result: " << result << ";"
47 << " Expected result: " << expectedResult);
51 void InstallRequest::setPkgId(const char *pkgId, lib_retcode expectedResult)
53 int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId);
54 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
55 "setting pkg id returned wrong value."
56 << " Pkg id: " << pkgId << ";"
57 << " Result: " << result << ";"
58 << " Expected result: " << expectedResult);
62 void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
64 int result = security_manager_app_inst_req_add_privilege(m_req, privilege);
65 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
66 "adding privilege returned wrong value."
67 << " Privilege: " << privilege << ";"
68 << " Result: " << result << ";"
69 << " Expected result: " << expectedResult);
70 m_privileges.push_back(privilege);
73 void InstallRequest::addPath(const char *path, app_install_path_type pathType, lib_retcode expectedResult)
75 int result = security_manager_app_inst_req_add_path(m_req, path, pathType);
76 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
77 "adding path returned wrong value."
78 << " Path: " << path << ";"
79 << " Path type: " << pathType << ";"
80 << " Result: " << result << ";"
81 << " Expected result: " << expectedResult);
82 m_paths.push_back(std::pair<std::string, app_install_path_type>(path, pathType));
85 void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
87 int result = security_manager_app_inst_req_set_uid(m_req, uid);
88 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
89 "setting uid returned wrong value."
90 << " Uid: " << uid << ";"
91 << " Result: " << result << ";"
92 << " Expected result: " << expectedResult);
97 std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
99 if (request.m_appId != nullptr)
100 os << "app id: " << request.m_appId << "; ";
101 if (request.m_pkgId != nullptr)
102 os << "pkg id: " << request.m_pkgId << "; ";
103 if (!request.m_privileges.empty()) {
104 os << "privileges: [ " << request.m_privileges[0];
105 for (size_t i=1; i < request.m_privileges.size(); ++i) {
106 os << "; " << request.m_privileges[i];
110 if (!request.m_paths.empty()) {
111 os << "paths: [ " << "< " << request.m_paths[0].first << "; "
112 << request.m_paths[0].second << " >";
113 for (size_t i=1; i < request.m_paths.size(); ++i) {
114 os << "; < " << request.m_paths[i].first << "; "
115 << request.m_paths[i].second << " >";
119 if (request.m_uid.first)
120 os << "uid: " << request.m_uid.second << "; ";
124 } // namespace SecurityManagerTest