Fri, 17 Jan 2020 22:23:30 +0100
implement multistatus writer
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> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <ucx/string.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <ucx/list.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <ucx/map.h> |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "../daemon/session.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "testutils.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "vfs.h" |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | typedef struct TestVFS { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | UcxMap *files; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | } TestVFS; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | typedef struct TestVFSFile { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | VFSFile file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | sstr_t path; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | int isdir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | } TestVFSFile; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | typedef struct TestVFSDir { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | VFSDir dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | TestVFSFile *file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | UcxMapIterator i; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | sstr_t name; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | } TestVFSDir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | /* dir io */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | static char* test_resource_name(char *url) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | sstr_t urlstr = sstr(url); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | if(urlstr.ptr[urlstr.length-1] == '/') { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | urlstr.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | sstr_t resname = sstrrchr(urlstr, '/'); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | if(resname.length > 1) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | return resname.ptr+1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | return url; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | 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
|
75 | TestVFS *vfs = dir->ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | TestVFSDir *vfsdir = (TestVFSDir*)dir; |
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 | 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
|
79 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | UCX_MAP_FOREACH(key, file, vfsdir->i) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | if(sstrprefix(file->path, prefix)) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | break; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | free(prefix.ptr); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | vfsdir->name = sstrdup_a( |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | session_get_allocator(dir->ctx->sn), |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | 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
|
94 | ZERO(entry, sizeof(VFS_ENTRY)); |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | entry->name = vfsdir->name.ptr; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } else { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | } |
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 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | void testvfs_dir_close(VFS_DIR dir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | TestVFSDir *testdir = (TestVFSDir*)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | pool_free(testdir->dir.ctx->sn->pool, dir); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | VFS_DIRIO test_dir_io = { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | testvfs_readdir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | testvfs_dir_close |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | }; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | /* vfs funcs */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | SYS_FILE testvfs_open(VFSContext *ctx, char *path, int oflags) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | TestVFSFile *file = NULL; |
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 | sstr_t s_path = sstr(path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
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 | 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
|
126 | if(!file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | if((oflags & O_CREAT) == O_CREAT) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | file = pool_malloc(ctx->sn->pool, sizeof(TestVFSFile)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | ZERO(file, sizeof(TestVFSFile)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | file->path = sstrdup_a(session_get_allocator(ctx->sn), s_path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | ucx_map_sstr_put(vfs->files, s_path, file); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | return (SYS_FILE)file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | int testvfs_stat(VFSContext *ctx, char *path, struct stat *buf) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | sstr_t s_path = sstr(path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | 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
|
149 | if(!file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | 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
|
156 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | VFS_DIR testvfs_opendir(VFSContext *ctx, char *path) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | TestVFSFile *file = NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | sstr_t s_path = sstr(path); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | if(sstrsuffix(s_path, S("/"))) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | s_path.length--; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | 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
|
169 | if(!file) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | return NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | if(!file->isdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | return NULL; |
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 | 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
|
178 | ZERO(dir, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | dir->file = file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | dir->i = ucx_map_iterator(vfs->files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | dir->dir.ctx = ctx; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | dir->dir.io = &test_dir_io; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | return (VFS_DIR)dir; |
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 | 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
|
189 | TestVFS *vfs = ctx->vfs->instance; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | TestVFSFile *file = (TestVFSFile*)fd; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | if(!file->isdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | return NULL; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | 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
|
196 | ZERO(dir, sizeof(TestVFSDir)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | dir->file = file; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | dir->i = ucx_map_iterator(vfs->files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | dir->dir.ctx = ctx; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | dir->dir.io = &test_dir_io; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | return (VFS_DIR)dir; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | int testvfs_mkdir(VFSContext *ctx, char *path) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | 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
|
208 | if(!fd) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | return 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | } |
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 | TestVFSFile *file = (TestVFSFile*)fd; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | file->isdir = 1; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | return 0; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | int testvfs_unlink(VFSContext *ctx, char *path) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | return 0; |
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 | static VFS testVFSClass = { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | testvfs_open, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | testvfs_stat, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | testvfs_fstat, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | testvfs_opendir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | testvfs_fdopendir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | testvfs_mkdir, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | testvfs_unlink, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | 0, |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | NULL |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | }; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | |
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 | VFS* testvfs_create(Session *sn) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | TestVFS *vfs = pool_malloc(sn->pool, sizeof(TestVFS)); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | 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
|
238 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | testVFSClass.instance = vfs; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | return &testVFSClass; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | /* ------------------------------------------------------------------------- */ |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | // |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | // VFS Tests |
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 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | UCX_TEST(test_vfs_open) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | rq->vfs = testvfs_create(sn); |
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 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | UCX_TEST_BEGIN; |
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 | UCX_TEST_ASSERT(vfs, "vfs is NULL"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | 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
|
262 | UCX_TEST_ASSERT(f1, "f1 not opened"); |
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 | SYS_FILE f2 = vfs_open(vfs, "/file1", 0); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | UCX_TEST_ASSERT(f2, "f2 not opened"); |
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 | UCX_TEST_END; |
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 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | UCX_TEST(test_vfs_mkdir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | rq->vfs = testvfs_create(sn); |
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 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | SYS_FILE fd = vfs_open(vfs, "/dir", 0); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | UCX_TEST_ASSERT(fd, "no fd"); |
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 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | UCX_TEST(test_vfs_opendir) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | rq->vfs = testvfs_create(sn); |
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 | VFSContext *vfs = vfs_request_context(sn, rq); |
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 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | VFSDir *dir = vfs_opendir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | UCX_TEST_ASSERT(dir, "no dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | } |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | |
220
2915b6c11aec
add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
312 | UCX_TEST(test_vfs_readdir) { |
219
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | Session *sn = testutil_session(); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | rq->vfs = testvfs_create(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | VFSContext *vfs = vfs_request_context(sn, rq); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | UCX_TEST_BEGIN; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | int err = vfs_mkdir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | UCX_TEST_ASSERT(err == 0, "error not 0"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | // add some test file to /dir |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | 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
|
329 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | VFSDir *dir = vfs_opendir(vfs, "/dir"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | UCX_TEST_ASSERT(dir, "dir not opened"); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | UcxMap *files = ucx_map_new(8); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | VFSEntry entry; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | while(vfs_readdir(dir, &entry)) { |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | ucx_map_cstr_put(files, entry.name, dir); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | } |
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 | 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
|
341 | 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
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | ucx_map_free(files); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | UCX_TEST_END; |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | testutil_destroy_session(sn); |
dd6c155c082a
add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | } |