Extract IANA language tags into a separate DB.
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Tue, 16 Jul 2013 12:41:34 +0000 (14:41 +0200)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Mon, 22 Jul 2013 05:34:08 +0000 (05:34 +0000)
[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

27 files changed:
CMakeLists.txt
build/CMakeLists.txt
build/i18n/CMakeLists.txt [new file with mode: 0644]
build/i18n/wrt-commons-i18n-dao-ro.pc.in [new file with mode: 0644]
etc/wrt_commons_create_clean_db.sh
modules/CMakeLists.txt
modules/i18n/CMakeLists.txt [new file with mode: 0644]
modules/i18n/dao/CMakeLists.txt [new file with mode: 0644]
modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_dao_read_only.h [new file with mode: 0644]
modules/i18n/dao/include/wrt-commons/i18n-dao-ro/i18n_database.h [new file with mode: 0644]
modules/i18n/dao/orm/gen_db_md5.sh [new file with mode: 0755]
modules/i18n/dao/orm/i18n_db_definitions [new file with mode: 0644]
modules/i18n/dao/orm/i18n_db_sql_generator.h [new file with mode: 0644]
modules/i18n/dao/orm/iana_db [moved from modules/widget_dao/orm/iana_db with 100% similarity]
modules/i18n/dao/orm/orm_generator_i18n.h [new file with mode: 0644]
modules/i18n/dao/orm/version_db [new file with mode: 0644]
modules/i18n/dao/src/i18n_dao_read_only.cpp [new file with mode: 0644]
modules/i18n/dao/src/i18n_database.cpp [new file with mode: 0644]
modules/widget_dao/CMakeLists.txt
modules/widget_dao/dao/global_dao_read_only.cpp
modules/widget_dao/include/dpl/wrt-dao-ro/global_dao_read_only.h
modules/widget_dao/orm/wrt_db_definitions
packaging/wrt-commons.spec
tests/CMakeLists.txt
tests/i18n/CMakeLists.txt [new file with mode: 0644]
tests/i18n/main.cpp [new file with mode: 0644]
tests/i18n/test_i18n_dao_read_only.cpp [new file with mode: 0644]

index 746e7b7..fe837ef 100644 (file)
@@ -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)
index d151c82..852127c 100644 (file)
@@ -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 (file)
index 0000000..3d97f54
--- /dev/null
@@ -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 (file)
index 0000000..270630b
--- /dev/null
@@ -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
index bb8d16e..893631c 100755 (executable)
@@ -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
index 20f132c..4467c2c 100644 (file)
@@ -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 (file)
index 0000000..9b1b175
--- /dev/null
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(dao)
diff --git a/modules/i18n/dao/CMakeLists.txt b/modules/i18n/dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c7b5ada
--- /dev/null
@@ -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 (file)
index 0000000..7e8ef9d
--- /dev/null
@@ -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 <dpl/string.h>
+
+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 (file)
index 0000000..3492f63
--- /dev/null
@@ -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 <dpl/thread.h>
+#include <dpl/mutex.h>
+#include <dpl/db/thread_database_support.h>
+
+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<InternalType> *tlsCommand##Ptr = NULL;     \
+    {                                                                          \
+        DPL::Mutex::ScopedLock lock(                                           \
+            &I18n::DB::Interface::g_dbQueriesMutex);                           \
+        if (!tlsCommand##Ptr) {                                                \
+            static DPL::ThreadLocalVariable<InternalType> tmp;                 \
+            tlsCommand##Ptr = &tmp;                                            \
+        }                                                                      \
+    }                                                                          \
+    DPL::ThreadLocalVariable<InternalType> &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 (executable)
index 0000000..22c2530
--- /dev/null
@@ -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 (file)
index 0000000..ee94c0a
--- /dev/null
@@ -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 (file)
index 0000000..d8f326d
--- /dev/null
@@ -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 <dpl/db/orm_macros.h>
+
+#include "i18n_db_definitions"
diff --git a/modules/i18n/dao/orm/orm_generator_i18n.h b/modules/i18n/dao/orm/orm_generator_i18n.h
new file mode 100644 (file)
index 0000000..53cfea3
--- /dev/null
@@ -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 <dpl/db/orm_generator.h>
+#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 (file)
index 0000000..7e20d8d
--- /dev/null
@@ -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 (file)
index 0000000..19822ff
--- /dev/null
@@ -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 <wrt-commons/i18n-dao-ro/i18n_dao_read_only.h>
+#include <wrt-commons/i18n-dao-ro/i18n_database.h>
+
+#include <orm_generator_i18n.h>
+
+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<iana_records::SUBTAG>(tag),
+                    Equals<iana_records::TYPE>(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 (file)
index 0000000..e1a1fc5
--- /dev/null
@@ -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 <wrt-commons/i18n-dao-ro/i18n_database.h>
+
+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
index d62ee17..141a29f 100755 (executable)
@@ -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
index 968839b..071ca43 100644 (file)
@@ -41,20 +41,6 @@ bool GlobalDAOReadOnly::GetSecureByDefault()
     return select->GetSingleValue<GlobalProperties::secure_by_default>();
 }
 
-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<iana_records::SUBTAG>(tag));
-    auto row = select->GetRowList();
-    if (row.empty() || row.front().Get_TYPE() != type) {
-        return false;
-    } else {
-        return true;
-    }
-}
-
 GlobalDAOReadOnly::NetworkAccessMode
 GlobalDAOReadOnly::GetHomeNetworkDataUsage()
 {
index a3560a4..0206e89 100644 (file)
@@ -55,8 +55,6 @@ class GlobalDAOReadOnly
 
   public:
 
-    static bool IsValidSubTag(const DPL::String& tag, int type);
-
     static bool GetSecureByDefault();
 
     static WidgetAccessInfoList GetWhiteURIList();
index 1e2200e..f2a4a2e 100644 (file)
@@ -1,7 +1,6 @@
 DATABASE_START(wrt)
 
 #include "wrt_db"
-#include "iana_db"
 #include "version_db"
 
 DATABASE_END()
index 8939a1d..75cd398 100644 (file)
@@ -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 ..."
 
index b271d5c..50227c7 100644 (file)
@@ -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 (file)
index 0000000..9a90b43
--- /dev/null
@@ -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 (file)
index 0000000..4ed6191
--- /dev/null
@@ -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 <dpl/test/test_runner.h>
+
+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 (file)
index 0000000..57dfe2d
--- /dev/null
@@ -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 <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+#include <wrt-commons/i18n-dao-ro/i18n_database.h>
+#include <wrt-commons/i18n-dao-ro/i18n_dao_read_only.h>
+
+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");
+}