From af6f2ed52016357933a8098e4e530ea46537649d Mon Sep 17 00:00:00 2001 From: Zbigniew Kostrzewa Date: Thu, 6 Dec 2012 18:22:13 +0100 Subject: [PATCH] Add tests - DAO. [Issue#] N/A [Feature] Add DAO tests back to wrt-commons. Build tests conditionally. [Problem] N/A [Cause] Unit tests should reside in the same repositories the code they test. Tests should be built only on explicit request. [Solution] Add DAO tests to wrt-commons repository. Build tests only when option WITH_TESTS is set. [SCMRequest] gbs >= 0.12 [Verification] REQUIRES: gbs >= 0.12 1. Remove `wrt-extra` RPM package from the device, if present. 2. Make sure `wrt-tests-dao` binary is not present on the device. 3. Build repository using gbs with option `--define "WITH_TESTS OFF"`. 4. Check if subdirectory `tests/` was included in the build process (it should NOT be included) and if `wrt-tests-dao` is included in the RPM package (it should NOT be included). 5. Install RPM package created in step 3. 6. Check if `wrt-tests-dao` binary is present on the device (it should NOT be present). 7. Build repository using gbs with option `--define "WITH_TESTS ON"`. 8. Check if subdirectory `tests/` was included in build process (it should be included) and if `wrt-tests-dao` is included in the RPM package (it should be included). 9. Install RPM package created in step 7. 10. Run `wrt-tests-dao` test suite. Change-Id: I5dbe07a30f9ab1d2c3f106e704a4d9254f5e493f --- CMakeLists.txt | 6 + packaging/wrt-commons.spec | 6 +- tests/CMakeLists.txt | 7 + tests/CMakeUtils.txt | 168 +++++++ tests/dao/CMakeLists.txt | 37 ++ tests/dao/README | 11 + tests/dao/TestCases_FeatureDAO.cpp | 244 +++++++++ tests/dao/TestCases_GlobalDAO.cpp | 111 ++++ tests/dao/TestCases_PluginDAO.cpp | 441 ++++++++++++++++ tests/dao/TestCases_PropertyDAO.cpp | 163 ++++++ tests/dao/TestCases_WidgetDAO.cpp | 919 ++++++++++++++++++++++++++++++++++ tests/dao/tests_dao.cpp | 49 ++ tests/dao/wrt_dao_tests_prepare_db.sh | 129 +++++ 13 files changed, 2288 insertions(+), 3 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/CMakeUtils.txt create mode 100644 tests/dao/CMakeLists.txt create mode 100644 tests/dao/README create mode 100644 tests/dao/TestCases_FeatureDAO.cpp create mode 100644 tests/dao/TestCases_GlobalDAO.cpp create mode 100644 tests/dao/TestCases_PluginDAO.cpp create mode 100644 tests/dao/TestCases_PropertyDAO.cpp create mode 100644 tests/dao/TestCases_WidgetDAO.cpp create mode 100644 tests/dao/tests_dao.cpp create mode 100755 tests/dao/wrt_dao_tests_prepare_db.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 06da368..084e4c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,8 @@ ELSE(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling") MESSAGE(STATUS "Logging disabled for DPL") ENDIF(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling") +OPTION(WITH_TESTS "Build tests" OFF) + # Compiler flags SET(CMAKE_C_FLAGS_PROFILING "-O2") SET(CMAKE_CXX_FLAGS_PROFILING "-O2 -std=c++0x") @@ -105,6 +107,7 @@ MESSAGE(STATUS "CMAKE_COMPILER_IS_GNUCC: " ${CMAKE_COMPILER_IS_GNUCC}) MESSAGE(STATUS "CMAKE_COMPILER_IS_GNUCXX : " ${CMAKE_COMPILER_IS_GNUCXX}) MESSAGE(STATUS "CMAKE_AR: " ${CMAKE_AR}) MESSAGE(STATUS "CMAKE_RANLIB: " ${CMAKE_RANLIB}) +MESSAGE(STATUS "WITH_TESTS: " ${WITH_TESTS}) MESSAGE(STATUS "========================================") # Build 3rd party libraries first @@ -201,3 +204,6 @@ ADD_SUBDIRECTORY(modules) ADD_SUBDIRECTORY(build) ADD_SUBDIRECTORY(etc) +IF(WITH_TESTS) + ADD_SUBDIRECTORY(tests) +ENDIF(WITH_TESTS) diff --git a/packaging/wrt-commons.spec b/packaging/wrt-commons.spec index 41b549c..20c253f 100644 --- a/packaging/wrt-commons.spec +++ b/packaging/wrt-commons.spec @@ -44,7 +44,8 @@ export LDFLAGS+="-Wl,--rpath=%{_libdir} -Wl,--hash-style=both -Wl,--as-needed" cmake . -DVERSION=%{version} \ -DDPL_LOG="OFF" \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} + -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} \ + %{?WITH_TESTS:-DWITH_TESTS=%WITH_TESTS} make %{?jobs:-j%jobs} %install @@ -125,9 +126,8 @@ echo "[WRT] wrt-commons postinst done ..." %{_libdir}/*.so %{_libdir}/*.so.* /usr/share/wrt-engine/* -%attr(775,root,root) %{_bindir}/wrt_commons_reset_db.sh -%attr(775,root,root) %{_bindir}/wrt_commons_create_clean_db.sh %{_datadir}/license/%{name} +%attr(755,root,root) %{_bindir}/* %files devel %{_includedir}/dpl-efl/* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..be69d36 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +INCLUDE(CMakeUtils.txt) + +WRT_ADD_INTERNAL_DEPENDENCIES( + ${TARGET_DPL_TEST_ENGINE_EFL} +) + +ADD_SUBDIRECTORY(dao) diff --git a/tests/CMakeUtils.txt b/tests/CMakeUtils.txt new file mode 100644 index 0000000..8508178 --- /dev/null +++ b/tests/CMakeUtils.txt @@ -0,0 +1,168 @@ +# @file CMakeUtils.txt +# @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) +# @author Pawel Sikorski (p.sikorski@samsung.com) +# @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) +# @version 1.0 +# @brief +# + +# +# Discovers target's INCLUDE_DIRECTORIES and LINK_DIRECTORIES. +# This is done by retrieving the directory target was built in and +# fetching appropriate properties of that directory. +FUNCTION(WRT_INTROSPECT_TARGET PREFIX TARGET_NAME) + GET_TARGET_PROPERTY(LOCATION ${TARGET_NAME} LOCATION) + IF(${LOCATION} STREQUAL "LOCATION-NOTFOUND") + MESSAGE(FATAL_ERROR "Target '${TARGET_NAME}' introspection failed") + ELSE(${LOCATION} STREQUAL "LOCATION-NOTFOUND") + STRING(FIND ${LOCATION} "/" LAST_SLASH_POSITION REVERSE) + STRING(SUBSTRING ${LOCATION} 0 ${LAST_SLASH_POSITION} LOCATION) + + GET_DIRECTORY_PROPERTY(INCLUDE_DIRS DIRECTORY ${LOCATION} INCLUDE_DIRECTORIES) + SET("${PREFIX}_INCLUDE_DIRS" ${INCLUDE_DIRS} PARENT_SCOPE) + + GET_DIRECTORY_PROPERTY(LIBRARY_DIRS DIRECTORY ${LOCATION} LINK_DIRECTORIES) + SET("${PREFIX}_LIBRARY_DIRS" ${LIBRARY_DIRS} PARENT_SCOPE) + ENDIF(${LOCATION} STREQUAL "LOCATION-NOTFOUND") +ENDFUNCTION(WRT_INTROSPECT_TARGET) + +# +# Replacement functions for standard (w/o "WRT_" prefix) CMake functions. +# They store supplied arguments in global properties to assign them to tests. +# Anything added with this functions is used by all targets that are built with +# WRT_TEST_BUILD function. + +# +# Appends directories to global property TESTS_INCLUDE_DIRS which is +# then read by WRT_TEST_BUILD and its content is forwarded to +# command INCLUDE_DIRECTORIES() (for all targets). +FUNCTION(WRT_INCLUDE_DIRECTORIES) + SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_INCLUDE_DIRS ${ARGV}) +ENDFUNCTION(WRT_INCLUDE_DIRECTORIES) + +# +# Appends directories to global property TESTS_LIBRARY_DIRS which is +# then read by WRT_TEST_BUILD and its content is forwarded to +# command LINK_DIRECTORIES() (for all targets). +FUNCTION(WRT_LINK_DIRECTORIES) + SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARY_DIRS ${ARGV}) +ENDFUNCTION(WRT_LINK_DIRECTORIES) + +# +# Appends directories to global property TESTS_LIBRARIES which is +# then read by WRT_TEST_BUILD and its content is forwarded to +# command TARGET_LINK_LIBRARIES() (for all targets). +FUNCTION(WRT_TARGET_LINK_LIBRARIES) + SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARIES ${ARGV}) +ENDFUNCTION(WRT_TARGET_LINK_LIBRARIES) + +# +# Convenience method that fills TESTS_INCLUDE_DIRS, TESTS_LIBRARY_DIRS +# and TESTS_LIBRARIES with values discovered from introspecting supplied +# targets. +# Function takes arbitrary number of targets. +FUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES) + FOREACH(DEPENDENCY ${ARGV}) + WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY}) + WRT_INCLUDE_DIRECTORIES(${prefix_INCLUDE_DIRS}) + WRT_LINK_DIRECTORIES(${prefix_LIBRARY_DIRS}) + WRT_TARGET_LINK_LIBRARIES(${DEPENDENCY}) + ENDFOREACH(DEPENDENCY) +ENDFUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES) + + +# +# Replacement functions for standard (w/o "WRT_" prefix) CMake functions. +# They store supplied arguments in global properties to assign them to specific +# tests. Properties names are based on the test target name. +# Anything added with this functions is used only by the specified target that +# is built with WRT_TEST_BUILD function. + +# +# Appends directories to global property ${TARGET_NAME}_INCLUDE_DIRS +# which is then read by WRT_TEST_BUILD and its content is forwarded to +# command INCLUDE_DIRECTORIES() (for specified target). +FUNCTION(WRT_TEST_INCLUDE_DIRECTORIES TARGET_NAME) + SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_INCLUDE_DIRS ${ARGN}) +ENDFUNCTION(WRT_TEST_INCLUDE_DIRECTORIES) + +# +# Appends directories to global property ${TARGET_NAME}_LIBRARY_DIRS +# which is then read by WRT_TEST_BUILD and its content is forwarded to +# command LINK_DIRECTORIES() (for specified target). +FUNCTION(WRT_TEST_LINK_DIRECTORIES TARGET_NAME) + SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARY_DIRS ${ARGN}) +ENDFUNCTION(WRT_TEST_LINK_DIRECTORIES) + +# +# Appends directories to global property ${TARGET_NAME}_LIBRARIES +# which is then read by WRT_TEST_BUILD and its content is forwarded to +# command TARGET_LINK_LIBRARIES() (for specified target). +FUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES TARGET_NAME) + SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARIES ${ARGN}) +ENDFUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES) + +# +# Convenience method that fills ${TARGET_NAME}_INCLUDE_DIRS, +# ${TARGET_NAME}_LIBRARY_DIRS and ${TARGET_NAME}_LIBRARIES with +# values discovered from introspecting supplied targets. +# Function takes arbitrary number of targets. +FUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES TARGET_NAME) + FOREACH(DEPENDENCY ${ARGN}) + WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY}) + WRT_TEST_INCLUDE_DIRECTORIES(${TARGET_NAME} ${prefix_INCLUDE_DIRS}) + WRT_TEST_LINK_DIRECTORIES(${TARGET_NAME} ${prefix_LIBRARY_DIRS}) + WRT_TEST_TARGET_LINK_LIBRARIES(${TARGET_NAME} ${DEPENDENCY}) + ENDFOREACH(DEPENDENCY) +ENDFUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES) + +# Functions used to build test targets (proper sources, includes, libs are +# added automatically) +FUNCTION(WRT_TEST_BUILD TARGET_NAME) + SET(SOURCES "${ARGN}") + ADD_EXECUTABLE("${TARGET_NAME}" + ${WRT_DETAIL_SOURCES} + ${SOURCES} + ) + # get include dirs global property + GET_PROPERTY(INCLUDE_DIRS GLOBAL PROPERTY TESTS_INCLUDE_DIRS) + GET_PROPERTY(TEST_INCLUDE_DIRS GLOBAL PROPERTY ${TARGET_NAME}_INCLUDE_DIRS) + INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR} + ${INCLUDE_DIRS} + ${TEST_INCLUDE_DIRS} + ) + # get library dirs global property + GET_PROPERTY(LIBRARY_DIRS GLOBAL PROPERTY TESTS_LIBRARY_DIRS) + GET_PROPERTY(TEST_LIBRARY_DIRS GLOBAL PROPERTY ${TARGET_NAME}_LIBRARY_DIRS) + LINK_DIRECTORIES( + ${COMMON_LIBRARY_DIRS} + ${LIBRARY_DIRS} + ${TEST_LIBRARY_DIRS} + ) + # get link libraries global property + GET_PROPERTY(LINK_LIBRARIES GLOBAL PROPERTY TESTS_LIBRARIES) + GET_PROPERTY(TEST_LIBRARIES GLOBAL PROPERTY ${TARGET_NAME}_LIBRARIES) + TARGET_LINK_LIBRARIES("${TARGET_NAME}" + ${COMMON_LIBRARIES} + ${LINK_LIBRARIES} + ${TEST_LIBRARIES} + ) +ENDFUNCTION(WRT_TEST_BUILD) + +FUNCTION(WRT_TEST_INSTALL) + SET_TARGET_PROPERTIES(${ARGV} PROPERTIES + BUILD_WITH_INSTALL_RPATH ON + INSTALL_RPATH_USE_LINK_PATH ON + ) + INSTALL(TARGETS ${ARGV} + DESTINATION bin + PERMISSIONS OWNER_READ + OWNER_WRITE + OWNER_EXECUTE + GROUP_READ + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE + ) +ENDFUNCTION(WRT_TEST_INSTALL) diff --git a/tests/dao/CMakeLists.txt b/tests/dao/CMakeLists.txt new file mode 100644 index 0000000..8b0a964 --- /dev/null +++ b/tests/dao/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# @author Pawel Sikorski (p.sikorski@samsung.com) +# @version 1.0 +# @brief +# + +# common part +FILE(GLOB DAO_TESTS_SOURCES "${PROJECT_SOURCE_DIR}/tests/dao/*DAO.cpp") + + +# target wrt-tests-dao +SET(TARGET_DAO_TEST "wrt-tests-dao") +WRT_TEST_INCLUDE_DIRECTORIES(${TARGET_DAO_TEST} ${PROJECT_SOURCE_DIR}/modules/support/) +WRT_TEST_ADD_INTERNAL_DEPENDENCIES(${TARGET_DAO_TEST} ${TARGET_WRT_DAO_RW_LIB}) +WRT_TEST_BUILD(${TARGET_DAO_TEST} ${DAO_TESTS_SOURCES} tests_dao.cpp) +WRT_TEST_INSTALL(${TARGET_DAO_TEST}) + + +# common installed files +INSTALL(PROGRAMS + ${PROJECT_SOURCE_DIR}/tests/dao/wrt_dao_tests_prepare_db.sh + DESTINATION bin + ) diff --git a/tests/dao/README b/tests/dao/README new file mode 100644 index 0000000..6c60a17 --- /dev/null +++ b/tests/dao/README @@ -0,0 +1,11 @@ +Wrt DAO +System tests. Tests database access layer: widgets information database, global configuration, plugins. +Binary file: wrt-tests-dao. Uses our test framework. Allows to use different types of output. Text output shows results on console - green passed. +To run: +1. Install wrt-extra on target +2. Run wrt-tests-dao --output=text + +Automatic: YES +Included in Daily Build: YES (http://build01.sprc.samsung.pl/browse/LINUXNGWAP-INT) +Included in Gerrit Builds: YES (http://build01.sprc.samsung.pl/browse/LINUXNGWAP-GERRIT) +Number of test cases: 45 \ No newline at end of file diff --git a/tests/dao/TestCases_FeatureDAO.cpp b/tests/dao/TestCases_FeatureDAO.cpp new file mode 100644 index 0000000..26ea2bd --- /dev/null +++ b/tests/dao/TestCases_FeatureDAO.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file TestCases_FeatureDAO.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for feature dao class. + */ + +#include +#include +#include +#include +#include + +using namespace WrtDB; + +#define RUNNER_ASSERT_WHAT_EQUALS(in, test) \ + {std::string tmp(in); \ + RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");} + +RUNNER_TEST_GROUP_INIT(DAO) + +/* +Name: feature_dao_test_register_features +Description: Checks if plugin registeration performs features registration +Expected: registrartion should succeed +*/ +RUNNER_TEST(feature_dao_test_register_features) +{ + PluginHandle plHandle; + { + std::string libraryPath("nfp1 lib_path"); + std::string libraryName("nfp1"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + plHandle = PluginDAO::registerPlugin(pluginData, libraryPath); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + FeatureHandleList old = FeatureDAOReadOnly::GetHandleList(); + PluginMetafileData::Feature f; + f.m_name = std::string("new_f1"); + + FeatureHandle handle = FeatureDAO::RegisterFeature(f,plHandle); + RUNNER_ASSERT_MSG(handle != -1, "Already registered"); + RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(), + "New feature should be saved"); + + FeatureDAOReadOnly dao(handle); + + RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(),"new_f1"); + plHandle = dao.GetPluginHandle(); + } + + { + FeatureHandleList old = FeatureDAOReadOnly::GetHandleList(); + + PluginMetafileData::Feature f; + f.m_name = std::string("new_f2"); + + FeatureHandle handle = FeatureDAO::RegisterFeature(f,plHandle); + RUNNER_ASSERT_MSG(handle != -1, "Already registered"); + RUNNER_ASSERT_MSG(old.size() < FeatureDAOReadOnly::GetHandleList().size(), + "New feature should be saved"); + + FeatureDAOReadOnly dao(handle); + + RUNNER_ASSERT_MSG(plHandle == dao.GetPluginHandle(), + "New plugin registered (should be old used)"); + } +} + +/* +Name: feature_dao_test_get_feature_properties +Description: Checks properties of inserted features +Expected: properties of features should match values inserted to database directly +*/ +RUNNER_TEST(feature_dao_test_get_feature_properties) +{ + { + FeatureDAOReadOnly dao("feature1"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature1"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "plugin1"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), ""); + } + + { + FeatureDAOReadOnly dao("feature2"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature2"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4"); + } + + { + FeatureDAOReadOnly dao("feature3"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), "feature3"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryName(), "p4"); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetLibraryPath(), "path_to_p4"); + } +} + +/* +Name: feature_dao_test_feature_constructor_name +Description: - +Expected: - + +TODO: test +*/ +RUNNER_TEST(feature_dao_test_feature_constructor_name) +{ + std::list preinstalled; + preinstalled.push_back("feature1"); + preinstalled.push_back("feature2"); + preinstalled.push_back("feature3"); + preinstalled.push_back("feature4"); + + FOREACH(it, preinstalled) + { + FeatureDAOReadOnly dao(*it); + RUNNER_ASSERT_WHAT_EQUALS(dao.GetName(), *it); + } + + //TODO check exception that may occur (feature does not exist) +} + +/* +Name: feature_dao_test_feature_handle_list +Description: Checks if list of installed features is returend correctly +Expected: list size should be at last equal number of preinserted features +*/ +RUNNER_TEST(feature_dao_test_feature_handle_list) +{ + FeatureHandleList handles = FeatureDAOReadOnly::GetHandleList(); + RUNNER_ASSERT(handles.size() >= 4); +} + +/* +Name: feature_dao_test_is_feature_installed +Description: Checks if installed features are showed correctly. +Expected: correct installed features should be present +*/ +RUNNER_TEST(feature_dao_test_is_feature_installed) +{ + //installed + { + std::list preinstalled; + preinstalled.push_back("feature1"); + preinstalled.push_back("feature2"); + preinstalled.push_back("feature3"); + preinstalled.push_back("feature4"); + + FOREACH(it, preinstalled) + RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled(*it)); + } + + //not installed + { + RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("not_installed1")==false); + RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("plugin1") == false); + RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("") == false); + RUNNER_ASSERT(FeatureDAOReadOnly::isFeatureInstalled("ff") == false); + } +} + +/* +Name: feature_dao_test_get_device_capab +Description: - +Expected: - + +TODO: fix test +*/ +RUNNER_TEST(feature_dao_test_get_device_capab) +{ +#if 0 + //TODO do more tests + + {//check deviceCaps + Feature f; + f.setName("new_dev_f4"); + f.setLibraryName("new_dev_f4 lib_name"); + + FeatureDAOReadOnly::DeviceCapabilitiesList devList; + devList.insert("new_dev_f4 devcap1"); + devList.insert("new_dev_f4 devcap2"); + + FOREACH(it, devList) + f.addDeviceCapability(*it); + + FeatureHandle handle = FeatureDAO::RegisterFeature(f,"new_dev_f4 path"); + + FeatureDAOReadOnly dao(handle); + + FeatureDAOReadOnly::DeviceCapabilitiesList gotList = + dao.GetDeviceCapabilities(); + RUNNER_ASSERT_MSG(gotList.size() == devList.size(), + "deviceCaps wrong"); + } +#endif +} + +/* +Name: feature_dao_test_is_device_capab_installed +Description: Checks if FeatureDAOReadOnly::isDeviceCapabilityInstalled works correctly. +Expected: correct capabilities should be present +*/ +RUNNER_TEST(feature_dao_test_is_device_capab_installed) +{ + //installed + std::list preinstalled; + preinstalled.push_back("devicecap1"); + preinstalled.push_back("devicecap2"); + preinstalled.push_back("devicecap3"); + preinstalled.push_back("devicecap4"); + + FOREACH(it, preinstalled) + RUNNER_ASSERT(FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it)); + + //not installed + std::list notinstalled; + notinstalled.push_back("notinstalled1"); + notinstalled.push_back("plugin1"); + notinstalled.push_back(""); + notinstalled.push_back("ff"); + + FOREACH(it, notinstalled) + RUNNER_ASSERT(!FeatureDAOReadOnly::isDeviceCapabilityInstalled(*it)); +} + +#undef RUNNER_ASSERT_WHAT_EQUALS diff --git a/tests/dao/TestCases_GlobalDAO.cpp b/tests/dao/TestCases_GlobalDAO.cpp new file mode 100644 index 0000000..0098eee --- /dev/null +++ b/tests/dao/TestCases_GlobalDAO.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file TestCases_GlobalDAO.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for global dao class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace WrtDB; + + +namespace +{ +const DPL::String widgetPackage5(L"widgetpackage5"); +} // namespace + +RUNNER_TEST_GROUP_INIT(DAO) + +/* +Name: global_dao_developer_mode +Description: tests if developer mode is correctly set and get +Expected: received developer shoudl match the one was set +*/ +RUNNER_TEST(global_dao_developer_mode) +{ + bool prev_mode = GlobalDAO::GetDeveloperMode(); + GlobalDAO::SetDeveloperMode(false); + RUNNER_ASSERT_MSG(!GlobalDAO::GetDeveloperMode(), "set false failed"); + + GlobalDAO::SetDeveloperMode(true); + RUNNER_ASSERT_MSG(GlobalDAO::GetDeveloperMode(), "set true failed"); + GlobalDAO::SetDeveloperMode(prev_mode); +} + +/* +Name: home_network_data_usage +Description: tests if HomeNetworkDataUsage is correctly set and get +Expected: received developer shoudl match the one was set +*/ +RUNNER_TEST(home_network_data_usage) +{ + GlobalDAO::NetworkAccessMode original = + GlobalDAO::GetHomeNetworkDataUsage(); + + GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::CONNECT_AUTOMATICALLY); + RUNNER_ASSERT_MSG(GlobalDAO::CONNECT_AUTOMATICALLY == + GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated"); + + GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::ALWAYS_ASK); + RUNNER_ASSERT_MSG(GlobalDAO::ALWAYS_ASK == + GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated"); + + GlobalDAO::SetHomeNetworkDataUsage(GlobalDAO::NEVER_CONNECT); + RUNNER_ASSERT_MSG(GlobalDAO::NEVER_CONNECT == + GlobalDAO::GetHomeNetworkDataUsage(), "Value not updated"); + + GlobalDAO::SetHomeNetworkDataUsage(original); + RUNNER_ASSERT_MSG(original == GlobalDAO::GetHomeNetworkDataUsage(), + "Value not updated"); +} + +/* +Name: roaming_data_usage +Description: tests if RoamingDataUsage is correctly set and get +Expected: received developer shoudl match the one was set +*/ +RUNNER_TEST(roaming_data_usage) +{ + GlobalDAO::NetworkAccessMode original = + GlobalDAO::GetRoamingDataUsage(); + + GlobalDAO::SetRoamingDataUsage(GlobalDAO::CONNECT_AUTOMATICALLY); + RUNNER_ASSERT_MSG(GlobalDAO::CONNECT_AUTOMATICALLY == + GlobalDAO::GetRoamingDataUsage(), "Value not updated"); + + GlobalDAO::SetRoamingDataUsage(GlobalDAO::ALWAYS_ASK); + RUNNER_ASSERT_MSG(GlobalDAO::ALWAYS_ASK == + GlobalDAO::GetRoamingDataUsage(), "Value not updated"); + + GlobalDAO::SetRoamingDataUsage(GlobalDAO::NEVER_CONNECT); + RUNNER_ASSERT_MSG(GlobalDAO::NEVER_CONNECT == + GlobalDAO::GetRoamingDataUsage(), "Value not updated"); + + GlobalDAO::SetRoamingDataUsage(original); + RUNNER_ASSERT_MSG(original == GlobalDAO::GetRoamingDataUsage(), + "Value not updated"); +} diff --git a/tests/dao/TestCases_PluginDAO.cpp b/tests/dao/TestCases_PluginDAO.cpp new file mode 100644 index 0000000..d737752 --- /dev/null +++ b/tests/dao/TestCases_PluginDAO.cpp @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file TestCases_PluginDAO.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for feature dao class. + */ + +#include +#include +#include +#include +#include +//#include +#include +#include + +using namespace WrtDB; + +#define RUNNER_ASSERT_WHAT_EQUALS(in, test) \ + {std::string tmp(in); \ + RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");} + +RUNNER_TEST_GROUP_INIT(DAO) + +/* +Name: plugin_dao_test_register_plugins +Description: registers new plugin and check if it was correctly registered +Expected: plugin should be correctly registered +*/ +RUNNER_TEST(plugin_dao_test_register_plugins) +{ + { + std::string libraryPath("np1 lib_path"); + std::string libraryName("np1"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + PluginHandle handle = PluginDAO::registerPlugin(pluginData, libraryPath); + PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + PluginDAO dao(handle); + std::string tmp; + tmp = dao.getLibraryPath(); //do for each + RUNNER_ASSERT_MSG(tmp == libraryPath, "Equals: " + tmp); + } + + { + std::string libraryName("np2"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + PluginHandle handle = PluginDAO::registerPlugin(pluginData, ""); + PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + PluginDAO dao(handle); + RUNNER_ASSERT(dao.getLibraryPath() == ""); + } +} + +/* +Name: plugin_dao_test_register_plugin_implemented_object +Description: registers new PluginImplementedObject + and check if it was correctly registered +Expected: plugin dao shoudld be upodated with PluginImplementedObject +*/ +RUNNER_TEST(plugin_dao_test_register_plugin_implemented_object) +{ + { + std::string libraryPath("np3 lib_path"); + std::string libraryName("np3"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + PluginHandle handle = + PluginDAO::registerPlugin(pluginData, libraryPath); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + std::string object1("object1"); + std::string object2("object2"); + PluginDAO::registerPluginImplementedObject(object1, handle); + PluginDAO::registerPluginImplementedObject(object2, handle); + + PluginHandle retHandle1 = + PluginDAO::getPluginHandleForImplementedObject(object1); + PluginHandle retHandle2 = + PluginDAO::getPluginHandleForImplementedObject(object1); + RUNNER_ASSERT(retHandle1 == handle); + RUNNER_ASSERT(retHandle2 == handle); + } +} + +/* +Name: plugin_dao_test_register_plugin_implemented_object +Description: registers dependecies for plugins and checks if they were saved +Expected: registered dependecies should be returned from database +*/ +RUNNER_TEST(plugin_dao_test_register_library_dependencies) +{ + { + std::string libraryPath("np4 lib_path"); + std::string libraryName("np4"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + PluginHandle handle = + PluginDAO::registerPlugin(pluginData, libraryPath); + PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + PluginHandle depHandles[] = {117, 119}; + + PluginHandleSetPtr dependencies(new PluginHandleSet); + dependencies->insert(depHandles[1]); + dependencies->insert(depHandles[2]); + + PluginDAO::registerPluginLibrariesDependencies(handle, dependencies); + + PluginDAO dao(handle); + PluginHandleSetPtr retDependencies; + retDependencies = dao.getLibraryDependencies(); + + RUNNER_ASSERT( + retDependencies->size()==sizeof(depHandles)/sizeof(depHandles[0])); + RUNNER_ASSERT( + retDependencies->find(depHandles[1]) != retDependencies->end()); + RUNNER_ASSERT( + retDependencies->find(depHandles[2]) != retDependencies->end()); + } +} + +/* +Name: plugin_dao_test_register_required_object +Description: registers required plugin objects for plugins and checks if they were saved +Expected: registered required plugin objects should be returned from database +*/ +RUNNER_TEST(plugin_dao_test_register_required_object) +{ + { + std::string libraryPath("np5 lib_path"); + std::string libraryName("np5"); + + PluginMetafileData pluginData; + pluginData.m_libraryName = libraryName; + + PluginHandle handle = + PluginDAO::registerPlugin(pluginData, libraryPath); + PluginDAO::setPluginInstallationStatus(handle,PluginDAO::INSTALLATION_COMPLETED); + RUNNER_ASSERT(PluginDAO::isPluginInstalled(libraryName) == true); + + const size_t numObjects =2; + std::string objectReq [numObjects]; + objectReq[0] = std::string("object1.req"); + objectReq[1] = std::string("object2.req"); + PluginDAO::registerPluginRequiredObject(objectReq[0], handle); + PluginDAO::registerPluginRequiredObject(objectReq[1], handle); + + WrtDB::PluginObjectsDAO::ObjectsPtr objects = + PluginDAO::getRequiredObjectsForPluginHandle(handle); + + RUNNER_ASSERT(objects->size() == numObjects + && objects->find(objectReq[0]) != objects->end() + && objects->find(objectReq[1]) != objects->end()); + } +} + +/* +Name: plugin_dao_test_is_library_installed +Description: tests if plugin isntallation/registrartion works +Expected: only registered plugins should be reported as installed +*/ +RUNNER_TEST(plugin_dao_test_is_library_installed) +{ + { + //exist + std::list preinstalled; + preinstalled.push_back("plugin1"); + preinstalled.push_back("plugin2"); + preinstalled.push_back("plugin3"); + preinstalled.push_back("p4"); + preinstalled.push_back("p5"); + + FOREACH(it, preinstalled) + RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled(*it), + std::string("Not found: ") + *it); + } + + { + //does not exist + RUNNER_ASSERT_MSG( + PluginDAO::isPluginInstalled("not_installed1") == false, + "Found not_installed1"); + RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p 4") == false, + "Found p 4"); + RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("") == false, + "Found "); + RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("p33") == false, + "Found p33"); + RUNNER_ASSERT_MSG(PluginDAO::isPluginInstalled("feature1") == false, + "Found feature1"); + } +} + +/* +Name: plugin_dao_test_get_plugin_handle_list +Description: test of returning plugin handle list +Expected: returned list should be no less than number of registered plugins +*/ +RUNNER_TEST(plugin_dao_test_get_plugin_handle_list) +{ + PluginHandleList handles = PluginDAO::getPluginHandleList(); + RUNNER_ASSERT(handles.size() >= 5); +} + +/* +Name: plugin_dao_test_constructor_name +Description: tests construction of plugin dao based on plugin name +Expected: Instance of dao should be constructed only + if there is given plugin in database +*/ +RUNNER_TEST(plugin_dao_test_constructor_name) +{ + { + //exist + std::list preinstalled; + preinstalled.push_back("plugin1"); + preinstalled.push_back("plugin2"); + preinstalled.push_back("plugin3"); + preinstalled.push_back("p4"); + preinstalled.push_back("p5"); + + FOREACH(it, preinstalled) + { + PluginDAO dao(*it); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), *it); + } + } + + { + //does not exist + std::list not_installed; + not_installed.push_back("plugin 1"); + not_installed.push_back(""); + not_installed.push_back("p 3"); + + FOREACH(it, not_installed) + { + Try { + //Plugin not exist + PluginDAO dao(*it); + RUNNER_ASSERT_MSG(false, "should not be found"); + } + Catch (PluginDAO::Exception::PluginNotExist) { + continue; + } + } + } + +} + +/* +Name: plugin_dao_test_get_plugin_properties +Description: tests reading plugin properties from database +Expected: Data, inserted into database, should be accessible via dao +*/ +RUNNER_TEST(plugin_dao_test_get_plugin_properties) +{ + { + PluginDAO dao("p4"); + RUNNER_ASSERT(dao.getPluginHandle() == 4); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p4"); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p4"); + } + + { + PluginDAO dao(5); + RUNNER_ASSERT(dao.getPluginHandle() == 5); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "p5"); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_p5"); + } + + { + PluginDAO dao(2); + RUNNER_ASSERT(dao.getPluginHandle() == 2); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin2"); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), "path_to_plugin2"); + } + + { + PluginDAO dao(1); + RUNNER_ASSERT(dao.getPluginHandle() == 1); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryName(), "plugin1"); + RUNNER_ASSERT_WHAT_EQUALS(dao.getLibraryPath(), ""); + } +} + +/* +Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_1 +Description: tests receiving from dao Implemented Objects +Expected: returned object is size 0 +*/ +RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_1) +{ + { + const int handle = 1; + PluginDAOReadOnly dao(handle); + auto dbHandle = dao.getPluginHandle(); + RUNNER_ASSERT(dbHandle == handle); + auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle); + + RUNNER_ASSERT(objects.size() == 0); + } +} + +/* +Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_2 +Description: tests receiving from dao Implemented Objects +Expected: returned object is size as it was inserted +*/ +RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_2) +{ + { + std::set< std::string > preinstalled = + { + "" + }; + + PluginDAOReadOnly dao(2); + auto dbHandle = dao.getPluginHandle(); + auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle); + + //LogError("\n" << objects.size() << " " << preinstalled.size() << "\n"); + + RUNNER_ASSERT(objects.size() == preinstalled.size()); + + FOREACH(dbObject, objects) + { + RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end()); + } + } +} + +/* +Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_3 +Description: tests receiving from dao Implemented Objects +Expected: returned objects list has preinserted object +*/ +RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_3) +{ + { + std::set< std::string > preinstalled = + { + "Plugin_3_Object_A" + }; + + PluginDAOReadOnly dao(3); + auto dbHandle = dao.getPluginHandle(); + auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle); + RUNNER_ASSERT(objects.size() == preinstalled.size()); + + FOREACH(dbObject, objects) + { + RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end()); + } + } +} + +/* +Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_4 +Description: tests receiving from dao Implemented Objects +Expected: returned objects list has all preinserted objects +*/ +RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_4) +{ + { + std::set< std::string > preinstalled = + { + "Plugin_4_Object_A", + "Plugin_4_Object_B", + "Plugin_4_Object_C", + }; + + PluginDAOReadOnly dao(4); + auto dbHandle = dao.getPluginHandle(); + auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle); + RUNNER_ASSERT(objects.size() == preinstalled.size()); + + FOREACH(dbObject, objects) + { + RUNNER_ASSERT(preinstalled.find(*dbObject) != preinstalled.end()); + } + } +} + +/* +Name: plugin_dao_test_get_implemented_objects_for_plugin_handle_5 +Description: tests receiving from dao Implemented Objects +Expected: returned objects list do not have object that was not inserted +*/ +RUNNER_TEST(plugin_dao_test_get_implemented_objects_for_plugin_handle_5) +{ + { + std::set< std::string > preinstalled = + { + "Plugin_5_Object_B", + }; + + PluginDAOReadOnly dao(5); + auto dbHandle = dao.getPluginHandle(); + auto objects = dao.getImplementedObjectsForPluginHandle(dbHandle); + RUNNER_ASSERT(objects.size() == preinstalled.size()); + + FOREACH(dbObject, objects) + { + RUNNER_ASSERT(preinstalled.find(*dbObject) == preinstalled.end()); + } + } +} + + +#undef RUNNER_ASSERT_WHAT_EQUALS diff --git a/tests/dao/TestCases_PropertyDAO.cpp b/tests/dao/TestCases_PropertyDAO.cpp new file mode 100644 index 0000000..e72b01b --- /dev/null +++ b/tests/dao/TestCases_PropertyDAO.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file TestCases_PropertyDAO.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for property dao class. + */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace WrtDB; +using namespace WrtDB::PropertyDAOReadOnly; + +// Widgets used 2000, 2001, 2002, 2003(saved by wrt_dao_tests_prepare_db.sh) + +#define RUNNER_ASSERT_WHAT_EQUALS(in, test) \ + {std::string tmp(in); \ + RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");} + +#define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \ + { \ + if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \ + else RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in),test);\ + } + +RUNNER_TEST_GROUP_INIT(DAO) + +/* +Name: property_dao_get_lists +Description: tests returning list of properties for given id +Expected: data received should match those, which were inserted in prepare script +*/ +RUNNER_TEST(property_dao_get_lists) +{ + {//property list + std::map prefsMap; + prefsMap.insert(std::pair(2000, 2)); + prefsMap.insert(std::pair(2001, 1)); + prefsMap.insert(std::pair(2002, 2)); + prefsMap.insert(std::pair(1, 0)); //no widget + + FOREACH(it, prefsMap) { + PropertyDAOReadOnly::WidgetPreferenceList prefs = + PropertyDAOReadOnly::GetPropertyList(it->first); + RUNNER_ASSERT(prefs.size() == it->second); + } + } + + {//property key list + WidgetPropertyKeyList orig_2000; + orig_2000.push_back(DPL::FromUTF8String("key1_for_2000")); + orig_2000.push_back(DPL::FromUTF8String("key2_for_2000")); + + WidgetPropertyKeyList orig_2001; + orig_2001.push_back(DPL::FromUTF8String("key1_for_2001")); + + WidgetPropertyKeyList orig_2002; + orig_2002.push_back(DPL::FromUTF8String("key1_for_2002")); + orig_2002.push_back(DPL::FromUTF8String("key2_for_2002")); + + std::map prefsKeyMap; + prefsKeyMap.insert(std::pair( + 2000, &orig_2000)); + prefsKeyMap.insert(std::pair( + 2001, &orig_2001)); + prefsKeyMap.insert(std::pair( + 2002, &orig_2002)); + + FOREACH(it_out, prefsKeyMap) { + WidgetPropertyKeyList got = PropertyDAOReadOnly::GetPropertyKeyList( + it_out->first); + RUNNER_ASSERT(got.size() == it_out->second->size()); + //TODO + // FOREACH(it_in, got) + // { + // RUNNER_ASSERT(it_out->second. + // } + } + } +} + +/* +Name: property_dao_set_update_remove +Description: tests set new property for widget, updating property and removing it +Expected: given operation should works +*/ +RUNNER_TEST(property_dao_set_update_remove) +{ + WidgetPropertyKeyList keys = PropertyDAOReadOnly::GetPropertyKeyList(2000); + + //ADD + PropertyDAO::SetProperty(2000, + DPL::FromUTF8String("new_key"), + DPL::FromUTF8String("new_value1")); + + RUNNER_ASSERT_MSG( + keys.size() + 1 == PropertyDAOReadOnly::GetPropertyKeyList(2000).size(), + "new property not added"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL( + PropertyDAOReadOnly::GetPropertyValue(2000, + DPL::FromUTF8String("new_key")), + "new_value1"); + + //UPDATE + PropertyDAO::SetProperty(2000, + DPL::FromUTF8String("new_key"), + DPL::FromUTF8String("new_value2")); + RUNNER_ASSERT_MSG( + keys.size() + 1 == PropertyDAOReadOnly::GetPropertyKeyList(2000).size(), + "new property not added"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL( + PropertyDAOReadOnly::GetPropertyValue(2000, + DPL::FromUTF8String("new_key")), + "new_value2"); + + //REMOVE + PropertyDAO::RemoveProperty(2000, DPL::FromUTF8String("new_key")); + + RUNNER_ASSERT_MSG( + keys.size() == PropertyDAOReadOnly::GetPropertyKeyList(2000).size(), + "property not removed"); + +} + +/* +Name: property_dao_get_value +Description: tests if properties can be received from database +Expected: value, which were inserted before test, should be present +*/ +RUNNER_TEST(property_dao_get_value) +{ + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL( + PropertyDAOReadOnly::GetPropertyValue( + 2000, DPL::FromUTF8String("key1_for_2000")), + "value_for_key1_2000"); + + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL( + PropertyDAOReadOnly::GetPropertyValue( + 2000, DPL::FromUTF8String("key2_for_2000")), + "value_for_key2_2000"); +} + +#undef RUNNER_ASSERT_WHAT_EQUALS diff --git a/tests/dao/TestCases_WidgetDAO.cpp b/tests/dao/TestCases_WidgetDAO.cpp new file mode 100644 index 0000000..c04752a --- /dev/null +++ b/tests/dao/TestCases_WidgetDAO.cpp @@ -0,0 +1,919 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file TestCases_WidgetDAO.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for widget dao class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace WrtDB; + +namespace { + +class WacSecurityMock : public WrtDB::IWacSecurity +{ +public: + WacSecurityMock() : + mRecognized(false), + mDistributorSigned(false), + mWacSigned(false) + { + } + + virtual const WidgetCertificateDataList& getCertificateList() const + { + return mList; + } + + virtual bool isRecognized() const { return mRecognized; } + virtual bool isDistributorSigned() const { return mDistributorSigned; } + virtual bool isWacSigned() const { return mWacSigned; } + virtual void getCertificateChainList(CertificateChainList& /*lst*/) const {} + virtual void getCertificateChainList(CertificateChainList& /*lst*/, + CertificateSource source) const {} + + WrtDB::WidgetCertificateDataList& getCertificateListRef() + { + return mList; + } + + void setRecognized(bool recognized) { mRecognized = recognized; } + void setDistributorSigned(bool distributorSigned) + { + mDistributorSigned = distributorSigned; + } + void setWacSigned(bool wacSigned) { mWacSigned = wacSigned; } + +private: + WrtDB::WidgetCertificateDataList mList; + // author signature verified + bool mRecognized; + // known distribuor + bool mDistributorSigned; + // distributor is wac + bool mWacSigned; + +}; + +WidgetPkgName _registerWidget(const WidgetRegisterInfo& regInfo, + const IWacSecurity& sec, + int line) +{ + WidgetPkgName pkgname; + Try { + auto previous = WidgetDAO::getPkgnameList(); + + // register widget + pkgname = WidgetDAO::registerWidgetGenerateTizenId(regInfo, sec); + + RUNNER_ASSERT_MSG(!pkgname.empty(), + "(called from line " << line << ")"); + + auto current = WidgetDAO::getPkgnameList(); + RUNNER_ASSERT_MSG(previous.size()+1 == current.size(), + "(called from line " << line << ")"); + + RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), + "(called from line " << line << " pkgname: " << pkgname << ")"); + } + Catch (WidgetDAO::Exception::AlreadyRegistered) { + RUNNER_ASSERT_MSG( + false, + "Unexpected exception (called from line " << line << ")"); + } + return pkgname; +} + +#define REGISTER_WIDGET(regInfo, sec) _registerWidget((regInfo),(sec), __LINE__) + +} // namespace + +// Widgets used <2300,2500), 2000, 2001, 2002, 2003 + +#define RUNNER_ASSERT_WHAT_EQUALS(in, test) \ + {std::string tmp(in); \ + RUNNER_ASSERT_MSG(tmp == test, "Equals: [" + tmp + "]");} + +#define RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(in, test) \ + { \ + if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \ + else RUNNER_ASSERT_WHAT_EQUALS(DPL::ToUTF8String(*in),test);\ + } + +#define RUNNER_ASSERT_WHAT_EQUALS_OPTIONALINT(in, test) \ + { \ + if(in.IsNull()) RUNNER_ASSERT_MSG(false, "NULL"); \ + else RUNNER_ASSERT_MSG(*in == test, "Equals: [" + *in + "]"); \ + } + +RUNNER_TEST_GROUP_INIT(DAO) + +//2300 +/* +Name: widget_dao_test_register_widget_empty_strings +Description: Tests registeration of new widget with empty values +Expected: widget should be registered in database +*/ +RUNNER_TEST(widget_dao_test_register_widget_empty_strings) +{ + WidgetRegisterInfo regInfo; + + //ext info + regInfo.shareHref = ""; + + //info + regInfo.configInfo.widget_id = DPL::FromUTF8String(""); + regInfo.configInfo.version = DPL::FromUTF8String(""); + regInfo.configInfo.width = 10; + regInfo.configInfo.height = 10; + regInfo.configInfo.authorName = DPL::FromUTF8String(""); + regInfo.configInfo.authorEmail = DPL::FromUTF8String(""); + regInfo.configInfo.authorHref = DPL::FromUTF8String(""); + regInfo.baseFolder = ""; + //TODO authenticated, etc... + regInfo.configInfo.flashNeeded = false; + regInfo.configInfo.minVersionRequired = DPL::FromUTF8String("1.0"); + regInfo.configInfo.backSupported = true; + + //loc info + ConfigParserData::LocalizedData locData; + locData.name = DPL::FromUTF8String(""); + locData.shortName = DPL::FromUTF8String(""); + locData.description = DPL::FromUTF8String(""); + locData.license = DPL::FromUTF8String(""); + locData.licenseFile = DPL::FromUTF8String(""); + locData.licenseHref = DPL::FromUTF8String(""); + regInfo.configInfo.localizedDataSet.insert( + std::make_pair(DPL::FromUTF8String("en"),locData)); + + //userAgentLoc + + //icons + ConfigParserData::Icon icon(DPL::FromUTF8String("")); + icon.width = 10; + icon.height = 10; + LocaleSet locs; + locs.insert(DPL::FromUTF8String("en")); + WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs); + regInfo.localizationData.icons.push_back(locIcon); + + //start file + WidgetRegisterInfo::StartFileProperties prop; + prop.encoding = DPL::FromUTF8String(""); + prop.type = DPL::FromUTF8String(""); + WidgetRegisterInfo::LocalizedStartFile file; + file.path = DPL::FromUTF8String(""); + file.propertiesForLocales.insert( + std::make_pair(DPL::FromUTF8String("en"), prop)); + regInfo.localizationData.startFiles.push_back(file); + + //widget pref + ConfigParserData::Preference pref(DPL::FromUTF8String(""),false); + pref.value = DPL::FromUTF8String(""); + regInfo.configInfo.preferencesList.insert(pref); + + //widget feature + ConfigParserData::Feature feat(DPL::FromUTF8String(""),false); + ConfigParserData::Param par(DPL::FromUTF8String((""))); + par.value = DPL::FromUTF8String(""); + feat.paramsList.insert(par); + regInfo.configInfo.featuresList.insert(feat); + + //win modes + regInfo.configInfo.windowModes.insert(DPL::FromUTF8String("")); + + //WARP info + ConfigParserData::AccessInfo access(DPL::FromUTF8String(""),true); + regInfo.configInfo.accessInfoSet.insert(access); + + //certificates + WidgetCertificateData cert; + cert.owner = WidgetCertificateData::AUTHOR; + cert.type = WidgetCertificateData::ROOT; + cert.chainId = 1; + cert.strMD5Fingerprint = ""; + cert.strSHA1Fingerprint = ""; + cert.strCommonName = DPL::FromUTF8String(""); + + WacSecurityMock security; + security.getCertificateListRef().push_back(cert); + + REGISTER_WIDGET(regInfo,security); +} + +/* +Name: widget_dao_test_register_widget_empty_strings +Description: Tests possiblity of registering twice same content (different tizenId) +Expected: it should be possible +*/ +RUNNER_TEST(widget_dao_test_twice_install_same_widget) +{ + WacSecurityMock sec; + { + WidgetRegisterInfo regInfo; + REGISTER_WIDGET(regInfo, sec); + } + { + WidgetRegisterInfo regInfo; + REGISTER_WIDGET(regInfo, sec); + } + +} + +/* +Name: widget_dao_test_register_widget_minimum_info +Description: Tests simplest registeration of new widget +Expected: widget should be registered in database +*/ +RUNNER_TEST(widget_dao_test_register_widget_minimum_info) +{ + WacSecurityMock sec; + const std::size_t NUMBER_OF_WIDGETS = 5; + + DPL::Optional lastPkgname; + + for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) + { + WidgetRegisterInfo regInfo; + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + lastPkgname = pkgname; + + WidgetDAO dao(pkgname); + //TODO check nulls + } +} + +/* +Name: widget_dao_test_register_widget_info +Description: Tests registeration of many widgets +Expected: all widgets should be registered in database +*/ +RUNNER_TEST(widget_dao_test_register_widget_info) +{ + WacSecurityMock sec; + const std::size_t NUMBER_OF_WIDGETS = 5; + + for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) + { + std::ostringstream str; + str << "register_info_test_" << number; + + WidgetRegisterInfo regInfo; + regInfo.configInfo.widget_id = DPL::FromUTF8String(str.str()); + regInfo.configInfo.version = DPL::FromUTF8String(str.str()); + regInfo.configInfo.width = 10; + regInfo.configInfo.height = 10; + regInfo.configInfo.authorName = DPL::FromUTF8String(str.str()); + regInfo.configInfo.authorEmail = DPL::FromUTF8String(str.str()); + regInfo.configInfo.authorHref = DPL::FromUTF8String(str.str()); + regInfo.baseFolder = str.str(); //base folder at the end has / + regInfo.configInfo.flashNeeded = false; + //TODO authenticated, etc... + //in wrt-installer: TaskWidgetConfig::fillWidgetConfig: + //regInfo.minVersion = regInfo.configInfo.minVersionRequired + regInfo.minVersion = DPL::FromUTF8String("1.0"); + regInfo.configInfo.backSupported = true; + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), str.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), str.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), str.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), str.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), str.str()); + RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), str.str() + "/"); + RUNNER_ASSERT(dao.getWebkitPluginsRequired() == false); +// RUNNER_ASSERT( +// dao.GetWidgetSecurityDomain() == WacSecurity::Trusted); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0"); + } + +} + +/* +Name: widget_dao_test_register_widget_extended_info +Description: Tests registeration of widget_extended_info +Expected: registeration of extended inforamtion is checked + via existence of backgroudn page value +*/ +RUNNER_TEST(widget_dao_test_register_widget_extended_info) +{ + WacSecurityMock sec; + const std::size_t NUMBER_OF_WIDGETS = 5; + + for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) + { + std::ostringstream str; + str << "register_ext_info_test_" << number; + + WidgetRegisterInfo regInfo; + +// regInfo.shareHref = str.str(); + regInfo.configInfo.backgroundPage = L"background.html"; + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); +// RUNNER_ASSERT_WHAT_EQUALS(dao.GetShareHref(), str.str()); + + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getBackgroundPage(), + "background.html"); + } +} + +/* +Name: widget_dao_test_register_widget_localized_info +Description: Tests registeration of localized widgets information +Expected: values received by dao should match those which were registered +*/ +RUNNER_TEST(widget_dao_test_register_widget_localized_info) +{ + WacSecurityMock sec; + const std::size_t NUMBER_OF_WIDGETS = 5; + + for (std::size_t number = 0; number < NUMBER_OF_WIDGETS; ++number) + { + WidgetRegisterInfo regInfo; + std::ostringstream str_en; + std::ostringstream str_pl; + str_en << "register_loc_info_test_en_" << number; + str_pl<< "register_loc_info_test_pl_" << number; + {//EN + ConfigParserData::LocalizedData locDataEn; + locDataEn.name = DPL::FromUTF8String(str_en.str()); + locDataEn.shortName = DPL::FromUTF8String(str_en.str()); + locDataEn.description = DPL::FromUTF8String(str_en.str()); + locDataEn.license = DPL::FromUTF8String(str_en.str()); + locDataEn.licenseFile = DPL::FromUTF8String(str_en.str()); + locDataEn.licenseHref = DPL::FromUTF8String(str_en.str()); + regInfo.configInfo.localizedDataSet.insert( + std::make_pair(DPL::FromUTF8String("en"),locDataEn)); + } + + {//PL + ConfigParserData::LocalizedData locDataPl; + locDataPl.name = DPL::FromUTF8String(str_pl.str()); + locDataPl.shortName = DPL::FromUTF8String(str_pl.str()); + locDataPl.description = DPL::FromUTF8String(str_pl.str()); + locDataPl.license = DPL::FromUTF8String(str_pl.str()); + locDataPl.licenseFile = DPL::FromUTF8String(str_pl.str()); + locDataPl.licenseHref = DPL::FromUTF8String(str_pl.str()); + regInfo.configInfo.localizedDataSet.insert( + std::make_pair(DPL::FromUTF8String("pl"),locDataPl)); + } + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + RUNNER_ASSERT_MSG(dao.getLanguageTags().size() == 2, + "language tags list invalid"); + + {//EN + WidgetLocalizedInfo locInfo = + dao.getLocalizedInfo(DPL::FromUTF8String("en")); + + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name, + str_en.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName, + str_en.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description, + str_en.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license, + str_en.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref, + str_en.str()); + } + + {//PL + WidgetLocalizedInfo locInfo = + dao.getLocalizedInfo(DPL::FromUTF8String("pl")); + + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.name, + str_pl.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.shortName, + str_pl.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.description, + str_pl.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.license, + str_pl.str()); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(locInfo.licenseHref, + str_pl.str()); + } + } +} + +/* +Name: widget_dao_test_register_widget_icons +Description: Tests registeration of localized icons information +Expected: values received by dao should match those which were registered + for icon +*/ +RUNNER_TEST(widget_dao_test_register_widget_icons) +{ + WacSecurityMock sec; + WidgetRegisterInfo regInfo; + + ConfigParserData::Icon icon(L"icon1"); + icon.width = 10; + icon.height = 10; + LocaleSet locs; + locs.insert(DPL::FromUTF8String("en")); + WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs); + regInfo.localizationData.icons.push_back(locIcon); + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + WidgetDAOReadOnly::WidgetIconList list = dao.getIconList(); + + RUNNER_ASSERT(list.size() == regInfo.localizationData.icons.size()); + WidgetDAOReadOnly::WidgetIconList::const_iterator it1 = list.begin(); + WidgetRegisterInfo::LocalizedIconList::const_iterator it2 = + regInfo.localizationData.icons.begin(); + for(;it1!=list.end() && it2!=regInfo.localizationData.icons.end(); + ++it1,++it2) + { + RUNNER_ASSERT(it2->height == it1->iconHeight); + RUNNER_ASSERT(it2->width == it1->iconWidth); + RUNNER_ASSERT(it2->src == it1->iconSrc); + RUNNER_ASSERT(it2->availableLocales == locs); + } +} + +/* +Name: widget_dao_test_register_widget_start_files +Description: Tests registeration of localized start files +Expected: no expectations as it should be removed +*/ +RUNNER_TEST(widget_dao_test_register_widget_start_files) +{ + WacSecurityMock sec; + + WidgetRegisterInfo::LocalizedStartFileList files; + WidgetRegisterInfo::StartFilePropertiesForLocalesMap map1; + WidgetRegisterInfo::StartFileProperties prop1; + prop1.encoding = DPL::FromUTF8String("enc1"); + prop1.type = DPL::FromUTF8String("type1"); + + map1.insert(std::make_pair(DPL::FromUTF8String("en"),prop1)); + map1.insert(std::make_pair(DPL::FromUTF8String("pl"),prop1)); + + WidgetRegisterInfo::LocalizedStartFile file1; + WidgetRegisterInfo::LocalizedStartFile file2; + file1.path = DPL::FromUTF8String("path1"); + file1.propertiesForLocales = map1; + file2.path = DPL::FromUTF8String("path2"); + file2.propertiesForLocales = map1; + + files.push_back(file1); + files.push_back(file1); + + WidgetRegisterInfo regInfo; + regInfo.localizationData.startFiles = files; + + REGISTER_WIDGET(regInfo, sec); + + //TODO no getter in WidgetDAO (getter in LocalizedWidgetDAO, + // but it will be removed +} + +/* +Name: widget_dao_test_register_widget_features +Description: Tests registeration of features of widget +Expected: number of features should match (for given widget reginfo) +*/ +RUNNER_TEST(widget_dao_test_register_widget_features) +{ + WacSecurityMock sec; + ConfigParserData::FeaturesList features; + features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f1"),true)); + features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f2"))); + features.insert(ConfigParserData::Feature(DPL::FromUTF8String("f3"), + false)); + + WidgetRegisterInfo regInfo; + FOREACH(it, features) + regInfo.configInfo.featuresList.insert(*it); + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + WidgetFeatureSet out = dao.getFeaturesList(); + RUNNER_ASSERT_MSG(out.size() == features.size(), + "wrong number of features"); +// FOREACH(it, out) +// RUNNER_ASSERT(features.find(*it) != features.end()); +} + +/* +Name: widget_dao_test_register_widget_win_modes +Description: Tests registeration of window modes +Expected: all modes should be returned from dao +*/ +RUNNER_TEST(widget_dao_test_register_widget_win_modes) +{ + WacSecurityMock sec; + std::set modes; + modes.insert(DPL::FromUTF8String("full")); + modes.insert(DPL::FromUTF8String("window")); + + WidgetRegisterInfo regInfo; + + FOREACH(it, modes) + regInfo.configInfo.windowModes.insert(*it); + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + std::list wins = dao.getWindowModes(); + RUNNER_ASSERT_MSG(modes.size() == wins.size(), + "wrong number of window modes"); + FOREACH(it, wins) + RUNNER_ASSERT(modes.find(*it) != modes.end()); +} + +/* +Name: widget_dao_test_register_widget_warp_info +Description: Tests registeration of access info iris +Expected: all access info iris should be returned from dao +*/ +RUNNER_TEST(widget_dao_test_register_widget_warp_info) +{ + WacSecurityMock sec; + ConfigParserData::AccessInfoSet orig; + orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri1"), + true)); + orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri2"), + false)); + orig.insert(ConfigParserData::AccessInfo(DPL::FromUTF8String("iri3"), + true)); + + WidgetRegisterInfo regInfo; + FOREACH(it, orig) + regInfo.configInfo.accessInfoSet.insert(*it); + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + + WidgetAccessInfoList out; + dao.getWidgetAccessInfo(out); + RUNNER_ASSERT_MSG(out.size() == orig.size(), + "wrong number of access info elem"); + FOREACH(it, out){ + ConfigParserData::AccessInfo tmp(it->strIRI,it->bSubDomains); + RUNNER_ASSERT(orig.find(tmp) != orig.end()); + } +} + +/* +Name: widget_dao_test_register_widget_certificates +Description: Tests registeration of widget certificates +Expected: all certificates should be returned from dao + and should contain inserted data +*/ +RUNNER_TEST(widget_dao_test_register_widget_certificates) +{ + WacSecurityMock sec; + WidgetRegisterInfo regInfo; + + WidgetCertificateData cert; + cert.owner = WidgetCertificateData::AUTHOR; + cert.type = WidgetCertificateData::ROOT; + cert.chainId = 1; + cert.strMD5Fingerprint = "md5"; + cert.strSHA1Fingerprint = "sha1"; + cert.strCommonName = DPL::FromUTF8String("common name"); + + WidgetCertificateDataList& certListRef = sec.getCertificateListRef(); + certListRef.push_back(cert); + + // register widget + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + + // certificates + WidgetCertificateDataList recList = dao.getCertificateDataList(); + RUNNER_ASSERT(recList.size() == certListRef.size()); + + auto recListIt = recList.begin(); + auto certListIt = certListRef.begin(); + for(;recListIt != recList.end() && certListIt != certListRef.end(); + ++recListIt,++certListIt) + { + RUNNER_ASSERT(recListIt->chainId == certListIt->chainId); + RUNNER_ASSERT(recListIt->owner == certListIt->owner); + RUNNER_ASSERT(recListIt->strCommonName == certListIt->strCommonName); + RUNNER_ASSERT(recListIt->strMD5Fingerprint == + certListIt->strMD5Fingerprint); + RUNNER_ASSERT(recListIt->strSHA1Fingerprint == + certListIt->strSHA1Fingerprint); + RUNNER_ASSERT(recListIt->type == certListIt->type); + } + + // fingerprints + RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR, + WidgetCertificateData::ENDENTITY).empty()); + RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::AUTHOR, + WidgetCertificateData::ENDENTITY).empty()); + RUNNER_ASSERT(dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR, + WidgetCertificateData::ROOT).empty()); + + FingerPrintList fingerprints = dao.getKeyFingerprints( + WidgetCertificateData::AUTHOR, + WidgetCertificateData::ROOT); + + RUNNER_ASSERT(fingerprints.size() == certListRef.size()*2); + FOREACH(it, certListRef) + { + auto md5 = std::find(fingerprints.begin(), + fingerprints.end(), + it->strMD5Fingerprint); + RUNNER_ASSERT(md5 != fingerprints.end()); + + auto sha = std::find(fingerprints.begin(), + fingerprints.end(), + it->strSHA1Fingerprint); + RUNNER_ASSERT(sha != fingerprints.end()); + } + + // common names + RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR, + WidgetCertificateData::ENDENTITY).empty()); + RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR, + WidgetCertificateData::ENDENTITY).empty()); + RUNNER_ASSERT(dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR, + WidgetCertificateData::ROOT).empty()); + + FingerPrintList commonNames = dao.getKeyCommonNameList( + WidgetCertificateData::AUTHOR, + WidgetCertificateData::ROOT); + + RUNNER_ASSERT(commonNames.size() == certListRef.size()); + FOREACH(it, certListRef) + { + auto cn = std::find(commonNames.begin(), + commonNames.end(), + DPL::ToUTF8String(it->strCommonName)); + RUNNER_ASSERT(cn != commonNames.end()); + } +} + +/* +Name: widget_dao_test_is_widget_installed +Description: Tests checking if widgets are installed +Expected: installed widgets should be stated as installed +*/ +RUNNER_TEST(widget_dao_test_is_widget_installed) +{ + RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(L"tizenid201")); + + WacSecurityMock sec; + WidgetRegisterInfo regInfo; + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + RUNNER_ASSERT(WidgetDAO::isWidgetInstalled(pkgname)); +} + +/* +Name: widget_dao_test_unregister_widget +Description: Tests unregistering widgets +Expected: widget register informations should be successfully removed +*/ +RUNNER_TEST(widget_dao_test_unregister_widget) +{ + WacSecurityMock sec; + WidgetHandleList handles = WidgetDAO::getHandleList(); + + WidgetRegisterInfo regInfo; + + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO::unregisterWidget(pkgname); + + RUNNER_ASSERT_MSG(handles.size() == WidgetDAO::getHandleList().size(), + "Widget unregister failed"); +} + +/* +Name: widget_dao_test_register_or_update_widget +Description: Tests reregistering widgets +Expected: widget should be successfully replaced +*/ +RUNNER_TEST(widget_dao_test_register_or_update_widget) +{ + WacSecurityMock sec; + + WidgetRegisterInfo regInfo; + regInfo.configInfo.version = L"1.0"; + regInfo.configInfo.authorName = L"AAA"; + + WidgetRegisterInfo regInfo2; + regInfo2.configInfo.version = L"1.1"; + regInfo2.configInfo.authorName = L"BBB"; + + WrtDB::WidgetPkgName pkgname(L"abcdefghij"); + + //first installation + WidgetDAO::registerWidget(pkgname, regInfo, sec); + RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not registered"); + + //success full update + WidgetDAO::registerOrUpdateWidget(pkgname, regInfo2, sec); + RUNNER_ASSERT_MSG(WidgetDAO::isWidgetInstalled(pkgname), "Widget is not reregistered"); + WidgetDAO dao(pkgname); + RUNNER_ASSERT_MSG(*dao.getVersion() == L"1.1", "Data widget was not updated"); + RUNNER_ASSERT_MSG(*dao.getAuthorName() == L"BBB", "Data widget was not updated"); + + WidgetDAO::unregisterWidget(pkgname); +} + +/* +Name: widget_dao_test_get_widget_pkgname_list +Description: Tests getPkgnameList API for backendlib +Expected: For all position in database should be returned one item in list +*/ +RUNNER_TEST(widget_dao_test_get_widget_pkgname_list) +{ + WidgetPkgNameList pkgnames = WidgetDAO::getPkgnameList(); + RUNNER_ASSERT(pkgnames.size() >= 3); +} + +/* +Name: widget_dao_test_get_widget_list +Description: Tests getPkgnameList API for backendlib +Expected: For all position in database should be returned one item in list + Those item should contain valid pkgname +*/ +RUNNER_TEST(widget_dao_test_get_widget_list) +{ + WidgetDAOReadOnlyList list = WidgetDAOReadOnly::getWidgetList(); + RUNNER_ASSERT(list.size() >= 3); + RUNNER_ASSERT_MSG(!!list.front(), "widget dao exists"); + WidgetDAOReadOnlyPtr dao = list.front(); + RUNNER_ASSERT_MSG(!dao->getPkgname().IsNull(), "dao object do not have tizen id"); +} + +/* +Name: widget_dao_test_get_widget_attributes +Description: Tests returning basic widget attributes by dao +Expected: Attributes should match values inserted into database +*/ +RUNNER_TEST(widget_dao_test_get_widget_attributes) +{ + { + WidgetPkgName pkgname = L"tizenid201"; + WidgetDAO dao(pkgname); + + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getGUID(), "w_id_2000"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getVersion(), "1.0.0"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorName(), "a_name_2000"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorEmail(), + "a_email_2000"); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getAuthorHref(), "a_href_2000"); + RUNNER_ASSERT_WHAT_EQUALS(dao.getBaseFolder(), "basef_2000/"); + RUNNER_ASSERT(dao.getWebkitPluginsRequired() == true); + RUNNER_ASSERT_WHAT_EQUALS_OPTIONAL(dao.getMinimumWacVersion(), "1.0"); + } +} + +/* +Name: widget_dao_test_localization +Description: Tests inserting and returning localization info +Expected: Values inserted into database should match values received from database +*/ +RUNNER_TEST(widget_dao_test_localization) +{ + WacSecurityMock sec; + + // icon + WidgetRegisterInfo regInfo; + ConfigParserData::Icon icon(L"icon1"); + icon.width = 10; + icon.height = 10; + LocaleSet locs; + locs.insert(DPL::FromUTF8String("en")); + locs.insert(DPL::FromUTF8String("pl")); + WidgetRegisterInfo::LocalizedIcon locIcon(icon,locs); + regInfo.localizationData.icons.push_back(locIcon); + + //start file + WidgetRegisterInfo::StartFileProperties prop_en; + prop_en.encoding = DPL::FromUTF8String("encoding_en"); + prop_en.type = DPL::FromUTF8String("type_en"); + + WidgetRegisterInfo::StartFileProperties prop_pl; + prop_pl.encoding = DPL::FromUTF8String("encoding_pl"); + prop_pl.type = DPL::FromUTF8String("type_pl"); + + WidgetRegisterInfo::LocalizedStartFile file; + file.path = DPL::FromUTF8String("path"); + file.propertiesForLocales.insert( + std::make_pair(DPL::FromUTF8String("en"), prop_en)); + file.propertiesForLocales.insert( + std::make_pair(DPL::FromUTF8String("pl"), prop_pl)); + regInfo.localizationData.startFiles.push_back(file); + + // register widget + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + + WidgetDAO dao(pkgname); + + // check localized icons + WidgetDAO::WidgetLocalizedIconList locList = dao.getLocalizedIconList(); + RUNNER_ASSERT(locList.size() == locs.size()); + + // non-localized icon + WidgetDAO::WidgetIconList list = dao.getIconList(); + int iconId = list.front().iconId; + + // compare every icon with the origin + auto locsIt = locs.begin(); + auto iconIt = locList.begin(); + for(;locsIt!=locs.end() && iconIt!=locList.end();++locsIt,++iconIt) { + RUNNER_ASSERT(iconIt->appId == dao.getHandle()); + RUNNER_ASSERT(iconIt->iconId == iconId); + RUNNER_ASSERT(iconIt->widgetLocale == *locsIt); + } + + // localized start file list + WidgetDAO::LocalizedStartFileList fList = dao.getLocalizedStartFileList(); + RUNNER_ASSERT(fList.size() == file.propertiesForLocales.size()); + + int startFileId = dao.getStartFileList().front().startFileId; + + FOREACH(it,fList) + { + RUNNER_ASSERT(it->appId == dao.getHandle()); + auto propIt = file.propertiesForLocales.find(it->widgetLocale); + RUNNER_ASSERT(propIt != file.propertiesForLocales.end()); + RUNNER_ASSERT(it->encoding == propIt->second.encoding); + RUNNER_ASSERT(it->type == propIt->second.type); + RUNNER_ASSERT(it->startFileId == startFileId); + } +} + +/* +Name: widget_dao_test_wac_security +Description: Tests inserting and returning wac security information +Expected: Values inserted into database should match values received from database +*/ +RUNNER_TEST(widget_dao_test_wac_security) +{ + WacSecurityMock sec; + WidgetRegisterInfo regInfo; + { + // register widget + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + WidgetDAO dao(pkgname); + + RUNNER_ASSERT(!dao.isDistributorSigned()); + RUNNER_ASSERT(!dao.isRecognized()); + RUNNER_ASSERT(!dao.isWacSigned()); + } + sec.setDistributorSigned(true); + sec.setRecognized(true); + sec.setWacSigned(true); + { + // register widget + WidgetPkgName pkgname = REGISTER_WIDGET(regInfo, sec); + WidgetDAO dao(pkgname); + + RUNNER_ASSERT(dao.isDistributorSigned()); + RUNNER_ASSERT(dao.isRecognized()); + RUNNER_ASSERT(dao.isWacSigned()); + } +} + +#undef RUNNER_ASSERT_WHAT_EQUALS diff --git a/tests/dao/tests_dao.cpp b/tests/dao/tests_dao.cpp new file mode 100644 index 0000000..0b32edb --- /dev/null +++ b/tests/dao/tests_dao.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file tests_plugin_dao.cpp + * @author Pawel Sikorski (p.sikorski@samsung.com) + * @version 1.0 + * @brief This file contains tests for plugin dao class. + */ + +#include +#include +#include + +int main (int argc, char *argv[]) +{ + int ret = system("/usr/bin/wrt_dao_tests_prepare_db.sh start"); + if (ret != 0) { + LogError("Preparation script has return error: " << ret + << ". Quitting"); + return -1; + } + + WrtDB::WrtDatabase::attachToThreadRW(); + + LogInfo("Starting tests"); + int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); + + WrtDB::WrtDatabase::detachFromThread(); + + ret = system("/usr/bin/wrt_dao_tests_prepare_db.sh stop"); + if (ret != 0) { + LogError("Finalization script has return error: " << ret); + return -1; + } + return status; +} diff --git a/tests/dao/wrt_dao_tests_prepare_db.sh b/tests/dao/wrt_dao_tests_prepare_db.sh new file mode 100755 index 0000000..386c68b --- /dev/null +++ b/tests/dao/wrt_dao_tests_prepare_db.sh @@ -0,0 +1,129 @@ +#!/bin/sh +# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +WRT_DB=/opt/dbspace/.wrt.db +WRT_DB_BCK=/tmp/wrt.db_backup + +if [ "x$1" == "xstart" ]; then + echo start; + cp $WRT_DB $WRT_DB_BCK + wrt_commons_create_clean_db.sh; + + #simple plugins + INS_MIN_PLUGINPROP="insert into PluginProperties(PluginPropertiesId, InstallationState, PluginLibraryName" + INS_ALL_PLUGINPROP="insert into PluginProperties(PluginPropertiesId, InstallationState, PluginLibraryName, PluginLibraryPath)" + INS_PLUGIN_OBJECTS="insert into PluginImplementedObjects(PluginObject, PluginPropertiesId)" + + sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}) VALUES(1, 1, 'plugin1')"; + sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}, PluginLibraryPath) VALUES(2, 1, 'plugin2', 'path_to_plugin2')"; + sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}) VALUES(3, 1, 'plugin3')"; + sqlite3 $WRT_DB "${INS_ALL_PLUGINPROP} VALUES(4, 1, 'p4', 'path_to_p4')"; + sqlite3 $WRT_DB "${INS_ALL_PLUGINPROP} VALUES(5, 1, 'p5', 'path_to_p5')"; + + #plugin dependendencies + #sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES(1, )"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('', 2)"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('Plugin_3_Object_A', 3)"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('Plugin_4_Object_A', 4)"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('Plugin_4_Object_B', 4)"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('Plugin_4_Object_C', 4)"; + sqlite3 $WRT_DB "${INS_PLUGIN_OBJECTS} VALUES('Plugin_5_Object_A', 5)"; + + + #simple features + INS_ALL_FEATURESLIST="insert into FeaturesList(FeatureUUID, FeatureName, PluginPropertiesId)" + sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(1, 'feature1', 1)"; + sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(2, 'feature2', 4)"; + sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(3, 'feature3', 4)"; + sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(4, 'feature4', 4)"; + + #device capabilities + INS_ALL_DEVICECAPS="insert into DeviceCapabilities(DeviceCapID, DeviceCapName, DeviceCapDefaultValue)" + sqlite3 $WRT_DB "${INS_ALL_DEVICECAPS} VALUES(1, 'devicecap1', 1)"; + sqlite3 $WRT_DB "${INS_ALL_DEVICECAPS} VALUES(2, 'devicecap2', 2)"; + sqlite3 $WRT_DB "${INS_ALL_DEVICECAPS} VALUES(3, 'devicecap3', 3)"; + sqlite3 $WRT_DB "${INS_ALL_DEVICECAPS} VALUES(4, 'devicecap4', 4)"; + + #Widgets + INS_ALL_WIDGETEXT="insert into WidgetExtendedInfo(app_id, share_href, signature_type)" + INS_ALL_WIDGET="insert into WidgetInfo(app_id, widget_id, widget_version, widget_width, widget_height, author_name, author_email, author_href, base_folder, webkit_plugins_required, recognized, wac_signed, distributor_signed, min_version, pkgname)" + INS_ALL_WIDGET_LOC="insert into LocalizedWidgetInfo(app_id, widget_locale, widget_name, widget_shortname, widget_description, widget_license, widget_license_file, widget_license_href)" + INS_ALL_WIDGET_ICONS="insert into WidgetIcon(app_id, icon_src, icon_width, icon_height)" + INS_ALL_WIDGET_LOC_ICONS="insert into WidgetLocalizedIcon(app_id, icon_id, widget_locale)" + INS_ALL_WIDGET_STARTFILE="insert into WidgetStartFile(app_id, src)" + INS_ALL_WIDGET_LOC_STARTFILE="insert into WidgetLocalizedStartFile(app_id, start_file_id, widget_locale, type, encoding)" + INS_ALL_WIDGET_DEFPREF="insert into WidgetDefaultPreference(app_id, key_name, key_value, readonly)" + INS_ALL_WIDGET_PREF="insert into WidgetPreference(app_id, key_name, key_value, readonly)" + INS_ALL_WIDGET_FEATURE="insert into WidgetFeature(app_id, name, required)" + INS_ALL_WIDGET_FEATURE_PARAM="insert into FeatureParam(widget_feature_id, name, value)" + INS_ALL_WIDGET_WINMODES="insert into WidgetWindowModes(app_id, window_mode)" + INS_ALL_WIDGET_WARP="insert into WidgetWARPInfo(app_id, iri, subdomain_access)" + INS_ALL_WIDGET_CERT="insert into WidgetCertificateFingerprint(app_id, owner, chainid, type, md5_fingerprint, sha1_fingerprint, common_name)" + INS_ALL_WIDGET_POWDERLEV="insert into PowderLevels(app_id, category, level)" + INS_ALL_WIDGET_POWDERLEV_CONT="insert into PowderLevelContexts(levelid, context)" + + + sqlite3 $WRT_DB "${INS_ALL_WIDGET} VALUES(2000, 'w_id_2000', '1.0.0', 100, 200, 'a_name_2000', 'a_email_2000', 'a_href_2000', 'basef_2000', 1, 1, 1, 1, '1.0', 'tizenid201')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET} VALUES(2001, 'w_id_2001', '2.0.0', 100, 200, 'a_name_2001', 'a_email_2001', 'a_href_2001', 'basef_2001', 1, 1, 1, 1, '0.5', 'tizenid202')"; + sqlite3 $WRT_DB "insert into WidgetInfo(app_id, back_supported, pkgname) VALUES(2002, 0, 'tizenid203')"; + sqlite3 $WRT_DB "insert into WidgetInfo(app_id, back_supported, pkgname) VALUES(2003, 0, 'tizenid204')"; # for properties tests + + sqlite3 $WRT_DB "${INS_ALL_WIDGETEXT} VALUES(2000, 'share_href_2000', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGETEXT} VALUES(2001, 'share_href_2001', 0)"; + sqlite3 $WRT_DB "insert into WidgetExtendedInfo(app_id) VALUES(2002)"; + sqlite3 $WRT_DB "insert into WidgetExtendedInfo(app_id) VALUES(2003)"; + + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC} VALUES(2000, 'en', 'w_name_2000_en', 'w_shortname_2000_en', 'w_desc_2000_en', 'w_lic_2000_en', 'w_licf_2000_en', 'w_lic_href_2000_en')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC} VALUES(2000, 'pl', 'w_name_2000_pl', 'w_shortname_2000_pl', 'w_desc_2000_pl', 'w_lic_2000_pl', 'w_licf_2000_pl', 'w_lic_href_2000_pl')"; + sqlite3 $WRT_DB "insert into LocalizedWidgetInfo(app_id, widget_locale) VALUES(2002, 'en')"; + sqlite3 $WRT_DB "insert into LocalizedWidgetInfo(app_id, widget_locale) VALUES(2003, 'en')"; + + sqlite3 $WRT_DB "${INS_ALL_WIDGET_ICONS} VALUES(2000, 'icon_src_2000', 50, 50)"; + sqlite3 $WRT_DB "insert into WidgetIcon(app_id, icon_src) VALUES(2002, 'icon_src_2002')"; + + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_ICONS} VALUES(2000, 1, 'en')"; + + sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2000, 'start_file_2000')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2001, 'start_file_2001')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2002, 'start_file_2002')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2003, 'start_file_2003')"; + + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2000, 1, 'en', '', '')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2001, 2, 'en', '', '')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2002, 3, 'en', '', '')"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2003, 4, 'en', '', '')"; + + #widget properties + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2000, 'key1_for_2000', 'value_for_key1_2000', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2000, 'key2_for_2000', 'value_for_key2_2000', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2001, 'key1_for_2001', 'value1_for_key_2001', 1)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2002, 'key1_for_2002', 'value1_for_key_2002', 0)"; + sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES(2002, 'key2_for_2002', 'value2_for_key_2002', 1)"; + + #create if not exists and fix autoincrement value + sqlite3 $WRT_DB "INSERT INTO WidgetInfo(pkgname) VALUES('temp')"; + sqlite3 $WRT_DB "DELETE FROM WidgetInfo WHERE pkgname = 'temp'"; + sqlite3 $WRT_DB "UPDATE sqlite_sequence SET seq = 2004 WHERE name = 'WidgetInfo'"; + + exit $? + +elif [ "x$1" == "xstop" ]; then + echo stop; + cp $WRT_DB_BCK $WRT_DB + exit $? +else + exit 1 +fi -- 2.7.4