Merging tizen into ckm. Stage 1.
[platform/core/test/security-tests.git] / tests / libprivilege-control-tests / common / db.h
1 /*
2  * Copyright (c) 2012 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 /*
18  * @file        libprivilege-control_test_db.h
19  * @author      Lukasz Wojciechowski (l.wojciechow@partner.samsung.com)
20  * @version     1.0
21  * @brief       libprivilege-control tests database record check functions
22  */
23
24 #ifndef LIBPRIVILEGE_CONTROL_TEST_DB_H_
25 #define LIBPRIVILEGE_CONTROL_TEST_DB_H_
26
27 #include <privilege-control.h>
28 #include "libprivilege-control_test_common.h"
29 #include "db_sqlite.h"
30
31 /**
32  * @class       TestLibPrivilegeControlDatabase
33  * @brief       Class containing methods for testing libprivlege database.
34  */
35 class TestLibPrivilegeControlDatabase
36 {
37 public:
38 /**
39  * @brief A constructor
40  */
41     TestLibPrivilegeControlDatabase();
42
43 /**
44  * @brief A destructor
45  */
46     ~TestLibPrivilegeControlDatabase() = default;
47
48 /**
49  * @brief Method for testing database after "perm_app_install" was run.
50  *
51  * It checks existence of proper: label, app records and permission for ALL_APPS for installed app.
52  *
53  * @param name          name of installed app
54  */
55     void test_db_after__perm_app_install(const char* name);
56
57 /**
58  * @brief Method for testing database after "perm_app_uninstall" was run.
59  *
60  * It checks absence of proper: label for installed app.
61  *
62  * @param name          name of uninstalled app
63  */
64     void test_db_after__perm_app_uninstall(const char* name);
65
66 /**
67  * @brief Method for testing database after "perm_app_enable_permissions" was run.
68  *
69  * It checks existence of proper permissions from perm_list and main permission for whole app_type.
70  *
71  * @param name          name of application
72  * @param app_type      type of application (EFL, WRT, etc. )
73  * @param perm_list     list of permission to enable
74  * @param persistent    persistence or volatileness of permissions
75  */
76     void test_db_after__perm_app_enable_permissions(const char* name, app_type_t app_type,
77         const char** perm_list, bool persistent);
78
79 private:
80 /**
81  * @var base
82  * @brief Sqlite3DBase object giving simple access to database
83  *
84  * Connection to database is open first time it is needed
85  * and closed in destructor of TestLibPrivilegeControlDatabase.
86  */
87     Sqlite3DBase m_base;
88
89 /**
90  * @brief Check existence of label related records for given app.
91  *
92  * @param app_name      name of application
93  */
94     void app_label(const std::string& app_name);
95
96 /**
97  * @brief Check absence of label record for given app.
98  *
99  * @param app_name      name of application
100  */
101     void app_not_label(const std::string& app_name);
102
103 /**
104  * @brief It checks existence of single permission.
105  *
106  * @param app_name              name of application
107  * @param permission_name       name of permission
108  * @param permission_type_name  name of permission type
109  * @param is_volatile           persistence or volatileness of permissions
110  * @param is_enabled            permission enable flag
111  */
112     void app_permission(const std::string& app_name, const std::string& permission_name,
113         const std::string& permission_type_name, int is_volatile, int is_enabled);
114 };
115
116 #endif /* LIBPRIVILEGE_CONTROL_TEST_DB_H_ */