[cleanup]revise file location, name and so on 08/239808/1
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 30 Jul 2020 04:50:39 +0000 (13:50 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 30 Jul 2020 04:50:39 +0000 (13:50 +0900)
Change-Id: Ibb07ff6f809495437edf3b2658cbe2d27859018b

24 files changed:
AUTHORS [deleted file]
CMakeLists.txt
LICENSE [deleted file]
LICENSE.APLv2 [new file with mode: 0644]
collation.c [deleted file]
include/db-util-debug.h [deleted file]
packaging/libslp-db-util-devel.manifest [deleted file]
packaging/libslp-db-util.changes [deleted file]
packaging/libslp-db-util.spec [changed mode: 0755->0644]
src/collation.c [new file with mode: 0644]
src/db-util-debug.h [new file with mode: 0644]
src/util-func.c [new file with mode: 0644]
tests/CMakeLists.txt [new file with mode: 0644]
tests/db-util-gtest.cpp [new file with mode: 0644]
tests/run_coverage.sh [new file with mode: 0755]
tests/test-collation-db.sh [new file with mode: 0755]
tests/vconf.c [new file with mode: 0644]
unittest/CMakeLists.txt [deleted file]
unittest/db-util_gtest.cpp [deleted file]
unittest/run_coverage.sh [deleted file]
unittest/test_collation_db.sh [deleted file]
unittest/vconf.c [deleted file]
unittest/vconf.sym [deleted file]
util_func.c [deleted file]

diff --git a/AUTHORS b/AUTHORS
deleted file mode 100644 (file)
index 058627b..0000000
--- a/AUTHORS
+++ /dev/null
@@ -1,3 +0,0 @@
-Hakjoo Ko <hakjoo.ko@samsung.com>\r
-Hyungdeuk Kim <hd3.kim@samsung.com>\r
-\r
index 114179a01c85546fbb91959d51e59a56f8c16b03..68be338d9d39ebc014789cc7bae4361d6611dd9d 100644 (file)
@@ -7,7 +7,7 @@ SET(INCLUDEDIR "\${prefix}/include/db-util")
 SET(VERSION_MAJOR 0)
 SET(VERSION  "${VERSION_MAJOR}.1.0")
 
-SET(SRCS util_func.c collation.c)
+SET(SRCS src/util-func.c src/collation.c)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
@@ -51,5 +51,5 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/util-func.h DESTINATION includ
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/collation.h DESTINATION include/db-util)
 
 IF( DEFINED GCOV )
-ADD_SUBDIRECTORY(unittest)
+ADD_SUBDIRECTORY(tests)
 ENDIF()
