src/server/test/xml.c

changeset 633
392ec9026b07
parent 324
44cf877b3d9f
--- a/src/server/test/xml.c	Sat Nov 22 12:49:20 2025 +0100
+++ b/src/server/test/xml.c	Sat Nov 22 14:27:01 2025 +0100
@@ -152,57 +152,57 @@
     return 0;
 }
 
-UCX_TEST(test_wsxml_iterator) {
+CX_TEST(test_wsxml_iterator) {
     Session *sn = testutil_session();
     
-    UCX_TEST_BEGIN;
-    
-    xmlDoc *doc = xmlReadMemory(
-            XML_TESTDATA1, strlen(XML_TESTDATA1), NULL, NULL, 0);
-    xmlDoc *doc2 = xmlReadMemory(
-            XML_TESTDATA2, strlen(XML_TESTDATA2), NULL, NULL, 0);
-    xmlDoc *doc6 = xmlReadMemory(
-            XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0);
-    UCX_TEST_ASSERT(doc, "doc is NULL");
-    UCX_TEST_ASSERT(doc2, "doc2 is NULL");
-    UCX_TEST_ASSERT(doc6, "doc6 is NULL");
-    
-    xmlNode *root = xmlDocGetRootElement(doc);
-    
-    // Test 1: iterate over complete document
-    Test1Data testdata;
-    ZERO(&testdata, sizeof(Test1Data));
-    int ret = wsxml_iterator(sn->pool, root, test1_begin, test1_end, &testdata);
-    UCX_TEST_ASSERT(ret == 0, "wsxml_iterator failed");
-    UCX_TEST_ASSERT(!testdata.err, "wrong element order (begin)");
-    UCX_TEST_ASSERT(!testdata.endErr, "wrong element order (end)");
-    UCX_TEST_ASSERT(!testdata.textErr, "text order error");
-    UCX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter, "begin/end counter not equal");
+    CX_TEST_DO {
     
-    // Test 2: iterate over sub-document
-    ZERO(&testdata, sizeof(Test1Data));
-    xmlNode *root2 = xmlDocGetRootElement(doc2);
-    xmlNode *sub = root2->children->children;
-    ret = wsxml_iterator(sn->pool, sub, test1_begin, test1_end, &testdata);
-    UCX_TEST_ASSERT(ret == 0, "test2: wsxml_iterator failed");
-    UCX_TEST_ASSERT(!testdata.err, "test2: wrong element order (begin)");
-    UCX_TEST_ASSERT(!testdata.endErr, "test2: wrong element order (end)");
-    UCX_TEST_ASSERT(!testdata.textErr, "test2: text order error");
-    UCX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter, "test2: begin/end counter not equal");
-    
-    // Test 3: iterate over document with all kinds of node types
-    xmlNode *root6 = xmlDocGetRootElement(doc6);
-    ZERO(&testdata, sizeof(Test1Data));
-    ret = wsxml_iterator(sn->pool, root6, test2_begin, test2_end, &testdata);
-    UCX_TEST_ASSERT(ret == 0, "test3: wsxml_iterator failed");
-    UCX_TEST_ASSERT(testdata.elmCounter == testdata.endElmCounter, "test3: begin/end counter not equal");
-    UCX_TEST_ASSERT(testdata.elmCounter == 12, "test3: wrong elm counter");
-    UCX_TEST_ASSERT(testdata.nodesWithAttributesCounter == 5, "test3: wrong entity ref counter");
-    
-    xmlFreeDoc(doc);
-    xmlFreeDoc(doc2);
-    xmlFreeDoc(doc6);
-    UCX_TEST_END;
+        xmlDoc *doc = xmlReadMemory(
+                XML_TESTDATA1, strlen(XML_TESTDATA1), NULL, NULL, 0);
+        xmlDoc *doc2 = xmlReadMemory(
+                XML_TESTDATA2, strlen(XML_TESTDATA2), NULL, NULL, 0);
+        xmlDoc *doc6 = xmlReadMemory(
+                XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0);
+        CX_TEST_ASSERT(doc);
+        CX_TEST_ASSERT(doc2);
+        CX_TEST_ASSERT(doc6);
+
+        xmlNode *root = xmlDocGetRootElement(doc);
+
+        // Test 1: iterate over complete document
+        Test1Data testdata;
+        ZERO(&testdata, sizeof(Test1Data));
+        int ret = wsxml_iterator(sn->pool, root, test1_begin, test1_end, &testdata);
+        CX_TEST_ASSERT(ret == 0);
+        CX_TEST_ASSERT(!testdata.err);
+        CX_TEST_ASSERT(!testdata.endErr);
+        CX_TEST_ASSERT(!testdata.textErr);
+        CX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter);
+
+        // Test 2: iterate over sub-document
+        ZERO(&testdata, sizeof(Test1Data));
+        xmlNode *root2 = xmlDocGetRootElement(doc2);
+        xmlNode *sub = root2->children->children;
+        ret = wsxml_iterator(sn->pool, sub, test1_begin, test1_end, &testdata);
+        CX_TEST_ASSERT(ret == 0);
+        CX_TEST_ASSERT(!testdata.err);
+        CX_TEST_ASSERT(!testdata.endErr);
+        CX_TEST_ASSERT(!testdata.textErr);
+        CX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter);
+
+        // Test 3: iterate over document with all kinds of node types
+        xmlNode *root6 = xmlDocGetRootElement(doc6);
+        ZERO(&testdata, sizeof(Test1Data));
+        ret = wsxml_iterator(sn->pool, root6, test2_begin, test2_end, &testdata);
+        CX_TEST_ASSERT(ret == 0);
+        CX_TEST_ASSERT(testdata.elmCounter == testdata.endElmCounter);
+        CX_TEST_ASSERT(testdata.elmCounter == 12);
+        CX_TEST_ASSERT(testdata.nodesWithAttributesCounter == 5);
+
+        xmlFreeDoc(doc);
+        xmlFreeDoc(doc2);
+        xmlFreeDoc(doc6);
+    }
     
     testutil_destroy_session(sn);
 }
