2 * Copyright (c) 2014-2016 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()
28 int result = security_manager_app_inst_req_new(&m_req);
29 RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
30 "creation of new request failed. Result: " << result);
31 RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
34 InstallRequest::~InstallRequest()
36 security_manager_app_inst_req_free(m_req);
39 void InstallRequest::setAppTizenVersion(std::string tizenVer, lib_retcode expectedResult)
41 int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer.c_str());
42 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
43 "setting app id returned wrong value."
44 << " Tizen version: " << tizenVer << ";"
45 << " Result: " << result << ";"
46 << " Expected result: " << expectedResult);
47 m_tizenVer = std::move(tizenVer);
50 void InstallRequest::setAppId(std::string appId, lib_retcode expectedResult)
52 int result = security_manager_app_inst_req_set_app_id(m_req, appId.c_str());
53 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
54 "setting app id returned wrong value."
55 << " App id: " << appId << ";"
56 << " Result: " << result << ";"
57 << " Expected result: " << expectedResult);
58 m_appId = std::move(appId);
61 void InstallRequest::setPkgId(std::string pkgId, lib_retcode expectedResult)
63 int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId.c_str());
64 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
65 "setting pkg id returned wrong value."
66 << " Pkg id: " << pkgId << ";"
67 << " Result: " << result << ";"
68 << " Expected result: " << expectedResult);
69 m_pkgId = std::move(pkgId);
72 void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
74 int result = security_manager_app_inst_req_add_privilege(m_req, privilege);
75 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
76 "adding privilege returned wrong value."
77 << " Privilege: " << privilege << ";"
78 << " Result: " << result << ";"
79 << " Expected result: " << expectedResult);
80 m_privileges.push_back(strdup(privilege));
83 void InstallRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
85 int result = security_manager_app_inst_req_add_path(m_req, path.c_str(), pathType);
86 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
87 "adding path returned wrong value."
88 << " Path: " << path << ";"
89 << " Path type: " << pathType << ";"
90 << " Result: " << result << ";"
91 << " Expected result: " << expectedResult);
92 m_paths.emplace_back(std::pair<std::string, app_install_path_type>(std::move(path), pathType));
95 void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
97 int result = security_manager_app_inst_req_set_uid(m_req, uid);
98 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
99 "setting uid returned wrong value."
100 << " Uid: " << uid << ";"
101 << " Result: " << result << ";"
102 << " Expected result: " << expectedResult);
107 void InstallRequest::setAuthorId(std::string authorId, lib_retcode expectedResult)
109 int result = security_manager_app_inst_req_set_author_id(m_req, authorId.c_str());
110 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
111 "setting author id returned wrong value."
112 << " Author id: " << m_authorId << ";"
113 << " Result: " << result << ";"
114 << " Expected result: " << expectedResult);
115 m_authorId = std::move(authorId);
118 void InstallRequest::setInstallType(const enum app_install_type &type, lib_retcode expectedResult)
120 int result = security_manager_app_inst_req_set_install_type(m_req, type);
121 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
122 "setting install type returned wrong value."
123 << " Install type: " << type << ";"
124 << " Result: " << result << ";"
125 << " Expected result: " << expectedResult);
128 std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
130 if (!request.m_appId.empty())
131 os << "app id: " << request.m_appId << "; ";
132 if (!request.m_pkgId.empty())
133 os << "pkg id: " << request.m_pkgId << "; ";
134 if (!request.m_privileges.empty()) {
135 os << "privileges: [ " << request.m_privileges[0];
136 for (size_t i=1; i < request.m_privileges.size(); ++i) {
137 os << "; " << request.m_privileges[i];
141 if (!request.m_paths.empty()) {
142 os << "paths: [ " << "< " << request.m_paths[0].first << "; "
143 << request.m_paths[0].second << " >";
144 for (size_t i=1; i < request.m_paths.size(); ++i) {
145 os << "; < " << request.m_paths[i].first << "; "
146 << request.m_paths[i].second << " >";
150 if (request.m_uid.first)
151 os << "uid: " << request.m_uid.second << "; ";
152 if (!request.m_authorId.empty()) {
153 os << "author id: " << request.m_authorId << "; ";
158 PathsRequest::PathsRequest()
162 int result = security_manager_path_req_new(&m_req);
163 RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
164 "creation of new request failed. Result: " << result);
165 RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
168 PathsRequest::~PathsRequest()
170 security_manager_path_req_free(m_req);
173 void PathsRequest::setPkgId(std::string pkgId, lib_retcode expectedResult)
175 int result = security_manager_path_req_set_pkg_id(m_req, pkgId.c_str());
176 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
177 "setting pkg id returned wrong value."
178 << " Pkg id: " << pkgId << ";"
179 << " Result: " << result << ";"
180 << " Expected result: " << expectedResult);
181 m_pkgId = std::move(pkgId);
184 void PathsRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
186 int result = security_manager_path_req_add_path(m_req, path.c_str(), pathType);
187 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
188 "adding path returned wrong value."
189 << " Path: " << path << ";"
190 << " Path type: " << pathType << ";"
191 << " Result: " << result << ";"
192 << " Expected result: " << expectedResult);
193 m_paths.emplace_back(std::pair<std::string, app_install_path_type>(std::move(path), pathType));
196 void PathsRequest::setUid(const uid_t uid, lib_retcode expectedResult)
198 int result = security_manager_path_req_set_uid(m_req, uid);
199 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
200 "setting uid returned wrong value."
201 << " Uid: " << uid << ";"
202 << " Result: " << result << ";"
203 << " Expected result: " << expectedResult);
208 void PathsRequest::setInstallType(const enum app_install_type &type, lib_retcode expectedResult)
210 int result = security_manager_path_req_set_install_type(m_req, type);
211 RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
212 "setting install type returned wrong value."
213 << " Install type: " << type << ";"
214 << " Result: " << result << ";"
215 << " Expected result: " << expectedResult);
218 std::ostream& operator<<(std::ostream &os, const PathsRequest &request)
220 if (!request.m_pkgId.empty())
221 os << "pkg id: " << request.m_pkgId << "; ";
222 if (!request.m_paths.empty()) {
223 os << "paths: [ " << "< " << request.m_paths[0].first << "; "
224 << request.m_paths[0].second << " >";
225 for (size_t i=1; i < request.m_paths.size(); ++i) {
226 os << "; < " << request.m_paths[i].first << "; "
227 << request.m_paths[i].second << " >";
231 if (request.m_uid.first)
232 os << "uid: " << request.m_uid.second << "; ";
236 } // namespace SecurityManagerTest