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