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 directly
92 */
93 RUNNER_TEST(feature_dao_test_get_feature_properties)
94 {
95     {
96         FeatureDAOReadOnly dao("feature1");
97         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature1");
98         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "plugin1");
99         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "");
100     }
101
102     {
103         FeatureDAOReadOnly dao("feature2");
104         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature2");
105         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
106         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
107     }
108
109     {
110         FeatureDAOReadOnly dao("feature3");
111         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature3");
112         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
113         RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
114     }
115 }
116
117 /*
118 Name: feature_dao_test_feature_constructor_name
119 Description: -
120 Expected: -
121
122 TODO: test
123 */
124 RUNNER_TEST(feature_dao_test_feature_constructor_name)
125 {
126     std::list<const char *> preinstalled;
127     preinstalled.push_back("feature1");
128     preinstalled.push_back("feature2");
129     preinstalled.push_back("feature3");
130     preinstalled.push_back("feature4");
131
132     FOREACH(it, preinstalled)
133     {
134         FeatureDAOReadOnly dao(*it);
135         RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), *it);
136     }
137
138     //TODO check exception that may occur (feature does not exist)
139 }
140
141 /*
142 Name: feature_dao_test_feature_handle_list
143 Description: Checks if list of installed features is returend correctly
144 Expected: list size should be at last equal number of preinserted features
145 */
146 RUNNER_TEST(feature_dao_test_feature_handle_list)
147 {
148     FeatureHandleList handles = FeatureDAOReadOnly::GetHandleList();
149     RUNNER_ASSERT(handles.size() >= 4);
150 }
151
152 /*
153 Name: feature_dao_test_is_feature_installed
154 Description: Checks if installed features are showed correctly.
155 Expected: correct installed features should be present
156 */
157 RUNNER_TEST(feature_dao_test_is_feature_installed)
158 {
159     //installed
160     {
161         std::list<const char *> preinstalled;
162         preinstalled.push_back("feature1");
163         preinstalled.push_back("feature2");
164         preinstalled.push_back("feature3");
165         preinstalled.push_back("feature4");
166
167         FOREACH(it, preinstalled)
168             RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(*it));
169     }
170
171     //not installed
172     {
173         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("not_installed1")==false);
174         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("plugin1") == false);
175         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("") == false);
176         RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("ff") == false);
177     }
178 }
179
180 /*
181 Name: feature_dao_test_get_device_capab
182 Description: -
183 Expected: -
184
185 TODO: fix test
186 */
187 RUNNER_TEST(feature_dao_test_get_device_capab)
188 {
189 #if 0
190     //TODO do more tests
191
192     {//check deviceCaps
193         Feature f;
194         f.setName("new_dev_f4");
195         f.setLibraryName("new_dev_f4 lib_name");
196
197         FeatureDAOReadOnly::DeviceCapabilitiesList devList;
198         devList.insert("new_dev_f4 devcap1");
199         devList.insert("new_dev_f4 devcap2");
200
201         FOREACH(it, devList)
202             f.addDeviceCapability(*it);
203
204         FeatureHandle handle = FeatureDAO::RegisterFeature(f,"new_dev_f4 path");
205
206         FeatureDAOReadOnly dao(handle);
207
208         FeatureDAOReadOnly::DeviceCapabilitiesList gotList =
209                 dao.GetDeviceCapabilities();
210         RUNNER_ASSERT_MSG(gotList.size() == devList.size(),
211                           "deviceCaps wrong");
212     }
213 #endif
214 }
215
216 /*
217 Name: feature_dao_test_is_device_capab_installed
218 Description: Checks if FeatureDAOReadOnly::isDeviceCapabilityInstalled works correctly.
219 Expected: correct capabilities should be present
220 */
221 RUNNER_TEST(feature_dao_test_is_device_capab_installed)
222 {
223     //installed
224     std::list<const char *> preinstalled;
225     preinstalled.push_back("devicecap1");
226     preinstalled.push_back("devicecap2");
227     preinstalled.push_back("devicecap3");
228     preinstalled.push_back("devicecap4");
229
230     FOREACH(it, preinstalled)
231         RUNNER_ASSERT(FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
232
233     //not installed
234     std::list<const char *> notinstalled;
235     notinstalled.push_back("notinstalled1");
236     notinstalled.push_back("plugin1");
237     notinstalled.push_back("");
238     notinstalled.push_back("ff");
239
240     FOREACH(it, notinstalled)
241         RUNNER_ASSERT(!FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
242 }
243
244 #undef RUNNER_ASSERT_WHAT_EQUALS