+/*
+ * 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>
#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);
// 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);
}
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();
}
/*
- * 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,
* 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