tizen 2.3 release
[framework/web/wearable/wrt-security.git] / tests / ace_settings / test_cases.cpp
1 /*
2  * Copyright (c) 2011 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  * @file    test_cases.cpp
18  * @author  Tonasz Swierczek (t.swierczek@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for ACE settings test cases.
21  */
22 #include <dpl/test/test_runner.h>
23
24 #include "ace_api_settings.h"
25
26 namespace {
27
28 static const char* resource1 = "resource1-name";
29 static const char* resource2 = "resource2-name";
30 static int handle1 = 0;
31 static int handle2 = 1;
32 static ace_preference_t preference1 = ACE_PREFERENCE_PERMIT;
33 static ace_preference_t preference2 = ACE_PREFERENCE_BLANKET_PROMPT;
34
35 } // namespace
36
37 RUNNER_TEST_GROUP_INIT(ACE_SETTINGS_TEST_SUITE)
38
39 /*
40  * test author: Tomasz Swierczek (t.swierczek@samsung.com)
41  * tested functions: ace_settings_initialize(), ace_settings_shutdown()
42  * purpose: New C-API tests. Tests proper initialization and deinitialization
43  * of ace-settings library.
44  */
45 RUNNER_TEST(ace_settings_test_01_initialization)
46 {
47     RUNNER_ASSERT(ACE_OK == ace_settings_initialize());
48     RUNNER_ASSERT(ACE_OK == ace_settings_shutdown());
49     RUNNER_ASSERT(ACE_OK == ace_settings_initialize());
50 }
51
52 /*
53  * test author: Tomasz Swierczek (t.swierczek@samsung.com)
54  * tested functions: ace_set_global_resource_preference(),
55  * ace_get_global_resource_preference()
56  * purpose: New C-API tests. Tests setting and getting global per resource
57  * access preferences.
58  */
59 RUNNER_TEST(ace_settings_test_02_global_preferences)
60 {
61     RUNNER_ASSERT(ACE_OK == ace_set_global_resource_preference(
62             const_cast<char*>(resource1), preference1));
63     ace_preference_t pref;
64     RUNNER_ASSERT(ACE_OK == ace_get_global_resource_preference(
65             const_cast<char*>(resource1), &pref));
66     RUNNER_ASSERT(preference1 == pref);
67
68     RUNNER_ASSERT(ACE_OK == ace_set_global_resource_preference(
69             const_cast<char*>(resource2), preference2));
70     RUNNER_ASSERT(ACE_OK == ace_get_global_resource_preference(
71             const_cast<char*>(resource2), &pref));
72     RUNNER_ASSERT(preference2 == pref);
73 }
74
75 /*
76  * test author: Tomasz Swierczek (t.swierczek@samsung.com)
77  * tested functions: ace_set_widget_resource_preference(),
78  * ace_get_widget_resource_preference()
79  * purpose: New C-API tests. Tests setting and getting per widget/resource
80  * access preferences.
81  */
82 RUNNER_TEST(ace_settings_test_03_widget_preferences)
83 {
84     RUNNER_ASSERT(ACE_OK == ace_set_widget_resource_preference(handle1,
85             const_cast<char*>(resource1),
86             preference1));
87     ace_preference_t pref;
88     RUNNER_ASSERT(ACE_OK == ace_get_widget_resource_preference(handle1,
89             const_cast<char*>(resource1),
90             &pref));
91     RUNNER_ASSERT(preference1 == pref);
92
93     RUNNER_ASSERT(ACE_OK == ace_set_widget_resource_preference(handle2,
94             const_cast<char*>(resource2),
95             preference2));
96     RUNNER_ASSERT(ACE_OK == ace_get_widget_resource_preference(handle2,
97             const_cast<char*>(resource2),
98             &pref));
99     RUNNER_ASSERT(preference2 == pref);
100 }
101
102 /*
103  * test author: Tomasz Swierczek (t.swierczek@samsung.com)
104  * tested functions: ace_get_widget_resource_preference(),
105  * ace_get_global_resource_preference(),
106  * ace_reset_widget_resource_settings(),
107  * ace_reset_global_resource_settings()
108  * purpose: New C-API tests. Tests proper resetting of settings database.
109  */
110 RUNNER_TEST(ace_settings_test_04_database_reset)
111 {
112     RUNNER_ASSERT(ACE_OK == ace_reset_widget_resource_settings());
113     RUNNER_ASSERT(ACE_OK == ace_reset_global_resource_settings());
114     ace_preference_t pref;
115     RUNNER_ASSERT(ACE_OK == ace_get_widget_resource_preference(handle1,
116             const_cast<char*>(resource1),
117             &pref));
118     RUNNER_ASSERT(ACE_PREFERENCE_DEFAULT == pref);
119     RUNNER_ASSERT(ACE_OK == ace_get_widget_resource_preference(handle2,
120             const_cast<char*>(resource2),
121             &pref));
122     RUNNER_ASSERT(ACE_PREFERENCE_DEFAULT == pref);
123     RUNNER_ASSERT(ACE_OK == ace_get_global_resource_preference(
124             const_cast<char*>(resource1),
125             &pref));
126     RUNNER_ASSERT(ACE_PREFERENCE_DEFAULT == pref);
127     RUNNER_ASSERT(ACE_OK == ace_get_global_resource_preference(
128             const_cast<char*>(resource2),
129             &pref));
130     RUNNER_ASSERT(ACE_PREFERENCE_DEFAULT == pref);
131 }
132
133 /*
134  * test author: Bartlomiej Grzelewski (b.grzelewski@samsung.com)
135  * tested functions: ace_is_private_api
136  * purpose: This function should return true if device cap
137  * belongs to private api.
138  */
139 RUNNER_TEST(ace_settings_test_05_private_api_positive)
140 {
141     static const char *api_private[] = {
142         "bluetooth.admin",
143         "contact.read",
144         "nfc.tag",
145         NULL
146     };
147     for (int i=0; api_private[i]; ++i) {
148         ace_bool_t response = ACE_FALSE;
149         RUNNER_ASSERT(ACE_OK == ace_is_private_api(
150             const_cast<char*>(api_private[i]), &response));
151         RUNNER_ASSERT(ACE_TRUE == response);
152     }
153 }
154
155 /*
156  * test author: Bartlomiej Grzelewski (b.grzelewski@samsung.com)
157  * tested functions: ace_is_private_api
158  * purpose: All calls should fail as non of the strings are connected with
159  * private api.
160  */
161 RUNNER_TEST(ace_settings_test_06_private_api_negative)
162 {
163     static const char *api_private[] = {
164         "bluetooth",
165         "contact.reed",
166         "nfc.tag.extended",
167         "totaly.fake",
168         NULL
169     };
170
171     for (int i=0; api_private[i]; ++i) {
172         ace_bool_t response = ACE_TRUE;
173         RUNNER_ASSERT(ACE_OK == ace_is_private_api(
174             const_cast<char*>(api_private[i]), &response));
175         RUNNER_ASSERT(ACE_FALSE == response);
176     }
177 }
178