src/server/plugins/postgresql/pgtest.c

changeset 415
d938228c382e
parent 403
0f678595d497
child 490
d218607f5a7e
--- a/src/server/plugins/postgresql/pgtest.c	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/plugins/postgresql/pgtest.c	Sun Nov 06 15:53:32 2022 +0100
@@ -36,9 +36,9 @@
 #include "../../public/webdav.h"
 #include "../../webdav/webdav.h"
 
-#include <ucx/string.h>
-#include <ucx/utils.h>
-#include <ucx/buffer.h>
+#include <cx/string.h>
+#include <cx/utils.h>
+#include <cx/buffer.h>
 
 #include "pgtest.h"
 #include "vfs.h"
@@ -48,6 +48,9 @@
 
 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
 
+#define MAP_GET(map, key) cxMapGet(map, cx_hash_key_str(key))
+#define MAP_PUT(map, key, value) cxMapPut(map, cx_hash_key_str(key), value)
+
 static char *pg_connstr = "postgresql://localhost/test1";
 static int abort_pg_tests = 0;
 static PGconn *test_connection;
@@ -118,11 +121,11 @@
 
 static void parse_response_tag(TestMultistatus *ms, xmlNode *node) {
     // thanks to dav for some of this code
-    UcxAllocator *a = ms->mp->allocator;
+    CxAllocator *a = (CxAllocator*)ms->mp->allocator;
     node = node->children;
     
-    sstr_t href = {NULL, 0};
-    UcxMap *properties = ucx_map_new_a(ms->mp->allocator, 16);
+    cxmutstr href = {NULL, 0};
+    CxMap *properties = cxHashMapCreate(a, 16);
     
     while(node) {
         if(node->type == XML_ELEMENT_NODE) {
@@ -131,7 +134,7 @@
                 if(href_node->type != XML_TEXT_NODE) {
                     return;
                 }
-                href = sstrdup_a(ms->mp->allocator, scstr((const char*)href_node->content));
+                href = cx_strdup_a(a, cx_str((const char*)href_node->content));
             } else if(xstreq(node->name, "propstat")) {
                 xmlNode *n = node->children;
                 xmlNode *prop_node = NULL;
@@ -145,12 +148,12 @@
                             if(status_node->type != XML_TEXT_NODE) {
                                 return;
                             }
-                            sstr_t status_str = sstr((char*)status_node->content);
+                            cxmutstr status_str = cx_mutstr((char*)status_node->content);
                             if(status_str.length < 13) {
                                 return;
                             }
-                            status_str = sstrsubsl(status_str, 9, 3);
-                            sstr_t status_s = sstrdup(status_str);
+                            status_str = cx_strsubsl_m(status_str, 9, 3);
+                            cxmutstr status_s = cx_strdup(cx_strcast(status_str));
                             status_code = atoi(status_s.ptr);
                             free(status_s.ptr);
                         }
@@ -161,21 +164,21 @@
                 n = prop_node->children;
                 while(n) {
                     if(n->type == XML_ELEMENT_NODE) {
-                        TestProperty *property = ucx_mempool_calloc(ms->mp, 1, sizeof(TestProperty));
+                        TestProperty *property = cxCalloc(ms->mp->allocator, 1, sizeof(TestProperty));
                         if(n->ns) {
-                            property->prefix = n->ns->prefix ? sstrdup_a(a, scstr((const char*)n->ns->prefix)).ptr : NULL;
-                            property->namespace = n->ns->href ? sstrdup_a(a, scstr((const char*)n->ns->href)).ptr : NULL;
+                            property->prefix = n->ns->prefix ? cx_strdup_a(a, cx_str((const char*)n->ns->prefix)).ptr : NULL;
+                            property->namespace = n->ns->href ? cx_strdup_a(a, cx_str((const char*)n->ns->href)).ptr : NULL;
                         }
-                        property->name = sstrdup_a(a, scstr((const char*)n->name)).ptr;
+                        property->name = cx_strdup_a(a, cx_str((const char*)n->name)).ptr;
                         property->node = n;
                         property->status = status_code;
                         xmlNode *value = n->children;
                         if(value && value->type == XML_TEXT_NODE) {
-                            property->value = sstrdup_a(a, scstr((const char*)value->content)).ptr;
+                            property->value = cx_strdup_a(a, cx_str((const char*)value->content)).ptr;
                         }
                         if(property->namespace && property->name) {
-                            sstr_t pname = sstrcat(2, sstr(property->namespace), sstr(property->name));
-                            ucx_map_sstr_put(properties, pname, property);
+                            cxmutstr pname = cx_strcat(2, cx_str(property->namespace), cx_str(property->name));
+                            cxMapPut(properties, cx_hash_key(pname.ptr, pname.length), property);
                             free(pname.ptr);
                         }
                     }
@@ -186,11 +189,11 @@
         node = node->next;
     }
     
-    TestResponse *resp =almalloc(a, sizeof(TestResponse));
+    TestResponse *resp = cxMalloc(a, sizeof(TestResponse));
     resp->href = href.ptr;
     resp->properties = properties;
     
-    ucx_map_sstr_put(ms->responses, href, resp);
+    cxMapPut(ms->responses, cx_hash_key(href.ptr, href.length), resp);
 }
 
 TestMultistatus* test_parse_multistatus(const char *space, size_t size) {
@@ -199,11 +202,11 @@
         return NULL;
     }
     
-    UcxMempool *mp = ucx_mempool_new(64);
-    TestMultistatus *ms = ucx_mempool_malloc(mp, sizeof(TestMultistatus));
+    CxMempool *mp = cxBasicMempoolCreate(64);
+    TestMultistatus *ms = cxMalloc(mp->allocator, sizeof(TestMultistatus));
     ms->doc = doc;
     ms->mp = mp;
-    ms->responses = ucx_map_new_a(mp->allocator, 8);
+    ms->responses = cxHashMapCreate((CxAllocator*)mp->allocator, 8);
     
     // parse response
     xmlNode *xml_root = xmlDocGetRootElement(doc);
@@ -224,7 +227,7 @@
 void test_multistatus_destroy(TestMultistatus *ms) {
     if(!ms) return;
     xmlFreeDoc(ms->doc);
-    ucx_mempool_destroy(ms->mp);
+    cxMempoolDestroy(ms->mp);
 }
 
 
@@ -641,16 +644,16 @@
     TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml");
     
-    TestResponse *r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    TestResponse *r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
     
-    UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 1, "propfind1: wrong response count");
     
