add resource iterator and resource map dav-2

Mon, 08 Sep 2025 11:39:54 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 08 Sep 2025 11:39:54 +0200
branch
dav-2
changeset 881
64989511f6c3
parent 880
5f8ccd1d59bd
child 882
86e61b4ef708

add resource iterator and resource map

dav/obj.mk file | annotate | diff | comparison | revisions
dav/pull.c file | annotate | diff | comparison | revisions
dav/pull.h file | annotate | diff | comparison | revisions
dav/push.c file | annotate | diff | comparison | revisions
dav/push.h file | annotate | diff | comparison | revisions
libidav/resource.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
test/Makefile file | annotate | diff | comparison | revisions
test/helper.c file | annotate | diff | comparison | revisions
test/helper.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
test/test_resource.c file | annotate | diff | comparison | revisions
test/test_resource.h file | annotate | diff | comparison | revisions
--- a/dav/obj.mk	Mon Sep 08 10:31:08 2025 +0200
+++ b/dav/obj.mk	Mon Sep 08 11:39:54 2025 +0200
@@ -45,6 +45,8 @@
 SYNC_SRC  = scfg.c
 SYNC_SRC += db.c
 SYNC_SRC += tags.c
+SYNC_SRC += pull.c
+SYNC_SRC += push.c
 
 XATTR_SRC  = xattrtool.c
 XATTR_SRC += libxattr.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dav/pull.c	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,30 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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 "pull.h"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dav/pull.h	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,44 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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.
+ */
+
+#ifndef PULL_H
+#define PULL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PULL_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dav/push.c	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,30 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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 "push.h"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dav/push.h	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,44 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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.
+ */
+
+#ifndef PUSH_H
+#define PUSH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PUSH_H */
+
--- a/libidav/resource.c	Mon Sep 08 10:31:08 2025 +0200
+++ b/libidav/resource.c	Mon Sep 08 11:39:54 2025 +0200
@@ -281,6 +281,35 @@
     return resource->href;
 }
 
