Apache HTTPD
testfmt.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 "testutil.h"
18#include "apr.h"
19#include "apr_portable.h"
20#include "apr_strings.h"
21
22static void ssize_t_fmt(abts_case *tc, void *data)
23{
24 char buf[100];
25 apr_ssize_t var = 0;
26
28 ABTS_STR_EQUAL(tc, "0", buf);
29 apr_snprintf(buf, sizeof(buf), "%" APR_SSIZE_T_FMT, var);
30 ABTS_STR_EQUAL(tc, "0", buf);
31}
32
33static void size_t_fmt(abts_case *tc, void *data)
34{
35 char buf[100];
36 apr_size_t var = 0;
37
39 ABTS_STR_EQUAL(tc, "0", buf);
40 apr_snprintf(buf, sizeof(buf), "%" APR_SIZE_T_FMT, var);
41 ABTS_STR_EQUAL(tc, "0", buf);
42}
43
44static void time_t_fmt(abts_case *tc, void *data)
45{
46 char buf[100];
47 apr_time_t var = 1;
48
50 ABTS_STR_EQUAL(tc, "1", buf);
51 apr_snprintf(buf, sizeof(buf), "%" APR_TIME_T_FMT, var);
52 ABTS_STR_EQUAL(tc, "1", buf);
53}
54
55static void off_t_fmt(abts_case *tc, void *data)
56{
57 char buf[100];
58 apr_off_t var = 0;
59
61 ABTS_STR_EQUAL(tc, "0", buf);
62 apr_snprintf(buf, sizeof(buf), "%" APR_OFF_T_FMT, var);
63 ABTS_STR_EQUAL(tc, "0", buf);
64}
65
66static void pid_t_fmt(abts_case *tc, void *data)
67{
68 char buf[100];
69 pid_t var = 0;
70
72 ABTS_STR_EQUAL(tc, "0", buf);
73 apr_snprintf(buf, sizeof(buf), "%" APR_PID_T_FMT, var);
74 ABTS_STR_EQUAL(tc, "0", buf);
75}
76
77static void int64_t_fmt(abts_case *tc, void *data)
78{
79 char buf[100];
80 apr_int64_t var = 0;
81
83 ABTS_STR_EQUAL(tc, "0", buf);
84 apr_snprintf(buf, sizeof(buf), "%" APR_INT64_T_FMT, var);
85 ABTS_STR_EQUAL(tc, "0", buf);
86}
87
88static void uint64_t_fmt(abts_case *tc, void *data)
89{
90 char buf[100];
91 apr_uint64_t var = APR_UINT64_C(14000000);
92
94 ABTS_STR_EQUAL(tc, "14000000", buf);
95 apr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_FMT, var);
96 ABTS_STR_EQUAL(tc, "14000000", buf);
97}
98
99static void uint64_t_hex_fmt(abts_case *tc, void *data)
100{
101 char buf[100];
102 apr_uint64_t var = APR_UINT64_C(14000000);
103
105 ABTS_STR_EQUAL(tc, "d59f80", buf);
107 ABTS_STR_EQUAL(tc, "d59f80", buf);
108}
109
110static void more_int64_fmts(abts_case *tc, void *data)
111{
112 char buf[100];
114 apr_int64_t ibig = APR_INT64_C(-314159265358979323);
116 apr_uint64_t big = APR_UINT64_C(10267677267010969076);
117
118 apr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, i);
119 ABTS_STR_EQUAL(tc, "-42", buf);
120
121 apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, ui);
122 ABTS_STR_EQUAL(tc, "42", buf);
123
124 apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, big);
125 ABTS_STR_EQUAL(tc, "10267677267010969076", buf);
126
127 apr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, ibig);
128 ABTS_STR_EQUAL(tc, "-314159265358979323", buf);
129}
130
131static void error_fmt(abts_case *tc, void *data)
132{
133 char ebuf[150], sbuf[150], *s;
134 apr_status_t rv;
135
136 rv = APR_SUCCESS;
137 apr_strerror(rv, ebuf, sizeof ebuf);
138 apr_snprintf(sbuf, sizeof sbuf, "%pm", &rv);
140
141 rv = APR_ENOTIMPL;
142 s = apr_pstrcat(p, "foo-",
143 apr_strerror(rv, ebuf, sizeof ebuf),
144 "-bar", NULL);
145 apr_snprintf(sbuf, sizeof sbuf, "foo-%pm-bar", &rv);
146 ABTS_STR_EQUAL(tc, sbuf, s);
147}
148
150{
151 suite = ADD_SUITE(suite)
152
163
164 return suite;
165}
166
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
APR Portability Routines.
APR Strings library.
const unsigned char * buf
Definition util_md5.h:50
#define APR_ENOTIMPL
Definition apr_errno.h:476
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
const char * s
Definition apr_strings.h:95
#define APR_TIME_T_FMT
Definition apr_time.h:52
apr_int64_t apr_time_t
Definition apr_time.h:45
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
static void uint64_t_hex_fmt(abts_case *tc, void *data)
Definition testfmt.c:99
abts_suite * testfmt(abts_suite *suite)
Definition testfmt.c:149
static void ssize_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:22
static void size_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:33
static void uint64_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:88
static void off_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:55
static void int64_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:77
static void error_fmt(abts_case *tc, void *data)
Definition testfmt.c:131
static void time_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:44
static void more_int64_fmts(abts_case *tc, void *data)
Definition testfmt.c:110
static void pid_t_fmt(abts_case *tc, void *data)
Definition testfmt.c:66
#define var