--- /dev/null
+/*
+ * 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 <sm_request.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace SecurityManagerTest {
+
+InstallRequest::InstallRequest()
+ : m_req(nullptr)
+ , m_appId(nullptr)
+ , m_pkgId(nullptr)
+ , m_uid(false, 0)
+{
+ int result = security_manager_app_inst_req_new(&m_req);
+ RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+ "creation of new request failed. Result: " << result);
+ RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
+}
+
+InstallRequest::~InstallRequest()
+{
+ security_manager_app_inst_req_free(m_req);
+}
+
+void InstallRequest::setAppId(const char *appId, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_set_app_id(m_req, appId);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting app id returned wrong value."
+ << " App id: " << appId << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_appId = appId;
+}
+
+void InstallRequest::setPkgId(const char *pkgId, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting pkg id returned wrong value."
+ << " Pkg id: " << pkgId << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_pkgId = pkgId;
+}
+
+void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_add_privilege(m_req, privilege);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "adding privilege returned wrong value."
+ << " Privilege: " << privilege << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_privileges.push_back(privilege);
+}
+
+void InstallRequest::addPath(const char *path, app_install_path_type pathType, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_add_path(m_req, path, pathType);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "adding path returned wrong value."
+ << " Path: " << path << ";"
+ << " Path type: " << pathType << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_paths.push_back(std::pair<std::string, app_install_path_type>(path, pathType));
+}
+
+void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_set_uid(m_req, uid);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting uid returned wrong value."
+ << " Uid: " << uid << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_uid.first = true;
+ m_uid.second = uid;
+}
+
+std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
+{
+ if (request.m_appId != nullptr)
+ os << "app id: " << request.m_appId << "; ";
+ if (request.m_pkgId != nullptr)
+ os << "pkg id: " << request.m_pkgId << "; ";
+ if (!request.m_privileges.empty()) {
+ os << "privileges: [ " << request.m_privileges[0];
+ for (size_t i=1; i < request.m_privileges.size(); ++i) {
+ os << "; " << request.m_privileges[i];
+ }
+ os << " ]";
+ }
+ if (!request.m_paths.empty()) {
+ os << "paths: [ " << "< " << request.m_paths[0].first << "; "
+ << request.m_paths[0].second << " >";
+ for (size_t i=1; i < request.m_paths.size(); ++i) {
+ os << "; < " << request.m_paths[i].first << "; "
+ << request.m_paths[i].second << " >";
+ }
+ os << " ]";
+ }
+ if (request.m_uid.first)
+ os << "uid: " << request.m_uid.second << "; ";
+ return os;
+}
+
+} // namespace SecurityManagerTest
--- /dev/null
+/*
+ * 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_INSTALLREQUEST
+#define SECURITY_MANAGER_TEST_INSTALLREQUEST
+
+#include <iostream>
+#include <string>
+#include <sys/types.h>
+#include <utility>
+#include <vector>
+
+#include <security-manager.h>
+
+namespace SecurityManagerTest {
+
+class InstallRequest
+{
+public:
+ InstallRequest();
+ InstallRequest(const InstallRequest&) = delete;
+ InstallRequest& operator=(const InstallRequest&) = delete;
+ ~InstallRequest();
+
+ void setAppId(const char *appId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+ void setPkgId(const char *pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+ void addPrivilege(const char *privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+ void addPath(const char *path, app_install_path_type pathType,
+ lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+ void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+
+ const app_inst_req *get() const { return m_req; }
+ friend std::ostream& operator<<(std::ostream &, const InstallRequest&);
+
+private:
+ app_inst_req *m_req;
+
+ const char *m_appId;
+ const char *m_pkgId;
+ std::vector<std::string> m_privileges;
+ std::vector<std::pair<std::string, app_install_path_type> > m_paths;
+ std::pair<bool, uid_t> m_uid;
+};
+
+std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::InstallRequest &request);
+
+} // namespace SecurityManagerTest
+
+#endif // SECURITY_MANAGER_TEST_INSTALLREQUEST