+CxTreeIterator dav_resource_iterator(DavResource *res) {
+    return cx_tree_iterator(res, FALSE, offsetof(DavResource, children), offsetof(DavResource, next));
+}
+
+CxTreeVisitor dav_resource_visitor(DavResource *res) {
+    return cx_tree_visitor(res, offsetof(DavResource, children), offsetof(DavResource, next));
+}
+
+CxMap* dav_resource_map(DavResource *res) {
+    CxMap *map = cxHashMapCreate(res->session->mp->allocator, CX_STORE_POINTERS, 16);
+    if(!map) {
+        return NULL;
+    }
+    CxTreeIterator i = dav_resource_iterator(res);
+    int error = 0;
+    cx_foreach(DavResource *, res, i) {
+        if(cxMapPut(map, res->path, res)) {
+            error = 1;
+        }
+    }
+    if(!error) {
+        cxMapRehash(map);
+        return map;
+    } else {
+        cxMapFree(map);
+        return NULL;
+    }
+}
+
 void resource_add_prop(DavResource *res, const char *ns, const char *name, DavXmlNode *val) {
     DavSession *sn = res->session;
     
--- a/libidav/webdav.h	Mon Sep 08 10:31:08 2025 +0200
+++ b/libidav/webdav.h	Mon Sep 08 11:39:54 2025 +0200
@@ -36,6 +36,7 @@
 #include <cx/linked_list.h>
 #include <cx/string.h>
 #include <cx/buffer.h>
+#include <cx/tree.h>
 #include <curl/curl.h>
 #include <libxml/tree.h>
 
@@ -337,6 +338,10 @@
 
 char* dav_resource_get_href(DavResource *resource);
 
+CxTreeIterator dav_resource_iterator(DavResource *res);
+CxTreeVisitor dav_resource_visitor(DavResource *res);
+CxMap* dav_resource_map(DavResource *res);
+
 DavResource* dav_create_child(DavResource *parent, char *name);
 int dav_delete(DavResource *res);
 int dav_create(DavResource *res);
--- a/test/Makefile	Mon Sep 08 10:31:08 2025 +0200
+++ b/test/Makefile	Mon Sep 08 11:39:54 2025 +0200
@@ -31,9 +31,11 @@
 include ../dav/obj.mk
 
 TEST_SRC  = main.c
+TEST_SRC += helper.c
 TEST_SRC += base64.c
 TEST_SRC += crypto.c
 TEST_SRC += utils.c
+TEST_SRC += test_resource.c
 
 TEST_SRC += test_finfo.c
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/helper.c	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,34 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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 "helper.h"
+
+
+DavSession* test_session(DavContext *ctx) {
+    return dav_session_new(ctx, "http://localhost:8182/webdav/"); 
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/helper.h	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,46 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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.
+ */
+
+#ifndef TEST_HELPER_H
+#define TEST_HELPER_H
+
+#include <libidav/webdav.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DavSession* test_session(DavContext *ctx);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_HELPER_H */
+
--- a/test/main.c	Mon Sep 08 10:31:08 2025 +0200
+++ b/test/main.c	Mon Sep 08 11:39:54 2025 +0200
@@ -35,6 +35,8 @@
 #include "crypto.h"
 #include "utils.h"
 
+#include "test_resource.h"
+
 int test_main(int argc, char **argv);
 
 #ifdef _WIN32
@@ -63,6 +65,9 @@
     cx_test_register(suite, test_dav_pw2key);
     cx_test_register(suite, test_util_parse_creationdate);
     
+    cx_test_register(suite, test_resource_iterator_visitor);
+    cx_test_register(suite, test_resource_map);
+    
     cx_test_run(suite, stdout, (cx_write_func)fwrite);
     fflush(stdout);
     cx_test_suite_free(suite);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_resource.c	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,166 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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_resource.h"
+
+#include "helper.h"
+
+
+CX_TEST(test_resource_iterator_visitor) {
+    DavContext *ctx = dav_context_new();
+    DavSession *sn = test_session(ctx);
+    CX_TEST_DO {
+        DavResource *root = dav_resource_new(sn, "/");
+        DavResource *c1 = dav_resource_new(sn, "/child1");
+        DavResource *c2 = dav_resource_new(sn, "/child2");
+        DavResource *c1c1 = dav_resource_new(sn, "/child1/sub1");
+        DavResource *c1c2 = dav_resource_new(sn, "/child1/sub2");
+        DavResource *c1c2c1 = dav_resource_new(sn, "/child2/sub2/x1");
+        DavResource *c1c3 = dav_resource_new(sn, "/child1/sub3");
+        DavResource *c3 = dav_resource_new(sn, "/child3");
+        
+        root->children = c1;
+        c1->next = c2; c2->prev = c1;
+        c2->next = c3; c3->prev = c2;
+        
+        c1->parent = root;
+        c2->parent = root;
+        c3->parent = root;
+        
+        c1->children = c1c1;
+        c1c1->next = c1c2; c1c2->prev = c1c1;
+        c1c2->next = c1c3; c1c3->prev = c1c2;
+        
+        c1c1->parent = c1;
+        c1c2->parent = c1;
+        c1c3->parent = c1;
+        
+        c1c2->children = c1c2c1; c1c2c1->parent = c1c2;
+        
+        DavResource *resources[] = {root, c1, c2, c3, c1c1, c1c2, c1c3, c1c2c1 };
+        
+        // Iterator Test
+        CxTreeIterator i = dav_resource_iterator(root);
+        int iterated = 0;
+        cx_foreach(DavResource *, res, i) {
+            for(int r=0;r<8;r++) {
+                if(res == resources[r]) {
+                    res->exists = 1;
+                    break;
+                }
+            }
+            iterated++;
+        }
+        CX_TEST_ASSERT(iterated == 8);
+        
+        for(int ir=0;ir<8;ir++) {
+            CX_TEST_ASSERT(resources[ir]->exists);
+            resources[ir]->exists = 0; // reset for next test
+        }
+        
+        // Visitor Test
+        CxTreeVisitor v = dav_resource_visitor(root);
+        int visited = 0;
+        cx_foreach(DavResource *, res, v) {
+            for(int r=0;r<8;r++) {
+                if(res == resources[r]) {
+                    res->exists = 1;
+                    break;
+                }
+            }
+            visited++;
+        }
+        CX_TEST_ASSERT(visited == 8);
+        
+        for(int vr=0;vr<8;vr++) {
+            CX_TEST_ASSERT(resources[vr]->exists);
+            resources[vr]->exists = 0; // reset for next test
+        }
+        
+        
+        // partial test
+        i = dav_resource_iterator(c1);
+        iterated = 0;
+        cx_foreach(DavResource *, res, i) {
+            iterated++;
+        }
+        CX_TEST_ASSERT(iterated == 7);
+        
+        v = dav_resource_visitor(c1);
+        visited = 0;
+        cx_foreach(DavResource *, res, v) {
+            visited++;
+        }
+        CX_TEST_ASSERT(visited == 7);
+    }
+    dav_context_destroy(ctx);
+}
+
+CX_TEST(test_resource_map) {
+    DavContext *ctx = dav_context_new();
+    DavSession *sn = test_session(ctx);
+    CX_TEST_DO {
+        DavResource *root = dav_resource_new(sn, "/");
+        DavResource *c1 = dav_resource_new(sn, "/child1");
+        DavResource *c2 = dav_resource_new(sn, "/child2");
+        DavResource *c1c1 = dav_resource_new(sn, "/child1/sub1");
+        DavResource *c1c2 = dav_resource_new(sn, "/child1/sub2");
+        DavResource *c2c2c1 = dav_resource_new(sn, "/child2/sub2/x1");
+        DavResource *c1c3 = dav_resource_new(sn, "/child1/sub3");
+        DavResource *c3 = dav_resource_new(sn, "/child3");
+        
+        root->children = c1;
+        c1->next = c2; c2->prev = c1;
+        c2->next = c3; c3->prev = c2;
+        
+        c1->parent = root;
+        c2->parent = root;
+        c3->parent = root;
+        
+        c1->children = c1c1;
+        c1c1->next = c1c2; c1c2->prev = c1c1;
+        c1c2->next = c1c3; c1c3->prev = c1c2;
+        
+        c1c1->parent = c1;
+        c1c2->parent = c1;
+        c1c3->parent = c1;
+        
+        c1c2->children = c2c2c1; c2c2c1->parent = c1c2;
+        
+        CxMap *map = dav_resource_map(root);
+        CX_TEST_ASSERT(cxMapGet(map, "/") == root);
+        CX_TEST_ASSERT(cxMapGet(map, "/child1") == c1);
+        CX_TEST_ASSERT(cxMapGet(map, "/child2") == c2);
+        CX_TEST_ASSERT(cxMapGet(map, "/child3") == c3);
+        CX_TEST_ASSERT(cxMapGet(map, "/child1/sub1") == c1c1);
+        CX_TEST_ASSERT(cxMapGet(map, "/child1/sub2") == c1c2);
+        CX_TEST_ASSERT(cxMapGet(map, "/child1/sub3") == c1c3);
+        CX_TEST_ASSERT(cxMapGet(map, "/child2/sub2/x1") == c2c2c1);
+    }
+    dav_context_destroy(ctx);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_resource.h	Mon Sep 08 11:39:54 2025 +0200
@@ -0,0 +1,47 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 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.
+ */
+
+#ifndef TEST_RESOURCE_H
+#define TEST_RESOURCE_H
+
+#include <cx/test.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CX_TEST(test_resource_iterator_visitor);
+CX_TEST(test_resource_map);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_RESOURCE_H */
+

mercurial