--- a/libpurple/purplekeyvaluepair.c Thu Apr 30 23:43:54 2020 -0500
+++ b/libpurple/purplekeyvaluepair.c Fri May 01 00:10:57 2020 -0500
@@ -35,7 +35,7 @@
- kvp = g_new0(PurpleKeyValuePair, 1);
+ kvp = g_new(PurpleKeyValuePair, 1); kvp->key = g_strdup(key);
kvp->value_destroy_func = value_destroy_func;
@@ -59,7 +59,7 @@
purple_key_value_pair_copy(PurpleKeyValuePair *kvp) {
g_return_val_if_fail(kvp != NULL, NULL);
+ g_return_val_if_fail(kvp->value_destroy_func == NULL, NULL); - return purple_key_value_pair_new_full(kvp->key, kvp->value,
- kvp->value_destroy_func);
+ return purple_key_value_pair_new(kvp->key, kvp->value); --- a/libpurple/purplekeyvaluepair.h Thu Apr 30 23:43:54 2020 -0500
+++ b/libpurple/purplekeyvaluepair.h Fri May 01 00:10:57 2020 -0500
@@ -110,6 +110,9 @@
* Creates a copy of @kvp.
+ * If @kvp has a %value_destroy_func, %NULL will be returned as we this + * function has no way to know how to allocate a new copy of the value. * Returns: (transfer full): A new copy of @kvp.
PurpleKeyValuePair *purple_key_value_pair_copy(PurpleKeyValuePair *kvp);
--- a/libpurple/tests/meson.build Thu Apr 30 23:43:54 2020 -0500
+++ b/libpurple/tests/meson.build Fri May 01 00:10:57 2020 -0500
@@ -3,6 +3,7 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_keyvaluepair.c Fri May 01 00:10:57 2020 -0500
@@ -0,0 +1,116 @@
+ * Purple is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program 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 General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. +/****************************************************************************** + *****************************************************************************/ +test_key_value_pair_new(void) { + PurpleKeyValuePair *kvp = NULL; + kvp = purple_key_value_pair_new("abc", "123"); + g_assert_cmpstr(kvp->key, ==, "abc"); + g_assert_cmpstr(kvp->value, ==, "123"); + g_assert_null(kvp->value_destroy_func); + purple_key_value_pair_free(kvp); +test_key_value_pair_new_full(void) { + PurpleKeyValuePair *kvp = NULL; + kvp = purple_key_value_pair_new_full("abc", g_strdup("123"), g_free); + g_assert_cmpstr(kvp->key, ==, "abc"); + g_assert_cmpstr(kvp->value, ==, "123"); + g_assert_true(kvp->value_destroy_func == g_free); + purple_key_value_pair_free(kvp); +test_key_value_pair_copy(void) { + PurpleKeyValuePair *kvp1 = NULL, *kvp2 = NULL; + kvp1 = purple_key_value_pair_new("abc", "123"); + g_assert_nonnull(kvp1); + kvp2 = purple_key_value_pair_copy(kvp1); + g_assert_nonnull(kvp2); + g_assert_cmpstr(kvp1->key, ==, kvp2->key); + g_assert_cmpstr(kvp1->value, ==, kvp2->value);; + g_assert_true(kvp1->value_destroy_func == kvp2->value_destroy_func); + purple_key_value_pair_free(kvp1); + purple_key_value_pair_free(kvp2); +test_key_value_pair_copy_allocated_subprocess(void) { + PurpleKeyValuePair *kvp1 = NULL, *kvp2 = NULL; + kvp1 = purple_key_value_pair_new_full("abc", g_strdup("123"), g_free); + g_assert_nonnull(kvp1); + kvp2 = purple_key_value_pair_copy(kvp1); + purple_key_value_pair_free(kvp1); +test_key_value_pair_copy_allocated(void) { + g_test_trap_subprocess("/key-value-pair/copy-allocated/subprocess", 0, 0); + g_test_trap_assert_failed(); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + g_test_set_nonfatal_assertions(); + g_test_add_func("/key-value-pair/new", + test_key_value_pair_new); + g_test_add_func("/key-value-pair/new-full", + test_key_value_pair_new_full); + g_test_add_func("/key-value-pair/copy", + test_key_value_pair_copy); + g_test_add_func("/key-value-pair/copy-allocated", + test_key_value_pair_copy_allocated); + g_test_add_func("/key-value-pair/copy-allocated/subprocess", + test_key_value_pair_copy_allocated_subprocess);