port tests to ucx 3 dav-2

Sun, 07 Sep 2025 15:57:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 07 Sep 2025 15:57:36 +0200
branch
dav-2
changeset 879
255a5ef46400
parent 878
68ea3a0fe66f
child 880
5f8ccd1d59bd

port tests to ucx 3

test/Makefile file | annotate | diff | comparison | revisions
test/base64.c file | annotate | diff | comparison | revisions
test/base64.h file | annotate | diff | comparison | revisions
test/crypto.c file | annotate | diff | comparison | revisions
test/crypto.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
test/test.c file | annotate | diff | comparison | revisions
test/test.h file | annotate | diff | comparison | revisions
test/test_finfo.h file | annotate | diff | comparison | revisions
test/utils.c file | annotate | diff | comparison | revisions
test/utils.h file | annotate | diff | comparison | revisions
--- a/test/Makefile	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/Makefile	Sun Sep 07 15:57:36 2025 +0200
@@ -31,7 +31,6 @@
 include ../dav/obj.mk
 
 TEST_SRC  = main.c
-TEST_SRC += test.c
 TEST_SRC += base64.c
 TEST_SRC += crypto.c
 TEST_SRC += utils.c
--- a/test/base64.c	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/base64.c	Sun Sep 07 15:57:36 2025 +0200
@@ -35,20 +35,18 @@
 #include <cx/string.h>
 #include <libidav/utils.h>
 
