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.
18 #include "arch/win32/apr_arch_utf8.h"
29 void displaynw(struct testval *f, struct testval *l)
33 for (i = 0; i < f->nl; ++i)
34 t += sprintf(t, "%02X ", f->n[i]);
36 for (i = 0; i < l->nl; ++i)
37 t += sprintf(t, " %02X", l->n[i]);
41 for (i = 0; i < f->wl; ++i)
42 t += sprintf(t, "%04X ", f->w[i]);
44 for (i = 0; i < l->wl; ++i)
45 t += sprintf(t, " %04X", l->w[i]);
50 * Test every possible byte value.
51 * If the test passes or fails at this byte value we are done.
52 * Otherwise iterate test_nrange again, appending another byte.
54 void test_nrange(struct testval *p)
56 struct testval f, l, s;
60 memcpy (&s, p, sizeof(s));
64 apr_size_t nl = s.nl, wl = sizeof(s.w) / 2;
65 rc = apr_conv_utf8_to_ucs2(s.n, &nl, s.w, &wl);
66 s.wl = (sizeof(s.w) / 2) - wl;
67 if (!nl && rc == APR_SUCCESS) {
69 memcpy(&f, &s, sizeof(s));
74 || memcmp(s.w, l.w, (s.wl - 1) * 2) != 0
75 || s.w[s.wl - 1] != l.w[l.wl - 1] + 1) {
77 memcpy(&f, &s, sizeof(s));
80 memcpy(&l, &s, sizeof(s));
87 if (rc == APR_INCOMPLETE) {
91 } while (++s.n[s.nl - 1]);
100 * Test every possible word value.
101 * Once we are finished, retest every possible word value.
102 * if the test fails on the following null word, iterate test_nrange
103 * again, appending another word.
104 * This assures the output order of the two tests are in sync.
106 void test_wrange(struct testval *p)
108 struct testval f, l, s;
112 memcpy (&s, p, sizeof(s));
116 apr_size_t nl = sizeof(s.n), wl = s.wl;
117 rc = apr_conv_ucs2_to_utf8(s.w, &wl, s.n, &nl);
118 s.nl = sizeof(s.n) - nl;
119 if (!wl && rc == APR_SUCCESS) {
121 memcpy(&f, &s, sizeof(s));
126 || memcmp(s.n, l.n, s.nl - 1) != 0
127 || s.n[s.nl - 1] != l.n[l.nl - 1] + 1) {
129 memcpy(&f, &s, sizeof(s));
132 memcpy(&l, &s, sizeof(s));
140 } while (++s.w[s.wl - 1]);
148 int wl = s.wl, nl = sizeof(s.n);
149 rc = apr_conv_ucs2_to_utf8(s.w, &wl, s.n, &nl);
150 s.nl = sizeof(s.n) - s.nl;
151 if (rc == APR_INCOMPLETE) {
154 } while (++s.w[s.wl - 1]);
158 * Syntax: testucs [w|n]
160 * If arg is not recognized, run both tests.
162 int main(int argc, char **argv)
165 memset (&s, 0, sizeof(s));
167 if (argc < 2 || apr_tolower(*argv[1]) != 'w') {
168 printf ("\n\nTesting Narrow Char Ranges\n");
171 if (argc < 2 || apr_tolower(*argv[1]) != 'n') {
172 printf ("\n\nTesting Wide Char Ranges\n");