Apache HTTPD
testdir.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "apr_file_io.h"
21#include "apr_file_info.h"
22#include "apr_errno.h"
23#include "apr_general.h"
24#include "apr_lib.h"
25#include "apr_thread_proc.h"
26#include "testutil.h"
27
28static void test_mkdir(abts_case *tc, void *data)
29{
30 apr_status_t rv;
31 apr_finfo_t finfo;
32
33 rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
35
36 rv = apr_stat(&finfo, "data/testdir", APR_FINFO_TYPE, p);
39}
40
41static void test_mkdir_recurs(abts_case *tc, void *data)
42{
43 apr_status_t rv;
44 apr_finfo_t finfo;
45
46 rv = apr_dir_make_recursive("data/one/two/three",
49
50 rv = apr_stat(&finfo, "data/one", APR_FINFO_TYPE, p);
53
54 rv = apr_stat(&finfo, "data/one/two", APR_FINFO_TYPE, p);
57
58 rv = apr_stat(&finfo, "data/one/two/three", APR_FINFO_TYPE, p);
61}
62
89
90#if APR_HAS_THREADS
91struct thread_data
92{
93 abts_case *tc;
95};
96
98{
99 struct thread_data *td = data;
100 mkdir_func(td->tc, td->pool);
101 return NULL;
102}
103#endif /* APR_HAS_THREADS */
104
106{
107#if APR_HAS_THREADS
108 struct thread_data td1, td2, td3, td4;
109 apr_thread_t *t1, *t2, *t3, *t4;
111
112 td1.tc = td2.tc = td3.tc = td4.tc = tc;
113 apr_pool_create(&td1.pool, p);
114 apr_pool_create(&td2.pool, p);
115 apr_pool_create(&td3.pool, p);
116 apr_pool_create(&td4.pool, p);
117
126
131
136#else
137 /* Create the test directories for test_removeall anwyay. */
138 mkdir_func(tc, p);
139 ABTS_SKIP(tc, data, "This test requires APR thread support.");
140#endif /* APR_HAS_THREADS */
141}
142
143static void test_remove(abts_case *tc, void *data)
144{
145 apr_status_t rv;
146 apr_finfo_t finfo;
147
148 rv = apr_dir_remove("data/testdir", p);
150
151 rv = apr_stat(&finfo, "data/testdir", APR_FINFO_TYPE, p);
153}
154
155static void test_removeall_fail(abts_case *tc, void *data)
156{
157 apr_status_t rv;
158
159 rv = apr_dir_remove("data/one", p);
161}
162
163static void test_removeall(abts_case *tc, void *data)
164{
165 apr_status_t rv;
166
167 rv = apr_dir_remove("data/one/two/three", p);
169
170 rv = apr_dir_remove("data/one/two", p);
172
173 rv = apr_dir_remove("data/one", p);
175
176 rv = apr_dir_remove("data/prll/one/thwo/three", p);
178
179 rv = apr_dir_remove("data/prll/one/thwo", p);
181
182 rv = apr_dir_remove("data/prll/one", p);
184
185 rv = apr_dir_remove("data/prll/four/five/six/seven/eight", p);
187
188 rv = apr_dir_remove("data/prll/four/five/six/seven", p);
190
191 rv = apr_dir_remove("data/prll/four/five/six", p);
193
194 rv = apr_dir_remove("data/prll/four/five", p);
196
197 rv = apr_dir_remove("data/prll/four", p);
199
200 rv = apr_dir_remove("data/prll/nine/ten", p);
202
203 rv = apr_dir_remove("data/prll/nine", p);
205
206 rv = apr_dir_remove("data/prll/11/12/13/14/15/16/17/18/19/20", p);
208
209 rv = apr_dir_remove("data/prll/11/12/13/14/15/16/17/18/19", p);
211
212 rv = apr_dir_remove("data/prll/11/12/13/14/15/16/17/18", p);
214
215 rv = apr_dir_remove("data/prll/11/12/13/14/15/16/17", p);
217
218 rv = apr_dir_remove("data/prll/11/12/13/14/15/16", p);
220
221 rv = apr_dir_remove("data/prll/11/12/13/14/15", p);
223
224 rv = apr_dir_remove("data/prll/11/12/13/14", p);
226
227 rv = apr_dir_remove("data/prll/11/12/13", p);
229
230 rv = apr_dir_remove("data/prll/11/12", p);
232
233 rv = apr_dir_remove("data/prll/11", p);
235
236 rv = apr_dir_remove("data/prll", p);
238
239 rv = apr_dir_remove("data/fortytwo", p);
241}
242
243static void test_remove_notthere(abts_case *tc, void *data)
244{
245 apr_status_t rv;
246
247 rv = apr_dir_remove("data/notthere", p);
249}
250
251static void test_mkdir_twice(abts_case *tc, void *data)
252{
253 apr_status_t rv;
254
255 rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
257
258 rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
260
261 rv = apr_dir_remove("data/testdir", p);
263}
264
265static void test_opendir(abts_case *tc, void *data)
266{
267 apr_status_t rv;
268 apr_dir_t *dir;
269
270 rv = apr_dir_open(&dir, "data", p);
273}
274
275static void test_opendir_notthere(abts_case *tc, void *data)
276{
277 apr_status_t rv;
278 apr_dir_t *dir;
279
280 rv = apr_dir_open(&dir, "notthere", p);
282}
283
284static void test_closedir(abts_case *tc, void *data)
285{
286 apr_status_t rv;
287 apr_dir_t *dir;
288
289 rv = apr_dir_open(&dir, "data", p);
291 rv = apr_dir_close(dir);
293}
294
295static void test_rewind(abts_case *tc, void *data)
296{
297 apr_dir_t *dir;
299
300 APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p));
301
302 APR_ASSERT_SUCCESS(tc, "apr_dir_read failed",
304
305 APR_ASSERT_SUCCESS(tc, "apr_dir_rewind failed", apr_dir_rewind(dir));
306
307 APR_ASSERT_SUCCESS(tc, "second apr_dir_read failed",
309
310 APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir));
311
312 ABTS_STR_EQUAL(tc, first.name, second.name);
313}
314
315/* Test for a (fixed) bug in apr_dir_read(). This bug only happened
316 in threadless cases. */
317static void test_uncleared_errno(abts_case *tc, void *data)
318{
320 apr_finfo_t finfo;
323 apr_status_t rv;
324
325 rv = apr_dir_make("dir1", APR_OS_DEFAULT, p);
327 rv = apr_dir_make("dir2", APR_OS_DEFAULT, p);
329 rv = apr_file_open(&thefile, "dir1/file1",
334
335 /* Try to remove dir1. This should fail because it's not empty.
336 However, on a platform with threads disabled (such as FreeBSD),
337 `errno' will be set as a result. */
338 rv = apr_dir_remove("dir1", p);
340
341 /* Read `.' and `..' out of dir2. */
342 rv = apr_dir_open(&this_dir, "dir2", p);
344 rv = apr_dir_read(&finfo, finfo_flags, this_dir);
346 rv = apr_dir_read(&finfo, finfo_flags, this_dir);
348
349 /* Now, when we attempt to do a third read of empty dir2, and the
350 underlying system readdir() returns NULL, the old value of
351 errno shouldn't cause a false alarm. We should get an ENOENT
352 back from apr_dir_read, and *not* the old errno. */
353 rv = apr_dir_read(&finfo, finfo_flags, this_dir);
355
358
359 /* Cleanup */
360 rv = apr_file_remove("dir1/file1", p);
362 rv = apr_dir_remove("dir1", p);
364 rv = apr_dir_remove("dir2", p);
366
367}
368
369static void test_rmkdir_nocwd(abts_case *tc, void *data)
370{
371 char *cwd, *path;
372
373 APR_ASSERT_SUCCESS(tc, "make temp dir",
374 apr_dir_make("dir3", APR_OS_DEFAULT, p));
375
376 APR_ASSERT_SUCCESS(tc, "obtain cwd", apr_filepath_get(&cwd, 0, p));
377
378 APR_ASSERT_SUCCESS(tc, "determine path to temp dir",
379 apr_filepath_merge(&path, cwd, "dir3", 0, p));
380
381 APR_ASSERT_SUCCESS(tc, "change to temp dir", apr_filepath_set(path, p));
382
383 APR_ASSERT_SUCCESS(tc, "restore cwd", apr_filepath_set(cwd, p));
384
385 APR_ASSERT_SUCCESS(tc, "remove cwd", apr_dir_remove(path, p));
386}
387
388
412
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_SKIP(tc, data, msg)
Definition abts.h:135
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
#define APR_ASSERT_SUCCESS(tc, ctxt, rv)
Definition testutil.h:58
APR Error Codes.
APR File Information.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Thread and Process Library.
apr_status_t apr_dir_make_recursive(const char *path, apr_fileperms_t perm, apr_pool_t *pool)
request_rec int int apr_table_t const char * path
#define APR_STATUS_IS_EEXIST(s)
Definition apr_errno.h:1233
#define APR_STATUS_IS_ENOTEMPTY(s)
Definition apr_errno.h:1323
#define APR_STATUS_IS_ENOENT(s)
Definition apr_errno.h:1246
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
@ APR_DIR
apr_file_t * thefile
void * data
#define APR_FOPEN_WRITE
Definition apr_file_io.h:55
#define APR_FOPEN_READ
Definition apr_file_io.h:54
#define APR_FOPEN_CREATE
Definition apr_file_io.h:56
#define APR_FPROT_UEXECUTE
#define APR_UEXECUTE
#define APR_UWRITE
#define APR_FPROT_UWRITE
#define APR_UREAD
#define APR_OS_DEFAULT
#define APR_FPROT_UREAD
#define APR_FINFO_NAME
#define APR_FINFO_DIRENT
#define APR_FINFO_TYPE
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
apr_dir_t * dir
const apr_array_header_t * first
Definition apr_tables.h:207
const apr_array_header_t const apr_array_header_t * second
Definition apr_tables.h:208
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
Definition thread.c:166
apr_status_t apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *pool)
Definition thread.c:73
apr_filetype_e filetype
static void test_mkdir_recurs_parallel(abts_case *tc, void *data)
Definition testdir.c:105
static void mkdir_func(abts_case *tc, apr_pool_t *pool)
Definition testdir.c:63
static void test_uncleared_errno(abts_case *tc, void *data)
Definition testdir.c:317
static void test_remove(abts_case *tc, void *data)
Definition testdir.c:143
static void test_rmkdir_nocwd(abts_case *tc, void *data)
Definition testdir.c:369
static void test_opendir(abts_case *tc, void *data)
Definition testdir.c:265
static void test_mkdir_recurs(abts_case *tc, void *data)
Definition testdir.c:41
static void test_removeall_fail(abts_case *tc, void *data)
Definition testdir.c:155
static void test_opendir_notthere(abts_case *tc, void *data)
Definition testdir.c:275
static void test_mkdir_twice(abts_case *tc, void *data)
Definition testdir.c:251
static void test_remove_notthere(abts_case *tc, void *data)
Definition testdir.c:243
abts_suite * testdir(abts_suite *suite)
Definition testdir.c:389
static void test_closedir(abts_case *tc, void *data)
Definition testdir.c:284
static void test_removeall(abts_case *tc, void *data)
Definition testdir.c:163
static void test_rewind(abts_case *tc, void *data)
Definition testdir.c:295
static void test_mkdir(abts_case *tc, void *data)
Definition testdir.c:28
static apr_table_t * t1
Definition testtable.c:34
apr_status_t apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, apr_dir_t *thedir)
Definition dir.c:142
apr_status_t apr_dir_make(const char *path, apr_fileperms_t perm, apr_pool_t *pool)
Definition dir.c:297
apr_status_t apr_dir_remove(const char *path, apr_pool_t *pool)
Definition dir.c:343
apr_status_t apr_dir_close(apr_dir_t *thedir)
Definition dir.c:109
apr_status_t apr_dir_open(apr_dir_t **new, const char *dirname, apr_pool_t *pool)
Definition dir.c:75
apr_status_t apr_dir_rewind(apr_dir_t *thedir)
Definition dir.c:291