changeset 524:19dc326dcdad

Add few tests for th_get_hex_triplet().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Dec 2019 09:16:21 +0200
parents 9acbbfea68a9
children 59b8f15c5334
files tests.c
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Fri Dec 27 09:16:00 2019 +0200
+++ b/tests.c	Fri Dec 27 09:16:21 2019 +0200
@@ -286,6 +286,20 @@
 #define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0]))
 
 
+#define TEST1(fun) do { \
+        test_ctx ctx; \
+        test_start(&ctx, # fun ); \
+        test_result(&ctx, fun); \
+        test_end(&ctx); \
+    } while (0)
+
+#define TEST1A(fmt, fun, fcmp, fres) do { \
+        test_ctx ctx; \
+        test_start(&ctx, #fun " " #fcmp " " fmt " (" fmt ")", fres, fun); \
+        test_result(&ctx, fun fcmp fres ); \
+        test_end(&ctx); \
+    } while (0)
+
 #define TEST2(fun, str1, str2, ret) do { \
         test_ctx ctx; \
         test_start(&ctx, # fun  "('%s', '%s')", str1, str2); \
@@ -739,6 +753,21 @@
     }
 
     //
+    // String functions
+    //
+    if (test_set_start("String functions"))
+    {
+        char *tmpStr;
+        unsigned int tmpUint;
+
+        TEST1(th_get_hex_triplet("0fac11", &tmpUint) == TRUE);
+        TEST1A("0x%06x", tmpUint, ==, 0x0fac11);
+        TEST1(th_get_hex_triplet("120fac11", &tmpUint) == TRUE);
+        TEST1A("0x%06x", tmpUint, ==, 0x120fac11);
+        TEST1(th_get_hex_triplet("x120fac11", &tmpUint) == FALSE);
+    }
+
+    //
     // Print summary and exit
     //
     tprint(1,