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 319b7fa9 2021-02-08 op /* to make the linker happy */
23 319b7fa9 2021-02-08 op struct conf conf;
24 bc99d868 2021-03-19 op struct imsgbuf logibuf, servibuf[PROC_MAX];
25 319b7fa9 2021-02-08 op
26 e5d82d94 2022-03-19 op const struct suite {
27 3300cbe0 2021-01-27 op const char *src;
28 3300cbe0 2021-01-27 op const char *res;
29 3300cbe0 2021-01-27 op } t[] = {
30 3300cbe0 2021-01-27 op {"foo", "foo"},
31 44ee1bac 2021-01-27 op {"h.n", "h.n"},
32 3300cbe0 2021-01-27 op {"xn-invalid", "xn-invalid"},
33 3300cbe0 2021-01-27 op {"naïve", "naïve"},
34 3300cbe0 2021-01-27 op {"xn--8ca", "è"},
35 3300cbe0 2021-01-27 op {"xn--caff-8oa", "caffè"},
36 3300cbe0 2021-01-27 op {"xn--nave-6pa", "naïve"},
37 3300cbe0 2021-01-27 op {"xn--e-0mbbc", "τeστ"},
38 3300cbe0 2021-01-27 op {"xn--8ca67lbac", "τèστ"},
39 3300cbe0 2021-01-27 op {"xn--28j2a3ar1p", "こんにちは"},
40 3300cbe0 2021-01-27 op {"xn--hello--ur7iy09x", "hello-世界"},
41 3300cbe0 2021-01-27 op {"xn--hi--hi-rr7iy09x", "hi-世界-hi"},
42 3300cbe0 2021-01-27 op {"xn--caf-8la.foo.org", "cafè.foo.org"},
43 3300cbe0 2021-01-27 op /* 3 bytes */
44 3300cbe0 2021-01-27 op {"xn--j6h", "♨"},
45 3300cbe0 2021-01-27 op /* 4 bytes */
46 3300cbe0 2021-01-27 op {"xn--x73l", "𩸽"},
47 3300cbe0 2021-01-27 op {"xn--x73laaa", "𩸽𩸽𩸽𩸽"},
48 3300cbe0 2021-01-27 op {NULL, NULL}
49 3300cbe0 2021-01-27 op };
50 3300cbe0 2021-01-27 op
51 62e001b0 2021-03-20 op void
52 62e001b0 2021-03-20 op sandbox_logger_process(void)
53 62e001b0 2021-03-20 op {
54 62e001b0 2021-03-20 op /* to make the linker happy! */
55 62e001b0 2021-03-20 op return;
56 62e001b0 2021-03-20 op }
57 62e001b0 2021-03-20 op
58 3300cbe0 2021-01-27 op int
59 3300cbe0 2021-01-27 op main(int argc, char **argv)
60 3300cbe0 2021-01-27 op {
61 e5d82d94 2022-03-19 op const struct suite *i;
62 3300cbe0 2021-01-27 op int failed;
63 3300cbe0 2021-01-27 op char buf[64]; /* name len */
64 1e7591a9 2021-02-01 op const char *parse_err;
65 3300cbe0 2021-01-27 op
66 3300cbe0 2021-01-27 op failed = 0;
67 3300cbe0 2021-01-27 op for (i = t; i->src != NULL; ++i) {
68 3300cbe0 2021-01-27 op memset(buf, 0, sizeof(buf));
69 cef60084 2021-01-29 op if (!puny_decode(i->src, buf, sizeof(buf), &parse_err)) {
70 cef60084 2021-01-29 op printf("decode: failure with %s: %s\n",
71 cef60084 2021-01-29 op i->src, parse_err);
72 3300cbe0 2021-01-27 op failed = 1;
73 3300cbe0 2021-01-27 op continue;
74 3300cbe0 2021-01-27 op }
75 3300cbe0 2021-01-27 op
76 3300cbe0 2021-01-27 op if (strcmp(buf, i->res)) {
77 3300cbe0 2021-01-27 op printf("ERR: expected \"%s\", got \"%s\"\n",
78 3300cbe0 2021-01-27 op i->res, buf);
79 3300cbe0 2021-01-27 op failed = 1;
80 3300cbe0 2021-01-27 op continue;
81 3300cbe0 2021-01-27 op } else
82 3300cbe0 2021-01-27 op printf("OK: %s => %s\n", i->src, buf);
83 3300cbe0 2021-01-27 op }
84 3300cbe0 2021-01-27 op
85 3300cbe0 2021-01-27 op return failed;
86 3300cbe0 2021-01-27 op }