summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-02-13 13:52:30 +0100
committerThomas Haller <thaller@redhat.com>2020-02-13 14:20:26 +0100
commit760551e3fc11b367431c80e36d9ca892c10481f2 (patch)
tree6c3081ce2edfe7f89c37fe10bf8240a387cf7e1d
parent5a731747c529cc1a62bfa0f54f17d5e3f3c71c4c (diff)
shared/tests: add test for NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*()
-rw-r--r--shared/nm-glib-aux/tests/test-shared-general.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/tests/test-shared-general.c b/shared/nm-glib-aux/tests/test-shared-general.c
index a6721c362..92e4330a2 100644
--- a/shared/nm-glib-aux/tests/test-shared-general.c
+++ b/shared/nm-glib-aux/tests/test-shared-general.c
@@ -554,6 +554,35 @@ test_nm_ref_string (void)
/*****************************************************************************/
+NM_UTILS_STRING_TABLE_LOOKUP_DEFINE_STATIC (
+ _do_string_table_lookup,
+ int,
+ { ; },
+ { return -1; },
+ { "0", 0 },
+ { "1", 1 },
+ { "2", 2 },
+ { "3", 3 },
+)
+
+static void
+test_string_table_lookup (void)
+{
+ const char *const args[] = { NULL, "0", "1", "2", "3", "x", };
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (args); i++) {
+ const char *needle = args[i];
+ const int val2 = _nm_utils_ascii_str_to_int64 (needle, 10, 0, 100, -1);
+ int val;
+
+ val = _do_string_table_lookup (needle);
+ g_assert_cmpint (val, ==, val2);
+ }
+}
+
+/*****************************************************************************/
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -572,6 +601,7 @@ int main (int argc, char **argv)
g_test_add_func ("/general/test_strstrip_avoid_copy", test_strstrip_avoid_copy);
g_test_add_func ("/general/test_nm_utils_bin2hexstr", test_nm_utils_bin2hexstr);
g_test_add_func ("/general/test_nm_ref_string", test_nm_ref_string);
+ g_test_add_func ("/general/test_string_table_lookup", test_string_table_lookup);
return g_test_run ();
}