summaryrefslogtreecommitdiff
path: root/xc/lib/xtrans/parsetest.c
blob: 018e5e809438186a37a73a81583f8241aa19a1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* $XConsortium$ */

#include <stdio.h>
#include <X11/Xtrans.h>

/*
 * parsetest
 *
 * This test programs will invoke the main parseing routine on a list of
 * addresses to determine if the parsing algorith is working correctly.
 * Of course, this test is only as good as the list of addresses supplied,
 * so the list below should probably continue to grow.
 */

typedef	struct	{
	char	*addr;
	char	*protocol;
	char	*host;
	char	*port;
	} addr;

addr	address[] = {
	{"","local","local",""},
	{":","local","local",""},
	{"/:","local","local",""},
	{"/"THISHOST":","inet",THISHOST,""},
	{"local/"THISHOST":","local",THISHOST,""},
	{"local/:","local","local",""},
	{"inet/"THISHOST":","inet",THISHOST,""},
	{"inet/:","inet","local",""},
	{"::","decnet","local",""},
	{THISHOST"::0","decnet",THISHOST,"0"},
	{"/::","decnet","local",""},
	{"/"THISHOST"::0","decnet",THISHOST,"0"},
	{"decnet/:","decnet","local",""},
	{"decnet/::","decnet","local",""},
	{":0","local","local","0"},
	{":/tmp/.ICE/test","local","local","/tmp/.ICE/test"},
	{"/:0","local","local","0"},
	{"/:/tmp/.ICE/test","local","local","/tmp/.ICE/test"},
	{"pts/:0","pts","local","0"},
	{"pts/:/tmp/.ICE/test","pts","local","/tmp/.ICE/test"},
	{"unix/:0","unix","local","0"},
	{"unix/:/tmp/.ICE/test","unix","local","/tmp/.ICE/test"},
	{"inet/:0","inet","local","0"},
	{"inet/"THISHOST":0","inet",THISHOST,"0"},
	{"tli/:0","tli","local","0"},
	{"tli/"THISHOST":0","tli",THISHOST,"0"},
	{"decnet/"THISHOST":0","decnet",THISHOST,"0"},
	};

#define NUMADDRESS	(sizeof(address)/sizeof(addr))

main()
{
int	i;
char	*protocol;
char	*host;
char	*port;

for(i=0;i<NUMADDRESS;i++)
	{
	if(_TESTTransParseAddress(address[i].addr,&protocol,&host,&port) == 0)
		{
		fprintf(stderr,"%%%%Failed to parse \"%s\"\n", address[i].addr );
		continue;
		}
	fprintf(stderr,"%-20s becomes %s/%s:%s\n",
		address[i].addr, protocol, host, port );
	/*
	 * validate the result against what is expected.
	 */
	if( strcmp(address[i].protocol,protocol) )
		{
		fprintf(stderr,"%%%%Parse error: %s doesn't match %s\n",
						address[i].protocol, protocol );
		}
	if( strcmp(address[i].host,host) )
		{
		fprintf(stderr,"%%%%Parse error: %s doesn't match %s\n",
						address[i].host, host );
		}
	if( strcmp(address[i].port,port) )
		{
		fprintf(stderr,"%%%%Parse error: %s doesn't match %s\n",
						address[i].port, port );
		}
	}
}