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_PluginDAO.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief This file contains tests for feature dao class.
24 #include <dpl/test/test_runner.h>
25 #include <dpl/foreach.h>
26 #include <dpl/exception.h>
27 #include <dpl/wrt-dao-rw/plugin_dao.h>
28 //#include <plugin_install/plugin_objects.h>
29 #include <dpl/wrt-dao-ro/wrt_db_types.h>
30 #include <dpl/log/log.h>
32 using namespace WrtDB;
34 #define RUNNER_ASSERT_WHAT_EQUALS(in, test) \
35 { std::string tmp(in); \
36 RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]"); }
38 RUNNER_TEST_GROUP_INIT(DAO)
41 * Name: plugin_dao_test_register_plugins
42 * Description: registers new plugin and check if it was correctly registered
43 * Expected: plugin should be correctly registered
45 RUNNER_TEST(plugin_dao_test_register_plugins)
48 std::string libraryPath("np1 lib_path");
49 std::string libraryName("np1");
51 PluginMetafileData pluginData;
52 pluginData.m_libraryName = libraryName;
54 PluginHandle handle = PluginDAO::registerPlugin(pluginData, libraryPath);
55 PluginDAO::setPluginInstallationStatus(
58 INSTALLATION_COMPLETED);
59 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
61 PluginDAO dao(handle);
63 tmp = dao.getLibraryPath(); //do for each
64 RUNNER_ASSERT_MSG(tmp == libraryPath, "Equals: " + tmp);
68 std::string libraryName("np2");
70 PluginMetafileData pluginData;
71 pluginData.m_libraryName = libraryName;
73 PluginHandle handle = PluginDAO::registerPlugin(pluginData, "");
74 PluginDAO::setPluginInstallationStatus(
77 INSTALLATION_COMPLETED);
78 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
80 PluginDAO dao(handle);
81 RUNNER_ASSERT(dao.getLibraryPath() == "");
86 * Name: plugin_dao_test_register_plugin_implemented_object
87 * Description: registers new PluginImplementedObject
88 * and check if it was correctly registered
89 * Expected: plugin dao shoudld be upodated with PluginImplementedObject
91 RUNNER_TEST(plugin_dao_test_register_plugin_implemented_object)
94 std::string libraryPath("np3 lib_path");
95 std::string libraryName("np3");
97 PluginMetafileData pluginData;
98 pluginData.m_libraryName = libraryName;
100 PluginHandle handle =
101 PluginDAO::registerPlugin(pluginData, libraryPath);
102 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
104 std::string object1("object1");
105 std::string object2("object2");
106 PluginDAO::registerPluginImplementedObject(object1, handle);
107 PluginDAO::registerPluginImplementedObject(object2, handle);
109 PluginHandle retHandle1 =
110 PluginDAO::getPluginHandleForImplementedObject(object1);
111 PluginHandle retHandle2 =
112 PluginDAO::getPluginHandleForImplementedObject(object1);
113 RUNNER_ASSERT(retHandle1 == handle);
114 RUNNER_ASSERT(retHandle2 == handle);
119 * Name: plugin_dao_test_register_plugin_implemented_object
120 * Description: registers dependecies for plugins and checks if they were saved
121 * Expected: registered dependecies should be returned from database
123 RUNNER_TEST(plugin_dao_test_register_library_dependencies)
126 std::string libraryPath("np4 lib_path");
127 std::string libraryName("np4");
129 PluginMetafileData pluginData;
130 pluginData.m_libraryName = libraryName;
132 PluginHandle handle =
133 PluginDAO::registerPlugin(pluginData, libraryPath);
134 PluginDAO::setPluginInstallationStatus(
137 INSTALLATION_COMPLETED);
138 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
140 PluginHandle depHandles[] = { 117, 119 };
142 PluginHandleSetPtr dependencies(new PluginHandleSet);
143 dependencies->insert(depHandles[1]);
144 dependencies->insert(depHandles[2]);
146 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
148 PluginDAO dao(handle);
149 PluginHandleSetPtr retDependencies;
150 retDependencies = dao.getLibraryDependencies();
153 retDependencies->size() == sizeof(depHandles) /
154 sizeof(depHandles[0]));
156 retDependencies->find(depHandles[1]) != retDependencies->end());
158 retDependencies->find(depHandles[2]) != retDependencies->end());
163 * Name: plugin_dao_test_register_required_object
164 * Description: registers required plugin objects for plugins and checks if they
166 * Expected: registered required plugin objects should be returned from database
168 RUNNER_TEST(plugin_dao_test_register_required_object)
171 std::string libraryPath("np5 lib_path");
172 std::string libraryName("np5");
174 PluginMetafileData pluginData;
175 pluginData.m_libraryName = libraryName;
177 PluginHandle handle =
178 PluginDAO::registerPlugin(pluginData, libraryPath);
179 PluginDAO::setPluginInstallationStatus(
182 INSTALLATION_COMPLETED);
183 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
185 const size_t numObjects = 2;
186 std::string objectReq[numObjects];
187 objectReq[0] = std::string("object1.req");
188 objectReq[1] = std::string("object2.req");
189 PluginDAO::registerPluginRequiredObject(objectReq[0], handle);
190 PluginDAO::registerPluginRequiredObject(objectReq[1], handle);
192 WrtDB::PluginObjectsDAO::ObjectsPtr objects =
193 PluginDAO::getRequiredObjectsForPluginHandle(handle);
195 RUNNER_ASSERT(objects->size() == numObjects
196 && objects->find(objectReq[0]) != objects->end()
197 && objects->find(objectReq[1]) != objects->end());
202 * Name: plugin_dao_test_is_library_installed
203 * Description: tests if plugin isntallation/registrartion works
204 * Expected: only registered plugins should be reported as installed
206 RUNNER_TEST(plugin_dao_test_is_library_installed)
210 std::list<const char *> preinstalled;
211 preinstalled.push_back("plugin1");
212 preinstalled.push_back("plugin2");
213 preinstalled.push_back("plugin3");
214 preinstalled.push_back("p4");
215 preinstalled.push_back("p5");
217 FOREACH(it, preinstalled)
218 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled(*it),
219 std::string("Not found: ") + *it);
225 PluginDAO::isPluginInstalled("not_installed1") == false,
226 "Found not_installed1");
227 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p 4") == false,
229 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("") == false,
231 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p33") == false,
233 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("feature1") == false,
239 * Name: plugin_dao_test_get_plugin_handle_list
240 * Description: test of returning plugin handle list
241 * Expected: returned list should be no less than number of registered plugins
243 RUNNER_TEST(plugin_dao_test_get_plugin_handle_list)
245 PluginHandleList handles = PluginDAO::getPluginHandleList();
246 RUNNER_ASSERT(handles.size() >= 5);
250 * Name: plugin_dao_test_constructor_name
251 * Description: tests construction of plugin dao based on plugin name
252 * Expected: Instance of dao should be constructed only
253 * if there is given plugin in database
255 RUNNER_TEST(plugin_dao_test_constructor_name)
259 std::list<const char *> preinstalled;
260 preinstalled.push_back("plugin1");
261 preinstalled.push_back("plugin2");
262 preinstalled.push_back("plugin3");
263 preinstalled.push_back("p4");
264 preinstalled.push_back("p5");
266 FOREACH(it, preinstalled)
269 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), *it);
275 std::list<const char *> not_installed;
276 not_installed.push_back("plugin 1");
277 not_installed.push_back("");
278 not_installed.push_back("p 3");
280 FOREACH(it, not_installed)
285 RUNNER_ASSERT_MSG(false, "should not be found");
287 Catch(PluginDAO::Exception::PluginNotExist) {
295 * Name: plugin_dao_test_get_plugin_properties
296 * Description: tests reading plugin properties from database
297 * Expected: Data, inserted into database, should be accessible via dao
299 RUNNER_TEST(plugin_dao_test_get_plugin_properties)
303 RUNNER_ASSERT(dao.getPluginHandle() == 4);
304 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p4");
305 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p4");
310 RUNNER_ASSERT(dao.getPluginHandle() == 5);
311 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p5");
312 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p5");
317 RUNNER_ASSERT(dao.getPluginHandle() == 2);
318 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin2");
319 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_plugin2");
324 RUNNER_ASSERT(dao.getPluginHandle() == 1);
325 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin1");
326 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "");
331 * Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_1
332 * Description: tests receiving from dao Implemented Objects
333 * Expected: returned object is size 0
335 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_1)
338 const int handle = 1;
339 PluginDAOReadOnly dao(handle);
340 auto dbHandle = dao.getPluginHandle();
341 RUNNER_ASSERT(dbHandle == handle);
342 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
344 RUNNER_ASSERT(objects.empty());
349 * Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_2
350 * Description: tests receiving from dao Implemented Objects
351 * Expected: returned object is size as it was inserted
353 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_2)
356 std::set< std::string > preinstalled = {
360 PluginDAOReadOnly dao(2);
361 auto dbHandle = dao.getPluginHandle();
362 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
364 //LogError("\n" << objects.size() << " " << preinstalled.size() <<
367 RUNNER_ASSERT(objects.size() == preinstalled.size());
369 FOREACH(dbObject, objects)
371 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
377 * Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_3
378 * Description: tests receiving from dao Implemented Objects
379 * Expected: returned objects list has preinserted object
381 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_3)
384 std::set< std::string > preinstalled = {
388 PluginDAOReadOnly dao(3);
389 auto dbHandle = dao.getPluginHandle();
390 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
391 RUNNER_ASSERT(objects.size() == preinstalled.size());
393 FOREACH(dbObject, objects)
395 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
401 * Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_4
402 * Description: tests receiving from dao Implemented Objects
403 * Expected: returned objects list has all preinserted objects
405 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_4)
408 std::set< std::string > preinstalled = {
414 PluginDAOReadOnly dao(4);
415 auto dbHandle = dao.getPluginHandle();
416 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
417 RUNNER_ASSERT(objects.size() == preinstalled.size());
419 FOREACH(dbObject, objects)
421 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
427 * Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_5
428 * Description: tests receiving from dao Implemented Objects
429 * Expected: returned objects list do not have object that was not inserted
431 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_5)
434 std::set< std::string > preinstalled = {
438 PluginDAOReadOnly dao(5);
439 auto dbHandle = dao.getPluginHandle();
440 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
441 RUNNER_ASSERT(objects.size() == preinstalled.size());
443 FOREACH(dbObject, objects)
445 RUNNER_ASSERT(preinstalled.find(*dbObject) == preinstalled.end());
450 #undef RUNNER_ASSERT_WHAT_EQUALS