diff options
author | Robert Fairley <rfairley@redhat.com> | 2019-08-29 12:14:26 -0400 |
---|---|---|
committer | Robert Fairley <rfairley@redhat.com> | 2019-11-07 23:39:10 -0500 |
commit | aadc4db012ed32455416864c6841e68a8b8ebf58 (patch) | |
tree | 7ccc5f09f3df47569df273c94b45a47cd72dbe28 /tests/test-kargs.c | |
parent | 49513ccc1b520220bc89382d751c9a7b9879f2d0 (diff) | |
download | ostree-aadc4db012ed32455416864c6841e68a8b8ebf58.tar.gz |
lib/kernel-args: Store kernel args as key/value entries
Define an `OstreeKernelArgsEntry` structure, which holds
both the key and the value. The kargs order array stores
entries for each key/value pair, instead of just the keys.
The hash table is used to locate entries, by storing
entries in a pointer array for each key. The same public
interface is preserved, while maintaining ordering
information of each key/value pair when
appending/replacing/deleting kargs.
Fixes: #1859
Diffstat (limited to 'tests/test-kargs.c')
-rw-r--r-- | tests/test-kargs.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/tests/test-kargs.c b/tests/test-kargs.c index 8d34f73c..d8370555 100644 --- a/tests/test-kargs.c +++ b/tests/test-kargs.c @@ -32,6 +32,22 @@ check_string_existance (OstreeKernelArgs *karg, return g_strv_contains ((const char* const*) string_list, string_to_find); } +static gboolean +kernel_args_entry_value_equal (gconstpointer data, + gconstpointer value) +{ + const OstreeKernelArgsEntry *e = data; + return g_strcmp0 (_ostree_kernel_args_entry_get_value (e), value) == 0; +} + +static gboolean +kernel_args_entry_key_equal (gconstpointer data, + gconstpointer key) +{ + const OstreeKernelArgsEntry *e = data; + return g_strcmp0 (_ostree_kernel_args_entry_get_key (e), key) == 0; +} + static void test_kargs_delete (void) { @@ -82,7 +98,7 @@ test_kargs_delete (void) g_assert (ret); /* verify the value array is properly updated */ GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (karg); - g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", g_str_equal, NULL)); + g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", kernel_args_entry_value_equal, NULL)); g_assert (!check_string_existance (karg, "single_key")); /* Delete specific key/value pair */ @@ -177,13 +193,6 @@ test_kargs_replace (void) g_assert (check_string_existance (karg, "test=newval")); } -static gboolean -strcmp0_equal (gconstpointer v1, - gconstpointer v2) -{ - return g_strcmp0 (v1, v2) == 0; -} - /* In this function, we want to verify that ostree_kernel_args_append * and ostree_kernel_args_to_string is correct. After that * we will use these two functions(append and tostring) in other tests: delete and replace @@ -208,22 +217,22 @@ test_kargs_append (void) { if (g_str_equal (key, "test")) { - g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", strcmp0_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", strcmp0_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, "", strcmp0_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, strcmp0_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "", kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL)); } else { g_assert_cmpstr (key, ==, "second_test"); - g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, strcmp0_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL)); } } /* verify the value array is properly updated */ GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (append_arg); - g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "test", g_str_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", g_str_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "test", kernel_args_entry_key_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", kernel_args_entry_key_equal, NULL)); /* Up till this point, we verified that the above was all correct, we then * check ostree_kernel_args_to_string has the right result |