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(handle,PluginDAO::INSTALLATION_COMPLETED);
56 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
58 PluginDAO dao(handle);
60 tmp = dao.getLibraryPath(); //do for each
61 RUNNER_ASSERT_MSG(tmp == libraryPath, "Equals: " + tmp);
65 std::string libraryName("np2");
67 PluginMetafileData pluginData;
68 pluginData.m_libraryName = libraryName;
70 PluginHandle handle = PluginDAO::registerPlugin(pluginData, "");
71 PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED);
72 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
74 PluginDAO dao(handle);
75 RUNNER_ASSERT(dao.getLibraryPath() == "");
80 Name: plugin_dao_test_register_plugin_implemented_object
81 Description: registers new PluginImplementedObject
82 and check if it was correctly registered
83 Expected: plugin dao shoudld be upodated with PluginImplementedObject
85 RUNNER_TEST(plugin_dao_test_register_plugin_implemented_object)
88 std::string libraryPath("np3 lib_path");
89 std::string libraryName("np3");
91 PluginMetafileData pluginData;
92 pluginData.m_libraryName = libraryName;
95 PluginDAO::registerPlugin(pluginData, libraryPath);
96 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
98 std::string object1("object1");
99 std::string object2("object2");
100 PluginDAO::registerPluginImplementedObject(object1, handle);
101 PluginDAO::registerPluginImplementedObject(object2, handle);
103 PluginHandle retHandle1 =
104 PluginDAO::getPluginHandleForImplementedObject(object1);
105 PluginHandle retHandle2 =
106 PluginDAO::getPluginHandleForImplementedObject(object1);
107 RUNNER_ASSERT(retHandle1 == handle);
108 RUNNER_ASSERT(retHandle2 == handle);
113 Name: plugin_dao_test_register_plugin_implemented_object
114 Description: registers dependecies for plugins and checks if they were saved
115 Expected: registered dependecies should be returned from database
117 RUNNER_TEST(plugin_dao_test_register_library_dependencies)
120 std::string libraryPath("np4 lib_path");
121 std::string libraryName("np4");
123 PluginMetafileData pluginData;
124 pluginData.m_libraryName = libraryName;
126 PluginHandle handle =
127 PluginDAO::registerPlugin(pluginData, libraryPath);
128 PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED);
129 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
131 PluginHandle depHandles[] = {117, 119};
133 PluginHandleSetPtr dependencies(new PluginHandleSet);
134 dependencies->insert(depHandles[1]);
135 dependencies->insert(depHandles[2]);
137 PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
139 PluginDAO dao(handle);
140 PluginHandleSetPtr retDependencies;
141 retDependencies = dao.getLibraryDependencies();
144 retDependencies->size()==sizeof(depHandles)/sizeof(depHandles[0]));
146 retDependencies->find(depHandles[1]) != retDependencies->end());
148 retDependencies->find(depHandles[2]) != retDependencies->end());
153 Name: plugin_dao_test_register_required_object
154 Description: registers required plugin objects for plugins and checks if they were saved
155 Expected: registered required plugin objects should be returned from database
157 RUNNER_TEST(plugin_dao_test_register_required_object)
160 std::string libraryPath("np5 lib_path");
161 std::string libraryName("np5");
163 PluginMetafileData pluginData;
164 pluginData.m_libraryName = libraryName;
166 PluginHandle handle =
167 PluginDAO::registerPlugin(pluginData, libraryPath);
168 PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED);
169 RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true);
171 const size_t numObjects =2;
172 std::string objectReq [numObjects];
173 objectReq[0] = std::string("object1.req");
174 objectReq[1] = std::string("object2.req");
175 PluginDAO::registerPluginRequiredObject(objectReq[0], handle);
176 PluginDAO::registerPluginRequiredObject(objectReq[1], handle);
178 WrtDB::PluginObjectsDAO::ObjectsPtr objects =
179 PluginDAO::getRequiredObjectsForPluginHandle(handle);
181 RUNNER_ASSERT(objects->size() == numObjects
182 && objects->find(objectReq[0]) != objects->end()
183 && objects->find(objectReq[1]) != objects->end());
188 Name: plugin_dao_test_is_library_installed
189 Description: tests if plugin isntallation/registrartion works
190 Expected: only registered plugins should be reported as installed
192 RUNNER_TEST(plugin_dao_test_is_library_installed)
196 std::list<const char *> preinstalled;
197 preinstalled.push_back("plugin1");
198 preinstalled.push_back("plugin2");
199 preinstalled.push_back("plugin3");
200 preinstalled.push_back("p4");
201 preinstalled.push_back("p5");
203 FOREACH(it, preinstalled)
204 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled(*it),
205 std::string("Not found: ") + *it);
211 PluginDAO::isPluginInstalled("not_installed1") == false,
212 "Found not_installed1");
213 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p 4") == false,
215 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("") == false,
217 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p33") == false,
219 RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("feature1") == false,
225 Name: plugin_dao_test_get_plugin_handle_list
226 Description: test of returning plugin handle list
227 Expected: returned list should be no less than number of registered plugins
229 RUNNER_TEST(plugin_dao_test_get_plugin_handle_list)
231 PluginHandleList handles = PluginDAO::getPluginHandleList();
232 RUNNER_ASSERT(handles.size() >= 5);
236 Name: plugin_dao_test_constructor_name
237 Description: tests construction of plugin dao based on plugin name
238 Expected: Instance of dao should be constructed only
239 if there is given plugin in database
241 RUNNER_TEST(plugin_dao_test_constructor_name)
245 std::list<const char *> preinstalled;
246 preinstalled.push_back("plugin1");
247 preinstalled.push_back("plugin2");
248 preinstalled.push_back("plugin3");
249 preinstalled.push_back("p4");
250 preinstalled.push_back("p5");
252 FOREACH(it, preinstalled)
255 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), *it);
261 std::list<const char *> not_installed;
262 not_installed.push_back("plugin 1");
263 not_installed.push_back("");
264 not_installed.push_back("p 3");
266 FOREACH(it, not_installed)
271 RUNNER_ASSERT_MSG(false, "should not be found");
273 Catch (PluginDAO::Exception::PluginNotExist) {
282 Name: plugin_dao_test_get_plugin_properties
283 Description: tests reading plugin properties from database
284 Expected: Data, inserted into database, should be accessible via dao
286 RUNNER_TEST(plugin_dao_test_get_plugin_properties)
290 RUNNER_ASSERT(dao.getPluginHandle() == 4);
291 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p4");
292 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p4");
297 RUNNER_ASSERT(dao.getPluginHandle() == 5);
298 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p5");
299 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p5");
304 RUNNER_ASSERT(dao.getPluginHandle() == 2);
305 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin2");
306 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_plugin2");
311 RUNNER_ASSERT(dao.getPluginHandle() == 1);
312 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin1");
313 RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "");
318 Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_1
319 Description: tests receiving from dao Implemented Objects
320 Expected: returned object is size 0
322 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_1)
325 const int handle = 1;
326 PluginDAOReadOnly dao(handle);
327 auto dbHandle = dao.getPluginHandle();
328 RUNNER_ASSERT(dbHandle == handle);
329 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
331 RUNNER_ASSERT(objects.size() == 0);
336 Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_2
337 Description: tests receiving from dao Implemented Objects
338 Expected: returned object is size as it was inserted
340 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_2)
343 std::set< std::string > preinstalled =
348 PluginDAOReadOnly dao(2);
349 auto dbHandle = dao.getPluginHandle();
350 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
352 //LogError("\n" << objects.size() << " " << preinstalled.size() << "\n");
354 RUNNER_ASSERT(objects.size() == preinstalled.size());
356 FOREACH(dbObject, objects)
358 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
364 Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_3
365 Description: tests receiving from dao Implemented Objects
366 Expected: returned objects list has preinserted object
368 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_3)
371 std::set< std::string > preinstalled =
376 PluginDAOReadOnly dao(3);
377 auto dbHandle = dao.getPluginHandle();
378 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
379 RUNNER_ASSERT(objects.size() == preinstalled.size());
381 FOREACH(dbObject, objects)
383 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
389 Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_4
390 Description: tests receiving from dao Implemented Objects
391 Expected: returned objects list has all preinserted objects
393 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_4)
396 std::set< std::string > preinstalled =
403 PluginDAOReadOnly dao(4);
404 auto dbHandle = dao.getPluginHandle();
405 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
406 RUNNER_ASSERT(objects.size() == preinstalled.size());
408 FOREACH(dbObject, objects)
410 RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end());
416 Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_5
417 Description: tests receiving from dao Implemented Objects
418 Expected: returned objects list do not have object that was not inserted
420 RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_5)
423 std::set< std::string > preinstalled =
428 PluginDAOReadOnly dao(5);
429 auto dbHandle = dao.getPluginHandle();
430 auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle);
431 RUNNER_ASSERT(objects.size() == preinstalled.size());
433 FOREACH(dbObject, objects)
435 RUNNER_ASSERT(preinstalled.find(*dbObject) == preinstalled.end());
441 #undef RUNNER_ASSERT_WHAT_EQUALS