@@ -238,193 +238,193 @@
     }
 }
 
-UCX_TEST(test_wsxml_get_required_namespaces) {
+CX_TEST(test_wsxml_get_required_namespaces) {
     Session *sn = testutil_session();
     
-    UCX_TEST_BEGIN;
-    
-    xmlDoc *doc3 = xmlReadMemory(
-            XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0);
-    xmlDoc *doc4 = xmlReadMemory(
-            XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0);
-    xmlDoc *doc5 = xmlReadMemory(
-            XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0);
-    
-    xmlNode *node0 = xmlDocGetRootElement(doc3);
-    xmlNode *node1 = xmlDocGetRootElement(doc3)->children;
-    xmlNode *node2 = xmlDocGetRootElement(doc4)->children;
-    xmlNode *node3 = xmlDocGetRootElement(doc5)->children;
-    
-    UCX_TEST_ASSERT(doc3, "doc3 is NULL");
-    UCX_TEST_ASSERT(doc4, "doc4 is NULL");
-    UCX_TEST_ASSERT(doc5, "doc5 is NULL");
-    
-    int err0, err1, err2, err3;
-    int x1 = 0;
-    int x2 = 0;
-    int x3 = 0;
-    int x4 = 0;
-    WebdavNSList *elm = NULL;
-    
-    // Test 0: 
-    WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0);
-    UCX_TEST_ASSERT(!err0, "ns0 failed");
-    UCX_TEST_ASSERT(!ns0, "ns0: nsdefs should be ignored");
+    CX_TEST_DO {
     
-    WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1);
-    check_ns_list(ns1, &x1, &x2, &x3, &x4);
-    UCX_TEST_ASSERT(!err1, "ns1 failed");
-    UCX_TEST_ASSERT(ns1, "ns1: no list");
-    UCX_TEST_ASSERT(x1, "ns1: x1 missing");
-    UCX_TEST_ASSERT(x2, "ns1: x2 missing");
-    UCX_TEST_ASSERT(x3, "ns1: x3 missing");
-    UCX_TEST_ASSERT(x4, "ns1: x4 missing");
-    
-    WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2);
-    check_ns_list(ns2, &x1, &x2, &x3, &x4);
-    UCX_TEST_ASSERT(!err2, "ns2 failed");
-    UCX_TEST_ASSERT(ns2, "ns2: no list");
-    UCX_TEST_ASSERT(x1, "ns2: x1 missing");
-    UCX_TEST_ASSERT(x2, "ns2: x2 missing");
-    UCX_TEST_ASSERT(!x3, "ns2: x3");
-    UCX_TEST_ASSERT(!x4, "ns2: x4");
-    
-    WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3);
-    check_ns_list(ns3, &x1, &x2, &x3, &x4);
-    UCX_TEST_ASSERT(!err3, "ns3 failed");
-    UCX_TEST_ASSERT(ns3, "ns3: no list");
-    UCX_TEST_ASSERT(x1, "ns3: x1 missing");
-    UCX_TEST_ASSERT(x2, "ns3: x2 missing");
-    UCX_TEST_ASSERT(!x3, "ns3: x3");
-    UCX_TEST_ASSERT(!x4, "ns3: x4");
-    
-    xmlFreeDoc(doc3);
-    xmlFreeDoc(doc4);
-    xmlFreeDoc(doc5);
-    UCX_TEST_END;
+        xmlDoc *doc3 = xmlReadMemory(
+                XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0);
+        xmlDoc *doc4 = xmlReadMemory(
+                XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0);
+        xmlDoc *doc5 = xmlReadMemory(
+                XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0);
+
+        xmlNode *node0 = xmlDocGetRootElement(doc3);
+        xmlNode *node1 = xmlDocGetRootElement(doc3)->children;
+        xmlNode *node2 = xmlDocGetRootElement(doc4)->children;
+        xmlNode *node3 = xmlDocGetRootElement(doc5)->children;
+
+        CX_TEST_ASSERT(doc3);
+        CX_TEST_ASSERT(doc4);
+        CX_TEST_ASSERT(doc5);
+
+        int err0, err1, err2, err3;
+        int x1 = 0;
+        int x2 = 0;
+        int x3 = 0;
+        int x4 = 0;
+        WebdavNSList *elm = NULL;
+
+        // Test 0: 
+        WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0);
+        CX_TEST_ASSERT(!err0);
+        CX_TEST_ASSERT(!ns0);
+
+        WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1);
+        check_ns_list(ns1, &x1, &x2, &x3, &x4);
+        CX_TEST_ASSERT(!err1);
+        CX_TEST_ASSERT(ns1);
+        CX_TEST_ASSERT(x1);
+        CX_TEST_ASSERT(x2);
+        CX_TEST_ASSERT(x3);
+        CX_TEST_ASSERT(x4);
+
+        WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2);
+        check_ns_list(ns2, &x1, &x2, &x3, &x4);
+        CX_TEST_ASSERT(!err2);
+        CX_TEST_ASSERT(ns2);
+        CX_TEST_ASSERT(x1);
+        CX_TEST_ASSERT(x2);
+        CX_TEST_ASSERT(!x3);
+        CX_TEST_ASSERT(!x4);
+
+        WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3);
+        check_ns_list(ns3, &x1, &x2, &x3, &x4);
+        CX_TEST_ASSERT(!err3);
+        CX_TEST_ASSERT(ns3);
+        CX_TEST_ASSERT(x1);
+        CX_TEST_ASSERT(x2);
+        CX_TEST_ASSERT(!x3);
+        CX_TEST_ASSERT(!x4);
+
+        xmlFreeDoc(doc3);
+        xmlFreeDoc(doc4);
+        xmlFreeDoc(doc5);
+    }
     
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_wsxml_write_nodes) {
+CX_TEST(test_wsxml_write_nodes) {
     Session *sn = testutil_session();
     TestIOStream *st = testutil_iostream(2048, TRUE);
     
-    UCX_TEST_BEGIN;
-    xmlDoc *doc = xmlReadMemory(
-            XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0);
-    UCX_TEST_ASSERT(doc, "xml parser error");
-    xmlNode *root = xmlDocGetRootElement(doc);
-    
-    Writer writer;
-    char buffer[1024];
-    writer_init(&writer, st, buffer, 1024);
+    CX_TEST_DO {
+        xmlDoc *doc = xmlReadMemory(
+                XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0);
+        CX_TEST_ASSERT(doc);
+        xmlNode *root = xmlDocGetRootElement(doc);
+
+        Writer writer;
+        char buffer[1024];
+        writer_init(&writer, st, buffer, 1024);
+
+        int err = wsxml_write_nodes(sn->pool, &writer, NULL, root);
+        writer_flush(&writer);
+        CX_TEST_ASSERT(err == 0);
+        CX_TEST_ASSERT(st->buf->pos > 0);
+
+        //printf("\n\n");
+        //printf("%.*s\n", (int)st->buf->size, st->buf->space);
+        //printf("\n\n");
+
+        xmlDoc *genDoc = xmlReadMemory(
+                st->buf->space, st->buf->size, NULL, NULL, 0);
+        CX_TEST_ASSERT(genDoc);
+
+        xmlFreeDoc(doc);
+        xmlFreeDoc(genDoc);
     
-    int err = wsxml_write_nodes(sn->pool, &writer, NULL, root);
-    writer_flush(&writer);
-    UCX_TEST_ASSERT(err == 0, "wsxml_write_nodes error");
-    UCX_TEST_ASSERT(st->buf->pos > 0, "buffer is empty");
-    
-    //printf("\n\n");
-    //printf("%.*s\n", (int)st->buf->size, st->buf->space);
-    //printf("\n\n");
-    
-    xmlDoc *genDoc = xmlReadMemory(
-            st->buf->space, st->buf->size, NULL, NULL, 0);
-    UCX_TEST_ASSERT(genDoc, "generated doc is not valid xml");
-    
-    xmlFreeDoc(doc);
-    xmlFreeDoc(genDoc);
-    
-    UCX_TEST_END;
+    }
     testutil_iostream_destroy(st);
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_wsxml_nslist2string) {
+CX_TEST(test_wsxml_nslist2string) {
     Session *sn = testutil_session();
     
-    UCX_TEST_BEGIN;
-    
-    WSNamespace ns1;
-    WSNamespace ns2;
-    WSNamespace ns3;  
-    memset(&ns1, 0, sizeof(WSNamespace));
-    memset(&ns2, 0, sizeof(WSNamespace));
-    memset(&ns3, 0, sizeof(WSNamespace));
-    ns1.prefix = (const xmlChar*)"x";
-    ns1.href = (const xmlChar*)"ns1";
-    ns2.prefix = (const xmlChar*)"y";
-    ns2.href = (const xmlChar*)"ns2";
-    ns3.prefix = (const xmlChar*)"z";
-    ns3.href = (const xmlChar*)"ns3";
-    
-    WebdavNSList elm1 = { &ns1, NULL, NULL };
-    WebdavNSList elm2 = { &ns2, NULL, NULL };
-    WebdavNSList elm3 = { &ns3, NULL, NULL };
+    CX_TEST_DO {
     
-    // single elm test
-    char *str1 = wsxml_nslist2string(sn->pool, &elm1);
-    UCX_TEST_ASSERT(str1, "str1 is null");
-    UCX_TEST_ASSERT(!strcmp(str1, "x:ns1"), "str1: wrong content");
-    
-    // 2 elm test
-    elm1.next = &elm2;
-    char *str2 = wsxml_nslist2string(sn->pool, &elm1);
-    UCX_TEST_ASSERT(str2, "str2 is null");
-    UCX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2"), "str2: wrong content");
+        WSNamespace ns1;
+        WSNamespace ns2;
+        WSNamespace ns3;  
+        memset(&ns1, 0, sizeof(WSNamespace));
+        memset(&ns2, 0, sizeof(WSNamespace));
+        memset(&ns3, 0, sizeof(WSNamespace));
+        ns1.prefix = (const xmlChar*)"x";
+        ns1.href = (const xmlChar*)"ns1";
+        ns2.prefix = (const xmlChar*)"y";
+        ns2.href = (const xmlChar*)"ns2";
+        ns3.prefix = (const xmlChar*)"z";
+        ns3.href = (const xmlChar*)"ns3";
+
+        WebdavNSList elm1 = { &ns1, NULL, NULL };
+        WebdavNSList elm2 = { &ns2, NULL, NULL };
+        WebdavNSList elm3 = { &ns3, NULL, NULL };
+
+        // single elm test
+        char *str1 = wsxml_nslist2string(sn->pool, &elm1);
+        CX_TEST_ASSERT(str1);
+        CX_TEST_ASSERT(!strcmp(str1, "x:ns1"));
+
+        // 2 elm test
+        elm1.next = &elm2;
+        char *str2 = wsxml_nslist2string(sn->pool, &elm1);
+        CX_TEST_ASSERT(str2);
+        CX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2"));
+
+        // 3 elm test
+        elm2.next = &elm3;
+        char *str3 = wsxml_nslist2string(sn->pool, &elm1);
+        CX_TEST_ASSERT(str3);
+        CX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3"));
+
+        // empty prefix test
+        ns1.prefix = NULL;
+        char *str4 = wsxml_nslist2string(sn->pool, &elm1);
+        CX_TEST_ASSERT(str4);
+        CX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3"));
     
-    // 3 elm test
-    elm2.next = &elm3;
-    char *str3 = wsxml_nslist2string(sn->pool, &elm1);
-    UCX_TEST_ASSERT(str3, "str3 is null");
-    UCX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3"), "str3: wrong content");
-    
-    // empty prefix test
-    ns1.prefix = NULL;
-    char *str4 = wsxml_nslist2string(sn->pool, &elm1);
-    UCX_TEST_ASSERT(str4, "str3 is null");
-    UCX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3"), "str4: wrong content");
-    
-    UCX_TEST_END;
+    }
     testutil_destroy_session(sn);
 }
 
-UCX_TEST(test_wsxml_string2nslist) {
+CX_TEST(test_wsxml_string2nslist) {
     Session *sn = testutil_session();
     
-    UCX_TEST_BEGIN;
-    
-    // empty list
-    WebdavNSList *list1 = wsxml_string2nslist(sn->pool, "");
-    UCX_TEST_ASSERT(!list1, "list1 should be NULL");
-    
-    // 1 elm list
-    WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1");
-    UCX_TEST_ASSERT(list2, "list2 is NULL");
-    UCX_TEST_ASSERT(list2->namespace, "list2 namespace is NULL");
-    UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x"), "list2: wrong prefix");
-    UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1"), "list2: wrong href");
+    CX_TEST_DO {
     
-    // 2 elm list
-    WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2");
-    UCX_TEST_ASSERT(list3, "list3 is NULL");
-    UCX_TEST_ASSERT(list3->namespace, "list3 namespace is NULL");
-    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: wrong prefix");
-    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
-    UCX_TEST_ASSERT(list3->next, "list3 elm2 is NULL");
-    UCX_TEST_ASSERT(list3->next->namespace, "list3 namespace 2 is NULL");
-    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: elm2 wrong prefix");
-    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: elm2 wrong href");
-    
-    // empty prefix
-    WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2");
-    UCX_TEST_ASSERT(list4, "list4 is NULL");
-    UCX_TEST_ASSERT(list4->namespace, "list4 namespace is NULL");
-    UCX_TEST_ASSERT(!list4->namespace->prefix, "list4 elm1 prefix should be NULL");
-    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
+        // empty list
+        WebdavNSList *list1 = wsxml_string2nslist(sn->pool, "");
+        CX_TEST_ASSERT(!list1);
+
+        // 1 elm list
+        WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1");
+        CX_TEST_ASSERT(list2);
+        CX_TEST_ASSERT(list2->namespace);
+        CX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x"));
+        CX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1"));
+
+        // 2 elm list
+        WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2");
+        CX_TEST_ASSERT(list3);
+        CX_TEST_ASSERT(list3->namespace);
+        CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"));
+        CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"));
+        CX_TEST_ASSERT(list3->next);
+        CX_TEST_ASSERT(list3->next->namespace);
+        CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"));
+        CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"));
+
+        // empty prefix
+        WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2");
+        CX_TEST_ASSERT(list4);
+        CX_TEST_ASSERT(list4->namespace);
+        CX_TEST_ASSERT(!list4->namespace->prefix);
+        CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"));
     
     
-    UCX_TEST_END;
+    }
     testutil_destroy_session(sn);
 }

mercurial