Tizen 2.0 Release
[framework/web/wrt-commons.git] / tests / dao / TestCases_FeatureDAO.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   TestCases_FeatureDAO.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @version 1.0
20  * @brief   This file contains tests for feature dao class.
21  */
22
23 #include <dpl/test/test_runner.h>
24 #include <dpl/foreach.h>
25 #include <dpl/wrt-dao-rw/feature_dao.h>
26 #include <dpl/wrt-dao-rw/plugin_dao.h>
27 #include <dpl/wrt-dao-ro/wrt_db_types.h>
28
29 using namespace WrtDB;
30
31 #define RUNNER_ASSERT_WHAT_EQUALS(in, test)                   \
32     { std::string tmp(in);                                     \
33       RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
34
35 RUNNER_TEST_GROUP_INIT(DAO)
36
37 /*
38  * Name: feature_dao_test_register_features
39  * Description: Checks if plugin registeration performs features registration
40  * Expected: registrartion should succeed
41  */
42 RUNNER_TEST(feature_dao_test_register_features)
43 {
44     PluginHandle plHandle;
45     {
46         std::string libraryPath("nfp1 lib_path");
47         std::string libraryName("nfp1");
48
49         PluginMetafileData pluginData;
50         pluginData.m_libraryName = libraryName;
51
52         plHandle = PluginDAO::registerPlugin(pluginData, libraryPath);
53         RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
54
55         FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
56         PluginMetafileData::Feature f;
57         f.m_name = std::string("new_f1");
58
59         FeatureHandle handle = FeatureDAO::RegisterFeature(f, plHandle);
60         RUNNER_ASSERT_MSG(handle != -1, "Already registered");
61         RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(),
62                           "New feature should be saved");
63
64         FeatureDAOReadOnly dao(handle);
65
66         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "new_f1");
67         plHandle = dao.GetPluginHandle();
68     }
69
70     {
71         FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
72
73         PluginMetafileData::Feature f;
74         f.m_name = std::string("new_f2");
75
76         FeatureHandle handle = FeatureDAO::RegisterFeature(f, plHandle);
77         RUNNER_ASSERT_MSG(handle != -1, "Already registered");
78         RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(),
79                           "New feature should be saved");
80
81         FeatureDAOReadOnly dao(handle);
82
83         RUNNER_ASSERT_MSG(plHandle == dao.GetPluginHandle(),
84                           "New plugin registered (should be old used)");
85     }
86 }
87
88 /*
89  * Name: feature_dao_test_get_feature_properties
90  * Description: Checks properties of inserted features
91  * Expected: properties of features should match values inserted to database
92  * directly
93  */
94 RUNNER_TEST(feature_dao_test_get_feature_properties)
95 {
96     {
97         FeatureDAOReadOnly dao("feature1");
98         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature1");
99         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "plugin1");
100         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "");
101     }
102
103     {
104         FeatureDAOReadOnly dao("feature2");
105         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature2");
106         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
107         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
108     }
109
110     {
111         FeatureDAOReadOnly dao("feature3");
112         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature3");
113         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
114         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
115     }
116 }
117
118 /*
119  * Name: feature_dao_test_feature_constructor_name
120  * Description: -
121  * Expected: -
122  *
123  * TODO: test
124  */
125 RUNNER_TEST(feature_dao_test_feature_constructor_name)
126 {
127     std::list<const char *> preinstalled;
128     preinstalled.push_back("feature1");
129     preinstalled.push_back("feature2");
130     preinstalled.push_back("feature3");
131     preinstalled.push_back("feature4");
132
133     FOREACH(it, preinstalled)
134     {
135         FeatureDAOReadOnly dao(*it);
136         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), *it);
137     }
138
139     //TODO check exception that may occur (feature does not exist)
140 }
141
142 /*
143  * Name: feature_dao_test_feature_handle_list
144  * Description: Checks if list of installed features is returend correctly
145  * Expected: list size should be at last equal number of preinserted features
146  */
147 RUNNER_TEST(feature_dao_test_feature_handle_list)
148 {
149     FeatureHandleList handles = FeatureDAOReadOnly::GetHandleList();
150     RUNNER_ASSERT(handles.size() >= 4);
151 }
152
153 /*
154  * Name: feature_dao_test_is_feature_installed
155  * Description: Checks if installed features are showed correctly.
156  * Expected: correct installed features should be present
157  */
158 RUNNER_TEST(feature_dao_test_is_feature_installed)
159 {
160     //installed
161     {
162         std::list<const char *> preinstalled;
163         preinstalled.push_back("feature1");
164         preinstalled.push_back("feature2");
165         preinstalled.push_back("feature3");
166         preinstalled.push_back("feature4");
167
168         FOREACH(it, preinstalled)
169         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(*it));
170     }
171
172     //not installed
173     {
174         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(
175                           "not_installed1") == false);
176         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(
177                           "plugin1") == false);
178         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("") == false);
179         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("ff") == false);
180     }
181 }
182
183 /*
184  * Name: feature_dao_test_get_device_capab
185  * Description: -
186  * Expected: -
187  *
188  * TODO: fix test
189  */
190 RUNNER_TEST(feature_dao_test_get_device_capab)
191 {
192 #if 0
193     //TODO do more tests
194
195     { //check deviceCaps
196         Feature f;
197         f.setName("new_dev_f4");
198         f.setLibraryName("new_dev_f4 lib_name");
199
200         FeatureDAOReadOnly::DeviceCapabilitiesList devList;
201         devList.insert("new_dev_f4 devcap1");
202         devList.insert("new_dev_f4 devcap2");
203
204         FOREACH(it, devList)
205         f.addDeviceCapability(*it);
206
207         FeatureHandle handle = FeatureDAO::RegisterFeature(f, "new_dev_f4 path");
208
209         FeatureDAOReadOnly dao(handle);
210
211         FeatureDAOReadOnly::DeviceCapabilitiesList gotList =
212             dao.GetDeviceCapabilities();
213         RUNNER_ASSERT_MSG(gotList.size() == devList.size(),
214                           "deviceCaps wrong");
215     }
216 #endif
217 }
218
219 /*
220  * Name: feature_dao_test_is_device_capab_installed
221  * Description: Checks if FeatureDAOReadOnly::isDeviceCapabilityInstalled works
222  * correctly.
223  * Expected: correct capabilities should be present
224  */
225 RUNNER_TEST(feature_dao_test_is_device_capab_installed)
226 {
227     //installed
228     std::list<const char *> preinstalled;
229     preinstalled.push_back("devicecap1");
230     preinstalled.push_back("devicecap2");
231     preinstalled.push_back("devicecap3");
232     preinstalled.push_back("devicecap4");
233
234     FOREACH(it, preinstalled)
235     RUNNER_ASSERT(FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
236
237     //not installed
238     std::list<const char *> notinstalled;
239     notinstalled.push_back("notinstalled1");
240     notinstalled.push_back("plugin1");
241     notinstalled.push_back("");
242     notinstalled.push_back("ff");
243
244     FOREACH(it, notinstalled)
245     RUNNER_ASSERT(!FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
246 }
247
248 #undef RUNNER_ASSERT_WHAT_EQUALS