src/cx/test.h

changeset 1710
d53be93acc10
parent 1675
36c0fb2b60b2
--- a/src/cx/test.h	Sun May 24 12:18:44 2026 +0200
+++ b/src/cx/test.h	Wed Aug 26 16:03:54 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
  *   }
@@ -67,8 +67,7 @@
 #ifndef UCX_TEST_H
 #define	UCX_TEST_H
 
-#include "common.h"
-
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <setjmp.h>
@@ -90,8 +89,11 @@
 /** 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;
@@ -132,7 +134,6 @@
  * @param name optional name of the suite
  * @return a new test suite
  */
-CX_NONNULL CX_NODISCARD  CX_CSTR_ARG(1) CX_MALLOC
 static inline CxTestSuite* cx_test_suite_new(const char *name) {
     CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite));
     if (suite != NULL) {
@@ -150,7 +151,7 @@
  *
  * @param suite the test suite to free
  */
-CX_INLINE 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) {
@@ -169,8 +170,7 @@
  * @retval zero success
  * @retval non-zero failure
  */
-CX_NONNULL
-CX_INLINE 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,8 +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
  */
-CX_NONNULL
-CX_INLINE 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 {
@@ -225,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.
@@ -240,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.
@@ -290,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.
@@ -304,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