2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file TestCases_FeatureDAO.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains tests for feature dao class.
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>
29 using namespace WrtDB;
31 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
32 { std::string tmp(in); \
33 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
35 RUNNER_TEST_GROUP_INIT(DAO)
38 * Name: feature_dao_test_register_features
39 * Description: Checks if plugin registeration performs features registration
40 * and if registration is made properly
41 * Expected: registrartion should succeed
43 RUNNER_TEST(feature_dao_test_register_features)
45 PluginHandle plHandle;
47 std::string libraryPath("nfp1 lib_path");
48 std::string libraryName("nfp1");
50 PluginMetafileData pluginData;
51 pluginData.m_libraryName = libraryName;
53 plHandle = PluginDAO::registerPlugin(pluginData, libraryPath);
54 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
56 FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
57 PluginMetafileData::Feature f;
58 f.m_name = std::string("new_f1");
60 FeatureHandle handle = FeatureDAO::RegisterFeature(f, plHandle);
61 RUNNER_ASSERT_MSG(handle != -1, "Already registered");
62 RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(),
63 "New feature should be saved");
65 FeatureDAOReadOnly dao(handle);
67 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "new_f1");
68 plHandle = dao.GetPluginHandle();
72 FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
74 PluginMetafileData::Feature f;
75 f.m_name = std::string("new_f2");
77 FeatureHandle handle = FeatureDAO::RegisterFeature(f, plHandle);
78 RUNNER_ASSERT_MSG(handle != -1, "Already registered");
79 RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(),
80 "New feature should be saved");
82 FeatureDAOReadOnly dao(handle);
84 RUNNER_ASSERT_MSG(plHandle == dao.GetPluginHandle(),
85 "New plugin registered (should be old used)");
87 FeatureDAO::UnregisterFeature(handle);
88 PluginDAO::unregisterPlugin(plHandle);
93 * Name: feature_dao_test_get_feature_handle
94 * Description: Checks GetFeatureHandleListForPlugin
95 * Expected: no errors found
98 RUNNER_TEST(feature_dao_test_get_feature_handle)
100 PluginHandleSetPtr plugins =
101 PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_COMPLETED);
103 RUNNER_ASSERT(plugins->size() == 5);
105 FOREACH(it, *plugins) {
106 FeatureHandleListPtr featureListPtr =
107 FeatureDAOReadOnly::GetFeatureHandleListForPlugin(*it);
108 int size = featureListPtr->size();
113 RUNNER_ASSERT(size == 1);
116 RUNNER_ASSERT(size == 0);
119 RUNNER_ASSERT(size == 0);
122 RUNNER_ASSERT(size == 3);
125 RUNNER_ASSERT(size == 0);
128 RUNNER_ASSERT_MSG(false, "Wrong plugin handle");
135 * Name: feature_dao_test_get_device_capability
136 * Description: Checks GetDeviceCapability
137 * Expected: no errors found
140 RUNNER_TEST(feature_dao_test_get_device_capability)
142 RUNNER_ASSERT(FeatureDAOReadOnly::GetDeviceCapability(L"feature1").size() == 1);
143 RUNNER_ASSERT(FeatureDAOReadOnly::GetDeviceCapability(L"feature2").size() == 2);
144 RUNNER_ASSERT(FeatureDAOReadOnly::GetDeviceCapability(L"feature3").size() == 1);
145 RUNNER_ASSERT(FeatureDAOReadOnly::GetDeviceCapability(L"feature4").size() == 0);
149 * Name: feature_dao_test_unregister
150 * Description: Checks UnregisterFeature
151 * Expected: no errors found
153 RUNNER_TEST(feature_dao_test_unregister)
155 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("feature5") == false);
156 unsigned int size = FeatureDAOReadOnly::GetHandleList().size();
158 PluginHandle plHandle;
159 PluginMetafileData pluginData;
160 pluginData.m_libraryName = "nfp1 lib_path";
161 plHandle = PluginDAO::registerPlugin(pluginData, "lib_path");
163 PluginMetafileData::Feature f0;
164 f0.m_name = std::string("feature5");
165 f0.m_deviceCapabilities.insert("1devicecap");
166 f0.m_deviceCapabilities.insert("2devicecap");
167 f0.m_deviceCapabilities.insert("3devicecap");
169 FeatureHandle handle0 = FeatureDAO::RegisterFeature(f0, plHandle);
170 RUNNER_ASSERT_MSG(handle0 != -1, "Already registered");
172 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(handle0) == true);
173 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("feature5") == true);
174 RUNNER_ASSERT(FeatureDAOReadOnly::GetHandleList().size() == size + 1);
176 FeatureDAO::UnregisterFeature(handle0);
178 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(handle0) == false);
179 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("feature5") == false);
180 RUNNER_ASSERT(FeatureDAOReadOnly::GetHandleList().size() == size);
182 PluginMetafileData::Feature f1;
183 f1.m_name = std::string("feature5");
185 FeatureHandle handle1 = FeatureDAO::RegisterFeature(f1, plHandle);
186 RUNNER_ASSERT_MSG(handle1 != -1, "Already registered");
188 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(handle1) == true);
189 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("feature5") == true);
190 RUNNER_ASSERT(FeatureDAOReadOnly::GetHandleList().size() == size + 1);
192 FeatureDAO::UnregisterFeature(handle1);
194 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(handle1) == false);
195 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("feature5") == false);
196 RUNNER_ASSERT(FeatureDAOReadOnly::GetHandleList().size() == size);
198 PluginDAO::unregisterPlugin(plHandle);
202 * Name: feature_dao_test_get_device_capabilities
203 * Description: Checks GetDeviceCapabilities
204 * Expected: no errors found
206 RUNNER_TEST(feature_dao_test_get_device_capabilities)
208 FeatureDAOReadOnly f1("feature1");
209 RUNNER_ASSERT(f1.GetDeviceCapabilities().size() == 1);
211 FeatureDAOReadOnly f2("feature2");
212 RUNNER_ASSERT(f2.GetDeviceCapabilities().size() == 2);
214 FeatureDAOReadOnly f3("feature3");
215 RUNNER_ASSERT(f3.GetDeviceCapabilities().size() == 1);
217 FeatureDAOReadOnly f4("feature4");
218 RUNNER_ASSERT(f4.GetDeviceCapabilities().size() == 0);
222 * Name: feature_dao_test_get_names
223 * Description: Checks GetNames
224 * Expected: no errors found
227 RUNNER_TEST(feature_dao_test_get_names)
229 FeatureDAOReadOnly::NameMap names = FeatureDAOReadOnly::GetNames();
231 RUNNER_ASSERT(names.size() == 4);
235 if(n->second == "feature1" || n->second == "feature2" ||
236 n->second == "feature3" || n->second == "feature4")
238 else RUNNER_ASSERT_MSG(false, "Wrong feature name");
241 RUNNER_ASSERT(count == 4);
245 * Name: feature_dao_test_dev_cap_with_feature_handle
246 * Description: Checks GetDevCapWithFeatureHandle
247 * Expected: no errors found
249 RUNNER_TEST(feature_dao_test_dev_cap_with_feature_handle)
251 FeatureDAOReadOnly::DeviceCapabilitiesMap map = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
252 RUNNER_ASSERT(map.size() == 4);
256 if(n->second == "devicecap1" || n->second == "devicecap2" ||
257 n->second == "devicecap3" || n->second == "devicecap4")
259 else RUNNER_ASSERT_MSG(false, "Wrong device capability");
262 RUNNER_ASSERT(count == 4);
267 * Name: feature_dao_test_get_features
268 * Description: Checks GetFeatures
269 * Expected: no errors
271 RUNNER_TEST(feature_dao_test_get_features)
273 //tests commented because internal error occured due to many GetFeatures() calls
274 // std::list<std::string> fs0(4);
275 // RUNNER_ASSERT(FeatureDAOReadOnly::GetFeatures(fs0).size() == 0);
277 // std::list<std::string> fs1(4);
278 // fs1.push_front("feature");
279 // fs1.push_front("feature2");
280 // RUNNER_ASSERT(FeatureDAOReadOnly::GetFeatures(fs1).size() == 2);
281 // std::list<std::string> fs2(4);
282 // fs2.push_front("feature");
283 // fs2.push_front("feature2");
284 // RUNNER_ASSERT(FeatureDAOReadOnly::GetFeatures(fs2).size() == 1);
286 std::list<std::string> fs3(4);
287 fs3.push_front("feature1");
288 fs3.push_front("feature2");
289 fs3.push_front("feature3");
290 fs3.push_front("feature4");
291 RUNNER_ASSERT(FeatureDAOReadOnly::GetFeatures(fs3).size() == 4);
295 * Name: feature_dao_test_get_feature_properties
296 * Description: Checks properties of inserted features
297 * Expected: properties of features should match values inserted to database
300 RUNNER_TEST(feature_dao_test_get_feature_properties)
303 FeatureDAOReadOnly dao("feature1");
304 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature1");
305 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "plugin1");
306 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "");
310 FeatureDAOReadOnly dao("feature2");
311 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature2");
312 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
313 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
317 FeatureDAOReadOnly dao("feature3");
318 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature3");
319 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4");
320 RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4");
325 * Name: feature_dao_test_feature_constructor_name
331 RUNNER_TEST(feature_dao_test_feature_constructor_name)
333 std::list<const char *> preinstalled;
334 preinstalled.push_back("feature1");
335 preinstalled.push_back("feature2");
336 preinstalled.push_back("feature3");
337 preinstalled.push_back("feature4");
339 FOREACH(it, preinstalled)
341 FeatureDAOReadOnly dao(*it);
342 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), *it);
345 //TODO check exception that may occur (feature does not exist)
349 * Name: feature_dao_test_feature_handle_list
350 * Description: Checks if list of installed features is returend correctly
351 * Expected: list size should be at last equal number of preinserted features
353 RUNNER_TEST(feature_dao_test_feature_handle_list)
355 RUNNER_ASSERT(FeatureDAOReadOnly::GetHandleList().size() == 4);
359 * Name: feature_dao_test_is_feature_installed
360 * Description: Checks if installed features are showed correctly.
361 * Expected: correct installed features should be present
363 RUNNER_TEST(feature_dao_test_is_feature_installed)
367 std::list<const char *> preinstalled;
368 preinstalled.push_back("feature1");
369 preinstalled.push_back("feature2");
370 preinstalled.push_back("feature3");
371 preinstalled.push_back("feature4");
373 FOREACH(it, preinstalled)
374 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(*it));
379 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(
380 "not_installed1") == false);
381 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(
382 "plugin1") == false);
383 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("") == false);
384 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("ff") == false);
389 * Name: feature_dao_test_is_device_capab_installed
390 * Description: Checks if FeatureDAOReadOnly::isDeviceCapabilityInstalled works
392 * Expected: correct capabilities should be present
394 RUNNER_TEST(feature_dao_test_is_device_capab_installed)
397 std::list<const char *> preinstalled;
398 preinstalled.push_back("devicecap1");
399 preinstalled.push_back("devicecap2");
400 preinstalled.push_back("devicecap3");
401 preinstalled.push_back("devicecap4");
403 FOREACH(it, preinstalled)
404 RUNNER_ASSERT(FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
407 std::list<const char *> notinstalled;
408 notinstalled.push_back("notinstalled1");
409 notinstalled.push_back("plugin1");
410 notinstalled.push_back("");
411 notinstalled.push_back("ff");
413 FOREACH(it, notinstalled)
414 RUNNER_ASSERT(!FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
417 #undef RUNNER_ASSERT_WHAT_EQUALS