Add collation unit test 68/232168/3
authorDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 29 Apr 2020 00:57:48 +0000 (09:57 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 29 Apr 2020 03:36:07 +0000 (12:36 +0900)
Change-Id: I06bdf4040a695b3a3b0f604d10adfc534715a5dc
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
CMakeLists.txt
include/db-util-debug.h
unittest/CMakeLists.txt
unittest/db-util_gtest.cc [deleted file]
unittest/db-util_gtest.cpp [new file with mode: 0644]
unittest/run_coverage.sh
unittest/test_collation_db.sh [new file with mode: 0755]
unittest/vconf.c [new file with mode: 0644]
unittest/vconf.sym [new file with mode: 0644]

index 15f3e94..114179a 100644 (file)
@@ -30,7 +30,9 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
+IF(NOT DEFINED GCOV )
 ADD_DEFINITIONS("-DDB_UTIL_USING_PLATFORM_DBG")
+ENDIF()
 ADD_DEFINITIONS("-DDB_UTIL_ENABLE_TRACE")
 ##ADD_DEFINITIONS("-DDB_UTIL_ENABLE_DEVDEBUG")
 
index d0fbf42..24cf82e 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef __DB_UTIL_DEBUG_H_
 #define __DB_UTIL_DEBUG_H_
 #include <stdio.h>
+#include <errno.h>
 
 #ifdef DB_UTIL_USING_PLATFORM_DBG
        #include <dlog.h>
index 5e0daa6..4d178e4 100644 (file)
@@ -2,17 +2,28 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
 
 
-pkg_check_modules(gtest_pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n )
-
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(/usr/include/vconf)
 
+pkg_check_modules(gtest_pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
 
 #=======================================================================================#
+SET(VCONF_MOCK "vconf")
+SET(VCONF_MOCK_SRCS vconf.c )
+SET(VCONF_MOCK_CFLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden ")
+ADD_LIBRARY(${VCONF_MOCK} SHARED ${VCONF_MOCK_SRCS})
+SET_TARGET_PROPERTIES(vconf PROPERTIES
+    COMPILE_FLAGS ${VCONF_MOCK_CFLAGS}
+    LINK_FLAGS "-Wl,--version-script=vconf.sym"
+    VERSION 0.3.1
+    SOVERSION 0
+)
+TARGET_LINK_LIBRARIES(${VCONF_MOCK} ${gtest_pkgs_LIBRARIES} -ldl)
+#=======================================================================================#
 SET(DB-UTIL_GTEST "db-util_gtest")
-SET(DB-UTIL_GTEST_SRCS db-util_gtest.cc)
+SET(DB-UTIL_GTEST_SRCS db-util_gtest.cpp)
 ADD_EXECUTABLE(${DB-UTIL_GTEST} ${DB-UTIL_GTEST_SRCS})
-TARGET_LINK_LIBRARIES(${DB-UTIL_GTEST} ${gtest_pkgs_LIBRARIES} gtest pthread SLP-db-util )
-# INSTALL(TARGETS ${DB-UTIL_GTEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
+TARGET_LINK_LIBRARIES(${DB-UTIL_GTEST} ${gtest_pkgs_LIBRARIES} pthread gtest vconf SLP-db-util )
 #=======================================================================================#
diff --git a/unittest/db-util_gtest.cc b/unittest/db-util_gtest.cc
deleted file mode 100644 (file)
index a6ecf20..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "gtest/gtest.h"
-
-
-#include <db-util.h>
-
-#define FILE_LEN 255
-
-//=======================================================================================
-class DbUtil : public ::testing::Test {
-    public:
-        char    pszFilePath[FILE_LEN + 1];
-        sqlite3 *db;
-        int     nOption;
-        int     flags;
-        const char* zVfs;
-
-        DbUtil() {
-            strncpy(pszFilePath, "test.db", FILE_LEN);
-            db = NULL;
-            nOption = 0;
-            flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
-            zVfs = NULL;
-        }
-
-        void SetUp() {
-        }
-
-        void TearDown() {
-            int rc;
-            rc = system("rm -f test.db");
-        }
-};
-
-TEST_F(DbUtil, db_util_open_p) {
-        int rc;
-
-        rc = db_util_open(pszFilePath, &db, nOption);
-        ASSERT_EQ ( DB_UTIL_OK , rc );
-
-        rc = db_util_close(db);
-        ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n1) {
-        int rc;
-
-        // Invalid db name
-        rc = db_util_open(".", &db, nOption);
-        ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n2) {
-        int rc;
-
-        // Invalid db pointer
-        rc = db_util_open(pszFilePath, NULL, nOption);
-        ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_close_n) {
-        int rc;
-
-        // Invalid db close
-        rc = db_util_close(NULL);
-        ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_p) {
-        int rc;
-
-        rc = db_util_open_with_options(pszFilePath, &db, flags, zVfs);
-        ASSERT_EQ ( DB_UTIL_OK , rc );
-
-        rc = db_util_close(db);
-        ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_n1) {
-        int rc;
-
-        // Invalid db name
-        rc = db_util_open_with_options(".", &db, flags, zVfs);
-        ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_n2) {
-        int rc;
-
-        // Invalid db name
-        rc = db_util_open_with_options(pszFilePath, NULL, flags, zVfs);
-        ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n4) {
-    int rc;
-
-    rc = db_util_open(pszFilePath, &db, nOption);
-    ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // In case of (geteuid() != 0) && access(pszFilePath, R_OK)
-       system("chmod 000 test.db");
-       setuid(1000);
-
-    rc = db_util_open(pszFilePath, &db, nOption);
-    ASSERT_EQ ( SQLITE_PERM , rc );
-}
-//=======================================================================================
-
-
-
-int main(int argc, char** argv) {
-    ::testing::InitGoogleTest(&argc, argv);
-    return RUN_ALL_TESTS();
-}
-
-
diff --git a/unittest/db-util_gtest.cpp b/unittest/db-util_gtest.cpp
new file mode 100644 (file)
index 0000000..2eadb35
--- /dev/null
@@ -0,0 +1,406 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "gtest/gtest.h"
+
+
+#include <db-util.h>
+#include <vconf.h>
+
+#define FILE_LEN 255
+#define COL_NAME_LEN 255
+#define BUF_LEN 255
+
+//=======================================================================================
+class DbUtil : public ::testing::Test {
+       public:
+               char    pszFilePath[FILE_LEN + 1];
+               sqlite3 *db;
+               int     nOption;
+               int     flags;
+               const char* zVfs;
+               char    col_name[COL_NAME_LEN + 1];
+
+               DbUtil() {
+                       strncpy(pszFilePath, "test.db", FILE_LEN);
+                       db = NULL;
+                       nOption = 0;
+                       flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
+
+                       zVfs = NULL;
+               }
+
+               void SetUp() {
+               }
+
+               void TearDown() {
+                       int rc;
+                       rc = system("rm -f test.db");
+                       rc = system("rm -f test.db-journal");
+               }
+};
+//=======================================================================================
+// Testing for util_func.c
+//=======================================================================================
+TEST_F(DbUtil, db_util_open_p) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n1) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open(".", &db, nOption);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n2) {
+       int rc;
+
+       // Invalid db pointer
+       rc = db_util_open(pszFilePath, NULL, nOption);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_close_n) {
+       int rc;
+
+       // Invalid db close
+       rc = db_util_close(NULL);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_p) {
+       int rc;
+
+       rc = db_util_open_with_options(pszFilePath, &db, flags, zVfs);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_n1) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open_with_options(".", &db, flags, zVfs);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_n2) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open_with_options(pszFilePath, NULL, flags, zVfs);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n4) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // In case of (geteuid() != 0) && access(pszFilePath, R_OK)
+       system("chmod 000 test.db");
+
+       uid_t uid = getuid();
+       setuid(1000);
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+
+       setuid(uid);
+       ASSERT_EQ ( SQLITE_PERM , rc );
+}
+
+TEST_F(DbUtil, db_util_busyhandler) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+
+       sqlite3 *db1;
+       rc = db_util_open(pszFilePath, &db1, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       sqlite3_exec(db1, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+       sqlite3_exec(db1, "END EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+       db_util_close(db1);
+
+       sqlite3_exec(db, "END TRANSACTION;", NULL, NULL, NULL);
+       db_util_close(db);
+}
+//=======================================================================================
+// Testing for collation.c
+//=======================================================================================
+
+int run_query(sqlite3 *db, char* col_name) {
+
+       int rc;
+
+       sqlite3_stmt *stmt = NULL;
+       char sql[BUF_LEN+1];
+       snprintf( sql, BUF_LEN, "SELECT key, value FROM collation order by value COLLATE %s", col_name);
+    rc = sqlite3_prepare(db, sql, -1, &stmt, 0);
+       if(rc == SQLITE_OK ){
+               rc = sqlite3_step(stmt);
+               while(rc == SQLITE_ROW){
+#if 0
+                       printf("key : [%s] : Value [%s]\n",
+                                       sqlite3_column_text(stmt,0),
+                                       sqlite3_column_text(stmt,1) );
+#endif
+                       rc = sqlite3_step(stmt);
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+TEST_F(DbUtil, db_util_create_collation_p1) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p2) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AS_CI_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p3) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p4) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_LC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p5) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_UCA_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p6) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AS_CI_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p7) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p8) {
+       int rc;
+
+       rc = system("./test_collation_db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_LC_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n1) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // vconf error
+       vconf_set_str("db/menu_widget/language", "" );
+
+       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n2) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_type error
+       strncpy(col_name,"COL_KO_IC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n3) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_type error
+       strncpy(col_name,"COL_KO_IC_LC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC_LC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n4) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_textrep error
+       strncpy(col_name, "COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, (db_util_collate_textrep)3, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+//=======================================================================================
+int main(int argc, char** argv) {
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
index 693149f..10f7f3b 100755 (executable)
@@ -1,9 +1,15 @@
 #!/bin/bash
-export LD_LIBRARY_PATH=..:.:$LD_LIBRARY_PATH
-pushd ../ 
+export LD_LIBRARY_PATH=.:..:$LD_LIBRARY_PATH
+pushd ../
 RootDir=$PWD
 popd
 
+# Create vconf keys
+# if [ -x "/usr/bin/buxton2ctl" ]
+# then
+# /usr/bin/buxton2ctl -i -d create-string "system"  "db/menu_widget/language"   "en_US.UTF-8"  "http://tizen.org/privilege/internal/default/public" "http://tizen.org/privilege/systemsettings.admin"
+# fi
+
 unitTestFile=db-util_gtest
 if [ ! -x  "./$unitTestFile" ]
 then
@@ -16,9 +22,9 @@ fi
 CMakeDir=${RootDir}/CMakeFiles/SLP-db-util.dir
 CoverageDir=${RootDir}/coverage
 
-pushd $CMakeDir 
+pushd $CMakeDir
     for obj in `ls *.o`
-    do  
+    do
         gcov -b -c $obj
     done
 
@@ -26,7 +32,7 @@ pushd $CMakeDir
     then
         lcov -c -d . -o cov.info
         genhtml cov.info -o ${CoverageDir}
-        echo "Coverage test result created! [${CoverageDir}]" 
+        echo "Coverage test result created! [${CoverageDir}]"
     else
         echo "lcov does not exist!"
     fi
diff --git a/unittest/test_collation_db.sh b/unittest/test_collation_db.sh
new file mode 100755 (executable)
index 0000000..f75dfab
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+db_name=test.db
+tableName=collation
+
+sqlite3 $db_name << EOF
+DROP TABLE IF EXISTS ${tableName};
+
+CREATE TABLE IF NOT EXISTS ${tableName} (
+key CHAR not NULL,
+value CHAR );
+
+PRAGMA synchronous=OFF;
+PRAGMA count_changes=OFF;
+PRAGMA journal_mode=MEMORY;
+PRAGMA temp_store=MEMORY;
+
+BEGIN TRANSACTION;
+INSERT INTO ${tableName} ( key, value) values ( "test_01", "테스트 1");
+INSERT INTO ${tableName} ( key, value) values ( "test_04", "테스트 01");
+INSERT INTO ${tableName} ( key, value) values ( "test_07", "테스트 001");
+INSERT INTO ${tableName} ( key, value) values ( "test_02", "테스트 2");
+INSERT INTO ${tableName} ( key, value) values ( "test_08", "테스트 002");
+INSERT INTO ${tableName} ( key, value) values ( "test_05", "테스트 02");
+INSERT INTO ${tableName} ( key, value) values ( "test_09", "테스트 003");
+INSERT INTO ${tableName} ( key, value) values ( "test_03", "테스트 3");
+INSERT INTO ${tableName} ( key, value) values ( "test_06", "테스트 03");
+COMMIT TRANSACTION;
+EOF
+
diff --git a/unittest/vconf.c b/unittest/vconf.c
new file mode 100644 (file)
index 0000000..c005f49
--- /dev/null
@@ -0,0 +1,534 @@
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <sqlite3.h>
+
+#ifndef EXPORT
+#  define EXPORT __attribute__((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define VCONF_OK                    0
+#define VCONF_ERROR                 -1
+#define VCONF_ERROR_WRONG_PREFIX    -2
+#define VCONF_ERROR_WRONG_TYPE      -3
+#define VCONF_ERROR_WRONG_VALUE     -4
+#define VCONF_ERROR_NOT_INITIALIZED -5
+#define VCONF_ERROR_NO_MEM          -6
+#define VCONF_ERROR_FILE_PERM       -11
+#define VCONF_ERROR_FILE_BUSY       -12
+#define VCONF_ERROR_FILE_NO_MEM     -13
+#define VCONF_ERROR_FILE_NO_ENT     -14
+#define VCONF_ERROR_FILE_OPEN       -21
+#define VCONF_ERROR_FILE_FREAD      -22
+#define VCONF_ERROR_FILE_FGETS      -23
+#define VCONF_ERROR_FILE_WRITE      -24
+#define VCONF_ERROR_FILE_SYNC       -25
+#define VCONF_ERROR_FILE_CLOSE      -26
+#define VCONF_ERROR_FILE_ACCESS     -27
+#define VCONF_ERROR_FILE_CHMOD      -28
+#define VCONF_ERROR_FILE_LOCK       -29
+#define VCONF_ERROR_FILE_REMOVE     -30
+#define VCONF_ERROR_FILE_SEEK       -31
+#define VCONF_ERROR_FILE_TRUNCATE   -32
+#define VCONF_ERROR_NOT_SUPPORTED   -33
+
+#define MAX_BUF_LEN 256
+
+enum get_option_t {
+       VCONF_GET_KEY = 0, /**< Get only keys */
+       VCONF_GET_ALL,     /**< Get keys and directories */
+       VCONF_GET_DIR      /**< Get only directories */
+};
+typedef enum get_option_t get_option_t;
+enum vconf_t {
+       VCONF_TYPE_NONE = 0,    /**< Vconf none type for Error detection */
+       VCONF_TYPE_STRING = 40, /**< Vconf string type */
+       VCONF_TYPE_INT = 41,    /**< Vconf integer type */
+       VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */
+       VCONF_TYPE_BOOL = 43,   /**< Vconf boolean type */
+       VCONF_TYPE_DIR          /**< Vconf directory type */
+};
+
+typedef struct _keynode_t {
+       char *keyname;           /**< Keyname for keynode */
+       int type;                /**< Keynode type */
+       union {
+               int i;               /**< Integer type */
+               int b;               /**< Bool type */
+               double d;            /**< Double type */
+               char *s;             /**< String type */
+       } value;                 /**< Value for keynode */
+} keynode_t;
+typedef struct _keylist_t keylist_t;
+
+typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data);
+
+static char g_str[MAX_BUF_LEN+1];
+
+/************************************************
+ * keynode handling APIs                        *
+ ************************************************/
+EXPORT char *vconf_keynode_get_name(keynode_t *keynode){
+    return NULL;
+}
+
+EXPORT int vconf_keynode_get_type(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT int vconf_keynode_get_int(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT double vconf_keynode_get_dbl(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT int vconf_keynode_get_bool(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT char *vconf_keynode_get_str(keynode_t *keynode){
+    return NULL;
+}
+
+
+/************************************************
+ * keylist handling APIs
+ ************************************************/
+keylist_t *vconf_keylist_new(void){
+    return NULL;
+}
+
+/**
+ * @code
+    int r =0;
+    keylist_t* pKeyList = NULL;
+    pKeyList = vconf_keylist_new();
+
+    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
+    if (r) {
+    tet_infoline("vconf_get() failed in positive test case");
+    tet_result(TET_FAIL);
+    return;
+    }
+
+    vconf_keylist_nextnode(pKeyList);
+    vconf_keylist_nextnode(pKeyList);
+
+    // Move first position from KeyList
+    r = vconf_keylist_rewind(pKeyList);
+    if (r<0) {
+    tet_infoline("vconf_keylist_rewind() failed in positive test case");
+    tet_result(TET_FAIL);
+    return;
+    }
+
+    while(vconf_keylist_nextnode(pKeyList)) ;
+ * @endcode
+ */
+EXPORT int vconf_keylist_rewind(keylist_t *keylist){
+    return 0;
+}
+
+EXPORT int vconf_keylist_free(keylist_t *keylist){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+    int r = 0;
+    int nResult = 0;
+    keylist_t* pKeyList = NULL;
+    keynode_t *pKeyNode;
+
+    pKeyList = vconf_keylist_new();
+    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
+    if (r<0) {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+    }
+
+    r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
+    if (r<0) {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+    }
+
+    if (r == VCONF_TYPE_NONE) {
+        printf("vconf key not found");
+        return -1;
+    }
+
+    nResult = vconf_keynode_get_int(pKeyNode);
+    if(nResult !=KEY_02_INT_VALUE)
+    {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+
+    }
+
+    vconf_keylist_free(pKeyList);
+    return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
+               keynode_t **return_node){
+    return 0;
+}
+
+EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist){
+    return NULL;
+}
+
+EXPORT int vconf_keylist_add_int(keylist_t *keylist, const char *keyname,
+               const int value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname,
+               const int value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname,
+               const double value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_str(keylist_t *keylist, const char *keyname,
+               const char *value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname){
+    return 0;
+}
+
+EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname){
+    return 0;
+}
+
+/************************************************
+ * setting APIs                                 *
+ ************************************************/
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+   keylist_t *kl=NULL;
+   const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
+
+   // Transaction Test(all or nothing is written)
+   kl = vconf_keylist_new();
+
+   vconf_keylist_add_int(kl, keyname_list[0], 1);
+   vconf_keylist_add_str(kl, keyname_list[1], "transaction Test");
+   vconf_keylist_add_dbl(kl, keyname_list[2], 0.3);
+   if(vconf_set(kl))
+      fprintf(stderr, "nothing is written\n");
+   else
+      printf("everything is written\n");
+
+   vconf_keylist_free(kl);
+
+   // You can set items which have different backend.
+   kl = vconf_keylist_new();
+
+   vconf_keylist_add_int(kl, "memory/a/xxx1", 4);
+   vconf_keylist_add_str(kl, "file/a/xxx2", "test 3");
+   vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3);
+   vconf_set(kl)
+
+   vconf_keylist_free(kl);
+   return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_set(keylist_t *keylist){
+    return 0;
+}
+
+EXPORT int vconf_set_int(const char *in_key, const int intval){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+ const char *key1_name="memory/test/key1";
+
+ int main(int argc, char **argv)
+ {
+   int key1_value;
+
+   if(vconf_set_bool(key1_name, 1))
+      fprintf(stderr, "vconf_set_bool FAIL\n");
+   else
+      printf("vconf_set_bool OK\n");
+
+   if(vconf_get_bool(key1_name, &key1_value))
+      fprintf(stderr, "vconf_get_bool FAIL\n");
+   else
+      printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
+
+   return 0;
+ }
+ * @endcode
+ */
+EXPORT int vconf_set_bool(const char *in_key, const int boolval){
+    return 0;
+}
+
+EXPORT int vconf_set_dbl(const char *in_key, const double dblval){
+    return 0;
+}
+
+EXPORT int vconf_set_str(const char *in_key, const char *strval){
+
+    strncpy( g_str, strval, MAX_BUF_LEN );
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+   keylist_t *kl=NULL;
+   keynode_t *temp_node;
+   const char *vconfkeys1="db/test/key1";
+   const char *parent_dir="db/test";
+
+   kl = vconf_keylist_new();
+   if(vconf_get(kl, parent_dir, 0))
+      fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
+   else
+      printf("vconf_get OK(%s)", vconfkeys1);
+
+   while((temp_node = vconf_keylist_nextnode(kl))) {
+      switch(vconf_keynode_get_type(temp_node)) {
+    case VCONF_TYPE_INT:
+        printf("key = %s, value = %d\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
+        break;
+    case VCONF_TYPE_BOOL:
+        printf("key = %s, value = %d\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
+        break;
+    case VCONF_TYPE_DOUBLE:
+        printf("key = %s, value = %f\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
+        break;
+    case VCONF_TYPE_STRING:
+        printf("key = %s, value = %s\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
+        break;
+    default:
+        printf("Unknown Type\n");
+      }
+   }
+   vconf_keylist_free(kl);
+}
+ * @endcode
+ */
+EXPORT int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+const char *key1_name="db/test/key1";
+
+int main(int argc, char **argv)
+{
+   int key1_value;
+
+   if(vconf_set_int(key1_name,1))
+      fprintf(stderr, "vconf_set_int FAIL\n");
+   else
+      printf("vconf_set_int OK\n");
+
+   if(vconf_get_int(key1_name, &key1_value))
+      fprintf(stderr, "vconf_get_int FAIL\n");
+   else
+      printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
+
+   return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_get_int(const char *in_key, int *intval){
+    return 0;
+}
+
+EXPORT int vconf_get_bool(const char *in_key, int *boolval){
+    return 0;
+}
+
+EXPORT int vconf_get_dbl(const char *in_key, double *dblval){
+    return 0;
+}
+
+/**
+ * @code
+   #include <stdio.h>
+   #include <vconf.h>
+
+   char *get_str=vconf_get_str("db/test/test1");
+   if(get_str) {
+      printf("vconf_get_str OK(value = %s)", get_str);
+      free(get_str);
+   }else
+      fprintf(stderr, "vconf_get_str FAIL");
+ * @endcode
+ */
+EXPORT char *vconf_get_str(const char *in_key){
+
+#if 1
+    char *str = (char*)malloc(MAX_BUF_LEN+1);
+    strcpy( str, g_str);
+
+    return str;
+#endif
+}
+
+EXPORT int vconf_unset(const char *in_key){
+    return 0;
+}
+
+/**
+ * @code
+ if(vconf_set_int("file/test/key1",1))
+    fprintf(stderr, "vconf_set_int FAIL\n");
+ else {
+    printf("vconf_set_int OK\n");
+    vconf_sync_key("file/test/key1");
+ }
+ * @endcode
+ */
+EXPORT int vconf_sync_key(const char *in_key){
+    return 0;
+}
+
+/**
+ * @code
+   vconf_set_int("db/test/key1",1);
+   vconf_set_int("db/test/test1/key1",1);
+   vconf_set_int("db/test/test2/key1",1);
+   vconf_set_int("db/test/key2",1);
+
+   if(vconf_unset_recursive("db/test"))
+      fprintf(stderr, "vconf_unset_recursive FAIL\n");
+   else
+      printf("vconf_unset_recursive OK(deleted db/test\n");
+
+ * @endcode
+ */
+EXPORT int vconf_unset_recursive(const char *in_dir){
+    return 0;
+}
+
+/**
+ * @code
+ void test_cb(keynode_t *key, void* data)
+ {
+    switch(vconf_keynode_get_type(key))
+    {
+       case VCONF_TYPE_INT:
+    printf("key = %s, value = %d(int)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_int(key));
+    break;
+       case VCONF_TYPE_BOOL:
+    printf("key = %s, value = %d(bool)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
+    break;
+       case VCONF_TYPE_DOUBLE:
+    printf("key = %s, value = %f(double)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
+    break;
+       case VCONF_TYPE_STRING:
+    printf("key = %s, value = %s(string)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_str(key));
+    break;
+       default:
+    fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
+    break;
+    }
+    return;
+ }
+
+ int main()
+ {
+    int i;
+    GMainLoop *event_loop;
+
+    g_type_init();
+
+    vconf_notify_key_changed("db/test/test1", test_cb, NULL);
+
+    event_loop = g_main_loop_new(NULL, FALSE);
+    g_main_loop_run(event_loop);
+
+    vconf_ignore_key_changed("db/test/test1", test_cb);
+    return 0;
+ }
+ * @endcode
+ */
+EXPORT int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb,
+                void *user_data){
+    return 0;
+}
+
+EXPORT int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb){
+    return 0;
+}
+
+EXPORT int vconf_get_ext_errno(void){
+    return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+
diff --git a/unittest/vconf.sym b/unittest/vconf.sym
new file mode 100644 (file)
index 0000000..745cacf
--- /dev/null
@@ -0,0 +1,38 @@
+VCONF_BUXTON_1.0 {
+       global:
+               vconf_keynode_get_name;
+               vconf_keynode_get_type;
+               vconf_keynode_get_int;
+               vconf_keynode_get_dbl;
+               vconf_keynode_get_bool;
+               vconf_keynode_get_str;
+               vconf_notify_key_changed;
+               vconf_ignore_key_changed;
+               vconf_set_int;
+               vconf_set_bool;
+               vconf_set_str;
+               vconf_set_dbl;
+               vconf_get_int;
+               vconf_get_bool;
+               vconf_get_str;
+               vconf_get_dbl;
+               vconf_get_ext_errno;
+               vconf_keylist_new;
+               vconf_keylist_free;
+               vconf_keylist_add_int;
+               vconf_keylist_add_bool;
+               vconf_keylist_add_dbl;
+               vconf_keylist_add_str;
+               vconf_keylist_add_null;
+               vconf_keylist_del;
+               vconf_keylist_nextnode;
+               vconf_keylist_rewind;
+               vconf_get;
+               vconf_set;
+               vconf_unset;
+               vconf_unset_recursive;
+               vconf_sync_key;
+               vconf_keylist_lookup;
+       local:
+               *;
+};