Merge remote-tracking branch 'origin/tizen' into security-manager
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_request.h
1 /*
2  * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef SECURITY_MANAGER_TEST_INSTALLREQUEST
18 #define SECURITY_MANAGER_TEST_INSTALLREQUEST
19
20 #include <iostream>
21 #include <string>
22 #include <sys/types.h>
23 #include <utility>
24 #include <vector>
25
26 #include <security-manager.h>
27
28 namespace SecurityManagerTest {
29
30 class InstallRequest
31 {
32 public:
33     InstallRequest();
34     InstallRequest(const InstallRequest&) = delete;
35     InstallRequest& operator=(const InstallRequest&) = delete;
36     InstallRequest(InstallRequest &&other)
37         : m_req(std::move(other.m_req)),
38           m_appId(std::move(other.m_appId)),
39           m_pkgId(std::move(other.m_pkgId)),
40           m_authorId(std::move(other.m_authorId)),
41           m_privileges(std::move(other.m_privileges)),
42           m_paths(std::move(other.m_paths)),
43           m_uid(std::move(other.m_uid))
44     {
45         other.m_req = nullptr;
46         other.m_uid.first = false;
47         other.m_uid.second = 0;
48     }
49     ~InstallRequest();
50
51     void setAppTizenVersion(std::string tizenVer,
52             lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
53     void setAppId(std::string appId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
54     void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
55     void addPrivilege(const char *privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
56     void addPath(std::string path, app_install_path_type pathType,
57                  lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
58     void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
59     void setAuthorId(std::string authorId, lib_retcode expectedResult= SECURITY_MANAGER_SUCCESS);
60     void setInstallType(const enum app_install_type &type, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
61
62     std::string getAppTizenVersion() const { return m_tizenVer; }
63     app_inst_req *get() { return m_req; }
64     const app_inst_req *get() const { return m_req; }
65     friend std::ostream& operator<<(std::ostream &, const InstallRequest&);
66
67 private:
68     app_inst_req *m_req;
69
70     std::string m_tizenVer;
71     std::string m_appId;
72     std::string m_pkgId;
73     std::string m_authorId;
74     std::vector<std::string> m_privileges;
75     std::vector<std::pair<std::string, app_install_path_type> > m_paths;
76     std::pair<bool, uid_t> m_uid;
77 };
78
79 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::InstallRequest &request);
80
81 class PathsRequest
82 {
83 public:
84     PathsRequest();
85     PathsRequest(const PathsRequest&) = delete;
86     PathsRequest& operator=(const PathsRequest&) = delete;
87     ~PathsRequest();
88
89     void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
90     void addPath(std::string path, app_install_path_type pathType,
91                  lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
92     void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
93     void setInstallType(const enum app_install_type &type, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
94
95     //app_inst_req *get() { return m_req; }
96     const path_req *get() const { return m_req; }
97     friend std::ostream& operator<<(std::ostream &, const PathsRequest&);
98
99 private:
100     path_req *m_req;
101
102     std::string m_pkgId;
103     std::vector<std::pair<std::string, app_install_path_type> > m_paths;
104     std::pair<bool, uid_t> m_uid;
105 };
106
107 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PathsRequest &request);
108
109 } // namespace SecurityManagerTest
110
111 #endif // SECURITY_MANAGER_TEST_INSTALLREQUEST