Sqlite3 support for tests. Libprivilege tests: check database
[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 <tracker.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 tracker       make assertion comments if error more useful
54  * @param name  name of installed app
55  */
56     void test_db_after__perm_app_install(const Tracker& tracker, const char* name);
57
58 /**
59  * @brief Method for testing database after "perm_app_install" was run.
60  *
61  * It checks existence of proper: label, app records and permission for ALL_APPS for installed app.
62  *
63  * @param tracker       make assertion comments if error more useful
64  * @param name  name of installed app
65  */
66     void test_db_after__perm_app_uninstall(const Tracker& tracker, const char* name);
67
68 /**
69  * @brief Method for testing database after "perm_app_enable_permissions" was run.
70  *
71  * It checks existence of proper permissions from perm_list and main permission for whole app_type.
72  *
73  * @param tracker       make assertion comments if error more useful
74  * @param name          name of application
75  * @param app_type      type of application (EFL, WRT, etc. )
76  * @param perm_list     list of permission to enable
77  * @param persistent    persistence or volatileness of permissions
78  */
79     void test_db_after__perm_app_enable_permissions(const Tracker& tracker, const char* name,
80         app_type_t app_type, const char** perm_list, bool persistent);
81
82 private:
83 /**
84  * @var base
85  * @brief Sqlite3DBase object giving simple access to database
86  *
87  * Connection to database is open first time it is needed
88  * and closed in destructor of TestLibPrivilegeControlDatabase.
89  */
90     Sqlite3DBase m_base;
91
92 /**
93  * @brief Check existence of label related records for given app.
94  *
95  * @param tracker       make assertion comments if error more useful
96  * @param app_name      name of application
97  */
98     void app_label(const Tracker& tracker, const std::string& app_name);
99
100 /**
101  * @brief Check absence of label record for given app.
102  *
103  * @param tracker       make assertion comments if error more useful
104  * @param app_name      name of application
105  */
106     void app_not_label(const Tracker& tracker, const std::string& app_name);
107
108 /**
109  * @brief It checks existence of single permission.
110  * @param tracker               make assertion comments if error more useful
111  * @param app_name              name of application
112  * @param permission_name       name of permission
113  * @param permission_type_name  name of permission type
114  * @param is_volatile           persistence or volatileness of permissions
115  * @param is_enabled            permission enable flag
116  */
117     void app_permission(const Tracker& tracker, const std::string& app_name,
118         const std::string& permission_name, const std::string& permission_type_name,
119         int is_volatile, int is_enabled);
120 };
121
122 #endif /* LIBPRIVILEGE_CONTROL_TEST_DB_H_ */