src/server/test/writer.c

changeset 633
392ec9026b07
parent 415
d938228c382e
--- a/src/server/test/writer.c	Sat Nov 22 12:49:20 2025 +0100
+++ b/src/server/test/writer.c	Sat Nov 22 14:27:01 2025 +0100
@@ -36,116 +36,112 @@
 #include "writer.h"
 #include "testutils.h"
 
-UCX_TEST(test_writer_putc) {
+CX_TEST(test_writer_putc) {
     Session *sn = testutil_session();
     TestIOStream *st = testutil_iostream(2048, TRUE);
     CxBuffer *buf = st->buf;
     
-    UCX_TEST_BEGIN;
-    
-    Writer writer;
-    char wbuf[1024];
-    writer_init(&writer, st, wbuf, 4);
-    Writer *out = &writer;
-    
-    writer_putc(out, 'a');
-    UCX_TEST_ASSERT(wbuf[0] == 'a', "1: wrong char at pos 0");
-    UCX_TEST_ASSERT(writer.pos == 1, "1: wrong pos");
+    CX_TEST_DO {
     
-    writer_putc(out, 'b');
-    UCX_TEST_ASSERT(wbuf[1] == 'b', "2: wrong char at pos 1");
-    UCX_TEST_ASSERT(writer.pos == 2, "2: wrong pos");
-    
-    writer_putc(out, 'c');
-    writer_putc(out, 'd');
-    UCX_TEST_ASSERT(wbuf[2] == 'c', "3: wrong char at pos 2");
-    UCX_TEST_ASSERT(wbuf[3] == 'd', "4: wrong char at pos 3");
+        Writer writer;
+        char wbuf[1024];
+        writer_init(&writer, st, wbuf, 4);
+        Writer *out = &writer;
+
+        writer_putc(out, 'a');
+        CX_TEST_ASSERT(wbuf[0] == 'a');
+        CX_TEST_ASSERT(writer.pos == 1);
+
+        writer_putc(out, 'b');
+        CX_TEST_ASSERT(wbuf[1] == 'b');
+        CX_TEST_ASSERT(writer.pos == 2);
+
+        writer_putc(out, 'c');
+        writer_putc(out, 'd');
+        CX_TEST_ASSERT(wbuf[2] == 'c');
+        CX_TEST_ASSERT(wbuf[3] == 'd');
+
+        writer_putc(out, 'f'); // should flush the buffer
+        CX_TEST_ASSERT(wbuf[0] == 'f');
+        CX_TEST_ASSERT(writer.pos == 1);
+        CX_TEST_ASSERT(buf->space[0] == 'a');
+        CX_TEST_ASSERT(buf->space[1] == 'b');
+        CX_TEST_ASSERT(buf->pos == 4);    
     
-    writer_putc(out, 'f'); // should flush the buffer
-    UCX_TEST_ASSERT(wbuf[0] == 'f', "5: wrong char at pos 0");
-    UCX_TEST_ASSERT(writer.pos == 1, "5: wrong pos");
-    UCX_TEST_ASSERT(buf->space[0] == 'a', "5: wrong char at UcxBuffer pos 0");
-    UCX_TEST_ASSERT(buf->space[1] == 'b', "5: wrong char at UcxBuffer pos 1");
-    UCX_TEST_ASSERT(buf->pos == 4, "5: wrong UcxBuffer pos");    
-    
-    UCX_TEST_END;
+    }
     testutil_iostream_destroy(st);
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_writer_flush) {
+CX_TEST(test_writer_flush) {
     Session *sn = testutil_session();
     TestIOStream *st = testutil_iostream(2048, TRUE);
     CxBuffer *buf = st->buf;
     
-    UCX_TEST_BEGIN;
-    
-    Writer writer;
-    char wbuf[1024];
-    writer_init(&writer, st, wbuf, 4);
-    Writer *out = &writer;
-    
-    writer_putc(out, 'a');
-    UCX_TEST_ASSERT(wbuf[0] == 'a', "1: wrong char at pos 0");
-    UCX_TEST_ASSERT(writer.pos == 1, "1: wrong pos");
+    CX_TEST_DO {
     
-    writer_flush(out);
-    UCX_TEST_ASSERT(writer.pos == 0, "wrong pos after flush");
-    UCX_TEST_ASSERT(buf->space[0] == 'a', "wrong UcxBuffer content");
-    UCX_TEST_ASSERT(buf->pos == 1, "wrong UcxBuffer pos");
+        Writer writer;
+        char wbuf[1024];
+        writer_init(&writer, st, wbuf, 4);
+        Writer *out = &writer;
+
+        writer_putc(out, 'a');
+        CX_TEST_ASSERT(wbuf[0] == 'a');
+        CX_TEST_ASSERT(writer.pos == 1);
+
+        writer_flush(out);
+        CX_TEST_ASSERT(writer.pos == 0);
+        CX_TEST_ASSERT(buf->space[0] == 'a');
+        CX_TEST_ASSERT(buf->pos == 1);
+
+        writer_putc(out, 'b');
+        CX_TEST_ASSERT(wbuf[0] == 'b');
+        CX_TEST_ASSERT(writer.pos == 1);
     
-    writer_putc(out, 'b');
-    UCX_TEST_ASSERT(wbuf[0] == 'b', "2: wrong char at pos 0");
-    UCX_TEST_ASSERT(writer.pos == 1, "2: wrong pos");
-    
-    UCX_TEST_END;
+    }
     testutil_iostream_destroy(st);
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_writer_put) {
+CX_TEST(test_writer_put) {
     Session *sn = testutil_session();
     TestIOStream *st = testutil_iostream(2048, TRUE);
     CxBuffer *buf = st->buf;
     
-    UCX_TEST_BEGIN;
-    
-    Writer writer;
-    char wbuf[1024];
-    writer_init(&writer, st, wbuf, 8);
-    Writer *out = &writer;
-    
-    writer_put(out, "abcd", 4);
-    UCX_TEST_ASSERT(!memcmp(wbuf, "abcd", 4), "1: wrong content");
-    UCX_TEST_ASSERT(writer.pos == 4, "1: wrong pos");
-    
-    writer_put(out, "efgh", 4);
-    UCX_TEST_ASSERT(!memcmp(wbuf, "abcdefgh", 8), "2: wrong content");
-    UCX_TEST_ASSERT(writer.pos == 8, "2: wrong pos");
+    CX_TEST_DO {
     
-    writer_put(out, "1234", 4);
-    UCX_TEST_ASSERT(!memcmp(wbuf, "1234", 4), "3: wrong content");
-    UCX_TEST_ASSERT(writer.pos == 4, "3: wrong pos");
-    UCX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh", 8), "3: wrong UcxBuffer content");
-    UCX_TEST_ASSERT(buf->pos == 8, "3: wrong UcxBuffer pos");
-    
-    writer_put(out, "5678xx", 6);
-    UCX_TEST_ASSERT(!memcmp(wbuf, "xx", 2), "4: wrong content");
-    UCX_TEST_ASSERT(writer.pos == 2, "4: wrong pos");
-    UCX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678", 16), "4: wrong UcxBuffer content");
-    UCX_TEST_ASSERT(buf->pos == 16, "4: wrong UcxBuffer pos");
+        Writer writer;
+        char wbuf[1024];
+        writer_init(&writer, st, wbuf, 8);
+        Writer *out = &writer;
+
+        writer_put(out, "abcd", 4);
+        CX_TEST_ASSERT(!memcmp(wbuf, "abcd", 4));
+        CX_TEST_ASSERT(writer.pos == 4);
+
+        writer_put(out, "efgh", 4);
+        CX_TEST_ASSERT(!memcmp(wbuf, "abcdefgh", 8));
+        CX_TEST_ASSERT(writer.pos == 8);
+
+        writer_put(out, "1234", 4);
+        CX_TEST_ASSERT(!memcmp(wbuf, "1234", 4));
+        CX_TEST_ASSERT(writer.pos == 4);
+        CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh", 8));
+        CX_TEST_ASSERT(buf->pos == 8);
+
+        writer_put(out, "5678xx", 6);
+        CX_TEST_ASSERT(!memcmp(wbuf, "xx", 2));
+        CX_TEST_ASSERT(writer.pos == 2);
+        CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678", 16));
+        CX_TEST_ASSERT(buf->pos == 16);
+
+        writer_puts(out, cx_str("345678abcdefgh12345678end."));
+        CX_TEST_ASSERT(!memcmp(wbuf, "end.", 4));
+        CX_TEST_ASSERT(writer.pos == 4);
+        CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678xx345678abcdefgh12345678", 40));
+        CX_TEST_ASSERT(buf->pos == 40);
     
-    writer_puts(out, cx_str("345678abcdefgh12345678end."));
-    UCX_TEST_ASSERT(!memcmp(wbuf, "end.", 4), "5: wrong content");
-    UCX_TEST_ASSERT(writer.pos == 4, "5: wrong pos");
-    UCX_TEST_ASSERT(!memcmp(
-            buf->space,
-            "abcdefgh12345678xx345678abcdefgh12345678",
-            40),
-            "5: wrong UcxBuffer content");
-    UCX_TEST_ASSERT(buf->pos == 40, "5: wrong UcxBuffer pos");
-    
-    UCX_TEST_END;
+    }
     testutil_iostream_destroy(st);
     testutil_destroy_session(sn);
 }

mercurial