Blame


1 3300cbe0 2021-01-27 op /*
2 3300cbe0 2021-01-27 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 3300cbe0 2021-01-27 op *
4 3300cbe0 2021-01-27 op * Permission to use, copy, modify, and distribute this software for any
5 3300cbe0 2021-01-27 op * purpose with or without fee is hereby granted, provided that the above
6 3300cbe0 2021-01-27 op * copyright notice and this permission notice appear in all copies.
7 3300cbe0 2021-01-27 op *
8 3300cbe0 2021-01-27 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3300cbe0 2021-01-27 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3300cbe0 2021-01-27 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3300cbe0 2021-01-27 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3300cbe0 2021-01-27 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3300cbe0 2021-01-27 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3300cbe0 2021-01-27 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 3300cbe0 2021-01-27 op */
16 3300cbe0 2021-01-27 op
17 3300cbe0 2021-01-27 op #include <stdio.h>
18 3300cbe0 2021-01-27 op #include <string.h>
19 3300cbe0 2021-01-27 op
20 3300cbe0 2021-01-27 op #include "../gmid.h"
21 3300cbe0 2021-01-27 op
22 e5d82d94 2022-03-19 op const struct suite {
23 3300cbe0 2021-01-27 op const char *src;
24 3300cbe0 2021-01-27 op const char *res;
25 3300cbe0 2021-01-27 op } t[] = {
26 3300cbe0 2021-01-27 op {"foo", "foo"},
27 44ee1bac 2021-01-27 op {"h.n", "h.n"},
28 3300cbe0 2021-01-27 op {"xn-invalid", "xn-invalid"},
29 3300cbe0 2021-01-27 op {"naïve", "naïve"},
30 3300cbe0 2021-01-27 op {"xn--8ca", "è"},
31 3300cbe0 2021-01-27 op {"xn--caff-8oa", "caffè"},
32 3300cbe0 2021-01-27 op {"xn--nave-6pa", "naïve"},
33 3300cbe0 2021-01-27 op {"xn--e-0mbbc", "τeστ"},
34 3300cbe0 2021-01-27 op {"xn--8ca67lbac", "τèστ"},
35 3300cbe0 2021-01-27 op {"xn--28j2a3ar1p", "こんにちは"},
36 3300cbe0 2021-01-27 op {"xn--hello--ur7iy09x", "hello-世界"},
37 3300cbe0 2021-01-27 op {"xn--hi--hi-rr7iy09x", "hi-世界-hi"},
38 3300cbe0 2021-01-27 op {"xn--caf-8la.foo.org", "cafè.foo.org"},
39 3300cbe0 2021-01-27 op /* 3 bytes */
40 3300cbe0 2021-01-27 op {"xn--j6h", "♨"},
41 3300cbe0 2021-01-27 op /* 4 bytes */
42 3300cbe0 2021-01-27 op {"xn--x73l", "𩸽"},
43 3300cbe0 2021-01-27 op {"xn--x73laaa", "𩸽𩸽𩸽𩸽"},
44 3300cbe0 2021-01-27 op {NULL, NULL}
45 3300cbe0 2021-01-27 op };
46 3300cbe0 2021-01-27 op
47 62e001b0 2021-03-20 op void
48 62e001b0 2021-03-20 op sandbox_logger_process(void)
49 62e001b0 2021-03-20 op {
50 62e001b0 2021-03-20 op /* to make the linker happy! */
51 62e001b0 2021-03-20 op return;
52 62e001b0 2021-03-20 op }
53 62e001b0 2021-03-20 op
54 3300cbe0 2021-01-27 op int
55 3300cbe0 2021-01-27 op main(int argc, char **argv)
56 3300cbe0 2021-01-27 op {
57 e5d82d94 2022-03-19 op const struct suite *i;
58 3300cbe0 2021-01-27 op int failed;
59 3300cbe0 2021-01-27 op char buf[64]; /* name len */
60 1e7591a9 2021-02-01 op const char *parse_err;
61 3300cbe0 2021-01-27 op
62 3300cbe0 2021-01-27 op failed = 0;
63 3300cbe0 2021-01-27 op for (i = t; i->src != NULL; ++i) {
64 3300cbe0 2021-01-27 op memset(buf, 0, sizeof(buf));
65 cef60084 2021-01-29 op if (!puny_decode(i->src, buf, sizeof(buf), &parse_err)) {
66 cef60084 2021-01-29 op printf("decode: failure with %s: %s\n",
67 cef60084 2021-01-29 op i->src, parse_err);
68 3300cbe0 2021-01-27 op failed = 1;
69 3300cbe0 2021-01-27 op continue;
70 3300cbe0 2021-01-27 op }
71 3300cbe0 2021-01-27 op
72 3300cbe0 2021-01-27 op if (strcmp(buf, i->res)) {
73 3300cbe0 2021-01-27 op printf("ERR: expected \"%s\", got \"%s\"\n",
74 3300cbe0 2021-01-27 op i->res, buf);
75 3300cbe0 2021-01-27 op failed = 1;
76 3300cbe0 2021-01-27 op continue;
77 3300cbe0 2021-01-27 op } else
78 3300cbe0 2021-01-27 op printf("OK: %s => %s\n", i->src, buf);
79 3300cbe0 2021-01-27 op }
80 3300cbe0 2021-01-27 op
81 3300cbe0 2021-01-27 op return failed;
82 3300cbe0 2021-01-27 op }