From 41fd2c7561243d75ff33ca4e80248e9982b7072c Mon Sep 17 00:00:00 2001 From: Zbigniew Kostrzewa Date: Tue, 16 Jul 2013 14:41:34 +0200 Subject: [PATCH] Extract IANA language tags into a separate DB. [Issue#] N/A [Problem] Could not restrict access to iana_records table only. [Cause] N/A [Solution] Extract iana_records table into a separate DB. [Verification] 1. Build repository 2. Run command `wrt-commons-tests-i18n --output=text` Change-Id: Iacfec548485f5742a0c9fbf5f4596d4d3de8c3d5 --- CMakeLists.txt | 1 + build/CMakeLists.txt | 1 + build/i18n/CMakeLists.txt | 20 ++++++++ build/i18n/wrt-commons-i18n-dao-ro.pc.in | 12 +++++ etc/wrt_commons_create_clean_db.sh | 2 +- modules/CMakeLists.txt | 1 + modules/i18n/CMakeLists.txt | 1 + modules/i18n/dao/CMakeLists.txt | 59 ++++++++++++++++++++++ .../wrt-commons/i18n-dao-ro/i18n_dao_read_only.h | 39 ++++++++++++++ .../wrt-commons/i18n-dao-ro/i18n_database.h | 56 ++++++++++++++++++++ modules/i18n/dao/orm/gen_db_md5.sh | 19 +++++++ modules/i18n/dao/orm/i18n_db_definitions | 6 +++ modules/i18n/dao/orm/i18n_db_sql_generator.h | 27 ++++++++++ modules/{widget_dao => i18n/dao}/orm/iana_db | 0 modules/i18n/dao/orm/orm_generator_i18n.h | 24 +++++++++ modules/i18n/dao/orm/version_db | 5 ++ modules/i18n/dao/src/i18n_dao_read_only.cpp | 45 +++++++++++++++++ modules/i18n/dao/src/i18n_database.cpp | 43 ++++++++++++++++ modules/widget_dao/CMakeLists.txt | 4 +- modules/widget_dao/dao/global_dao_read_only.cpp | 14 ----- .../include/dpl/wrt-dao-ro/global_dao_read_only.h | 2 - modules/widget_dao/orm/wrt_db_definitions | 1 - packaging/wrt-commons.spec | 2 + tests/CMakeLists.txt | 1 + tests/i18n/CMakeLists.txt | 40 +++++++++++++++ tests/i18n/main.cpp | 28 ++++++++++ tests/i18n/test_i18n_dao_read_only.cpp | 53 +++++++++++++++++++ 27 files changed, 485 insertions(+), 21 deletions(-) create mode 100644 build/i18n/CMakeLists.txt create mode 100644 build/i18n/wrt-commons-i18n-dao-ro.pc.in create mode 100644 modules/i18n/CMakeLists.txt create mode 100644 modules/i18n/dao/CMakeLists.txt create mode 100644 modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h create mode 100644 modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_database.h create mode 100755 modules/i18n/dao/orm/gen_db_md5.sh create mode 100644 modules/i18n/dao/orm/i18n_db_definitions create mode 100644 modules/i18n/dao/orm/i18n_db_sql_generator.h rename modules/{widget_dao => i18n/dao}/orm/iana_db (100%) create mode 100644 modules/i18n/dao/orm/orm_generator_i18n.h create mode 100644 modules/i18n/dao/orm/version_db create mode 100644 modules/i18n/dao/src/i18n_dao_read_only.cpp create mode 100644 modules/i18n/dao/src/i18n_database.cpp create mode 100644 tests/i18n/CMakeLists.txt create mode 100644 tests/i18n/main.cpp create mode 100644 tests/i18n/test_i18n_dao_read_only.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 746e7b7..fe837ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,7 @@ SET(TARGET_SECURITY_ORIGIN_DAO_LIB "wrt-commons-security-origin-dao") SET(TARGET_CERTIFICATE_DAO_LIB "wrt-commons-certificate-dao") SET(TARGET_DPL_UTILS_EFL "lib${PROJECT_NAME}-utils-efl") SET(TARGET_DPL_ENCRYPTION "lib${PROJECT_NAME}-encryption") +SET(TARGET_I18N_DAO_RO_LIB "wrt-commons-i18n-dao-ro") macro(configure_and_install_pkg PKG_FILE) CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index d151c82..852127c 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -33,3 +33,4 @@ ADD_SUBDIRECTORY(utils) ADD_SUBDIRECTORY(support) ADD_SUBDIRECTORY(encryption) ADD_SUBDIRECTORY(certificate_dao) +ADD_SUBDIRECTORY(i18n) diff --git a/build/i18n/CMakeLists.txt b/build/i18n/CMakeLists.txt new file mode 100644 index 0000000..3d97f54 --- /dev/null +++ b/build/i18n/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2012 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 Zbigniew Kostrzewa (z.kostrzewa@samsung.com) +# @brief +# + +configure_and_install_pkg(wrt-commons-i18n-dao-ro.pc) diff --git a/build/i18n/wrt-commons-i18n-dao-ro.pc.in b/build/i18n/wrt-commons-i18n-dao-ro.pc.in new file mode 100644 index 0000000..270630b --- /dev/null +++ b/build/i18n/wrt-commons-i18n-dao-ro.pc.in @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} + +libdir=${prefix}/lib +includedir=${prefix}/include +Name: wrt-commons-i18n-dao-ro +Description: wrt-commons-i18n-dao-ro + +Version: @VERSION@ +Requires: dpl-efl +Libs: -lwrt-commons-i18n-dao-ro -L${libdir} +Cflags: -I${includedir}/dpl-efl diff --git a/etc/wrt_commons_create_clean_db.sh b/etc/wrt_commons_create_clean_db.sh index bb8d16e..893631c 100755 --- a/etc/wrt_commons_create_clean_db.sh +++ b/etc/wrt_commons_create_clean_db.sh @@ -66,7 +66,7 @@ do create_db $name $DB_PATH done -for name in wrt_custom_handler +for name in wrt_custom_handler wrt_i18n do create_db $name $DB_USER_PATH done diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 20f132c..4467c2c 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -31,6 +31,7 @@ ADD_SUBDIRECTORY(widget_dao) ADD_SUBDIRECTORY(security_origin_dao) ADD_SUBDIRECTORY(custom_handler_dao) ADD_SUBDIRECTORY(certificate_dao) +ADD_SUBDIRECTORY(i18n) include(utils/config.cmake) include(localization/config.cmake) include(support/config.cmake) diff --git a/modules/i18n/CMakeLists.txt b/modules/i18n/CMakeLists.txt new file mode 100644 index 0000000..9b1b175 --- /dev/null +++ b/modules/i18n/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(dao) diff --git a/modules/i18n/dao/CMakeLists.txt b/modules/i18n/dao/CMakeLists.txt new file mode 100644 index 0000000..c7b5ada --- /dev/null +++ b/modules/i18n/dao/CMakeLists.txt @@ -0,0 +1,59 @@ +SET(TARGET_I18N_DAO_DB "Sqlite3DbI18n") + +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_BINARY_DIR}/modules/i18n/dao/database_checksum_i18n.h + COMMAND ${CMAKE_SOURCE_DIR}/modules/i18n/dao/orm/gen_db_md5.sh + ARGS ${CMAKE_BINARY_DIR}/modules/i18n/dao/database_checksum_i18n.h + ${CMAKE_SOURCE_DIR}/modules/i18n/dao/orm/iana_db + DEPENDS ${CMAKE_SOURCE_DIR}/modules/i18n/dao/orm/iana_db + ${CMAKE_SOURCE_DIR}/modules/i18n/dao/orm/gen_db_md5.sh + COMMENT "Generating WRT i18n database checksum" + ) + +ADD_CUSTOM_COMMAND( OUTPUT .wrt_i18n.db + COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.wrt_i18n.db + COMMAND gcc -Wall -include ${CMAKE_BINARY_DIR}/modules/i18n/dao/database_checksum_i18n.h -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/i18n/dao/orm -E ${PROJECT_SOURCE_DIR}/modules/i18n/dao/orm/i18n_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/wrt_i18n_db.sql + COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.wrt_i18n.db ".read ${CMAKE_CURRENT_BINARY_DIR}/wrt_i18n_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.wrt_i18n.db + DEPENDS ${CMAKE_BINARY_DIR}/modules/i18n/dao/database_checksum_i18n.h ${PROJECT_SOURCE_DIR}/modules/i18n/dao/orm/i18n_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/i18n/dao/orm/iana_db + ) + +ADD_CUSTOM_COMMAND( OUTPUT .wrt_i18n.db-journal + COMMAND touch + ARGS ${CMAKE_CURRENT_BINARY_DIR}/.wrt_i18n.db-journal + ) + +ADD_CUSTOM_TARGET(${TARGET_I18N_DAO_DB} ALL DEPENDS .wrt_i18n.db .wrt_i18n.db-journal) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/wrt_i18n_db.sql DESTINATION share/wrt-engine/) + +############################################################################### + +SET(I18N_DAO_INCLUDE_DIRS + ${PROJECT_SOURCE_DIR}/modules/i18n/dao/include + ${PROJECT_SOURCE_DIR}/modules/i18n/dao/orm + ${PROJECT_SOURCE_DIR}/modules/core/include + ${PROJECT_SOURCE_DIR}/modules/db/include + ${PROJECT_SOURCE_DIR}/modules/log/include +) + + +SET(I18N_DAO_RO_SOURCES + src/i18n_database.cpp + src/i18n_dao_read_only.cpp +) + +INCLUDE_DIRECTORIES(${I18N_DAO_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${I18N_DAO_DEPS_INCLUDE_DIRS}) + +ADD_LIBRARY(${TARGET_I18N_DAO_RO_LIB} SHARED ${I18N_DAO_RO_SOURCES}) +SET_TARGET_PROPERTIES(${TARGET_I18N_DAO_RO_LIB} PROPERTIES SOVERSION ${API_VERSION} VERSION ${VERSION}) +SET_TARGET_PROPERTIES(${TARGET_I18N_DAO_RO_LIB} PROPERTIES COMPILE_FLAGS "-include ${CMAKE_BINARY_DIR}/modules/i18n/dao/database_checksum_i18n.h") +TARGET_LINK_LIBRARIES(${TARGET_I18N_DAO_RO_LIB} ${TARGET_DPL_DB_EFL}) +ADD_DEPENDENCIES(${TARGET_I18N_DAO_RO_LIB} ${TARGET_I18N_DAO_DB}) + +INSTALL(TARGETS ${TARGET_I18N_DAO_RO_LIB} DESTINATION lib) + +INSTALL(FILES + include/wrt-commons/i18n-dao-ro/i18n_database.h + include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h + DESTINATION include/dpl-efl/wrt-commons/i18n-dao-ro +) diff --git a/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h b/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h new file mode 100644 index 0000000..7e8ef9d --- /dev/null +++ b/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012 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. + */ +/** + * This file contains the declaration of i18n dao namespace. + * + * @file i18n_dao_read_only.h + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief This file contains the declaration of i18n dao. + */ + +#ifndef _I18N_DAO_READ_ONLY_H_ +#define _I18N_DAO_READ_ONLY_H_ + +#include + +namespace I18n { +namespace DB { +namespace I18nDAOReadOnly { +bool IsValidSubTag(const DPL::String& tag, int type); +} // namespace I18nDAOReadOnly +} // namespace DB +} // namespace I18n + +#endif // _I18N_DAO_READ_ONLY_H_ + diff --git a/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_database.h b/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_database.h new file mode 100644 index 0000000..3492f63 --- /dev/null +++ b/modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_database.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012 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. + */ + +#ifndef _I18N_DATABASE_H_ +#define _I18N_DATABASE_H_ + +#include +#include +#include + +namespace I18n { +namespace DB { +namespace Interface { +void attachDatabaseRO(); +void detachDatabase(); + +extern DPL::Mutex g_dbQueriesMutex; +extern DPL::DB::ThreadDatabaseSupport g_dbInterface; +} // namespace Interface +} // namespace DB +} // namespace I18n + +#define I18N_DB_INTERNAL(tlsCommand, InternalType) \ + static DPL::ThreadLocalVariable *tlsCommand##Ptr = NULL; \ + { \ + DPL::Mutex::ScopedLock lock( \ + &I18n::DB::Interface::g_dbQueriesMutex); \ + if (!tlsCommand##Ptr) { \ + static DPL::ThreadLocalVariable tmp; \ + tlsCommand##Ptr = &tmp; \ + } \ + } \ + DPL::ThreadLocalVariable &tlsCommand = *tlsCommand##Ptr; \ + if (tlsCommand.IsNull()) \ + { \ + tlsCommand = InternalType(&I18n::DB::Interface::g_dbInterface); \ + } + +#define I18N_DB_SELECT(name, type) \ + I18N_DB_INTERNAL(name, type::Select) + +#endif /* _I18N_DATABASE_H_ */ + diff --git a/modules/i18n/dao/orm/gen_db_md5.sh b/modules/i18n/dao/orm/gen_db_md5.sh new file mode 100755 index 0000000..22c2530 --- /dev/null +++ b/modules/i18n/dao/orm/gen_db_md5.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (c) 2012 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. +# +CHECKSUM=`cat ${2} ${3} 2>/dev/null | md5sum 2>/dev/null | cut -d\ -f1 2>/dev/null` +echo "#define DB_CHECKSUM DB_VERSION_${CHECKSUM}" > ${1} +echo "#define DB_CHECKSUM_STR \"DB_VERSION_${CHECKSUM}\"" >> ${1} + diff --git a/modules/i18n/dao/orm/i18n_db_definitions b/modules/i18n/dao/orm/i18n_db_definitions new file mode 100644 index 0000000..ee94c0a --- /dev/null +++ b/modules/i18n/dao/orm/i18n_db_definitions @@ -0,0 +1,6 @@ +DATABASE_START(i18n) + +#include "iana_db" +#include "version_db" + +DATABASE_END() diff --git a/modules/i18n/dao/orm/i18n_db_sql_generator.h b/modules/i18n/dao/orm/i18n_db_sql_generator.h new file mode 100644 index 0000000..d8f326d --- /dev/null +++ b/modules/i18n/dao/orm/i18n_db_sql_generator.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 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 i18n_db_sql_generator.h + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief Macro definitions for generating the SQL + * input file from database definition. + */ + +//Do not include this file directly! It is used only for SQL code generation. +#include + +#include "i18n_db_definitions" diff --git a/modules/widget_dao/orm/iana_db b/modules/i18n/dao/orm/iana_db similarity index 100% rename from modules/widget_dao/orm/iana_db rename to modules/i18n/dao/orm/iana_db diff --git a/modules/i18n/dao/orm/orm_generator_i18n.h b/modules/i18n/dao/orm/orm_generator_i18n.h new file mode 100644 index 0000000..53cfea3 --- /dev/null +++ b/modules/i18n/dao/orm/orm_generator_i18n.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012 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. + */ + +#ifndef _ORM_GENERATOR_I18N_H_ +#define _ORM_GENERATOR_I18N_H_ + +#define ORM_GENERATOR_DATABASE_NAME i18n_db_definitions +#include +#undef ORM_GENERATOR_DATABASE_NAME + +#endif // _ORM_GENERATOR_I18N_H_ diff --git a/modules/i18n/dao/orm/version_db b/modules/i18n/dao/orm/version_db new file mode 100644 index 0000000..7e20d8d --- /dev/null +++ b/modules/i18n/dao/orm/version_db @@ -0,0 +1,5 @@ +SQL( + BEGIN TRANSACTION; + CREATE TABLE DB_CHECKSUM (version INT); + COMMIT; +) diff --git a/modules/i18n/dao/src/i18n_dao_read_only.cpp b/modules/i18n/dao/src/i18n_dao_read_only.cpp new file mode 100644 index 0000000..19822ff --- /dev/null +++ b/modules/i18n/dao/src/i18n_dao_read_only.cpp @@ -0,0 +1,45 @@ +/* + * 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. + */ +/** + * This file contains the definition of i18n dao namespace. + * + * @file i18n_dao_read_only.cpp + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief This file contains the definition of i18n dao + */ + +#include +#include + +#include + +using namespace DPL::DB::ORM; +using namespace DPL::DB::ORM::i18n; + +namespace I18n { +namespace DB { +namespace I18nDAOReadOnly { +bool IsValidSubTag(const DPL::String& tag, int type) +{ + I18N_DB_SELECT(select, iana_records) + select->Where(And(Equals(tag), + Equals(type))); + return !select->GetRowList().empty(); +} +} +} +} diff --git a/modules/i18n/dao/src/i18n_database.cpp b/modules/i18n/dao/src/i18n_database.cpp new file mode 100644 index 0000000..e1a1fc5 --- /dev/null +++ b/modules/i18n/dao/src/i18n_database.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 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. + */ +#include + +namespace I18n { +namespace DB { +namespace Interface { +namespace { +const char* const I18N_DB_FILE_PATH = "/opt/usr/dbspace/.wrt_i18n.db"; + +DPL::DB::SqlConnection::Flag::Type I18N_DB_FLAGS = + DPL::DB::SqlConnection::Flag::UseLucene; +} + +DPL::Mutex g_dbQueriesMutex; +DPL::DB::ThreadDatabaseSupport g_dbInterface(I18N_DB_FILE_PATH, + I18N_DB_FLAGS); + +void attachDatabaseRO() +{ + g_dbInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RO); +} + +void detachDatabase() +{ + g_dbInterface.DetachFromThread(); +} +} //namespace Interface +} //namespace DB +} //namespace I18n diff --git a/modules/widget_dao/CMakeLists.txt b/modules/widget_dao/CMakeLists.txt index d62ee17..141a29f 100755 --- a/modules/widget_dao/CMakeLists.txt +++ b/modules/widget_dao/CMakeLists.txt @@ -5,9 +5,7 @@ ADD_CUSTOM_COMMAND( COMMAND ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/gen_db_md5.sh ARGS ${CMAKE_BINARY_DIR}/modules/widget_dao/database_checksum.h ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/wrt_db - ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/iana_db DEPENDS ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/wrt_db - ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/iana_db ${CMAKE_SOURCE_DIR}/modules/widget_dao/orm/gen_db_md5.sh COMMENT "Generating WRT database checksum" ) @@ -16,7 +14,7 @@ ADD_CUSTOM_COMMAND( OUTPUT .wrt.db COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.wrt.db COMMAND gcc -Wall -include ${CMAKE_BINARY_DIR}/modules/widget_dao/database_checksum.h -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/widget_dao/orm -E ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/wrt_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/wrt_db.sql COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.wrt.db ".read ${CMAKE_CURRENT_BINARY_DIR}/wrt_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.wrt.db - DEPENDS ${CMAKE_BINARY_DIR}/modules/widget_dao/database_checksum.h ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/wrt_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/wrt_db ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/iana_db + DEPENDS ${CMAKE_BINARY_DIR}/modules/widget_dao/database_checksum.h ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/wrt_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/widget_dao/orm/wrt_db ) ADD_CUSTOM_COMMAND( OUTPUT .wrt.db-journal diff --git a/modules/widget_dao/dao/global_dao_read_only.cpp b/modules/widget_dao/dao/global_dao_read_only.cpp index 968839b..071ca43 100644 --- a/modules/widget_dao/dao/global_dao_read_only.cpp +++ b/modules/widget_dao/dao/global_dao_read_only.cpp @@ -41,20 +41,6 @@ bool GlobalDAOReadOnly::GetSecureByDefault() return select->GetSingleValue(); } -bool GlobalDAOReadOnly::IsValidSubTag(const DPL::String& tag, int type) -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::wrt; - WRT_DB_SELECT(select, iana_records, &WrtDatabase::interface()) - select->Where(Equals(tag)); - auto row = select->GetRowList(); - if (row.empty() || row.front().Get_TYPE() != type) { - return false; - } else { - return true; - } -} - GlobalDAOReadOnly::NetworkAccessMode GlobalDAOReadOnly::GetHomeNetworkDataUsage() { diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/global_dao_read_only.h b/modules/widget_dao/include/dpl/wrt-dao-ro/global_dao_read_only.h index a3560a4..0206e89 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/global_dao_read_only.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/global_dao_read_only.h @@ -55,8 +55,6 @@ class GlobalDAOReadOnly public: - static bool IsValidSubTag(const DPL::String& tag, int type); - static bool GetSecureByDefault(); static WidgetAccessInfoList GetWhiteURIList(); diff --git a/modules/widget_dao/orm/wrt_db_definitions b/modules/widget_dao/orm/wrt_db_definitions index 1e2200e..f2a4a2e 100644 --- a/modules/widget_dao/orm/wrt_db_definitions +++ b/modules/widget_dao/orm/wrt_db_definitions @@ -1,7 +1,6 @@ DATABASE_START(wrt) #include "wrt_db" -#include "iana_db" #include "version_db" DATABASE_END() diff --git a/packaging/wrt-commons.spec b/packaging/wrt-commons.spec index 8939a1d..75cd398 100644 --- a/packaging/wrt-commons.spec +++ b/packaging/wrt-commons.spec @@ -132,6 +132,8 @@ chsmack -a 'wrt-commons::db_wrt' /opt/dbspace/.wrt.db chsmack -a 'wrt-commons::db_wrt' /opt/dbspace/.wrt.db-journal chsmack -a 'wrt-commons::db_wrt' /opt/usr/dbspace/.wrt_custom_handler.db chsmack -a 'wrt-commons::db_wrt' /opt/usr/dbspace/.wrt_custom_handler.db-journal +chsmack -a 'wrt-commons::db_wrt_i18n' /opt/usr/dbspace/.wrt_i18n.db +chsmack -a 'wrt-commons::db_wrt_i18n' /opt/usr/dbspace/.wrt_i18n.db-journal echo "[WRT] wrt-commons postinst done ..." diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b271d5c..50227c7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ ADD_SUBDIRECTORY(event) ADD_SUBDIRECTORY(files_localization) ADD_SUBDIRECTORY(localizationTagsProvider) ADD_SUBDIRECTORY(utils) +ADD_SUBDIRECTORY(i18n) IF(WITH_CHILD) MESSAGE(STATUS "Additional test subdirectory is being added") diff --git a/tests/i18n/CMakeLists.txt b/tests/i18n/CMakeLists.txt new file mode 100644 index 0000000..9a90b43 --- /dev/null +++ b/tests/i18n/CMakeLists.txt @@ -0,0 +1,40 @@ +# 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 Zbigniew Kostrzewa (z.kostrzewa@samsung.com) +# @version 1.0 +# @brief +# + +# +# Test files +# +# Define all DPL tests sources. +# Runner is responsible for runnint it all and +# generating proper output files +# + +SET(TARGET_NAME "wrt-commons-tests-i18n") + +# Set DPL tests sources +SET(DPL_TESTS_I18N_SOURCES + ${TESTS_DIR}/i18n/main.cpp + ${TESTS_DIR}/i18n/test_i18n_dao_read_only.cpp +) + +#include subdirectory +WRT_TEST_ADD_INTERNAL_DEPENDENCIES(${TARGET_NAME} ${TARGET_I18N_DAO_RO_LIB}) +WRT_TEST_BUILD(${TARGET_NAME} ${DPL_TESTS_I18N_SOURCES}) +WRT_TEST_INSTALL(${TARGET_NAME}) diff --git a/tests/i18n/main.cpp b/tests/i18n/main.cpp new file mode 100644 index 0000000..4ed6191 --- /dev/null +++ b/tests/i18n/main.cpp @@ -0,0 +1,28 @@ +/* + * 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 main.cpp + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of main. + */ + +#include + +int main(int argc, char *argv[]) +{ + return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); +} diff --git a/tests/i18n/test_i18n_dao_read_only.cpp b/tests/i18n/test_i18n_dao_read_only.cpp new file mode 100644 index 0000000..57dfe2d --- /dev/null +++ b/tests/i18n/test_i18n_dao_read_only.cpp @@ -0,0 +1,53 @@ +/* + * 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 test_i18n_dao_read_only.cpp + * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) + * @version 1.0 + * @brief This file is the implementation file of i18n dao tests + */ +#include +#include +#include +#include + +RUNNER_TEST_GROUP_INIT(I18N) + +/* +Name: I18nDAOReadOnly_IsValidSubTag_True +Description: Test valid IANA subtag presence +Expected: Subtag found +*/ +RUNNER_TEST(I18nDAOReadOnly_IsValidSubTag_True) +{ + I18n::DB::Interface::attachDatabaseRO(); + bool result = I18n::DB::I18nDAOReadOnly::IsValidSubTag(L"aa", 0); + I18n::DB::Interface::detachDatabase(); + RUNNER_ASSERT_MSG(result, "Subtag not found"); +} + +/* +Name: I18nDAOReadOnly_IsValidSubTag_False +Description: Test invalid IANA subtag presence +Expected: Subtag not found +*/ +RUNNER_TEST(I18nDAOReadOnly_IsValidSubTag_False) +{ + I18n::DB::Interface::attachDatabaseRO(); + bool result = I18n::DB::I18nDAOReadOnly::IsValidSubTag(L"xxx000xxx", -1); + I18n::DB::Interface::detachDatabase(); + RUNNER_ASSERT_MSG(!result, "Subtag found"); +} -- 2.7.4