changeset 465:6d44592cdab1

Improve tests slightly.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 02 Jun 2018 03:54:14 +0300
parents 761724e01c02
children bdee04d21282
files tests.c
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Thu May 10 17:15:36 2018 +0300
+++ b/tests.c	Sat Jun 02 03:54:14 2018 +0300
@@ -310,6 +310,13 @@
         test_end(&ctx); \
     } while (0)
 
+#define TEST2C(fun, str1, str2, ret) do { \
+        test_ctx ctx; test_init(&ctx); \
+        test_start(&ctx, # fun  "('%s', '%s')", str1, str2); \
+        test_result(&ctx, (fun (str1, str2) != NULL) == ret); \
+        test_end(&ctx); \
+    } while (0)
+
 #define TEST3(fun, str1, str2, len, ret) do { \
         test_ctx ctx; test_init(&ctx); \
         test_start(&ctx, # fun  "('%s', '%s', %d)", str1, str2, len); \
@@ -327,7 +334,7 @@
     //
     // Initialization
     //
-    th_init("th-test", "th-libs unit tests", "0.0.1", NULL, NULL);
+    th_init("th-test", "th-libs unit tests", "0.1", NULL, NULL);
     th_verbosityLevel = 0;
 
     if (sizeof(char) != sizeof(unsigned char))
@@ -442,7 +449,7 @@
     //
     // String matching functions
     //
-    if (test_set_start("String matching #1"))
+    if (test_set_start("String compare #1"))
     {
         TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE);
         TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE);
@@ -451,7 +458,7 @@
         TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE);
     }
 
-    if (test_set_start("String matching #2"))
+    if (test_set_start("String compare #2"))
     {
         TEST3(th_strncasecmp, "aSdFq", "asFfqB", 4, FALSE);
         TEST3(th_strncasecmp, "aSdFq", "asFfqQ", 2, TRUE);
@@ -462,7 +469,14 @@
         TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE);
     }
 
-    if (test_set_start("String matching #3"))
+    if (test_set_start("String compare #3"))
+    {
+        TEST2C(th_strrcasecmp, "foo aSdFq", " asdfq", TRUE);
+        TEST2C(th_strrcasecmp, "aSdFq", " asdfq", FALSE);
+        TEST2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", FALSE);
+    }
+
+    if (test_set_start("String matching #1"))
     {
         TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE);
         TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE);
@@ -474,7 +488,7 @@
         TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE);
     }
 
-    if (test_set_start("String matching #4"))
+    if (test_set_start("String matching #2"))
     {
         TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE);
         TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE);