4 #include <9p-mixp/srv_addr.h>
6 void dumpaddr(MIXP_SERVER_ADDRESS
* a
, const char* prefix
, const char* uri
)
10 printf("%s FAIL URI = %s\n", prefix
, uri
);
17 printf("%s proto = TCP\n", prefix
);
20 printf("%s proto = UNIX\n", prefix
);
23 printf("%s proto = %d\n", prefix
, a
->proto
);
26 printf("%s addrstr = %s\n", prefix
, a
->addrstr
);
27 printf("%s port = %d\n", prefix
, a
->port
);
28 printf("%s hostname = %s\n", prefix
, a
->hostname
);
30 printf("%s username = %s\n", prefix
, a
->username
);
32 printf("%s key = %s\n", prefix
, a
->key
);
33 printf("%s path = %s\n", prefix
, a
->path
);
36 int test_parse_tcp(const char* str
, const char* want_server
, int want_port
, const char* want_path
)
38 MIXP_SERVER_ADDRESS
* addr
= mixp_srv_addr_parse(str
);
40 printf("[TCP] Testing address: %s\n", str
);
44 fprintf(stderr
,"[test-tcp] could not parse: %s\n", str
);
48 dumpaddr(addr
, "", str
);
50 if (addr
->proto
!= P9_PROTO_TCP
)
51 fprintf(stderr
,"[test-tcp] wrong proto: %d\n", addr
->proto
);
53 if (strcmp(addr
->hostname
, want_server
)!=0)
54 fprintf(stderr
,"[test-tcp] wrong hostname - should be \"%s\"\n", want_server
);
56 if (addr
->port
!= want_port
)
57 fprintf(stderr
,"[test-tcp] wrong port - should be %d\n", want_port
);
59 if (strcmp(addr
->path
, want_path
)!=0)
60 fprintf(stderr
,"[test-tcp] wrong path - should be \"%s\"\n", want_path
);
66 int test_parse_unix(const char* url
, const char* test_path
)
68 MIXP_SERVER_ADDRESS
* addr
= mixp_srv_addr_parse(url
);
70 printf("[UNIX] Testing address: %s\n", url
);
74 fprintf(stderr
,"[test unix] could not parse: %s\n", url
);
78 dumpaddr(addr
, "", url
);
80 if (addr
->proto
!= P9_PROTO_UNIX
)
81 fprintf(stderr
,"[test unix] wrong proto: %d\n", addr
->proto
);
83 if (strcmp(addr
->path
, test_path
)!=0)
84 fprintf(stderr
,"[test unix] pathname mismatch - should be \"%s\"\n", test_path
);
87 fprintf(stderr
,"[test unix] wrong port - should be -1\n");
89 if (strlen(addr
->hostname
))
90 fprintf(stderr
,"[test unix] wrong hostname - should be \"\"");
101 test_parse_tcp ("9p://server:1234/prefix", "server", 1234, "/prefix");
102 test_parse_tcp ("9p:/server:99", "server", 99, "/");
103 test_parse_tcp ("9p:tcp://srv:0023/path/name", "srv", 23, "/path/name");
104 test_parse_unix ("9p:unix://my/local/path", "/my/local/path");
105 test_parse_unix ("9p:unix:/tmp/foo/bar", "/tmp/foo/bar");