From 46e90ca889a55db5d5d6b14c54dac14b85ae4392 Mon Sep 17 00:00:00 2001 From: Zbigniew Kostrzewa Date: Fri, 19 Jul 2013 09:49:17 +0200 Subject: [PATCH] Utilize extracted i18n db in LanguageSubtagRstTree. [Issue#] N/A [Problem] iana_records table, on which LanguageSubtagRstTree relies, has been extracted into a separate DB [Cause] N/A [Solution] utilize new DB (replace references from GlobalDAOReadOnly to I18nDAOReadOnly) [SCMRequest] Depends on: https://review.tizendev.org/82091 [Verification] 1. Build repository 2. Run command `wrt-installer-tests-general --output=text` Pay attention espaecially to test cases ValidateLanguageTag_Invalid and ValidateLanguageTag_Valid; however, run whole test suite. Change-Id: Ie6d82b26e8effc0d62eaaba0701c122e50172154 --- packaging/wrt-installer.spec | 1 + src/wrt-installer/CMakeLists.txt | 1 + src/wrt-installer/language_subtag_rst_tree.cpp | 84 ++++++++++++++++++-------- tests/general/CMakeLists.txt | 26 ++++++-- tests/general/LanguageSubtagRstTreeTests.cpp | 55 +++++++++++++++++ 5 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 tests/general/LanguageSubtagRstTreeTests.cpp diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 41dbc01..6616545 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -19,6 +19,7 @@ BuildRequires: pkgconfig(dpl-event-efl) BuildRequires: pkgconfig(dpl-utils-efl) BuildRequires: pkgconfig(dpl-wrt-dao-ro) BuildRequires: pkgconfig(dpl-wrt-dao-rw) +BuildRequires: pkgconfig(wrt-commons-i18n-dao-ro) BuildRequires: pkgconfig(security-install) BuildRequires: pkgconfig(ecore-x) BuildRequires: pkgconfig(xmlsec1) diff --git a/src/wrt-installer/CMakeLists.txt b/src/wrt-installer/CMakeLists.txt index 7fef88f..0bd83bb 100644 --- a/src/wrt-installer/CMakeLists.txt +++ b/src/wrt-installer/CMakeLists.txt @@ -43,6 +43,7 @@ PKG_CHECK_MODULES(WRT_INSTALLER_DEPS pkgmgr-info pkgmgr security-install + wrt-commons-i18n-dao-ro REQUIRED) INCLUDE_DIRECTORIES( diff --git a/src/wrt-installer/language_subtag_rst_tree.cpp b/src/wrt-installer/language_subtag_rst_tree.cpp index 8bf901f..291c67d 100644 --- a/src/wrt-installer/language_subtag_rst_tree.cpp +++ b/src/wrt-installer/language_subtag_rst_tree.cpp @@ -22,13 +22,17 @@ #include #include #include -#include +#include +#include +#include #include #include #include #include IMPLEMENT_SINGLETON(LanguageSubtagRstTree) +namespace I18nDAOReadOnly = I18n::DB::I18nDAOReadOnly; + bool LanguageSubtagRstTree::ValidateLanguageTag(const std::string &tag_input) { std::string tag = tag_input; @@ -40,57 +44,82 @@ bool LanguageSubtagRstTree::ValidateLanguageTag(const std::string &tag_input) std::back_inserter(parts), false); std::vector::iterator token = parts.begin(); - if (token == parts.end()) { + if (token == parts.end()) + { return false; } - if (WrtDB::GlobalDAOReadOnly::IsValidSubTag(*token, - RECORD_TYPE_LANGUAGE)) + + I18n::DB::Interface::attachDatabaseRO(); + DPL_SCOPE_EXIT() + { + I18n::DB::Interface::detachDatabase(); + }; + + if (I18nDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_LANGUAGE)) { ++token; - } else { + } + else + { return false; } - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - if (WrtDB::GlobalDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_EXTLANG)) { + + if (I18nDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_EXTLANG)) + { ++token; } - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - if (WrtDB::GlobalDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_SCRIPT)) { + + if (I18nDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_SCRIPT)) + { ++token; } - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - if (WrtDB::GlobalDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_REGION)) { + + if (I18nDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_REGION)) + { ++token; } - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - while (token != parts.end()) { - if (WrtDB::GlobalDAOReadOnly::IsValidSubTag( - *token, RECORD_TYPE_VARIANT)) + + while (token != parts.end()) + { + if (I18nDAOReadOnly::IsValidSubTag(*token, RECORD_TYPE_VARIANT)) { ++token; - } else { + } + else + { break; } } //'u' - unicode extension - only one BCP47 extension is registered. //TODO: unicode extension should be also validated (l.wrzosek) - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - if (*token == L"u") { + + if (*token == L"u") + { ++token; bool one_or_more = false; while (token != parts.end() && @@ -100,16 +129,20 @@ bool LanguageSubtagRstTree::ValidateLanguageTag(const std::string &tag_input) one_or_more = true; ++token; } - if (!one_or_more) { + if (!one_or_more) + { return false; } } //'x' - privateuse - if (token == parts.end()) { + if (token == parts.end()) + { return true; } - if (*token == L"x") { + + if (*token == L"x") + { ++token; bool one_or_more = false; while (token != parts.end() && @@ -119,18 +152,21 @@ bool LanguageSubtagRstTree::ValidateLanguageTag(const std::string &tag_input) one_or_more = true; ++token; } - if (!one_or_more) { + if (!one_or_more) + { return false; } } - if (token == parts.end()) { + if (token == parts.end()) + { return true; } //Try private use now: token = parts.begin(); - if (*token == L"x") { + if (*token == L"x") + { ++token; bool one_or_more = false; while (token != parts.end() && diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt index 74272b1..376170b 100644 --- a/tests/general/CMakeLists.txt +++ b/tests/general/CMakeLists.txt @@ -59,6 +59,13 @@ INCLUDE_DIRECTORIES(${COMMON_LIB_PKGS_INCLUDE_DIRS}) ADD_LIBRARY(${WRT_TEST_LIBRARY} STATIC ${WRT_DETAIL_SOURCES}) + +SET(INSTALLER_TESTS_TARGET "wrt-installer-tests-general") + +PKG_CHECK_MODULES(INSTALLER_TESTS_DEPS + wrt-commons-i18n-dao-ro + REQUIRED) + SET(INSTALLER_TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/TestInit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ManifestTests.cpp @@ -68,16 +75,18 @@ SET(INSTALLER_TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ParsingTizenAppcontrolTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/WidgetUpdateTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PluginsInstallation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LanguageSubtagRstTreeTests.cpp + ${CMAKE_SOURCE_DIR}/src/wrt-installer/language_subtag_rst_tree.cpp ) -SET(INSTALLER_TESTS_TARGET "wrt-installer-tests-general") +SET(INSTALLER_TESTS_INCLUDE_DIRS + ${INSTALLER_TESTS_DEPS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src/wrt-installer +) # 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}" ${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) @@ -94,6 +103,9 @@ FUNCTION(WRT_TEST_BUILD TARGET_NAME) ${TEST_LIBRARY_DIRS} ) + SET(SOURCES "${ARGN}") + ADD_EXECUTABLE("${TARGET_NAME}" ${SOURCES}) + # get link libraries global property GET_PROPERTY(LINK_LIBRARIES GLOBAL PROPERTY TESTS_LIBRARIES) GET_PROPERTY(TEST_LIBRARIES GLOBAL PROPERTY ${TARGET_NAME}_LIBRARIES) @@ -120,6 +132,11 @@ FUNCTION(WRT_TEST_INSTALL) ) ENDFUNCTION(WRT_TEST_INSTALL) +FUNCTION(WRT_TEST_INCLUDE_DIRS TARGET_NAME) + SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_INCLUDE_DIRS ${ARGN}) +ENDFUNCTION(WRT_TEST_INCLUDE_DIRS) + +WRT_TEST_INCLUDE_DIRS(${INSTALLER_TESTS_TARGET} ${INSTALLER_TESTS_INCLUDE_DIRS}) WRT_TEST_BUILD(${INSTALLER_TESTS_TARGET} ${INSTALLER_TESTS_SOURCES}) WRT_TEST_INSTALL(${INSTALLER_TESTS_TARGET}) target_link_libraries(${INSTALLER_TESTS_TARGET} @@ -128,6 +145,7 @@ target_link_libraries(${INSTALLER_TESTS_TARGET} ${WRT_TEST_LIBRARY} ${TARGET_CORE_MODULE_LIB} ${COMMON_LIB_PKGS_LIBRARIES} + ${INSTALLER_TESTS_DEPS_LIBRARIES} ) #widgets diff --git a/tests/general/LanguageSubtagRstTreeTests.cpp b/tests/general/LanguageSubtagRstTreeTests.cpp new file mode 100644 index 0000000..bd05f87 --- /dev/null +++ b/tests/general/LanguageSubtagRstTreeTests.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013 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 LanguageSubtagRstTreeTests.cpp + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief Language tags tests + */ + +#include +#include + +namespace { +const char LANGUAGE_TAG_VALID[] = "en-us"; +const char LANGUAGE_TAG_INVALID[] = "invalid0"; +} + +//////////////////////////////////////////////////////////////////////////////// + +RUNNER_TEST_GROUP_INIT(LanguageSubtagRstTree) + +/* +Name: ValidateLanguageTag_Valid +Description: tests result returned for valid language tag +Expected: value true should be returned +*/ +RUNNER_TEST(ValidateLanguageTag_Valid) +{ + RUNNER_ASSERT(LanguageSubtagRstTreeSingleton::Instance(). + ValidateLanguageTag(LANGUAGE_TAG_VALID)); +} + +/* +Name: ValidateLanguageTag_Invalid +Description: tests result returned for invalid language tag +Expected: value false should be returned +*/ +RUNNER_TEST(ValidateLanguageTag_Invalid) +{ + RUNNER_ASSERT(!LanguageSubtagRstTreeSingleton::Instance(). + ValidateLanguageTag(LANGUAGE_TAG_INVALID)); +} -- 2.7.4