1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
#include "apr_file_io.h"
19
#include "apr_file_info.h"
20
#include "apr_errno.h"
21
#include "apr_pools.h"
23
static void copy_helper(abts_case *tc, const char *from, const char * to,
24
apr_fileperms_t perms, int append, apr_pool_t *p)
32
dest_rv = apr_stat(&dest, to, APR_FINFO_SIZE, p);
35
rv = apr_file_copy(from, to, perms, p);
38
rv = apr_file_append(from, to, perms, p);
40
APR_ASSERT_SUCCESS(tc, "Error copying file", rv);
42
rv = apr_stat(&orig, from, APR_FINFO_SIZE, p);
43
APR_ASSERT_SUCCESS(tc, "Couldn't stat original file", rv);
45
rv = apr_stat(©, to, APR_FINFO_SIZE, p);
46
APR_ASSERT_SUCCESS(tc, "Couldn't stat copy file", rv);
49
ABTS_ASSERT(tc, "File size differs", orig.size == copy.size);
52
ABTS_ASSERT(tc, "File size differs",
53
((dest_rv == APR_SUCCESS)
54
? dest.size : 0) + orig.size == copy.size);
58
static void copy_short_file(abts_case *tc, void *data)
62
/* make absolutely sure that the dest file doesn't exist. */
63
apr_file_remove("data/file_copy.txt", p);
65
copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt",
66
APR_FILE_SOURCE_PERMS, 0, p);
67
rv = apr_file_remove("data/file_copy.txt", p);
68
APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
71
static void copy_over_existing(abts_case *tc, void *data)
75
/* make absolutely sure that the dest file doesn't exist. */
76
apr_file_remove("data/file_copy.txt", p);
78
/* This is a cheat. I don't want to create a new file, so I just copy
79
* one file, then I copy another. If the second copy succeeds, then
82
copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt",
83
APR_FILE_SOURCE_PERMS, 0, p);
85
copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt",
86
APR_FILE_SOURCE_PERMS, 0, p);
88
rv = apr_file_remove("data/file_copy.txt", p);
89
APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
92
static void append_nonexist(abts_case *tc, void *data)
96
/* make absolutely sure that the dest file doesn't exist. */
97
apr_file_remove("data/file_copy.txt", p);
99
copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt",
100
APR_FILE_SOURCE_PERMS, 0, p);
101
rv = apr_file_remove("data/file_copy.txt", p);
102
APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
105
static void append_exist(abts_case *tc, void *data)
109
/* make absolutely sure that the dest file doesn't exist. */
110
apr_file_remove("data/file_copy.txt", p);
112
/* This is a cheat. I don't want to create a new file, so I just copy
113
* one file, then I copy another. If the second copy succeeds, then
116
copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt",
117
APR_FILE_SOURCE_PERMS, 0, p);
119
copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt",
120
APR_FILE_SOURCE_PERMS, 1, p);
122
rv = apr_file_remove("data/file_copy.txt", p);
123
APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
126
abts_suite *testfilecopy(abts_suite *suite)
128
suite = ADD_SUITE(suite)
130
abts_run_test(suite, copy_short_file, NULL);
131
abts_run_test(suite, copy_over_existing, NULL);
133
abts_run_test(suite, append_nonexist, NULL);
134
abts_run_test(suite, append_exist, NULL);