src/server/test/vfs.c

Sun, 31 May 2020 19:35:29 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 31 May 2020 19:35:29 +0200
branch
webdav
changeset 249
3b302093945c
parent 248
bc8f8ddbad2e
child 251
f727a21497bb
permissions
-rw-r--r--

add webdav_delete tests

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;
248
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
44 int count_unlink;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
45 int count_rmdir;
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 } TestVFS;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 typedef struct TestVFSFile {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 VFSFile file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 sstr_t path;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 int isdir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 } TestVFSFile;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 typedef struct TestVFSDir {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 VFSDir dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 TestVFSFile *file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 UcxMapIterator i;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 sstr_t name;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 } TestVFSDir;
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 /* dir io */
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 static char* test_resource_name(char *url) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 sstr_t urlstr = sstr(url);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 if(urlstr.ptr[urlstr.length-1] == '/') {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 urlstr.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 sstr_t resname = sstrrchr(urlstr, '/');
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 if(resname.length > 1) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 return resname.ptr+1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 } else {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 return url;
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 }
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 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
77 TestVFS *vfs = dir->ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 TestVFSDir *vfsdir = (TestVFSDir*)dir;
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 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
81
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 UCX_MAP_FOREACH(key, file, vfsdir->i) {
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
84 sstr_t file_path = sstrcat(
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
85 2,
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
86 prefix,
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
87 sstr(test_resource_name(file->path.ptr)));
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
88 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
89 // don't ask why alfree and not free()
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
90 alfree(ucx_default_allocator(), file_path.ptr);
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
91 if(m) {
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 break;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 } else {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 free(prefix.ptr);
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 if(file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 vfsdir->name = sstrdup_a(
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 session_get_allocator(dir->ctx->sn),
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 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
103 ZERO(entry, sizeof(VFS_ENTRY));
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 entry->name = vfsdir->name.ptr;
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
105
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
106 if(getstat) {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
107 ZERO(&entry->stat, sizeof(struct stat));
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
108 if(file->isdir) {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
109 entry->stat.st_mode = S_IFDIR;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
110 }
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
111 }
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
112
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 return 1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 } else {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
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 void testvfs_dir_close(VFS_DIR dir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 TestVFSDir *testdir = (TestVFSDir*)dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 pool_free(testdir->dir.ctx->sn->pool, dir);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
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 VFS_DIRIO test_dir_io = {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 testvfs_readdir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 testvfs_dir_close
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 };
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 /* vfs funcs */
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
133 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
134 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
137 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 s_path.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 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
143 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 if((oflags & O_CREAT) == O_CREAT) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 file = pool_malloc(ctx->sn->pool, sizeof(TestVFSFile));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 ZERO(file, sizeof(TestVFSFile));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 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
148
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 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
150 }
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 return (SYS_FILE)file;
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
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
156 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
157 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
160 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 s_path.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 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
166 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 return 1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
249
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
169
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
170 ZERO(buf, sizeof(struct stat));
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
171 if(file->isdir) {
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
172 buf->st_mode = S_IFDIR;
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
173 }
3b302093945c add webdav_delete tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 248
diff changeset
174
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 return 0;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 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
179 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
182 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
183 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
186 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 s_path.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 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
192 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 return NULL;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 if(!file->isdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 return NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
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 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
201 ZERO(dir, sizeof(TestVFSDir));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 dir->file = file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 dir->i = ucx_map_iterator(vfs->files);
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 dir->dir.ctx = ctx;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 dir->dir.io = &test_dir_io;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 return (VFS_DIR)dir;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 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
212 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 TestVFSFile *file = (TestVFSFile*)fd;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 if(!file->isdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 return NULL;
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 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
219 ZERO(dir, sizeof(TestVFSDir));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 dir->file = file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 dir->i = ucx_map_iterator(vfs->files);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 dir->dir.ctx = ctx;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 dir->dir.io = &test_dir_io;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 return (VFS_DIR)dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
229 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
230 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
231 if(!fd) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 return 1;
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 TestVFSFile *file = (TestVFSFile*)fd;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 file->isdir = 1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
241 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
242 TestVFS *vfs = ctx->vfs->instance;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
243 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
244 if(!file) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
245 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
246 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
247
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
248 if(file->isdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
249 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
250 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
251
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
252 ucx_map_cstr_remove(vfs->files, path);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
253 vfs->count_unlink++;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
254 return 0;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
255 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
256
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
257 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
258 TestVFS *vfs = ctx->vfs->instance;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
259 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
260 if(!dir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
261 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
262 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
263
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
264 if(!dir->isdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
265 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
266 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
267
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
268 UcxMapIterator i = ucx_map_iterator(vfs->files);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
269 TestVFSFile *f;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
270 UCX_MAP_FOREACH(key, f, i) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
271 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
272 return 1; // dir not empty
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
273 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
274 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
275
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
276 ucx_map_cstr_remove(vfs->files, path);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
277 vfs->count_rmdir++;
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
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 static VFS testVFSClass = {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 testvfs_open,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 testvfs_stat,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 testvfs_fstat,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 testvfs_opendir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 testvfs_fdopendir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 testvfs_mkdir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 testvfs_unlink,
248
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
289 testvfs_rmdir,
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 0,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 NULL
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 VFS* testvfs_create(Session *sn) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 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
297 vfs->count_unlink = 0;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
298 vfs->count_rmdir = 0;
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 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
300
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 testVFSClass.instance = vfs;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 return &testVFSClass;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305
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 //
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 // VFS Tests
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 //
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 UCX_TEST(test_vfs_open) {
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 UCX_TEST_ASSERT(vfs, "vfs is NULL");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 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
324 UCX_TEST_ASSERT(f1, "f1 not opened");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 SYS_FILE f2 = vfs_open(vfs, "/file1", 0);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 UCX_TEST_ASSERT(f2, "f2 not opened");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 UCX_TEST_END;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 testutil_destroy_session(sn);
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 UCX_TEST(test_vfs_mkdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 rq->vfs = testvfs_create(sn);
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 VFSContext *vfs = vfs_request_context(sn, rq);
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 UCX_TEST_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 UCX_TEST_ASSERT(err == 0, "error not 0");
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 SYS_FILE fd = vfs_open(vfs, "/dir", 0);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 UCX_TEST_ASSERT(fd, "no fd");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 UCX_TEST_END;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 testutil_destroy_session(sn);
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 UCX_TEST(test_vfs_opendir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 rq->vfs = testvfs_create(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 VFSContext *vfs = vfs_request_context(sn, rq);
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 UCX_TEST_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 UCX_TEST_ASSERT(err == 0, "error not 0");
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 VFSDir *dir = vfs_opendir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 UCX_TEST_ASSERT(dir, "no dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 UCX_TEST_END;
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 testutil_destroy_session(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373
220
2915b6c11aec add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
374 UCX_TEST(test_vfs_readdir) {
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 rq->vfs = testvfs_create(sn);
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 VFSContext *vfs = vfs_request_context(sn, rq);
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_BEGIN;
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 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 UCX_TEST_ASSERT(err == 0, "error not 0");
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 // add some test file to /dir
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 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
388 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
389 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
390 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
391
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 VFSDir *dir = vfs_opendir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 UCX_TEST_ASSERT(dir, "dir not opened");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395 UcxMap *files = ucx_map_new(8);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 VFSEntry entry;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398 while(vfs_readdir(dir, &entry)) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 ucx_map_cstr_put(files, entry.name, dir);
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 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
403 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
404 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
405 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
406 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
407
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 ucx_map_free(files);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 UCX_TEST_END;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 testutil_destroy_session(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 }
248
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
414
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
415 UCX_TEST(test_vfs_unlink) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
416 Session *sn = testutil_session();
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
417 Request *rq = testutil_request(sn->pool, "PUT", "/");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
418 rq->vfs = testvfs_create(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
419
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
420 VFSContext *vfs = vfs_request_context(sn, rq);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
421
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
422 UCX_TEST_BEGIN;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
423 // prepare test
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
424 int err;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
425 err = vfs_mkdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
426 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
427 err = vfs_mkdir(vfs, "/dir2");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
428 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
429
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
430 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
431 UCX_TEST_ASSERT(f1, "f1 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
432
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
433 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
434 UCX_TEST_ASSERT(f1, "f2 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
435
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
436 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
437 UCX_TEST_ASSERT(f1, "f3 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
438
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
439 // test unlink
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
440 err = vfs_unlink(vfs, "/file1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
441 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
442 err = vfs_unlink(vfs, "/dir1/file3");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
443 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
444
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
445 err = vfs_unlink(vfs, "/filex");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
446 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
447
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
448 // check if files were removed
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
449 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
450 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
451 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
452 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
453
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
454 // file2 should still be there
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
455 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
456 UCX_TEST_ASSERT(o2, "/file2 deleted");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
457
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
458 // check if dir unlink fails
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
459 err = vfs_unlink(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
460 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
461
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
462 UCX_TEST_END;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
463
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
464 testutil_destroy_session(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
465 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
466
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
467 UCX_TEST(test_vfs_rmdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
468 Session *sn = testutil_session();
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
469 Request *rq = testutil_request(sn->pool, "PUT", "/");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
470 rq->vfs = testvfs_create(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
471
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
472 VFSContext *vfs = vfs_request_context(sn, rq);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
473
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
474 UCX_TEST_BEGIN;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
475 // prepare test
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
476 int err;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
477 err = vfs_mkdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
478 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
479 err = vfs_mkdir(vfs, "/dir2");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
480 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
481
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
482 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
483 UCX_TEST_ASSERT(f1, "f1 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
484
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
485 err = vfs_rmdir(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, "rmdir /dir1 should fail");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
487 err = vfs_rmdir(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, "rmdir /dir2 failed");
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 err = vfs_unlink(vfs, "/dir1/file1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
491 UCX_TEST_ASSERT(err == 0, "unlink failed");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
492 err = vfs_rmdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
493 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
494
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
495 UCX_TEST_END;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
496
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
497 testutil_destroy_session(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
498 }

mercurial