test/ucxtest.h

changeset 213
cf7b86d79d35
parent 149
ea2448961441
--- a/test/ucxtest.h	Thu Sep 03 11:53:58 2026 +0200
+++ b/test/ucxtest.h	Thu Sep 03 11:54:19 2026 +0200
@@ -48,7 +48,7 @@
  * 
  * CX_TEST(function_name) {
  *   // memory allocation and other stuff here
- *   #CX_TEST_DO {
+ *   CX_TEST_DO {
  *     // tests with CX_TEST_ASSERT() and/or
  *     // calls with CX_TEST_CALL_SUBROUTINE() here
  *   }
@@ -72,8 +72,6 @@
 #include <string.h>
 #include <setjmp.h>
 
-typedef size_t (*cx_write_func)(const void*, size_t, size_t, void*);
-
 #ifndef __FUNCTION__
 /**
  * Alias for the <code>__func__</code> preprocessor macro.
@@ -86,14 +84,16 @@
 
 #if !defined(__clang__) && __GNUC__ > 3
 #pragma GCC diagnostic ignored "-Wclobbered"
-#pragma GCC diagnostic ignored "-Wunused-function"
 #endif
 
 /** Type for the CxTestSuite. */
 typedef struct CxTestSuite CxTestSuite;
 
+/** Output function compatible to cx_write_func */
+typedef size_t (*cx_test_output_func)(const void*, size_t, size_t, void*);
+
 /** Pointer to a test function. */
-typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func);
+typedef void(*CxTest)(CxTestSuite *, void *, cx_test_output_func);
 
 /** Type for the internal list of test cases. */
 typedef struct CxTestSet CxTestSet;
@@ -134,7 +134,7 @@
  * @param name optional name of the suite
  * @return a new test suite
  */
-static CxTestSuite* cx_test_suite_new(const char *name) {
+static inline CxTestSuite* cx_test_suite_new(const char *name) {
     CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite));
     if (suite != NULL) {
         suite->name = name;
@@ -151,7 +151,7 @@
  *
  * @param suite the test suite to free
  */
-static void cx_test_suite_free(CxTestSuite* suite) {
+static inline void cx_test_suite_free(CxTestSuite* suite) {
     if (suite == NULL) return;
     CxTestSet *l = suite->tests;
     while (l != NULL) {
@@ -170,7 +170,7 @@
  * @retval zero success
  * @retval non-zero failure
  */
-static int cx_test_register(CxTestSuite* suite, CxTest test) {
+static inline int cx_test_register(CxTestSuite* suite, CxTest test) {
     CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet));
     if (t) {
         t->test = test;
@@ -196,7 +196,8 @@
  * @param out_target the target buffer or file to write the output to
  * @param out_writer the write function writing to @p out_target
  */
-static void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer) {
+static inline void cx_test_run(CxTestSuite *suite, void *out_target,
+        cx_test_output_func out_writer) {
     if (suite->name == NULL) {
         out_writer("*** Test Suite ***\n", 1, 19, out_target);
     } else {
@@ -224,7 +225,8 @@
  * @param suite (@c CxTestSuite*) the test suite to run
  * @param file (@c FILE*) the target file to write the output to
  */
-#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, (cx_write_func)fwrite)
+#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, \
+        (cx_test_output_func) fwrite)
 
 /**
  * Runs a test suite and writes the test log to stdout.
@@ -239,7 +241,8 @@
  * 
  * @param name the name of the test function
  */
-#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, cx_write_func _writefnc_)
+#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, \
+        cx_test_output_func _writefnc_)
 
 /**
  * Defines the scope of a test.
@@ -289,7 +292,8 @@
  * written to the test suites output stream.
  * @param condition (@c bool) the condition to check
  */
-#define CX_TEST_ASSERT(condition) CX_TEST_ASSERTM(condition, #condition " failed")
+#define CX_TEST_ASSERT(condition) \
+        CX_TEST_ASSERTM(condition, #condition " failed")
 
 /**
  * Macro for a test subroutine function header.
@@ -303,7 +307,8 @@
  * @see CX_TEST_CALL_SUBROUTINE()
  */
 #define CX_TEST_SUBROUTINE(name,...) void name(CxTestSuite* _suite_,\
-        void *_output_, cx_write_func _writefnc_, jmp_buf _env_, __VA_ARGS__)
+        void *_output_, cx_test_output_func _writefnc_, \
+        jmp_buf _env_, __VA_ARGS__)
 
 /**
  * Macro for calling a test subroutine.

mercurial