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 std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
120 if (!request.m_appId.empty())
121 os << "app id: " << request.m_appId << "; ";
122 if (!request.m_pkgId.empty())
123 os << "pkg id: " << request.m_pkgId << "; ";
124 if (!request.m_privileges.empty()) {
125 os << "privileges: [ " << request.m_privileges[0];
126 for (size_t i=1; i < request.m_privileges.size(); ++i) {
127 os << "; " << request.m_privileges[i];
131 if (!request.m_paths.empty()) {
132 os << "paths: [ " << "< " << request.m_paths[0].first << "; "
133 << request.m_paths[0].second << " >";
134 for (size_t i=1; i < request.m_paths.size(); ++i) {
135 os << "; < " << request.m_paths[i].first << "; "
136 << request.m_paths[i].second << " >";
140 if (request.m_uid.first)
141 os << "uid: " << request.m_uid.second << "; ";
142 if (!request.m_authorId.empty()) {
143 os << "author id: " << request.m_authorId << "; ";
148 } // namespace SecurityManagerTest