All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/5] unit: add settings test for clone APIs
@ 2022-02-04 17:05 James Prestwood
  0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2022-02-04 17:05 UTC (permalink / raw)
  To: ell 

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

---
 unit/test-settings.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/unit/test-settings.c b/unit/test-settings.c
index a25197a..d9f25f9 100644
--- a/unit/test-settings.c
+++ b/unit/test-settings.c
@@ -559,6 +559,44 @@ static void test_invalid_data(const void *test_data)
 	l_settings_free(settings);
 }
 
+static void check_clone_data(struct l_settings *settings)
+{
+	const char *value;
+	const char *type = NULL;
+
+	assert(l_settings_has_group(settings, "normal"));
+	assert(l_settings_has_key(settings, "normal", "key"));
+	value = l_settings_get_value(settings, "normal", "key");
+	assert(value);
+	assert(!strcmp(value, "value"));
+
+	assert(l_settings_has_embedded_group(settings, "single_cert"));
+	value = l_settings_get_embedded_value(settings, "single_cert",
+								&type);
+	assert(value && type);
+	assert(!strcmp(type, "pem"));
+	assert(!strcmp(value, TEST_CERTIFICATE));
+}
+
+static void test_clone(const void *data)
+{
+	const char *raw_data =
+			"[normal]\n"
+			"key=value\n"
+			"[@pem(a)single_cert]\n"
+			TEST_CERTIFICATE;
+
+	struct l_settings *settings = l_settings_new();
+	struct l_settings *copy;
+
+	assert(l_settings_load_from_data(settings, raw_data, strlen(raw_data)));
+	check_clone_data(settings);
+
+	copy = l_settings_clone(settings);
+	check_clone_data(copy);
+	l_settings_free(copy);
+}
+
 int main(int argc, char *argv[])
 {
 	l_test_init(&argc, &argv);
@@ -571,7 +609,7 @@ int main(int argc, char *argv[])
 	l_test_add("Invalid Data 2", test_invalid_data, key_before_group_data);
 	l_test_add("Test valid ext group", test_valid_extended_group, NULL);
 	l_test_add("Test invalid ext group", test_invalid_extended_group, NULL);
-
+	l_test_add("Test clone", test_clone, NULL);
 
 	return l_test_run();
 }
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/5] unit: add settings test for clone APIs
@ 2022-02-04 17:29 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-02-04 17:29 UTC (permalink / raw)
  To: ell 

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

Hi James,

On 2/4/22 11:05, James Prestwood wrote:
> ---
>   unit/test-settings.c | 40 +++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 39 insertions(+), 1 deletion(-)
> 

There seems to be a leak somewhere?

TEST: Test clone
==22270==
==22270== HEAP SUMMARY:
==22270==     in use at exit: 1,860 bytes in 14 blocks
==22270==   total heap usage: 599 allocs, 585 frees, 25,152 bytes allocated
==22270==
==22270== 1,860 (40 direct, 1,820 indirect) bytes in 1 blocks are definitely 
lost in loss record 14 of 14
==22270==    at 0x483F7B5: malloc (in 
/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==22270==    by 0x10D88D: l_malloc (util.c:62)
==22270==    by 0x10FCDB: l_settings_new (settings.c:112)
==22270==    by 0x10D565: test_clone (test-settings.c:589)
==22270==    by 0x10E438: l_test_run (test.c:84)
==22270==    by 0x10B5D9: main (test-settings.c:614)

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-04 17:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-04 17:05 [PATCH 2/5] unit: add settings test for clone APIs James Prestwood
  -- strict thread matches above, loose matches on Subject: below --
2022-02-04 17:29 Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.