changeset 552:22f6204c4208

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Jan 2020 08:23:55 +0200
parents 2fbf5c2a662c
children 3a852e9f70a6
files tests.c
diffstat 1 files changed, 15 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Fri Jan 03 08:15:10 2020 +0200
+++ b/tests.c	Fri Jan 03 08:23:55 2020 +0200
@@ -12,6 +12,9 @@
 #define SET_SENTINEL_BYTE      0x0e5
 
 
+#define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0]))
+
+
 enum
 {
     TST_SUPERFLUOUS = 0x0001,
@@ -109,8 +112,7 @@
             memset(sets_enabled, 0, sizeof(sets_enabled));
 
             do {
-                next = strchr(pos, ',');
-                if (next != NULL)
+                if ((next = strchr(pos, ',')) != NULL)
                     *next = 0;
 
                 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH);
@@ -305,9 +307,6 @@
 }
 
 
-#define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0]))
-
-
 #define TEST1(fun) do { \
         test_ctx ctx; \
         test_start(&ctx, # fun ); \
@@ -378,7 +377,7 @@
 }
 
 
-void test_free(th_llist_t *node)
+void test_config_free(th_llist_t *node)
 {
     th_free_r(&node->data);
 }
@@ -400,19 +399,17 @@
 }
 
 
-int test_strcmp(const void *v1, const void *v2)
+int test_config_strcmp(const void *v1, const void *v2)
 {
     return strcmp((const char *) v1, (const char *) v2);
 }
 
 
-static const char *test_strings[] =
+static const char *test_config_strings[] =
 {
     "zoo", "foo", "b\"ar",
 };
 
-static const int ntest_strings = sizeof(test_strings) / sizeof(test_strings[0]);
-
 
 void test_config_read(th_cfgitem_t *cfg, const char *filename)
 {
@@ -447,23 +444,23 @@
         static const char *nostr = "not to be found";
         th_llist_t **plist = (th_llist_t **) item->v.list;
 
-        for (nsubtest = 0; nsubtest < ntest_strings; nsubtest++)
+        for (nsubtest = 0; nsubtest < (int) NCOUNT(test_config_strings); nsubtest++)
         {
             test_start(&ctx, "Test configuration string list values #%d: '%s'",
-                nsubtest + 1, test_strings[nsubtest]);
+                nsubtest + 1, test_config_strings[nsubtest]);
 
             test_result(&ctx,
                 th_llist_find_func(*plist,
-                test_strings[nsubtest], test_strcmp) != NULL);
+                test_config_strings[nsubtest], test_config_strcmp) != NULL);
             test_end(&ctx);
         }
 
         test_start(&ctx, "Test configuration string list values #%d: '%s'",
             ++nsubtest, nostr);
-        test_result(&ctx, th_llist_find_func(*plist, nostr, test_strcmp) == NULL);
+        test_result(&ctx, th_llist_find_func(*plist, nostr, test_config_strcmp) == NULL);
         test_end(&ctx);
 
-        th_llist_free_func_node(*plist, test_free);
+        th_llist_free_func_node(*plist, test_config_free);
         *plist = NULL;
     }
 
@@ -485,8 +482,8 @@
     th_llist_t *v_str_list = NULL;
 
     // Create v_str_list
-    for (int n = 0; n < ntest_strings; n++)
-        th_llist_append(&v_str_list, th_strdup(test_strings[n]));
+    for (size_t n = 0; n < NCOUNT(test_config_strings); n++)
+        th_llist_append(&v_str_list, th_strdup(test_config_strings[n]));
 
     // Create the configuration structure
     tprint(2, "Creating configuration structure\n");
@@ -548,7 +545,7 @@
 out:
     // Free the data for v_str_list
     th_io_free(fh);
-    th_llist_free_func_node(v_str_list, test_free);
+    th_llist_free_func_node(v_str_list, test_config_free);
     v_str_list = NULL;
 }