-    TestProperty *p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    TestProperty *p = MAP_GET(r1->properties, "DAV:resourcetype");
     UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'");
     UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'");
     
-    p = ucx_map_cstr_get(r1->properties, "DAV:getlastmodified");
+    p = MAP_GET(r1->properties, "DAV:getlastmodified");
     UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'");
     UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'");
     
@@ -673,15 +676,15 @@
     ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response");
     
-    UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 5, "propfind2: wrong response count");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res2");
+    r1 = MAP_GET(ms->responses, "/propfind/res2");
     UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response");
     
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    p = MAP_GET(r1->properties, "http://example.com/test");
     UCX_TEST_ASSERT(p, "propfind2: missing property 'test'");
     UCX_TEST_ASSERT(p->status == 200, "propfind2: wrong status code for property 'test'");
     UCX_TEST_ASSERT(!strcmp(p->value, "res2test"), "propfind2: wrong property value");
@@ -707,27 +710,27 @@
     ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response");
     
-    UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 6, "propfind3: wrong response count");
     
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    r1 = MAP_GET(ms->responses, "/propfind/res1");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res1 response");
     
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    p = MAP_GET(r1->properties, "http://example.com/test");
     UCX_TEST_ASSERT(p, "propfind3: missing property 'test'");
     UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'test'");
     UCX_TEST_ASSERT(!strcmp(p->value, "testvalue"), "propfind3: wrong property value");
     
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    p = MAP_GET(r1->properties, "http://example.com/prop2");
     UCX_TEST_ASSERT(p, "propfind3: missing property 'prop2'");
     UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'prop2'");
     UCX_TEST_ASSERT(!strcmp(p->value, "value2"), "propfind3: wrong property value");
     
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/sub/res4");
+    r1 = MAP_GET(ms->responses, "/propfind/sub/res4");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response");
     
     testutil_destroy_session(sn);
@@ -770,11 +773,11 @@
     TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
-    UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 1, "propfind1: wrong response count");
     
-    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    p = MAP_GET(r1->properties, "DAV:resourcetype");
     UCX_TEST_ASSERT(r1, "propfind1: missing resourcetype property");
     
     testutil_destroy_session(sn);
@@ -795,23 +798,23 @@
     ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response");
-    UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 5, "propfind2: wrong response count");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    r1 = MAP_GET(ms->responses, "/propfind/res1");
     UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res1 response");
     
-    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    p = MAP_GET(r1->properties, "DAV:resourcetype");
     UCX_TEST_ASSERT(r1, "propfind2: missing resourcetype property");
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    p = MAP_GET(r1->properties, "http://example.com/test");
     UCX_TEST_ASSERT(r1, "propfind2: missing test property");
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    p = MAP_GET(r1->properties, "http://example.com/prop2");
     UCX_TEST_ASSERT(r1, "propfind2: missing prop2 property");
     
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response");
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response");
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response");
     
     testutil_destroy_session(sn);
     test_multistatus_destroy(ms);
@@ -829,24 +832,24 @@
     ms = test_parse_multistatus(st->buf->space, st->buf->size);
     UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
+    r1 = MAP_GET(ms->responses, "/propfind/");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response");
-    UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
+    UCX_TEST_ASSERT(ms->responses->size == 6, "propfind3: wrong response count");
     
-    r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
+    r1 = MAP_GET(ms->responses, "/propfind/res1");
     UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/res1 response");
     
-    p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
+    p = MAP_GET(r1->properties, "DAV:resourcetype");
     UCX_TEST_ASSERT(r1, "propfind3: missing resourcetype property");
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
+    p = MAP_GET(r1->properties, "http://example.com/test");
     UCX_TEST_ASSERT(r1, "propfind3: missing test property");
-    p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
+    p = MAP_GET(r1->properties, "http://example.com/prop2");
     UCX_TEST_ASSERT(r1, "propfind3: missing prop2 property");
     
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response");
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response");
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response");
-    UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response");
+    UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response");
     
     testutil_destroy_session(sn);
     test_multistatus_destroy(ms);

mercurial