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 Expected: registrartion should succeed
42 RUNNER_TEST(feature_dao_test_register_features)
44 PluginHandle plHandle;
46 std::string libraryPath("nfp1 lib_path");
47 std::string libraryName("nfp1");
49 PluginMetafileData pluginData;
50 pluginData.m_libraryName = libraryName;
52 plHandle = PluginDAO::registerPlugin(pluginData, libraryPath);
53 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
55 FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
56 PluginMetafileData::Feature f;
57 f.m_name = std::string("new_f1");
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");
64 FeatureDAOReadOnly dao(handle);
66 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(),"new_f1");
67 plHandle = dao.GetPluginHandle();
71 FeatureHandleList old = FeatureDAOReadOnly::GetHandleList();
73 PluginMetafileData::Feature f;
74 f.m_name = std::string("new_f2");
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");
81 FeatureDAOReadOnly dao(handle);
83 RUNNER_ASSERT_MSG(plHandle == dao.GetPluginHandle(),
84 "New plugin registered (should be old used)");
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
93 RUNNER_TEST(feature_dao_test_get_feature_properties)
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(), "");
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");
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");
118 Name: feature_dao_test_feature_constructor_name
124 RUNNER_TEST(feature_dao_test_feature_constructor_name)
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");
132 FOREACH(it, preinstalled)
134 FeatureDAOReadOnly dao(*it);
135 RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), *it);
138 //TODO check exception that may occur (feature does not exist)
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
146 RUNNER_TEST(feature_dao_test_feature_handle_list)
148 FeatureHandleList handles = FeatureDAOReadOnly::GetHandleList();
149 RUNNER_ASSERT(handles.size() >= 4);
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
157 RUNNER_TEST(feature_dao_test_is_feature_installed)
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");
167 FOREACH(it, preinstalled)
168 RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(*it));
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);
181 Name: feature_dao_test_get_device_capab
187 RUNNER_TEST(feature_dao_test_get_device_capab)
194 f.setName("new_dev_f4");
195 f.setLibraryName("new_dev_f4 lib_name");
197 FeatureDAOReadOnly::DeviceCapabilitiesList devList;
198 devList.insert("new_dev_f4 devcap1");
199 devList.insert("new_dev_f4 devcap2");
202 f.addDeviceCapability(*it);
204 FeatureHandle handle = FeatureDAO::RegisterFeature(f,"new_dev_f4 path");
206 FeatureDAOReadOnly dao(handle);
208 FeatureDAOReadOnly::DeviceCapabilitiesList gotList =
209 dao.GetDeviceCapabilities();
210 RUNNER_ASSERT_MSG(gotList.size() == devList.size(),
217 Name: feature_dao_test_is_device_capab_installed
218 Description: Checks if FeatureDAOReadOnly::isDeviceCapabilityInstalled works correctly.
219 Expected: correct capabilities should be present
221 RUNNER_TEST(feature_dao_test_is_device_capab_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");
230 FOREACH(it, preinstalled)
231 RUNNER_ASSERT(FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
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");
240 FOREACH(it, notinstalled)
241 RUNNER_ASSERT(!FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it));
244 #undef RUNNER_ASSERT_WHAT_EQUALS