[Pkg-sssd-devel] ding-libs: Changes to 'upstream'
Timo Aaltonen
tjaalton at moszumanska.debian.org
Sat Aug 15 22:30:19 UTC 2015
Makefile.am | 63 +
collection/collection.c | 266 +++++-
collection/collection.h | 180 ++++
collection/collection_ut.c | 338 ++++++++
collection/libcollection.sym | 8
contrib/ding-libs.spec.in | 13
ini/ini.d/merge.validator | 60 +
ini/ini.d/real.conf | 2
ini/ini2.d/real16be.conf |binary
ini/ini2.d/real16le.conf |binary
ini/ini2.d/real32be.conf |binary
ini/ini2.d/real32le.conf |binary
ini/ini2.d/real8.conf | 54 +
ini/ini_augment.c | 972 ++++++++++++++++++++++++
ini/ini_augment_ut.c | 390 +++++++++
ini/ini_comment.c | 59 +
ini/ini_comment.h | 13
ini/ini_comment_ut.c | 38
ini/ini_config.cfg.doxy.in | 2
ini/ini_config_priv.h | 9
ini/ini_config_ut.c | 5
ini/ini_configmod.c | 1607 ++++++++++++++++++++++++++++++++++++++++
ini/ini_configmod.h | 767 +++++++++++++++++++
ini/ini_configmod_ut.c | 1153 +++++++++++++++++++++++++++++
ini/ini_configmod_ut_check.c | 1695 +++++++++++++++++++++++++++++++++++++++++++
ini/ini_configobj.h | 306 +++++++
ini/ini_defines.h | 9
ini/ini_fileobj.c | 879 +++++++++++++++++++++-
ini/ini_get_valueobj.c | 2
ini/ini_parse.c | 13
ini/ini_print.c | 2
ini/ini_save_ut.c | 259 ++++++
ini/ini_valueobj.c | 7
ini/libini_config.sym | 42 +
refarray/ref_array.c | 5
version.m4 | 8
36 files changed, 9090 insertions(+), 136 deletions(-)
New commits:
commit 4b3c284e3978ad569deed38489e57041dca604c0
Author: Lukas Slebodnik <lslebodn at redhat.com>
Date: Tue Jun 23 12:51:13 2015 +0200
Update versions before 0.5.0 release
Version for libcollection was already updated
with patch:
df4d87161410bb6ab11105e74d2232cca6730f8b
Function to return one of the dups
Reviewed-by: Jakub Hrozek <jhrozek at redhat.com>
diff --git a/version.m4 b/version.m4
index 45ff9e2..8f4ce54 100644
--- a/version.m4
+++ b/version.m4
@@ -1,5 +1,5 @@
# Primary version number
-m4_define([VERSION_NUMBER], [0.4.0])
+m4_define([VERSION_NUMBER], [0.5.0])
# If the PRERELEASE_VERSION_NUMBER is set, we'll append
# it to the release tag when creating an RPM or SRPM
@@ -13,6 +13,6 @@ m4_define([PRERELEASE_VERSION_NUMBER], [])
m4_define([PATH_UTILS_VERSION_NUMBER], [0.2.1])
m4_define([DHASH_VERSION_NUMBER], [0.4.3])
m4_define([COLLECTION_VERSION_NUMBER], [0.7.0])
-m4_define([REF_ARRAY_VERSION_NUMBER], [0.1.4])
+m4_define([REF_ARRAY_VERSION_NUMBER], [0.1.5])
m4_define([BASICOBJECTS_VERSION_NUMBER], [0.1.1])
-m4_define([INI_CONFIG_VERSION_NUMBER], [1.1.0])
+m4_define([INI_CONFIG_VERSION_NUMBER], [1.2.0])
commit 7689460153b056b4064af6ed06a34915530b11a7
Author: Lukas Slebodnik <lslebodn at redhat.com>
Date: Tue Jun 23 12:50:53 2015 +0200
Bump version-info
The function ref_array_debug was updated. There wasn't any other
changes to ref_array.
New functions were added to collections:
col_get_dup_item, col_delete_item_with_cb, col_remove_item_with_cb
New functions were added to ini_config:
ini_config_augment, ini_comment_construct and many functions
from ini_configmod.h
Reviewed-by: Jakub Hrozek <jhrozek at redhat.com>
diff --git a/Makefile.am b/Makefile.am
index e37884e..5b1da33 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,7 +142,7 @@ libcollection_la_SOURCES = \
trace/trace.h
libcollection_la_DEPENDENCIES = collection/libcollection.sym
libcollection_la_LDFLAGS = \
- -version-info 4:0:0 \
+ -version-info 5:0:1 \
-Wl,--version-script=$(top_srcdir)/collection/libcollection.sym
check_PROGRAMS += \
@@ -180,7 +180,7 @@ libref_array_la_SOURCES = \
trace/trace.h
libref_array_la_DEPENDENCIES = refarray/libref_array.sym
libref_array_la_LDFLAGS = \
- -version-info 3:0:2 \
+ -version-info 3:1:2 \
-Wl,--version-script=$(top_srcdir)/refarray/libref_array.sym
check_PROGRAMS += ref_array_ut
@@ -268,7 +268,7 @@ libini_config_la_LIBADD = \
libref_array.la \
libbasicobjects.la
libini_config_la_LDFLAGS = \
- -version-info 5:0:0 \
+ -version-info 6:0:1 \
-Wl,--version-script=$(top_srcdir)/ini/libini_config.sym
dist_noinst_DATA += \
diff --git a/contrib/ding-libs.spec.in b/contrib/ding-libs.spec.in
index 54d8b97..fe180ff 100644
--- a/contrib/ding-libs.spec.in
+++ b/contrib/ding-libs.spec.in
@@ -174,7 +174,7 @@ and serialization
%doc COPYING
%doc COPYING.LESSER
%{_libdir}/libcollection.so.4
-%{_libdir}/libcollection.so.4.0.0
+%{_libdir}/libcollection.so.4.1.0
%files -n libcollection-devel
%defattr(-,root,root,-)
@@ -218,7 +218,7 @@ A dynamically-growing, reference-counted array
%doc COPYING
%doc COPYING.LESSER
%{_libdir}/libref_array.so.1
-%{_libdir}/libref_array.so.1.2.0
+%{_libdir}/libref_array.so.1.2.1
%files -n libref_array-devel
%defattr(-,root,root,-)
@@ -303,7 +303,7 @@ structure
%doc COPYING
%doc COPYING.LESSER
%{_libdir}/libini_config.so.5
-%{_libdir}/libini_config.so.5.0.0
+%{_libdir}/libini_config.so.5.1.0
%files -n libini_config-devel
%defattr(-,root,root,-)
commit 4d7e92836d8582a8af2f2885d4fcae34fd14b662
Author: Lukas Slebodnik <lslebodn at redhat.com>
Date: Tue Jun 23 10:16:34 2015 +0200
INI: Add check based test ini_configmod_ut_check
Signed-off-by: Lukas Slebodnik <lslebodn at redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek at redhat.com>
diff --git a/Makefile.am b/Makefile.am
index a3bbbb7..e37884e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,8 +69,8 @@ libpath_utils_la_LDFLAGS = \
-Wl,--version-script=$(top_srcdir)/path_utils/libpath_utils.sym
if HAVE_CHECK
- check_PROGRAMS += path_utils_ut
- TESTS += path_utils_ut
+ check_PROGRAMS += path_utils_ut ini_configmod_ut_check
+ TESTS += path_utils_ut ini_configmod_ut_check
endif
path_utils_ut_SOURCES = path_utils/path_utils_ut.c
@@ -341,6 +341,13 @@ ini_configmod_ut_SOURCES = ini/ini_configmod_ut.c
ini_configmod_ut_LDADD = libini_config.la libcollection.la \
libbasicobjects.la libpath_utils.la libref_array.la
+ini_configmod_ut_check_SOURCES = ini/ini_configmod_ut_check.c
+ini_configmod_ut_check_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
+ini_configmod_ut_check_LDADD = libini_config.la libcollection.la \
+ libbasicobjects.la libpath_utils.la \
+ libref_array.la \
+ $(CHECK_LIBS)
+
ini_save_ut_SOURCES = ini/ini_save_ut.c
ini_save_ut_LDADD = libini_config.la libcollection.la \
libbasicobjects.la libpath_utils.la libref_array.la
diff --git a/ini/ini_configmod_ut_check.c b/ini/ini_configmod_ut_check.c
new file mode 100644
index 0000000..75d6874
--- /dev/null
+++ b/ini/ini_configmod_ut_check.c
@@ -0,0 +1,1695 @@
+/*
+ INI LIBRARY
+
+ Unit test for the configuration object modification API.
+
+ Copyright (C) Lukas Slebodnik <lslebodn at redhat.com> 2015
+
+ INI Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ INI Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with INI Library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <check.h>
+
+/* #define TRACE_LEVEL 7 */
+#define TRACE_HOME
+#include "trace.h"
+#include "ini_configobj.h"
+#include "ini_config_priv.h"
+#include "collection_tools.h"
+#include "ini_configmod.h"
+#include "path_utils.h"
+#include "../basicobjects/simplebuffer.h"
+
+int verbose = 0;
+
+#define WRAP_SIZE 80
+
+static void dump_configuration(struct ini_cfgobj *in_cfg,
+ FILE *file)
+{
+ int ret;
+ struct simplebuffer *sbobj = NULL;
+ void *buff;
+ uint32_t len;
+
+ ret = simplebuffer_alloc(&sbobj);
+ fail_unless(ret == EOK,
+ "Failed to allocate buffer. Error %d.\n", ret);
+
+ ret = ini_config_serialize(in_cfg, sbobj);
+ fail_unless(ret == EOK,
+ "Failed to serialize. Error %d.\n", ret);
+
+ buff = simplebuffer_get_vbuf(sbobj);
+ len = simplebuffer_get_len(sbobj);
+ ret = fwrite(buff, 1, len, file);
+ fail_if(ret == -1,
+ "Failed to write to file. Error: %d %s\n", ret, strerror(ret));
+
+ simplebuffer_free(sbobj);
+ return;
+}
+
+static int call_diff(const char *function,
+ const char *expected_cfg,
+ size_t expected_cfg_len,
+ const char *res_cfg,
+ size_t res_cfg_len)
+{
+ char expected_fn[PATH_MAX];
+ char res_fn[PATH_MAX];
+ char command[PATH_MAX * 3];
+ char *builddir;
+ int ret;
+ int expected_fd;
+ int res_fd;
+
+ builddir = getenv("builddir");
+
+ snprintf(expected_fn, PATH_MAX, "%s/expected.conf_%s_XXXXXX",
+ (builddir == NULL) ? "." : builddir, function);
+ snprintf(res_fn, PATH_MAX, "%s/result.conf_%s_XXXXXX",
+ (builddir == NULL) ? "." : builddir, function);
+
+ expected_fd = mkstemp(expected_fn);
+ fail_if(expected_fd == -1, "mkstemp failed: %s\n", strerror(errno));
+
+ ret = write(expected_fd, expected_cfg, expected_cfg_len);
+ fail_if(ret == -1,
+ "Failed write to %s. Error %s\n",
+ expected_fn, strerror(errno));
+
+ close(expected_fd);
+
+ res_fd = mkstemp(res_fn);
+ fail_if(res_fd == -1, "mkstemp failed: %s\n", strerror(errno));
+
+ ret = write(res_fd, res_cfg, res_cfg_len);
+ fail_if(ret == -1,
+ "Failed write to %s. Error %s\n",
+ expected_fn, strerror(errno));
+ close(res_fd);
+
+ snprintf(command, PATH_MAX * 3, "diff -wi %s %s", expected_fn, res_fn);
+ ret = system(command);
+ fail_if(ret == -1,
+ "Failed to execute command:%s. Erorr %s\n",
+ command, strerror(errno));
+
+ return EOK;
+}
+
+#define assert_configuration_equal(expected_cfg, expected_cfg_len, res_cfg) \
+ _assert_configuration_equal(expected_cfg, expected_cfg_len, res_cfg, \
+ __func__, __FILE__, __LINE__)
+static void _assert_configuration_equal(const char *expected_cfg,
+ size_t expected_cfg_len,
+ struct ini_cfgobj *res_cfg,
+ const char *function,
+ const char *file,
+ int line)
+{
+ char *res_buffer = NULL;
+ size_t res_buffer_size;
+ FILE *f_memstream;
+ int ret;
+
+ --expected_cfg_len; /* do not use trailing zero */
+
+ f_memstream = open_memstream(&res_buffer, &res_buffer_size);
+ fail_if(f_memstream == NULL,
+ "\n\t[%s:%d] open_memstream failed.", file, line);
+
+ dump_configuration(res_cfg, f_memstream);
+ fclose(f_memstream);
+
+ fail_unless(expected_cfg_len == res_buffer_size,
+ "\n\t[%s:%d] Size of expected config %zu and result config %d "
+ "does not match. Res:%d\n",
+ file, line, expected_cfg_len, res_buffer_size,
+ call_diff(function, expected_cfg, expected_cfg_len,
+ res_buffer, res_buffer_size));
+
+ ret = memcmp(res_buffer, expected_cfg, expected_cfg_len);
+ fail_unless(ret == EOK,
+ "\n\t[%s:%d] Configurations are not identical. Res:%d\n",
+ file, line,
+ call_diff(function, expected_cfg, expected_cfg_len,
+ res_buffer, res_buffer_size));
+
+ free(res_buffer);
+}
+
+static struct ini_cfgobj *get_ini_config_from_str(char input_data[],
+ size_t input_data_len)
+{
+ struct ini_cfgobj *in_cfg;
+ struct ini_cfgfile *file_ctx;
+ int ret;
+
+ ret = ini_config_create(&in_cfg);
+ fail_unless(ret == EOK, "Failed to create config. Error %d.\n", ret);
+
+ ret = ini_config_file_from_mem(input_data, input_data_len, &file_ctx);
+ fail_unless(ret == EOK, "Failed to load config. Error %d.\n", ret);
+
+ ret = ini_config_parse(file_ctx, INI_STOP_ON_NONE, INI_MV1S_ALLOW, 0,
+ in_cfg);
+ fail_unless(ret == EOK, "Failed to parse config. Error %d.\n", ret);
+
+ ini_config_file_destroy(file_ctx);
+
+ return in_cfg;
+}
+
+START_TEST(test_delete_value_wrong_arguments)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg = NULL;
+
+ char exp_data[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n";
+
+ in_cfg = get_ini_config_from_str(exp_data, sizeof(exp_data));
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ /* missing ini_config */
+ ret = ini_config_delete_value(NULL, "one", COL_DSP_NDUP, "key1", 0);
+ fail_unless(ret == EINVAL, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ /* missing section */
+ ret = ini_config_delete_value(in_cfg, NULL, COL_DSP_NDUP, "key1", 0);
+ fail_unless(ret == EINVAL, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ /* missing key */
+ ret = ini_config_delete_value(in_cfg, "one", COL_DSP_NDUP, NULL, 0);
+ fail_unless(ret == EINVAL, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ /* value index is too low */
+ ret = ini_config_delete_value(in_cfg, "one", COL_DSP_NDUP, "key1", -1);
+ fail_unless(ret == EINVAL, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ /* value index is too high */
+ ret = ini_config_delete_value(in_cfg, "one", COL_DSP_NDUP, "key1", 1);
+ fail_unless(ret == ENOENT, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data, sizeof(exp_data), in_cfg);
+
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_delete_value)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = first\n"
+ "key1 = second\n"
+ "key1 = third\n"
+ "key1 = last\n";
+
+ char delete_first[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = first\n"
+ "key1 = second\n"
+ "key1 = third\n";
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ ret = ini_config_delete_value(in_cfg, "one", COL_DSP_NDUP, "key1", 3);
+ fail_unless(ret == EOK, "delete value should fail. Error: %d", ret);
+ assert_configuration_equal(delete_first, sizeof(delete_first), in_cfg);
+
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_update_comments_wrong_arguments)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[one]\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "// This is a test\n"
+ "key1 = value1b\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ const char *comment[] = { "// This is a test", NULL };
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing ini_config */
+ ret = ini_config_update_comment(NULL, "one", "key1", comment, 1, 3);
+ fail_unless(ret == EINVAL, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing section */
+ ret = ini_config_update_comment(in_cfg, NULL, "key1", comment, 1, 3);
+ fail_unless(ret == EINVAL, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing key */
+ ret = ini_config_update_comment(in_cfg, "one", NULL, comment, 1, 3);
+ fail_unless(ret == EINVAL, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* wrong section */
+ ret = ini_config_update_comment(in_cfg, "noexist", "key1", comment, 1, 3);
+ fail_unless(ret == ENOENT, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* wrong key */
+ ret = ini_config_update_comment(in_cfg, "one", "noexist", comment, 1, 3);
+ fail_unless(ret == ENOENT, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* value index is too low */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comment, 1, -1);
+ fail_unless(ret == EINVAL, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* value index is too high */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comment, 1, 5);
+ fail_unless(ret == ENOENT, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_update_comments)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[one]\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "// this is a comment\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ char exp_data_1comment[] =
+ "[one]\n"
+ "// This is a test1\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "// this is a comment\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ char exp_data_2comments[] =
+ "[one]\n"
+ "// This is a test1\n"
+ "// This is a test2\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "// this is a comment\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ char exp_data_1comment_after2[] =
+ "[one]\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "// This is a test1\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "// this is a comment\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ char exp_replaced[] =
+ "[one]\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "// This is a test1\n"
+ "// This is a test2\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ char exp_removed_comment[] =
+ "[one]\n"
+ "key1 = value1\n"
+ "key1 = value1a\n"
+ "key1 = value1a_bis\n"
+ "key1 = value1b\n"
+ "key1 = value1c\n"
+ "key2 = value2\n"
+ "key3 = value3\n";
+
+ const char *comments[] = { "// This is a test1", "// This is a test2",
+ NULL };
+
+ const char *empty_comment[] = { NULL };
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add comments with size */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comments, 1, 0);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data_1comment, sizeof(exp_data_1comment),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add comments with size */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comments, 2, 0);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data_2comments, sizeof(exp_data_2comments),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add comments (NULL terminated array), size is 0 */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comments, 0, 0);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data_2comments, sizeof(exp_data_2comments),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add comments (NULL terminated array), size is 0 */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comments, 1, 2);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_data_1comment_after2,
+ sizeof(exp_data_1comment_after2),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* replace comment */
+ ret = ini_config_update_comment(in_cfg, "one", "key1", comments, 0, 4);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_replaced, sizeof(exp_replaced),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* remove comment */
+ ret = ini_config_update_comment(in_cfg, "one", "key1",
+ empty_comment, 0, 4);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_removed_comment,
+ sizeof(exp_removed_comment),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* remove comment (2nd way; argument is NULL) */
+ ret = ini_config_update_comment(in_cfg, "one", "key1",
+ NULL, 0, 4);
+ fail_unless(ret == EOK, "update commants should fail. Error: %d", ret);
+ assert_configuration_equal(exp_removed_comment,
+ sizeof(exp_removed_comment),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_add_str_wrong_arguments)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n";
+
+ const char *comments[] = { "// This is a test1", "// This is a test2",
+ NULL };
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing ini_config */
+ ret = ini_config_add_str_value(NULL, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EINVAL, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing section */
+ ret = ini_config_add_str_value(in_cfg, NULL, "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EINVAL, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing key */
+ ret = ini_config_add_str_value(in_cfg, "one", NULL, "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EINVAL, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* missing value */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", NULL,
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EINVAL, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* wrong index */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ -1, INI_VA_NOCHECK);
+ fail_unless(ret == EINVAL, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* wrong flag */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, "key1",
+ 0, 0xff);
+ fail_unless(ret == ENOSYS, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add duplicate for missing key */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_NDUP,
+ "key1", 0, INI_VA_NOCHECK);
+ fail_unless(ret == ENOENT, "Add str should fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_add_str_simple)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n";
+
+ const char *comments[] = { "// This is a test1", "// This is a test2",
+ NULL };
+
+ char add_new_value_to_end[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n"
+ "newkey = newvalue\n";
+
+ char add_new_value_to_end_with_comment[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n"
+ "// This is a test1\n"
+ "// This is a test2\n"
+ "newkey = newvalue\n";
+
+ char add_new_value_to_front[] =
+ "[zero]\n"
+ "[one]\n"
+ "newkey = newvalue\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n";
+
+ char add_new_value_to_front_with_comment[] =
+ "[zero]\n"
+ "[one]\n"
+ "// This is a test1\n"
+ "// This is a test2\n"
+ "newkey = newvalue\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n";
+
+ char add_new_value_after_key1[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n"
+ "newkey = newvalue\n"
+ "key1 = value1b\n"
+ "key2 = value2a\n";
+
+ char add_new_value_before_key2[] =
+ "[zero]\n"
+ "[one]\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "newkey = newvalue\n"
+ "key2 = value2a\n";
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* Simple add new value to end of section */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_END, NULL,
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_to_end,
+ sizeof(add_new_value_to_end), in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value with comment to end of section */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_END, NULL,
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_to_end_with_comment,
+ sizeof(add_new_value_to_end_with_comment),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* Simple add new value to the begin of section */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_FRONT, NULL,
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_to_front,
+ sizeof(add_new_value_to_front), in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value with comment to the begin of section */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ comments, 2, WRAP_SIZE, COL_DSP_FRONT, NULL,
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_to_front_with_comment,
+ sizeof(add_new_value_to_front_with_comment),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value after "key1" with index 0 */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_AFTER, "key1",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_after_key1,
+ sizeof(add_new_value_after_key1),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value after "key1" with index 1 (index ignored) */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_AFTER, "key1",
+ 1, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_after_key1,
+ sizeof(add_new_value_after_key1),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value after "key1" with very big index (index ignored) */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_AFTER, "key1",
+ 1000, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_after_key1,
+ sizeof(add_new_value_after_key1),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* add new value before "key2" */
+ ret = ini_config_add_str_value(in_cfg, "one", "newkey", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_BEFORE, "key2",
+ 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_new_value_before_key2,
+ sizeof(add_new_value_before_key2),
+ in_cfg);
+ ini_config_destroy(in_cfg);
+}
+END_TEST
+
+START_TEST(test_add_str_duplicate)
+{
+ int ret = EOK;
+ struct ini_cfgobj *in_cfg;
+
+ char input_data[] =
+ "[zero]\n"
+ "[one]\n"
+ "key0 = value0a\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "// This is a test1\n"
+ "key2 = value2a\n";
+
+ char add_first_duplicate[] =
+ "[zero]\n"
+ "[one]\n"
+ "key0 = newvalue\n"
+ "key0 = value0a\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "// This is a test1\n"
+ "key2 = value2a\n";
+
+ char add_first_duplicate_for_multi[] =
+ "[zero]\n"
+ "[one]\n"
+ "key0 = value0a\n"
+ "key1 = newvalue\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "// This is a test1\n"
+ "key2 = value2a\n";
+
+ char add_last_duplicate[] =
+ "[zero]\n"
+ "[one]\n"
+ "key0 = value0a\n"
+ "key1 = value1a\n"
+ "key1 = value1b\n"
+ "key1 = newvalue\n"
+ "// This is a test1\n"
+ "key2 = value2a\n";
+
+ char add_duplicate_with_index1[] =
+ "[zero]\n"
+ "[one]\n"
+ "key0 = value0a\n"
+ "key1 = value1a\n"
+ "// This is a test1\n"
+ "// This is a test2\n"
+ "key1 = newvalue\n"
+ "key1 = value1b\n"
+ "// This is a test1\n"
+ "key2 = value2a\n";
+
+ const char *comments[] = { "// This is a test1", "// This is a test2",
+ NULL };
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* cannot add key as the first duplicate for non-existing key */
+ ret = ini_config_add_str_value(in_cfg, "one", "noexist", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_FIRSTDUP,
+ NULL, 0, INI_VA_NOCHECK);
+ fail_unless(ret == ENOENT, "Add duplicate key must fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* cannot add key as the last duplicate for non-existing key */
+ ret = ini_config_add_str_value(in_cfg, "one", "noexist", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_LASTDUP,
+ NULL, 0, INI_VA_NOCHECK);
+ fail_unless(ret == ENOENT, "Add duplicate key must fail. Error: %d", ret);
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
+ /* Add duplicate value */
+ ret = ini_config_add_str_value(in_cfg, "one", "key0", "newvalue",
+ NULL, 0, WRAP_SIZE, COL_DSP_FIRSTDUP,
+ NULL, 0, INI_VA_NOCHECK);
+ fail_unless(ret == EOK, "Failed to add str. Error: %d", ret);
+ assert_configuration_equal(add_first_duplicate,
+ sizeof(add_first_duplicate), in_cfg);
+ ini_config_destroy(in_cfg);
+
+ in_cfg = get_ini_config_from_str(input_data, sizeof(input_data));
+ assert_configuration_equal(input_data, sizeof(input_data), in_cfg);
+
More information about the Pkg-sssd-devel
mailing list