Sun, 14 Aug 2022 12:43:14 +0200
build pg propfind query from components
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2019 Olaf Wintermann. All rights reserved. |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
31 | #include <errno.h> |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <ucx/string.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <ucx/list.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <ucx/map.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "../daemon/session.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "testutils.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "vfs.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | typedef struct TestVFS { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | UcxMap *files; |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
45 | int count_unlink; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
46 | int count_rmdir; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | } TestVFS; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | typedef struct TestVFSFile { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | VFSFile file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | sstr_t path; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | int isdir; |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
53 | UcxBuffer *content; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | } TestVFSFile; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | typedef struct TestVFSDir { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | VFSDir dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | TestVFSFile *file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | UcxMapIterator i; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | sstr_t name; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } TestVFSDir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /* dir io */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | static char* test_resource_name(char *url) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | sstr_t urlstr = sstr(url); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | if(urlstr.ptr[urlstr.length-1] == '/') { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | urlstr.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | sstr_t resname = sstrrchr(urlstr, '/'); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | if(resname.length > 1) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | return resname.ptr+1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | return url; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | int testvfs_readdir(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | TestVFS *vfs = dir->ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | TestVFSDir *vfsdir = (TestVFSDir*)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | sstr_t prefix = sstrcat(2, vfsdir->file->path, S("/")); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | UCX_MAP_FOREACH(key, file, vfsdir->i) { |
249
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
86 | sstr_t file_path = sstrcat( |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
87 | 2, |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
88 | prefix, |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
89 | sstr(test_resource_name(file->path.ptr))); |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
90 | void *m = ucx_map_get(vfs->files, ucx_key(file_path.ptr, file_path.length)); |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
91 | // don't ask why alfree and not free() |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
92 | alfree(ucx_default_allocator(), file_path.ptr); |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
93 | if(m) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | break; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | free(prefix.ptr); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | if(file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | vfsdir->name = sstrdup_a( |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | session_get_allocator(dir->ctx->sn), |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | sstr(test_resource_name(file->path.ptr))); |
220
2915b6c11aec
add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
105 | ZERO(entry, sizeof(VFS_ENTRY)); |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | entry->name = vfsdir->name.ptr; |
249
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
107 | |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
108 | if(getstat) { |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
109 | ZERO(&entry->stat, sizeof(struct stat)); |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
110 | if(file->isdir) { |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
111 | entry->stat.st_mode = S_IFDIR; |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
112 | } |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
113 | } |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
114 | |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | void testvfs_dir_close(VFS_DIR dir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | TestVFSDir *testdir = (TestVFSDir*)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | pool_free(testdir->dir.ctx->sn->pool, dir); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
127 | ssize_t testvfs_read(SYS_FILE fd, void *buf, size_t nbyte) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
128 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
129 | return (ssize_t)ucx_buffer_read(buf, 1, nbyte, file->content); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
130 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
131 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
132 | ssize_t testvfs_write(SYS_FILE fd, const void *buf, size_t nbyte) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
133 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
134 | return (ssize_t)ucx_buffer_write(buf, 1, nbyte, file->content); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
135 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
136 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
137 | ssize_t testvfs_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
138 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
139 | file->content->pos = (size_t)offset; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
140 | return testvfs_read(fd, buf, nbyte); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
141 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
142 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
143 | ssize_t testvfs_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
144 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
145 | file->content->pos = (size_t)offset; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
146 | return testvfs_write(fd, buf, nbyte); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
147 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
148 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
149 | off_t testvfs_seek(SYS_FILE fd, off_t offset, int whence) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
150 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
151 | ucx_buffer_seek(file->content, offset, whence); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
152 | return (off_t)file->content->pos; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
153 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
154 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
155 | void testvfs_close(SYS_FILE fd) { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
156 | TestVFSFile *file = (TestVFSFile*)fd; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
157 | file->content->pos = 0; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
158 | } |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
159 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
160 | VFS_IO test_file_io = { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
161 | testvfs_read, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
162 | testvfs_write, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
163 | testvfs_pread, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
164 | testvfs_pwrite, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
165 | testvfs_seek, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
166 | testvfs_close, |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
167 | NULL, /* aio_read */ |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
168 | NULL /* aio_write */ |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
169 | }; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
170 | |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | VFS_DIRIO test_dir_io = { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | testvfs_readdir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | testvfs_dir_close |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | }; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | /* vfs funcs */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
179 | SYS_FILE testvfs_open(VFSContext *ctx, const char *path, int oflags) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
183 | sstr_t s_path = sstr((char*)path); |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | file = ucx_map_sstr_get(vfs->files, s_path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | if(!file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | if((oflags & O_CREAT) == O_CREAT) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | file = pool_malloc(ctx->sn->pool, sizeof(TestVFSFile)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | ZERO(file, sizeof(TestVFSFile)); |
323
dc5b0fee49df
fix TestVFSFile ctx initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
251
diff
changeset
|
193 | file->file.ctx = ctx; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | file->path = sstrdup_a(session_get_allocator(ctx->sn), s_path); |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
195 | file->file.io = &test_file_io; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
196 | |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
197 | file->content = pool_calloc(ctx->sn->pool, 1, sizeof(UcxBuffer)); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
198 | file->content->capacity = 2048; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
199 | file->content->space = pool_malloc(ctx->sn->pool, file->content->capacity); |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
200 | file->content->flags = 0; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
201 | file->content->pos = 0; |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
202 | file->content->size = 0; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | ucx_map_sstr_put(vfs->files, s_path, file); |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
205 | } else { |
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
206 | ctx->vfs_errno = ENOENT; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
208 | } |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | return (SYS_FILE)file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
213 | int testvfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
217 | sstr_t s_path = sstr((char*)path); |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | file = ucx_map_sstr_get(vfs->files, s_path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | if(!file) { |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
224 | ctx->vfs_errno = ENOENT; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | } |
249
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
227 | |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
228 | ZERO(buf, sizeof(struct stat)); |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
229 | if(file->isdir) { |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
230 | buf->st_mode = S_IFDIR; |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
231 | } |
3b302093945c
add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
248
diff
changeset
|
232 | |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | int testvfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
240 | VFS_DIR testvfs_opendir(VFSContext *ctx, const char *path) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
244 | sstr_t s_path = sstr((char*)path); |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | file = ucx_map_sstr_get(vfs->files, s_path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | if(!file) { |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
251 | ctx->vfs_errno = ENOENT; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | return NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | if(!file->isdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | return NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | TestVFSDir *dir = pool_malloc(ctx->sn->pool, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | ZERO(dir, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | dir->file = file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | dir->i = ucx_map_iterator(vfs->files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | dir->dir.ctx = ctx; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | dir->dir.io = &test_dir_io; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | return (VFS_DIR)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | VFS_DIR testvfs_fdopendir(VFSContext *ctx, SYS_FILE fd) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | TestVFSFile *file = (TestVFSFile*)fd; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | if(!file->isdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | return NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | TestVFSDir *dir = pool_malloc(ctx->sn->pool, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | ZERO(dir, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | dir->file = file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | dir->i = ucx_map_iterator(vfs->files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | dir->dir.ctx = ctx; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | dir->dir.io = &test_dir_io; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | return (VFS_DIR)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
288 | int testvfs_mkdir(VFSContext *ctx, const char *path) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | SYS_FILE fd = testvfs_open(ctx, path, O_CREAT); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | if(!fd) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | TestVFSFile *file = (TestVFSFile*)fd; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | file->isdir = 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
300 | int testvfs_unlink(VFSContext *ctx, const char *path) { |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
301 | TestVFS *vfs = ctx->vfs->instance; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
302 | TestVFSFile *file = ucx_map_cstr_get(vfs->files, path); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
303 | if(!file) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
304 | return 1; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
305 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
306 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
307 | if(file->isdir) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
308 | return 1; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
309 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
310 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
311 | ucx_map_cstr_remove(vfs->files, path); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
312 | vfs->count_unlink++; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
313 | return 0; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
314 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
315 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
316 | int testvfs_rmdir(VFSContext *ctx, const char *path) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
317 | TestVFS *vfs = ctx->vfs->instance; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
318 | TestVFSFile *dir = ucx_map_cstr_get(vfs->files, path); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
319 | if(!dir) { |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
249
diff
changeset
|
320 | ctx->vfs_errno = ENOENT; |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
321 | return 1; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
322 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
323 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
324 | if(!dir->isdir) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
325 | return 1; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
326 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
327 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
328 | UcxMapIterator i = ucx_map_iterator(vfs->files); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
329 | TestVFSFile *f; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
330 | UCX_MAP_FOREACH(key, f, i) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
331 | if(f->path.length > dir->path.length && sstrprefix(f->path, dir->path)){ |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
332 | return 1; // dir not empty |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
333 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
334 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
335 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
336 | ucx_map_cstr_remove(vfs->files, path); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
337 | vfs->count_rmdir++; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | static VFS testVFSClass = { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | testvfs_open, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | testvfs_stat, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | testvfs_fstat, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | testvfs_opendir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | testvfs_fdopendir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | testvfs_mkdir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | testvfs_unlink, |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
349 | testvfs_rmdir, |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | 0, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | NULL |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | }; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | VFS* testvfs_create(Session *sn) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | TestVFS *vfs = pool_malloc(sn->pool, sizeof(TestVFS)); |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
357 | vfs->count_unlink = 0; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
358 | vfs->count_rmdir = 0; |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | vfs->files = ucx_map_new_a(session_get_allocator(sn), 64); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | testVFSClass.instance = vfs; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | return &testVFSClass; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | /* ------------------------------------------------------------------------- */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | // |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | // VFS Tests |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | // |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | /* ------------------------------------------------------------------------- */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | UCX_TEST(test_vfs_open) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | rq->vfs = testvfs_create(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | UCX_TEST_ASSERT(vfs, "vfs is NULL"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | UCX_TEST_ASSERT(f1, "f1 not opened"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | SYS_FILE f2 = vfs_open(vfs, "/file1", 0); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | UCX_TEST_ASSERT(f2, "f2 not opened"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | UCX_TEST(test_vfs_mkdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | rq->vfs = testvfs_create(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | SYS_FILE fd = vfs_open(vfs, "/dir", 0); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | UCX_TEST_ASSERT(fd, "no fd"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | UCX_TEST(test_vfs_opendir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | rq->vfs = testvfs_create(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | VFSDir *dir = vfs_opendir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427 | UCX_TEST_ASSERT(dir, "no dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | |
220
2915b6c11aec
add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
434 | UCX_TEST(test_vfs_readdir) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | rq->vfs = testvfs_create(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | // add some test file to /dir |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT), "creation of file1 failed"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT), "creation of file2 failed"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT), "creation of file3 failed"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT), "creation of file4 failed"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | VFSDir *dir = vfs_opendir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | UCX_TEST_ASSERT(dir, "dir not opened"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | UcxMap *files = ucx_map_new(8); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | VFSEntry entry; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | while(vfs_readdir(dir, &entry)) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | ucx_map_cstr_put(files, entry.name, dir); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | UCX_TEST_ASSERT(files->count == 4, "wrong files count"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | UCX_TEST_ASSERT(ucx_map_cstr_get(files, "file1"), "file1 missing"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | UCX_TEST_ASSERT(ucx_map_cstr_get(files, "file2"), "file2 missing"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | UCX_TEST_ASSERT(ucx_map_cstr_get(files, "file3"), "file3 missing"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | UCX_TEST_ASSERT(ucx_map_cstr_get(files, "file4"), "file4 missing"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | ucx_map_free(files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | } |
248
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
474 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
475 | UCX_TEST(test_vfs_unlink) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
476 | Session *sn = testutil_session(); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
477 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
478 | rq->vfs = testvfs_create(sn); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
479 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
480 | VFSContext *vfs = vfs_request_context(sn, rq); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
481 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
482 | UCX_TEST_BEGIN; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
483 | // prepare test |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
484 | int err; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
485 | err = vfs_mkdir(vfs, "/dir1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
486 | UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
487 | err = vfs_mkdir(vfs, "/dir2"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
488 | UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
489 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
490 | SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
491 | UCX_TEST_ASSERT(f1, "f1 not opened"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
492 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
493 | SYS_FILE f2 = vfs_open(vfs, "/file2", O_CREAT); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
494 | UCX_TEST_ASSERT(f1, "f2 not opened"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
495 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
496 | SYS_FILE f3 = vfs_open(vfs, "/dir1/file3", O_CREAT); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
497 | UCX_TEST_ASSERT(f1, "f3 not opened"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
498 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
499 | // test unlink |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
500 | err = vfs_unlink(vfs, "/file1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
501 | UCX_TEST_ASSERT(err == 0, "unlink /file1 failed"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
502 | err = vfs_unlink(vfs, "/dir1/file3"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
503 | UCX_TEST_ASSERT(err == 0, "unlink /dir1/file3 failed"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
504 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
505 | err = vfs_unlink(vfs, "/filex"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
506 | UCX_TEST_ASSERT(err != 0, "unlink /filex should fail"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
507 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
508 | // check if files were removed |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
509 | SYS_FILE o1 = vfs_open(vfs, "/file1", O_RDONLY); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
510 | UCX_TEST_ASSERT(o1 == NULL, "/file1 not deleted"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
511 | SYS_FILE o3 = vfs_open(vfs, "/dir1/file3", O_RDONLY); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
512 | UCX_TEST_ASSERT(o1 == NULL, "/dir1/file3 not deleted"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
513 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
514 | // file2 should still be there |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
515 | SYS_FILE o2 = vfs_open(vfs, "/file2", O_RDONLY); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
516 | UCX_TEST_ASSERT(o2, "/file2 deleted"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
517 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
518 | // check if dir unlink fails |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
519 | err = vfs_unlink(vfs, "/dir1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
520 | UCX_TEST_ASSERT(err != 0, "unlink dir1 should fail"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
521 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
522 | UCX_TEST_END; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
523 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
524 | testutil_destroy_session(sn); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
525 | } |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
526 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
527 | UCX_TEST(test_vfs_rmdir) { |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
528 | Session *sn = testutil_session(); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
529 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
530 | rq->vfs = testvfs_create(sn); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
531 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
532 | VFSContext *vfs = vfs_request_context(sn, rq); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
533 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
534 | UCX_TEST_BEGIN; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
535 | // prepare test |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
536 | int err; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
537 | err = vfs_mkdir(vfs, "/dir1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
538 | UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
539 | err = vfs_mkdir(vfs, "/dir2"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
540 | UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
541 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
542 | SYS_FILE f1 = vfs_open(vfs, "/dir1/file1", O_CREAT); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
543 | UCX_TEST_ASSERT(f1, "f1 not opened"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
544 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
545 | err = vfs_rmdir(vfs, "/dir1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
546 | UCX_TEST_ASSERT(err != 0, "rmdir /dir1 should fail"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
547 | err = vfs_rmdir(vfs, "/dir2"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
548 | UCX_TEST_ASSERT(err == 0, "rmdir /dir2 failed"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
549 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
550 | err = vfs_unlink(vfs, "/dir1/file1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
551 | UCX_TEST_ASSERT(err == 0, "unlink failed"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
552 | err = vfs_rmdir(vfs, "/dir1"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
553 | UCX_TEST_ASSERT(err == 0, "rmdir /dir1 (2) failed"); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
554 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
555 | UCX_TEST_END; |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
556 | |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
557 | testutil_destroy_session(sn); |
bc8f8ddbad2e
add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
558 | } |