diff options
74 files changed, 10920 insertions, 0 deletions
@@ -0,0 +1,3 @@ +SeungYeup Kim <sy2004.kim at samsung dot com> +HyungDeuk Kim <hd3.kim at samsung dot com> +HakJoo Ko <hakjoo.ko at samsung dot com> diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..025870e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,65 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(vconf C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${exec_prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.2.29") + +set(CMAKE_SKIP_BUILD_RPATH true) + +SET(SRCS vconf.c vconf-kdb.c) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(glib_pkg REQUIRED gobject-2.0) +pkg_check_modules(pkgs REQUIRED glib-2.0 dlog vconf-internal-keys) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +#ADD_DEFINITIONS("-Werror") +#ADD_DEFINITIONS("-Wall") +#ADD_DEFINITIONS("-Wextra") +#ADD_DEFINITIONS("-ansi") +#ADD_DEFINITIONS("-pedantic") + + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DDATAFS=\"$ENV{DATADIR}\"") + +ADD_DEFINITIONS("-DENABLE_FDATASYNC") +ADD_DEFINITIONS("-DSUPPORT_ELEKTRA_VALUE_FORMAT") +ADD_DEFINITIONS("-DHAVE_FCNTL_H") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +ADD_EXECUTABLE(vconftool vconftool.c) +STRING(REPLACE ";" " " TEMP_CFLAGS "${glib_pkg_CFLAGS}") +SET_TARGET_PROPERTIES(vconftool PROPERTIES COMPILE_FLAGS ${TEMP_CFLAGS}) +TARGET_LINK_LIBRARIES(vconftool ${pkgs_LDFLAGS} ${glib_pkg_LDFLAGS} ${PROJECT_NAME}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +INSTALL(TARGETS vconftool DESTINATION bin) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/vconf.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/vconf-keys.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/kdb_first_boot DESTINATION /opt/var/kdb) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/vconf-init DESTINATION /etc/rc.d/init.d/ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + +add_subdirectory(include) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..6103dfa --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +export TET_INSTALL_PATH=/home/deuk/Tetware # local tetware path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..f073ed9 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,20 @@ +#!/bin/sh +export TET_INSTALL_PATH=/mnt/nfs/tetware +#export TET_INSTALL_PATH=/scratchbox/tetware +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH + +export TET_ROOT=$TET_TARGET_PATH + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 3 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/tet_code b/TC/tet_code new file mode 100755 index 0000000..a2cf6c1 --- /dev/null +++ b/TC/tet_code @@ -0,0 +1,12 @@ +# TET reserved codes +0 "PASS" +1 "FAIL" +2 "UNRESOLVED" +3 "NOTINUSE" +4 "UNSUPPORTED" +5 "UNTESTED" +6 "UNINITIATED" +7 "NORESULT" + +# Test suite additional codes +33 "INSPECT" diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..43cbc9b --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/unit/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100755 index 0000000..a584acd --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,2 @@ +TET_OUTPUT_CAPTURE=False +TET_BUILD_TOOL=make diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100755 index 0000000..c66eda4 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,2 @@ +TET_OUTPUT_CAPTURE=False +TET_CLEAN_TOOL=make clean diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100755 index 0000000..0d9d39a --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1 @@ +TET_OUTPUT_CAPTURE=False diff --git a/TC/unit/Makefile b/TC/unit/Makefile new file mode 100644 index 0000000..1ea9242 --- /dev/null +++ b/TC/unit/Makefile @@ -0,0 +1,57 @@ +CC ?= gcc + +TARGETS = utc_ApplicationFW_vconf_set_int_func \ + utc_ApplicationFW_vconf_set_bool_func \ + utc_ApplicationFW_vconf_set_str_func \ + utc_ApplicationFW_vconf_set_dbl_func \ + utc_ApplicationFW_vconf_set_bytes_func \ + utc_ApplicationFW_vconf_get_bool_func \ + utc_ApplicationFW_vconf_get_bytes_func \ + utc_ApplicationFW_vconf_get_dbl_func \ + utc_ApplicationFW_vconf_get_int_func \ + utc_ApplicationFW_vconf_get_str_func \ + utc_ApplicationFW_vconf_unset_func\ + utc_ApplicationFW_vconf_unset_recursive_func \ + utc_ApplicationFW_vconf_keylist_new_func \ + utc_ApplicationFW_vconf_keylist_add_bool_func \ + utc_ApplicationFW_vconf_keylist_add_dbl_func \ + utc_ApplicationFW_vconf_keylist_add_int_func \ + utc_ApplicationFW_vconf_keylist_add_null_func \ + utc_ApplicationFW_vconf_keylist_add_str_func \ + utc_ApplicationFW_vconf_get_func \ + utc_ApplicationFW_vconf_keylist_nextnode_func \ + utc_ApplicationFW_vconf_keynode_get_bool_func \ + utc_ApplicationFW_vconf_keynode_get_dbl_func \ + utc_ApplicationFW_vconf_keynode_get_int_func \ + utc_ApplicationFW_vconf_keynode_get_name_func \ + utc_ApplicationFW_vconf_keynode_get_str_func \ + utc_ApplicationFW_vconf_keynode_get_type_func \ + utc_ApplicationFW_vconf_keylist_del_func \ + utc_ApplicationFW_vconf_keylist_free_func \ + utc_ApplicationFW_vconf_keylist_lookup_func \ + utc_ApplicationFW_vconf_keylist_rewind_func \ + utc_ApplicationFW_vconf_keynode_steal_str_func \ + utc_ApplicationFW_vconf_set_func \ + utc_ApplicationFW_vconf_sync_key_func \ + utc_ApplicationFW_vconf_ignore_key_changed_func \ + utc_ApplicationFW_vconf_notify_key_changed_func + +PKGS = vconf glib-2.0 + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s +LDFLAGS += -pthread + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +all: $(TARGETS) + +$(TARGETS): %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TARGETS) diff --git a/TC/unit/tc_gen.sh b/TC/unit/tc_gen.sh new file mode 100755 index 0000000..54f482d --- /dev/null +++ b/TC/unit/tc_gen.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +TMPSTR=$0 +SCRIPT=${TMPSTR##*/} + +if [ $# -lt 2 ]; then + echo "Usage) $SCRIPT module_name api_name" + exit 1 +fi + +MODULE=$1 +API=$2 +TEMPLATE=utc_MODULE_API_func.c.in +TESTCASE=utc_${MODULE}_${API}_func + +sed -e ' + s^@API@^'"$API"'^g + s^@MODULE@^'"$MODULE"'^g + ' $TEMPLATE > $TESTCASE.c + +if [ ! -e "$TESTCASE.c" ]; then + echo "Failed" + exit 1 +fi +echo "Testcase file is $TESTCASE.c" +echo "Done" +echo "please put \"$TESTCASE\" as Target in Makefile" +echo "please put \"/unit/$TESTCASE\" in tslist" diff --git a/TC/unit/tslist b/TC/unit/tslist new file mode 100644 index 0000000..b7295b2 --- /dev/null +++ b/TC/unit/tslist @@ -0,0 +1,33 @@ +/unit/utc_ApplicationFW_vconf_set_int_func +/unit/utc_ApplicationFW_vconf_set_bool_func +/unit/utc_ApplicationFW_vconf_set_str_func +/unit/utc_ApplicationFW_vconf_set_dbl_func +/unit/utc_ApplicationFW_vconf_get_bool_func +/unit/utc_ApplicationFW_vconf_get_dbl_func +/unit/utc_ApplicationFW_vconf_get_int_func +/unit/utc_ApplicationFW_vconf_get_str_func +/unit/utc_ApplicationFW_vconf_unset_func +/unit/utc_ApplicationFW_vconf_unset_recursive_func +/unit/utc_ApplicationFW_vconf_keylist_new_func +/unit/utc_ApplicationFW_vconf_keylist_add_bool_func +/unit/utc_ApplicationFW_vconf_keylist_add_dbl_func +/unit/utc_ApplicationFW_vconf_keylist_add_int_func +/unit/utc_ApplicationFW_vconf_keylist_add_null_func +/unit/utc_ApplicationFW_vconf_keylist_add_str_func +/unit/utc_ApplicationFW_vconf_get_func +/unit/utc_ApplicationFW_vconf_keylist_nextnode_func +/unit/utc_ApplicationFW_vconf_keynode_get_bool_func +/unit/utc_ApplicationFW_vconf_keynode_get_dbl_func +/unit/utc_ApplicationFW_vconf_keynode_get_int_func +/unit/utc_ApplicationFW_vconf_keynode_get_name_func +/unit/utc_ApplicationFW_vconf_keynode_get_str_func +/unit/utc_ApplicationFW_vconf_keynode_get_type_func +/unit/utc_ApplicationFW_vconf_keylist_del_func +/unit/utc_ApplicationFW_vconf_keylist_free_func +/unit/utc_ApplicationFW_vconf_keylist_lookup_func +/unit/utc_ApplicationFW_vconf_keylist_rewind_func +/unit/utc_ApplicationFW_vconf_set_func +/unit/utc_ApplicationFW_vconf_keylist_new_func +/unit/utc_ApplicationFW_vconf_sync_key_func +/unit/utc_ApplicationFW_vconf_ignore_key_changed_func +/unit/utc_ApplicationFW_vconf_notify_key_changed_func diff --git a/TC/unit/utc_ApplicationFW_vconf_get_bool_func.c b/TC/unit/utc_ApplicationFW_vconf_get_bool_func.c new file mode 100644 index 0000000..7d7540c --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_bool_func.c @@ -0,0 +1,129 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static const int KEY_DB_BOOL_VALUE = 1; +static const int KEY_MEMORY_BOOL_VALUE = 0; +static const int KEY_FILE_BOOL_VALUE = 1; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_bool_func_01(void); +static void utc_ApplicationFW_vconf_get_bool_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_bool_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_bool_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + vconf_set_bool(KEY_DB, KEY_DB_BOOL_VALUE); + vconf_set_bool(KEY_MEMORY, KEY_MEMORY_BOOL_VALUE); + vconf_set_bool(KEY_FILE, KEY_FILE_BOOL_VALUE); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_get_bool() + */ +static void utc_ApplicationFW_vconf_get_bool_func_01(void) +{ + int r = 0; + int nDBBoolValue = 0; + int nMemoryBoolValue = 0; + int nFileBoolValue = 0; + + r = vconf_get_bool(KEY_DB, &nDBBoolValue); + if (r || nDBBoolValue != KEY_DB_BOOL_VALUE) { + tet_infoline("vconf_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_bool(KEY_MEMORY, &nMemoryBoolValue); + if (r || nMemoryBoolValue != KEY_MEMORY_BOOL_VALUE) { + tet_infoline("vconf_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_bool(KEY_FILE, &nFileBoolValue); + if (r || nFileBoolValue != KEY_FILE_BOOL_VALUE) { + tet_infoline("vconf_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_bool() + */ +static void utc_ApplicationFW_vconf_get_bool_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + int nBoolValue = 0; + + r = vconf_get_bool(InvalidBackend, &nBoolValue); + if (!r) { + tet_infoline("vconf_get_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_bool(InvalidBackend, NULL); + if (!r) { + tet_infoline("vconf_get_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_get_bytes_func.c b/TC/unit/utc_ApplicationFW_vconf_get_bytes_func.c new file mode 100644 index 0000000..30514e0 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_bytes_func.c @@ -0,0 +1,144 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; +static char* pBufferString = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_bytes_func_01(void); +static void utc_ApplicationFW_vconf_get_bytes_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_bytes_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_bytes_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3";
+ pBufferString = "This is Test String"; + + vconf_set_bytes(KEY_DB, (void*)pBufferString, strlen(pBufferString)); + vconf_set_bytes(KEY_MEMORY, (void*)pBufferString, strlen(pBufferString)); + vconf_set_bytes(KEY_FILE, (void*)pBufferString, strlen(pBufferString)); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_get_bytes() + */ +static void utc_ApplicationFW_vconf_get_bytes_func_01(void) +{ + int r = 0; + char szResultBuffer[1024] = {0, }; + + r = vconf_get_bytes(KEY_DB, szResultBuffer, 1023); + if (r < -1 || memcmp(szResultBuffer, pBufferString, r)) + { + tet_infoline("vconf_get_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + memset(szResultBuffer, 0x00, sizeof(szResultBuffer)); + r = vconf_get_bytes(KEY_MEMORY, szResultBuffer, 1023); + if (r < -1 || memcmp(szResultBuffer, pBufferString, r)) + { + tet_infoline("vconf_get_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + memset(szResultBuffer, 0x00, sizeof(szResultBuffer)); + r = vconf_get_bytes(KEY_FILE, szResultBuffer, 1023); + if (r < -1 || memcmp(szResultBuffer, pBufferString, r)) + { + tet_infoline("vconf_get_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_bytes() + */ +static void utc_ApplicationFW_vconf_get_bytes_func_02(void) +{ + int r = 0; + char szResultBuffer[1024] = {0, }; + const char* InvalidBackend = "Invalid/tet/key_1"; + + + r = vconf_get_bytes(InvalidBackend, szResultBuffer, 1023); + if (r != -1) + { + tet_infoline("vconf_get_bytes() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + memset(szResultBuffer, 0x00, sizeof(szResultBuffer)); + r = vconf_get_bytes(KEY_DB, NULL, 1023); + if (r != -1) + { + tet_infoline("vconf_get_bytes() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + memset(szResultBuffer, 0x00, sizeof(szResultBuffer)); + r = vconf_get_bytes(KEY_DB, szResultBuffer, -10); + if (r != -1) + { + tet_infoline("vconf_get_bytes() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_get_dbl_func.c b/TC/unit/utc_ApplicationFW_vconf_get_dbl_func.c new file mode 100644 index 0000000..134a717 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_dbl_func.c @@ -0,0 +1,139 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static const double KEY_DB_BOOL_VALUE = 10.23; +static const double KEY_MEMORY_BOOL_VALUE = -32.45; +static const double KEY_FILE_BOOL_VALUE = 0.43; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_dbl_func_01(void); +static void utc_ApplicationFW_vconf_get_dbl_func_02(void); +static void utc_ApplicationFW_vconf_get_dbl_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_dbl_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_dbl_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_dbl_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + vconf_set_dbl(KEY_DB, KEY_DB_BOOL_VALUE); + vconf_set_dbl(KEY_MEMORY, KEY_MEMORY_BOOL_VALUE); + vconf_set_dbl(KEY_FILE, KEY_FILE_BOOL_VALUE); + +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_get_dbl() + */ +static void utc_ApplicationFW_vconf_get_dbl_func_01(void) +{ + int r = 0; + double fRetValue = 0.0; + + r = vconf_get_dbl(KEY_DB, &fRetValue); + if (r || fRetValue != KEY_DB_BOOL_VALUE) { + tet_infoline("vconf_get_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_dbl(KEY_MEMORY, &fRetValue); + if (r || fRetValue != KEY_MEMORY_BOOL_VALUE) { + tet_infoline("vconf_get_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_dbl(KEY_FILE, &fRetValue); + if (r || fRetValue != KEY_FILE_BOOL_VALUE) { + tet_infoline("vconf_get_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_dbl() + */ +static void utc_ApplicationFW_vconf_get_dbl_func_02(void) +{ + int r = 0; + double fRetValue = 0.0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_get_dbl(InvalidBackend, &fRetValue); + if (!r) { + tet_infoline("vconf_get_dbl() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_dbl() + */ +static void utc_ApplicationFW_vconf_get_dbl_func_03(void) +{ + int r = 0; + + r = vconf_get_dbl(KEY_DB, NULL); + if (!r) { + tet_infoline("vconf_get_dbl() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_get_func.c b/TC/unit/utc_ApplicationFW_vconf_get_func.c new file mode 100644 index 0000000..52e0fe7 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_func.c @@ -0,0 +1,142 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_func_01(void); +static void utc_ApplicationFW_vconf_get_func_02(void); +// static void utc_ApplicationFW_vconf_get_func_03(void); + + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_func_02, NEGATIVE_TC_IDX }, + // { utc_ApplicationFW_vconf_get_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + if(!pKeyList) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, 0); + vconf_keylist_add_int(pKeyList, KEY_02, 100); + vconf_keylist_add_dbl(pKeyList, KEY_03, 0.453); + + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(!pKeyList) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_get() + */ +static void utc_ApplicationFW_vconf_get_func_01(void) +{ + int r = 0, i = 0; + int aOption[3] = {VCONF_GET_KEY, VCONF_GET_ALL, VCONF_GET_DIR}; + + for(; i<3; ++i){ + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, aOption[i]); + if (r) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get() + */ +static void utc_ApplicationFW_vconf_get_func_02(void) +{ + int r = 0; + + r = vconf_get(NULL, KEY_PARENT, VCONF_GET_KEY); + if (r!=-1) { + tet_infoline("vconf_get() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +#if 0 +/** + * @brief Negative test case of ug_init vconf_get() + */ +static void utc_ApplicationFW_vconf_get_func_03(void) +{ + int r = 0; + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, NULL, VCONF_GET_KEY); + if (r!=-1) { + tet_infoline("vconf_get() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} +#endif diff --git a/TC/unit/utc_ApplicationFW_vconf_get_int_func.c b/TC/unit/utc_ApplicationFW_vconf_get_int_func.c new file mode 100644 index 0000000..f3f8de5 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_int_func.c @@ -0,0 +1,138 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static const int KEY_DB_BOOL_VALUE = 10; +static const int KEY_MEMORY_BOOL_VALUE = -45; +static const int KEY_FILE_BOOL_VALUE = 28; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_int_func_01(void); +static void utc_ApplicationFW_vconf_get_int_func_02(void); +static void utc_ApplicationFW_vconf_get_int_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_int_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_int_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_int_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + vconf_set_int(KEY_DB, KEY_DB_BOOL_VALUE); + vconf_set_int(KEY_MEMORY, KEY_MEMORY_BOOL_VALUE); + vconf_set_int(KEY_FILE, KEY_FILE_BOOL_VALUE); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_get_int() + */ +static void utc_ApplicationFW_vconf_get_int_func_01(void) +{ + int r = 0; + int nRetValue = 0; + + r = vconf_get_int(KEY_DB, &nRetValue); + if (r || nRetValue != KEY_DB_BOOL_VALUE) { + tet_infoline("vconf_get_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_int(KEY_MEMORY, &nRetValue); + if (r || nRetValue != KEY_MEMORY_BOOL_VALUE) { + tet_infoline("vconf_get_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_get_int(KEY_FILE, &nRetValue); + if (r || nRetValue != KEY_FILE_BOOL_VALUE) { + tet_infoline("vconf_get_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_int() + */ +static void utc_ApplicationFW_vconf_get_int_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + int nRetValue = 0; + + r = vconf_get_int(InvalidBackend, &nRetValue); + if (!r) { + tet_infoline("vconf_get_int() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_int() + */ +static void utc_ApplicationFW_vconf_get_int_func_03(void) +{ + int r = 0; + + r = vconf_get_int(KEY_MEMORY, NULL); + if (!r) { + tet_infoline("vconf_get_int() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_get_str_func.c b/TC/unit/utc_ApplicationFW_vconf_get_str_func.c new file mode 100644 index 0000000..d210295 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_get_str_func.c @@ -0,0 +1,116 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; +static char* pBufferString = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_get_str_func_01(void); +static void utc_ApplicationFW_vconf_get_str_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_get_str_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_get_str_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3";
+ pBufferString = "This is Test String"; + + vconf_set_str(KEY_DB, pBufferString); + vconf_set_str(KEY_MEMORY, pBufferString); + vconf_set_str(KEY_FILE, pBufferString); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_get_str() + */ +static void utc_ApplicationFW_vconf_get_str_func_01(void) +{ + char* pRetString = NULL; + + pRetString = vconf_get_str(KEY_DB); + if (pRetString == NULL || strncmp(pBufferString, pRetString, strlen(pRetString))) { + tet_infoline("vconf_get_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + pRetString = vconf_get_str(KEY_MEMORY); + if (pRetString == NULL || strncmp(pBufferString, pRetString, strlen(pRetString))) { + tet_infoline("vconf_get_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + pRetString = vconf_get_str(KEY_FILE); + if (pRetString == NULL || strncmp(pBufferString, pRetString, strlen(pRetString))) { + tet_infoline("vconf_get_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_get_str() + */ +static void utc_ApplicationFW_vconf_get_str_func_02(void) +{ + char* pRetString = NULL; + const char* InvalidBackend = "Invalid/tet/key_1"; + + pRetString = vconf_get_str(InvalidBackend); + if (pRetString) { + tet_infoline("vconf_get_str() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_ignore_key_changed_func.c b/TC/unit/utc_ApplicationFW_vconf_ignore_key_changed_func.c new file mode 100644 index 0000000..3294463 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_ignore_key_changed_func.c @@ -0,0 +1,120 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <stdio.h> +#include <vconf.h> +#include <glib.h> +#include <glib-object.h> +#include <pthread.h> + +static GMainLoop* event_loop = NULL; +static char* KEY_DB = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_ignore_key_changed_func_01(void); +static void utc_ApplicationFW_vconf_ignore_key_changed_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_ignore_key_changed_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_ignore_key_changed_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +void *test_thread1(void *arg) +{ + vconf_set_int(KEY_DB, 100); + return NULL; +} + +void test_cb(keynode_t* pKey, void* pData) +{ + int r = 0; + g_main_loop_quit(event_loop); + + r = vconf_ignore_key_changed(KEY_DB, test_cb); + if (r) { + tet_infoline("vconf_notify_key_changed() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + vconf_set_int(KEY_DB, 10); + + event_loop = g_main_loop_new(NULL, FALSE); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); +} + +/** + * @brief Positive test case of vconf_ignore_key_changed() + */ +static void utc_ApplicationFW_vconf_ignore_key_changed_func_01(void) +{ + pthread_t test_thread; + int r = 0; + + r = vconf_notify_key_changed(KEY_DB, test_cb, NULL); + if (r) { + tet_infoline("vconf_notify_key_changed() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + pthread_create(&test_thread, NULL, test_thread1, NULL); + pthread_detach(test_thread); + + g_main_loop_run(event_loop); +} + +/** + * @brief Negative test case of ug_init vconf_ignore_key_changed() + */ +static void utc_ApplicationFW_vconf_ignore_key_changed_func_02(void) +{ + int r = 0; + + r = vconf_ignore_key_changed(KEY_DB, NULL); + if (!r) { + tet_infoline("vconf_ignore_key_changed() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_add_bool_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_add_bool_func.c new file mode 100644 index 0000000..b740fd5 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_add_bool_func.c @@ -0,0 +1,140 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_add_bool_func_01(void); +static void utc_ApplicationFW_vconf_keylist_add_bool_func_02(void); +// static void utc_ApplicationFW_vconf_keylist_add_bool_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_add_bool_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_add_bool_func_02, NEGATIVE_TC_IDX }, +// { utc_ApplicationFW_vconf_keylist_add_bool_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_add_bool() + */ +static void utc_ApplicationFW_vconf_keylist_add_bool_func_01(void) +{ + int r = 0; + + r = vconf_keylist_add_bool(pKeyList, KEY_DB, 1); + if (r<0) { + tet_infoline("vconf_keylist_add_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_bool(pKeyList, KEY_MEMORY, 0); + if (r<0) { + tet_infoline("vconf_keylist_add_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_bool(pKeyList, KEY_FILE, 1); + if (r<0) { + tet_infoline("vconf_keylist_add_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_add_bool() + */ +static void utc_ApplicationFW_vconf_keylist_add_bool_func_02(void) +{ + int r = 0; + + r = vconf_keylist_add_bool(NULL, KEY_DB, 0); + if (r!=-1) { + tet_infoline("vconf_keylist_add_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +#if 0 +/** + * @brief Negative test case of ug_init vconf_keylist_add_bool() + */ +static void utc_ApplicationFW_vconf_keylist_add_bool_func_03(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_keylist_add_bool(pKeyList, InvalidBackend, 0); + if (r!=-1) { + tet_infoline("vconf_keylist_add_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} +#endif diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_add_dbl_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_add_dbl_func.c new file mode 100644 index 0000000..7a964eb --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_add_dbl_func.c @@ -0,0 +1,140 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_add_dbl_func_01(void); +static void utc_ApplicationFW_vconf_keylist_add_dbl_func_02(void); +// static void utc_ApplicationFW_vconf_keylist_add_dbl_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_add_dbl_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_add_dbl_func_02, NEGATIVE_TC_IDX }, +// { utc_ApplicationFW_vconf_keylist_add_dbl_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_add_dbl() + */ +static void utc_ApplicationFW_vconf_keylist_add_dbl_func_01(void) +{ + int r = 0; + + r = vconf_keylist_add_dbl(pKeyList, KEY_DB, 0.45); + if (r<0) { + tet_infoline("vconf_keylist_add_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_dbl(pKeyList, KEY_MEMORY, -320.45); + if (r<0) { + tet_infoline("vconf_keylist_add_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_dbl(pKeyList, KEY_FILE, 235.25); + if (r<0) { + tet_infoline("vconf_keylist_add_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_add_dbl() + */ +static void utc_ApplicationFW_vconf_keylist_add_dbl_func_02(void) +{ + int r = 0; + + r = vconf_keylist_add_dbl(NULL, KEY_DB, 43.456); + if (r!=-1) { + tet_infoline("vconf_keylist_add_dbl() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +#if 0 +/** + * @brief Negative test case of ug_init vconf_keylist_add_dbl() + */ +static void utc_ApplicationFW_vconf_keylist_add_dbl_func_03(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_keylist_add_dbl(pKeyList, InvalidBackend, 43.456); + if (r!=-1) { + tet_infoline("vconf_keylist_add_dbl() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} +#endif diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_add_int_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_add_int_func.c new file mode 100644 index 0000000..528882f --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_add_int_func.c @@ -0,0 +1,118 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_add_int_func_01(void); +static void utc_ApplicationFW_vconf_keylist_add_int_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_add_int_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_add_int_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_add_int() + */ +static void utc_ApplicationFW_vconf_keylist_add_int_func_01(void) +{ + int r = 0; + + r = vconf_keylist_add_int(pKeyList, KEY_DB, 15); + if (r<0) { + tet_infoline("vconf_keylist_add_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_int(pKeyList, KEY_MEMORY, 435); + if (r<0) { + tet_infoline("vconf_keylist_add_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_int(pKeyList, KEY_FILE, -15); + if (r<0) { + tet_infoline("vconf_keylist_add_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_add_int() + */ +static void utc_ApplicationFW_vconf_keylist_add_int_func_02(void) +{ + int r = 0; + + r = vconf_keylist_add_int(NULL, KEY_DB, 45); + if (r!=-1) { + tet_infoline("vconf_keylist_add_int() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_add_null_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_add_null_func.c new file mode 100644 index 0000000..f9e2e51 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_add_null_func.c @@ -0,0 +1,118 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_add_null_func_01(void); +static void utc_ApplicationFW_vconf_keylist_add_null_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_add_null_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_add_null_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_add_null() + */ +static void utc_ApplicationFW_vconf_keylist_add_null_func_01(void) +{ + int r = 0; + + r = vconf_keylist_add_null(pKeyList, KEY_DB); + if (r<0) { + tet_infoline("vconf_keylist_add_null() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_null(pKeyList, KEY_MEMORY); + if (r<0) { + tet_infoline("vconf_keylist_add_null() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_null(pKeyList, KEY_FILE); + if (r<0) { + tet_infoline("vconf_keylist_add_null() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_add_null() + */ +static void utc_ApplicationFW_vconf_keylist_add_null_func_02(void) +{ + int r = 0; + + r = vconf_keylist_add_null(NULL, KEY_DB); + if (r!=-1) { + tet_infoline("vconf_keylist_add_null() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_add_str_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_add_str_func.c new file mode 100644 index 0000000..ddb6695 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_add_str_func.c @@ -0,0 +1,118 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_add_str_func_01(void); +static void utc_ApplicationFW_vconf_keylist_add_str_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_add_str_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_add_str_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_add_str() + */ +static void utc_ApplicationFW_vconf_keylist_add_str_func_01(void) +{ + int r = 0; + + r = vconf_keylist_add_str(pKeyList, KEY_DB, "TestMessage01"); + if (r<0) { + tet_infoline("vconf_keylist_add_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_str(pKeyList, KEY_MEMORY, "TestMessage02"); + if (r<0) { + tet_infoline("vconf_keylist_add_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_add_str(pKeyList, KEY_FILE, "TestMessage03"); + if (r<0) { + tet_infoline("vconf_keylist_add_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_add_str() + */ +static void utc_ApplicationFW_vconf_keylist_add_str_func_02(void) +{ + int r = 0; + + r = vconf_keylist_add_str(NULL, KEY_DB, "TestMessage01"); + if (r!=-1) { + tet_infoline("vconf_keylist_add_str() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_del_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_del_func.c new file mode 100644 index 0000000..50ed551 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_del_func.c @@ -0,0 +1,179 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_del_func_01(void); +static void utc_ApplicationFW_vconf_keylist_del_func_02(void); +static void utc_ApplicationFW_vconf_keylist_del_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_del_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_del_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_del_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_del() + */ +static void utc_ApplicationFW_vconf_keylist_del_func_01(void) +{ + int r = 0; + char* pszKeyName = NULL; + keynode_t* pKeyNode = 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; + } + + if(vconf_keylist_del(pKeyList, KEY_03)<0) + { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + pszKeyName = vconf_keynode_get_name(pKeyNode); + if(!strncmp(pszKeyName, KEY_03, strlen(pszKeyName))) + { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_del() + */ +static void utc_ApplicationFW_vconf_keylist_del_func_02(void) +{ + if(vconf_keylist_del(NULL, KEY_03)>=0) + { + tet_infoline("vconf_keylist_del() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_del() + */ +static void utc_ApplicationFW_vconf_keylist_del_func_03(void) +{ + int r = 0; + + 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; + } + + if(vconf_keylist_del(pKeyList, NULL)>=0) + { + tet_infoline("vconf_keylist_del() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + tet_result(TET_PASS); +} + diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_free_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_free_func.c new file mode 100644 index 0000000..b77ad84 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_free_func.c @@ -0,0 +1,96 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_free_func_01(void); +static void utc_ApplicationFW_vconf_keylist_free_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_free_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_free_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_free() + */ +static void utc_ApplicationFW_vconf_keylist_free_func_01(void) +{ + pKeyList = vconf_keylist_new(); + if (!pKeyList) { + tet_infoline("vconf_keylist_new() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + if(vconf_keylist_free(pKeyList)<0) + { + tet_infoline("vconf_keylist_new() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_free() + */ +static void utc_ApplicationFW_vconf_keylist_free_func_02(void) +{ + int r; + r = vconf_keylist_free(NULL); + + if (r!=-1) { + tet_infoline("vconf_keylist_free() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_get_bool_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_get_bool_func.c new file mode 100644 index 0000000..b036ae0 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_get_bool_func.c @@ -0,0 +1,86 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_get_bool_func_01(void); +static void utc_ApplicationFW_vconf_keylist_get_bool_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_get_bool_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_get_bool_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of vconf_keylist_get_bool() + */ +static void utc_ApplicationFW_vconf_keylist_get_bool_func_01(void) +{ + int r = 0; + +/* + r = vconf_keylist_get_bool(...); +*/ + if (r) { + tet_infoline("vconf_keylist_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_bool() + */ +static void utc_ApplicationFW_vconf_keylist_get_bool_func_02(void) +{ + int r = 0; + +/* + r = vconf_keylist_get_bool(...); +*/ + if (r) { + tet_infoline("vconf_keylist_get_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_lookup_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_lookup_func.c new file mode 100644 index 0000000..9644340 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_lookup_func.c @@ -0,0 +1,205 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_lookup_func_01(void); +static void utc_ApplicationFW_vconf_keylist_lookup_func_02(void); +static void utc_ApplicationFW_vconf_keylist_lookup_func_03(void); +static void utc_ApplicationFW_vconf_keylist_lookup_func_04(void); + + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_lookup_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_lookup_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_lookup_func_03, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_lookup_func_04, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_lookup() + */ +static void utc_ApplicationFW_vconf_keylist_lookup_func_01(void) +{ + int r = 0; + int nResult = 0; + keynode_t* pKeyNode = NULL; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r<0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode); + if (r<0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + nResult = vconf_keynode_get_int(pKeyNode); + if(nResult !=KEY_02_INT_VALUE) + { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_lookup() + */ +static void utc_ApplicationFW_vconf_keylist_lookup_func_02(void) +{ + int r = 0; + keynode_t* pKeyNode = NULL; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r<0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_lookup(pKeyList, NULL, &pKeyNode); + if (r>=0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_lookup() + */ +static void utc_ApplicationFW_vconf_keylist_lookup_func_03(void) +{ + int r; + keynode_t* pKeyNode = NULL; + r = vconf_keylist_lookup(NULL, KEY_02, &pKeyNode); + + if (r>=0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_lookup() + */ +static void utc_ApplicationFW_vconf_keylist_lookup_func_04(void) +{ + int r = 0; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r<0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_keylist_lookup(pKeyList, KEY_02, NULL); + if (r>=0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + + diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_new_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_new_func.c new file mode 100644 index 0000000..7f4f1b9 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_new_func.c @@ -0,0 +1,86 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_new_func_01(void); +static void utc_ApplicationFW_vconf_keylist_new_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_new_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_new_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_new() + */ +static void utc_ApplicationFW_vconf_keylist_new_func_01(void) +{ + pKeyList = vconf_keylist_new(); + if (!pKeyList) { + tet_infoline("vconf_keylist_new() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_new() + */ +static void utc_ApplicationFW_vconf_keylist_new_func_02(void) +{ + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_nextnode_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_nextnode_func.c new file mode 100644 index 0000000..91846f5 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_nextnode_func.c @@ -0,0 +1,112 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_nextnode_func_01(void); +static void utc_ApplicationFW_vconf_keylist_nextnode_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_nextnode_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_nextnode_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, 0); + vconf_keylist_add_int(pKeyList, KEY_02, 100); + vconf_keylist_add_dbl(pKeyList, KEY_03, 0.453); + + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_nextnode() + */ +static void utc_ApplicationFW_vconf_keylist_nextnode_func_01(void) +{ + int r; + + 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; + } + + while(vconf_keylist_nextnode(pKeyList)) ; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_nextnode() + */ +static void utc_ApplicationFW_vconf_keylist_nextnode_func_02(void) +{ + // There is no Negative test case for vconf_keylist_nextnode function. + + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keylist_rewind_func.c b/TC/unit/utc_ApplicationFW_vconf_keylist_rewind_func.c new file mode 100644 index 0000000..dcaadfe --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keylist_rewind_func.c @@ -0,0 +1,139 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <stdio.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keylist_rewind_func_01(void); +static void utc_ApplicationFW_vconf_keylist_rewind_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keylist_rewind_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keylist_rewind_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, 0); + vconf_keylist_add_int(pKeyList, KEY_02, 100); + vconf_keylist_add_dbl(pKeyList, KEY_03, 0.453); + + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_rewind() + */ +static void utc_ApplicationFW_vconf_keylist_rewind_func_01(void) +{ + int r; + int nCount = 0; + + 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); + + + 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)) { + nCount++; + } + + if (nCount <= 0) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_rewind() + */ +static void utc_ApplicationFW_vconf_keylist_rewind_func_02(void) +{ + if (vconf_keylist_rewind(NULL) >=0) { + tet_infoline("vconf_keylist_rewind() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_bool_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_bool_func.c new file mode 100644 index 0000000..9b42993 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_bool_func.c @@ -0,0 +1,192 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_bool_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_bool_func_02(void); +static void utc_ApplicationFW_vconf_keynode_get_bool_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_bool_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_bool_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_bool_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keynode_get_bool() + */ +static void utc_ApplicationFW_vconf_keynode_get_bool_func_01(void) +{ + int r = 0; + int nResult = 0; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_BOOL: + nResult = vconf_keynode_get_bool(pKeyNode); + if (nResult != KEY_01_BOOL_VALUE) { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keynode_get_bool() + */ +static void utc_ApplicationFW_vconf_keynode_get_bool_func_02(void) +{ + int r = 0; + + r = vconf_keynode_get_bool(NULL); + if (r!=-1) { + tet_infoline("vconf_keynode_get_bool() func_02 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keynode_get_bool() + */ +static void utc_ApplicationFW_vconf_keynode_get_bool_func_03(void) +{ + int r = 0; + keynode_t* pKeyNode = NULL; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r) { + tet_infoline("vconf_get() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_INT: + r = vconf_keynode_get_bool(pKeyNode); + if (r!=-1) { + tet_infoline("vconf_keynode_get_bool() func_03 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_dbl_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_dbl_func.c new file mode 100644 index 0000000..8848d72 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_dbl_func.c @@ -0,0 +1,192 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <stdio.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_02(void); +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_dbl_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_dbl_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_dbl_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_get_dbl() + */ +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_01(void) +{ + int r = 0; + double dResult = 0; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_DOUBLE: + dResult = vconf_keynode_get_dbl(pKeyNode); + if (dResult != KEY_03_DOUBLE_VALUE) { + tet_infoline("vconf_keynode_get_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_dbl() + */ +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_02(void) +{ + double dResult; + dResult = vconf_keynode_get_dbl(NULL); + if (dResult != -1.0) { + tet_infoline("vconf_keynode_get_bool() func_02 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_dbl() + */ +static void utc_ApplicationFW_vconf_keynode_get_dbl_func_03(void) +{ + double dResult; + int r; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_INT: + dResult = vconf_keynode_get_dbl(pKeyNode); + if (dResult!=-1.0) { + tet_infoline("vconf_keynode_get_bool() func_03 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_int_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_int_func.c new file mode 100644 index 0000000..7db0fe1 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_int_func.c @@ -0,0 +1,192 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_int_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_int_func_02(void); +static void utc_ApplicationFW_vconf_keynode_get_int_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_int_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_int_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_int_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_get_int() + */ +static void utc_ApplicationFW_vconf_keynode_get_int_func_01(void) +{ + int r = 0; + int nResult = 0; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_INT: + nResult = vconf_keynode_get_int(pKeyNode); + if (nResult != KEY_02_INT_VALUE) { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_int() + */ +static void utc_ApplicationFW_vconf_keynode_get_int_func_02(void) +{ + int nResult; + nResult = vconf_keynode_get_int(NULL); + if (nResult != -1) { + tet_infoline("vconf_keynode_get_int() func_02 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_int() + */ +static void utc_ApplicationFW_vconf_keynode_get_int_func_03(void) +{ + int nResult; + int r; + keynode_t* pKeyNode = NULL; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r) { + tet_infoline("vconf_get() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_DOUBLE: + nResult = vconf_keynode_get_int(pKeyNode); + if (nResult!=-1) { + tet_infoline("vconf_keynode_get_int() func_03 failed in negative test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_name_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_name_func.c new file mode 100644 index 0000000..ac6b636 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_name_func.c @@ -0,0 +1,168 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; +static char* KEY_04 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; +static char* KEY_04_STRING_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_name_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_name_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_name_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_name_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + KEY_04="db/tet/key_4"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + KEY_04_STRING_VALUE = "TestMessage"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + vconf_keylist_add_str(pKeyList, KEY_04, KEY_04_STRING_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_get_name() + */ +static void utc_ApplicationFW_vconf_keynode_get_name_func_01(void) +{ + int r = 0; + char* pszKeyName = NULL; + char* pszBasicKey = NULL; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_BOOL: + pszBasicKey = KEY_01; + break; + + case VCONF_TYPE_INT: + pszBasicKey = KEY_02; + break; + + case VCONF_TYPE_DOUBLE: + pszBasicKey = KEY_03; + break; + + case VCONF_TYPE_STRING: + pszBasicKey = KEY_04; + break; + + default: + break; + } + + + pszKeyName = vconf_keynode_get_name(pKeyNode); + if (strncmp(pszKeyName, pszBasicKey, strlen(pszKeyName))) + { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_name() + */ +static void utc_ApplicationFW_vconf_keynode_get_name_func_02(void) +{ + char* pszRet = vconf_keynode_get_name(NULL); + if (pszRet) { + tet_infoline("vconf_keylist_get_name() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_str_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_str_func.c new file mode 100644 index 0000000..54e5b70 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_str_func.c @@ -0,0 +1,196 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; +static char* KEY_04 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; +static char* KEY_04_STRING_VALUE; + + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_str_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_str_func_02(void); +// static void utc_ApplicationFW_vconf_keynode_get_str_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_str_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_str_func_02, NEGATIVE_TC_IDX }, +// { utc_ApplicationFW_vconf_keynode_get_str_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + KEY_04="db/tet/key_4"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + KEY_04_STRING_VALUE = "TestMessage"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + vconf_keylist_add_str(pKeyList, KEY_04, KEY_04_STRING_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_keylist_get_str() + */ +static void utc_ApplicationFW_vconf_keynode_get_str_func_01(void) +{ + int r = 0; + char* pszRet; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_STRING: + pszRet = vconf_keynode_get_str(pKeyNode); + if (strncmp(pszRet, KEY_04_STRING_VALUE, strlen(pszRet))) { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_str() + */ +static void utc_ApplicationFW_vconf_keynode_get_str_func_02(void) +{ + char* pszRet = NULL; + pszRet = vconf_keynode_get_str(NULL); + if (pszRet != NULL) { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +#if 0 +static void utc_ApplicationFW_vconf_keynode_get_str_func_03(void) +{ + int r = 0; + char* pszRet; + keynode_t* pKeyNode = 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; + } + + while(pKeyNode = vconf_keylist_nextnode(pKeyList)) + { + switch(vconf_keynode_get_type(pKeyNode)) + { + case VCONF_TYPE_INT: + pszRet = vconf_keynode_get_str(pKeyNode); + if (pszRet!=NULL) + { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + break; + + default: + break; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} +#endif diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_get_type_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_get_type_func.c new file mode 100644 index 0000000..9deb3ff --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_get_type_func.c @@ -0,0 +1,143 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <string.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; +static char* KEY_04 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; +static char* KEY_04_STRING_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_get_type_func_01(void); +static void utc_ApplicationFW_vconf_keynode_get_type_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_get_type_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_get_type_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + KEY_04="db/tet/key_4"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + KEY_04_STRING_VALUE = "TestMessage"; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + vconf_keylist_add_str(pKeyList, KEY_04, KEY_04_STRING_VALUE); + + vconf_set(pKeyList); + vconf_keylist_free(pKeyList); + pKeyList = NULL; +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } + +} + +/** + * @brief Positive test case of vconf_keylist_get_type() + */ +static void utc_ApplicationFW_vconf_keynode_get_type_func_01(void) +{ + int r = 0; + keynode_t* pKeyNode = 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; + } + + while((pKeyNode = vconf_keylist_nextnode(pKeyList))!=NULL) + { + if(vconf_keynode_get_type(pKeyNode) == -1) + { + tet_infoline("vconf_keynode_get_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keylist_get_type() + */ +static void utc_ApplicationFW_vconf_keynode_get_type_func_02(void) +{ + int r = vconf_keynode_get_type(NULL); + if (r!=-1) { + tet_infoline("vconf_keylist_get_name() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_keynode_steal_str_func.c b/TC/unit/utc_ApplicationFW_vconf_keynode_steal_str_func.c new file mode 100644 index 0000000..3359fe1 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_keynode_steal_str_func.c @@ -0,0 +1,86 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_keynode_steal_str_func_01(void); +static void utc_ApplicationFW_vconf_keynode_steal_str_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_keynode_steal_str_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_keynode_steal_str_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of vconf_keynode_steal_str() + */ +static void utc_ApplicationFW_vconf_keynode_steal_str_func_01(void) +{ + int r = 0; + +/* + r = vconf_keynode_steal_str(...); +*/ + if (r) { + tet_infoline("vconf_keynode_steal_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_keynode_steal_str() + */ +static void utc_ApplicationFW_vconf_keynode_steal_str_func_02(void) +{ + int r = 0; + +/* + r = vconf_keynode_steal_str(...); +*/ + if (r) { + tet_infoline("vconf_keynode_steal_str() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_notify_key_changed_func.c b/TC/unit/utc_ApplicationFW_vconf_notify_key_changed_func.c new file mode 100644 index 0000000..89eef85 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_notify_key_changed_func.c @@ -0,0 +1,121 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <stdio.h> +#include <vconf.h> +#include <glib.h> +#include <glib-object.h> +#include <pthread.h> + +static GMainLoop* event_loop = NULL; +static char* KEY_DB = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_notify_key_changed_func_01(void); +static void utc_ApplicationFW_vconf_notify_key_changed_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_notify_key_changed_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_notify_key_changed_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +void *test_thread1(void *arg) +{ + vconf_set_int(KEY_DB, 100); + return NULL; +} + +void test_cb(keynode_t* pKey, void* pData) +{ + switch(vconf_keynode_get_type(pKey)) + { + case VCONF_TYPE_INT: + printf("key = %s, value = %d(int)\n", vconf_keynode_get_name(pKey), vconf_keynode_get_int(pKey)); + break; + default: + break; + } + + tet_result(TET_PASS); + g_main_loop_quit(event_loop); +} + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + vconf_set_int(KEY_DB, 10); + + event_loop = g_main_loop_new(NULL, FALSE); +} + +static void cleanup(void) +{ + vconf_ignore_key_changed(KEY_DB, test_cb); + vconf_unset(KEY_DB); +} + +/** + * @brief Positive test case of vconf_notify_key_changed() + */ +static void utc_ApplicationFW_vconf_notify_key_changed_func_01(void) +{ + pthread_t test_thread; + int r = 0; + + r = vconf_notify_key_changed(KEY_DB, test_cb, NULL); + if (r) { + tet_infoline("vconf_notify_key_changed() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + pthread_create(&test_thread, NULL, test_thread1, NULL); + pthread_detach(test_thread); + + g_main_loop_run(event_loop); +} + +/** + * @brief Negative test case of ug_init vconf_notify_key_changed() + */ +static void utc_ApplicationFW_vconf_notify_key_changed_func_02(void) +{ + int r = 0; + + r = vconf_notify_key_changed(KEY_DB, NULL, NULL); + if (!r) { + tet_infoline("vconf_notify_key_changed() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_bool_func.c b/TC/unit/utc_ApplicationFW_vconf_set_bool_func.c new file mode 100644 index 0000000..3bceae6 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_bool_func.c @@ -0,0 +1,108 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_bool_func_01(void); +static void utc_ApplicationFW_vconf_set_bool_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_bool_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_bool_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_set_bool() + */ +static void utc_ApplicationFW_vconf_set_bool_func_01(void) +{ + int r = 0; + + r = vconf_set_bool(KEY_DB, 1); + if (r) { + tet_infoline("vconf_set_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_bool(KEY_MEMORY, 0); + if (r) { + tet_infoline("vconf_set_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_bool(KEY_FILE, 1); + if (r) { + tet_infoline("vconf_set_bool() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_set_bool() + */ +static void utc_ApplicationFW_vconf_set_bool_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_set_bool(InvalidBackend, 0); + if (!r) { + tet_infoline("vconf_set_bool() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_bytes_func.c b/TC/unit/utc_ApplicationFW_vconf_set_bytes_func.c new file mode 100644 index 0000000..ce9066d --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_bytes_func.c @@ -0,0 +1,112 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_bytes_func_01(void); +static void utc_ApplicationFW_vconf_set_bytes_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_bytes_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_bytes_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{
+ KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + + +/** + * @brief Positive test case of vconf_set_bytes() + */ +static void utc_ApplicationFW_vconf_set_bytes_func_01(void) +{ + int r = 0; + char szBuffer[1024] = {"This is a kind of test."}; + + r = vconf_set_bytes(KEY_DB, (void*)szBuffer, sizeof(szBuffer)); + if (r) { + tet_infoline("vconf_set_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + }
+ + r = vconf_set_bytes(KEY_MEMORY, (void*)szBuffer, sizeof(szBuffer)); + if (r) { + tet_infoline("vconf_set_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_bytes(KEY_FILE, (void*)szBuffer, sizeof(szBuffer)); + if (r) { + tet_infoline("vconf_set_bytes() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_set_bytes() + */ +static void utc_ApplicationFW_vconf_set_bytes_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + char szBuffer[1024] = {"This is a kind of test."}; + + r = vconf_set_bytes(InvalidBackend, (void*)szBuffer, sizeof(szBuffer)); + if (!r) { + tet_infoline("vconf_set_bytes() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_dbl_func.c b/TC/unit/utc_ApplicationFW_vconf_set_dbl_func.c new file mode 100644 index 0000000..9d2f925 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_dbl_func.c @@ -0,0 +1,111 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_dbl_func_01(void); +static void utc_ApplicationFW_vconf_set_dbl_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_dbl_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_dbl_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_set_dbl() + */ +static void utc_ApplicationFW_vconf_set_dbl_func_01(void) +{ + int r = 0; + + r = vconf_set_dbl(KEY_DB, 10.45); + if (r) { + tet_infoline("vconf_set_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_dbl(KEY_MEMORY, 0.528); + if (r) { + tet_infoline("vconf_set_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_dbl(KEY_FILE, -12.1324); + if (r) { + tet_infoline("vconf_set_dbl() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); + +} + +/** + * @brief Negative test case of ug_init vconf_set_dbl() + */ +static void utc_ApplicationFW_vconf_set_dbl_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + + r = vconf_set_dbl(InvalidBackend, 10.876); + if (!r) { + tet_infoline("vconf_set_dbl() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_func.c b/TC/unit/utc_ApplicationFW_vconf_set_func.c new file mode 100644 index 0000000..8795c66 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_func.c @@ -0,0 +1,117 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +keylist_t* pKeyList = NULL; +static char* KEY_PARENT = NULL; +static char* KEY_01 = NULL; +static char* KEY_02 = NULL; +static char* KEY_03 = NULL; + +static int KEY_01_BOOL_VALUE; +static int KEY_02_INT_VALUE; +static double KEY_03_DOUBLE_VALUE; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_func_01(void); +static void utc_ApplicationFW_vconf_set_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_PARENT = "db/tet"; + KEY_01="db/tet/key_1"; + KEY_02="db/tet/key_2"; + KEY_03="db/tet/key_3"; + + KEY_01_BOOL_VALUE = 1; + KEY_02_INT_VALUE = 100; + KEY_03_DOUBLE_VALUE = 25.458; + + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +static void cleanup(void) +{ + if(pKeyList!=NULL) + { + vconf_keylist_free(pKeyList); + pKeyList = NULL; + } +} + +/** + * @brief Positive test case of vconf_set() + */ +static void utc_ApplicationFW_vconf_set_func_01(void) +{ + int r = 0; + pKeyList = vconf_keylist_new(); + + vconf_keylist_add_bool(pKeyList, KEY_01, KEY_01_BOOL_VALUE); + vconf_keylist_add_int(pKeyList, KEY_02, KEY_02_INT_VALUE); + vconf_keylist_add_dbl(pKeyList, KEY_03, KEY_03_DOUBLE_VALUE); + + r = vconf_set(pKeyList); + if (r<0) { + tet_infoline("vconf_set() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + vconf_keylist_free(pKeyList); + pKeyList = NULL; + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_set() + */ +static void utc_ApplicationFW_vconf_set_func_02(void) +{ + if (vconf_set(NULL)>=0) { + tet_infoline("vconf_set() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_int_func.c b/TC/unit/utc_ApplicationFW_vconf_set_int_func.c new file mode 100644 index 0000000..4db76b0 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_int_func.c @@ -0,0 +1,111 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <stdio.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_int_func_01(void); +static void utc_ApplicationFW_vconf_set_int_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_int_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_int_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_set_int() + */ +static void utc_ApplicationFW_vconf_set_int_func_01(void) +{ + int r = 0; + + r = vconf_set_int(KEY_DB, 10); + if (r) { + tet_infoline("vconf_set_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_int(KEY_MEMORY, 10); + if (r) { + tet_infoline("vconf_set_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_int(KEY_FILE, 10); + if (r) { + tet_infoline("vconf_set_int() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_set_int() + */ +static void utc_ApplicationFW_vconf_set_int_func_02(void) +{ + int r = 0; + const char* pInvalidBackend = "Invalid/tet/key_1"; + + r = vconf_set_int(pInvalidBackend, 10); + if (!r) { + tet_infoline("vconf_set_int() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_set_str_func.c b/TC/unit/utc_ApplicationFW_vconf_set_str_func.c new file mode 100644 index 0000000..c4d64c7 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_set_str_func.c @@ -0,0 +1,108 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_set_str_func_01(void); +static void utc_ApplicationFW_vconf_set_str_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_set_str_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_set_str_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{
+ KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_set_str() + */ +static void utc_ApplicationFW_vconf_set_str_func_01(void) +{ + int r = 0; + + r = vconf_set_str(KEY_DB, "Test String"); + if (r) { + tet_infoline("vconf_set_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_str(KEY_MEMORY, "Test String"); + if (r) { + tet_infoline("vconf_set_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_set_str(KEY_FILE, "Test String"); + if (r) { + tet_infoline("vconf_set_str() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_set_str() + */ +static void utc_ApplicationFW_vconf_set_str_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_set_str(InvalidBackend, "Invalid Backend"); + if (!r) { + tet_infoline("vconf_set_str() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_sync_key_func.c b/TC/unit/utc_ApplicationFW_vconf_sync_key_func.c new file mode 100644 index 0000000..f71d16a --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_sync_key_func.c @@ -0,0 +1,91 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_FILE_01 = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_sync_key_func_01(void); +static void utc_ApplicationFW_vconf_sync_key_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_sync_key_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_sync_key_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_FILE_01="file/tet/key_1"; +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of vconf_sync_key() + */ +static void utc_ApplicationFW_vconf_sync_key_func_01(void) +{ + if(vconf_set_int(KEY_FILE_01, 10)<0) + { + tet_infoline("vconf_sync_key() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + if(vconf_sync_key(KEY_FILE_01)<0) + { + tet_infoline("vconf_sync_key() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_sync_key() + */ +static void utc_ApplicationFW_vconf_sync_key_func_02(void) +{ + const char* InvalidBackend = "Invalid/tet/key_1"; + if(vconf_sync_key(InvalidBackend)>=0) + { + tet_infoline("vconf_sync_key() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_ApplicationFW_vconf_unset_func.c b/TC/unit/utc_ApplicationFW_vconf_unset_func.c new file mode 100644 index 0000000..6150d83 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_unset_func.c @@ -0,0 +1,134 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> + +static char* KEY_DB = NULL; +static char* KEY_MEMORY = NULL; +static char* KEY_FILE = NULL; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_unset_func_01(void); +static void utc_ApplicationFW_vconf_unset_func_02(void); +static void utc_ApplicationFW_vconf_unset_func_03(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_unset_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_unset_func_02, NEGATIVE_TC_IDX }, + { utc_ApplicationFW_vconf_unset_func_03, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + KEY_DB="db/tet/key_1"; + KEY_MEMORY="memory/tet/key_2"; + KEY_FILE="file/tet/key_3"; + + vconf_set_bool(KEY_DB, 0); + vconf_set_int(KEY_MEMORY, 0); + vconf_set_dbl(KEY_FILE, 0); +} + +static void cleanup(void) +{ + vconf_unset(KEY_DB); + vconf_unset(KEY_MEMORY); + vconf_unset(KEY_FILE); +} + +/** + * @brief Positive test case of vconf_unset() + */ +static void utc_ApplicationFW_vconf_unset_func_01(void) +{ + int r = 0; + + r = vconf_unset(KEY_DB); + if (r) { + tet_infoline("vconf_unset() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_unset(KEY_MEMORY); + if (r) { + tet_infoline("vconf_unset() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + r = vconf_unset(KEY_FILE); + if (r) { + tet_infoline("vconf_unset() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_unset() + */ +static void utc_ApplicationFW_vconf_unset_func_02(void) +{ + int r = 0;
+ const char* InvalidBackend = "Invalid/tet/key_1"; + + r = vconf_unset(InvalidBackend); + if (!r) { + tet_infoline("vconf_unset() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_unset() + */ +static void utc_ApplicationFW_vconf_unset_func_03(void) +{ + int r = 0;
+ + vconf_unset(KEY_DB); + r = vconf_unset(KEY_DB); + if (!r) { + tet_infoline("vconf_unset() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + diff --git a/TC/unit/utc_ApplicationFW_vconf_unset_recursive_func.c b/TC/unit/utc_ApplicationFW_vconf_unset_recursive_func.c new file mode 100644 index 0000000..87720c6 --- /dev/null +++ b/TC/unit/utc_ApplicationFW_vconf_unset_recursive_func.c @@ -0,0 +1,105 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <tet_api.h> +#include <vconf.h> +#include <stdio.h> +#include <string.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_ApplicationFW_vconf_unset_recursive_func_01(void); +static void utc_ApplicationFW_vconf_unset_recursive_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_ApplicationFW_vconf_unset_recursive_func_01, POSITIVE_TC_IDX }, + { utc_ApplicationFW_vconf_unset_recursive_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of vconf_unset_recursive() + */ +static void utc_ApplicationFW_vconf_unset_recursive_func_01(void) +{ + int r = 0; + char* pszBackend[3] = {"db", "memory", "file"}; + char szBuffer[1024] = {0, }; + int i, j; + + for(i=0; i<3; ++i) + { + for(j=0; j<5; ++j) + { + snprintf(szBuffer, 1024, "%s/tet/key_%d", pszBackend[i], j); + vconf_set_int(szBuffer, 10); + memset(szBuffer, 0x00, sizeof(szBuffer)); + } + } + + for(i=0; i<3; ++i) + { + snprintf(szBuffer, 1024, "%s/tet", pszBackend[i]); + r = vconf_unset_recursive(szBuffer); + if (r) { + tet_infoline("vconf_unset_recursive() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + memset(szBuffer, 0x00, sizeof(szBuffer)); + } + + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init vconf_unset_recursive() + */ +static void utc_ApplicationFW_vconf_unset_recursive_func_02(void) +{ + int r = 0; + const char* InvalidBackend = "Invalid/tet"; + + r = vconf_unset_recursive(InvalidBackend); + if (!r) { + tet_infoline("vconf_unset_recursive() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/TC/unit/utc_MODULE_API_func.c.in b/TC/unit/utc_MODULE_API_func.c.in new file mode 100644 index 0000000..0f34b9c --- /dev/null +++ b/TC/unit/utc_MODULE_API_func.c.in @@ -0,0 +1,64 @@ +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_@MODULE@_@API@_func_01(void); +static void utc_@MODULE@_@API@_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_@MODULE@_@API@_func_01, POSITIVE_TC_IDX }, + { utc_@MODULE@_@API@_func_02, NEGATIVE_TC_IDX }, +}; + +static void startup(void) +{ +} + +static void cleanup(void) +{ +} + +/** + * @brief Positive test case of @API@() + */ +static void utc_@MODULE@_@API@_func_01(void) +{ + int r = 0; + + + r = @API@(...); + + if (r<0) { + tet_infoline("@API@() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} + +/** + * @brief Negative test case of ug_init @API@() + */ +static void utc_@MODULE@_@API@_func_02(void) +{ + int r = 0; + + + r = @API@(...); + + if (r>=0) { + tet_infoline("@API@() failed in negative test case"); + tet_result(TET_FAIL); + return; + } + tet_result(TET_PASS); +} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..842ae6f --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ + +cd `dirname $0` + +rm -rf cmake_tmp +mkdir -p cmake_tmp +cd cmake_tmp && + +cmake .. -DCMAKE_INSTALL_PREFIX=/usr && +make && +echo "Done." diff --git a/image/SLP_Vconf_PG_image01.png b/image/SLP_Vconf_PG_image01.png Binary files differnew file mode 100755 index 0000000..3e802cf --- /dev/null +++ b/image/SLP_Vconf_PG_image01.png diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..c18096f --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,52 @@ + +# Strict header check + +# Warnings mode +ADD_DEFINITIONS("-Werror") # Make all warnings into errors. + +# Warning flags +ADD_DEFINITIONS("-Wall") # Generate all warnings +ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings +ADD_DEFINITIONS("-ansi") # Accept only ANSI code +ADD_DEFINITIONS("-pedantic") # Accept only pedantic code +#ADD_DEFINITIONS("-Weffc++") # Accept only effective C++ code +ADD_DEFINITIONS("-Wwrite-strings") # Do not accept writing to contant string memory +ADD_DEFINITIONS("-Winit-self") # Do not accept initializing variable with itself +ADD_DEFINITIONS("-Wcast-align") # Do not accept misaligning with casting +ADD_DEFINITIONS("-Wcast-qual") # Do not accept removing qualifiers with casting +#ADD_DEFINITIONS("-Wold-style-cast") # Do not accept old style casting +ADD_DEFINITIONS("-Wpointer-arith") # Warn about void pointer arthimetic +ADD_DEFINITIONS("-Wstrict-aliasing") # Ensure strict aliasing +ADD_DEFINITIONS("-Wuninitialized") # Do not accept uninitialized variables +ADD_DEFINITIONS("-Wmissing-declarations") # Warn about global and non-accesible functions +#ADD_DEFINITIONS("-Woverloaded-virtual") # Warn about incidental overiding non-virtual base methods for C++ +#ADD_DEFINITIONS("-Wnon-virtual-dtor") # Warn about non-virtual destructor for C++ +#ADD_DEFINITIONS("-Wctor-dtor-privacy") # Warn about useless and non-constructible classes for C++ +ADD_DEFINITIONS("-Wlong-long") # Do not allow using long long +#ADD_DEFINITIONS("-Wunreachable-code") # Warn about unreachable code +ADD_DEFINITIONS("-Wfloat-equal") # Do not accept comparing floating points with equal operator +ADD_DEFINITIONS("-Wabi") # Warn about possible ABI problems +ADD_DEFINITIONS("-Wswitch-enum") # Check switch enumeration +ADD_DEFINITIONS("-Wformat=2") # Check printf formatting +ADD_DEFINITIONS("-Wundef") # Warn if an undefined identifier is evaluated in an @if directive. +ADD_DEFINITIONS("-Wshadow") # Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed +ADD_DEFINITIONS("-Wconversion") # Warn for implicit conversions that may alter a value +ADD_DEFINITIONS("-Wlogical-op") # Warn about suspicious uses of logical operators in expressions +#ADD_DEFINITIONS("-Waggregate-return") # Warn if any functions that return structures or unions are defined or called. +ADD_DEFINITIONS("-Wmissing-field-initializers") # Warn if a structure's initializer has some fields missing. +ADD_DEFINITIONS("-Wredundant-decls") # Warn if anything is declared more than once in the same scope, even in cases where multiple declaration is valid and changes nothing. +#ADD_DEFINITIONS("-Wmissing-include-dirs") # Warn if a user-supplied include directory does not exist. +ADD_DEFINITIONS("-Wswitch-default") # Warn whenever a switch statement does not have a default case. +ADD_DEFINITIONS("-Wsync-nand") # Warn when __sync_fetch_and_nand and __sync_nand_and_fetch built-in functions are used. These functions changed semantics in GCC 4.4. +ADD_DEFINITIONS("-Wunused") # All the above -Wunused options combined. +ADD_DEFINITIONS("-Wstrict-overflow=5") # Also warn about cases where the compiler reduces the magnitude of a constant involved in a comparison. +#ADD_DEFINITIONS("-Wunsafe-loop-optimizations") # Warn if the loop cannot be optimized because the compiler could not assume anything on the bounds of the loop indices. With -funsafe-loop-optimizations warn if the compiler made such assumptions. +#ADD_DEFINITIONS("-Wmissing-format-attribute") # Warn about function pointers which might be candidates for format attributes. +#ADD_DEFINITIONS("-Wpadded") # Warn if padding is included in a structure, either to align an element of the structure or to align the whole structure. +#ADD_DEFINITIONS("-Winline") # Warn if a function can not be inlined and it was declared as inline. +ADD_DEFINITIONS("-Wdisabled-optimization") # Warn if a requested optimization pass is disabled. + + + +add_executable(test-vconf-headers test-vconf-headers.c) + diff --git a/include/SLP_vconf_PG.h b/include/SLP_vconf_PG.h new file mode 100755 index 0000000..6b2ca80 --- /dev/null +++ b/include/SLP_vconf_PG.h @@ -0,0 +1,194 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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. + * + */ + +/** + * @ingroup SLP_PG + * @defgroup VCONF_PG VConf + * @{ + + <h1 class="pg">Introduction</h1> + VConf is a virtual configuration system which provides three kinds of backend and notification. Internally, VConf uses a modified Elektra 0.7 and inotify of kernel. + + @image html SLP_Vconf_PG_image01.png + + <h2 class="pg">Properties</h2> +- Convenient API (read/write common data type : integer, double, boolean, string) +- Guarantee Transaction(db backend) +- Apply Key-List concept +- Changeable Backend (db, file, memory) +- Simple Notification based Inotify +- Header File : vconf.h + +<h1 class="pg">Programming Guide</h1> + +<h2 class="pg">Backends</h1> +VConf has 3 kinds of backend. + +<h3 class="pg">1. db backend</h1> +We can use this backend by specifying the "db" prefix. <br> +E.g. db/test_app/key1 <br> +A key starting with ¡°db¡± is saved at a location which is mounted by libsqlfs. Therefore the key has characteristics of a database.(robustness, atomicity). But it is slower than the other backends. <br> +Developers can use this backend in order to synchronize immediately. <br> + +@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 + +<h3 class="pg">2. memory backend</h1> +We can use this backend by specifying the "memory" prefix. <br> +E.g. memory/test_app/key1 <br> +A key starting with ¡°memory¡± is saved at a location which is mounted by tmpfs. Therefore the key has characteristics of memory. It has the highest speed. But if the target is turned off, the key is removed (volatile). <br> +Developers can use this backend for keys such as the power state of phone. <br> + +@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 + +<h3 class="pg">3. File backend</h1> +We can use this backend by specifying the "file" prefix. <br> +E.g. file/test_app/key1 <br> +A key starting with ¡°file¡± is saved at a location which is mounted by basic file system. Therefore the key has characteristics of file. If the target is turned off without synchronising, the key can lose data. <br> +Developers can use this backend for keys such as the sync state of something, where it is not vitally important for the key to hold the correct data. <br> + +@code +#include <stdio.h> +#include <vconf.h> + +const char *key1_name="file/test/key1"; + +int main(int argc, char **argv) +{ + double key1_value; + + if(vconf_set_dbl(key1_name, 1.23)) + fprintf(stderr, "vconf_set_dbl FAIL\n"); + else { + printf("vconf_set_dbl OK\n"); + vconf_sync_key(key1_name); + } + + if(vconf_get_dbl(key1_name, &key1_value)) + fprintf(stderr, "vconf_get_dbl FAIL\n"); + else + printf("vconf_get_dbl OK(key1 value is %f)\n", key1_value); + + return 0; +} +@endcode + +<h2 class="pg">Notification</h1> +The notification of a changed key is handled in the g_main_loop of the default context. If you want to receive a notification, you should use g_main_loop of the default context. <br> +For g_main_loop, refer to glib manual. <br> + +@code +#include <stdio.h> +#include <vconf.h> +#include <glib-object.h> +#include <glib.h> + +const char *key1_name="file/test/key1"; + +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() +{ + GMainLoop *event_loop; + + vconf_notify_key_changed(key1_name, test_cb, NULL); + + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + + vconf_ignore_key_changed(key1_name, test_cb); + + return 0; +} +@endcode +*/ + +/** +@} +*/ diff --git a/include/test-vconf-headers.c b/include/test-vconf-headers.c new file mode 100644 index 0000000..e73983f --- /dev/null +++ b/include/test-vconf-headers.c @@ -0,0 +1,31 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 "vconf-internals.h" +#include "vconf-log.h" +*/ +#include "vconf.h" +#include "vconf-keys.h" +int main(void) +{ + return 0; +} diff --git a/include/vconf-internals.h b/include/vconf-internals.h new file mode 100755 index 0000000..24edfb1 --- /dev/null +++ b/include/vconf-internals.h @@ -0,0 +1,182 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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. + * + */ + +/* + * Internals of libslp-setting + * + * @file setting-internals.h + * @author Sangjung Woo (sangjung.woo@samsung.com) + * @version 0.2 + * @brief This file is the header file of internal functions. + */ + +#ifndef __VCONF_GCONF_H__ +#define __VCONF_GCONF_H__ + +#include "vconf-log.h" +#include "vconf.h" + +#define BACKEND_DB_PREFIX "db/" +#define BACKEND_FILE_PREFIX "file/" +#define BACKEND_MEMORY_PREFIX "memory/" + +#define BACKEND_SYSTEM_DIR "/opt/var/kdb/" +#define BACKEND_MEMORY_DIR "/var/run/" + +#define BUF_LEN (1024) +#define KEY_PATH (128) +#define ERR_LEN (128) + +enum { + VCONF_BACKEND_NULL = 0, + VCONF_BACKEND_DB, + VCONF_BACKEND_FILE, + VCONF_BACKEND_MEMORY +}; + +#if 0 +enum { + VCONF_TYPE_NONE = 0, + VCONF_TYPE_STRING = 40, /*KEY_TYPE_STRING of KDB is 40 */ + VCONF_TYPE_INT = 41, + VCONF_TYPE_DOUBLE = 42, + VCONF_TYPE_BOOL = 43, + VCONF_TYPE_DIR +}; + +typedef int get_option_t; +enum { + VCONF_GET_KEY = 0, + VCONF_GET_ALL, + VCONF_GET_DIR, +}; + +/*This is a callback function pointer signature for value return*/ +typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data); + +#endif + + + +#define VCONF_OK 0 +#define VCONF_ERROR -1 + +enum { + VCONF_ERROR_WRONG_PREFIX = 1, + VCONF_ERROR_WRONG_TYPE, + VCONF_ERROR_WRONG_VALUE, + VCONF_ERROR_NO_MEM, + VCONF_ERROR_FILE_OPEN = 11, + VCONF_ERROR_FILE_FREAD, + VCONF_ERROR_FILE_FGETS, + VCONF_ERROR_FILE_WRITE, + VCONF_ERROR_FILE_SYNC, + VCONF_ERROR_FILE_CLOSE, + VCONF_ERROR_FILE_ACCESS, + VCONF_ERROR_FILE_CHMOD, + VCONF_ERROR_FILE_LOCK +}; + +#define return_err(err) return 0-err; + +/* Error codes retunred by the configuration manager */ +#if 0 +typedef enum { + /*Unknown Error */ + VCONF_ERROR_UNKNOWN = -1, + VCONF_ERROR_SUCCESS = 0, + /* Something didn't work, don't know why, probably unrecoverable + so there's no point having a more specific errno */ + VCONF_ERROR_FAILED = 1, + /* Server can't be launched/contacted */ + VCONF_ERROR_NO_SERVER = 2, + /* don't have permission for that */ + VCONF_ERROR_NO_PERMISSION = 3, + /* Address couldn't be resolved */ + VCONF_ERROR_BAD_ADDRESS = 4, + /* directory or key isn't valid + (contains bad characters, or malformed slash arrangement) */ + VCONF_ERROR_BAD_KEY = 5, + /* Syntax error when parsing */ + VCONF_ERROR_PARSE_ERROR = 6, + /* Fatal error parsing/loading information inside the backend */ + VCONF_ERROR_CORRUPT = 7, + /* Type requested doesn't match type found */ + VCONF_ERROR_TYPE_MISMATCH = 8, + /* Requested key operation on a dir */ + VCONF_ERROR_IS_DIR = 9, + /* Requested dir operation on a key */ + VCONF_ERROR_IS_KEY = 10, + /* Read-only source at front of path has set the value */ + VCONF_ERROR_OVERRIDDEN = 11, + /* liboaf error */ + VCONF_ERROR_OAF_ERROR = 12, + /* Tried to use remote operations on a local engine */ + VCONF_ERROR_LOCAL_ENGINE = 13, + /* Failed to get a lockfile */ + VCONF_ERROR_LOCK_FAILED = 14, + /* nowhere to write a value */ + VCONF_ERROR_NO_WRITABLE_DATABASE = 15, + /* server is shutting down */ + VCONF_ERROR_IN_SHUTDOWN = 16, + /* no key */ + VCONF_NO_KEY = 17, + /* connection failure */ + VCONF_CONF_CONNECTION_FAIL = 18, + /* invalid parameter */ + VCONF_CONF_INVALID_PARAMETER = 19, + /* unable to get kdb key new */ + VCONF_CONF_ERROR_GET_KDB_KEY_NEW = 20, + /* kdb open failure */ + VCONF_CONF_ERROR_KDB_OPEN = 21, + /* unable to set kdb key val */ + VCONF_CONF_ERROR_KDB_KEY_SET = 22, + /* unable to get kdb key val */ + VCONF_CONF_ERROR_KDB_KEY_GET = 23, + /* unable to register callback notification */ + VCONF_ERROR_NOTI_ADD_FILE_CB = 24, + /* kdb remove failure */ + VCONF_CONF_ERROR_KDB_REMOVE = 25, + /* unable to remove callback function registered */ + VCONF_ERROR_NOTI_DEL_FILE_CB = 26, + /*Supplied keylist is empty/Non existing */ + VCONF_ERROR_NO_KEYLIST = 27, + /*This functionality is not supported */ + VCONF_ERROR_NOT_SUPPORTED = 28, + /*Callback could not be called/Failed */ + VCONF_ERROR_CALLBACK_FAILED = 29 +} SLP_Setting_Error; +#endif + +int _vconf_kdb_add_notify + (const char *keyname, vconf_callback_fn cb, void *data); +int _vconf_kdb_del_notify + (const char *keyname, vconf_callback_fn cb); + +int _vconf_get_key_path(const char *keyname, char *path); +int _vconf_get_key(keynode_t *keynode); + +int _vconf_keynode_set_keyname(keynode_t *keynode, const char *keyname); +inline void _vconf_keynode_set_null(keynode_t *keynode); +inline keynode_t *_vconf_keynode_new(void); +inline void _vconf_keynode_free(keynode_t *keynode); + +#endif diff --git a/include/vconf-keys.h b/include/vconf-keys.h new file mode 100755 index 0000000..8df0778 --- /dev/null +++ b/include/vconf-keys.h @@ -0,0 +1,319 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __VCONF_KEYS_H__ +#define __VCONF_KEYS_H__ + +#include "vconf-internal-keys.h" + +/** + * This file defines keys and values. + * + * @file vconf-keys.h + * @defgroup vconf_key Definitions of shared Keys + * @ingroup VCONF + * @author Hyungdeuk Kim (hd3.kim@samsung.com) + * @version 0.3 + * @brief This file has the definitions of shared keys. + * + * add keys(key name) and values(enum) here for shared keys.... + * + */ + +/* ========================== System Manager Notification ============================= */ +/** + * @defgroup vconf_key_SystemManager System Manager Keys + * @ingroup vconf_key + * @addtogroup vconf_key_SystemManager + * @{ + * @brief Maintainer: giyeol.ok@samsung.com + */ + +/** + * @brief usbhost status + * + * 0 : Remove \n + * 1 : Add \n + * 2 : Over current \n + */ +#define VCONFKEY_SYSMAN_USB_HOST_STATUS "memory/sysman/usbhost_status" +enum { + VCONFKEY_SYSMAN_USB_HOST_DISCONNECTED = 0, + VCONFKEY_SYSMAN_USB_HOST_CONNECTED, + VCONFKEY_SYSMAN_USB_HOST_OVERCURRENT +}; + +/** + * @brief mmc status + * + * 0 : Remove \n + * 1 : mount \n + * 2 : insert(not mount) \n + */ +#define VCONFKEY_SYSMAN_MMC_STATUS "memory/sysman/mmc" +enum { + VCONFKEY_SYSMAN_MMC_REMOVED = 0, + VCONFKEY_SYSMAN_MMC_MOUNTED, + VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED +}; + +/** + * @brief earkey status + * + * 0 : not press \n + * 1 : press \n + */ +#define VCONFKEY_SYSMAN_EARJACKKEY "memory/sysman/earjack_key" + +/** + * @brief cradle status + * + * 0 : Remove \n + * 1 : Add \n + */ +#define VCONFKEY_SYSMAN_CRADLE_STATUS "memory/sysman/cradle_status" + +/** + * @} + */ + + +/* =============================== Wifi ====================================== */ +/** + * @defgroup vconf_key_Wifi Wifi Keys + * @ingroup vconf_key + * @addtogroup vconf_key_Wifi + * @{ + * @brief Maintainer : dwmax.lee@samsung.com + */ + +/** + * @Wi-Fi Direct state + * + * 0: Power off \n + * 1: Power on \n + * 2: Discoverable mode \n + * 3: Connected with peer as GC \n + * 4: Connected with peer as GO + */ +#define VCONFKEY_WIFI_DIRECT_STATE "memory/wifi_direct/state" +enum { + /** Power off */ + VCONFKEY_WIFI_DIRECT_DEACTIVATED = 0, + /** Power on */ + VCONFKEY_WIFI_DIRECT_ACTIVATED, + /** Discoverable mode */ + VCONFKEY_WIFI_DIRECT_DISCOVERING, + /** Connected with peer as GC */ + VCONFKEY_WIFI_DIRECT_CONNECTED, + /** Connected with peer as GO */ + VCONFKEY_WIFI_DIRECT_GROUP_OWNER +}; + +/** + * @} + */ + + + +/* ================================= BT =====================================*/ +/** + * @defgroup vconf_key_BT BT Keys + * @ingroup vconf_key + * @addtogroup vconf_key_BT + * @{ + * @brief Maintainer : chanyeol.park@samsung.com + */ + +/** \ + * @brief Bluetooth status + * + * 0x0000 : Bluetooth OFF \n + * 0x0001 : Bluetooth ON \n + * 0x0002 : Discoverable mode \n + * 0x0004 : In transfering \n +*/ +#define VCONFKEY_BT_STATUS "db/bluetooth/status" +enum { + /** Bluetooth OFF */ + VCONFKEY_BT_STATUS_OFF = 0x0000, + /** Bluetooth ON */ + VCONFKEY_BT_STATUS_ON = 0x0001, + /** Discoverable mode */ + VCONFKEY_BT_STATUS_BT_VISIBLE = 0x0002, + /** In transfering */ + VCONFKEY_BT_STATUS_TRANSFER = 0x0004 +}; + +/** + * @brief Bluetooth Connected status + * + * 0x0000 : Not connected \n + * 0x0004 : Headset connected \n + * 0x0010 : A2DP headset connected \n + * 0x0020 : SAP connected \n + * 0x0040 : PBAP connected \n +*/ +#define VCONFKEY_BT_DEVICE "memory/bluetooth/device" +enum { + /** Not connected */ + VCONFKEY_BT_DEVICE_NONE = 0x0000, + /** Headset connected */ + VCONFKEY_BT_DEVICE_HEADSET_CONNECTED = 0x0004, + /** A2DP headset connected */ + VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED = 0x0010, + /** SAP connected */ + VCONFKEY_BT_DEVICE_SAP_CONNECTED = 0x0020, + /** PBAP connected */ + VCONFKEY_BT_DEVICE_PBAP_CONNECTED = 0x0040 +}; + +/* Media sound path for BT */ +enum { + /** Media Player Select Speaker */ + VCONFKEY_BT_PLAYER_SELECT_SPEAKER = 0x00, + /** Media Player Select Bluetooth */ + VCONFKEY_BT_PLAYER_SELECT_BLUETOOTH = 0x01, + /** BT application Select Speaker */ + VCONFKEY_BT_APP_SELECT_SPEAKER = 0x02, + /** BT application Select Bluetooth */ + VCONFKEY_BT_APP_SELECT_BLUETOOTH = 0x04 +}; + +/** + * @} + */ + +/* =========================== IDLE lock =======================================*/ +/** + * @defgroup vconf_key_idleLock idleLock Keys + * @ingroup vconf_key + * @addtogroup vconf_key_idleLock + * @{ + * @brief Maintainer : seungtaek.chung@samsung.com, wonil22.choi@samsung.com hyoyoung.chang@samsung.com angelkim@samsung.com + */ + +/** + * @brief lock screen status + * + * VCONFKEY_IDLE_UNLOCK : unlocked state \n + * VCONFKEY_IDLE_LOCK : locked state \n + */ +#define VCONFKEY_IDLE_LOCK_STATE "memory/idle_lock/state" +enum { + /** unlocked state */ + VCONFKEY_IDLE_UNLOCK = 0x00, + /** locked state */ + VCONFKEY_IDLE_LOCK +}; + +/** + * @brief wallpaper of lock screen + * + * Value : Wallpaper file path in the lock screen \n + */ +#define VCONFKEY_IDLE_LOCK_BGSET "db/idle_lock/bgset" + +/** + * @} + */ + + + +/* =========================== pwlock =======================================*/ +/** + * @defgroup vconf_key_pwlock Lock application for password verification: phone, pin, sum, network, etc. + * @ingroup vconf_key + * @addtogroup vconf_key_pwlock + * @{ + * @brief Maintainer : seungtaek.chung@samsung.com miju52.lee@samsung.com + * Used module : pwlock + * + */ + +/** + * @brief mobex engine status + * + * VCONFKEY_PWLOCK_BOOTING_UNLOCK : unlocked state in boointg time \n + * VCONFKEY_PWLOCK_BOOTING_LOCK : locked state in boointg time \n + * VCONFKEY_PWLOCK_RUNNING_UNLOCK : unlocked state in running time \n + * VCONFKEY_PWLOCK_RUNNING_LOCK : locked state in running time \n + */ +#define VCONFKEY_PWLOCK_STATE "memory/pwlock/state" +enum { + /** unlocked state in boointg time */ + VCONFKEY_PWLOCK_BOOTING_UNLOCK = 0x00, + /** locked state in boointg time */ + VCONFKEY_PWLOCK_BOOTING_LOCK, + /** unlocked state in running time */ + VCONFKEY_PWLOCK_RUNNING_UNLOCK, + /** locked state in running time */ + VCONFKEY_PWLOCK_RUNNING_LOCK +}; +/** + * @} + */ + + + +/* =========================== browser =======================================*/ +/** + * @defgroup vconf_key_browser browser public keys + * @ingroup vconf_key + * @addtogroup vconf_key_browser + * @{ + * @brief Maintainer : sangpyo7.kim@samsung.com ibchang@samsung.com + * + */ + +/** + * @brief browser user agent string + * + * Value : The user agent string currently being used by embeded browser \n + */ +#define VCONFKEY_BROWSER_USER_AGENT "db/browser/user_agent" + +/** + * @brief browser user agent profile + * + * Value : The user agent string profile currently being used by embeded browser for 2G network \n + */ +#define VCONFKEY_BROWSER_USER_AGENT_PROFILE_2G "db/browser/user_agent_profile_2G" + +/** + * @brief browser user agent profile + * + * Value : The user agent string profile currently being used by embeded browser for 3G network \n + */ +#define VCONFKEY_BROWSER_USER_AGENT_PROFILE_3G "db/browser/user_agent_profile_3G" + +/** + * @brief browser user agent profile + * + * Value : The user agent string profile currently being used by embeded browser for 4G network \n + */ +#define VCONFKEY_BROWSER_USER_AGENT_PROFILE_4G "db/browser/user_agent_profile_4G" + +/** + * @} + */ +#endif /* __VCONF_KEYS_H__ */ + diff --git a/include/vconf-log.h b/include/vconf-log.h new file mode 100755 index 0000000..9b28dc2 --- /dev/null +++ b/include/vconf-log.h @@ -0,0 +1,125 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __VCONF_LOG_H__ +#define __VCONF_LOG_H__ + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> + +#define VCONF_DLOG_OUT + +/************** Error ***************/ +#ifdef VCONF_SYSLOG_OUT + #include <syslog.h> + + #define INFO(fmt, arg...) \ + do { \ + syslog(LOG_INFO, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) + #define ERR(fmt, arg...) \ + do { \ + syslog(LOG_ERR, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) + #define WARN(fmt, arg...) \ + do { \ + syslog(LOG_ERR, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) + +#elif defined(VCONF_DLOG_OUT) + #define LOG_TAG "VCONF" + #include <dlog.h> + + #define INFO(fmt, arg...) SLOGI(fmt, ##arg) + #define ERR(fmt, arg...) SLOGE(fmt, ##arg) + #define WARN(fmt, arg...) SLOGW(fmt, ##arg + +#else + #include <stdlib.h> + + #define INFO(fmt, arg...) \ + do { \ + fprintf(stdout,"[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) + #define WARN(fmt, arg...) \ + do { \ + fprintf(stderr,"[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) + #define ERR(fmt, arg...) \ + do { \ + fprintf(stderr,"[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + }while(0) +#endif + + +/************** Return ***************/ +#define ret_if(expr) \ + do { \ + if (expr) { \ + ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +#define retv_if(expr, val) \ + do { \ + if (expr) { \ + ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) +#define retm_if(expr, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return; \ + } \ + } while (0) +#define retvm_if(expr, val, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) +#define retex_if(expr, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + goto CATCH; \ + } \ + } while (0) + + +/************** TimeCheck ***************/ +#ifdef VCONF_TIMECHECK +#define START_TIME_CHECK \ + init_time();\ + startT = set_start_time(); +#define END_TIME_CHECK \ + VCONF_DEBUG("time = %f ms\n", exec_time(startT)); +#else +#define START_TIME_CHECK +#define END_TIME_CHECK +#endif + + +#endif /* __VCONF_LOG_H__ */ diff --git a/include/vconf.h b/include/vconf.h new file mode 100755 index 0000000..1460321 --- /dev/null +++ b/include/vconf.h @@ -0,0 +1,847 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __VCONF_H__ +#define __VCONF_H__ + +/** + * @addtogroup APPLICATION_FRAMEWORK + * @{ + * + * @defgroup VCONF VConf + * @author Sangjung Woo (sangjung.woo@samsung.com) + * @version 0.2 + * @brief A library for reading/writing Configuration Data + * + * @section Header To use Them: + * @code + * #include <vconf.h> + * @endcode + * + * @section Properties + * - Convenient API + * - Guarantee Transaction(db backend only) + * - Apply Key-List concept + * - Changeable Backend + * - Simple Notification based on inotify + * + * @section Backend key has below backend. + * - db => use libsqlfs ex) db/a/b + * \n Lowest speed, highest robustness, correctly sync + * - memory => use tmpfs ex) memory/a/b + * \n Highest speed, volitile + * - file => use basic file system(not support atomicity) ex) file/a/b + * \n Higher speed, lower robustness(Not guarantee atomicity) + * + * @section example Simple Example + * @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 + * + */ + +/** + * @addtogroup VCONF + * @{ + */ + +#include "vconf-keys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * VCONF_GET_KEY, VCONF_GET_ALL, VCONF_GET_DIR + * \n Use for vconf_get() + * @see vconf_get() + */ +enum get_option_t { + VCONF_GET_KEY = 0, + /**< get only keys */ + VCONF_GET_ALL, + /**< get keys and directorys */ + VCONF_GET_DIR + /**< get only directorys */ +}; +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 */ +}; + + +/** + * keynode_t is an opaque type, it must be + * used via accessor functions. + * @see vconf_keynode_get_name(), vconf_keynode_get_type() + * @see vconf_keynode_get_bool(), vconf_keynode_get_dbl(), vconf_keynode_get_int(), vconf_keynode_get_str() + */ +typedef struct _keynode_t { + char *keyname; + int type; + union { + int i; + int b; + double d; + char *s; + } value; + struct _keynode_t *next; +} keynode_t; + +/** + * keylist_t is an opaque type, it must be + * used via accessor functions. + * @see vconf_keylist_new(), vconf_keylist_free() + * @see vconf_keylist_add_bool(),vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_int() + * @see vconf_keylist_del(), vconf_keylist_add_null() + * @see vconf_keylist_lookup(), vconf_keylist_nextnode(), vconf_keylist_rewind() + */ +typedef struct _keylist_t { + int num; + keynode_t *head; + keynode_t *cursor; +} keylist_t; + + +/** + * This is the signature of a callback function added with vconf_notify_key_changed(). + * \n The callback function is invoked when the key is set. + * @see keynode_t + */ + typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data); + +/************************************************ + * keynode handling APIs * + ************************************************/ + +/** + * This function gets Key name of the keynode. + * @param[in] keynode The Key + * @return Key Name of the keynode + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t + */ + char *vconf_keynode_get_name(keynode_t *keynode); + +/** + * This function gets value type of the keynode. + * @param[in] keynode The Key + * @return Type of the keynode + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t + */ + int vconf_keynode_get_type(keynode_t *keynode); + +/** + * This function gets Integer value of the keynode. + * @param[in] keynode The Key + * @return Integer value, or 0 if no value is obtained + ** @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_dbl, keynode_t, vconf_t + */ + int vconf_keynode_get_int(keynode_t *keynode); + +/** + * This function gets Double value of the keynode. + * @param[in] keynode The Key + * @return Double value, or 0.0 if no value is obtained + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, keynode_t, vconf_t + */ + double vconf_keynode_get_dbl(keynode_t *keynode); + +/** + * This function gets Boolean value of the keynode. + * @param[in] keynode The Key + * @return Boolean value, -1 on error (Integer value 1 is 'True', and 0 is 'False') + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_type, vconf_keynode_get_str, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t + */ + int vconf_keynode_get_bool(keynode_t *keynode); + +/** + * This function gets String value of the keynode. + * @param[in] keynode The Key + * @return String value, or NULL if no value is obtained + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed(), vconf_keynode_get_name, vconf_keynode_get_bool, vconf_keynode_get_type, vconf_keynode_get_int, vconf_keynode_get_dbl, keynode_t, vconf_t + */ + char *vconf_keynode_get_str(keynode_t *keynode); + + +/************************************************ + * keylist handling APIs + ************************************************/ + +/** + * Allocate, initialize and return a new Keylist object. + * Return value keylist_t* pointer must be relised by calling vconf_keylist_free() + * @return The pointer of New keylist, NULL on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_new(), vconf_keylist_free() + */ + keylist_t *vconf_keylist_new(void); + +/** + * This function moves the current Keynode position to the first items. + * @param[in] keylist Key List + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_nextnode(), vconf_keylist_rewind(), vconf_keylist_nextnode() + * @par example + * @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 + */ + int vconf_keylist_rewind(keylist_t *keylist); + +/** + * A destructor for Keylist objects.<br> + * After calling vconf_keylist_new(), developer have to call this function for release internal memory. + * @param[in] keylist Key List + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_new() + */ + int vconf_keylist_free(keylist_t *keylist); + +/** + * This function looks for a Keynode contained in keylist that matches keyname. + * @param[in] keylist Key List + * @param[in] keyname Key to find + * @param[out] return_node pointer of keynode to set + * @return Type of the found key that is vconf_t enumeration value + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), keynode_t, vconf_t + * @par example + * @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; + } + + 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 + */ + int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, + keynode_t **return_node); + +/** + * This function returns the next Key in a Keylist. + * Next key is known by the keylist internal cursor. + * @param[in] keylist Key List + * @return The next Keynode, NULL on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_rewind(), vconf_keylist_nextnode(), keynode_t + */ + keynode_t *vconf_keylist_nextnode(keylist_t *keylist); + +/** + * This function appends a new Keynode included integer value to the keylist. + * \n If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The integer value + * @return Number of keynode included in the keylist, -1 on error + * @see vconf_set(), vconf_get() + */ + int vconf_keylist_add_int(keylist_t *keylist, const char *keyname, + const int value); + +/** + * This function appends a new Keynode included boolean value to the keylist. + * \n If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The boolean value + * @return Number of keynode included in the keylist, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + */ + int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, + const int value); + +/** + * This function appends a new Keynode included double value to the keylist. + * \n If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The double value + * @return Number of keynode included in the keylist, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + */ + int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname, + const double value); + +/** + * This function appends a new Keynode included string value to the keylist. + * \n If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The pointer of string value + * @return Number of keynode included in the keylist, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + */ + int vconf_keylist_add_str(keylist_t *keylist, const char *keyname, + const char *value); + +/** + * This function Appends a new Keynode to the keylist without value. + * \n Use for vconf_get() + * @param[in] keylist Key List + * @param[in] keyname Key + * @return Number of keynode included in the keylist, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + */ + int vconf_keylist_add_null(keylist_t *keylist, const char *keyname); + +/** + * This function removes the keynode that matches keyname. + * @param[in] keylist the keylist included the keyname + * @param[in] keyname key + * @return 0 on success, -1(Invalid parameter), -2(Not exist keyname in keylist) on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + */ + int vconf_keylist_del(keylist_t *keylist, const char *keyname); + +/************************************************ + * setting APIs * + ************************************************/ + +/** + * This function sets the keys included in keylist. + * \n If you use db backend, keylist is handled as one transaction. + * @param[in] keylist the keylist which should contain changed keys + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set(), vconf_get(), vconf_keylist_add_int(), vconf_keylist_add_str(), vconf_keylist_add_dbl(), vconf_keylist_add_bool(), vconf_keylist_del(), vconf_keylist_add_null() + * @par example + * @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 + */ + int vconf_set(keylist_t *keylist); + +/** + * This function sets the integer value of given key. + * @param[in] in_key key + * @param[in] intval integer value to set (0 is also allowed as a value.) + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_str() + */ + int vconf_set_int(const char *in_key, const int intval); + +/** + * This function sets the boolean value of given key. + * @param[in] in_key key + * @param[in] boolval boolean value(1 or 0) to set. (Integer value 1 is 'True', and 0 is 'False') + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set_int(), vconf_set_dbl(), vconf_set_str() + * @par example + * @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 + */ + int vconf_set_bool(const char *in_key, const int boolval); + +/** + * This function sets the double value of given key. + * @param[in] in_key key + * @param[in] dblval double value to set (0.0 is also allowed as a value.) + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set_int(), vconf_set_bool(), vconf_set_str() + */ + int vconf_set_dbl(const char *in_key, const double dblval); + +/** + * This function sets the string value of given key. + * @param[in] in_key key + * @param[in] strval string value to set + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_set_bool(), vconf_set_dbl(), vconf_set_int() + */ + int vconf_set_str(const char *in_key, const char *strval); + +/** + * This function get the keys or subdirectory in in_parentDIR.<br> + * If keylist has any key information, vconf only retrieves the keys.<br> + * This is not recursive. + * @param[in] keylist keylist created by vconf_keylist_new() + * @param[in] in_parentDIR parent DIRECTORY of needed keys + * @param[in] option VCONF_GET_KEY|VCONF_GET_DIR|VCONF_GET_ALL + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remkar None + * @par example + * @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 + */ + int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option); + +/** + * This function get the integer value of given key. + * + * @param[in] in_key key + * @param[out] intval output buffer + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remkar None + * @see vconf_get_bool, vconf_get_dbl, vconf_get_str + * @par example + * @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 + */ + int vconf_get_int(const char *in_key, int *intval); + +/** + * This function get the boolean value(1 or 0) of given key. + * @param[in] in_key key + * @param[out] boolval output buffer + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_get_int(), vconf_get_dbl(), vconf_get_str() + */ + int vconf_get_bool(const char *in_key, int *boolval); + +/** + * This function get the double value of given key. + * @param[in] in_key key + * @param[out] dblval output buffer + * @return 0 on success, -1 on error + * @pre None + * @post None + * @remarks None + * @see vconf_get_int(), vconf_get_bool(), vconf_get_str() + */ + int vconf_get_dbl(const char *in_key, double *dblval); + +/** + * This function gets the string value of given key. + * \n You have to free this returned value. + * @param[in] in_key key + * @return allocated pointer of key value on success, NULL on error + * @pre None + * @post None + * @remarks None + * @see vconf_get_int(), vconf_get_dbl(), vconf_get_bool() + * @par example + * @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 + */ + char *vconf_get_str(const char *in_key); + +/** + * This function deletes given key from backend system. + * @param[in] in_key key + * @return 0 on success, -1 on error + */ + int vconf_unset(const char *in_key); + +/** + * This function synchronizes the given key(only file backend) with storage device. + * @param[in] in_key key + * @return 0 on success, -1 on error + * @pre Nome + * @post None + * @remarks None + * @par example + * @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 + */ + int vconf_sync_key(const char *in_key); + +/** + * This function deletes all keys and directories below given Directory from backend system. + * @param[in] in_dir Directory name for removing + * @return 0 on success, -1 on error + * @pre Nome + * @post None + * @remarks None + * @par example + * @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 + */ + int vconf_unset_recursive(const char *in_dir); + +/** + * This function adds a change callback for given key, + * which is called when the key is set or unset. + * \n Information(#keynode_t) of the key that changed is delivered to #vconf_callback_fn, + * or if the key is deleted, the @link #keynode_t keynode @endlink has #VCONF_TYPE_NONE as type. + * \n Multiple vconf_callback_fn functions may exist for one key. + * \n The callback is issued in the context of the glib main loop. + * \n WARNING: This callback mechanism DOES NOT GUARANTEE consistency of data chage. For example, + * When you have a callback for a certain key, assume that two or more processes are trying to + * change the value of the key competitively. In this case, your callback function will always + * get 'CURRENT' value, not the value raised the notify that caused run of the callback. So, + * do not use vconf callback when competitive write for a key is happening. In such case, use + * socket-based IPC(dbus or something else) instead. + * + * @param[in] in_key key + * @param[in] cb callback function + * @param[in] user_data callback data + * @return 0 on success, -1 on error + * @pre Nome + * @post None + * @remarks None + * @see vconf_ignore_key_changed + * @par example + * @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 + */ + int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, + void *user_data); + +/** + * This function removes a change callback for given key, + * which was added by vconf_notify_key_changed(). + * @param[in] in_key key + * @param[in] cb callback function + * @return 0 on success, -1 on error + * @pre Nome + * @post None + * @remarks None + * @see vconf_notify_key_changed() + */ + int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb); + +#ifdef __cplusplus +} +#endif +/** + * @} @} + */ +#endif /* __VCONF_H__ */ diff --git a/kdb_first_boot b/kdb_first_boot new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/kdb_first_boot diff --git a/packaging/vconf-setup.conf b/packaging/vconf-setup.conf new file mode 100644 index 0000000..5031f46 --- /dev/null +++ b/packaging/vconf-setup.conf @@ -0,0 +1,3 @@ +# This file is a config for libslp-settings to be used as part of vconf-setup.service +# See tmpfiles.d(5) for details +d /var/run/memory 0777 root root - - diff --git a/packaging/vconf-setup.service b/packaging/vconf-setup.service new file mode 100644 index 0000000..2f158f7 --- /dev/null +++ b/packaging/vconf-setup.service @@ -0,0 +1,15 @@ + +[Unit] +Description=Initialize the VConf storage +DefaultDependencies=no +After=opt-var-kdb-db-libsqlfs.service +Requires=opt-var-kdb-db-libsqlfs.service +Before=basic.target + +[Service] +Type=oneshot +ExecStart=/bin/cp -pr /opt/var/kdb/memory_init/memory /var/run/ + +[Install] +WantedBy=basic.target + diff --git a/packaging/vconf.spec b/packaging/vconf.spec new file mode 100755 index 0000000..40df5a2 --- /dev/null +++ b/packaging/vconf.spec @@ -0,0 +1,115 @@ +Name: vconf +Summary: Configuration system library +Version: 0.2.32 +Release: 1 +Group: System/Libraries +License: Apache License, Version 2.0 +Source0: %{name}-%{version}.tar.gz +Source1: vconf-setup.service +Source2: vconf-setup.conf +Requires(post): /sbin/ldconfig, systemd +Requires(postun): /sbin/ldconfig, systemd +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf-internal-keys) + +%description +Configuration system library + +%package devel +Summary: vconf (devel) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: pkgconfig(glib-2.0) +Requires: vconf = %{version}-%{release} +Requires: vconf-keys-devel = %{version}-%{release} + +%description devel +Vconf library (devel) + +%package keys-devel +Summary: vconf (devel) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: vconf = %{version}-%{release} +Requires: vconf-internal-keys-devel + +%description keys-devel +Vconf key management header files + +%prep +%setup -q -n %{name}-%{version} + +%build +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +mkdir -p %{buildroot}/etc/rc.d/rc3.d +mkdir -p %{buildroot}/etc/rc.d/rc4.d +ln -sf /etc/rc.d/init.d/vconf-init %{buildroot}/etc/rc.d/rc3.d/S04vconf-init +ln -sf /etc/rc.d/init.d/vconf-init %{buildroot}/etc/rc.d/rc4.d/S04vconf-init +mkdir -p %{buildroot}/opt/var/kdb/db +mkdir -p %{buildroot}%{_libdir}/systemd/system/basic.target.wants +mkdir -p %{buildroot}%{_libdir}/tmpfiles.d +install -m0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/ +install -m0644 %SOURCE2 %{buildroot}%{_libdir}/tmpfiles.d/ +ln -sf ../vconf-setup.service %{buildroot}%{_libdir}/systemd/system/basic.target.wants/ +mkdir -p %{buildroot}/usr/share/license +install LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} + +%post +/sbin/ldconfig +systemctl daemon-reload + +%postun +/sbin/ldconfig +systemctl daemon-reload + +%files +%manifest vconf.manifest +%defattr(-,root,root,-) +%attr(755,root,root) %{_sysconfdir}/rc.d/init.d/vconf-init +%{_sysconfdir}/rc.d/rc3.d/S04vconf-init +%{_sysconfdir}/rc.d/rc4.d/S04vconf-init +%{_bindir}/vconftool +%config(missingok) %attr(644,root,root) /opt/var/kdb/kdb_first_boot +%{_libdir}/*.so.* +%dir %attr(777,root,root) /opt/var/kdb/db +%{_libdir}/systemd/system/basic.target.wants/vconf-setup.service +%{_libdir}/systemd/system/vconf-setup.service +%{_libdir}/tmpfiles.d/vconf-setup.conf +/usr/share/license/%{name} + +%files devel +%defattr(-,root,root,-) +%{_includedir}/vconf/vconf.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/*.so + +%files keys-devel +%defattr(-,root,root,-) +%{_includedir}/vconf/vconf-keys.h + +%changelog +* Tue Oct 23 2012 - SeungYeup Kim <sy2004.kim@samsung.com> +- Add thread safe code + +* Tue Sep 18 2012 - SeungYeup Kim <sy2004.kim@samsung.com> +- Add 4 public keys (Browser User Agent) + +* Tue Aug 28 2012 - SeungYeup Kim <sy2004.kim@samsung.com> +- Remove memory leak +- Remove use after free + +* Tue Aug 14 2012 - Hyungdeuk Kim <hd3.kim@samsung.com> +- Fix issues related prevent +- Fix warning msg at build time + +* Mon Jul 23 2012 - SeungYeup Kim <sy2004.kim@samsung.com> +- Enable -f option for force update diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..09c3378 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,23 @@ +CC = gcc + +REQUIRED_PKG = vconf ecore +CFLAGS = -g -Wall +LDFLAGS = +ifdef REQUIRED_PKG + CFLAGS += `pkg-config --cflags $(REQUIRED_PKG)` + LDFLAGS += `pkg-config --libs $(REQUIRED_PKG)` +endif + +SRCS = vconf_notitest.c vconf_timecheck.c vconf_unit_test.c +OBJECTS = $(SRCS:.c=.o) +TARGETS = $(OBJECTS:.o=) + + +all: $(TARGETS) + +% : %.o + $(CC) $(LDFLAGS) -o $@ $< + +clean: + rm -rf $(OBJECTS) $(TARGETS) + diff --git a/test/vconf_notitest.c b/test/vconf_notitest.c new file mode 100644 index 0000000..596935a --- /dev/null +++ b/test/vconf_notitest.c @@ -0,0 +1,120 @@ +/* + * vconf + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo ko <hakjoo.ko@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#include <stdio.h> +#include <vconf.h> +#include <Ecore.h> +#include <gconf/gconf-client.h> + +//#define CHECK_THREAD +//#define CHECK_AFTER_RUN + +GMainLoop *event_loop; + +void test_cb(keynode_t *key, void* data) +{ + printf("\x1b[105;37m[TEST]%s noti get\x1b[0m\n", vconf_keynode_get_name(key)); + 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; + } + //vconf_ignore_key_changed(vconf_keynode_get_name(key), test_cb); +// sleep(1); +// g_main_loop_quit(event_loop); + return; +} + + +#ifdef CHECK_THREAD +#include <pthread.h> + +void *test_thread1(void *arg) +{ + if(!vconf_notify_key_changed((char *)arg, test_cb, NULL)) + printf("%s added\n", (char *)arg); + return NULL; +} +#endif + +#ifdef CHECK_AFTER_RUN +gboolean timeout_handler(gpointer data) +{ + char *key = data; + if(!vconf_notify_key_changed(key, test_cb, NULL)) + printf("%s added\n", key); + return FALSE; +} +#endif + +int main(int argc, char **argv) +{ + int i; +// char temp[100]="/opt/var/kdb/"; + + g_type_init(); + ecore_init(); + + event_loop = g_main_loop_new(NULL, FALSE); + + for(i=1;i<argc;i++) { + if(argv[i]) { +#ifdef CHECK_AFTER_RUN + g_timeout_add_seconds(3, (GSourceFunc)timeout_handler, argv[i]); +#elif defined(CHECK_THREAD) + pthread_t test_thread; + + pthread_create(&test_thread, NULL, test_thread1, argv[i]); + pthread_detach(test_thread); +#else + vconf_notify_key_changed(argv[i], test_cb, NULL); +#endif + +// strcat(temp, argv[1]); +// open(temp, O_RDONLY); + } + } + +// g_main_loop_run(event_loop); + ecore_main_loop_begin(); + + return 0; +} diff --git a/test/vconf_timecheck.c b/test/vconf_timecheck.c new file mode 100644 index 0000000..20b12a7 --- /dev/null +++ b/test/vconf_timecheck.c @@ -0,0 +1,229 @@ +/* + * vconf + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo ko <hakjoo.ko@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#include <stdio.h> +#include <vconf.h> +#include <Ecore.h> +#include <gconf/gconf-client.h> + +const char *vconfkeys[5][4]={ + {"db/timetest/key1", "db/timetest/key2", "db/timetest/key3", "db/timetest/key4"}, + {"file/timetest/key1", "file/timetest/key2", "file/timetest/key3", "file/timetest/key4"}, + {"memory/timetest/key1", "memory/timetest/key2", "memory/timetest/key3", "memory/timetest/key4"}, + {"gconf_l/timetest/key1", "gconf_l/timetest/key2", "gconf_l/timetest/key3", "gconf_l/timetest/key4"}, + {"gconf_d/timetest/key1", "gconf_d/timetest/key2", "gconf_d/timetest/key3", "gconf_d/timetest/key4"} +}; + +void test_cb(void* data) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + printf("\x1b[105;37m[VConf]\x1b[0m %d.%6d\n",(int)tv.tv_sec, (int)tv.tv_usec); + printf("\x1b[105;37m[VConf](%s)noti get\x1b[0m\n", (char *)data); + + return; +} + +void test_cb2(keynode_t *key, void* data) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + printf("\x1b[105;37m[VConf]\x1b[0m %d.%6d\n",(int)tv.tv_sec, (int)tv.tv_usec); + printf("\x1b[105;37m[VConf]test_cb2 noti get\x1b[0m\n"); + + 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; + } +// vconf_del_changed_cb2(vconf_keynode_get_name(key), test_cb2); + return; +} + +void set_operation(int i) +{ + keylist_t *kl=NULL; + + vconf_set_int(vconfkeys[i][0], 1); + vconf_set_dbl(vconfkeys[i][1], 0.1); + vconf_set_bool(vconfkeys[i][2], 1); + vconf_set_str(vconfkeys[i][3], "this is time test"); + + kl = vconf_keylist_new(); + vconf_keylist_add_dbl(kl, vconfkeys[i][0], 0.2); + vconf_keylist_add_bool(kl, vconfkeys[i][1], 0); + vconf_keylist_add_str(kl, vconfkeys[i][2], "this is time test"); + vconf_keylist_add_int(kl, vconfkeys[i][3], 2); + vconf_set(kl); + vconf_keylist_free(kl); +} + + +void get_operation(int i, const char* parent_dir) +{ + keylist_t *kl=NULL; + keynode_t *temp_node; + int get_int; + double get_dbl; + char *get_str; + + vconf_get_dbl(vconfkeys[i][0], &get_dbl); + vconf_get_bool(vconfkeys[i][1], &get_int); + get_str=vconf_get_str(vconfkeys[i][2]); + free(get_str); + vconf_get_int(vconfkeys[i][3], &get_int); + + kl = vconf_keylist_new(); + vconf_get(kl, parent_dir, 0); + 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); +} + +void unset_operation(int i) +{ + vconf_unset(vconfkeys[i][0]); + vconf_unset(vconfkeys[i][1]); + vconf_unset(vconfkeys[i][2]); + vconf_unset(vconfkeys[i][3]); +} + + + +int main(int argc, char **argv) +{ + int operation; + + g_type_init(); + ecore_init(); + if(argc < 2) { + fprintf(stderr, "1:set(db), 2:set(file), 3:set(memory), 4:set(gconf_d), 5:set(gconf_l) \n"); + fprintf(stderr, "6:get(db), 7:get(file), 8:get(memory), 9:get(gconf_d), 10:get(gconf_l) \n"); + fprintf(stderr, "11:unset(db), 12:unset(file), 13:unset(memory), 14:unset(gconf_d), 15:unset(gconf_l) \n"); + return -1; + } + + operation = atoi(argv[1]); + switch(operation) + { + case 1: + set_operation(0); + break; + case 2: + set_operation(1); + break; + case 3: + set_operation(2); + break; + case 4: + set_operation(3); + break; + case 5: + set_operation(4); + break; + case 6: + get_operation(0, "db/timetest"); + break; + case 7: + get_operation(1, "file/timetest"); + break; + case 8: + get_operation(2, "memory/timetest"); + break; + case 9: + get_operation(3, "gconf_l/timetest"); + break; + case 10: + get_operation(4, "gconf_d/timetest"); + break; + case 11: + unset_operation(0); + break; + case 12: + unset_operation(1); + break; + case 13: + unset_operation(2); + break; + case 14: + unset_operation(3); + break; + case 15: + unset_operation(4); + break; + case 16: + vconf_notify_key_changed(vconfkeys[0][1], test_cb2, NULL); + vconf_notify_key_changed(vconfkeys[1][1], test_cb2, NULL); + vconf_notify_key_changed(vconfkeys[2][1], test_cb2, NULL); + vconf_notify_key_changed(vconfkeys[3][1], test_cb2, NULL); + vconf_notify_key_changed(vconfkeys[4][1], test_cb2, NULL); + + //ecore_main_loop_begin(); + GMainLoop *event_loop; + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + break; + } + + return 0; +} diff --git a/test/vconf_unit_test.c b/test/vconf_unit_test.c new file mode 100644 index 0000000..736c351 --- /dev/null +++ b/test/vconf_unit_test.c @@ -0,0 +1,283 @@ +/* + * vconf + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo ko <hakjoo.ko@samsung.com> + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <stdio.h> +#include <vconf.h> +#include <Ecore.h> +#include <gconf/gconf-client.h> +#include <dirent.h> + +const char *vconfkeys[5][5]={ + {"db", "db/unittest/key1", "db/unittest/key2", "db/unittest/key3", "db/unittest/key4"}, + {"file", "file/unittest/key1", "file/unittest/key2", "file/unittest/key3", "file/unittest/key4"}, + {"memory", "memory/unittest/key1", "memory/unittest/key2", "memory/unittest/key3", "memory/unittest/key4"}, + {"gconf_l", "gconf_l/unittest/key1", "gconf_l/unittest/key2", "gconf_l/unittest/key3", "gconf_l/unittest/key4"}, + {"gconf_d", "gconf_d/unittest/key1", "gconf_d/unittest/key2", "gconf_d/unittest/key3", "gconf_d/unittest/key4"} +}; + +#define EPRINT(FMT, ARG...) \ + fprintf(stderr, "\x1b[31m[VConf Unit Test]\x1b[0m" FMT "\n", ##ARG) + +#define PRINT(FMT, ARG...) \ + fprintf(stdout, "\x1b[33m[VConf Unit Test]\x1b[0m" FMT "\n", ##ARG) + +static GMainLoop *event_loop; + +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; + case VCONF_TYPE_NONE: + printf("key = %s, deleted\n", vconf_keynode_get_name(key)); + if(data == (void *)vconfkeys[4][0]) g_main_loop_quit(event_loop); + break; + default: + fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key)); + break; + } + + PRINT("%s Notification OK", (char *)data); + return; +} + +void set_operation(int i) +{ + keylist_t *kl=NULL; + + if(vconf_set_int(vconfkeys[i][1], 1)) + EPRINT("vconf_set_int FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_set_int OK(%s)", vconfkeys[i][0]); + + if(vconf_set_dbl(vconfkeys[i][2], 0.1)) + EPRINT("vconf_set_dbl FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_set_dbl OK(%s)", vconfkeys[i][0]); + + if(vconf_set_bool(vconfkeys[i][3], 1)) + EPRINT("vconf_set_bool FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_set_bool OK(%s)", vconfkeys[i][0]); + + if(vconf_set_str(vconfkeys[i][4], "This is UNIT test")) + EPRINT("vconf_set_str FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_set_str OK(%s)", vconfkeys[i][0]); + + kl = vconf_keylist_new(); + vconf_keylist_add_dbl(kl, vconfkeys[i][1], 0.2); + vconf_keylist_add_bool(kl, vconfkeys[i][2], 0); + vconf_keylist_add_str(kl, vconfkeys[i][3], "This is UNIT test"); + vconf_keylist_add_int(kl, vconfkeys[i][4], 2); + if(vconf_set(kl)) + EPRINT("vconf_set FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_set OK(%s)", vconfkeys[i][0]); + vconf_keylist_free(kl); + +} + + +void get_operation(int i, const char* parent_dir) +{ + keylist_t *kl=NULL; + keynode_t *temp_node; + int get_int; + double get_dbl; + char *get_str; + + if(vconf_get_dbl(vconfkeys[i][1], &get_dbl) || get_dbl != 0.2) + EPRINT("vconf_get_dbl FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_get_dbl OK(%s)", vconfkeys[i][0]); + + if(vconf_get_bool(vconfkeys[i][2], &get_int) || get_int != 0) + EPRINT("vconf_get_bool FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_get_bool OK(%s)", vconfkeys[i][0]); + + get_str=vconf_get_str(vconfkeys[i][3]); + if(get_str && !strcmp(get_str, "This is UNIT test")) + PRINT("vconf_get_str OK(%s)", vconfkeys[i][0]); + else + EPRINT("vconf_get_str FAIL(%s)", vconfkeys[i][0]); + if(get_str) free(get_str); + + if(vconf_get_int(vconfkeys[i][4], &get_int) || get_int != 2) + EPRINT("vconf_get_int FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_get_int OK(%s)", vconfkeys[i][0]); + + kl = vconf_keylist_new(); + if(vconf_get(kl, parent_dir, 0)) + EPRINT("vconf_get FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_get OK(%s)", vconfkeys[i][0]); + + 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); +} + +void unset_operation(int i) +{ + if(vconf_unset(vconfkeys[i][1])) + EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_unset OK(%s)", vconfkeys[i][0]); + if(vconf_unset(vconfkeys[i][2])) + EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_unset OK(%s)", vconfkeys[i][0]); + if(vconf_unset(vconfkeys[i][3])) + EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_unset OK(%s)", vconfkeys[i][0]); + if(vconf_unset(vconfkeys[i][4])) + EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]); + else + PRINT("vconf_unset OK(%s)", vconfkeys[i][0]); +} + +const char *test_dir[5]={ + "/opt/var/kdb/db/unittest", "/opt/var/kdb/file/unittest", "/var/run/memory/unittest", + "/opt/var/gconf/local/unittest", "/opt/var/gconf/unittest"}; + +void recursive_unset_operation(void) +{ + char parent[1024]; + int i,j; + for(i=0;i<5;i++) { + for(j=1;j<5;j++) + vconf_set_int(vconfkeys[i][j],1); + + sprintf(parent, "%s/unittest", vconfkeys[i][0]); + if(vconf_unset_recursive(parent)) + EPRINT("vconf_unset_recursive FAIL(%s)", parent); + else { + if(opendir(test_dir[i])) + EPRINT("vconf_unset_recursive FAIL(%s)", parent); + else + PRINT("vconf_unset_recursive OK(%s)", parent); + } + } +} + +void notify_operation(int i) +{ + int j; + for(j=1;j<5;j++) + { + if(vconf_notify_key_changed(vconfkeys[i][j], test_cb, (void *)vconfkeys[i][0])) { + if(3==i) + PRINT("vconf_notify_key_changed OK(%s)", vconfkeys[i][j]); + else + EPRINT("vconf_notify_key_changed FAIL(%s)", vconfkeys[i][j]); + }else { + if(3==i) + EPRINT("vconf_notify_key_changed FAIL(%s)", vconfkeys[i][j]); + else + PRINT("vconf_notify_key_changed OK(%s)", vconfkeys[i][j]); + } + } +} + +int main(int argc, char **argv) +{ + g_type_init(); + + set_operation(0); + set_operation(1); + set_operation(2); + set_operation(3); + set_operation(4); + get_operation(0, "db/unittest"); + get_operation(1, "file/unittest"); + get_operation(2, "memory/unittest"); + get_operation(3, "gconf_l/unittest"); + get_operation(4, "gconf_d/unittest"); + unset_operation(0); + unset_operation(1); + unset_operation(2); + unset_operation(3); + unset_operation(4); + recursive_unset_operation(); + notify_operation(0); + notify_operation(1); + notify_operation(2); + notify_operation(3); + notify_operation(4); + printf("For Notification TEST, You have to excute below command\n"); + printf("vconftool set -t int db/unittest/key1 1\n"); + printf("vconftool set -t int file/unittest/key2 1\n"); + printf("vconftool set -t int memory/unittest/key3 1\n"); + printf("vconftool set -t int gconf_d/unittest/key4 1\n"); + printf("vconftool unset db/unittest/key1\n"); + printf("vconftool unset file/unittest/key2\n"); + printf("vconftool unset memory/unittest/key3\n"); + printf("vconftool unset gconf_d/unittest/key4\n"); + + //ecore_main_loop_begin(); + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + + EPRINT("Did you get 8 Notifications\n"); + + return 0; +} diff --git a/vconf-init b/vconf-init new file mode 100755 index 0000000..f60adda --- /dev/null +++ b/vconf-init @@ -0,0 +1,9 @@ +#!/bin/sh + +mkdir /var/run/memory +chmod 777 /var/run/memory + +# Copy initialized memory backend key +cp /opt/var/kdb/memory_init/memory/* /var/run/memory -r -p + +touch /tmp/vconf-initialized
\ No newline at end of file diff --git a/vconf-kdb.c b/vconf-kdb.c new file mode 100755 index 0000000..a59c85a --- /dev/null +++ b/vconf-kdb.c @@ -0,0 +1,407 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <sys/types.h> +#include <sys/inotify.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <linux/version.h> +#include <stdlib.h> +#include <pthread.h> +#include <glib.h> +#include "vconf-internals.h" + +#include <glib.h> + +#define INOTY_EVENT_MASK (IN_CLOSE_WRITE | IN_DELETE_SELF) + +/* inotify */ +struct noti_node { + int wd; + char *keyname; + vconf_callback_fn cb; + void *cb_data; + struct noti_node *next; +}; +typedef struct noti_node noti_node_s; +static GList *g_notilist; + +static int _vconf_inoti_comp_with_wd(gconstpointer a, gconstpointer b) +{ + int r; + + noti_node_s *key1 = (noti_node_s *) a; + noti_node_s *key2 = (noti_node_s *) b; + + r = key1->wd - key2->wd; + return r; +} + +static int _vconf_inoti_comp_with_wd_cb(gconstpointer a, gconstpointer b) +{ + int r; + + noti_node_s *key1 = (noti_node_s *) a; + noti_node_s *key2 = (noti_node_s *) b; + + r = key1->wd - key2->wd; + if (r != 0) + return r; + + r = (int)(key1->cb - key2->cb); + return r; +} + +static int _kdb_inoti_fd; + +static pthread_mutex_t _kdb_inoti_fd_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t _kdb_g_ns_mutex = PTHREAD_MUTEX_INITIALIZER; + +static GSource *_kdb_handler; + +static GList* _vconf_copy_noti_list(GList *orig_notilist) +{ + GList *copy_notilist = NULL; + struct noti_node *n = NULL; + struct noti_node *t = NULL; + + if (!orig_notilist) + return NULL; + + orig_notilist = g_list_first(orig_notilist); + if (!orig_notilist) + return NULL; + + while(orig_notilist) { + t = orig_notilist->data; + + n = calloc(1, sizeof(noti_node_s)); + if (n == NULL) { + ERR("_vconf_copy_noti_list : calloc failed. memory full"); + break; + } + + n->wd = t->wd; + n->keyname = strndup(t->keyname, BUF_LEN); + n->cb_data = t->cb_data; + n->cb = t->cb; + + copy_notilist = g_list_append(copy_notilist, n); + orig_notilist = g_list_next(orig_notilist); + } + return copy_notilist; + +} + +static void _vconf_free_noti_node(gpointer data) +{ + struct noti_node *n = (struct noti_node*)data; + g_free(n->keyname); + g_free(n); +} + +static void _vconf_free_noti_list(GList *noti_list) +{ + g_list_free_full(noti_list, _vconf_free_noti_node); +} + + +static gboolean _vconf_kdb_gio_cb(GIOChannel *src, GIOCondition cond, gpointer data) +{ + int fd, r; + struct inotify_event ie; + GList *l_notilist = NULL; + + INFO("vconf noti function"); + + fd = g_io_channel_unix_get_fd(src); + r = read(fd, &ie, sizeof(ie)); + + while (r > 0) { + INFO("read event from GIOChannel. pid : %d", getpid()); + + pthread_mutex_lock(&_kdb_g_ns_mutex); + l_notilist = _vconf_copy_noti_list(g_notilist); + pthread_mutex_unlock(&_kdb_g_ns_mutex); + + + if (l_notilist) { + + struct noti_node *t = NULL; + GList *noti_list = NULL; + keynode_t* keynode = NULL; + + retvm_if(!(ie.mask & INOTY_EVENT_MASK), TRUE, + "Invalid argument: ie.mask(%d), ie.len(%d)", + ie.mask, ie.len); + + noti_list = g_list_first(l_notilist); + + while (noti_list) { + t = noti_list->data; + + keynode_t* keynode = _vconf_keynode_new(); + retvm_if(keynode == NULL, TRUE, "key malloc fail"); + + if( (t) && (t->wd == ie.wd) ) { + if ((ie.mask & IN_DELETE_SELF)) { + INFO("Notify that key(%s) is deleted", t->keyname); + _vconf_keynode_set_keyname(keynode, (const char *)t->keyname); + _vconf_keynode_set_null(keynode); + t->cb(keynode, t->cb_data); + _vconf_kdb_del_notify(t->keyname, t->cb); + } else { + _vconf_keynode_set_keyname(keynode, t->keyname); + _vconf_get_key(keynode); + t->cb(keynode, t->cb_data); + } + } + + _vconf_keynode_free(keynode); + + noti_list = g_list_next(noti_list); + } + + _vconf_free_noti_list(l_notilist); + } + + if (ie.len > 0) + (void) lseek(fd, ie.len, SEEK_CUR); + + r = read(fd, &ie, sizeof(ie)); + } + return TRUE; +} + +static int _vconf_kdb_noti_init(void) +{ + GIOChannel *gio; + int ret = 0; + + pthread_mutex_lock(&_kdb_inoti_fd_mutex); + + if (0 < _kdb_inoti_fd) { + ERR("Error: invalid _kdb_inoti_fd"); + pthread_mutex_unlock(&_kdb_inoti_fd_mutex); + return VCONF_ERROR; + } + _kdb_inoti_fd = inotify_init(); + if (_kdb_inoti_fd == -1) { + char err_buf[100] = { 0, }; + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("inotify init: %s", err_buf); + pthread_mutex_unlock(&_kdb_inoti_fd_mutex); + return VCONF_ERROR; + } + + ret = fcntl(_kdb_inoti_fd, F_SETFD, FD_CLOEXEC); + if (ret < 0) { + char err_buf[100] = { 0, }; + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("inotify init: %s", err_buf); + pthread_mutex_unlock(&_kdb_inoti_fd_mutex); + return VCONF_ERROR; + } + + ret = fcntl(_kdb_inoti_fd, F_SETFL, O_NONBLOCK); + if (ret < 0) { + char err_buf[100] = { 0, }; + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("inotify init: %s", err_buf); + pthread_mutex_unlock(&_kdb_inoti_fd_mutex); + return VCONF_ERROR; + } + + pthread_mutex_unlock(&_kdb_inoti_fd_mutex); + + gio = g_io_channel_unix_new(_kdb_inoti_fd); + retvm_if(gio == NULL, -1, "Error: create a new GIOChannel"); + + g_io_channel_set_flags(gio, G_IO_FLAG_NONBLOCK, NULL); + + _kdb_handler = g_io_create_watch(gio, G_IO_IN); + g_source_set_callback(_kdb_handler, (GSourceFunc) _vconf_kdb_gio_cb, NULL, NULL); + g_source_attach(_kdb_handler, NULL); + g_io_channel_unref(gio); + g_source_unref(_kdb_handler); + + return VCONF_OK; +} + + int +_vconf_kdb_add_notify(const char *keyname, vconf_callback_fn cb, void *data) +{ + char path[KEY_PATH]; + int wd, r; + struct noti_node t, *n; + char err_buf[ERR_LEN] = { 0, }; + int ret = 0; + GList *list = NULL; + int func_ret = VCONF_OK; + + retvm_if((keyname == NULL || cb == NULL), VCONF_ERROR, + "_vconf_kdb_add_notify : Invalid argument - keyname(%s) cb(%p)", + keyname, cb); + + if (_kdb_inoti_fd <= 0) + if (_vconf_kdb_noti_init()) + return VCONF_ERROR; + + ret = _vconf_get_key_path((char*)keyname, path); + retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid"); + + if (0 != access(path, F_OK)) { + if (errno == ENOENT) { + ERR("_vconf_kdb_add_notify : Key(%s) does not exist", keyname); + return VCONF_ERROR; + } + } + + wd = inotify_add_watch(_kdb_inoti_fd, path, INOTY_EVENT_MASK); + if (wd == -1) { + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("_vconf_kdb_add_notify : add noti(%s)", err_buf); + return VCONF_ERROR; + } + + t.wd = wd; + t.cb = cb; + + pthread_mutex_lock(&_kdb_g_ns_mutex); + + list = g_list_find_custom(g_notilist, &t, (GCompareFunc)_vconf_inoti_comp_with_wd_cb); + if (list) { + ERR("_vconf_kdb_add_notify : key(%s) has same callback(%p)", keyname, cb); + errno = EALREADY; + func_ret = VCONF_ERROR; + goto out_func; + } + + n = calloc(1, sizeof(noti_node_s)); + if (n == NULL) { + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("_vconf_kdb_add_notify : add noti(%s)", err_buf); + func_ret = VCONF_ERROR; + goto out_func; + } + + n->wd = wd; + n->keyname = strndup(keyname, BUF_LEN); + n->cb_data = data; + n->cb = cb; + + g_notilist = g_list_append(g_notilist, n); + if(!g_notilist) { + ERR("g_list_append fail"); + } + + INFO("cb(%p) is added for %s. tot cb cnt : %d\n", cb, n->keyname, g_list_length(g_notilist)); + +out_func: + pthread_mutex_unlock(&_kdb_g_ns_mutex); + + return func_ret; +} + + int +_vconf_kdb_del_notify(const char *keyname, vconf_callback_fn cb) +{ + int wd = 0; + int r = 0; + struct noti_node *n = NULL; + struct noti_node t; + char path[KEY_PATH] = { 0, }; + char err_buf[ERR_LEN] = { 0, }; + int del = 0; + int remain = 0; + int ret = 0; + int func_ret = VCONF_OK; + GList *noti_list; + + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname(%s)", keyname); + retvm_if(_kdb_inoti_fd == 0, VCONF_ERROR, "Invalid operation: not exist anything for inotify"); + + ret = _vconf_get_key_path((char*)keyname, path); + retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid"); + + /* get wd */ + wd = inotify_add_watch(_kdb_inoti_fd, path, INOTY_EVENT_MASK); + if (wd == -1) { + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("Error: inotify_add_watch() [%s]: %s", path, err_buf); + return VCONF_ERROR; + } + + pthread_mutex_lock(&_kdb_g_ns_mutex); + + t.wd = wd; + t.cb = cb; + + noti_list = g_list_find_custom(g_notilist, &t, (GCompareFunc)_vconf_inoti_comp_with_wd_cb); + if(noti_list) { + del++; + + n = noti_list->data; + g_notilist = g_list_remove(g_notilist, n); + g_free(n->keyname); + g_free(n); + + INFO("key(%s) cb is removed. remained noti list total length(%d)", + keyname, g_list_length(g_notilist)); + } + + noti_list = NULL; + noti_list = g_list_find_custom(g_notilist, &t, (GCompareFunc)_vconf_inoti_comp_with_wd); + if(noti_list == NULL) { + INFO("all noti for keyname(%s)/wd(%d) is removed", keyname, wd); + + r = inotify_rm_watch(_kdb_inoti_fd, wd); + if(r == -1) { + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("Error: inotify_rm_watch [%s]: %s", keyname, err_buf); + func_ret = VCONF_ERROR; + } + } + + if(g_list_length(g_notilist) == 0) { + close(_kdb_inoti_fd); + _kdb_inoti_fd = 0; + + g_source_destroy(_kdb_handler); + _kdb_handler = NULL; + + g_list_free(g_notilist); + g_notilist = NULL; + + INFO("all noti list is freed"); + } + + pthread_mutex_unlock(&_kdb_g_ns_mutex); + + if(del == 0) { + ERR("Error: nothing deleted"); + errno = ENOENT; + func_ret = VCONF_ERROR; + } + + return func_ret; +} @@ -0,0 +1,2138 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <stdlib.h> +#include <limits.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include "vconf-internals.h" +#include <dirent.h> +#include <sys/stat.h> +#include <sys/xattr.h> +#include <ctype.h> + +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +#define VCONF_ERROR_RETRY_CNT 10 +#define VCONF_ERROR_RETRY_SLEEP_UTIME 5000 + +int IN_SBOX=0; + +#define VCONF_MOUNT_PATH "/opt/var/kdb/db" +#define VCONF_MOUNT_PATH_CHECK \ +do{\ + if(!IN_SBOX) \ + IN_SBOX = access("/opt/var/kdb/kdb_first_boot", F_OK) + 2; \ + if(2==IN_SBOX) return 0;\ +}while(0) + +__thread int is_transaction; + +#ifdef VCONF_TIMECHECK +double correction, startT; + +double set_start_time(void) +{ + struct timeval tv; + double curtime; + + gettimeofday(&tv, NULL); + curtime = tv.tv_sec * 1000 + (double)tv.tv_usec / 1000; + return curtime; +} + +double exec_time(double start) +{ + double end = set_start_time(); + return (end - start - correction); +} + +int init_time(void) +{ + double temp_t; + temp_t = set_start_time(); + correction = exec_time(temp_t); + + return 0; +} +#endif + +int _vconf_keynode_set_keyname(keynode_t *keynode, const char *keyname) +{ + if (keynode->keyname) free(keynode->keyname); + keynode->keyname = strndup(keyname, BUF_LEN); + retvm_if(keynode->keyname == NULL, VCONF_ERROR, "strndup Fails"); + return VCONF_OK; +} + +static inline void _vconf_keynode_set_dir(keynode_t *keynode) +{ + keynode->type = VCONF_TYPE_DIR; +} + +static inline void _vconf_keynode_set_value_int(keynode_t *keynode, const int value) +{ + keynode->type = VCONF_TYPE_INT; + keynode->value.i = value; +} + +static inline void _vconf_keynode_set_value_bool(keynode_t *keynode, const int value) +{ + keynode->type = VCONF_TYPE_BOOL; + keynode->value.b = !!value; +} + +static inline void _vconf_keynode_set_value_dbl(keynode_t *keynode, const double value) +{ + keynode->type = VCONF_TYPE_DOUBLE; + keynode->value.d = value; +} + +static inline void _vconf_keynode_set_value_str(keynode_t *keynode, const char *value) +{ + keynode->type = VCONF_TYPE_STRING; + keynode->value.s = strdup(value); +} + +inline void _vconf_keynode_set_null(keynode_t *keynode) +{ + keynode->type = VCONF_TYPE_NONE; + //keynode->value.d = NULL; +} + +static inline keynode_t *_vconf_keynode_next(keynode_t *keynode) +{ + return keynode->next; +} + +inline keynode_t *_vconf_keynode_new(void) +{ + keynode_t *keynode; + keynode = calloc(1, sizeof(keynode_t)); + + return keynode; +} + +inline void _vconf_keynode_free(keynode_t *keynode) +{ + if(keynode) { + if (keynode->keyname) + free(keynode->keyname); + if (keynode->type == VCONF_TYPE_STRING && keynode->value.s) + free(keynode->value.s); + free(keynode); + } +} + +static inline keynode_t *_vconf_keylist_headnode(keylist_t *keylist) +{ + return keylist->head; +} + +static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname, + keynode_t **before_keynode) +{ + keynode_t *found_node, *temp_node = NULL; + + found_node = _vconf_keylist_headnode(keylist); + + while (found_node) { + if(found_node->keyname == NULL) { + ERR("key node has null keyname"); + return NULL; + } + + if (!strncmp(keyname, found_node->keyname, strlen(keyname))) { + if (before_keynode) { + *before_keynode = temp_node; + } + return found_node; + } + + temp_node = found_node; + found_node = _vconf_keynode_next(found_node); + } + return NULL; +} + +/* + * This function get Key name of the keynode. + * @param[in] keynode The Key + * @return Key Name of the keynode + */ +API char *vconf_keynode_get_name(keynode_t *keynode) +{ + retvm_if(keynode == NULL, NULL, "Invalid argument: keynode is NULL"); + retvm_if(keynode->keyname == NULL, NULL, "The name of keynode is NULL"); + + return keynode->keyname; +} + +/* + * This function get value type of the keynode. + * @param[in] keynode The Key + * @return Type of the keynode + */ +API int vconf_keynode_get_type(keynode_t *keynode) +{ + retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL"); + + return keynode->type; +} + +API int vconf_keynode_get_int(keynode_t *keynode) +{ + retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL"); + retvm_if(keynode->type != VCONF_TYPE_INT, VCONF_ERROR, + "The type(%d) of keynode(%s) is not INT", keynode->type, keynode->keyname); + + return keynode->value.i; +} + +API double vconf_keynode_get_dbl(keynode_t *keynode) +{ + retvm_if(keynode == NULL, -1.0, "Invalid argument: keynode is NULL"); + retvm_if(keynode->type != VCONF_TYPE_DOUBLE, -1.0, + "The type(%d) of keynode(%s) is not DBL", keynode->type, keynode->keyname); + + return keynode->value.d; +} + +/* + * This function get Boolean value of the keynode. + * @param[in] keynode The Key + * @return Boolean value, -1 on error + */ +API int vconf_keynode_get_bool(keynode_t *keynode) +{ + retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: keynode is NULL"); + retvm_if(keynode->type != VCONF_TYPE_BOOL, VCONF_ERROR, + "The type(%d) of keynode(%s) is not BOOL", keynode->type, keynode->keyname); + + return !!(keynode->value.b); +} + +/* + * This function get String value of the keynode. + * @param[in] keynode The Key + * @return String value, NULL on error + */ +API char *vconf_keynode_get_str(keynode_t *keynode) +{ + retvm_if(keynode == NULL, NULL, "Invalid argument: keynode is NULL"); + retvm_if(keynode->type != VCONF_TYPE_STRING, NULL, + "The type(%d) of keynode(%s) is not STR", keynode->type, keynode->keyname); + + return keynode->value.s; +} + +/* + * Allocate, initialize and return a new Keylist object. + * @return The pointer of New keylist, NULL on error + */ +API keylist_t *vconf_keylist_new(void) +{ + keylist_t *keylist; + keylist = calloc(1, sizeof(keylist_t)); + + return keylist; +} + +/* + * This function rewinds the KeyList internal cursor. + * @param[in] keylist Key List + * @return 0 on success, -1 on error + */ +API int vconf_keylist_rewind(keylist_t *keylist) +{ + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + + keylist->cursor = NULL; + + return 0; +} + +/* + * A destructor for Keylist objects. + * @param[in] keylist Key List + * @return 0 on success, -1 on error + */ +API int vconf_keylist_free(keylist_t *keylist) +{ + keynode_t *keynode, *temp; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + + if (keylist->num) { + keynode = _vconf_keylist_headnode(keylist); + while (keynode) { + temp = _vconf_keynode_next(keynode); + _vconf_keynode_free(keynode); + keynode = temp; + } + } + free(keylist); + return 0; +} + +/* + * This function look for a Keynode contained in keylist that matches keyname. + * @param[in] keylist Key List + * @param[in] keyname Key to find + * @param[out] return_node pointer of keynode to set + * @return Type of the found key + */ +API int +vconf_keylist_lookup(keylist_t *keylist, + const char *keyname, keynode_t **return_node) +{ + keynode_t *found_node; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + retvm_if(return_node == NULL, VCONF_ERROR, "Invalid argument: return_node is NULL"); + + found_node = _vconf_keylist_lookup(keylist, keyname, NULL); + if (NULL == found_node) + return 0; + + if (return_node) + *return_node = found_node; + return found_node->type; +} + +/* + * This function returns the next Key in a Keylist. + * Next key is known by the keylist internal cursor. + * @param[in] keylist Key List + * @return The next Keynode, NULL on error + */ +API keynode_t *vconf_keylist_nextnode(keylist_t *keylist) +{ + retvm_if(keylist == NULL, NULL, "Invalid argument: keylist is NULL"); + + if (keylist->cursor) + keylist->cursor = _vconf_keynode_next(keylist->cursor); + else + keylist->cursor = keylist->head; + + return keylist->cursor; +} + +/* + * This function appends a new Keynode included integer value to the keylist. + * If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The integer value + * @return Number of keynode included in the keylist, -1 on error + */ +API int +vconf_keylist_add_int(keylist_t *keylist, const char *keyname, const int value) +{ + keynode_t *keynode = NULL, *addition = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) { + _vconf_keynode_set_value_int(keynode, value); + return keylist->num; + } + if ((keynode = _vconf_keylist_headnode(keylist))) + while (_vconf_keynode_next(keynode)) + keynode = _vconf_keynode_next(keynode); + + addition = calloc(1, sizeof(keynode_t)); + retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory"); + if (!_vconf_keynode_set_keyname(addition, keyname)) { + _vconf_keynode_set_value_int(addition, value); + if (keylist->head && NULL != keynode) + keynode->next = addition; + else + keylist->head = addition; + keylist->num += 1; + } else { + ERR("(maybe)not enought memory"); + free(addition), addition = NULL; + return VCONF_ERROR; + } + + return keylist->num; +} + +/* + * This function appends a new Keynode included boolean value to the keylist. + * If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The boolean value + * @return Number of keynode included in the keylist, -1 on error + */ +API int +vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, const int value) +{ + keynode_t *keynode = NULL, *addition = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) { + _vconf_keynode_set_value_bool(keynode, value); + return keylist->num; + } + if ((keynode = _vconf_keylist_headnode(keylist))) + while (_vconf_keynode_next(keynode)) + keynode = _vconf_keynode_next(keynode); + + addition = calloc(1, sizeof(keynode_t)); + retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory"); + if (!_vconf_keynode_set_keyname(addition, keyname)) { + _vconf_keynode_set_value_bool(addition, value); + if (keylist->head && NULL != keynode) + keynode->next = addition; + else + keylist->head = addition; + keylist->num += 1; + } else { + ERR("(maybe)not enought memory"); + free(addition), addition = NULL; + return VCONF_ERROR; + } + + return keylist->num; +} + +/* + * This function appends a new Keynode included double value to the keylist. + * If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The double value + * @return Number of keynode included in the keylist, -1 on error + */ +API int +vconf_keylist_add_dbl(keylist_t *keylist, + const char *keyname, const double value) +{ + keynode_t *keynode = NULL, *addition = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) { + _vconf_keynode_set_value_dbl(keynode, value); + return keylist->num; + } + if ((keynode = _vconf_keylist_headnode(keylist))) + while (_vconf_keynode_next(keynode)) + keynode = _vconf_keynode_next(keynode); + + addition = calloc(1, sizeof(keynode_t)); + retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory"); + if (!_vconf_keynode_set_keyname(addition, keyname)) { + _vconf_keynode_set_value_dbl(addition, value); + if (keylist->head && NULL != keynode) + keynode->next = addition; + else + keylist->head = addition; + keylist->num += 1; + } else { + ERR("(maybe)not enought memory"); + free(addition), addition = NULL; + return VCONF_ERROR; + } + + return keylist->num; +} + +/* + * This function appends a new Keynode included string value to the keylist. + * If same keyname exist, the keynode will change. + * @param[in] keylist Key List + * @param[in] keyname Key + * @param[in] value The pointer of string value + * @return Number of keynode included in the keylist, -1 on error + */ +API int +vconf_keylist_add_str(keylist_t *keylist, + const char *keyname, const char *value) +{ + keynode_t *keynode = NULL, *addition = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if ((keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) { + if (VCONF_TYPE_STRING == keynode->type && keynode->value.s) + free(keynode->value.s); + _vconf_keynode_set_value_str(keynode, value); + return keylist->num; + } + if (NULL != (keynode = _vconf_keylist_headnode(keylist))) + while (_vconf_keynode_next(keynode)) + keynode = _vconf_keynode_next(keynode); + + addition = calloc(1, sizeof(keynode_t)); + retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory"); + if (!_vconf_keynode_set_keyname(addition, keyname)) { + _vconf_keynode_set_value_str(addition, value); + if (keylist->head && NULL != keynode) + keynode->next = addition; + else + keylist->head = addition; + keylist->num += 1; + } else { + ERR("(maybe)not enought memory"); + free(addition), addition = NULL; + return VCONF_ERROR; + } + + return keylist->num; +} + +/* + * This function Appends a new Keynode to the keylist without value. + * Use on vconf_get() + * @param[in] keylist Key List + * @param[in] keyname Key + * @return Number of keynode included in the keylist, -1 on error + */ +API int vconf_keylist_add_null(keylist_t *keylist, const char *keyname) +{ + keynode_t *keynode = NULL, *addition = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if (NULL != (keynode = _vconf_keylist_lookup(keylist, keyname, NULL))) { + keynode->type = 0; + keynode->value.d = 0; + return keylist->num; + } + if ((keynode = _vconf_keylist_headnode(keylist))) + while (_vconf_keynode_next(keynode)) + keynode = _vconf_keynode_next(keynode); + + addition = calloc(1, sizeof(keynode_t)); + retvm_if(addition == NULL, VCONF_ERROR, "(maybe)not enought memory"); + if (!_vconf_keynode_set_keyname(addition, keyname)) { + if (keylist->head && keynode) + keynode->next = addition; + else + keylist->head = addition; + keylist->num += 1; + } else { + ERR("(maybe)not enought memory"); + free(addition), addition = NULL; + return VCONF_ERROR; + } + + return keylist->num; +} + +/* + * This function remove the keynode that matches keyname. + * @param[in] keylist the keylist included the keyname + * @param[in] keyname key + * @return 0 on success, -1(Invalid parameter), -2(Not exist keyname in keylist) on error + */ +API int vconf_keylist_del(keylist_t *keylist, const char *keyname) +{ + keynode_t *found_node, *before_node = NULL; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + retvm_if(keyname == NULL, VCONF_ERROR, "Invalid argument: keyname is NULL"); + + if ((found_node = _vconf_keylist_lookup(keylist, keyname, &before_node))) { + if(before_node) { + before_node->next = found_node->next; + } else { + /* requested key is headnode of keylist */ + keylist->head = found_node->next; + } + + _vconf_keynode_free(found_node); + } else + return VCONF_ERROR; + + return VCONF_OK; +} + + +int _vconf_get_key_prefix(const char *keyname, int *prefix) +{ + if (strncmp(keyname, BACKEND_DB_PREFIX, sizeof(BACKEND_DB_PREFIX) - 1) == 0) { + *prefix = VCONF_BACKEND_DB; + } else if (0 == strncmp(keyname, BACKEND_FILE_PREFIX, sizeof(BACKEND_FILE_PREFIX) - 1)) { + *prefix = VCONF_BACKEND_FILE; + } else if (0 == strncmp(keyname, BACKEND_MEMORY_PREFIX, sizeof(BACKEND_MEMORY_PREFIX) - 1)) { + *prefix = VCONF_BACKEND_MEMORY; + } else { + ERR("Invalid argument: wrong prefix of key(%s)", keyname); + *prefix = VCONF_BACKEND_NULL; + return VCONF_ERROR_WRONG_PREFIX; + } + + return VCONF_OK; +} + +int _vconf_get_key_path(const char *keyname, char *path) +{ + if (strncmp(keyname, BACKEND_DB_PREFIX, sizeof(BACKEND_DB_PREFIX) - 1) == 0) { + snprintf(path, KEY_PATH, "%s%s", BACKEND_SYSTEM_DIR, keyname); + } else if (0 == strncmp(keyname, BACKEND_FILE_PREFIX, sizeof(BACKEND_FILE_PREFIX) - 1)) { + snprintf(path, KEY_PATH, "%s%s", BACKEND_SYSTEM_DIR, keyname); + } else if (0 == strncmp(keyname, BACKEND_MEMORY_PREFIX, sizeof(BACKEND_MEMORY_PREFIX) - 1)) { + snprintf(path, KEY_PATH, "%s%s", BACKEND_MEMORY_DIR, keyname); + } else { + ERR("Invalid argument: wrong prefix of key(%s)", keyname); + return VCONF_ERROR_WRONG_PREFIX; + } + + return VCONF_OK; +} + +#ifndef DISABLE_RUNTIME_KEY_CREATION +static int _vconf_set_key_check_parent_dir(const char* path) +{ + int exists = 0; + struct stat stat_info; + char* parent; + char path_buf[KEY_PATH] = {0,}; + int ret = 0; + + mode_t dir_mode = 0664 | 0111; + + parent = strrchr(path, '/'); + strncpy(path_buf, path, parent-path); + path_buf[parent-path]=0; + + exists = stat(path_buf,&stat_info); + if(exists){ + if(mkdir(path_buf, dir_mode) != 0) { + if(errno == ENOENT) { + ret = _vconf_set_key_check_parent_dir((const char*)path_buf); + if(ret != VCONF_OK) return ret; + if(mkdir(path_buf, dir_mode) != 0) { + ERR("mkdir error(%d)", errno); + return VCONF_ERROR; + } + } + } + } + + return VCONF_OK; +} + +static int _vconf_set_key_creation(const char* path) +{ + int fd; + mode_t temp; + temp = umask(0000); + fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); + umask(temp); + if(fd == -1) { + ERR("open(rdwr,create) error\n"); + return VCONF_ERROR; + } + close(fd); + + return VCONF_OK; +} +#endif + +static int _vconf_set_file_lock(int fd, short type) +{ +#ifdef HAVE_FCNTL_H + int ret = 0; + struct flock l; + + l.l_type = type; /*Do read Lock*/ + l.l_start= 0; /*Start at begin*/ + l.l_whence = SEEK_SET; + l.l_len = 0; /*Do it with whole file*/ + ret = fcntl(fd, F_SETLKW, &l); + return ret; +#else + return 0; +#endif +} + +static int _vconf_set_read_lock(int fd) +{ + return _vconf_set_file_lock(fd, F_RDLCK); +} + +static int _vconf_set_write_lock(int fd) +{ + return _vconf_set_file_lock(fd, F_WRLCK); +} + +static int _vconf_set_unlock(int fd) +{ + return _vconf_set_file_lock(fd, F_UNLCK); +} + +static void _vconf_acquire_transaction_delay(int ms) +{ + struct timeval timeout; + timeout.tv_sec = ms / 1000 ; + timeout.tv_usec = 1000 * ( ms % 1000 ); + + select(0, 0, 0, 0, &timeout); +} + +static int _vconf_db_begin_transaction() +{ + pid_t value; + VCONF_MOUNT_PATH_CHECK; + + if(is_transaction == 0) { + value = getpid(); +transaction_retry: + if(setxattr(VCONF_MOUNT_PATH, "full_db_transaction_start", &value, sizeof(value), 0) == -1) + { + _vconf_acquire_transaction_delay(50); + goto transaction_retry; + } else { + is_transaction++; + } + } else { + is_transaction++; + } + + return VCONF_OK; +} + +static int _vconf_db_commit_transaction() +{ + pid_t value; + VCONF_MOUNT_PATH_CHECK; + + retv_if(is_transaction <= 0, VCONF_ERROR); + + if(is_transaction == 1) { + value = getpid(); + setxattr(VCONF_MOUNT_PATH, "full_db_transaction_stop", &value, sizeof(value), 0); + is_transaction = 0; + } else { + is_transaction --; + } + + return 0; +} + +static int _vconf_db_rollback_transaction() +{ + pid_t value; + VCONF_MOUNT_PATH_CHECK; + + retv_if(is_transaction <= 0, VCONF_ERROR); + + if(is_transaction == 1) { + value = getpid(); + setxattr(VCONF_MOUNT_PATH, "full_db_transaction_rb", &value, sizeof(value), 0); + is_transaction = 0; + } else { + is_transaction --; + } + + return 0; +} + +static int _vconf_set_key_filesys(keynode_t *keynode, int prefix) +{ + char path[KEY_PATH] = {0,}; + FILE *fp = NULL; + int ret = -1; + int func_ret = VCONF_OK; + int err_no = 0; + char err_buf[100] = { 0, }; + int is_write_error = 0; + + errno = 0; + + ret = _vconf_get_key_path(keynode->keyname, path); + retv_if(ret != VCONF_OK, ret); + + if( (fp = fopen(path, "w")) == NULL ) { + func_ret = VCONF_ERROR_FILE_OPEN; + err_no = errno; + goto out_return; + } + + if(prefix != VCONF_BACKEND_DB) { + (void) _vconf_set_write_lock(fileno(fp)); + if(errno != 0) { + func_ret = VCONF_ERROR_FILE_LOCK; + err_no = errno; + goto out_close; + } + } + + /* write key type */ + ret = fwrite((void *)&(keynode->type), sizeof(int), 1, fp); + if(ret <= 0) + { + if(errno) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_WRITE; + goto out_unlock; + } + + /* write key value */ + switch(keynode->type) + { + case VCONF_TYPE_INT: + ret = fwrite((void *)&(keynode->value.i), sizeof(int), 1, fp); + if(ret <= 0) is_write_error = 1; + break; + case VCONF_TYPE_DOUBLE: + ret = fwrite((void *)&(keynode->value.d), sizeof(double), 1, fp); + if(ret <= 0) is_write_error = 1; + break; + case VCONF_TYPE_BOOL: + ret = fwrite((void *)&(keynode->value.b), sizeof(int), 1, fp); + if(ret <= 0) is_write_error = 1; + break; + case VCONF_TYPE_STRING: + ret = fprintf(fp,"%s",keynode->value.s); + if(ret < strlen(keynode->value.s)) is_write_error = 1; + //ret = fwrite((void *)keynode->value.s, sizeof(char), strlen(keynode->value.s), fp); + break; + default : + func_ret = VCONF_ERROR_WRONG_TYPE; + goto out_unlock; + } + if(is_write_error) + { + if(errno) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_WRITE; + goto out_unlock; + } + +#ifdef ENABLE_FDATASYNC + if(prefix == VCONF_BACKEND_FILE) { + fflush(fp); + + ret = fdatasync(fileno(fp)); + if(ret == -1) { + err_no = errno; + func_ret = VCONF_ERROR_FILE_SYNC; + } + } +#endif + +out_unlock : + if(prefix != VCONF_BACKEND_DB) { + (void) _vconf_set_unlock(fileno(fp)); + if(errno != 0) { + func_ret = VCONF_ERROR_FILE_LOCK; + err_no = errno; + goto out_close; + } + } + +out_close : + fclose(fp); + +out_return : + if(err_no != 0) { + strerror_r(err_no, err_buf, 100); + ERR("_vconf_set_key_filesys(%d-%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf); + } + + return func_ret; +} + +static int _vconf_set_key(keynode_t *keynode) +{ + int func_ret = VCONF_OK; + int ret = 0; + int is_busy_err = 0; + int retry = -1; + int prefix = 0; + int rc = 0; + + ret = _vconf_get_key_prefix(keynode->keyname, &prefix); + retv_if(ret != VCONF_OK, ret); + + if(prefix == VCONF_BACKEND_DB) { + _vconf_db_begin_transaction(); + } + + while((ret = _vconf_set_key_filesys(keynode, prefix)) != VCONF_OK) + { + is_busy_err = 0; + retry++; + + if(ret == VCONF_ERROR_FILE_OPEN) + { + switch (errno) + { + /* file is not exist, make path */ +#ifndef DISABLE_RUNTIME_KEY_CREATION + case EFAULT : + case ENOENT : + { + char path[KEY_PATH] = {0,}; + rc = _vconf_get_key_path(keynode->keyname, path); + if(rc != VCONF_OK) { + ERR("_vconf_get_key_path error"); + break; + } + + ret = _vconf_set_key_check_parent_dir(path); + if(rc != VCONF_OK) { + ERR("_vconf_set_key_check_parent_dir error : %s", path); + break; + } + + ret = _vconf_set_key_creation(path); + if(rc != VCONF_OK) { + ERR("_vconf_set_key_creation error : %s", path); + break; + } + INFO("%s key is created", keynode->keyname); + } +#endif + case EAGAIN : + case EMFILE : + case ENFILE : + case ETXTBSY : + { + is_busy_err = 1; + } + } + } + else if (ret == VCONF_ERROR_FILE_CHMOD) + { + switch (errno) + { + case EINTR : + case EBADF : + { + is_busy_err = 1; + } + } + } + else if (ret == VCONF_ERROR_FILE_LOCK) + { + switch (errno) + { + case EBADF : + case EACCES : + case EAGAIN : + case ENOLCK : + { + is_busy_err = 1; + } + } + } + else if (ret == VCONF_ERROR_FILE_WRITE) + { + switch (errno) + { + case 0 : + case EAGAIN : + case EINTR : + case EIO : + case ENOMEM : + { + is_busy_err = 1; + } + } + } + else + { + is_busy_err = 0; + } + + if ((is_busy_err == 1) && (retry < VCONF_ERROR_RETRY_CNT)) { + ERR("%s : write buf error(%d). write will be retried(%d) , usleep time : %d\n", keynode->keyname, ret, retry, (retry)*VCONF_ERROR_RETRY_SLEEP_UTIME); + usleep((retry)*VCONF_ERROR_RETRY_SLEEP_UTIME); + continue; + } else { + ERR("%s : write buf error(%d). break. (%d)\n", keynode->keyname, ret, retry); + func_ret = VCONF_ERROR; + break; + } + } + + if(prefix == VCONF_BACKEND_DB) { + if(func_ret == VCONF_ERROR) { + _vconf_db_rollback_transaction(); + } else { + _vconf_db_commit_transaction(); + } + } + + return func_ret; +} + +/* + * This function set the value of given keys + * @param[in] keylist the keylist which should contain changed keys + * @return 0 on success, -1 on error + */ +API int vconf_set(keylist_t *keylist) +{ + START_TIME_CHECK + + keynode_t *got_node; + + int func_ret = VCONF_OK; + int ret = 0; + int prefix = 0; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is NULL"); + + INFO("vconf_set (%d)START", keylist->num); + + got_node = _vconf_keylist_headnode(keylist); + + retvm_if(got_node == NULL, VCONF_ERROR, "Invalid argument: headnode is NULL"); + + ret = _vconf_get_key_prefix(got_node->keyname, &prefix); + retv_if(ret != VCONF_OK, ret); + + if(prefix == VCONF_BACKEND_DB) { + _vconf_db_begin_transaction(); + } + + while (got_node != NULL) { + ret = _vconf_set_key(got_node); + if(ret != VCONF_OK) { + func_ret = VCONF_ERROR; + } + + got_node = _vconf_keynode_next(got_node); + } + + if(prefix == VCONF_BACKEND_DB) { + if(func_ret == VCONF_ERROR) { + _vconf_db_rollback_transaction(); + } else { + _vconf_db_commit_transaction(); + } + } + + END_TIME_CHECK + + return func_ret; +} + +API int vconf_sync_key(const char *in_key) +{ + START_TIME_CHECK + + int fd; + char path[KEY_PATH] = {0,}; + int ret = -1; + + ret = _vconf_get_key_path(in_key, path); + if(ret != VCONF_OK) return VCONF_ERROR; + + fd = open(path, O_RDWR); + if(fd == -1) return VCONF_ERROR; + + fsync(fd); + close(fd); + + END_TIME_CHECK + + return 0; +} + +/* + * This function set the integer value of given key + * @param[in] in_key key + * @param[in] intval integer value to set + * @return 0 on success, -1 on error + */ +API int vconf_set_int(const char *in_key, const int intval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL"); + + int func_ret = VCONF_OK; + + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key); + if(func_ret != VCONF_OK) { + _vconf_keynode_free(pKeyNode); + ERR("set key name error"); + return VCONF_ERROR; + } + _vconf_keynode_set_value_int(pKeyNode, intval); + + if (_vconf_set_key(pKeyNode) != VCONF_OK) { + ERR("vconf_set_int(%d) : %s(%d) error", getpid(), in_key, intval); + func_ret = VCONF_ERROR; + } else{ + INFO("vconf_set_int(%d) : %s(%d) success", getpid(), in_key, intval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* +* This function set the boolean value of given key +* @param[in] in_key key +* @param[in] boolval boolean value to set + (Integer value 1 is 'True', and 0 is 'False') +* @return 0 on success, -1 on error +*/ +API int vconf_set_bool(const char *in_key, const int boolval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key); + if(func_ret != VCONF_OK) { + _vconf_keynode_free(pKeyNode); + ERR("set key name error"); + return VCONF_ERROR; + } + _vconf_keynode_set_value_bool(pKeyNode, boolval); + + if (_vconf_set_key(pKeyNode) != VCONF_OK) { + ERR("vconf_set_bool(%d) : %s(%d) error", getpid(), in_key, boolval); + func_ret = VCONF_ERROR; + } else { + INFO("vconf_set_bool(%d) : %s(%d) success", getpid(), in_key, boolval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function set the double value of given key + * @param[in] in_key key + * @param[in] dblval double value to set + * @return 0 on success, -1 on error + */ +API int vconf_set_dbl(const char *in_key, const double dblval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key); + if(func_ret != VCONF_OK) { + _vconf_keynode_free(pKeyNode); + ERR("set key name error"); + return VCONF_ERROR; + } + _vconf_keynode_set_value_dbl(pKeyNode, dblval); + + if (_vconf_set_key(pKeyNode) != VCONF_OK) { + ERR("vconf_set_dbl(%d) : %s(%f) error", getpid(), in_key, dblval); + func_ret = VCONF_ERROR; + } else { + INFO("vconf_set_dbl(%d) : %s(%f) success", getpid(), in_key, dblval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function set the string value of given key + * @param[in] in_key key + * @param[in] strval string value to set + * @return 0 on success, -1 on error + */ +API int vconf_set_str(const char *in_key, const char *strval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is NULL"); + retvm_if(strval == NULL, VCONF_ERROR, "Invalid argument: value is NULL"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + func_ret = _vconf_keynode_set_keyname(pKeyNode, in_key); + if(func_ret != VCONF_OK) { + _vconf_keynode_free(pKeyNode); + ERR("set key name error"); + return VCONF_ERROR; + } + _vconf_keynode_set_value_str(pKeyNode, strval); + + if (_vconf_set_key(pKeyNode) != VCONF_OK) { + ERR("vconf_set_str(%d) : %s(%s) error", getpid(), in_key, strval); + func_ret = VCONF_ERROR; + } else { + INFO("vconf_set_str(%d) : %s(%s) success", getpid(), in_key, strval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + + +#ifdef SUPPORT_ELEKTRA_VALUE_FORMAT +/* keyFileUnserialize function of ELEKTRA */ +static int _vconf_get_key_elektra_format(keynode_t *keynode, FILE *fp) +{ + char version[10] = {0,}; + char type[5] = {0,}; + char comment[8] = {0,}; + char file_buf[BUF_LEN] = {0,}; + char *value = NULL; + int value_size = 0; + int err_no = 0; + char err_buf[100] = { 0, }; + int func_ret = VCONF_OK; + + INFO("_vconf_get_key_elektra_format start"); + + rewind(fp); + + if (!fgets(version, sizeof(version), fp)) + { + if(ferror(fp)) { + err_no = errno; + } else { + err_no = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FGETS; + goto out_return; + } + if (strncmp(version,"RG",2)) { + func_ret = VCONF_ERROR_WRONG_TYPE; + goto out_return; + } + + if (!fgets(type, sizeof(type), fp)) + { + if(ferror(fp)) { + err_no = errno; + } else { + err_no = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FGETS; + goto out_return; + } + + if (!fgets(comment, sizeof(comment), fp)) + { + if(ferror(fp)) { + err_no = errno; + } else { + err_no = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FGETS; + goto out_return; + } + + while(fgets(file_buf, sizeof(file_buf), fp)) + { + if(value) { + value_size = value_size + strlen(file_buf); + value = (char *) realloc(value, value_size); + if(value == NULL) { + func_ret = VCONF_ERROR_NO_MEM; + break; + } + strncat(value, file_buf, strlen(file_buf)); + } else { + value_size = strlen(file_buf) + 1; + value = (char *)malloc(value_size); + if(value == NULL) { + func_ret = VCONF_ERROR_NO_MEM; + break; + } + memset(value, 0x00, value_size); + strncpy(value, file_buf, strlen(file_buf)); + } + } + + if(ferror(fp)) { + err_no = errno; + func_ret = VCONF_ERROR_FILE_FGETS; + } else { + if(value) { + switch(atoi(type)) + { + case VCONF_TYPE_INT: + { + _vconf_keynode_set_value_int(keynode, atoi(value)); + break; + } + case VCONF_TYPE_DOUBLE: + { + _vconf_keynode_set_value_dbl(keynode, atof(value)); + break; + } + case VCONF_TYPE_BOOL: + { + _vconf_keynode_set_value_bool(keynode, atoi(value)); + break; + } + case VCONF_TYPE_STRING: + { + _vconf_keynode_set_value_str(keynode, value); + break; + } + default : + { + func_ret = VCONF_ERROR_WRONG_VALUE; + } + } + } else { + if(atoi(type) == VCONF_TYPE_STRING) { + _vconf_keynode_set_value_str(keynode, ""); + } else { + func_ret = VCONF_ERROR_WRONG_VALUE; + } + } + } + +out_return : + if(err_no != 0) { + strerror_r(err_no, err_buf, 100); + ERR("_vconf_set_key_filesys(%d/%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf); + } + + if(value) free(value); + + return func_ret; +} +#endif + +static int _vconf_get_key_filesys(keynode_t *keynode, int prefix) +{ + char path[KEY_PATH] = {0,}; + int ret = -1; + int func_ret = VCONF_OK; + char err_buf[100] = { 0, }; + int err_no = 0; + int type = 0; + FILE *fp = NULL; + + errno = 0; + + ret = _vconf_get_key_path(keynode->keyname, path); + retv_if(ret != VCONF_OK, ret); + + if( (fp = fopen(path, "r")) == NULL ) { + func_ret = VCONF_ERROR_FILE_OPEN; + err_no = errno; + goto out_return; + } + + if(prefix != VCONF_BACKEND_DB) { + (void) _vconf_set_read_lock(fileno(fp)); + if(errno != 0) { + func_ret = VCONF_ERROR_FILE_LOCK; + err_no = errno; + goto out_close; + } + } + + /* read data type */ + if(!fread((void*)&type, sizeof(int), 1, fp)) { + if(ferror(fp)) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FREAD; + goto out_unlock; + } + + /* read data value */ + switch(type) + { + case VCONF_TYPE_INT: + { + int value_int = 0; + if(!fread((void*)&value_int, sizeof(int), 1, fp)) { + if(ferror(fp)) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FREAD; + goto out_unlock; + } else { + _vconf_keynode_set_value_int(keynode, value_int); + } + + break; + } + case VCONF_TYPE_DOUBLE: + { + double value_dbl = 0; + if(!fread((void*)&value_dbl, sizeof(double), 1, fp)) { + if(ferror(fp)) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FREAD; + goto out_unlock; + } else { + _vconf_keynode_set_value_dbl(keynode, value_dbl); + } + + break; + } + case VCONF_TYPE_BOOL: + { + int value_int = 0; + if(!fread((void*)&value_int, sizeof(int), 1, fp)) { + if(ferror(fp)) { + err_no = errno; + } else { + errno = EAGAIN; + } + func_ret = VCONF_ERROR_FILE_FREAD; + goto out_unlock; + } else { + _vconf_keynode_set_value_bool(keynode, value_int); + } + + break; + } + case VCONF_TYPE_STRING: + { + char file_buf[BUF_LEN] = {0,}; + char *value = NULL; + int value_size = 0; + + while(fgets(file_buf, sizeof(file_buf), fp)) + { + if(value) { + value_size = value_size + strlen(file_buf); + value = (char *) realloc(value, value_size); + if(value == NULL) { + func_ret = VCONF_ERROR_NO_MEM; + break; + } + strncat(value, file_buf, strlen(file_buf)); + } else { + value_size = strlen(file_buf) + 1; + value = (char *)malloc(value_size); + if(value == NULL) { + func_ret = VCONF_ERROR_NO_MEM; + break; + } + memset(value, 0x00, value_size); + strncpy(value, file_buf, strlen(file_buf)); + } + } + + if(ferror(fp)) { + err_no = errno; + func_ret = VCONF_ERROR_FILE_FGETS; + } else { + if(value) { + _vconf_keynode_set_value_str(keynode, value); + } else { + _vconf_keynode_set_value_str(keynode, ""); + } + } + if(value) + free(value); + + break; + } + default : +#ifdef SUPPORT_ELEKTRA_VALUE_FORMAT + func_ret = _vconf_get_key_elektra_format(keynode, fp); +#else + func_ret = VCONF_ERROR_WRONG_TYPE; +#endif + } + +out_unlock : + if(prefix != VCONF_BACKEND_DB) { + (void) _vconf_set_unlock(fileno(fp)); + if(errno != 0) { + func_ret = VCONF_ERROR_FILE_LOCK; + err_no = errno; + goto out_close; + } + } + +out_close : + fclose(fp); + +out_return : + if(err_no != 0) { + strerror_r(err_no, err_buf, 100); + ERR("_vconf_get_key_filesys(%d-%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf); + } + + return func_ret; +} + + +int _vconf_get_key(keynode_t *keynode) +{ + int func_ret = VCONF_OK; + int ret = 0; + int is_busy_err = 0; + int retry = -1; + int prefix = 0; + + ret = _vconf_get_key_prefix(keynode->keyname, &prefix); + retv_if(ret != VCONF_OK, ret); + + if(prefix == VCONF_BACKEND_DB) { + _vconf_db_begin_transaction(); + } + + while((ret = _vconf_get_key_filesys(keynode, prefix)) != VCONF_OK) + { + is_busy_err = 0; + retry++; + + if(ret == VCONF_ERROR_FILE_OPEN) + { + switch (errno) + { + case EAGAIN : + case EMFILE : + case ETXTBSY : + { + is_busy_err = 1; + } + } + } + else if (ret == VCONF_ERROR_FILE_LOCK) + { + switch (errno) + { + case EBADF : + case EACCES : + case EAGAIN : + case ENOLCK : + { + is_busy_err = 1; + } + } + } + else if (ret == VCONF_ERROR_FILE_FREAD) + { + switch (errno) + { + case EAGAIN : + case EINTR : + case EIO : + { + is_busy_err = 1; + } + } + } + else + { + is_busy_err = 0; + } + + if ((is_busy_err == 1) && (retry < VCONF_ERROR_RETRY_CNT)) { + ERR("%s : read buf error(%d). read will be retried(%d) , %d\n", keynode->keyname, ret, retry, (retry)*VCONF_ERROR_RETRY_SLEEP_UTIME); + usleep((retry)*VCONF_ERROR_RETRY_SLEEP_UTIME); + continue; + } else { + ERR("%s : read buf error(%d). break\n", keynode->keyname, ret); + func_ret = VCONF_ERROR; + break; + } + } + + if(prefix == VCONF_BACKEND_DB) { + if(func_ret == VCONF_ERROR) { + _vconf_db_rollback_transaction(); + } else { + _vconf_db_commit_transaction(); + } + } + + return func_ret; +} + +static int _vconf_check_value_integrity(const void *value, int type) +{ + int i = 0; + + if ((type == VCONF_TYPE_STRING) && (value != NULL)) { + return 0; + } + + if ((value) && (strlen(value) > 0)) { + if ((type == VCONF_TYPE_INT) || + (type == VCONF_TYPE_BOOL)|| + (type == VCONF_TYPE_DOUBLE)) { + while (*(((char *)value) + i) != '\0') { + if ( !isdigit(*(((char *)value) + i)) ) { + if ((type != VCONF_TYPE_BOOL) && + (*(((char *)value) + i) != '-')) { + if ((type == VCONF_TYPE_DOUBLE) && + (*(((char *)value) + i) != '.')) { + ERR("ERROR : vconf value is not digit."); + return -1; + } + } + } + i++; + } + } + + return 0; + } else { + ERR("ERROR : vconf value is NULL."); + return -2; + } +} + +int _vconf_path_is_dir(char* path) +{ + struct stat entryInfo; + + if(lstat(path, &entryInfo) == 0 ) { + if( S_ISDIR( entryInfo.st_mode ) ) { + return 1; + } else { + return 0; + } + } else { + return VCONF_ERROR; + } +} + +API int vconf_get(keylist_t *keylist, const char *dirpath, get_option_t option) +{ + DIR *dir = NULL; + struct dirent entry; + struct dirent *result = NULL; + char full_file_path[KEY_PATH] = {0,}; + char file_path[KEY_PATH] = {0,}; + char full_path[KEY_PATH] = {0,}; + char err_buf[ERR_LEN] = {0,}; + int rc = 0; + int func_ret = 0; + int ret = 0; + int is_dir = 0; + int prefix = 0; + + keynode_t *temp_keynode; + + retvm_if(keylist == NULL, VCONF_ERROR, "Invalid argument: keylist is null"); + retvm_if(dirpath == NULL, VCONF_ERROR, "Invalid argument: dirpath is null"); + + temp_keynode = _vconf_keylist_headnode(keylist); + + if ((NULL != temp_keynode) && (VCONF_GET_KEY != option)) { + ERR("Not support mode : Only VCONF_GET_KEY \ + option support To retrieve key with keylist"); + return VCONF_ERROR; + } + + if(temp_keynode != NULL) { + while(_vconf_keynode_next(temp_keynode)) { + temp_keynode = _vconf_keynode_next(temp_keynode); + } + } + + ret = _vconf_get_key_path(dirpath, full_path); + retvm_if(ret != VCONF_OK, ret, "Invalid argument: key is not valid"); + + + ret = _vconf_get_key_prefix(dirpath, &prefix); + retv_if(ret != VCONF_OK, ret); + + if(prefix == VCONF_BACKEND_DB) { + _vconf_db_begin_transaction(); + } + + is_dir = _vconf_path_is_dir(full_path); + if(is_dir == 1) { + if((dir=opendir(full_path)) == NULL) { + strerror_r(errno, err_buf, ERR_LEN); + ERR("ERROR : open directory(%s) fail(%s)", dirpath, err_buf); + return VCONF_ERROR; + } + + if((readdir_r(dir, &entry, &result)) != 0) { + strerror_r(errno, err_buf, ERR_LEN); + ERR("ERROR : read directory(%s) fail(%s)", dirpath, err_buf); + func_ret = VCONF_ERROR; + } + + while(result != NULL) + { + if(( strcmp( entry.d_name, ".") == 0 ) || ( strcmp( entry.d_name, "..") == 0 )) { + goto NEXT; + } + + keynode_t* keynode = _vconf_keynode_new(); + if(keynode == NULL) { + closedir(dir); + ERR("Invalid argument: key malloc fail"); + return VCONF_ERROR; + } + + snprintf(file_path, KEY_PATH, "%s/%s", dirpath, entry.d_name); + snprintf(full_file_path, KEY_PATH, "%s/%s", full_path, entry.d_name); + + rc = _vconf_path_is_dir(full_file_path); + if(rc != VCONF_ERROR) { + if(rc == 1) { + /* directory */ + if(option == VCONF_GET_KEY) { + _vconf_keynode_free(keynode); + goto NEXT; + } else { + _vconf_keynode_set_keyname(keynode, file_path); + _vconf_keynode_set_dir(keynode); + } + } else { + _vconf_keynode_set_keyname(keynode, file_path); + _vconf_get_key(keynode); + } + + if (keylist->head && temp_keynode != NULL) + { + temp_keynode->next = keynode; + temp_keynode = _vconf_keynode_next(temp_keynode); + } + else { + keylist->head = keynode; + temp_keynode = keylist->head; + } + keylist->num += 1; + } else { + _vconf_keynode_free(keynode); + + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : get path(%s) fail(%s)", file_path, err_buf); + func_ret = VCONF_ERROR; + } + + NEXT: + if((readdir_r(dir, &entry, &result)) != 0) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : read directory(%s) fail(%s)", dirpath, err_buf); + func_ret = VCONF_ERROR; + } + } + + if((closedir(dir)) != 0) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : close directory(%s) fail(%s)", dirpath, err_buf); + func_ret = VCONF_ERROR; + } + } else if(is_dir == 0) { + keynode_t* keynode = _vconf_keynode_new(); + retvm_if(keynode == NULL, VCONF_ERROR, "Invalid argument: key malloc fail"); + + _vconf_keynode_set_keyname(keynode, dirpath); + + _vconf_get_key(keynode); + + if (keylist->head && temp_keynode != NULL) { + temp_keynode->next = keynode; + //temp_keynode = _vconf_keynode_next(temp_keynode); + } else { + keylist->head = keynode; + temp_keynode = keylist->head; + } + keylist->num += 1; + } else { + return VCONF_ERROR; + } + vconf_keylist_rewind(keylist); + + if(prefix == VCONF_BACKEND_DB) { + if(func_ret == VCONF_ERROR) { + _vconf_db_rollback_transaction(); + } else { + _vconf_db_commit_transaction(); + } + } + + return func_ret; +} + +/* + * This function get the integer value of given key + * @param[in] in_key key + * @param[out] intval output buffer + * @return 0 on success, -1 on error + */ +API int vconf_get_int(const char *in_key, int *intval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + retvm_if(intval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + _vconf_keynode_set_keyname(pKeyNode, in_key); + + if (_vconf_get_key(pKeyNode) != VCONF_OK) { + ERR("vconf_get_int(%d) : %s error", getpid(), in_key); + func_ret = VCONF_ERROR; + } else { + *intval = vconf_keynode_get_int(pKeyNode); + INFO("vconf_get_int(%d) : %s(%d) success", getpid(), in_key, *intval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function get the boolean value of given key + * @param[in] in_key key + * @param[out] boolval output buffer + * @return 0 on success, -1 on error + */ +API int vconf_get_bool(const char *in_key, int *boolval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + retvm_if(boolval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + _vconf_keynode_set_keyname(pKeyNode, in_key); + + if (_vconf_get_key(pKeyNode) != VCONF_OK) { + ERR("vconf_get_bool(%d) : %s error", getpid(), in_key); + func_ret = VCONF_ERROR; + } else { + *boolval = vconf_keynode_get_bool(pKeyNode); + INFO("vconf_get_bool(%d) : %s(%d) success", getpid(), in_key, *boolval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function get the double value of given key + * @param[in] in_key key + * @param[out] dblval output buffer + * @return 0 on success, -1 on error + */ +API int vconf_get_dbl(const char *in_key, double *dblval) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + retvm_if(dblval == NULL, VCONF_ERROR, "Invalid argument: output buffer is null"); + + int func_ret = VCONF_OK; + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, VCONF_ERROR, "key malloc fail"); + + _vconf_keynode_set_keyname(pKeyNode, in_key); + + if (_vconf_get_key(pKeyNode) != VCONF_OK) { + ERR("vconf_get_dbl(%d) : %s error", getpid(), in_key); + func_ret = VCONF_ERROR; + } else { + *dblval = vconf_keynode_get_dbl(pKeyNode); + INFO("vconf_get_dbl(%d) : %s(%f) success", getpid(), in_key, *dblval); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function get the string value of given key + * @param[in] in_key key + * @return pointer of key value on success, NULL on error + */ +API char *vconf_get_str(const char *in_key) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, NULL, "Invalid argument: key is null"); + + keynode_t* pKeyNode = _vconf_keynode_new(); + retvm_if(pKeyNode == NULL, NULL, "key malloc fail"); + + _vconf_keynode_set_keyname(pKeyNode, in_key); + + char *strval = NULL; + char *tempstr = NULL; + + if (_vconf_get_key(pKeyNode) != VCONF_OK) { + ERR("vconf_get_str(%d) : %s error", getpid(), in_key); + } else { + tempstr = vconf_keynode_get_str(pKeyNode); + if(tempstr) + strval = strdup(tempstr); + INFO("vconf_get_str(%d) : %s success", getpid(), in_key); + } + + _vconf_keynode_free(pKeyNode); + + END_TIME_CHECK + + return strval; +} + +/* + * This function unset given key + * @param[in] in_key key + * @return 0 on success, -1 on error + */ +API int vconf_unset(const char *in_key) +{ + START_TIME_CHECK + + char path[KEY_PATH] = {0,}; + int ret = -1; + int err_retry = VCONF_ERROR_RETRY_CNT; + int func_ret = VCONF_OK; + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + + ret = _vconf_get_key_path(in_key, path); + retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid"); + + do { + ret = remove(path); + if(ret == -1) { + ERR("vconf_unset error(%d) : %s", errno, in_key); + func_ret = VCONF_ERROR; + } else { + func_ret = VCONF_OK; + break; + } + } while(err_retry--); + + INFO("vconf_unset success : %s", in_key); + + END_TIME_CHECK + + return func_ret; +} + +/* + * This function unset given key recursively + * @param[in] in_dir Directory name for removing + * @return 0 on success, -1 on error + */ +API int vconf_unset_recursive(const char *in_dir) +{ + START_TIME_CHECK + + DIR *dir = NULL; + struct dirent entry; + struct dirent *result = NULL; + char fullpath[KEY_PATH] = {0,}; + char dirpath[KEY_PATH] = {0,}; + char err_buf[ERR_LEN] = {0,}; + int rc = 0; + int func_ret = 0; + int ret = 0; + + retvm_if(in_dir == NULL, VCONF_ERROR, "Invalid argument: dir path is null"); + + ret = _vconf_get_key_path(in_dir, dirpath); + retvm_if(ret != VCONF_OK, VCONF_ERROR, "Invalid argument: key is not valid"); + + if((dir=opendir(dirpath)) == NULL) { + strerror_r(errno, err_buf, ERR_LEN); + ERR("ERROR : open directory(%s) fail(%s)", in_dir, err_buf); + return VCONF_ERROR; + } + + if((readdir_r(dir, &entry, &result)) != 0) { + strerror_r(errno, err_buf, ERR_LEN); + ERR("ERROR : read directory(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } + + while(result != NULL) + { + if(( strcmp( entry.d_name, ".") == 0 ) || ( strcmp( entry.d_name, "..") == 0 )) { + goto NEXT; + } + + snprintf(fullpath,KEY_PATH, "%s/%s", dirpath, entry.d_name); + + ret = _vconf_path_is_dir(fullpath); + if(ret != VCONF_ERROR) { + if(ret == 1) { + rc = vconf_unset_recursive(fullpath); + if(rc == VCONF_ERROR) + func_ret = VCONF_ERROR; + } + + rc = remove(fullpath); + if(rc == -1) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } + } else { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } +NEXT: + if((readdir_r(dir, &entry, &result)) != 0) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : read directory(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } + } + + if((closedir(dir)) != 0) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : close directory(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } +#if 0 + if(func_ret == VCONF_OK) { + if((remove(in_dir)) == -1) { + memset(err_buf, 0x00, sizeof(err_buf)); + strerror_r(errno, err_buf, sizeof(err_buf)); + ERR("ERROR : remove path(%s) fail(%s)", in_dir, err_buf); + func_ret = VCONF_ERROR; + } + } +#endif + + return func_ret; +} + +API int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, void *user_data) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + retvm_if(cb == NULL, VCONF_ERROR, "Invalid argument: cb(%p)", cb); + + if (_vconf_kdb_add_notify(in_key, cb, user_data)) { + ERR("vconf_notify_key_changed : key(%s) add notify fail", in_key); + return VCONF_ERROR; + } + + INFO("vconf_notify_key_changed : %s noti is added", in_key); + + END_TIME_CHECK + + return VCONF_OK; +} + +API int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb) +{ + START_TIME_CHECK + + retvm_if(in_key == NULL, VCONF_ERROR, "Invalid argument: key is null"); + retvm_if(cb == NULL, VCONF_ERROR, "Invalid argument: cb(%p)", cb); + + if (_vconf_kdb_del_notify(in_key, cb)) { + ERR("vconf_ignore_key_changed() failed: key(%s)", in_key); + return VCONF_ERROR; + } + + INFO("vconf_ignore_key_changed : %s noti removed", in_key); + + END_TIME_CHECK + + return VCONF_OK; +} + +API mode_t vconf_set_permission(mode_t mode) +{ + /* TODO: implement! */ + return mode; +} + +API int vconf_set_key_permission(const char *in_key, const mode_t mode) +{ + /* TODO: implement! */ + return 0; +} + diff --git a/vconf.manifest b/vconf.manifest new file mode 100755 index 0000000..97e8c31 --- /dev/null +++ b/vconf.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/vconf.pc.in b/vconf.pc.in new file mode 100644 index 0000000..22f5f83 --- /dev/null +++ b/vconf.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: vconf +Description: configuration system library +Version: @VERSION@ +Requires: glib-2.0 +Libs: -L${libdir} -lvconf +Cflags: -I${includedir} diff --git a/vconftool.c b/vconftool.c new file mode 100755 index 0000000..f39df57 --- /dev/null +++ b/vconftool.c @@ -0,0 +1,531 @@ +/* + * libslp-setting + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Hakjoo Ko <hakjoo.ko@samsung.com> + * + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <vconf.h> +#include <glib-object.h> +#include "vconf-log.h" + +#include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <errno.h> + +#include <wordexp.h> + +enum { + VCONFTOOL_TYPE_NO = 0x00, + VCONFTOOL_TYPE_STRING, + VCONFTOOL_TYPE_INT, + VCONFTOOL_TYPE_DOUBLE, + VCONFTOOL_TYPE_BOOL +}; + +#define BUFSIZE 1024 + +const char *BACKEND_DB_PREFIX = "db/"; +const char *BACKEND_FILE_PREFIX = "file/"; +const char *BACKEND_MEMORY_PREFIX = "memory/"; + +const char *DB_PREFIX = "/opt/var/kdb"; +const char *FILE_PREFIX = "/opt/var/kdb"; +const char *MEMORY_PREFIX = "/var/run"; +const char *MEMORY_INIT = "/opt/var/kdb/memory_init"; + +static char *guid = NULL; +static char *uid = NULL; +static char *vconf_type = NULL; +static int is_recursive = FALSE; +static int is_initialization = FALSE; +static int is_forced = FALSE; +static int get_num = 0; + +static GOptionEntry entries[] = { + {"type", 't', 0, G_OPTION_ARG_STRING, &vconf_type, "type of value", + "int|bool|double|string"}, + {"recursive", 'r', 0, G_OPTION_ARG_NONE, &is_recursive, + "retrieve keys recursively", NULL}, + {"guid", 'g', 0, G_OPTION_ARG_STRING, &guid, "group permission", NULL}, + {"uid", 'u', 0, G_OPTION_ARG_STRING, &uid, "user permission", NULL}, + {"initialization", 'i', 0, G_OPTION_ARG_NONE, &is_initialization, + "memory backend initialization", NULL}, + {"force", 'f', 0, G_OPTION_ARG_NONE, &is_forced, + "overwrite vconf values by force", NULL}, + {NULL} +}; + +static void get_operation(char *input); +static void recursive_get(char *subDIR, int level); +static void print_keylist(keylist_t *keylist, keynode_t *temp_node, int level); + +static void print_help(const char *cmd) +{ + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "[Set vconf value]\n"); + fprintf(stderr, + " %s set -t <TYPE> <KEY NAME> <VALUE> <OPTIONS>\n", cmd); + fprintf(stderr, " <TYPE>=int|bool|double|string\n"); + fprintf(stderr, "\n"); + fprintf(stderr, + " Ex) %s set -t string db/testapp/key1 \"This is test\" \n", + cmd); + fprintf(stderr, "\n"); + fprintf(stderr, " <OPTIONS>\n"); + fprintf(stderr, + " -g <GUID> : Set Effective group id. The key's permission will be set to 0664.\n"); + fprintf(stderr, + " Ex) %s set -t string db/testapp/key1 \"This is test\" -g 425\n", + cmd); + fprintf(stderr, + " NOTE: -g and -u cannot be userd together. -u ignores -g option.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, + " -u <UID> : Set Effective user id. The key's permission will be set to 0644.\n"); + fprintf(stderr, + " Ex) %s set -t string db/testapp/key1 \"This is test\" -u 5000\n", + cmd); + fprintf(stderr, + " NOTE: -g and -u cannot be userd together. -u ignores -g option.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, + " -i : Install memory backend key into flash space for backup.\n"); + fprintf(stderr, + " Ex) %s set -t string db/testapp/key1 \"This is test\" -i\n", + cmd); + fprintf(stderr, "\n"); + fprintf(stderr, + " -f : Overwrite values by force, even when vconf values are already exist.\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "[Get vconf value]\n"); + fprintf(stderr, " %s get <OPTIONS> <KEY NAME>\n", cmd); + fprintf(stderr, "\n"); + fprintf(stderr, " <OPTIONS>\n"); + fprintf(stderr, + " -r : retrieve all keys included in sub-directorys \n"); + fprintf(stderr, " Ex) %s get db/testapp/key1\n", cmd); + fprintf(stderr, " %s get db/testapp/\n", cmd); + fprintf(stderr, "\n"); + fprintf(stderr, "[Unset vconf value]\n"); + fprintf(stderr, " %s unset <KEY NAME>\n", cmd); + fprintf(stderr, "\n"); + fprintf(stderr, " Ex) %s unset db/testapp/key1\n", cmd); + fprintf(stderr, "\n"); +} + +static int check_type(void) +{ + if (vconf_type) { + if (!strncasecmp(vconf_type, "int", 3)) + return VCONFTOOL_TYPE_INT; + else if (!strncasecmp(vconf_type, "string", 6)) + return VCONFTOOL_TYPE_STRING; + else if (!strncasecmp(vconf_type, "double", 6)) + return VCONFTOOL_TYPE_DOUBLE; + else if (!strncasecmp(vconf_type, "bool", 4)) + return VCONFTOOL_TYPE_BOOL; + } + return VCONFTOOL_TYPE_NO; +} + +static int __system(char * cmd) +{ + int status; + pid_t cpid; + + if((cpid = fork()) < 0) { + perror("fork"); + return -1; + } + + if (cpid == 0) { + /* child */ + wordexp_t p; + char **w; + + wordexp(cmd, &p, 0); + w = p.we_wordv; + + execv(w[0], (char *const *)w); + + wordfree(&p); + + _exit(-1); + } else { + /* parent */ + if (waitpid(cpid, &status, 0) == -1) { + perror("waitpid failed"); + return -1; + } + if (WIFSIGNALED(status)) { + printf("signal(%d)\n", WTERMSIG(status)); + perror("exit by signal"); + return -1; + } + if (!WIFEXITED(status)) { + perror("exit abnormally"); + return -1; + } + if (WIFEXITED(status) && WEXITSTATUS(status)) { + perror("child return error"); + return -1; + } + } + + return 0; +} + +static void disable_invalid_char(char* src) +{ + char* tmp; + + for(tmp = src; *tmp; ++tmp) + { + if( (*tmp == ';') || (*tmp == '|') ) + { + fprintf(stderr,"invalid char is found\n"); + *tmp = '_'; + } + } +} + +static int check_file_path_mode(char* file_path) +{ + char szCmd[BUFSIZE] = {0,}; + int create_file = 0; + int set_id = 0; + int fd; + + if (guid || uid) { + if (getuid() != 0) { + fprintf(stderr, + "Error!\t Only root user can use '-g or -u' option\n"); + return -1; + } + + set_id = 1; + } + + /* Check file path */ + if (access(file_path, F_OK) != 0) { + /* fprintf(stderr,"key does not exist\n"); */ + + char szPath[BUFSIZE] = { 0, }; + char *pCh = strrchr(file_path, '/'); + strncat(szPath, file_path, pCh - file_path); + /* fprintf(stderr, "szPath : %s\n", szPath); */ + + /* Check directory & create it */ + if (access(szPath, F_OK) != 0) { + /* fprintf(stderr,"parent dir does not exist\n"); */ + + snprintf(szCmd, BUFSIZE, "/bin/mkdir %s -p --mode=755", szPath); + disable_invalid_char(szCmd); + if (__system(szCmd)) { + fprintf(stderr,"Fail mkdir() szCmd=%s\n", __FILE__, __LINE__, szCmd); + return -1; + } + + } + + create_file = 1; + } else if (!is_forced) { + fprintf(stderr, "Key already exist. Use -f option to force update\n"); + return -1; + } + + if(create_file) { + /* Create file */ + mode_t temp; + temp = umask(0000); + fd = open(file_path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); + umask(temp); + if(fd == -1) { + fprintf(stderr, "open(rdwr,create) error\n"); + return -1; + } + close(fd); + } + + if(set_id) { + if((fd = open(file_path, O_RDONLY)) == -1) { + fprintf(stderr, "open(rdonly) error\n"); + return -1; + } + + if(uid) { + if (fchown(fd, atoi(uid), atoi(uid)) == -1) { + fprintf(stderr, "Error!\t Fail to fchown(%d)\n", errno); + close(fd); + return -1; + } + } else if (guid) { + if (-1 == fchown(fd, 0, atoi(guid))) { + fprintf(stderr, "Error!\t Fail to fchown()\n"); + close(fd); + return -1; + } + } + + close(fd); + } + + return 0; +} + +static int copy_memory_key(char *pszKey, char *pszOrigin) +{ + char szCmd[BUFSIZE] = { 0, }; + char szPath[BUFSIZE] = { 0, }; + char szFileName[BUFSIZE] = { 0, }; + char *pCh = strrchr(pszKey, '/'); + int nLen = strlen(pszKey); + + /* Get directory path and file name */ + snprintf(szPath, BUFSIZE, "%s/", MEMORY_INIT); + strncat(szPath, pszKey, pCh - pszKey); + strncpy(szFileName, pszKey + (pCh - pszKey) + 1, nLen - (pCh - pszKey)); + + /* Check directory & create it */ + if (0 != access(szPath, F_OK)) { + snprintf(szCmd, BUFSIZE, "mkdir %s -p --mode=755", szPath); + if (system(szCmd)) { + printf("[%s:%d]Fail mkdir() szCmd=%s\n", __FILE__, + __LINE__, szCmd); + return -1; + } + } + /* copy */ + strncat(szPath, "/", 1); + strncat(szPath, szFileName, strlen(szFileName)); + memset(szCmd, 0x00, BUFSIZE); + snprintf(szCmd, BUFSIZE, "cp %s %s -r -p", pszOrigin, szPath); + if (system(szCmd)) { + printf("[%s:%d]Fail copy\n", __FILE__, __LINE__); + return -1; + } + return 0; +} + +static int make_file_path(char *pszKey, char *pszBuf) +{ + if (0 == + strncmp(pszKey, BACKEND_DB_PREFIX, sizeof(BACKEND_DB_PREFIX) - 1)) { + snprintf(pszBuf, BUFSIZE, "%s/%s", DB_PREFIX, pszKey); + return 0; + } else if (0 == + strncmp(pszKey, BACKEND_FILE_PREFIX, + sizeof(BACKEND_FILE_PREFIX) - 1)) { + snprintf(pszBuf, BUFSIZE, "%s/%s", FILE_PREFIX, pszKey); + return 0; + } else if (0 == + strncmp(pszKey, BACKEND_MEMORY_PREFIX, + sizeof(BACKEND_MEMORY_PREFIX) - 1)) { + snprintf(pszBuf, BUFSIZE, "%s/%s", MEMORY_PREFIX, pszKey); + return 0; + } + return -1; +} + +int main(int argc, char **argv) +{ + int set_type; + char szFilePath[BUFSIZE] = { 0, }; + int fd; + int group_id; + int user_id; + char *psz_key = NULL; + + GError *error = NULL; + GOptionContext *context; + + g_type_init(); + context = g_option_context_new("- vconf library tool"); + g_option_context_add_main_entries(context, entries, NULL); + g_option_context_set_help_enabled(context, FALSE); + g_option_context_set_ignore_unknown_options(context, TRUE); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed: %s\n", error->message); + exit(1); + } + + if (argc < 2) { + print_help(argv[0]); + return 1; + } + + if (!strncmp(argv[1], "set", 3)) { + set_type = check_type(); + if (argc < 4 || !set_type) { + print_help(argv[0]); + return 1; + } + + if (make_file_path(argv[2], szFilePath)) { + fprintf(stderr, "Error!\t Bad prefix\n"); + return -1; + } + + if (check_file_path_mode(szFilePath)) { + fprintf(stderr, "Error!\t create key %s\n", argv[2]); + return -1; + } + + switch (set_type) { + case VCONFTOOL_TYPE_STRING: + vconf_set_str(argv[2], argv[3]); + break; + case VCONFTOOL_TYPE_INT: + vconf_set_int(argv[2], atoi(argv[3])); + break; + case VCONFTOOL_TYPE_DOUBLE: + vconf_set_dbl(argv[2], atof(argv[3])); + break; + case VCONFTOOL_TYPE_BOOL: + vconf_set_bool(argv[2], !!atoi(argv[3])); + break; + default: + fprintf(stderr, "never reach"); + exit(1); + } + + psz_key = argv[2]; + /* Install memory backend key into flash space *******/ + if (is_initialization) { + copy_memory_key(psz_key, szFilePath); + } + /* End memory backend key into flash space ***********/ + + } else if (!strncmp(argv[1], "get", 3)) { + if (argv[2]) + get_operation(argv[2]); + else + print_help(argv[0]); + } else if (!strncmp(argv[1], "unset", 5)) { + if (argv[2]) + vconf_unset(argv[2]); + else + print_help(argv[0]); + } else + fprintf(stderr, "%s is a invalid command\n", argv[1]); + return 0; +} + +static void get_operation(char *input) +{ + keylist_t *get_keylist; + keynode_t *temp_node; + char *test; + + get_keylist = vconf_keylist_new(); + /* ParentDIR parameter of gconf_client_all_entries + can not include the last slash. */ + if ('/' == input[strlen(input) - 1] && strlen(input) > 8) + input[strlen(input) - 1] = '\0'; + + vconf_get(get_keylist, input, VCONF_GET_ALL); + if (!(temp_node = vconf_keylist_nextnode(get_keylist))) { + test = strrchr(input, '/'); + if (NULL != test) { + vconf_keylist_add_null(get_keylist, input); + if (test - input < 7) + *(test + 1) = '\0'; + else + *test = '\0'; + vconf_get(get_keylist, input, VCONF_GET_KEY); + temp_node = vconf_keylist_nextnode(get_keylist); + } else { + fprintf(stderr, "Include at least one slash\"/\"\n"); + vconf_keylist_free(get_keylist); + return; + } + } + get_num = 0; + print_keylist(get_keylist, temp_node, 0); + + if (!get_num) + printf("No data\n"); + vconf_keylist_free(get_keylist); +} + +static void recursive_get(char *subDIR, int level) +{ + printf("%s", subDIR); + + keylist_t *get_keylist; + keynode_t *first_node; + + get_keylist = vconf_keylist_new(); + vconf_get(get_keylist, subDIR, VCONF_GET_ALL); + + if ((first_node = vconf_keylist_nextnode(get_keylist))) { + print_keylist(get_keylist, first_node, level); + } + vconf_keylist_free(get_keylist); +} + +static void print_keylist(keylist_t *keylist, keynode_t *temp_node, int level) +{ + do { + switch (vconf_keynode_get_type(temp_node)) + { + case VCONF_TYPE_INT: + printf("%s, value = %d (int)\n", + vconf_keynode_get_name(temp_node), + vconf_keynode_get_int(temp_node)); + get_num++; + break; + case VCONF_TYPE_BOOL: + printf("%s, value = %d (bool)\n", + vconf_keynode_get_name(temp_node), + vconf_keynode_get_bool(temp_node)); + get_num++; + break; + case VCONF_TYPE_DOUBLE: + printf("%s, value = %f (double)\n", + vconf_keynode_get_name(temp_node), + vconf_keynode_get_dbl(temp_node)); + get_num++; + break; + case VCONF_TYPE_STRING: + printf("%s, value = %s (string)\n", + vconf_keynode_get_name(temp_node), + vconf_keynode_get_str(temp_node)); + get_num++; + break; + case VCONF_TYPE_DIR: + printf("%s(Directory)\n", + vconf_keynode_get_name(temp_node)); + if (is_recursive) + recursive_get(vconf_keynode_get_name(temp_node), + level + 1); + break; + default: + /* fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(temp_node)); */ + break; + } + } while ((temp_node = vconf_keylist_nextnode(keylist))); +} |