summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/collation.c34
-rw-r--r--src/db-util-debug.h33
-rw-r--r--src/util-func.c1
-rw-r--r--tests/db-util-gtest.cpp366
-rwxr-xr-xtests/test-collation-db.sh2
-rw-r--r--tests/vconf.c517
7 files changed, 247 insertions, 707 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 68be338..75a92ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -ldl -g")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+ADD_DEFINITIONS("-DLIB_DIR=\"${LIB_INSTALL_DIR}\"")
ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
IF(NOT DEFINED GCOV )
diff --git a/src/collation.c b/src/collation.c
index e3358d9..6b24dbb 100644
--- a/src/collation.c
+++ b/src/collation.c
@@ -39,28 +39,24 @@
#include <vconf.h>
#define DB_UTIL_RETV_IF(cond, ret) \
- do { \
- if (cond) { \
- DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
- return ret; \
- } \
- } while (0)
+ do { \
+ if (cond) { \
+ DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
+ return ret; \
+ } \
+ } while (0)
#define DB_UTIL_RET_IF(cond) \
- do { \
- if (cond) { \
- DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
- return; \
- } \
- } while (0)
+ do { \
+ if (cond) { \
+ DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
+ return; \
+ } \
+ } while (0)
#define DB_UTIL_ERR_COL_FUNC_RET DB_UTIL_ERROR
-#ifdef DB_UTIL_ARCH_64
-#define ICUI18N_LIBPATH "/usr/lib64/libicui18n.so"
-#else
-#define ICUI18N_LIBPATH "/usr/lib/libicui18n.so"
-#endif
+#define ICUI18N_LIBPATH LIB_DIR"/libicui18n.so"
enum {
DB_UTIL_ERR_DLOPEN = -10,
@@ -98,9 +94,9 @@ typedef struct {
ICU_ULOC_GETDEFAULT icu_uloc_getDefault;
} db_util_icu_func_t;
-db_util_icu_func_t icu_symbol;
+static db_util_icu_func_t icu_symbol;
-void *g_dl_icu_handle = NULL;
+static void *g_dl_icu_handle = NULL;
#ifdef DB_UTIL_ENABLE_DEVDEBUG
static char *strtoutf8(const UChar * unichars, int len);
diff --git a/src/db-util-debug.h b/src/db-util-debug.h
index 49d61a4..da9e6f9 100644
--- a/src/db-util-debug.h
+++ b/src/db-util-debug.h
@@ -1,9 +1,5 @@
/*
- * libslp-db-util
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hakjoo Ko <hakjoo.ko@samsung.com>
+ * Copyright (c) 2000 - 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.
@@ -16,32 +12,18 @@
* 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 __DB_UTIL_DEBUG_H_
-#define __DB_UTIL_DEBUG_H_
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef DB_UTIL_USING_PLATFORM_DBG
- #include <dlog.h>
- #ifdef LOG_TAG
- #undef LOG_TAG
- #endif
- #define LOG_TAG "DBUTIL"
-#endif
+#pragma once
#ifdef DB_UTIL_ENABLE_TRACE
-
#ifdef DB_UTIL_USING_PLATFORM_DBG
-
+ #define LOG_TAG "DBUTIL"
+ #include <dlog.h>
#define DB_UTIL_TRACE_DEBUG LOGD
#define DB_UTIL_TRACE_WARNING LOGW
#define DB_UTIL_TRACE_ERROR LOGE
-
#else
-
+ #include <stdio.h>
#define DB_UTIL_TRACE_DEBUG(fmt, arg...) \
do {\
fprintf(stderr, "[DBUTIL]\033[0;32mDEBUG: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
@@ -56,14 +38,9 @@
do {\
fprintf(stderr, "[DBUTIL]\033[0;31mERROR: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
} while (0);
-
#endif
-
#else
-
#define DB_UTIL_TRACE_DEBUG(fmt, arg...)
#define DB_UTIL_TRACE_WARNING(fmt, arg...)
#define DB_UTIL_TRACE_ERROR(fmt, arg...)
-
#endif
-#endif /* __DB_UTIL_DEBUG_H_ */
diff --git a/src/util-func.c b/src/util-func.c
index 09ae820..a5d2b77 100644
--- a/src/util-func.c
+++ b/src/util-func.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <unistd.h>
#include <time.h>
+#include <errno.h>
#include "util-func.h"
#include "collation.h"
diff --git a/tests/db-util-gtest.cpp b/tests/db-util-gtest.cpp
index 7000986..51abd5d 100644
--- a/tests/db-util-gtest.cpp
+++ b/tests/db-util-gtest.cpp
@@ -1,10 +1,26 @@
+/*
+ * Copyright (c) 2020 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 <iostream>
+#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "gtest/gtest.h"
-
#include <db-util.h>
#include <vconf.h>
@@ -12,126 +28,151 @@
#define COL_NAME_LEN 255
#define BUF_LEN 255
+using namespace std;
//=======================================================================================
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;
- }
+protected:
+ void db_copy()
+ {
+ ifstream src("test.db.org", ios::binary);;
+ ofstream dst("test.db", ios::binary);
- void SetUp() {
- }
+ dst << src.rdbuf();
- void TearDown() {
- int rc;
- rc = system("rm -f test.db");
- rc = system("rm -f test.db-journal");
- }
+ src.close();
+ dst.close();
+ }
+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()
+ {
+ remove("test.db");
+ remove("test.db-journal");
+ }
};
//=======================================================================================
// Testing for util_func.c
//=======================================================================================
-TEST_F(DbUtil, db_util_open_p) {
+TEST_F(DbUtil, db_util_open_p)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
rc = db_util_close(db);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_n1) {
+TEST_F(DbUtil, db_util_open_n1)
+{
int rc;
// Invalid db name
rc = db_util_open(".", &db, nOption);
- ASSERT_NE ( DB_UTIL_OK , rc );
+ ASSERT_NE(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_n2) {
+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 );
+ ASSERT_NE(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_close_n) {
+TEST_F(DbUtil, db_util_close_n)
+{
int rc;
// Invalid db close
rc = db_util_close(NULL);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_with_options_p) {
+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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
rc = db_util_close(db);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_with_options_n1) {
+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 );
+ ASSERT_NE(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_with_options_n2) {
+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 );
+ ASSERT_NE(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_open_n4) {
+TEST_F(DbUtil, db_util_open_n4)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
// In case of (geteuid() != 0) && access(pszFilePath, R_OK)
- system("chmod 000 test.db");
+ chmod("test.db", 0000);
- uid_t uid = getuid();
- setuid(1000);
+ uid_t uid = geteuid();
+ if (seteuid(1000) < 0)
+ FAIL() << "errno = " << errno << std::endl;
rc = db_util_open(pszFilePath, &db, nOption);
- setuid(uid);
- ASSERT_EQ ( SQLITE_PERM , rc );
+ if (seteuid(uid) < 0)
+ FAIL() << "errno = " << errno << std::endl;
+ ASSERT_EQ(SQLITE_PERM, rc);
}
-TEST_F(DbUtil, db_util_busyhandler) {
+TEST_F(DbUtil, db_util_busyhandler)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
sqlite3_exec(db1, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
sqlite3_exec(db1, "END EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
@@ -144,21 +185,21 @@ TEST_F(DbUtil, db_util_busyhandler) {
// Testing for collation.c
//=======================================================================================
-int run_query(sqlite3 *db, char* col_name) {
-
+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 ){
+ 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){
+ while (rc == SQLITE_ROW) {
#if 0
printf("key : [%s] : Value [%s]\n",
- sqlite3_column_text(stmt,0),
- sqlite3_column_text(stmt,1) );
+ sqlite3_column_text(stmt, 0),
+ sqlite3_column_text(stmt, 1));
#endif
rc = sqlite3_step(stmt);
}
@@ -169,238 +210,251 @@ int run_query(sqlite3 *db, char* col_name) {
return 0;
}
-TEST_F(DbUtil, db_util_create_collation_p1) {
+TEST_F(DbUtil, db_util_create_collation_p1)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p2) {
+TEST_F(DbUtil, db_util_create_collation_p2)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p3) {
+TEST_F(DbUtil, db_util_create_collation_p3)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p4) {
+TEST_F(DbUtil, db_util_create_collation_p4)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p5) {
+TEST_F(DbUtil, db_util_create_collation_p5)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p6) {
+TEST_F(DbUtil, db_util_create_collation_p6)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p7) {
+TEST_F(DbUtil, db_util_create_collation_p7)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_p8) {
+TEST_F(DbUtil, db_util_create_collation_p8)
+{
int rc;
- rc = system("./test-collation-db.sh");
+ db_copy();
- rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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" );
+ vconf_set_str(VCONFKEY_LANGSET, "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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_n1) {
+TEST_F(DbUtil, db_util_create_collation_n1)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ ASSERT_EQ(DB_UTIL_OK, rc);
// vconf error
- vconf_set_str("db/menu_widget/language", "" );
+ vconf_set_str(VCONFKEY_LANGSET, "");
- 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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_n2) {
+TEST_F(DbUtil, db_util_create_collation_n2)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_n3) {
+TEST_F(DbUtil, db_util_create_collation_n3)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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 );
+ 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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
-TEST_F(DbUtil, db_util_create_collation_n4) {
+TEST_F(DbUtil, db_util_create_collation_n4)
+{
int rc;
rc = db_util_open(pszFilePath, &db, nOption);
- ASSERT_EQ ( DB_UTIL_OK , rc );
+ 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_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 );
+ ASSERT_EQ(DB_UTIL_OK, rc);
}
//=======================================================================================
-int main(int argc, char** argv) {
+int main(int argc, char** argv)
+{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
diff --git a/tests/test-collation-db.sh b/tests/test-collation-db.sh
index d549f4d..53090de 100755
--- a/tests/test-collation-db.sh
+++ b/tests/test-collation-db.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-db_name=test.db
+db_name="test.db.org"
tableName=collation
sqlite3 $db_name << EOF
diff --git a/tests/vconf.c b/tests/vconf.c
index fbcd1ef..9392208 100644
--- a/tests/vconf.c
+++ b/tests/vconf.c
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * 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
+ * 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,
@@ -13,518 +13,29 @@
* 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>
+#include <stdlib.h>
+#include <string.h>
-#ifndef EXPORT
-# define EXPORT __attribute__((visibility("default")))
-#endif
+#define MAX_BUF_LEN 256
+static char g_str[MAX_BUF_LEN + 1];
#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()
+__attribute__((visibility("default"))) int vconf_set_str(const char *in_key, const char *strval)
{
- 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;
+ strncpy(g_str, strval, MAX_BUF_LEN);
+ 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()
+__attribute__((visibility("default"))) char* vconf_get_str(const char *in_key)
{
- 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;
-}
+ char *str = malloc(MAX_BUF_LEN + 1);
+ strcpy(str, g_str);
-EXPORT int vconf_get_ext_errno(void){
- return 0;
+ return str;
}
#ifdef __cplusplus