Fix security_manager_02_app_install_uninstall_full test
[platform/core/test/security-tests.git] / tests / security-manager-tests / common / sm_policy_request.h
1 /*
2  * Copyright (c) 2015 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_POLICYREQUEST
18 #define SECURITY_MANAGER_TEST_POLICYREQUEST
19
20 #include <iostream>
21 #include <sys/types.h>
22 #include <utility>
23 #include <vector>
24
25 #include <security-manager.h>
26
27 namespace SecurityManagerTest {
28
29 class PolicyEntry
30 {
31 public:
32     PolicyEntry();
33
34     PolicyEntry(const std::string &appId,
35                 const std::string &user,
36                 const std::string &privilege
37                 );
38     ~PolicyEntry();
39
40     PolicyEntry(policy_entry &entry);
41
42     policy_entry *get() const { return m_entry; }
43     std::string getUser() const         { return m_user.second; }
44     std::string getAppId() const        { return m_appId.second; }
45     std::string getPrivilege() const    { return m_privilege.second; }
46     std::string getCurrentLevel() const { return m_currentLevel.second; }
47     std::string getMaxLevel() const     { return m_maxLevel.second; }
48     void setLevel(const std::string &level);
49     void setMaxLevel(const std::string &level);
50     void free(void);
51
52     friend std::ostream& operator<<(std::ostream &, const PolicyEntry&);
53
54 private:
55     policy_entry *m_entry;
56     std::pair<bool, std::string> m_appId;
57     std::pair<bool, std::string> m_user;
58     std::pair<bool, std::string> m_privilege;
59     std::pair<bool, std::string> m_currentLevel;
60     std::pair<bool, std::string> m_maxLevel;
61 };
62
63 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PolicyEntry &request);
64
65 class PolicyRequest
66 {
67 public:
68     PolicyRequest();
69     PolicyRequest(const PolicyRequest&) = delete;
70     PolicyRequest& operator=(const PolicyRequest&) = delete;
71     ~PolicyRequest();
72
73     void addEntry(PolicyEntry &entry, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
74
75     policy_update_req *get() const { return m_req; }
76     friend std::ostream& operator<<(std::ostream &, const PolicyRequest&);
77
78 private:
79     policy_update_req *m_req;
80     std::vector<PolicyEntry> m_entries;
81 };
82
83 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PolicyRequest &request);
84
85 } // namespace SecurityManagerTest
86
87 #endif // SECURITY_MANAGER_TEST_USERREQUEST