src/server/test/vfs.c

Sun, 31 May 2020 17:31:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 31 May 2020 17:31:43 +0200
branch
webdav
changeset 248
bc8f8ddbad2e
parent 241
4adad7faf452
child 249
3b302093945c
permissions
-rw-r--r--

add vfs unlink and rmdir 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) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 if(sstrprefix(file->path, prefix)) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 break;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 } else {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
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 free(prefix.ptr);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 if(file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 vfsdir->name = sstrdup_a(
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 session_get_allocator(dir->ctx->sn),
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 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
96 ZERO(entry, sizeof(VFS_ENTRY));
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 entry->name = vfsdir->name.ptr;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 return 1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 } else {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 return 0;
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 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 void testvfs_dir_close(VFS_DIR dir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 TestVFSDir *testdir = (TestVFSDir*)dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 pool_free(testdir->dir.ctx->sn->pool, dir);
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 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 VFS_DIRIO test_dir_io = {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 testvfs_readdir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 testvfs_dir_close
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
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 /* vfs funcs */
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
118 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
119 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
122 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 s_path.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 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
128 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 if((oflags & O_CREAT) == O_CREAT) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 file = pool_malloc(ctx->sn->pool, sizeof(TestVFSFile));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 ZERO(file, sizeof(TestVFSFile));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 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
133
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 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
135 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
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 return (SYS_FILE)file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
141 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
142 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
145 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 s_path.length--;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 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
151 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 return 1;
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 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 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
158 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
161 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
162 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 TestVFSFile *file = NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
165 sstr_t s_path = sstr((char*)path);
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 if(sstrsuffix(s_path, S("/"))) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 s_path.length--;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 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
171 if(!file) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 return NULL;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 if(!file->isdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 return NULL;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 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
180 ZERO(dir, sizeof(TestVFSDir));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 dir->file = file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 dir->i = ucx_map_iterator(vfs->files);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 dir->dir.ctx = ctx;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 dir->dir.io = &test_dir_io;
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 return (VFS_DIR)dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
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 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
191 TestVFS *vfs = ctx->vfs->instance;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 TestVFSFile *file = (TestVFSFile*)fd;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 if(!file->isdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 return NULL;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 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
198 ZERO(dir, sizeof(TestVFSDir));
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 dir->file = file;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 dir->i = ucx_map_iterator(vfs->files);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 dir->dir.ctx = ctx;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 dir->dir.io = &test_dir_io;
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 return (VFS_DIR)dir;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
208 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
209 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
210 if(!fd) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 return 1;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 TestVFSFile *file = (TestVFSFile*)fd;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 file->isdir = 1;
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 return 0;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219
241
4adad7faf452 add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
220 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
221 TestVFS *vfs = ctx->vfs->instance;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
222 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
223 if(!file) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
224 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
225 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
226
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
227 if(file->isdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
228 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
229 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
230
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
231 ucx_map_cstr_remove(vfs->files, path);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
232 vfs->count_unlink++;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
233 return 0;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
234 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
235
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
236 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
237 TestVFS *vfs = ctx->vfs->instance;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
238 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
239 if(!dir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
240 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
241 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
242
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
243 if(!dir->isdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
244 return 1;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
245 }
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 UcxMapIterator i = ucx_map_iterator(vfs->files);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
248 TestVFSFile *f;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
249 UCX_MAP_FOREACH(key, f, i) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
250 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
251 return 1; // dir not empty
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
252 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
253 }
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
254
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
255 ucx_map_cstr_remove(vfs->files, path);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
256 vfs->count_rmdir++;
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 return 0;
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 static VFS testVFSClass = {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 testvfs_open,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 testvfs_stat,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 testvfs_fstat,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 testvfs_opendir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 testvfs_fdopendir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 testvfs_mkdir,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 testvfs_unlink,
248
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
268 testvfs_rmdir,
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 0,
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 NULL
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 VFS* testvfs_create(Session *sn) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 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
276 vfs->count_unlink = 0;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
277 vfs->count_rmdir = 0;
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 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
279
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 testVFSClass.instance = vfs;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 return &testVFSClass;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 }
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 /* ------------------------------------------------------------------------- */
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 // VFS Tests
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 /* ------------------------------------------------------------------------- */
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 UCX_TEST(test_vfs_open) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 rq->vfs = testvfs_create(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 VFSContext *vfs = vfs_request_context(sn, rq);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 UCX_TEST_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 UCX_TEST_ASSERT(vfs, "vfs is NULL");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 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
303 UCX_TEST_ASSERT(f1, "f1 not opened");
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 SYS_FILE f2 = vfs_open(vfs, "/file1", 0);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 UCX_TEST_ASSERT(f2, "f2 not opened");
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 UCX_TEST_END;
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 testutil_destroy_session(sn);
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
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 UCX_TEST(test_vfs_mkdir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 rq->vfs = testvfs_create(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 VFSContext *vfs = vfs_request_context(sn, rq);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 UCX_TEST_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 UCX_TEST_ASSERT(err == 0, "error not 0");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 SYS_FILE fd = vfs_open(vfs, "/dir", 0);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 UCX_TEST_ASSERT(fd, "no fd");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 UCX_TEST_END;
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 testutil_destroy_session(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 }
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 UCX_TEST(test_vfs_opendir) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 rq->vfs = testvfs_create(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 VFSContext *vfs = vfs_request_context(sn, rq);
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_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 UCX_TEST_ASSERT(err == 0, "error not 0");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 VFSDir *dir = vfs_opendir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 UCX_TEST_ASSERT(dir, "no dir");
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 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352
220
2915b6c11aec add test for webdav_op_propfind_children
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
353 UCX_TEST(test_vfs_readdir) {
219
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 Session *sn = testutil_session();
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 Request *rq = testutil_request(sn->pool, "PUT", "/");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 rq->vfs = testvfs_create(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 VFSContext *vfs = vfs_request_context(sn, rq);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 UCX_TEST_BEGIN;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 int err = vfs_mkdir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 UCX_TEST_ASSERT(err == 0, "error not 0");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 // add some test file to /dir
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 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
367 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
368 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
369 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
370
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 VFSDir *dir = vfs_opendir(vfs, "/dir");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 UCX_TEST_ASSERT(dir, "dir not opened");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 UcxMap *files = ucx_map_new(8);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 VFSEntry entry;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 while(vfs_readdir(dir, &entry)) {
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 ucx_map_cstr_put(files, entry.name, dir);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 }
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 UCX_TEST_ASSERT(files->count == 4, "wrong files count");
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 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
383 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
384 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
385 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
386
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 ucx_map_free(files);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 UCX_TEST_END;
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 testutil_destroy_session(sn);
dd6c155c082a add simple vfs implementation for testing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 }
248
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
393
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
394 UCX_TEST(test_vfs_unlink) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
395 Session *sn = testutil_session();
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
396 Request *rq = testutil_request(sn->pool, "PUT", "/");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
397 rq->vfs = testvfs_create(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
398
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
399 VFSContext *vfs = vfs_request_context(sn, rq);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
400
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
401 UCX_TEST_BEGIN;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
402 // prepare test
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
403 int err;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
404 err = vfs_mkdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
405 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
406 err = vfs_mkdir(vfs, "/dir2");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
407 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
408
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
409 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
410 UCX_TEST_ASSERT(f1, "f1 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
411
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
412 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
413 UCX_TEST_ASSERT(f1, "f2 not opened");
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 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
416 UCX_TEST_ASSERT(f1, "f3 not opened");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
417
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
418 // test unlink
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
419 err = vfs_unlink(vfs, "/file1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
420 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
421 err = vfs_unlink(vfs, "/dir1/file3");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
422 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
423
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
424 err = vfs_unlink(vfs, "/filex");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
425 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
426
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
427 // check if files were removed
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
428 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
429 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
430 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
431 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
432
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
433 // file2 should still be there
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
434 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
435 UCX_TEST_ASSERT(o2, "/file2 deleted");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
436
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
437 // check if dir unlink fails
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
438 err = vfs_unlink(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
439 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
440
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
441 UCX_TEST_END;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
442
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
443 testutil_destroy_session(sn);
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
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
446 UCX_TEST(test_vfs_rmdir) {
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
447 Session *sn = testutil_session();
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
448 Request *rq = testutil_request(sn->pool, "PUT", "/");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
449 rq->vfs = testvfs_create(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
450
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
451 VFSContext *vfs = vfs_request_context(sn, rq);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
452
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
453 UCX_TEST_BEGIN;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
454 // prepare test
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
455 int err;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
456 err = vfs_mkdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
457 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
458 err = vfs_mkdir(vfs, "/dir2");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
459 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
460
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
461 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
462 UCX_TEST_ASSERT(f1, "f1 not opened");
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 err = vfs_rmdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
465 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
466 err = vfs_rmdir(vfs, "/dir2");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
467 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
468
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
469 err = vfs_unlink(vfs, "/dir1/file1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
470 UCX_TEST_ASSERT(err == 0, "unlink failed");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
471 err = vfs_rmdir(vfs, "/dir1");
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
472 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
473
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
474 UCX_TEST_END;
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
475
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
476 testutil_destroy_session(sn);
bc8f8ddbad2e add vfs unlink and rmdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 241
diff changeset
477 }

mercurial