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
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.
19 #include "apr_portable.h"
20 #include "apr_strings.h"
22 static void ssize_t_fmt(CuTest *tc)
27 sprintf(buf, "%" APR_SSIZE_T_FMT, var);
28 CuAssertStrEquals(tc, "0", buf);
29 apr_snprintf(buf, sizeof(buf), "%" APR_SSIZE_T_FMT, var);
30 CuAssertStrEquals(tc, "0", buf);
33 static void size_t_fmt(CuTest *tc)
38 sprintf(buf, "%" APR_SIZE_T_FMT, var);
39 CuAssertStrEquals(tc, "0", buf);
40 apr_snprintf(buf, sizeof(buf), "%" APR_SIZE_T_FMT, var);
41 CuAssertStrEquals(tc, "0", buf);
44 static void off_t_fmt(CuTest *tc)
49 sprintf(buf, "%" APR_OFF_T_FMT, var);
50 CuAssertStrEquals(tc, "0", buf);
51 apr_snprintf(buf, sizeof(buf), "%" APR_OFF_T_FMT, var);
52 CuAssertStrEquals(tc, "0", buf);
55 static void pid_t_fmt(CuTest *tc)
60 sprintf(buf, "%" APR_PID_T_FMT, var);
61 CuAssertStrEquals(tc, "0", buf);
62 apr_snprintf(buf, sizeof(buf), "%" APR_PID_T_FMT, var);
63 CuAssertStrEquals(tc, "0", buf);
66 static void int64_t_fmt(CuTest *tc)
71 sprintf(buf, "%" APR_INT64_T_FMT, var);
72 CuAssertStrEquals(tc, "0", buf);
73 apr_snprintf(buf, sizeof(buf), "%" APR_INT64_T_FMT, var);
74 CuAssertStrEquals(tc, "0", buf);
77 static void uint64_t_fmt(CuTest *tc)
80 apr_uint64_t var = 14000000;
82 sprintf(buf, "%" APR_UINT64_T_FMT, var);
83 CuAssertStrEquals(tc, "14000000", buf);
84 apr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_FMT, var);
85 CuAssertStrEquals(tc, "14000000", buf);
88 static void uint64_t_hex_fmt(CuTest *tc)
91 apr_uint64_t var = 14000000;
93 sprintf(buf, "%" APR_UINT64_T_HEX_FMT, var);
94 CuAssertStrEquals(tc, "d59f80", buf);
95 apr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_HEX_FMT, var);
96 CuAssertStrEquals(tc, "d59f80", buf);
99 CuSuite *testfmt(void)
101 CuSuite *suite = CuSuiteNew("Formats");
103 SUITE_ADD_TEST(suite, ssize_t_fmt);
104 SUITE_ADD_TEST(suite, size_t_fmt);
105 SUITE_ADD_TEST(suite, off_t_fmt);
106 SUITE_ADD_TEST(suite, pid_t_fmt);
107 SUITE_ADD_TEST(suite, int64_t_fmt);
108 SUITE_ADD_TEST(suite, uint64_t_fmt);
109 SUITE_ADD_TEST(suite, uint64_t_hex_fmt);