2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 unsigned int in_flags;
48 uint16_t ucs2[MAX_LENGTH];
49 unsigned int out_flags;
53 4, "\xff\xfe\x20\x00",
60 4, "\xfe\xff\x00\x20",
91 WIND_RW_BOM|WIND_RW_LE,
92 4, "\x34\x6C\x7A\x00",
100 4, "\x34\x6C\x7A\x00",
105 /* BOM + water + z */
108 6, "\xFF\xFE\x34\x6C\x7A\x00",
113 /* BOM + water + z */
116 6, "\xFE\xFF\x6C\x34\x00\x7A",
121 /* error, odd length */
125 WIND_ERR_LENGTH_NOT_MOD2,
129 /* error, missing BOM */
140 4, "\x00\x20\x00\x20",
151 unsigned int n, m, flags;
152 uint16_t data[MAX_LENGTH];
156 for (n = 0; n < sizeof(testcases)/sizeof(testcases[0]); n++) {
157 flags = testcases[n].in_flags;
159 datalen = testcases[n].ucs2_len;
160 assert(datalen < sizeof(data));
162 ret = wind_ucs2read(testcases[n].in_ptr,
167 if (ret != testcases[n].ret)
168 errx(1, "testcases %u: wind_ucs2read: %d", n, ret);
170 /* on error, skip all other tests */
174 if (flags != testcases[n].out_flags)
175 errx(1, "testcases %u: flags wrong", n);
177 if (datalen != testcases[n].ucs2_len)
178 errx(1, "testcases %u: ucs len wrong", n);
180 for (m = 0; m < datalen; m++)
181 if (testcases[n].ucs2[m] != data[m])
182 errx(1, "testcases %u: char %u wrong", n, m);