diff --git a/LICENSE b/LICENSE
deleted file mode 100644 (file)
index 9c13a9b..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,204 +0,0 @@
-Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
-\r
-                                 Apache License\r
-                           Version 2.0, January 2004\r
-                        http://www.apache.org/licenses/\r
-\r
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
-\r
-   1. Definitions.\r
-\r
-      "License" shall mean the terms and conditions for use, reproduction,\r
-      and distribution as defined by Sections 1 through 9 of this document.\r
-\r
-      "Licensor" shall mean the copyright owner or entity authorized by\r
-      the copyright owner that is granting the License.\r
-\r
-      "Legal Entity" shall mean the union of the acting entity and all\r
-      other entities that control, are controlled by, or are under common\r
-      control with that entity. For the purposes of this definition,\r
-      "control" means (i) the power, direct or indirect, to cause the\r
-      direction or management of such entity, whether by contract or\r
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
-      outstanding shares, or (iii) beneficial ownership of such entity.\r
-\r
-      "You" (or "Your") shall mean an individual or Legal Entity\r
-      exercising permissions granted by this License.\r
-\r
-      "Source" form shall mean the preferred form for making modifications,\r
-      including but not limited to software source code, documentation\r
-      source, and configuration files.\r
-\r
-      "Object" form shall mean any form resulting from mechanical\r
-      transformation or translation of a Source form, including but\r
-      not limited to compiled object code, generated documentation,\r
-      and conversions to other media types.\r
-\r
-      "Work" shall mean the work of authorship, whether in Source or\r
-      Object form, made available under the License, as indicated by a\r
-      copyright notice that is included in or attached to the work\r
-      (an example is provided in the Appendix below).\r
-\r
-      "Derivative Works" shall mean any work, whether in Source or Object\r
-      form, that is based on (or derived from) the Work and for which the\r
-      editorial revisions, annotations, elaborations, or other modifications\r
-      represent, as a whole, an original work of authorship. For the purposes\r
-      of this License, Derivative Works shall not include works that remain\r
-      separable from, or merely link (or bind by name) to the interfaces of,\r
-      the Work and Derivative Works thereof.\r
-\r
-      "Contribution" shall mean any work of authorship, including\r
-      the original version of the Work and any modifications or additions\r
-      to that Work or Derivative Works thereof, that is intentionally\r
-      submitted to Licensor for inclusion in the Work by the copyright owner\r
-      or by an individual or Legal Entity authorized to submit on behalf of\r
-      the copyright owner. For the purposes of this definition, "submitted"\r
-      means any form of electronic, verbal, or written communication sent\r
-      to the Licensor or its representatives, including but not limited to\r
-      communication on electronic mailing lists, source code control systems,\r
-      and issue tracking systems that are managed by, or on behalf of, the\r
-      Licensor for the purpose of discussing and improving the Work, but\r
-      excluding communication that is conspicuously marked or otherwise\r
-      designated in writing by the copyright owner as "Not a Contribution."\r
-\r
-      "Contributor" shall mean Licensor and any individual or Legal Entity\r
-      on behalf of whom a Contribution has been received by Licensor and\r
-      subsequently incorporated within the Work.\r
-\r
-   2. Grant of Copyright License. Subject to the terms and conditions of\r
-      this License, each Contributor hereby grants to You a perpetual,\r
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
-      copyright license to reproduce, prepare Derivative Works of,\r
-      publicly display, publicly perform, sublicense, and distribute the\r
-      Work and such Derivative Works in Source or Object form.\r
-\r
-   3. Grant of Patent License. Subject to the terms and conditions of\r
-      this License, each Contributor hereby grants to You a perpetual,\r
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
-      (except as stated in this section) patent license to make, have made,\r
-      use, offer to sell, sell, import, and otherwise transfer the Work,\r
-      where such license applies only to those patent claims licensable\r
-      by such Contributor that are necessarily infringed by their\r
-      Contribution(s) alone or by combination of their Contribution(s)\r
-      with the Work to which such Contribution(s) was submitted. If You\r
-      institute patent litigation against any entity (including a\r
-      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
-      or a Contribution incorporated within the Work constitutes direct\r
-      or contributory patent infringement, then any patent licenses\r
-      granted to You under this License for that Work shall terminate\r
-      as of the date such litigation is filed.\r
-\r
-   4. Redistribution. You may reproduce and distribute copies of the\r
-      Work or Derivative Works thereof in any medium, with or without\r
-      modifications, and in Source or Object form, provided that You\r
-      meet the following conditions:\r
-\r
-      (a) You must give any other recipients of the Work or\r
-          Derivative Works a copy of this License; and\r
-\r
-      (b) You must cause any modified files to carry prominent notices\r
-          stating that You changed the files; and\r
-\r
-      (c) You must retain, in the Source form of any Derivative Works\r
-          that You distribute, all copyright, patent, trademark, and\r
-          attribution notices from the Source form of the Work,\r
-          excluding those notices that do not pertain to any part of\r
-          the Derivative Works; and\r
-\r
-      (d) If the Work includes a "NOTICE" text file as part of its\r
-          distribution, then any Derivative Works that You distribute must\r
-          include a readable copy of the attribution notices contained\r
-          within such NOTICE file, excluding those notices that do not\r
-          pertain to any part of the Derivative Works, in at least one\r
-          of the following places: within a NOTICE text file distributed\r
-          as part of the Derivative Works; within the Source form or\r
-          documentation, if provided along with the Derivative Works; or,\r
-          within a display generated by the Derivative Works, if and\r
-          wherever such third-party notices normally appear. The contents\r
-          of the NOTICE file are for informational purposes only and\r
-          do not modify the License. You may add Your own attribution\r
-          notices within Derivative Works that You distribute, alongside\r
-          or as an addendum to the NOTICE text from the Work, provided\r
-          that such additional attribution notices cannot be construed\r
-          as modifying the License.\r
-\r
-      You may add Your own copyright statement to Your modifications and\r
-      may provide additional or different license terms and conditions\r
-      for use, reproduction, or distribution of Your modifications, or\r
-      for any such Derivative Works as a whole, provided Your use,\r
-      reproduction, and distribution of the Work otherwise complies with\r
-      the conditions stated in this License.\r
-\r
-   5. Submission of Contributions. Unless You explicitly state otherwise,\r
-      any Contribution intentionally submitted for inclusion in the Work\r
-      by You to the Licensor shall be under the terms and conditions of\r
-      this License, without any additional terms or conditions.\r
-      Notwithstanding the above, nothing herein shall supersede or modify\r
-      the terms of any separate license agreement you may have executed\r
-      with Licensor regarding such Contributions.\r
-\r
-   6. Trademarks. This License does not grant permission to use the trade\r
-      names, trademarks, service marks, or product names of the Licensor,\r
-      except as required for reasonable and customary use in describing the\r
-      origin of the Work and reproducing the content of the NOTICE file.\r
-\r
-   7. Disclaimer of Warranty. Unless required by applicable law or\r
-      agreed to in writing, Licensor provides the Work (and each\r
-      Contributor provides its Contributions) on an "AS IS" BASIS,\r
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
-      implied, including, without limitation, any warranties or conditions\r
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
-      PARTICULAR PURPOSE. You are solely responsible for determining the\r
-      appropriateness of using or redistributing the Work and assume any\r
-      risks associated with Your exercise of permissions under this License.\r
-\r
-   8. Limitation of Liability. In no event and under no legal theory,\r
-      whether in tort (including negligence), contract, or otherwise,\r
-      unless required by applicable law (such as deliberate and grossly\r
-      negligent acts) or agreed to in writing, shall any Contributor be\r
-      liable to You for damages, including any direct, indirect, special,\r
-      incidental, or consequential damages of any character arising as a\r
-      result of this License or out of the use or inability to use the\r
-      Work (including but not limited to damages for loss of goodwill,\r
-      work stoppage, computer failure or malfunction, or any and all\r
-      other commercial damages or losses), even if such Contributor\r
-      has been advised of the possibility of such damages.\r
-\r
-   9. Accepting Warranty or Additional Liability. While redistributing\r
-      the Work or Derivative Works thereof, You may choose to offer,\r
-      and charge a fee for, acceptance of support, warranty, indemnity,\r
-      or other liability obligations and/or rights consistent with this\r
-      License. However, in accepting such obligations, You may act only\r
-      on Your own behalf and on Your sole responsibility, not on behalf\r
-      of any other Contributor, and only if You agree to indemnify,\r
-      defend, and hold each Contributor harmless for any liability\r
-      incurred by, or claims asserted against, such Contributor by reason\r
-      of your accepting any such warranty or additional liability.\r
-\r
-   END OF TERMS AND CONDITIONS\r
-\r
-   APPENDIX: How to apply the Apache License to your work.\r
-\r
-      To apply the Apache License to your work, attach the following\r
-      boilerplate notice, with the fields enclosed by brackets "[]"\r
-      replaced with your own identifying information. (Don't include\r
-      the brackets!)  The text should be enclosed in the appropriate\r
-      comment syntax for the file format. We also recommend that a\r
-      file or class name and description of purpose be included on the\r
-      same "printed page" as the copyright notice for easier\r
-      identification within third-party archives.\r
-\r
-   Copyright [yyyy] [name of copyright owner]\r
-\r
-   Licensed under the Apache License, Version 2.0 (the "License");\r
-   you may not use this file except in compliance with the License.\r
-   You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-\r
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..247c97d
--- /dev/null
@@ -0,0 +1,203 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 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.
diff --git a/collation.c b/collation.c
deleted file mode 100644 (file)
index e1e966b..0000000
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- * libslp-db-util
- *
- * 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 <string.h>
-#include <math.h>
-#include <wchar.h>
-#include <wctype.h>
-
-#include <unistd.h>
-#include <glib.h>
-
-#include <dlfcn.h>
-
-#include <unicode/utypes.h>
-#include <unicode/ucol.h>
-#include <unicode/uiter.h>
-#include <unicode/ustring.h>
-
-#include "collation.h"
-
-#include "db-util-debug.h"
-#include <vconf.h>
-
-#define DB_UTIL_RETV_IF(cond, ret) \
-                       do { \
-                               if (cond) { \
-                                       DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
-                                       return ret; \
-                               } \
-                       } while (0)
-
-#define DB_UTIL_RET_IF(cond) \
-                       do { \
-                               if (cond) { \
-                                       DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
-                                       return; \
-                               } \
-                       } while (0)
-
-#define DB_UTIL_ERR_COL_FUNC_RET DB_UTIL_ERROR
-
-#ifdef DB_UTIL_ARCH_64
-#define ICUI18N_LIBPATH "/usr/lib64/libicui18n.so"
-#else
-#define ICUI18N_LIBPATH "/usr/lib/libicui18n.so"
-#endif
-
-enum {
-       DB_UTIL_ERR_DLOPEN = -10,
-       DB_UTIL_ERR_DLSYM,
-       DB_UTIL_ERR_ENV,
-       DB_UTIL_ERR_ICU,
-       DB_UTIL_ERR_PARAM
-};
-
-enum {
-       DB_UTIL_CMP_SC,
-       /* Loop comparison */
-       DB_UTIL_CMP_LC
-};
-
-#define ICU_FUNC_CNT 8
-
-typedef UCollator *(*ICU_UCOL_OPEN)(const char *, UErrorCode *);
-typedef void (*ICU_UCOL_CLOSE)(UCollator *);
-typedef void (*ICU_UCOL_SETSTRENGTH)(UCollator *, UCollationStrength);
-typedef UCollationResult (*ICU_UCOL_STRCOLL)(const UCollator *, const UChar *, int32_t, const UChar *, int32_t);
-typedef UCollationResult (*ICU_UCOL_STRCOLLITER)(const UCollator *, UCharIterator *, UCharIterator *, UErrorCode *);
-typedef void (*ICU_UITER_SETUTF8)(UCharIterator *, const char *, int32_t);
-typedef void (*ICU_ULOC_SETDEFAULT)(const char* localeID, UErrorCode* status);
-typedef const char* (*ICU_ULOC_GETDEFAULT)(void);
-
-typedef struct {
-       ICU_UCOL_OPEN icu_ucol_open;
-       ICU_UCOL_CLOSE icu_ucol_close;
-       ICU_UCOL_STRCOLL icu_ucol_strcoll;
-       ICU_UCOL_STRCOLLITER icu_ucol_strcollIter;
-       ICU_UCOL_SETSTRENGTH icu_ucol_setStrength;
-       ICU_UITER_SETUTF8 icu_uiter_setUTF8;
-       ICU_ULOC_SETDEFAULT icu_uloc_setDefault;
-       ICU_ULOC_GETDEFAULT icu_uloc_getDefault;
-} db_util_icu_func_t;
-
-db_util_icu_func_t icu_symbol;
-
-void *g_dl_icu_handle = NULL;
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-static char *strtoutf8(const UChar * unichars, int len);
-#endif
-
-static int __db_util_dl_load_icu()
-{
-       void *handle = NULL;
-       void *icu_handle[ICU_FUNC_CNT] = { 0 };
-       char *dl_error;
-       int i = 0;
-
-       const char *ICU_API[] = {
-               "ucol_open",
-               "ucol_close",
-               "ucol_strcoll",
-               "ucol_strcollIter",
-               "ucol_setStrength",
-               "uiter_setUTF8",
-               "uloc_setDefault",
-               "uloc_getDefault"
-       };
-
-       if (g_dl_icu_handle == NULL) {
-               g_dl_icu_handle = dlopen(ICUI18N_LIBPATH, RTLD_LAZY | RTLD_GLOBAL);
-               if (g_dl_icu_handle == NULL) {
-                       DB_UTIL_TRACE_WARNING("dlopen icu so fail");
-                       return DB_UTIL_ERR_DLOPEN;
-               }
-       }
-
-       for (i = 0; i < ICU_FUNC_CNT; i++) {
-               handle = dlsym(g_dl_icu_handle, ICU_API[i]);
-               if ((dl_error = dlerror()) != NULL)  {
-                       DB_UTIL_TRACE_WARNING("dlsym(%s) is failed for %s",
-                                                               dl_error, ICU_API[i]);
-                       return DB_UTIL_ERR_DLSYM;
-               }
-               icu_handle[i] = handle;
-       }
-
-       memcpy((void*)&icu_symbol, (const void*)icu_handle, sizeof(icu_handle));
-
-       return DB_UTIL_OK;
-}
-
-/* The collating function must return an integer that is negative, zero or positive */
-static int __db_util_collate_icu_16(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
-{
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_16 func start \n");
-
-       UChar* tmp_v1 = (UChar *)str1;
-       UChar* tmp_v2 = (UChar *)str2;
-       char* utf8_v1 = strtoutf8(tmp_v1, str1_len);
-       char* utf8_v2 = strtoutf8(tmp_v2, str2_len);
-
-       DB_UTIL_TRACE_DEBUG("v1(%d) : %s\n", str1_len, utf8_v1);
-       DB_UTIL_TRACE_DEBUG("v2(%d) : %s\n", str2_len, utf8_v2);
-#endif
-
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcoll == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-
-       UCollationResult result = icu_symbol.icu_ucol_strcoll(
-                                                               (UCollator *) ucol,
-                                                               (const UChar *) str1, str1_len,
-                                                               (const UChar *) str2, str2_len);
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       if (utf8_v1)
-               free(utf8_v1);
-       if (utf8_v2)
-               free(utf8_v2);
-
-       if (result == UCOL_LESS) {
-               DB_UTIL_TRACE_DEBUG("less \n");
-       } else if (result == UCOL_GREATER) {
-               DB_UTIL_TRACE_DEBUG("greater \n");
-       } else {
-               DB_UTIL_TRACE_DEBUG("equal \n");
-       }
-#endif
-
-       return result;
-}
-
-/* The collating function must return an integer that is negative, zero or positive */
-static int __db_util_collate_icu_16_lc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
-{
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_16_lc func start \n");
-
-       UChar* tmp_v1 = (UChar *)str1;
-       UChar* tmp_v2 = (UChar *)str2;
-
-       char* utf8_v1 = strtoutf8(tmp_v1, str1_len);
-       char* utf8_v2 = strtoutf8(tmp_v2, str2_len);
-
-       DB_UTIL_TRACE_DEBUG("v1(%d) : %s\n", str1_len, utf8_v1);
-       DB_UTIL_TRACE_DEBUG("v2(%d) : %s\n", str2_len, utf8_v2);
-
-       if (utf8_v1)
-               free(utf8_v1);
-       if (utf8_v2)
-               free(utf8_v2);
-#endif
-
-       UCollationResult result = 0;
-
-       UChar* str_to = (UChar *)str1;
-       UChar* str_from = (UChar *)str1;
-
-       int i;
-
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcoll == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-
-       if (str1_len > str2_len) {
-               for (i = 0; i < str2_len; i = i+2) {
-                       str_to++;
-               }
-
-               while ((int)(str_to-(UChar*)str1) <= str1_len) {
-                       result = icu_symbol.icu_ucol_strcoll(
-                                               (UCollator *) ucol,
-                                               (UChar *) str_from, str_to-str_from,
-                                               (const UChar *) str2, str2_len);
-
-                       if (result == UCOL_EQUAL) {
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-                               DB_UTIL_TRACE_DEBUG("equal \n");
-#endif
-                               return UCOL_EQUAL;
-                       }
-
-                       str_to++;
-                       str_from++;
-               }
-       } else {
-               result = icu_symbol.icu_ucol_strcoll(
-                                       (UCollator *) ucol,
-                                       (const UChar *) str1, str1_len,
-                                       (const UChar *) str2, str2_len);
-       }
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       if (result == UCOL_LESS) {
-               DB_UTIL_TRACE_DEBUG("less \n");
-       } else if (result == UCOL_GREATER) {
-               DB_UTIL_TRACE_DEBUG("greater \n");
-       } else if (result == UCOL_EQUAL) {
-               DB_UTIL_TRACE_DEBUG("equal \n");
-       } else {
-               DB_UTIL_TRACE_DEBUG("compare error : %d \n", result);
-       }
-#endif
-
-       return result;
-}
-
-/* The collating function must return an integer that is negative, zero or positive */
-static int __db_util_collate_icu_8(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
-{
-       UCharIterator uiter1, uiter2;
-       UErrorCode error = U_ZERO_ERROR;
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_8 func start \n");
-       DB_UTIL_TRACE_DEBUG("v1(%d) : %s, v2(%d) : %s \n", str1_len, (char*)str1, str2_len, (char*)str2);
-#endif
-
-       DB_UTIL_RETV_IF(icu_symbol.icu_uiter_setUTF8 == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcollIter == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-
-       icu_symbol.icu_uiter_setUTF8(&uiter1, (const char *) str1, str1_len);
-       icu_symbol.icu_uiter_setUTF8(&uiter2, (const char *) str2, str2_len);
-
-       UCollationResult result = icu_symbol.icu_ucol_strcollIter(
-                                                               (UCollator *) ucol,
-                                                               &uiter1,
-                                                               &uiter2,
-                                                               &error);
-       if (U_FAILURE(error)) {
-               DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8 ucol_strcollIter error: %d\n", error);
-               return DB_UTIL_ERR_COL_FUNC_RET;
-       }
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       if (result == UCOL_LESS) {
-               DB_UTIL_TRACE_DEBUG("less \n");
-       } else if (result == UCOL_GREATER) {
-               DB_UTIL_TRACE_DEBUG("greater \n");
-       } else {
-               DB_UTIL_TRACE_DEBUG("equal \n");
-       }
-#endif
-
-       return result;
-}
-
-static int __db_util_collate_icu_8_lc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
-{
-       UCharIterator uiter1, uiter2;
-       UErrorCode error = U_ZERO_ERROR;
-       UCollationResult result = 0;
-       char* str_from = (char*)str1;
-       char* str_to = (char*)str1;
-       glong v1_char_len, v2_char_len;
-       int i;
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_8_lc func start \n");
-       DB_UTIL_TRACE_DEBUG("v1(%d) : %s, v2(%d) : %s \n", str1_len, (char*)str1, str2_len, (char*)str2);
-#endif
-
-       DB_UTIL_RETV_IF(icu_symbol.icu_uiter_setUTF8 == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcollIter == NULL, DB_UTIL_ERR_COL_FUNC_RET);
-
-       icu_symbol.icu_uiter_setUTF8(&uiter2, (const char *) str2, str2_len);
-
-       v1_char_len = g_utf8_strlen((gchar *)str1, -1);
-       v2_char_len = g_utf8_strlen((gchar *)str2, -1);
-
-       if (v1_char_len > v2_char_len) {
-               for (i = 0; i < v2_char_len; i++) {
-                       str_to = g_utf8_next_char(str_to);
-               }
-
-               while ((int)(str_to-(char*)str1) <= str1_len) {
-                       icu_symbol.icu_uiter_setUTF8(
-                                               &uiter1,
-                                               (const char *) str_from,
-                                               str_to - str_from);
-
-                       result = icu_symbol.icu_ucol_strcollIter(
-                                               (UCollator *) ucol,
-                                               &uiter1,
-                                               &uiter2,
-                                               &error);
-                       if (U_FAILURE(error)) {
-                               DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8_lc ucol_strcollIter error: %d\n", error);
-                               return DB_UTIL_ERR_COL_FUNC_RET;
-                       }
-
-                       if (result == UCOL_EQUAL)
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-                       {
-                               DB_UTIL_TRACE_DEBUG("equal \n");
-                               return UCOL_EQUAL;
-                       }
-#else
-                               return UCOL_EQUAL;
-#endif
-
-                       str_to = g_utf8_next_char(str_to);
-                       str_from = g_utf8_next_char(str_from);
-               }
-       } else {
-               icu_symbol.icu_uiter_setUTF8(
-                                       &uiter1,
-                                       (const char *) str1,
-                                       str1_len);
-
-               result = icu_symbol.icu_ucol_strcollIter(
-                                       (UCollator *) ucol,
-                                       &uiter1,
-                                       &uiter2,
-                                       &error);
-               if (U_FAILURE(error)) {
-                       DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8_lc ucol_strcollIter error: %d\n", error);
-                       return DB_UTIL_ERR_COL_FUNC_RET;
-               }
-       }
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       if (result == UCOL_LESS) {
-               DB_UTIL_TRACE_DEBUG("less \n");
-       } else if (result == UCOL_GREATER) {
-               DB_UTIL_TRACE_DEBUG("greater \n");
-       } else if (result == UCOL_EQUAL) {
-               DB_UTIL_TRACE_DEBUG("equal \n");
-       } else {
-               DB_UTIL_TRACE_DEBUG("compare error : %d\n", result);
-       }
-#endif
-
-       return result;
-}
-
-static void __db_util_collate_icu_close(void* ucol)
-{
-       DB_UTIL_TRACE_DEBUG("close icu collator\n");
-       DB_UTIL_RET_IF(icu_symbol.icu_ucol_close == NULL);
-       icu_symbol.icu_ucol_close((UCollator *) ucol);
-}
-
-static int __db_util_collation_create(sqlite3* db_handle, char* locale, char* collator_name, UCollationStrength ucol_strength_value, int utf_type, int cmp_type)
-{
-       int err;
-       UErrorCode status = U_ZERO_ERROR;
-
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_open == NULL, DB_UTIL_ERR_DLSYM);
-       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_setStrength == NULL, DB_UTIL_ERR_DLSYM);
-
-       UCollator* ucol = icu_symbol.icu_ucol_open(locale, &status);
-       if (status == U_USING_DEFAULT_WARNING) {
-               DB_UTIL_TRACE_ERROR("ucol_open success with default collate option\n");
-       } else if (U_FAILURE(status)) {
-               DB_UTIL_TRACE_ERROR("ucol_open fail : %d \n", status);
-               return DB_UTIL_ERR_ICU;
-       }
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-       else {
-               DB_UTIL_TRACE_DEBUG("ucol_open success : %d \n", status);
-       }
-#endif
-
-       icu_symbol.icu_ucol_setStrength(ucol, ucol_strength_value);
-       if (U_FAILURE(status)) {
-               DB_UTIL_TRACE_ERROR("ucol_setStrength fail : %d \n", status);
-               return DB_UTIL_ERR_ICU;
-       } else {
-               DB_UTIL_TRACE_DEBUG("ucol_setStrength success \n");
-       }
-
-       if (utf_type == DB_UTIL_COL_UTF8) {
-               if (cmp_type == DB_UTIL_CMP_LC) {
-                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF8, ucol,
-                               __db_util_collate_icu_8_lc, (void(*)(void*))__db_util_collate_icu_close);
-               } else {
-                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF8, ucol,
-                               __db_util_collate_icu_8, (void(*)(void*))__db_util_collate_icu_close);
-               }
-       } else if (utf_type == DB_UTIL_COL_UTF16) {
-               if (cmp_type == DB_UTIL_CMP_LC) {
-                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF16, ucol,
-                               __db_util_collate_icu_16_lc, (void(*)(void*))__db_util_collate_icu_close);
-               } else {
-                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF16, ucol,
-                               __db_util_collate_icu_16, (void(*)(void*))__db_util_collate_icu_close);
-               }
-       } else {
-               DB_UTIL_TRACE_ERROR("wrong utf_type param value : %d\n", utf_type);
-               return DB_UTIL_ERR_PARAM;
-       }
-
-       if (err != SQLITE_OK) {
-               DB_UTIL_TRACE_ERROR("sqlite3_create_collation_v2 fail : %d \n", err);
-               __db_util_collate_icu_close((void*)ucol);
-               return err;
-       } else {
-               DB_UTIL_TRACE_DEBUG("sqlite3_create_collation_v2 success \n");
-               return DB_UTIL_OK;
-       }
-}
-
-int db_util_create_collation(
-       PARAM_IN sqlite3 *db_handle,
-       PARAM_IN db_util_collate_type type,
-       PARAM_IN db_util_collate_textrep text_type,
-       PARAM_IN char* col_name)
-{
-       int ret = DB_UTIL_OK;
-       UErrorCode status = U_ZERO_ERROR;
-       const char* locale = NULL;
-
-       if ((!db_handle) || (!col_name)) {
-               DB_UTIL_TRACE_ERROR("wrong input param");
-               return DB_UTIL_ERROR;
-       }
-
-       DB_UTIL_TRACE_DEBUG("db_util_create_collation start");
-
-       ret = __db_util_dl_load_icu();
-       DB_UTIL_RETV_IF(ret != DB_UTIL_OK, DB_UTIL_ERROR);
-
-       char *lang = vconf_get_str(VCONFKEY_LANGSET);
-       /* get current locale */
-       if (lang) {
-               icu_symbol.icu_uloc_setDefault(lang, &status);
-               free(lang);
-       } else {
-               DB_UTIL_TRACE_WARNING("Fail to get current language vconf : %d", DB_UTIL_ERR_ENV);
-               return DB_UTIL_ERROR;
-       }
-       locale = icu_symbol.icu_uloc_getDefault();
-       if (locale == NULL) {
-               DB_UTIL_TRACE_WARNING("Fail to get current locale : %d", DB_UTIL_ERR_ENV);
-               return DB_UTIL_ERROR;
-       }
-       DB_UTIL_TRACE_DEBUG("locale : %s", locale);
-
-#ifdef ENABLE_COL_KO_IC
-       if ((db_util_collate_type == DB_UTIL_COL_KO_IC) ||
-               (db_util_collate_type == DB_UTIL_COL_KO_IC_LC)) {
-               if (strncmp(locale, "ko", 2) != 0) {
-                       DB_UTIL_TRACE_WARNING("collate type is not match with current locale : %d", DB_UTIL_ERR_ENV);
-                       return DB_UTIL_ERROR;
-               }
-       }
-#endif
-
-       switch (type) {
-       case DB_UTIL_COL_UCA:
-               ret = __db_util_collation_create(db_handle, NULL, col_name, UCOL_SECONDARY, text_type, DB_UTIL_CMP_SC);
-               break;
-       case DB_UTIL_COL_LS_AS_CI:
-               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_SECONDARY, text_type, DB_UTIL_CMP_SC);
-               break;
-       case DB_UTIL_COL_LS_AI_CI:
-               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_SC);
-               break;
-       case DB_UTIL_COL_LS_AI_CI_LC:
-               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_LC);
-               break;
-#ifdef ENABLE_COL_KO_IC
-       case DB_UTIL_COL_KO_IC:
-               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_SC);
-               break;
-       case DB_UTIL_COL_KO_IC_LC:
-               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_LC);
-               break;
-#endif
-       default:
-               DB_UTIL_TRACE_WARNING("wrong collate input type");
-               ret = DB_UTIL_ERROR;
-       }
-
-       if (ret != DB_UTIL_OK)
-               ret = DB_UTIL_ERROR;
-
-       return ret;
-}
-
-#ifdef DB_UTIL_ENABLE_DEVDEBUG
-
-static char *strtoutf8(const UChar * unichars, int len)
-{
-       DB_UTIL_TRACE_WARNING("strtoutf8 start");
-
-       int lenstr, lenutf8;
-       char *pstr = NULL;
-       UErrorCode status = U_ZERO_ERROR;
-
-       lenstr = lenutf8 = 0;
-       lenstr = sizeof(char) * 4 * (len + 1);
-       pstr = (char *)malloc(lenstr);
-       if (!pstr)return NULL;
-       u_strToUTF8(pstr, lenstr, &lenutf8, unichars, len, &status);
-       if (U_FAILURE(status)) {
-               DB_UTIL_TRACE_WARNING("u_strToUTF8 failed in strtoutf8 :%s\n",
-                      u_errorName(status));
-               return NULL;
-       }
-       DB_UTIL_TRACE_WARNING("strtoutf8 out : %s", pstr);
-       return pstr;
-}
-
-#endif
-
diff --git a/include/db-util-debug.h b/include/db-util-debug.h
deleted file mode 100644 (file)
index 24cf82e..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * libslp-db-util
- *
- * 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 __DB_UTIL_DEBUG_H_
-#define __DB_UTIL_DEBUG_H_
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef DB_UTIL_USING_PLATFORM_DBG
-       #include <dlog.h>
-       #ifdef LOG_TAG
-               #undef LOG_TAG
-       #endif
-       #define LOG_TAG "DBUTIL"
-#endif
-
-#ifdef DB_UTIL_ENABLE_TRACE
-
-       #ifdef DB_UTIL_USING_PLATFORM_DBG
-
-               #define DB_UTIL_TRACE_DEBUG LOGD
-               #define DB_UTIL_TRACE_WARNING LOGW
-               #define DB_UTIL_TRACE_ERROR LOGE
-
-       #else
-
-               #define DB_UTIL_TRACE_DEBUG(fmt, arg...) \
-                       do {\
-                               fprintf(stderr, "[DBUTIL]\033[0;32mDEBUG: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
-                       } while (0);
-
-               #define DB_UTIL_TRACE_WARNING(fmt, arg...) \
-                       do {\
-                               fprintf(stderr, "[DBUTIL]\033[0;33mWARRING: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
-                       } while (0);
-
-               #define DB_UTIL_TRACE_ERROR(fmt, arg...) \
-                       do {\
-                               fprintf(stderr, "[DBUTIL]\033[0;31mERROR: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
-                       } while (0);
-
-       #endif
-
-#else
-
-       #define DB_UTIL_TRACE_DEBUG(fmt, arg...)
-       #define DB_UTIL_TRACE_WARNING(fmt, arg...)
-       #define DB_UTIL_TRACE_ERROR(fmt, arg...)
-
-#endif
-#endif /* __DB_UTIL_DEBUG_H_ */
-
diff --git a/packaging/libslp-db-util-devel.manifest b/packaging/libslp-db-util-devel.manifest
deleted file mode 100644 (file)
index c00c25b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
-        <request>
-                <domain name="_" />
-        </request>
-</manifest>
diff --git a/packaging/libslp-db-util.changes b/packaging/libslp-db-util.changes
deleted file mode 100644 (file)
index 6b431c6..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-* Thu Jun 27 2013 Anas Nashif <anas.nashif@intel.com> accepted/tizen/20130520.100924@61e2996
-- cleanup and remove obsolete files
-
old mode 100755 (executable)
new mode 100644 (file)
index 1f2c5ae..27d34ca
@@ -6,7 +6,6 @@ Summary:        DB Utility
 Group:          Application Framework/Database
 Source0:        %{name}-%{version}.tar.gz
 Source1001:    %{name}.manifest
-Source1002:    %{name}-devel.manifest
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
@@ -38,7 +37,7 @@ libslp-db-util gcov objects
 
 %prep
 %setup -q
-cp %{SOURCE1001} %{SOURCE1002} .
+cp %{SOURCE1001} ./%{name}.manifest
 
 %build
 
@@ -74,7 +73,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
 
 %check
 %if 0%{?gcov:1}
-pushd unittest
+pushd tests
 ./run_coverage.sh
 popd
 %endif
@@ -85,13 +84,12 @@ popd
 
 %files
 %manifest %{name}.manifest
-%license LICENSE
+%license LICENSE.APLv2
 %defattr(-,root,root,-)
 %{_libdir}/libSLP-db-util.so.0
 %{_libdir}/libSLP-db-util.so.0.1.0
 
 %files devel
-%manifest %{name}-devel.manifest
 %defattr(-,root,root,-)
 %dir %{_includedir}/db-util
 %{_includedir}/db-util/*.h
@@ -101,7 +99,6 @@ popd
 
 %if 0%{?gcov:1}
 %files gcov
-%manifest %{name}-devel.manifest
 %defattr(-,root,root,-)
 %{_datadir}/gcov/obj/*
 %endif
diff --git a/src/collation.c b/src/collation.c
new file mode 100644 (file)
index 0000000..e3358d9
--- /dev/null
@@ -0,0 +1,561 @@
+/*
+ * libslp-db-util
+ *
+ * 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 <string.h>
+#include <math.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <unistd.h>
+#include <glib.h>
+
+#include <dlfcn.h>
+
+#include <unicode/utypes.h>
+#include <unicode/ucol.h>
+#include <unicode/uiter.h>
+#include <unicode/ustring.h>
+
+#include "collation.h"
+
+#include "db-util-debug.h"
+#include <vconf.h>
+
+#define DB_UTIL_RETV_IF(cond, ret) \
+                       do { \
+                               if (cond) { \
+                                       DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
+                                       return ret; \
+                               } \
+                       } while (0)
+
+#define DB_UTIL_RET_IF(cond) \
+                       do { \
+                               if (cond) { \
+                                       DB_UTIL_TRACE_WARNING("\x1b[33m[%s()][RET_IF]\x1b[0m", __FUNCTION__); \
+                                       return; \
+                               } \
+                       } while (0)
+
+#define DB_UTIL_ERR_COL_FUNC_RET DB_UTIL_ERROR
+
+#ifdef DB_UTIL_ARCH_64
+#define ICUI18N_LIBPATH "/usr/lib64/libicui18n.so"
+#else
+#define ICUI18N_LIBPATH "/usr/lib/libicui18n.so"
+#endif
+
+enum {
+       DB_UTIL_ERR_DLOPEN = -10,
+       DB_UTIL_ERR_DLSYM,
+       DB_UTIL_ERR_ENV,
+       DB_UTIL_ERR_ICU,
+       DB_UTIL_ERR_PARAM
+};
+
+enum {
+       DB_UTIL_CMP_SC,
+       /* Loop comparison */
+       DB_UTIL_CMP_LC
+};
+
+#define ICU_FUNC_CNT 8
+
+typedef UCollator *(*ICU_UCOL_OPEN)(const char *, UErrorCode *);
+typedef void (*ICU_UCOL_CLOSE)(UCollator *);
+typedef void (*ICU_UCOL_SETSTRENGTH)(UCollator *, UCollationStrength);
+typedef UCollationResult (*ICU_UCOL_STRCOLL)(const UCollator *, const UChar *, int32_t, const UChar *, int32_t);
+typedef UCollationResult (*ICU_UCOL_STRCOLLITER)(const UCollator *, UCharIterator *, UCharIterator *, UErrorCode *);
+typedef void (*ICU_UITER_SETUTF8)(UCharIterator *, const char *, int32_t);
+typedef void (*ICU_ULOC_SETDEFAULT)(const char* localeID, UErrorCode* status);
+typedef const char* (*ICU_ULOC_GETDEFAULT)(void);
+
+typedef struct {
+       ICU_UCOL_OPEN icu_ucol_open;
+       ICU_UCOL_CLOSE icu_ucol_close;
+       ICU_UCOL_STRCOLL icu_ucol_strcoll;
+       ICU_UCOL_STRCOLLITER icu_ucol_strcollIter;
+       ICU_UCOL_SETSTRENGTH icu_ucol_setStrength;
+       ICU_UITER_SETUTF8 icu_uiter_setUTF8;
+       ICU_ULOC_SETDEFAULT icu_uloc_setDefault;
+       ICU_ULOC_GETDEFAULT icu_uloc_getDefault;
+} db_util_icu_func_t;
+
+db_util_icu_func_t icu_symbol;
+
+void *g_dl_icu_handle = NULL;
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+static char *strtoutf8(const UChar * unichars, int len);
+#endif
+
+static int __db_util_dl_load_icu()
+{
+       void *handle = NULL;
+       void *icu_handle[ICU_FUNC_CNT] = { 0 };
+       char *dl_error;
+       int i = 0;
+
+       const char *ICU_API[] = {
+               "ucol_open",
+               "ucol_close",
+               "ucol_strcoll",
+               "ucol_strcollIter",
+               "ucol_setStrength",
+               "uiter_setUTF8",
+               "uloc_setDefault",
+               "uloc_getDefault"
+       };
+
+       if (g_dl_icu_handle == NULL) {
+               g_dl_icu_handle = dlopen(ICUI18N_LIBPATH, RTLD_LAZY | RTLD_GLOBAL);
+               if (g_dl_icu_handle == NULL) {
+                       DB_UTIL_TRACE_WARNING("dlopen icu so fail");
+                       return DB_UTIL_ERR_DLOPEN;
+               }
+       }
+
+       for (i = 0; i < ICU_FUNC_CNT; i++) {
+               handle = dlsym(g_dl_icu_handle, ICU_API[i]);
+               if ((dl_error = dlerror()) != NULL)  {
+                       DB_UTIL_TRACE_WARNING("dlsym(%s) is failed for %s",
+                                                               dl_error, ICU_API[i]);
+                       return DB_UTIL_ERR_DLSYM;
+               }
+               icu_handle[i] = handle;
+       }
+
+       memcpy((void*)&icu_symbol, (const void*)icu_handle, sizeof(icu_handle));
+
+       return DB_UTIL_OK;
+}
+
+/* The collating function must return an integer that is negative, zero or positive */
+static int __db_util_collate_icu_16(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
+{
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_16 func start \n");
+
+       UChar* tmp_v1 = (UChar *)str1;
+       UChar* tmp_v2 = (UChar *)str2;
+       char* utf8_v1 = strtoutf8(tmp_v1, str1_len);
+       char* utf8_v2 = strtoutf8(tmp_v2, str2_len);
+
+       DB_UTIL_TRACE_DEBUG("v1(%d) : %s\n", str1_len, utf8_v1);
+       DB_UTIL_TRACE_DEBUG("v2(%d) : %s\n", str2_len, utf8_v2);
+#endif
+
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcoll == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+
+       UCollationResult result = icu_symbol.icu_ucol_strcoll(
+                                                               (UCollator *) ucol,
+                                                               (const UChar *) str1, str1_len,
+                                                               (const UChar *) str2, str2_len);
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       if (utf8_v1)
+               free(utf8_v1);
+       if (utf8_v2)
+               free(utf8_v2);
+
+       if (result == UCOL_LESS) {
+               DB_UTIL_TRACE_DEBUG("less \n");
+       } else if (result == UCOL_GREATER) {
+               DB_UTIL_TRACE_DEBUG("greater \n");
+       } else {
+               DB_UTIL_TRACE_DEBUG("equal \n");
+       }
+#endif
+
+       return result;
+}
+
+/* The collating function must return an integer that is negative, zero or positive */
+static int __db_util_collate_icu_16_lc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
+{
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_16_lc func start \n");
+
+       UChar* tmp_v1 = (UChar *)str1;
+       UChar* tmp_v2 = (UChar *)str2;
+
+       char* utf8_v1 = strtoutf8(tmp_v1, str1_len);
+       char* utf8_v2 = strtoutf8(tmp_v2, str2_len);
+
+       DB_UTIL_TRACE_DEBUG("v1(%d) : %s\n", str1_len, utf8_v1);
+       DB_UTIL_TRACE_DEBUG("v2(%d) : %s\n", str2_len, utf8_v2);
+
+       if (utf8_v1)
+               free(utf8_v1);
+       if (utf8_v2)
+               free(utf8_v2);
+#endif
+
+       UCollationResult result = 0;
+
+       UChar* str_to = (UChar *)str1;
+       UChar* str_from = (UChar *)str1;
+
+       int i;
+
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcoll == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+
+       if (str1_len > str2_len) {
+               for (i = 0; i < str2_len; i = i+2) {
+                       str_to++;
+               }
+
+               while ((int)(str_to-(UChar*)str1) <= str1_len) {
+                       result = icu_symbol.icu_ucol_strcoll(
+                                               (UCollator *) ucol,
+                                               (UChar *) str_from, str_to-str_from,
+                                               (const UChar *) str2, str2_len);
+
+                       if (result == UCOL_EQUAL) {
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+                               DB_UTIL_TRACE_DEBUG("equal \n");
+#endif
+                               return UCOL_EQUAL;
+                       }
+
+                       str_to++;
+                       str_from++;
+               }
+       } else {
+               result = icu_symbol.icu_ucol_strcoll(
+                                       (UCollator *) ucol,
+                                       (const UChar *) str1, str1_len,
+                                       (const UChar *) str2, str2_len);
+       }
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       if (result == UCOL_LESS) {
+               DB_UTIL_TRACE_DEBUG("less \n");
+       } else if (result == UCOL_GREATER) {
+               DB_UTIL_TRACE_DEBUG("greater \n");
+       } else if (result == UCOL_EQUAL) {
+               DB_UTIL_TRACE_DEBUG("equal \n");
+       } else {
+               DB_UTIL_TRACE_DEBUG("compare error : %d \n", result);
+       }
+#endif
+
+       return result;
+}
+
+/* The collating function must return an integer that is negative, zero or positive */
+static int __db_util_collate_icu_8(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
+{
+       UCharIterator uiter1, uiter2;
+       UErrorCode error = U_ZERO_ERROR;
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_8 func start \n");
+       DB_UTIL_TRACE_DEBUG("v1(%d) : %s, v2(%d) : %s \n", str1_len, (char*)str1, str2_len, (char*)str2);
+#endif
+
+       DB_UTIL_RETV_IF(icu_symbol.icu_uiter_setUTF8 == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcollIter == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+
+       icu_symbol.icu_uiter_setUTF8(&uiter1, (const char *) str1, str1_len);
+       icu_symbol.icu_uiter_setUTF8(&uiter2, (const char *) str2, str2_len);
+
+       UCollationResult result = icu_symbol.icu_ucol_strcollIter(
+                                                               (UCollator *) ucol,
+                                                               &uiter1,
+                                                               &uiter2,
+                                                               &error);
+       if (U_FAILURE(error)) {
+               DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8 ucol_strcollIter error: %d\n", error);
+               return DB_UTIL_ERR_COL_FUNC_RET;
+       }
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       if (result == UCOL_LESS) {
+               DB_UTIL_TRACE_DEBUG("less \n");
+       } else if (result == UCOL_GREATER) {
+               DB_UTIL_TRACE_DEBUG("greater \n");
+       } else {
+               DB_UTIL_TRACE_DEBUG("equal \n");
+       }
+#endif
+
+       return result;
+}
+
+static int __db_util_collate_icu_8_lc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2)
+{
+       UCharIterator uiter1, uiter2;
+       UErrorCode error = U_ZERO_ERROR;
+       UCollationResult result = 0;
+       char* str_from = (char*)str1;
+       char* str_to = (char*)str1;
+       glong v1_char_len, v2_char_len;
+       int i;
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       DB_UTIL_TRACE_DEBUG("__db_util_collate_icu_8_lc func start \n");
+       DB_UTIL_TRACE_DEBUG("v1(%d) : %s, v2(%d) : %s \n", str1_len, (char*)str1, str2_len, (char*)str2);
+#endif
+
+       DB_UTIL_RETV_IF(icu_symbol.icu_uiter_setUTF8 == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_strcollIter == NULL, DB_UTIL_ERR_COL_FUNC_RET);
+
+       icu_symbol.icu_uiter_setUTF8(&uiter2, (const char *) str2, str2_len);
+
+       v1_char_len = g_utf8_strlen((gchar *)str1, -1);
+       v2_char_len = g_utf8_strlen((gchar *)str2, -1);
+
+       if (v1_char_len > v2_char_len) {
+               for (i = 0; i < v2_char_len; i++) {
+                       str_to = g_utf8_next_char(str_to);
+               }
+
+               while ((int)(str_to-(char*)str1) <= str1_len) {
+                       icu_symbol.icu_uiter_setUTF8(
+                                               &uiter1,
+                                               (const char *) str_from,
+                                               str_to - str_from);
+
+                       result = icu_symbol.icu_ucol_strcollIter(
+                                               (UCollator *) ucol,
+                                               &uiter1,
+                                               &uiter2,
+                                               &error);
+                       if (U_FAILURE(error)) {
+                               DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8_lc ucol_strcollIter error: %d\n", error);
+                               return DB_UTIL_ERR_COL_FUNC_RET;
+                       }
+
+                       if (result == UCOL_EQUAL)
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+                       {
+                               DB_UTIL_TRACE_DEBUG("equal \n");
+                               return UCOL_EQUAL;
+                       }
+#else
+                               return UCOL_EQUAL;
+#endif
+
+                       str_to = g_utf8_next_char(str_to);
+                       str_from = g_utf8_next_char(str_from);
+               }
+       } else {
+               icu_symbol.icu_uiter_setUTF8(
+                                       &uiter1,
+                                       (const char *) str1,
+                                       str1_len);
+
+               result = icu_symbol.icu_ucol_strcollIter(
+                                       (UCollator *) ucol,
+                                       &uiter1,
+                                       &uiter2,
+                                       &error);
+               if (U_FAILURE(error)) {
+                       DB_UTIL_TRACE_ERROR("__db_util_collate_icu_8_lc ucol_strcollIter error: %d\n", error);
+                       return DB_UTIL_ERR_COL_FUNC_RET;
+               }
+       }
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       if (result == UCOL_LESS) {
+               DB_UTIL_TRACE_DEBUG("less \n");
+       } else if (result == UCOL_GREATER) {
+               DB_UTIL_TRACE_DEBUG("greater \n");
+       } else if (result == UCOL_EQUAL) {
+               DB_UTIL_TRACE_DEBUG("equal \n");
+       } else {
+               DB_UTIL_TRACE_DEBUG("compare error : %d\n", result);
+       }
+#endif
+
+       return result;
+}
+
+static void __db_util_collate_icu_close(void* ucol)
+{
+       DB_UTIL_TRACE_DEBUG("close icu collator\n");
+       DB_UTIL_RET_IF(icu_symbol.icu_ucol_close == NULL);
+       icu_symbol.icu_ucol_close((UCollator *) ucol);
+}
+
+static int __db_util_collation_create(sqlite3* db_handle, char* locale, char* collator_name, UCollationStrength ucol_strength_value, int utf_type, int cmp_type)
+{
+       int err;
+       UErrorCode status = U_ZERO_ERROR;
+
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_open == NULL, DB_UTIL_ERR_DLSYM);
+       DB_UTIL_RETV_IF(icu_symbol.icu_ucol_setStrength == NULL, DB_UTIL_ERR_DLSYM);
+
+       UCollator* ucol = icu_symbol.icu_ucol_open(locale, &status);
+       if (status == U_USING_DEFAULT_WARNING) {
+               DB_UTIL_TRACE_ERROR("ucol_open success with default collate option\n");
+       } else if (U_FAILURE(status)) {
+               DB_UTIL_TRACE_ERROR("ucol_open fail : %d \n", status);
+               return DB_UTIL_ERR_ICU;
+       }
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+       else {
+               DB_UTIL_TRACE_DEBUG("ucol_open success : %d \n", status);
+       }
+#endif
+
+       icu_symbol.icu_ucol_setStrength(ucol, ucol_strength_value);
+       if (U_FAILURE(status)) {
+               DB_UTIL_TRACE_ERROR("ucol_setStrength fail : %d \n", status);
+               return DB_UTIL_ERR_ICU;
+       } else {
+               DB_UTIL_TRACE_DEBUG("ucol_setStrength success \n");
+       }
+
+       if (utf_type == DB_UTIL_COL_UTF8) {
+               if (cmp_type == DB_UTIL_CMP_LC) {
+                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF8, ucol,
+                               __db_util_collate_icu_8_lc, (void(*)(void*))__db_util_collate_icu_close);
+               } else {
+                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF8, ucol,
+                               __db_util_collate_icu_8, (void(*)(void*))__db_util_collate_icu_close);
+               }
+       } else if (utf_type == DB_UTIL_COL_UTF16) {
+               if (cmp_type == DB_UTIL_CMP_LC) {
+                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF16, ucol,
+                               __db_util_collate_icu_16_lc, (void(*)(void*))__db_util_collate_icu_close);
+               } else {
+                       err = sqlite3_create_collation_v2(db_handle, collator_name, SQLITE_UTF16, ucol,
+                               __db_util_collate_icu_16, (void(*)(void*))__db_util_collate_icu_close);
+               }
+       } else {
+               DB_UTIL_TRACE_ERROR("wrong utf_type param value : %d\n", utf_type);
+               return DB_UTIL_ERR_PARAM;
+       }
+
+       if (err != SQLITE_OK) {
+               DB_UTIL_TRACE_ERROR("sqlite3_create_collation_v2 fail : %d \n", err);
+               __db_util_collate_icu_close((void*)ucol);
+               return err;
+       } else {
+               DB_UTIL_TRACE_DEBUG("sqlite3_create_collation_v2 success \n");
+               return DB_UTIL_OK;
+       }
+}
+
+int db_util_create_collation(
+       PARAM_IN sqlite3 *db_handle,
+       PARAM_IN db_util_collate_type type,
+       PARAM_IN db_util_collate_textrep text_type,
+       PARAM_IN char* col_name)
+{
+       int ret = DB_UTIL_OK;
+       UErrorCode status = U_ZERO_ERROR;
+       const char* locale = NULL;
+
+       if ((!db_handle) || (!col_name)) {
+               DB_UTIL_TRACE_ERROR("wrong input param");
+               return DB_UTIL_ERROR;
+       }
+
+       DB_UTIL_TRACE_DEBUG("db_util_create_collation start");
+
+       ret = __db_util_dl_load_icu();
+       DB_UTIL_RETV_IF(ret != DB_UTIL_OK, DB_UTIL_ERROR);
+
+       char *lang = vconf_get_str(VCONFKEY_LANGSET);
+       /* get current locale */
+       if (lang) {
+               icu_symbol.icu_uloc_setDefault(lang, &status);
+               free(lang);
+       } else {
+               DB_UTIL_TRACE_WARNING("Fail to get current language vconf : %d", DB_UTIL_ERR_ENV);
+               return DB_UTIL_ERROR;
+       }
+       locale = icu_symbol.icu_uloc_getDefault();
+       if (locale == NULL) {
+               DB_UTIL_TRACE_WARNING("Fail to get current locale : %d", DB_UTIL_ERR_ENV);
+               return DB_UTIL_ERROR;
+       }
+       DB_UTIL_TRACE_DEBUG("locale : %s", locale);
+
+#ifdef ENABLE_COL_KO_IC
+       if ((db_util_collate_type == DB_UTIL_COL_KO_IC) ||
+               (db_util_collate_type == DB_UTIL_COL_KO_IC_LC)) {
+               if (strncmp(locale, "ko", 2) != 0) {
+                       DB_UTIL_TRACE_WARNING("collate type is not match with current locale : %d", DB_UTIL_ERR_ENV);
+                       return DB_UTIL_ERROR;
+               }
+       }
+#endif
+
+       switch (type) {
+       case DB_UTIL_COL_UCA:
+               ret = __db_util_collation_create(db_handle, NULL, col_name, UCOL_SECONDARY, text_type, DB_UTIL_CMP_SC);
+               break;
+       case DB_UTIL_COL_LS_AS_CI:
+               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_SECONDARY, text_type, DB_UTIL_CMP_SC);
+               break;
+       case DB_UTIL_COL_LS_AI_CI:
+               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_SC);
+               break;
+       case DB_UTIL_COL_LS_AI_CI_LC:
+               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_LC);
+               break;
+#ifdef ENABLE_COL_KO_IC
+       case DB_UTIL_COL_KO_IC:
+               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_SC);
+               break;
+       case DB_UTIL_COL_KO_IC_LC:
+               ret = __db_util_collation_create(db_handle, (char*)locale, col_name, UCOL_PRIMARY, text_type, DB_UTIL_CMP_LC);
+               break;
+#endif
+       default:
+               DB_UTIL_TRACE_WARNING("wrong collate input type");
+               ret = DB_UTIL_ERROR;
+       }
+
+       if (ret != DB_UTIL_OK)
+               ret = DB_UTIL_ERROR;
+
+       return ret;
+}
+
+#ifdef DB_UTIL_ENABLE_DEVDEBUG
+
+static char *strtoutf8(const UChar * unichars, int len)
+{
+       DB_UTIL_TRACE_WARNING("strtoutf8 start");
+
+       int lenstr, lenutf8;
+       char *pstr = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+
+       lenstr = lenutf8 = 0;
+       lenstr = sizeof(char) * 4 * (len + 1);
+       pstr = (char *)malloc(lenstr);
+       if (!pstr)return NULL;
+       u_strToUTF8(pstr, lenstr, &lenutf8, unichars, len, &status);
+       if (U_FAILURE(status)) {
+               DB_UTIL_TRACE_WARNING("u_strToUTF8 failed in strtoutf8 :%s\n",
+                      u_errorName(status));
+               return NULL;
+       }
+       DB_UTIL_TRACE_WARNING("strtoutf8 out : %s", pstr);
+       return pstr;
+}
+
+#endif
diff --git a/src/db-util-debug.h b/src/db-util-debug.h
new file mode 100644 (file)
index 0000000..49d61a4
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * libslp-db-util
+ *
+ * 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 __DB_UTIL_DEBUG_H_
+#define __DB_UTIL_DEBUG_H_
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef DB_UTIL_USING_PLATFORM_DBG
+       #include <dlog.h>
+       #ifdef LOG_TAG
+               #undef LOG_TAG
+       #endif
+       #define LOG_TAG "DBUTIL"
+#endif
+
+#ifdef DB_UTIL_ENABLE_TRACE
+
+       #ifdef DB_UTIL_USING_PLATFORM_DBG
+
+               #define DB_UTIL_TRACE_DEBUG LOGD
+               #define DB_UTIL_TRACE_WARNING LOGW
+               #define DB_UTIL_TRACE_ERROR LOGE
+
+       #else
+
+               #define DB_UTIL_TRACE_DEBUG(fmt, arg...) \
+                       do {\
+                               fprintf(stderr, "[DBUTIL]\033[0;32mDEBUG: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
+                       } while (0);
+
+               #define DB_UTIL_TRACE_WARNING(fmt, arg...) \
+                       do {\
+                               fprintf(stderr, "[DBUTIL]\033[0;33mWARRING: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
+                       } while (0);
+
+               #define DB_UTIL_TRACE_ERROR(fmt, arg...) \
+                       do {\
+                               fprintf(stderr, "[DBUTIL]\033[0;31mERROR: " fmt "\033[0m\t%s:%d\n", ##arg, strrchr(__FILE__, '/')+1, __LINE__);\
+                       } while (0);
+
+       #endif
+
+#else
+
+       #define DB_UTIL_TRACE_DEBUG(fmt, arg...)
+       #define DB_UTIL_TRACE_WARNING(fmt, arg...)
+       #define DB_UTIL_TRACE_ERROR(fmt, arg...)
+
+#endif
+#endif /* __DB_UTIL_DEBUG_H_ */
diff --git a/src/util-func.c b/src/util-func.c
new file mode 100644 (file)
index 0000000..09ae820
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * libslp-db-util
+ *
+ * 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 <string.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "util-func.h"
+#include "collation.h"
+#include "db-util-debug.h"
+
+static int __db_util_busyhandler(void *pData, int count)
+{
+       if (5 - count > 0) {
+               DB_UTIL_TRACE_DEBUG("Busy Handler Called! : PID(%d) / CNT(%d)\n", getpid(), count+1);
+               struct timespec time = {
+                       .tv_sec = 0,
+                       .tv_nsec = (count+1) * 100 * 1000 * 1000
+               };
+               nanosleep(&time, NULL);
+
+               return 1;
+       } else {
+               DB_UTIL_TRACE_DEBUG("Busy Handler will be returned SQLITE_BUSY error : PID(%d) \n", getpid());
+               return 0;
+       }
+}
+
+void __db_util_collation_cb(void* pArg, sqlite3* pDB, int eTextRep, const char* szName)
+{
+       if (eTextRep == SQLITE_UTF8 && !sqlite3_stricmp(szName, "localized"))
+               db_util_create_collation(pDB, DB_UTIL_COL_LS_AS_CI,
+                                                               DB_UTIL_COL_UTF8, "localized");
+       else
+               DB_UTIL_TRACE_WARNING("No matching collator for %s", szName);
+}
+
+static int __db_util_open(sqlite3 *pDB)
+{
+       int rc = 0;
+
+       if (pDB == NULL) {
+               DB_UTIL_TRACE_WARNING("Invalid input param error");
+               return DB_UTIL_ERROR;
+       }
+
+       /* Register Busy handler */
+       rc = sqlite3_busy_handler(pDB, __db_util_busyhandler, NULL);
+       if (SQLITE_OK != rc) {
+               DB_UTIL_TRACE_WARNING("Fail to register busy handler\n");
+               sqlite3_close(pDB);
+               return rc;
+       }
+
+#ifdef SET_PERSIST_JOURNAL_MODE
+       /* Code to change default journal mode of sqlite3 is enabled so this option is disabled */
+       /* Enable persist journal mode */
+       rc = sqlite3_exec(pDB, "PRAGMA journal_mode = PERSIST",
+                       NULL, NULL, &pszErrorMsg);
+       if (SQLITE_OK != rc) {
+               DB_UTIL_TRACE_WARNING("Fail to change journal mode: %d, %d, %s, %s\n",
+                                                               sqlite3_errcode(pDB),
+                                                               sqlite3_extended_errcode(pDB),
+                                                               pszErrorMsg,
+                                                               sqlite3_errmsg(pDB));
+               sqlite3_free(pszErrorMsg);
+               sqlite3_close(pDB);
+               return rc;
+       }
+#endif
+
+       sqlite3_collation_needed(pDB, NULL, __db_util_collation_cb);
+
+#if 0
+       if (DB_UTIL_OK != rc) {
+               DB_UTIL_TRACE_WARNING("Fail to create collation");
+               return rc;
+       }
+#endif
+
+       return DB_UTIL_OK;
+}
+
+int db_util_open(const char *pszFilePath, sqlite3 **ppDB, int nOption)
+{
+       if ((pszFilePath == NULL) || (ppDB == NULL)) {
+               DB_UTIL_TRACE_WARNING("Invalid input param error");
+               return DB_UTIL_ERROR;
+       }
+
+       if ((geteuid() != 0) && (access(pszFilePath, R_OK))) {
+               if (errno == EACCES) {
+                       DB_UTIL_TRACE_ERROR("file access permission error");
+                       return SQLITE_PERM;
+               }
+       }
+
+       /* Open DB */
+       int rc = sqlite3_open(pszFilePath, ppDB);
+       if (SQLITE_OK != rc) {
+               return rc;
+       }
+
+       rc = __db_util_open(*ppDB);
+
+       return rc;
+}
+
+int db_util_open_with_options(const char *pszFilePath, sqlite3 **ppDB,
+                               int flags, const char *zVfs)
+{
+       if ((pszFilePath == NULL) || (ppDB == NULL)) {
+               DB_UTIL_TRACE_WARNING("sqlite3 handle null error");
+               return DB_UTIL_ERROR;
+       }
+
+       /* Open DB */
+       int rc = sqlite3_open_v2(pszFilePath, ppDB, flags, zVfs);
+       if (SQLITE_OK != rc) {
+               return rc;
+       }
+
+       rc = __db_util_open(*ppDB);
+
+       return rc;
+}
+
+int db_util_close(sqlite3 *pDB)
+{
+       /* Close DB */
+       int rc = sqlite3_close(pDB);
+       if (SQLITE_OK != rc) {
+               DB_UTIL_TRACE_WARNING("Fail to close DB\n");
+               return rc;
+       }
+
+       return DB_UTIL_OK;
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..592da0d
--- /dev/null
@@ -0,0 +1,26 @@
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(/usr/include/vconf)
+
+pkg_check_modules(gtest_pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n vconf)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
+
+#=======================================================================================#
+SET(VCONF_MOCK "vconf-mock")
+SET(VCONF_MOCK_SRCS vconf.c )
+SET(VCONF_MOCK_CFLAGS "${CMAKE_C_FLAGS}")
+ADD_LIBRARY(${VCONF_MOCK} SHARED ${VCONF_MOCK_SRCS})
+SET_TARGET_PROPERTIES(${VCONF_MOCK} PROPERTIES
+    COMPILE_FLAGS ${VCONF_MOCK_CFLAGS}
+)
+TARGET_LINK_LIBRARIES(${VCONF_MOCK} ${gtest_pkgs_LIBRARIES} -ldl)
+#=======================================================================================#
+SET(DB-UTIL_GTEST "db-util-gtest")
+SET(DB-UTIL_GTEST_SRCS db-util-gtest.cpp)
+ADD_EXECUTABLE(${DB-UTIL_GTEST} ${DB-UTIL_GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${DB-UTIL_GTEST} ${gtest_pkgs_LIBRARIES} pthread gtest SLP-db-util )
+#=======================================================================================#
diff --git a/tests/db-util-gtest.cpp b/tests/db-util-gtest.cpp
new file mode 100644 (file)
index 0000000..7000986
--- /dev/null
@@ -0,0 +1,406 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include "gtest/gtest.h"
+
+
+#include <db-util.h>
+#include <vconf.h>
+
+#define FILE_LEN 255
+#define COL_NAME_LEN 255
+#define BUF_LEN 255
+
+//=======================================================================================
+class DbUtil : public ::testing::Test {
+       public:
+               char    pszFilePath[FILE_LEN + 1];
+               sqlite3 *db;
+               int     nOption;
+               int     flags;
+               const char* zVfs;
+               char    col_name[COL_NAME_LEN + 1];
+
+               DbUtil() {
+                       strncpy(pszFilePath, "test.db", FILE_LEN);
+                       db = NULL;
+                       nOption = 0;
+                       flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
+
+                       zVfs = NULL;
+               }
+
+               void SetUp() {
+               }
+
+               void TearDown() {
+                       int rc;
+                       rc = system("rm -f test.db");
+                       rc = system("rm -f test.db-journal");
+               }
+};
+//=======================================================================================
+// Testing for util_func.c
+//=======================================================================================
+TEST_F(DbUtil, db_util_open_p) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n1) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open(".", &db, nOption);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n2) {
+       int rc;
+
+       // Invalid db pointer
+       rc = db_util_open(pszFilePath, NULL, nOption);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_close_n) {
+       int rc;
+
+       // Invalid db close
+       rc = db_util_close(NULL);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_p) {
+       int rc;
+
+       rc = db_util_open_with_options(pszFilePath, &db, flags, zVfs);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_n1) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open_with_options(".", &db, flags, zVfs);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_with_options_n2) {
+       int rc;
+
+       // Invalid db name
+       rc = db_util_open_with_options(pszFilePath, NULL, flags, zVfs);
+       ASSERT_NE ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_open_n4) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // In case of (geteuid() != 0) && access(pszFilePath, R_OK)
+       system("chmod 000 test.db");
+
+       uid_t uid = getuid();
+       setuid(1000);
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+
+       setuid(uid);
+       ASSERT_EQ ( SQLITE_PERM , rc );
+}
+
+TEST_F(DbUtil, db_util_busyhandler) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+
+       sqlite3 *db1;
+       rc = db_util_open(pszFilePath, &db1, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       sqlite3_exec(db1, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+       sqlite3_exec(db1, "END EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
+       db_util_close(db1);
+
+       sqlite3_exec(db, "END TRANSACTION;", NULL, NULL, NULL);
+       db_util_close(db);
+}
+//=======================================================================================
+// Testing for collation.c
+//=======================================================================================
+
+int run_query(sqlite3 *db, char* col_name) {
+
+       int rc;
+
+       sqlite3_stmt *stmt = NULL;
+       char sql[BUF_LEN+1];
+       snprintf( sql, BUF_LEN, "SELECT key, value FROM collation order by value COLLATE %s", col_name);
+    rc = sqlite3_prepare(db, sql, -1, &stmt, 0);
+       if(rc == SQLITE_OK ){
+               rc = sqlite3_step(stmt);
+               while(rc == SQLITE_ROW){
+#if 0
+                       printf("key : [%s] : Value [%s]\n",
+                                       sqlite3_column_text(stmt,0),
+                                       sqlite3_column_text(stmt,1) );
+#endif
+                       rc = sqlite3_step(stmt);
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+TEST_F(DbUtil, db_util_create_collation_p1) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p2) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AS_CI_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p3) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p4) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_LC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p5) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_UCA_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p6) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AS_CI_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p7) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_p8) {
+       int rc;
+
+       rc = system("./test-collation-db.sh");
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // set vconf data
+       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
+
+       strncpy(col_name,"COL_LS_AI_CI_LC_UTF16", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF16, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = run_query(db, col_name);
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n1) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // vconf error
+       vconf_set_str("db/menu_widget/language", "" );
+
+       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n2) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_type error
+       strncpy(col_name,"COL_KO_IC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n3) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_type error
+       strncpy(col_name,"COL_KO_IC_LC_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC_LC, DB_UTIL_COL_UTF8, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+TEST_F(DbUtil, db_util_create_collation_n4) {
+       int rc;
+
+       rc = db_util_open(pszFilePath, &db, nOption);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+
+       // collate_textrep error
+       strncpy(col_name, "COL_UCA_UTF8", COL_NAME_LEN);
+       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, (db_util_collate_textrep)3, col_name );
+       ASSERT_EQ ( DB_UTIL_ERROR , rc );
+
+       rc = db_util_close(db);
+       ASSERT_EQ ( DB_UTIL_OK , rc );
+}
+
+//=======================================================================================
+int main(int argc, char** argv) {
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/tests/run_coverage.sh b/tests/run_coverage.sh
new file mode 100755 (executable)
index 0000000..f93918f
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+pushd ../
+RootDir=$PWD
+popd
+
+# Create vconf keys
+# if [ -x "/usr/bin/buxton2ctl" ]
+# then
+# /usr/bin/buxton2ctl -i -d create-string "system"  "db/menu_widget/language"   "en_US.UTF-8"  "http://tizen.org/privilege/internal/default/public" "http://tizen.org/privilege/systemsettings.admin"
+# fi
+
+unitTestFile=db-util-gtest
+if [ ! -x  "./$unitTestFile" ]
+then
+    echo "$unitTestFile file does not exist!"
+    exit -1
+fi
+
+LD_LIBRARY_PATH=../:$LD_LIBRARY_PATH LD_PRELOAD=./libvconf-mock.so ./$unitTestFile
+
+CMakeDir=${RootDir}/CMakeFiles/SLP-db-util.dir
+CoverageDir=${RootDir}/coverage
+
+pushd $CMakeDir
+    for obj in `ls *.o`
+    do
+        gcov -b -c $obj
+    done
+
+    if [ -f /usr/bin/lcov ]
+    then
+        lcov -c -d . -o cov.info
+        genhtml cov.info -o ${CoverageDir}
+        echo "Coverage test result created! [${CoverageDir}]"
+    else
+        echo "lcov does not exist!"
+    fi
+popd
diff --git a/tests/test-collation-db.sh b/tests/test-collation-db.sh
new file mode 100755 (executable)
index 0000000..d549f4d
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+db_name=test.db
+tableName=collation
+
+sqlite3 $db_name << EOF
+DROP TABLE IF EXISTS ${tableName};
+
+CREATE TABLE IF NOT EXISTS ${tableName} (
+key CHAR not NULL,
+value CHAR );
+
+PRAGMA synchronous=OFF;
+PRAGMA count_changes=OFF;
+PRAGMA journal_mode=MEMORY;
+PRAGMA temp_store=MEMORY;
+
+BEGIN TRANSACTION;
+INSERT INTO ${tableName} ( key, value) values ( "test_01", "테스트 1");
+INSERT INTO ${tableName} ( key, value) values ( "test_04", "테스트 01");
+INSERT INTO ${tableName} ( key, value) values ( "test_07", "테스트 001");
+INSERT INTO ${tableName} ( key, value) values ( "test_02", "테스트 2");
+INSERT INTO ${tableName} ( key, value) values ( "test_08", "테스트 002");
+INSERT INTO ${tableName} ( key, value) values ( "test_05", "테스트 02");
+INSERT INTO ${tableName} ( key, value) values ( "test_09", "테스트 003");
+INSERT INTO ${tableName} ( key, value) values ( "test_03", "테스트 3");
+INSERT INTO ${tableName} ( key, value) values ( "test_06", "테스트 03");
+COMMIT TRANSACTION;
+EOF
diff --git a/tests/vconf.c b/tests/vconf.c
new file mode 100644 (file)
index 0000000..fbcd1ef
--- /dev/null
@@ -0,0 +1,532 @@
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <sqlite3.h>
+
+#ifndef EXPORT
+#  define EXPORT __attribute__((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define VCONF_OK                    0
+#define VCONF_ERROR                 -1
+#define VCONF_ERROR_WRONG_PREFIX    -2
+#define VCONF_ERROR_WRONG_TYPE      -3
+#define VCONF_ERROR_WRONG_VALUE     -4
+#define VCONF_ERROR_NOT_INITIALIZED -5
+#define VCONF_ERROR_NO_MEM          -6
+#define VCONF_ERROR_FILE_PERM       -11
+#define VCONF_ERROR_FILE_BUSY       -12
+#define VCONF_ERROR_FILE_NO_MEM     -13
+#define VCONF_ERROR_FILE_NO_ENT     -14
+#define VCONF_ERROR_FILE_OPEN       -21
+#define VCONF_ERROR_FILE_FREAD      -22
+#define VCONF_ERROR_FILE_FGETS      -23
+#define VCONF_ERROR_FILE_WRITE      -24
+#define VCONF_ERROR_FILE_SYNC       -25
+#define VCONF_ERROR_FILE_CLOSE      -26
+#define VCONF_ERROR_FILE_ACCESS     -27
+#define VCONF_ERROR_FILE_CHMOD      -28
+#define VCONF_ERROR_FILE_LOCK       -29
+#define VCONF_ERROR_FILE_REMOVE     -30
+#define VCONF_ERROR_FILE_SEEK       -31
+#define VCONF_ERROR_FILE_TRUNCATE   -32
+#define VCONF_ERROR_NOT_SUPPORTED   -33
+
+#define MAX_BUF_LEN 256
+
+enum get_option_t {
+       VCONF_GET_KEY = 0, /**< Get only keys */
+       VCONF_GET_ALL,     /**< Get keys and directories */
+       VCONF_GET_DIR      /**< Get only directories */
+};
+typedef enum get_option_t get_option_t;
+enum vconf_t {
+       VCONF_TYPE_NONE = 0,    /**< Vconf none type for Error detection */
+       VCONF_TYPE_STRING = 40, /**< Vconf string type */
+       VCONF_TYPE_INT = 41,    /**< Vconf integer type */
+       VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */
+       VCONF_TYPE_BOOL = 43,   /**< Vconf boolean type */
+       VCONF_TYPE_DIR          /**< Vconf directory type */
+};
+
+typedef struct _keynode_t {
+       char *keyname;           /**< Keyname for keynode */
+       int type;                /**< Keynode type */
+       union {
+               int i;               /**< Integer type */
+               int b;               /**< Bool type */
+               double d;            /**< Double type */
+               char *s;             /**< String type */
+       } value;                 /**< Value for keynode */
+} keynode_t;
+typedef struct _keylist_t keylist_t;
+
+typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data);
+
+static char g_str[MAX_BUF_LEN+1];
+
+/************************************************
+ * keynode handling APIs                        *
+ ************************************************/
+EXPORT char *vconf_keynode_get_name(keynode_t *keynode){
+    return NULL;
+}
+
+EXPORT int vconf_keynode_get_type(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT int vconf_keynode_get_int(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT double vconf_keynode_get_dbl(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT int vconf_keynode_get_bool(keynode_t *keynode){
+    return 0;
+}
+
+EXPORT char *vconf_keynode_get_str(keynode_t *keynode){
+    return NULL;
+}
+
+
+/************************************************
+ * keylist handling APIs
+ ************************************************/
+keylist_t *vconf_keylist_new(void){
+    return NULL;
+}
+
+/**
+ * @code
+    int r =0;
+    keylist_t* pKeyList = NULL;
+    pKeyList = vconf_keylist_new();
+
+    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
+    if (r) {
+    tet_infoline("vconf_get() failed in positive test case");
+    tet_result(TET_FAIL);
+    return;
+    }
+
+    vconf_keylist_nextnode(pKeyList);
+    vconf_keylist_nextnode(pKeyList);
+
+    // Move first position from KeyList
+    r = vconf_keylist_rewind(pKeyList);
+    if (r<0) {
+    tet_infoline("vconf_keylist_rewind() failed in positive test case");
+    tet_result(TET_FAIL);
+    return;
+    }
+
+    while(vconf_keylist_nextnode(pKeyList)) ;
+ * @endcode
+ */
+EXPORT int vconf_keylist_rewind(keylist_t *keylist){
+    return 0;
+}
+
+EXPORT int vconf_keylist_free(keylist_t *keylist){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+    int r = 0;
+    int nResult = 0;
+    keylist_t* pKeyList = NULL;
+    keynode_t *pKeyNode;
+
+    pKeyList = vconf_keylist_new();
+    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
+    if (r<0) {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+    }
+
+    r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
+    if (r<0) {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+    }
+
+    if (r == VCONF_TYPE_NONE) {
+        printf("vconf key not found");
+        return -1;
+    }
+
+    nResult = vconf_keynode_get_int(pKeyNode);
+    if(nResult !=KEY_02_INT_VALUE)
+    {
+        printf("vconf_get() failed in positive test case");
+        return -1;
+
+    }
+
+    vconf_keylist_free(pKeyList);
+    return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
+               keynode_t **return_node){
+    return 0;
+}
+
+EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist){
+    return NULL;
+}
+
+EXPORT int vconf_keylist_add_int(keylist_t *keylist, const char *keyname,
+               const int value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname,
+               const int value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname,
+               const double value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_str(keylist_t *keylist, const char *keyname,
+               const char *value){
+    return 0;
+}
+
+EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname){
+    return 0;
+}
+
+EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname){
+    return 0;
+}
+
+/************************************************
+ * setting APIs                                 *
+ ************************************************/
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+   keylist_t *kl=NULL;
+   const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
+
+   // Transaction Test(all or nothing is written)
+   kl = vconf_keylist_new();
+
+   vconf_keylist_add_int(kl, keyname_list[0], 1);
+   vconf_keylist_add_str(kl, keyname_list[1], "transaction Test");
+   vconf_keylist_add_dbl(kl, keyname_list[2], 0.3);
+   if(vconf_set(kl))
+      fprintf(stderr, "nothing is written\n");
+   else
+      printf("everything is written\n");
+
+   vconf_keylist_free(kl);
+
+   // You can set items which have different backend.
+   kl = vconf_keylist_new();
+
+   vconf_keylist_add_int(kl, "memory/a/xxx1", 4);
+   vconf_keylist_add_str(kl, "file/a/xxx2", "test 3");
+   vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3);
+   vconf_set(kl)
+
+   vconf_keylist_free(kl);
+   return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_set(keylist_t *keylist){
+    return 0;
+}
+
+EXPORT int vconf_set_int(const char *in_key, const int intval){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+ const char *key1_name="memory/test/key1";
+
+ int main(int argc, char **argv)
+ {
+   int key1_value;
+
+   if(vconf_set_bool(key1_name, 1))
+      fprintf(stderr, "vconf_set_bool FAIL\n");
+   else
+      printf("vconf_set_bool OK\n");
+
+   if(vconf_get_bool(key1_name, &key1_value))
+      fprintf(stderr, "vconf_get_bool FAIL\n");
+   else
+      printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
+
+   return 0;
+ }
+ * @endcode
+ */
+EXPORT int vconf_set_bool(const char *in_key, const int boolval){
+    return 0;
+}
+
+EXPORT int vconf_set_dbl(const char *in_key, const double dblval){
+    return 0;
+}
+
+EXPORT int vconf_set_str(const char *in_key, const char *strval){
+
+    strncpy( g_str, strval, MAX_BUF_LEN );
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+int main()
+{
+   keylist_t *kl=NULL;
+   keynode_t *temp_node;
+   const char *vconfkeys1="db/test/key1";
+   const char *parent_dir="db/test";
+
+   kl = vconf_keylist_new();
+   if(vconf_get(kl, parent_dir, 0))
+      fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
+   else
+      printf("vconf_get OK(%s)", vconfkeys1);
+
+   while((temp_node = vconf_keylist_nextnode(kl))) {
+      switch(vconf_keynode_get_type(temp_node)) {
+    case VCONF_TYPE_INT:
+        printf("key = %s, value = %d\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
+        break;
+    case VCONF_TYPE_BOOL:
+        printf("key = %s, value = %d\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
+        break;
+    case VCONF_TYPE_DOUBLE:
+        printf("key = %s, value = %f\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
+        break;
+    case VCONF_TYPE_STRING:
+        printf("key = %s, value = %s\n",
+            vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
+        break;
+    default:
+        printf("Unknown Type\n");
+      }
+   }
+   vconf_keylist_free(kl);
+}
+ * @endcode
+ */
+EXPORT int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option){
+    return 0;
+}
+
+/**
+ * @code
+#include <stdio.h>
+#include <vconf.h>
+
+const char *key1_name="db/test/key1";
+
+int main(int argc, char **argv)
+{
+   int key1_value;
+
+   if(vconf_set_int(key1_name,1))
+      fprintf(stderr, "vconf_set_int FAIL\n");
+   else
+      printf("vconf_set_int OK\n");
+
+   if(vconf_get_int(key1_name, &key1_value))
+      fprintf(stderr, "vconf_get_int FAIL\n");
+   else
+      printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
+
+   return 0;
+}
+ * @endcode
+ */
+EXPORT int vconf_get_int(const char *in_key, int *intval){
+    return 0;
+}
+
+EXPORT int vconf_get_bool(const char *in_key, int *boolval){
+    return 0;
+}
+
+EXPORT int vconf_get_dbl(const char *in_key, double *dblval){
+    return 0;
+}
+
+/**
+ * @code
+   #include <stdio.h>
+   #include <vconf.h>
+
+   char *get_str=vconf_get_str("db/test/test1");
+   if(get_str) {
+      printf("vconf_get_str OK(value = %s)", get_str);
+      free(get_str);
+   }else
+      fprintf(stderr, "vconf_get_str FAIL");
+ * @endcode
+ */
+EXPORT char *vconf_get_str(const char *in_key){
+
+#if 1
+    char *str = (char*)malloc(MAX_BUF_LEN+1);
+    strcpy( str, g_str);
+
+    return str;
+#endif
+}
+
+EXPORT int vconf_unset(const char *in_key){
+    return 0;
+}
+
+/**
+ * @code
+ if(vconf_set_int("file/test/key1",1))
+    fprintf(stderr, "vconf_set_int FAIL\n");
+ else {
+    printf("vconf_set_int OK\n");
+    vconf_sync_key("file/test/key1");
+ }
+ * @endcode
+ */
+EXPORT int vconf_sync_key(const char *in_key){
+    return 0;
+}
+
+/**
+ * @code
+   vconf_set_int("db/test/key1",1);
+   vconf_set_int("db/test/test1/key1",1);
+   vconf_set_int("db/test/test2/key1",1);
+   vconf_set_int("db/test/key2",1);
+
+   if(vconf_unset_recursive("db/test"))
+      fprintf(stderr, "vconf_unset_recursive FAIL\n");
+   else
+      printf("vconf_unset_recursive OK(deleted db/test\n");
+
+ * @endcode
+ */
+EXPORT int vconf_unset_recursive(const char *in_dir){
+    return 0;
+}
+
+/**
+ * @code
+ void test_cb(keynode_t *key, void* data)
+ {
+    switch(vconf_keynode_get_type(key))
+    {
+       case VCONF_TYPE_INT:
+    printf("key = %s, value = %d(int)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_int(key));
+    break;
+       case VCONF_TYPE_BOOL:
+    printf("key = %s, value = %d(bool)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
+    break;
+       case VCONF_TYPE_DOUBLE:
+    printf("key = %s, value = %f(double)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
+    break;
+       case VCONF_TYPE_STRING:
+    printf("key = %s, value = %s(string)\n",
+        vconf_keynode_get_name(key), vconf_keynode_get_str(key));
+    break;
+       default:
+    fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
+    break;
+    }
+    return;
+ }
+
+ int main()
+ {
+    int i;
+    GMainLoop *event_loop;
+
+    g_type_init();
+
+    vconf_notify_key_changed("db/test/test1", test_cb, NULL);
+
+    event_loop = g_main_loop_new(NULL, FALSE);
+    g_main_loop_run(event_loop);
+
+    vconf_ignore_key_changed("db/test/test1", test_cb);
+    return 0;
+ }
+ * @endcode
+ */
+EXPORT int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb,
+                void *user_data){
+    return 0;
+}
+
+EXPORT int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb){
+    return 0;
+}
+
+EXPORT int vconf_get_ext_errno(void){
+    return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
deleted file mode 100644 (file)
index 609a0a0..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
-
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(/usr/include/vconf)
-
-pkg_check_modules(gtest_pkgs REQUIRED sqlite3 dlog glib-2.0 icu-i18n vconf)
-INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
-
-#=======================================================================================#
-SET(VCONF_MOCK "vconf-mock")
-SET(VCONF_MOCK_SRCS vconf.c )
-SET(VCONF_MOCK_CFLAGS "${CMAKE_C_FLAGS}")
-ADD_LIBRARY(${VCONF_MOCK} SHARED ${VCONF_MOCK_SRCS})
-SET_TARGET_PROPERTIES(${VCONF_MOCK} PROPERTIES
-    COMPILE_FLAGS ${VCONF_MOCK_CFLAGS}
-)
-TARGET_LINK_LIBRARIES(${VCONF_MOCK} ${gtest_pkgs_LIBRARIES} -ldl)
-#=======================================================================================#
-SET(DB-UTIL_GTEST "db-util_gtest")
-SET(DB-UTIL_GTEST_SRCS db-util_gtest.cpp)
-ADD_EXECUTABLE(${DB-UTIL_GTEST} ${DB-UTIL_GTEST_SRCS})
-TARGET_LINK_LIBRARIES(${DB-UTIL_GTEST} ${gtest_pkgs_LIBRARIES} pthread gtest SLP-db-util )
-#=======================================================================================#
diff --git a/unittest/db-util_gtest.cpp b/unittest/db-util_gtest.cpp
deleted file mode 100644 (file)
index 2eadb35..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include "gtest/gtest.h"
-
-
-#include <db-util.h>
-#include <vconf.h>
-
-#define FILE_LEN 255
-#define COL_NAME_LEN 255
-#define BUF_LEN 255
-
-//=======================================================================================
-class DbUtil : public ::testing::Test {
-       public:
-               char    pszFilePath[FILE_LEN + 1];
-               sqlite3 *db;
-               int     nOption;
-               int     flags;
-               const char* zVfs;
-               char    col_name[COL_NAME_LEN + 1];
-
-               DbUtil() {
-                       strncpy(pszFilePath, "test.db", FILE_LEN);
-                       db = NULL;
-                       nOption = 0;
-                       flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
-
-                       zVfs = NULL;
-               }
-
-               void SetUp() {
-               }
-
-               void TearDown() {
-                       int rc;
-                       rc = system("rm -f test.db");
-                       rc = system("rm -f test.db-journal");
-               }
-};
-//=======================================================================================
-// Testing for util_func.c
-//=======================================================================================
-TEST_F(DbUtil, db_util_open_p) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n1) {
-       int rc;
-
-       // Invalid db name
-       rc = db_util_open(".", &db, nOption);
-       ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n2) {
-       int rc;
-
-       // Invalid db pointer
-       rc = db_util_open(pszFilePath, NULL, nOption);
-       ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_close_n) {
-       int rc;
-
-       // Invalid db close
-       rc = db_util_close(NULL);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_p) {
-       int rc;
-
-       rc = db_util_open_with_options(pszFilePath, &db, flags, zVfs);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_n1) {
-       int rc;
-
-       // Invalid db name
-       rc = db_util_open_with_options(".", &db, flags, zVfs);
-       ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_with_options_n2) {
-       int rc;
-
-       // Invalid db name
-       rc = db_util_open_with_options(pszFilePath, NULL, flags, zVfs);
-       ASSERT_NE ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_open_n4) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // In case of (geteuid() != 0) && access(pszFilePath, R_OK)
-       system("chmod 000 test.db");
-
-       uid_t uid = getuid();
-       setuid(1000);
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-
-       setuid(uid);
-       ASSERT_EQ ( SQLITE_PERM , rc );
-}
-
-TEST_F(DbUtil, db_util_busyhandler) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
-
-       sqlite3 *db1;
-       rc = db_util_open(pszFilePath, &db1, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       sqlite3_exec(db1, "BEGIN EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
-       sqlite3_exec(db1, "END EXCLUSIVE TRANSACTION;", NULL, NULL, NULL);
-       db_util_close(db1);
-
-       sqlite3_exec(db, "END TRANSACTION;", NULL, NULL, NULL);
-       db_util_close(db);
-}
-//=======================================================================================
-// Testing for collation.c
-//=======================================================================================
-
-int run_query(sqlite3 *db, char* col_name) {
-
-       int rc;
-
-       sqlite3_stmt *stmt = NULL;
-       char sql[BUF_LEN+1];
-       snprintf( sql, BUF_LEN, "SELECT key, value FROM collation order by value COLLATE %s", col_name);
-    rc = sqlite3_prepare(db, sql, -1, &stmt, 0);
-       if(rc == SQLITE_OK ){
-               rc = sqlite3_step(stmt);
-               while(rc == SQLITE_ROW){
-#if 0
-                       printf("key : [%s] : Value [%s]\n",
-                                       sqlite3_column_text(stmt,0),
-                                       sqlite3_column_text(stmt,1) );
-#endif
-                       rc = sqlite3_step(stmt);
-               }
-       }
-
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-TEST_F(DbUtil, db_util_create_collation_p1) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p2) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AS_CI_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p3) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AI_CI_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p4) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AI_CI_LC_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p5) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_UCA_UTF16", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF16, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p6) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AS_CI_UTF16", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AS_CI, DB_UTIL_COL_UTF16, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p7) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AI_CI_UTF16", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI, DB_UTIL_COL_UTF16, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_p8) {
-       int rc;
-
-       rc = system("./test_collation_db.sh");
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // set vconf data
-       vconf_set_str("db/menu_widget/language", "en_US.UTF-8" );
-
-       strncpy(col_name,"COL_LS_AI_CI_LC_UTF16", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_LS_AI_CI_LC, DB_UTIL_COL_UTF16, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = run_query(db, col_name);
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_n1) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // vconf error
-       vconf_set_str("db/menu_widget/language", "" );
-
-       strncpy(col_name,"COL_UCA_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_n2) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // collate_type error
-       strncpy(col_name,"COL_KO_IC_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_ERROR , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_n3) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // collate_type error
-       strncpy(col_name,"COL_KO_IC_LC_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_KO_IC_LC, DB_UTIL_COL_UTF8, col_name );
-       ASSERT_EQ ( DB_UTIL_ERROR , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-TEST_F(DbUtil, db_util_create_collation_n4) {
-       int rc;
-
-       rc = db_util_open(pszFilePath, &db, nOption);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-
-       // collate_textrep error
-       strncpy(col_name, "COL_UCA_UTF8", COL_NAME_LEN);
-       rc = db_util_create_collation(db, DB_UTIL_COL_UCA, (db_util_collate_textrep)3, col_name );
-       ASSERT_EQ ( DB_UTIL_ERROR , rc );
-
-       rc = db_util_close(db);
-       ASSERT_EQ ( DB_UTIL_OK , rc );
-}
-
-//=======================================================================================
-int main(int argc, char** argv) {
-       ::testing::InitGoogleTest(&argc, argv);
-       return RUN_ALL_TESTS();
-}
diff --git a/unittest/run_coverage.sh b/unittest/run_coverage.sh
deleted file mode 100755 (executable)
index 700484e..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-pushd ../
-RootDir=$PWD
-popd
-
-# Create vconf keys
-# if [ -x "/usr/bin/buxton2ctl" ]
-# then
-# /usr/bin/buxton2ctl -i -d create-string "system"  "db/menu_widget/language"   "en_US.UTF-8"  "http://tizen.org/privilege/internal/default/public" "http://tizen.org/privilege/systemsettings.admin"
-# fi
-
-unitTestFile=db-util_gtest
-if [ ! -x  "./$unitTestFile" ]
-then
-    echo "$unitTestFile file does not exist!"
-    exit -1
-fi
-
-LD_LIBRARY_PATH=../:$LD_LIBRARY_PATH LD_PRELOAD=./libvconf-mock.so ./$unitTestFile
-
-CMakeDir=${RootDir}/CMakeFiles/SLP-db-util.dir
-CoverageDir=${RootDir}/coverage
-
-pushd $CMakeDir
-    for obj in `ls *.o`
-    do
-        gcov -b -c $obj
-    done
-
-    if [ -f /usr/bin/lcov ]
-    then
-        lcov -c -d . -o cov.info
-        genhtml cov.info -o ${CoverageDir}
-        echo "Coverage test result created! [${CoverageDir}]"
-    else
-        echo "lcov does not exist!"
-    fi
-popd
-
diff --git a/unittest/test_collation_db.sh b/unittest/test_collation_db.sh
deleted file mode 100755 (executable)
index f75dfab..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-
-db_name=test.db
-tableName=collation
-
-sqlite3 $db_name << EOF
-DROP TABLE IF EXISTS ${tableName};
-
-CREATE TABLE IF NOT EXISTS ${tableName} (
-key CHAR not NULL,
-value CHAR );
-
-PRAGMA synchronous=OFF;
-PRAGMA count_changes=OFF;
-PRAGMA journal_mode=MEMORY;
-PRAGMA temp_store=MEMORY;
-
-BEGIN TRANSACTION;
-INSERT INTO ${tableName} ( key, value) values ( "test_01", "테스트 1");
-INSERT INTO ${tableName} ( key, value) values ( "test_04", "테스트 01");
-INSERT INTO ${tableName} ( key, value) values ( "test_07", "테스트 001");
-INSERT INTO ${tableName} ( key, value) values ( "test_02", "테스트 2");
-INSERT INTO ${tableName} ( key, value) values ( "test_08", "테스트 002");
-INSERT INTO ${tableName} ( key, value) values ( "test_05", "테스트 02");
-INSERT INTO ${tableName} ( key, value) values ( "test_09", "테스트 003");
-INSERT INTO ${tableName} ( key, value) values ( "test_03", "테스트 3");
-INSERT INTO ${tableName} ( key, value) values ( "test_06", "테스트 03");
-COMMIT TRANSACTION;
-EOF
-
diff --git a/unittest/vconf.c b/unittest/vconf.c
deleted file mode 100644 (file)
index c005f49..0000000
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * Copyright (C) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <errno.h>
-
-#include <sqlite3.h>
-
-#ifndef EXPORT
-#  define EXPORT __attribute__((visibility("default")))
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define VCONF_OK                    0
-#define VCONF_ERROR                 -1
-#define VCONF_ERROR_WRONG_PREFIX    -2
-#define VCONF_ERROR_WRONG_TYPE      -3
-#define VCONF_ERROR_WRONG_VALUE     -4
-#define VCONF_ERROR_NOT_INITIALIZED -5
-#define VCONF_ERROR_NO_MEM          -6
-#define VCONF_ERROR_FILE_PERM       -11
-#define VCONF_ERROR_FILE_BUSY       -12
-#define VCONF_ERROR_FILE_NO_MEM     -13
-#define VCONF_ERROR_FILE_NO_ENT     -14
-#define VCONF_ERROR_FILE_OPEN       -21
-#define VCONF_ERROR_FILE_FREAD      -22
-#define VCONF_ERROR_FILE_FGETS      -23
-#define VCONF_ERROR_FILE_WRITE      -24
-#define VCONF_ERROR_FILE_SYNC       -25
-#define VCONF_ERROR_FILE_CLOSE      -26
-#define VCONF_ERROR_FILE_ACCESS     -27
-#define VCONF_ERROR_FILE_CHMOD      -28
-#define VCONF_ERROR_FILE_LOCK       -29
-#define VCONF_ERROR_FILE_REMOVE     -30
-#define VCONF_ERROR_FILE_SEEK       -31
-#define VCONF_ERROR_FILE_TRUNCATE   -32
-#define VCONF_ERROR_NOT_SUPPORTED   -33
-
-#define MAX_BUF_LEN 256
-
-enum get_option_t {
-       VCONF_GET_KEY = 0, /**< Get only keys */
-       VCONF_GET_ALL,     /**< Get keys and directories */
-       VCONF_GET_DIR      /**< Get only directories */
-};
-typedef enum get_option_t get_option_t;
-enum vconf_t {
-       VCONF_TYPE_NONE = 0,    /**< Vconf none type for Error detection */
-       VCONF_TYPE_STRING = 40, /**< Vconf string type */
-       VCONF_TYPE_INT = 41,    /**< Vconf integer type */
-       VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */
-       VCONF_TYPE_BOOL = 43,   /**< Vconf boolean type */
-       VCONF_TYPE_DIR          /**< Vconf directory type */
-};
-
-typedef struct _keynode_t {
-       char *keyname;           /**< Keyname for keynode */
-       int type;                /**< Keynode type */
-       union {
-               int i;               /**< Integer type */
-               int b;               /**< Bool type */
-               double d;            /**< Double type */
-               char *s;             /**< String type */
-       } value;                 /**< Value for keynode */
-} keynode_t;
-typedef struct _keylist_t keylist_t;
-
-typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data);
-
-static char g_str[MAX_BUF_LEN+1];
-
-/************************************************
- * keynode handling APIs                        *
- ************************************************/
-EXPORT char *vconf_keynode_get_name(keynode_t *keynode){
-    return NULL;
-}
-
-EXPORT int vconf_keynode_get_type(keynode_t *keynode){
-    return 0;
-}
-
-EXPORT int vconf_keynode_get_int(keynode_t *keynode){
-    return 0;
-}
-
-EXPORT double vconf_keynode_get_dbl(keynode_t *keynode){
-    return 0;
-}
-
-EXPORT int vconf_keynode_get_bool(keynode_t *keynode){
-    return 0;
-}
-
-EXPORT char *vconf_keynode_get_str(keynode_t *keynode){
-    return NULL;
-}
-
-
-/************************************************
- * keylist handling APIs
- ************************************************/
-keylist_t *vconf_keylist_new(void){
-    return NULL;
-}
-
-/**
- * @code
-    int r =0;
-    keylist_t* pKeyList = NULL;
-    pKeyList = vconf_keylist_new();
-
-    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
-    if (r) {
-    tet_infoline("vconf_get() failed in positive test case");
-    tet_result(TET_FAIL);
-    return;
-    }
-
-    vconf_keylist_nextnode(pKeyList);
-    vconf_keylist_nextnode(pKeyList);
-
-    // Move first position from KeyList
-    r = vconf_keylist_rewind(pKeyList);
-    if (r<0) {
-    tet_infoline("vconf_keylist_rewind() failed in positive test case");
-    tet_result(TET_FAIL);
-    return;
-    }
-
-    while(vconf_keylist_nextnode(pKeyList)) ;
- * @endcode
- */
-EXPORT int vconf_keylist_rewind(keylist_t *keylist){
-    return 0;
-}
-
-EXPORT int vconf_keylist_free(keylist_t *keylist){
-    return 0;
-}
-
-/**
- * @code
-#include <stdio.h>
-#include <vconf.h>
-
-int main()
-{
-    int r = 0;
-    int nResult = 0;
-    keylist_t* pKeyList = NULL;
-    keynode_t *pKeyNode;
-
-    pKeyList = vconf_keylist_new();
-    r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY);
-    if (r<0) {
-        printf("vconf_get() failed in positive test case");
-        return -1;
-    }
-
-    r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode);
-    if (r<0) {
-        printf("vconf_get() failed in positive test case");
-        return -1;
-    }
-
-    if (r == VCONF_TYPE_NONE) {
-        printf("vconf key not found");
-        return -1;
-    }
-
-    nResult = vconf_keynode_get_int(pKeyNode);
-    if(nResult !=KEY_02_INT_VALUE)
-    {
-        printf("vconf_get() failed in positive test case");
-        return -1;
-
-    }
-
-    vconf_keylist_free(pKeyList);
-    return 0;
-}
- * @endcode
- */
-EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname,
-               keynode_t **return_node){
-    return 0;
-}
-
-EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist){
-    return NULL;
-}
-
-EXPORT int vconf_keylist_add_int(keylist_t *keylist, const char *keyname,
-               const int value){
-    return 0;
-}
-
-EXPORT int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname,
-               const int value){
-    return 0;
-}
-
-EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname,
-               const double value){
-    return 0;
-}
-
-EXPORT int vconf_keylist_add_str(keylist_t *keylist, const char *keyname,
-               const char *value){
-    return 0;
-}
-
-EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname){
-    return 0;
-}
-
-EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname){
-    return 0;
-}
-
-/************************************************
- * setting APIs                                 *
- ************************************************/
-
-/**
- * @code
-#include <stdio.h>
-#include <vconf.h>
-
-int main()
-{
-   keylist_t *kl=NULL;
-   const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"};
-
-   // Transaction Test(all or nothing is written)
-   kl = vconf_keylist_new();
-
-   vconf_keylist_add_int(kl, keyname_list[0], 1);
-   vconf_keylist_add_str(kl, keyname_list[1], "transaction Test");
-   vconf_keylist_add_dbl(kl, keyname_list[2], 0.3);
-   if(vconf_set(kl))
-      fprintf(stderr, "nothing is written\n");
-   else
-      printf("everything is written\n");
-
-   vconf_keylist_free(kl);
-
-   // You can set items which have different backend.
-   kl = vconf_keylist_new();
-
-   vconf_keylist_add_int(kl, "memory/a/xxx1", 4);
-   vconf_keylist_add_str(kl, "file/a/xxx2", "test 3");
-   vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3);
-   vconf_set(kl)
-
-   vconf_keylist_free(kl);
-   return 0;
-}
- * @endcode
- */
-EXPORT int vconf_set(keylist_t *keylist){
-    return 0;
-}
-
-EXPORT int vconf_set_int(const char *in_key, const int intval){
-    return 0;
-}
-
-/**
- * @code
-#include <stdio.h>
-#include <vconf.h>
-
- const char *key1_name="memory/test/key1";
-
- int main(int argc, char **argv)
- {
-   int key1_value;
-
-   if(vconf_set_bool(key1_name, 1))
-      fprintf(stderr, "vconf_set_bool FAIL\n");
-   else
-      printf("vconf_set_bool OK\n");
-
-   if(vconf_get_bool(key1_name, &key1_value))
-      fprintf(stderr, "vconf_get_bool FAIL\n");
-   else
-      printf("vconf_get_bool OK(key1 value is %d)\n", key1_value);
-
-   return 0;
- }
- * @endcode
- */
-EXPORT int vconf_set_bool(const char *in_key, const int boolval){
-    return 0;
-}
-
-EXPORT int vconf_set_dbl(const char *in_key, const double dblval){
-    return 0;
-}
-
-EXPORT int vconf_set_str(const char *in_key, const char *strval){
-
-    strncpy( g_str, strval, MAX_BUF_LEN );
-    return 0;
-}
-
-/**
- * @code
-#include <stdio.h>
-#include <vconf.h>
-
-int main()
-{
-   keylist_t *kl=NULL;
-   keynode_t *temp_node;
-   const char *vconfkeys1="db/test/key1";
-   const char *parent_dir="db/test";
-
-   kl = vconf_keylist_new();
-   if(vconf_get(kl, parent_dir, 0))
-      fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1);
-   else
-      printf("vconf_get OK(%s)", vconfkeys1);
-
-   while((temp_node = vconf_keylist_nextnode(kl))) {
-      switch(vconf_keynode_get_type(temp_node)) {
-    case VCONF_TYPE_INT:
-        printf("key = %s, value = %d\n",
-            vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
-        break;
-    case VCONF_TYPE_BOOL:
-        printf("key = %s, value = %d\n",
-            vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
-        break;
-    case VCONF_TYPE_DOUBLE:
-        printf("key = %s, value = %f\n",
-            vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
-        break;
-    case VCONF_TYPE_STRING:
-        printf("key = %s, value = %s\n",
-            vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
-        break;
-    default:
-        printf("Unknown Type\n");
-      }
-   }
-   vconf_keylist_free(kl);
-}
- * @endcode
- */
-EXPORT int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option){
-    return 0;
-}
-
-/**
- * @code
-#include <stdio.h>
-#include <vconf.h>
-
-const char *key1_name="db/test/key1";
-
-int main(int argc, char **argv)
-{
-   int key1_value;
-
-   if(vconf_set_int(key1_name,1))
-      fprintf(stderr, "vconf_set_int FAIL\n");
-   else
-      printf("vconf_set_int OK\n");
-
-   if(vconf_get_int(key1_name, &key1_value))
-      fprintf(stderr, "vconf_get_int FAIL\n");
-   else
-      printf("vconf_get_int OK(key1 value is %d)\n", key1_value);
-
-   return 0;
-}
- * @endcode
- */
-EXPORT int vconf_get_int(const char *in_key, int *intval){
-    return 0;
-}
-
-EXPORT int vconf_get_bool(const char *in_key, int *boolval){
-    return 0;
-}
-
-EXPORT int vconf_get_dbl(const char *in_key, double *dblval){
-    return 0;
-}
-
-/**
- * @code
-   #include <stdio.h>
-   #include <vconf.h>
-
-   char *get_str=vconf_get_str("db/test/test1");
-   if(get_str) {
-      printf("vconf_get_str OK(value = %s)", get_str);
-      free(get_str);
-   }else
-      fprintf(stderr, "vconf_get_str FAIL");
- * @endcode
- */
-EXPORT char *vconf_get_str(const char *in_key){
-
-#if 1
-    char *str = (char*)malloc(MAX_BUF_LEN+1);
-    strcpy( str, g_str);
-
-    return str;
-#endif
-}
-
-EXPORT int vconf_unset(const char *in_key){
-    return 0;
-}
-
-/**
- * @code
- if(vconf_set_int("file/test/key1",1))
-    fprintf(stderr, "vconf_set_int FAIL\n");
- else {
-    printf("vconf_set_int OK\n");
-    vconf_sync_key("file/test/key1");
- }
- * @endcode
- */
-EXPORT int vconf_sync_key(const char *in_key){
-    return 0;
-}
-
-/**
- * @code
-   vconf_set_int("db/test/key1",1);
-   vconf_set_int("db/test/test1/key1",1);
-   vconf_set_int("db/test/test2/key1",1);
-   vconf_set_int("db/test/key2",1);
-
-   if(vconf_unset_recursive("db/test"))
-      fprintf(stderr, "vconf_unset_recursive FAIL\n");
-   else
-      printf("vconf_unset_recursive OK(deleted db/test\n");
-
- * @endcode
- */
-EXPORT int vconf_unset_recursive(const char *in_dir){
-    return 0;
-}
-
-/**
- * @code
- void test_cb(keynode_t *key, void* data)
- {
-    switch(vconf_keynode_get_type(key))
-    {
-       case VCONF_TYPE_INT:
-    printf("key = %s, value = %d(int)\n",
-        vconf_keynode_get_name(key), vconf_keynode_get_int(key));
-    break;
-       case VCONF_TYPE_BOOL:
-    printf("key = %s, value = %d(bool)\n",
-        vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
-    break;
-       case VCONF_TYPE_DOUBLE:
-    printf("key = %s, value = %f(double)\n",
-        vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
-    break;
-       case VCONF_TYPE_STRING:
-    printf("key = %s, value = %s(string)\n",
-        vconf_keynode_get_name(key), vconf_keynode_get_str(key));
-    break;
-       default:
-    fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
-    break;
-    }
-    return;
- }
-
- int main()
- {
-    int i;
-    GMainLoop *event_loop;
-
-    g_type_init();
-
-    vconf_notify_key_changed("db/test/test1", test_cb, NULL);
-
-    event_loop = g_main_loop_new(NULL, FALSE);
-    g_main_loop_run(event_loop);
-
-    vconf_ignore_key_changed("db/test/test1", test_cb);
-    return 0;
- }
- * @endcode
- */
-EXPORT int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb,
-                void *user_data){
-    return 0;
-}
-
-EXPORT int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb){
-    return 0;
-}
-
-EXPORT int vconf_get_ext_errno(void){
-    return 0;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-
diff --git a/unittest/vconf.sym b/unittest/vconf.sym
deleted file mode 100644 (file)
index 745cacf..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-VCONF_BUXTON_1.0 {
-       global:
-               vconf_keynode_get_name;
-               vconf_keynode_get_type;
-               vconf_keynode_get_int;
-               vconf_keynode_get_dbl;
-               vconf_keynode_get_bool;
-               vconf_keynode_get_str;
-               vconf_notify_key_changed;
-               vconf_ignore_key_changed;
-               vconf_set_int;
-               vconf_set_bool;
-               vconf_set_str;
-               vconf_set_dbl;
-               vconf_get_int;
-               vconf_get_bool;
-               vconf_get_str;
-               vconf_get_dbl;
-               vconf_get_ext_errno;
-               vconf_keylist_new;
-               vconf_keylist_free;
-               vconf_keylist_add_int;
-               vconf_keylist_add_bool;
-               vconf_keylist_add_dbl;
-               vconf_keylist_add_str;
-               vconf_keylist_add_null;
-               vconf_keylist_del;
-               vconf_keylist_nextnode;
-               vconf_keylist_rewind;
-               vconf_get;
-               vconf_set;
-               vconf_unset;
-               vconf_unset_recursive;
-               vconf_sync_key;
-               vconf_keylist_lookup;
-       local:
-               *;
-};
diff --git a/util_func.c b/util_func.c
deleted file mode 100644 (file)
index ac0dcff..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * libslp-db-util
- *
- * 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 <string.h>
-#include <unistd.h>
-#include <time.h>
-
-#include "util-func.h"
-#include "collation.h"
-#include "db-util-debug.h"
-
-static int __db_util_busyhandler(void *pData, int count)
-{
-       if (5 - count > 0) {
-               DB_UTIL_TRACE_DEBUG("Busy Handler Called! : PID(%d) / CNT(%d)\n", getpid(), count+1);
-               struct timespec time = {
-                       .tv_sec = 0,
-                       .tv_nsec = (count+1) * 100 * 1000 * 1000
-               };
-               nanosleep(&time, NULL);
-
-               return 1;
-       } else {
-               DB_UTIL_TRACE_DEBUG("Busy Handler will be returned SQLITE_BUSY error : PID(%d) \n", getpid());
-               return 0;
-       }
-}
-
-void __db_util_collation_cb(void* pArg, sqlite3* pDB, int eTextRep, const char* szName)
-{
-       if (eTextRep == SQLITE_UTF8 && !sqlite3_stricmp(szName, "localized"))
-               db_util_create_collation(pDB, DB_UTIL_COL_LS_AS_CI,
-                                                               DB_UTIL_COL_UTF8, "localized");
-       else
-               DB_UTIL_TRACE_WARNING("No matching collator for %s", szName);
-}
-
-static int __db_util_open(sqlite3 *pDB)
-{
-       int rc = 0;
-
-       if (pDB == NULL) {
-               DB_UTIL_TRACE_WARNING("Invalid input param error");
-               return DB_UTIL_ERROR;
-       }
-
-       /* Register Busy handler */
-       rc = sqlite3_busy_handler(pDB, __db_util_busyhandler, NULL);
-       if (SQLITE_OK != rc) {
-               DB_UTIL_TRACE_WARNING("Fail to register busy handler\n");
-               sqlite3_close(pDB);
-               return rc;
-       }
-
-#ifdef SET_PERSIST_JOURNAL_MODE
-       /* Code to change default journal mode of sqlite3 is enabled so this option is disabled */
-       /* Enable persist journal mode */
-       rc = sqlite3_exec(pDB, "PRAGMA journal_mode = PERSIST",
-                       NULL, NULL, &pszErrorMsg);
-       if (SQLITE_OK != rc) {
-               DB_UTIL_TRACE_WARNING("Fail to change journal mode: %d, %d, %s, %s\n",
-                                                               sqlite3_errcode(pDB),
-                                                               sqlite3_extended_errcode(pDB),
-                                                               pszErrorMsg,
-                                                               sqlite3_errmsg(pDB));
-               sqlite3_free(pszErrorMsg);
-               sqlite3_close(pDB);
-               return rc;
-       }
-#endif
-
-       sqlite3_collation_needed(pDB, NULL, __db_util_collation_cb);
-
-#if 0
-       if (DB_UTIL_OK != rc) {
-               DB_UTIL_TRACE_WARNING("Fail to create collation");
-               return rc;
-       }
-#endif
-
-       return DB_UTIL_OK;
-}
-
-int db_util_open(const char *pszFilePath, sqlite3 **ppDB, int nOption)
-{
-       if ((pszFilePath == NULL) || (ppDB == NULL)) {
-               DB_UTIL_TRACE_WARNING("Invalid input param error");
-               return DB_UTIL_ERROR;
-       }
-
-       if ((geteuid() != 0) && (access(pszFilePath, R_OK))) {
-               if (errno == EACCES) {
-                       DB_UTIL_TRACE_ERROR("file access permission error");
-                       return SQLITE_PERM;
-               }
-       }
-
-       /* Open DB */
-       int rc = sqlite3_open(pszFilePath, ppDB);
-       if (SQLITE_OK != rc) {
-               return rc;
-       }
-
-       rc = __db_util_open(*ppDB);
-
-       return rc;
-}
-
-int db_util_open_with_options(const char *pszFilePath, sqlite3 **ppDB,
-                               int flags, const char *zVfs)
-{
-       if ((pszFilePath == NULL) || (ppDB == NULL)) {
-               DB_UTIL_TRACE_WARNING("sqlite3 handle null error");
-               return DB_UTIL_ERROR;
-       }
-
-       /* Open DB */
-       int rc = sqlite3_open_v2(pszFilePath, ppDB, flags, zVfs);
-       if (SQLITE_OK != rc) {
-               return rc;
-       }
-
-       rc = __db_util_open(*ppDB);
-
-       return rc;
-}
-
-int db_util_close(sqlite3 *pDB)
-{
-       /* Close DB */
-       int rc = sqlite3_close(pDB);
-       if (SQLITE_OK != rc) {
-               DB_UTIL_TRACE_WARNING("Fail to close DB\n");
-               return rc;
-       }
-
-       return DB_UTIL_OK;
-}
-
-