Apache HTTPD
testdup.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
18#include "apr_general.h"
19#include "apr_pools.h"
20#include "apr_errno.h"
21#include "apr_file_io.h"
22#include "testutil.h"
23
24#define TEST "Testing\n"
25#define TEST2 "Testing again\n"
26#define FILEPATH "data/"
27
28static void test_file_dup(abts_case *tc, void *data)
29{
32 apr_status_t rv;
33 apr_finfo_t finfo;
34
35 /* First, create a new file, empty... */
36 rv = apr_file_open(&file1, FILEPATH "testdup.file",
41
42 rv = apr_file_dup(&file3, file1, p);
45
48
49 /* cleanup after ourselves */
52 rv = apr_stat(&finfo, FILEPATH "testdup.file", APR_FINFO_NORM, p);
54}
55
56static void test_file_readwrite(abts_case *tc, void *data)
57{
60 apr_status_t rv;
61 apr_finfo_t finfo;
62 apr_size_t txtlen = sizeof(TEST);
63 char buff[50];
65
66 /* First, create a new file, empty... */
67 rv = apr_file_open(&file1, FILEPATH "testdup.readwrite.file",
72
73 rv = apr_file_dup(&file3, file1, p);
76
79 ABTS_SIZE_EQUAL(tc, sizeof(TEST), txtlen);
80
81 fpos = 0;
84 ABTS_ASSERT(tc, "File position mismatch, expected 0", fpos == 0);
85
86 txtlen = 50;
90
91 /* cleanup after ourselves */
94
97 rv = apr_stat(&finfo, FILEPATH "testdup.readwrite.file", APR_FINFO_NORM, p);
99}
100
101static void test_dup2(abts_case *tc, void *data)
102{
106 apr_status_t rv;
107
108 rv = apr_file_open(&testfile, FILEPATH "testdup2.file",
113
116
117 /* Set aside the real errfile */
118 rv = apr_file_dup(&saveerr, errfile, p);
121
125
127
131
133}
134
135static void test_dup2_readwrite(abts_case *tc, void *data)
136{
140 apr_status_t rv;
141 apr_size_t txtlen = sizeof(TEST);
142 char buff[50];
144
145 rv = apr_file_open(&testfile, FILEPATH "testdup2.readwrite.file",
150
153
154 /* Set aside the real errfile */
155 rv = apr_file_dup(&saveerr, errfile, p);
158
162
163 txtlen = sizeof(TEST2);
166 ABTS_SIZE_EQUAL(tc, sizeof(TEST2), txtlen);
167
168 fpos = 0;
171 ABTS_ASSERT(tc, "File position mismatch, expected 0", fpos == 0);
172
173 txtlen = 50;
177
179
183
185}
186
188{
189 suite = ADD_SUITE(suite)
190
195
196 return suite;
197}
198
const char * buff
Definition ap_regex.h:186
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_SIZE_EQUAL(a, b, c)
Definition abts.h:121
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR memory allocation.
#define APR_STATUS_IS_ENOENT(s)
Definition apr_errno.h:1246
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
#define APR_FOPEN_DELONCLOSE
Definition apr_file_io.h:66
#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_OS_DEFAULT
#define APR_SET
#define APR_FINFO_NORM
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
#define TEST2
Definition testdup.c:25
static void test_file_readwrite(abts_case *tc, void *data)
Definition testdup.c:56
static void test_dup2_readwrite(abts_case *tc, void *data)
Definition testdup.c:135
abts_suite * testdup(abts_suite *suite)
Definition testdup.c:187
#define FILEPATH
Definition testdup.c:26
static void test_file_dup(abts_case *tc, void *data)
Definition testdup.c:28
static void test_dup2(abts_case *tc, void *data)
Definition testdup.c:101
#define TEST
Definition testdup.c:24
abts_suite * testfile(abts_suite *suite)
Definition testfile.c:2230