-UCX_TEST(test_util_base64decode) {
+CX_TEST(test_util_base64decode) {
     char *s1 = util_base64decode("YWJj");
     char *s2 = util_base64decode("aGVsbG8gd29ybGQ=");
     char *s3 = util_base64decode("MA==");
     char *s4 = util_base64decode("MHh4MQ==");
     
-    UCX_TEST_BEGIN;
-    
-    UCX_TEST_ASSERT(!strcmp(s1, "abc"), "s1 wrong");
-    UCX_TEST_ASSERT(!strcmp(s2, "hello world"), "s2 wrong");
-    UCX_TEST_ASSERT(!strcmp(s3, "0"), "s3 wrong");
-    UCX_TEST_ASSERT(!strcmp(s4, "0xx1"), "s4 wrong");
-    
-    UCX_TEST_END;
+    CX_TEST_DO {
+        CX_TEST_ASSERT(!strcmp(s1, "abc"));
+        CX_TEST_ASSERT(!strcmp(s2, "hello world"));
+        CX_TEST_ASSERT(!strcmp(s3, "0"));
+        CX_TEST_ASSERT(!strcmp(s4, "0xx1"));
+    }
     
     free(s1);
     free(s2);
@@ -56,7 +54,7 @@
     free(s4);
 }
 
-UCX_TEST(test_util_base64decode_len) {
+CX_TEST(test_util_base64decode_len) {
     int len1, len2, len3, len4, len5, len6;
     char *s1 = util_base64decode_len("aGVsbG8=", &len1); // 5
     char *s2 = util_base64decode_len("MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5", &len2); // 30
@@ -65,27 +63,25 @@
     char *s5 = util_base64decode_len("YWJjLS0tLS0tM3g=", &len5); // 11
     char *s6 = util_base64decode_len("YWJjZGVmZy4uLjs7MGhlbGxv", &len6); // 18
     
-    UCX_TEST_BEGIN;
-    
-    UCX_TEST_ASSERT(!strcmp(s1, "hello"), "s1 wrong");
-    UCX_TEST_ASSERT(len1 == 5, "len1 wrong");
-    
-    UCX_TEST_ASSERT(!strcmp(s2, "012345678901234567890123456789"), "s2 wrong");
-    UCX_TEST_ASSERT(len2 == 30, "len2 wrong");
-    
-    UCX_TEST_ASSERT(!strcmp(s3, "."), "s3 wrong");
-    UCX_TEST_ASSERT(len3 == 1, "len3 wrong");
-    
-    UCX_TEST_ASSERT(!strcmp(s4, "lol"), "s4 wrong");
-    UCX_TEST_ASSERT(len4 == 3, "len4 wrong");
-    
-    UCX_TEST_ASSERT(!strcmp(s5, "abc------3x"), "s5 wrong");
-    UCX_TEST_ASSERT(len5 == 11, "len5 wrong");
-    
-    UCX_TEST_ASSERT(!strcmp(s6, "abcdefg...;;0hello"), "s6 failed");
-    UCX_TEST_ASSERT(len6 == 18, "len6 wrong");
-    
-    UCX_TEST_END;
+    CX_TEST_DO {
+        CX_TEST_ASSERT(!strcmp(s1, "hello"));
+        CX_TEST_ASSERT(len1 == 5);
+
+        CX_TEST_ASSERT(!strcmp(s2, "012345678901234567890123456789"));
+        CX_TEST_ASSERT(len2 == 30);
+
+        CX_TEST_ASSERT(!strcmp(s3, "."));
+        CX_TEST_ASSERT(len3 == 1);
+
+        CX_TEST_ASSERT(!strcmp(s4, "lol"));
+        CX_TEST_ASSERT(len4 == 3);
+
+        CX_TEST_ASSERT(!strcmp(s5, "abc------3x"));
+        CX_TEST_ASSERT(len5 == 11);
+
+        CX_TEST_ASSERT(!strcmp(s6, "abcdefg...;;0hello"));
+        CX_TEST_ASSERT(len6 == 18);
+    }
     
     free(s1);
     free(s2);
@@ -95,7 +91,7 @@
     free(s6);
 }
 
-UCX_TEST(test_util_base64encode) {  
+CX_TEST(test_util_base64encode) {  
     char *str1 = "hello world";
     char *str2 = "test string";
     char *str3 = "01234567890123456789012345678901234567890123456789";
@@ -127,21 +123,19 @@
     char *b9 = util_base64encode(str9, strlen(str9));
     char *b10 = util_base64encode(str10, strlen(str10));
     
-    UCX_TEST_BEGIN;
-    
-    UCX_TEST_ASSERT(!strcmp(b1, "aGVsbG8gd29ybGQ="), "b1 failed");
-    UCX_TEST_ASSERT(!strcmp(b2, "dGVzdCBzdHJpbmc="), "b2 failed");
-    UCX_TEST_ASSERT(!strcmp(b3, "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk="), "b3 failed");
-    UCX_TEST_ASSERT(!strcmp(b4, "AAwDMgJuPwE="), "b4 failed");
-    
-    UCX_TEST_ASSERT(!strcmp(b5, "YQ=="), "b5 failed");
-    UCX_TEST_ASSERT(!strcmp(b6, "YWI="), "b6 failed");
-    UCX_TEST_ASSERT(!strcmp(b7, "YWJj"), "b7 failed");
-    UCX_TEST_ASSERT(!strcmp(b8, "YWJjZA=="), "b8 failed");
-    UCX_TEST_ASSERT(!strcmp(b9, "YWJjZGU="), "b9 failed");
-    UCX_TEST_ASSERT(!strcmp(b10, "YWJjZGVm"), "b10 failed");
-    
-    UCX_TEST_END;
+    CX_TEST_DO {
+        CX_TEST_ASSERT(!strcmp(b1, "aGVsbG8gd29ybGQ="));
+        CX_TEST_ASSERT(!strcmp(b2, "dGVzdCBzdHJpbmc="));
+        CX_TEST_ASSERT(!strcmp(b3, "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk="));
+        CX_TEST_ASSERT(!strcmp(b4, "AAwDMgJuPwE="));
+
+        CX_TEST_ASSERT(!strcmp(b5, "YQ=="));
+        CX_TEST_ASSERT(!strcmp(b6, "YWI="));
+        CX_TEST_ASSERT(!strcmp(b7, "YWJj"));
+        CX_TEST_ASSERT(!strcmp(b8, "YWJjZA=="));
+        CX_TEST_ASSERT(!strcmp(b9, "YWJjZGU="));
+        CX_TEST_ASSERT(!strcmp(b10, "YWJjZGVm"));
+    }
     
     free(b1);
     free(b2);
--- a/test/base64.h	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/base64.h	Sun Sep 07 15:57:36 2025 +0200
@@ -29,15 +29,15 @@
 #ifndef BASE64_H
 #define BASE64_H
 
-#include "test.h"
+#include <cx/test.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-UCX_TEST(test_util_base64decode);
-UCX_TEST(test_util_base64decode_len);
-UCX_TEST(test_util_base64encode);
+CX_TEST(test_util_base64decode);
+CX_TEST(test_util_base64decode_len);
+CX_TEST(test_util_base64encode);
 
 
 #ifdef __cplusplus
--- a/test/crypto.c	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/crypto.c	Sun Sep 07 15:57:36 2025 +0200
@@ -192,146 +192,138 @@
     }
 }
 
-UCX_TEST(test_util_decrypt_str_k) {
+CX_TEST(test_util_decrypt_str_k) {
     create_keys();
     
     DavContext *ctx = dav_context_new();
     DavSession *sn = dav_session_new(ctx, "http://localhost/");
     
-    UCX_TEST_BEGIN;
-    
-    for(int k=0;k<2;k++) {
-        for(int i=0;i<20;i++) {
-            char *c1;
-            char *c2;
-            if(k == 0) {
-                c1 = cryptkey0aes128strings[i];
-                c2 = cryptkey0aes256strings[i];
-            } else {
-                c1 = cryptkey1aes128strings[i];
-                c2 = cryptkey1aes256strings[i];
+    CX_TEST_DO {
+        for(int k=0;k<2;k++) {
+            for(int i=0;i<20;i++) {
+                char *c1;
+                char *c2;
+                if(k == 0) {
+                    c1 = cryptkey0aes128strings[i];
+                    c2 = cryptkey0aes256strings[i];
+                } else {
+                    c1 = cryptkey1aes128strings[i];
+                    c2 = cryptkey1aes256strings[i];
+                }
+
+                char *s128 = util_decrypt_str_k(sn, c1, &keys128[k]);
+                char *s256 = util_decrypt_str_k(sn, c2, &keys256[k]);
+
+                CX_TEST_ASSERT(!strcmp(s128, strings[i]));
+                CX_TEST_ASSERT(!strcmp(s256, strings[i]));
             }
-            
-            char *s128 = util_decrypt_str_k(sn, c1, &keys128[k]);
-            char *s256 = util_decrypt_str_k(sn, c2, &keys256[k]);
-            
-            UCX_TEST_ASSERT(!strcmp(s128, strings[i]), "s128 wrong");
-            UCX_TEST_ASSERT(!strcmp(s256, strings[i]), "s256 wrong");
         }
     }
     
-    UCX_TEST_END;
-    
     dav_context_destroy(ctx);
 }
 
-UCX_TEST(test_util_encrypt_str_k) {
+CX_TEST(test_util_encrypt_str_k) {
     DavContext *ctx = dav_context_new();
     DavSession *sn = dav_session_new(ctx, "http://localhost/");
     
-    UCX_TEST_BEGIN;
-    
-    for(int k=0;k<16;k++) {
-        for(int i=0;i<20;i++) {
-            char *aes128 = util_encrypt_str_k(sn, strings[i], &keys128[k]);
-            char *aes256 = util_encrypt_str_k(sn, strings[i], &keys256[k]);
-            
-            char *dec1 = util_decrypt_str_k(sn, aes128, &keys128[k]);
-            char *dec2 = util_decrypt_str_k(sn, aes256, &keys256[k]);
-            
-            UCX_TEST_ASSERT(!strcmp(dec1, strings[i]), "aes128 encrypt failed");
-            UCX_TEST_ASSERT(!strcmp(dec2, strings[i]), "aes256 encrypt failed");
+    CX_TEST_DO {
+        for(int k=0;k<16;k++) {
+            for(int i=0;i<20;i++) {
+                char *aes128 = util_encrypt_str_k(sn, strings[i], &keys128[k]);
+                char *aes256 = util_encrypt_str_k(sn, strings[i], &keys256[k]);
+
+                char *dec1 = util_decrypt_str_k(sn, aes128, &keys128[k]);
+                char *dec2 = util_decrypt_str_k(sn, aes256, &keys256[k]);
+
+                CX_TEST_ASSERT(!strcmp(dec1, strings[i]));
+                CX_TEST_ASSERT(!strcmp(dec2, strings[i]));
+            }
         }
     }
-    
-    UCX_TEST_END;
 }
 
-UCX_TEST(test_crypto_buffer) {
-    UCX_TEST_BEGIN;
-    
-    for(int i=0;i<32;i++) {
-        DavKey *key = i < 16 ? &keys256[i] : &keys128[i%16];
-        
-        for(int j=0;j<20;j++) {
-            CxBuffer *content = cxBufferCreate(NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
-            cxBufferPutString(content, strings[j]);
-            content->pos = 0;
-            
-            CxBuffer *enc = aes_encrypt_buffer(content, key);
-            UCX_TEST_ASSERT(enc->size >= content->size + 16, "aes_encrypt_buffer failed");
-            
-            char *base64 = util_base64encode(enc->space, enc->size);
-            size_t plainlen = 0;
-            char *plain = aes_decrypt(base64, &plainlen, key);
-            
-            UCX_TEST_ASSERT(plain, "aes_decrypt failed");
-            UCX_TEST_ASSERT(plainlen == content->size, "aes_decrypt: wrong length");
-            UCX_TEST_ASSERT(!memcmp(plain, content->space, plainlen), "aes_decrypt: wrong content");
-            
-            CxBuffer *dec = aes_decrypt_buffer(enc, key);
-            UCX_TEST_ASSERT(dec->size == content->size, "aes_decrypt_buffer failed");
-            
-            UCX_TEST_ASSERT(!memcmp(content->space, dec->space, dec->size), "decrypted buffer has wrong content");
-            
-            cxBufferFree(content);
-            cxBufferFree(enc);
-            cxBufferFree(dec);
-            free(base64);
-            free(plain);
+CX_TEST(test_crypto_buffer) {
+    CX_TEST_DO {
+        for(int i=0;i<32;i++) {
+            DavKey *key = i < 16 ? &keys256[i] : &keys128[i%16];
+
+            for(int j=0;j<20;j++) {
+                CxBuffer *content = cxBufferCreate(NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
+                cxBufferPutString(content, strings[j]);
+                content->pos = 0;
+
+                CxBuffer *enc = aes_encrypt_buffer(content, key);
+                CX_TEST_ASSERT(enc->size >= content->size + 16);
+
+                char *base64 = util_base64encode(enc->space, enc->size);
+                size_t plainlen = 0;
+                char *plain = aes_decrypt(base64, &plainlen, key);
+
+                CX_TEST_ASSERT(plain);
+                CX_TEST_ASSERT(plainlen == content->size);
+                CX_TEST_ASSERT(!memcmp(plain, content->space, plainlen));
+
+                CxBuffer *dec = aes_decrypt_buffer(enc, key);
+                CX_TEST_ASSERT(dec->size == content->size);
+
+                CX_TEST_ASSERT(!memcmp(content->space, dec->space, dec->size));
+
+                cxBufferFree(content);
+                cxBufferFree(enc);
+                cxBufferFree(dec);
+                free(base64);
+                free(plain);
+            }
         }
     }
-    
-    UCX_TEST_END;
 }
 
-UCX_TEST(test_crypto_stream) {
+CX_TEST(test_crypto_stream) {
     CxBuffer *data = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     CxBuffer *cbuf = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     CxBuffer *pbuf = cxBufferCreate(NULL, 1024, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     
-    UCX_TEST_BEGIN;
-    
-    for(int i=0;i<32;i++) {
-        DavKey *key = i < 16 ? &keys256[i] : &keys128[i%16];
-        for(int j=0;j<20;j++) {
-            data->pos = 0;
-            data->size = 0;
-            size_t slen = strlen(strings[j]);
-            cxBufferWrite(strings[j], 1, slen, data);
-            cxBufferSeek(data, 0, SEEK_SET);
+    CX_TEST_DO {
+        for(int i=0;i<32;i++) {
+            DavKey *key = i < 16 ? &keys256[i] : &keys128[i%16];
+            for(int j=0;j<20;j++) {
+                data->pos = 0;
+                data->size = 0;
+                size_t slen = strlen(strings[j]);
+                cxBufferWrite(strings[j], 1, slen, data);
+                cxBufferSeek(data, 0, SEEK_SET);
 
-            cbuf->pos = 0;
-            cbuf->size = 0;
-            pbuf->pos = 0;
-            pbuf->size = 0;
+                cbuf->pos = 0;
+                cbuf->size = 0;
+                pbuf->pos = 0;
+                pbuf->size = 0;
 
-            AESEncrypter *enc = aes_encrypter_new(key, data, (dav_read_func)cxBufferRead, NULL);
-            char buf[1024];
-            size_t r = 0;
-            while((r = aes_read(buf, 1, 1024, enc)) != 0) {
-                cxBufferWrite(buf, 1, r, cbuf);
-            }
-            aes_encrypter_close(enc);
+                AESEncrypter *enc = aes_encrypter_new(key, data, (dav_read_func)cxBufferRead, NULL);
+                char buf[1024];
+                size_t r = 0;
+                while((r = aes_read(buf, 1, 1024, enc)) != 0) {
+                    cxBufferWrite(buf, 1, r, cbuf);
+                }
+                aes_encrypter_close(enc);
 
-            AESDecrypter *dec = aes_decrypter_new(key, pbuf, (dav_write_func)cxBufferWrite);
-            aes_write(cbuf->space, 1, cbuf->pos, dec);
-            aes_decrypter_shutdown(dec);
-            aes_decrypter_close(dec);
+                AESDecrypter *dec = aes_decrypter_new(key, pbuf, (dav_write_func)cxBufferWrite);
+                aes_write(cbuf->space, 1, cbuf->pos, dec);
+                aes_decrypter_shutdown(dec);
+                aes_decrypter_close(dec);
+
+                CX_TEST_ASSERT(slen == pbuf->pos);
+                CX_TEST_ASSERT(!memcmp(strings[j], pbuf->space, slen));
 
-            UCX_TEST_ASSERT(slen == pbuf->pos, "wrong length after enc-dec");
-            UCX_TEST_ASSERT(!memcmp(strings[j], pbuf->space, slen), "wrong content after enc-dec");
-            
-            data->pos = 0;
-            CxBuffer *enc2 = aes_encrypt_buffer(data, key);
-            CxBuffer *dec2 = aes_decrypt_buffer(enc2, key);
-            
-            UCX_TEST_ASSERT(dec2->size == data->size, "dec2 has wrong size");
-            UCX_TEST_ASSERT(!memcmp(strings[j], dec2->space, dec2->size), "dec2 has wrong content");
+                data->pos = 0;
+                CxBuffer *enc2 = aes_encrypt_buffer(data, key);
+                CxBuffer *dec2 = aes_decrypt_buffer(enc2, key);
+
+                CX_TEST_ASSERT(dec2->size == data->size);
+                CX_TEST_ASSERT(!memcmp(strings[j], dec2->space, dec2->size));
+            }
         }
     }
-    
-    UCX_TEST_END;
 }
 
 static char *pws[] = {
@@ -418,51 +410,50 @@
 };
 
 
-UCX_TEST(test_dav_pw2key) {
+CX_TEST(test_dav_pw2key) {
     
-    
-    UCX_TEST_BEGIN;
+    CX_TEST_DO {
     
-    for(int p=0;p<4;p++) {
-        for(int s=0;s<4;s++) {
-            DavKey *keys[4];
-            keys[0] =  dav_pw2key(
-                    pws[p],
-                    salt[s],
-                    saltlen[s],
-                    DAV_PWFUNC_PBKDF2_SHA256,
-                    DAV_KEY_AES128);
-            keys[1] = dav_pw2key(
-                    pws[p],
-                    salt[s],
-                    saltlen[s],
-                    DAV_PWFUNC_PBKDF2_SHA256,
-                    DAV_KEY_AES256);
-            keys[2] = dav_pw2key(
-                    pws[p],
-                    salt[s],
-                    saltlen[s],
-                    DAV_PWFUNC_PBKDF2_SHA512,
-                    DAV_KEY_AES128);
-            keys[3] = dav_pw2key(
-                    pws[p],
-                    salt[s],
-                    saltlen[s],
-                    DAV_PWFUNC_PBKDF2_SHA512,
-                    DAV_KEY_AES256);
-            
-            for(int i=0;i<4;i++) {
-                DavKey *key = keys[i];
-                
-                int index = 16*p + 4*s + i;
-                int keylen = index % 2 == 0 ? 16 : 32;
-                
-                UCX_TEST_ASSERT(key, "no key");
-                UCX_TEST_ASSERT(keylen == key->length, "wrong key length");
-                UCX_TEST_ASSERT(!memcmp(key->data, pwgenkeys[index], keylen), "wrong key data");
+        for(int p=0;p<4;p++) {
+            for(int s=0;s<4;s++) {
+                DavKey *keys[4];
+                keys[0] =  dav_pw2key(
+                        pws[p],
+                        salt[s],
+                        saltlen[s],
+                        DAV_PWFUNC_PBKDF2_SHA256,
+                        DAV_KEY_AES128);
+                keys[1] = dav_pw2key(
+                        pws[p],
+                        salt[s],
+                        saltlen[s],
+                        DAV_PWFUNC_PBKDF2_SHA256,
+                        DAV_KEY_AES256);
+                keys[2] = dav_pw2key(
+                        pws[p],
+                        salt[s],
+                        saltlen[s],
+                        DAV_PWFUNC_PBKDF2_SHA512,
+                        DAV_KEY_AES128);
+                keys[3] = dav_pw2key(
+                        pws[p],
+                        salt[s],
+                        saltlen[s],
+                        DAV_PWFUNC_PBKDF2_SHA512,
+                        DAV_KEY_AES256);
+
+                for(int i=0;i<4;i++) {
+                    DavKey *key = keys[i];
+
+                    int index = 16*p + 4*s + i;
+                    int keylen = index % 2 == 0 ? 16 : 32;
+
+                    CX_TEST_ASSERT(key);
+                    CX_TEST_ASSERT(keylen == key->length);
+                    CX_TEST_ASSERT(!memcmp(key->data, pwgenkeys[index], keylen));
+                }
             }
         }
+    
     }
-    
-    UCX_TEST_END;
 }
--- a/test/crypto.h	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/crypto.h	Sun Sep 07 15:57:36 2025 +0200
@@ -29,17 +29,17 @@
 #ifndef CRYPTO_H
 #define CRYPTO_H
 
-#include "test.h"
+#include <cx/test.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-UCX_TEST(test_util_decrypt_str_k);
-UCX_TEST(test_util_encrypt_str_k);
-UCX_TEST(test_crypto_buffer);
-UCX_TEST(test_crypto_stream);
-UCX_TEST(test_dav_pw2key);
+CX_TEST(test_util_decrypt_str_k);
+CX_TEST(test_util_encrypt_str_k);
+CX_TEST(test_crypto_buffer);
+CX_TEST(test_crypto_stream);
+CX_TEST(test_dav_pw2key);
 
 
 #ifdef __cplusplus
--- a/test/main.c	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/main.c	Sun Sep 07 15:57:36 2025 +0200
@@ -29,7 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "test.h"
+#include <cx/test.h>
 
 #include "base64.h"
 #include "crypto.h"
@@ -51,21 +51,21 @@
     printf("libidav tests\n");
     printf("-------------\n\n");
     
-    UcxTestSuite* suite = ucx_test_suite_new();
+    CxTestSuite* suite = cx_test_suite_new("libidav");
     
-    ucx_test_register(suite, test_util_base64decode);
-    ucx_test_register(suite, test_util_base64decode_len);
-    ucx_test_register(suite, test_util_base64encode);
-    ucx_test_register(suite, test_util_decrypt_str_k);
-    ucx_test_register(suite, test_util_encrypt_str_k);
-    ucx_test_register(suite, test_crypto_buffer);
-    ucx_test_register(suite, test_crypto_stream);
-    ucx_test_register(suite, test_dav_pw2key);
-    ucx_test_register(suite, test_util_parse_creationdate);
+    cx_test_register(suite, test_util_base64decode);
+    cx_test_register(suite, test_util_base64decode_len);
+    cx_test_register(suite, test_util_base64encode);
+    cx_test_register(suite, test_util_decrypt_str_k);
+    cx_test_register(suite, test_util_encrypt_str_k);
+    cx_test_register(suite, test_crypto_buffer);
+    cx_test_register(suite, test_crypto_stream);
+    cx_test_register(suite, test_dav_pw2key);
+    cx_test_register(suite, test_util_parse_creationdate);
     
-    ucx_test_run(suite, stdout);
+    cx_test_run(suite, stdout, (cx_write_func)fwrite);
     fflush(stdout);
-    ucx_test_suite_free(suite);
+    cx_test_suite_free(suite);
     
     return 0;
 }
--- a/test/test.c	Sun Sep 07 15:36:24 2025 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "test.h"
-
-UcxTestSuite* ucx_test_suite_new() {
-    UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite));
-    if (suite != NULL) {
-        suite->success = 0;
-        suite->failure = 0;
-        suite->tests = NULL;
-    }
-
-    return suite;
-}
-
-void ucx_test_suite_free(UcxTestSuite* suite) {
-    UcxTestList *l = suite->tests;
-    while (l != NULL) {
-        UcxTestList *e = l;
-        l = l->next;
-        free(e);
-    }
-    free(suite);
-}
-
-int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
-    if (suite->tests) {
-        UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
-        if (newelem) {
-            newelem->test = test;
-            newelem->next = NULL;
-            
-            UcxTestList *last = suite->tests;
-            while (last->next) {
-                last = last->next;
-            }
-            last->next = newelem;
-            
-            return EXIT_SUCCESS;
-        } else {
-            return EXIT_FAILURE;
-        }
-    } else {
-        suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
-        if (suite->tests) {
-            suite->tests->test = test;
-            suite->tests->next = NULL;
-            
-            return EXIT_SUCCESS;
-        } else {
-            return EXIT_FAILURE;
-        }
-    }
-}
-
-void ucx_test_run(UcxTestSuite* suite, FILE* output) {
-    suite->success = 0;
-    suite->failure = 0;
-    for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
-        elem->test(suite, output);
-    }
-    fwrite("\nAll test completed.\n", 1, 21, output);
-    fprintf(output, "  Total:   %u\n  Success: %u\n  Failure: %u\n",
-            suite->success+suite->failure, suite->success, suite->failure);
-}
--- a/test/test.h	Sun Sep 07 15:36:24 2025 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,241 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
- 
-/**
- * @file: test.h
- * 
- * UCX Test Framework.
- * 
- * Usage of this test framework:
- *
- * **** IN HEADER FILE: ****
- *
- * <pre>
- * UCX_TEST(function_name);
- * UCX_TEST_SUBROUTINE(subroutine_name, paramlist); // optional
- * </pre>
- *
- * **** IN SOURCE FILE: ****
- * <pre>
- * UCX_TEST_SUBROUTINE(subroutine_name, paramlist) {
- *   // tests with UCX_TEST_ASSERT()
- * }
- * 
- * UCX_TEST(function_name) {
- *   // memory allocation and other stuff here
- *   #UCX_TEST_BEGIN
- *   // tests with UCX_TEST_ASSERT() and/or
- *   // calls with UCX_TEST_CALL_SUBROUTINE() here
- *   #UCX_TEST_END
- *   // cleanup of memory here
- * }
- * </pre>
- *
- * <b>Note:</b> if a test fails, a longjump is performed
- * back to the #UCX_TEST_BEGIN macro!
- * 
- * <b>Attention:</b> Do not call own functions within a test, that use
- * UCX_TEST_ASSERT() macros and are not defined by using UCX_TEST_SUBROUTINE().
- * 
- *
- * @author Mike Becker
- * @author Olaf Wintermann
- *
- */
-
-#ifndef UCX_21_TEST_H
-#define	UCX_21_TEST_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <setjmp.h>
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-#ifndef __FUNCTION__
-
-/**
- * Alias for the <code>__func__</code> preprocessor macro.
- * Some compilers use <code>__func__</code> and others use __FUNCTION__.
- * We use __FUNCTION__ so we define it for those compilers which use
- * <code>__func__</code>.
- */
-#define __FUNCTION__ __func__
-#endif
-
-/** Type for the UcxTestSuite. */
-typedef struct UcxTestSuite UcxTestSuite;
-
-/** Pointer to a test function. */
-typedef void(*UcxTest)(UcxTestSuite*,FILE*);
-
-/** Type for the internal list of test cases. */
-typedef struct UcxTestList UcxTestList;
-
-/** Structure for the internal list of test cases. */
-struct UcxTestList {
-    
-    /** Test case. */
-    UcxTest test;
-    
-    /** Pointer to the next list element. */
-    UcxTestList *next;
-};
-
-/**
- * A test suite containing multiple test cases.
- */
-struct UcxTestSuite {
-    
-    /** The number of successful tests after the suite has been run. */
-    unsigned int success;
-    
-    /** The number of failed tests after the suite has been run. */
-    unsigned int failure;
-    
-    /**
-     * Internal list of test cases.
-     * Use ucx_test_register() to add tests to this list.
-     */
-    UcxTestList *tests;
-};
-
-/**
- * Creates a new test suite.
- * @return a new test suite
- */
-UcxTestSuite* ucx_test_suite_new();
-
-/**
- * Destroys a test suite.
- * @param suite the test suite to destroy
- */
-void ucx_test_suite_free(UcxTestSuite* suite);
-
-/**
- * Registers a test function with the specified test suite.
- * 
- * @param suite the suite, the test function shall be added to
- * @param test the test function to register
- * @return <code>EXIT_SUCCESS</code> on success or
- * <code>EXIT_FAILURE</code> on failure
- */
-int ucx_test_register(UcxTestSuite* suite, UcxTest test);
-
-/**
- * Runs a test suite and writes the test log to the specified stream.
- * @param suite the test suite to run
- * @param outstream the stream the log shall be written to
- */
-void ucx_test_run(UcxTestSuite* suite, FILE* outstream);
-
-/**
- * Macro for a #UcxTest function header.
- * 
- * Use this macro to declare and/or define a #UcxTest function.
- * 
- * @param name the name of the test function
- */
-#define UCX_TEST(name) void name(UcxTestSuite* _suite_,FILE *_output_)
-
-/**
- * Marks the begin of a test.
- * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>after</b>
- * #UCX_TEST_BEGIN.
- * 
- * @see #UCX_TEST_END
- */
-#define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\
-        fwrite(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
-        fwrite("... ", 1, 4, _output_);\
-        jmp_buf _env_; \
-        if (!setjmp(_env_)) {
-
-/**
- * Checks a test assertion.
- * If the assertion is correct, the test carries on. If the assertion is not
- * correct, the specified message (terminated by a dot and a line break) is
- * written to the test suites output stream.
- * @param condition the condition to check
- * @param message the message that shall be printed out on failure
- */
-#define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \
-        fwrite(message".\n", 1, 2+strlen(message), _output_); \
-        _suite_->failure++; \
-        longjmp(_env_, 1);\
-    }
-
-/**
- * Macro for a test subroutine function header.
- * 
- * Use this to declare and/or define a subroutine that can be called by using
- * UCX_TEST_CALL_SUBROUTINE().
- * 
- * @param name the name of the subroutine
- * @param ... the parameter list
- * 
- * @see UCX_TEST_CALL_SUBROUTINE()
- */
-#define UCX_TEST_SUBROUTINE(name,...) void name(UcxTestSuite* _suite_,\
-        FILE *_output_, jmp_buf _env_, __VA_ARGS__)
-
-/**
- * Macro for calling a test subroutine.
- * 
- * Subroutines declared with UCX_TEST_SUBROUTINE() can be called by using this
- * macro.
- * 
- * <b>Note:</b> You may <b>only</b> call subroutines within a #UCX_TEST_BEGIN-
- * #UCX_TEST_END-block.
- * 
- * @param name the name of the subroutine
- * @param ... the argument list
- * 
- * @see UCX_TEST_SUBROUTINE()
- */
-#define UCX_TEST_CALL_SUBROUTINE(name,...) \
-        name(_suite_,_output_,_env_,__VA_ARGS__);
-
-/**
- * Marks the end of a test.
- * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>before</b>
- * #UCX_TEST_END.
- * 
- * @see #UCX_TEST_BEGIN
- */
-#define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;}
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif	/* UCX_21_TEST_H */
-
--- a/test/test_finfo.h	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/test_finfo.h	Sun Sep 07 15:57:36 2025 +0200
@@ -29,7 +29,7 @@
 #ifndef TEST_FINFO_H
 #define TEST_FINFO_H
 
-#include "test.h"
+#include <cx/test.h>
 
 #ifdef __cplusplus
 extern "C" {
--- a/test/utils.c	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/utils.c	Sun Sep 07 15:57:36 2025 +0200
@@ -26,33 +26,28 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "test.h"
-
+#include "utils.h"
 #include <libidav/utils.h>
 
-UCX_TEST(test_util_parse_creationdate) {
-    UCX_TEST_BEGIN;
-    
-    time_t t1 = util_parse_creationdate("2012-11-29T21:35:36Z");
-    time_t t2 = util_parse_creationdate("2023-09-17T13:03:00+02:00");
-    
-    struct tm *tm = gmtime(&t1);
-    UCX_TEST_ASSERT(tm->tm_year == 112, "t1: wrong year");
-    UCX_TEST_ASSERT(tm->tm_mon == 10, "t1: wrong month");
-    UCX_TEST_ASSERT(tm->tm_mday == 29, "t1: wrong day");
-    UCX_TEST_ASSERT(tm->tm_hour == 21, "t1: wrong hour");
-    UCX_TEST_ASSERT(tm->tm_min == 35, "t1: wrong minute");
-    UCX_TEST_ASSERT(tm->tm_sec == 36, "t1: wrong second");
-    
-    tm = gmtime(&t2);
-    UCX_TEST_ASSERT(tm->tm_year == 123, "t2: wrong year");
-    UCX_TEST_ASSERT(tm->tm_mon == 8, "t2: wrong month");
-    UCX_TEST_ASSERT(tm->tm_mday == 17, "t2: wrong day");
-    UCX_TEST_ASSERT(tm->tm_hour == 11, "t2: wrong hour");
-    UCX_TEST_ASSERT(tm->tm_min == 03, "t2: wrong minute");
-    UCX_TEST_ASSERT(tm->tm_sec == 0, "t2: wrong second");
-    
-    UCX_TEST_END;
-    
-    
+CX_TEST(test_util_parse_creationdate) {
+    CX_TEST_DO {
+        time_t t1 = util_parse_creationdate("2012-11-29T21:35:36Z");
+        time_t t2 = util_parse_creationdate("2023-09-17T13:03:00+02:00");
+
+        struct tm *tm = gmtime(&t1);
+        CX_TEST_ASSERT(tm->tm_year == 112);
+        CX_TEST_ASSERT(tm->tm_mon == 10);
+        CX_TEST_ASSERT(tm->tm_mday == 29);
+        CX_TEST_ASSERT(tm->tm_hour == 21);
+        CX_TEST_ASSERT(tm->tm_min == 35);
+        CX_TEST_ASSERT(tm->tm_sec == 36);
+
+        tm = gmtime(&t2);
+        CX_TEST_ASSERT(tm->tm_year == 123);
+        CX_TEST_ASSERT(tm->tm_mon == 8);
+        CX_TEST_ASSERT(tm->tm_mday == 17);
+        CX_TEST_ASSERT(tm->tm_hour == 11);
+        CX_TEST_ASSERT(tm->tm_min == 03);
+        CX_TEST_ASSERT(tm->tm_sec == 0);
+    }  
 }
--- a/test/utils.h	Sun Sep 07 15:36:24 2025 +0200
+++ b/test/utils.h	Sun Sep 07 15:57:36 2025 +0200
@@ -29,13 +29,13 @@
 #ifndef TEST_UTILS_H
 #define TEST_UTILS_H
 
-#include "test.h"
+#include <cx/test.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-UCX_TEST(test_util_parse_creationdate);
+CX_TEST(test_util_parse_creationdate);
 
 
 #ifdef __cplusplus

mercurial