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.
21
#include "apr_errno.h"
22
#include "apr_general.h"
23
#include "apr_strings.h"
24
#include "apr_xlate.h"
26
static const char test_utf8[] = "Edelwei\xc3\x9f";
27
static const char test_utf7[] = "Edelwei+AN8-";
28
static const char test_latin1[] = "Edelwei\xdf";
29
static const char test_latin2[] = "Edelwei\xdf";
32
static int check_status (apr_status_t status, const char *msg)
36
static char buf[1024];
37
printf("ERROR: %s\n %s\n", msg,
38
apr_strerror(status, buf, sizeof(buf)));
44
static int test_conversion (apr_xlate_t *convset,
48
static char buf[1024];
50
apr_size_t inbytes_left = strlen(inbuf);
51
apr_size_t outbytes_left = sizeof(buf) - 1;
52
apr_status_t status = apr_xlate_conv_buffer(convset,
57
if (status == APR_SUCCESS) {
58
status = apr_xlate_conv_buffer(convset, NULL, NULL,
59
buf + sizeof(buf) - outbytes_left - 1,
62
buf[sizeof(buf) - outbytes_left - 1] = '\0';
63
retcode |= check_status(status, "apr_xlate_conv_buffer");
64
if ((!status || APR_STATUS_IS_INCOMPLETE(status))
65
&& strcmp(buf, expected))
67
printf("ERROR: expected: '%s'\n actual: '%s'"
68
"\n inbytes_left: %"APR_SIZE_T_FMT"\n",
69
expected, buf, inbytes_left);
75
static int one_test (const char *cs1, const char *cs2,
76
const char *str1, const char *str2,
80
const char *msg = apr_psprintf(pool, "apr_xlate_open(%s, %s)", cs2, cs1);
81
int retcode = check_status(apr_xlate_open(&convset, cs2, cs1, pool), msg);
84
retcode |= test_conversion(convset, str1, str2);
85
retcode |= check_status(apr_xlate_close(convset), "apr_xlate_close");
87
printf("%s: %s -> %s\n", (retcode ? "FAIL" : "PASS"), cs1, cs2);
92
int main (int argc, char **argv)
98
puts("SKIP: apr_xlate not implemented");
103
atexit(apr_terminate);
104
apr_pool_create(&pool, NULL);
106
/* 1. Identity transformation: UTF-8 -> UTF-8 */
107
retcode |= one_test("UTF-8", "UTF-8", test_utf8, test_utf8, pool);
109
/* 2. UTF-8 <-> ISO-8859-1 */
110
retcode |= one_test("UTF-8", "ISO-8859-1", test_utf8, test_latin1, pool);
111
retcode |= one_test("ISO-8859-1", "UTF-8", test_latin1, test_utf8, pool);
113
/* 3. ISO-8859-1 <-> ISO-8859-2, identity */
114
retcode |= one_test("ISO-8859-1", "ISO-8859-2",
115
test_latin1, test_latin2, pool);
116
retcode |= one_test("ISO-8859-2", "ISO-8859-1",
117
test_latin2, test_latin1, pool);
119
/* 4. Transformation using charset aliases */
120
retcode |= one_test("UTF-8", "UTF-7", test_utf8, test_utf7, pool);
121
retcode |= one_test("UTF-7", "UTF-8", test_utf7, test_utf8, pool);