mirror of
https://github.com/ksherlock/gopher.git
synced 2025-03-20 04:31:16 +00:00
add url test code.
This commit is contained in:
parent
5b1c6f48f5
commit
3c51fb869c
12
makefile.mk
12
makefile.mk
@ -4,12 +4,24 @@ OBJS = gopher.o url.o connection.o
|
||||
gopher: $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
|
||||
|
||||
utest: utest.o url.o
|
||||
$(CC) $(LDFLAGS) utest.o url.o -o $@
|
||||
|
||||
dtest: dtest.o dictionary.o
|
||||
$(CC) $(LDFLAGS) dtest.o dictionary.o -o $@
|
||||
|
||||
|
||||
gopher.o: gopher.c url.h connection.h
|
||||
url.o: url.c url.h
|
||||
connection.o: connection.c connection.h
|
||||
data.o: data.c data.h
|
||||
dictionary.o: dictionary.c dictionary.h
|
||||
|
||||
# tests
|
||||
utest.o: utest.c
|
||||
dtest.o: dtest.c
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.root
|
||||
|
||||
|
65
utest.c
Normal file
65
utest.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "url.h"
|
||||
|
||||
void test(const char *url)
|
||||
{
|
||||
URLComponents data;
|
||||
int ok;
|
||||
|
||||
char *buffer;
|
||||
buffer = strdup(url); // enough space.
|
||||
|
||||
if (!url || !*url) return;
|
||||
|
||||
ok = ParseURL(url, strlen(url), &data);
|
||||
|
||||
printf("%s (%s)\n", url, ok ? "ok" : "error");
|
||||
|
||||
printf(" schemeType: %d\n", data.schemeType);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentScheme, buffer);
|
||||
printf(" scheme: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentUser, buffer);
|
||||
printf(" username: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentPassword, buffer);
|
||||
printf(" password: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentHost, buffer);
|
||||
printf(" host: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentPort, buffer);
|
||||
printf(" port: %s [%d]\n", buffer, data.portNumber);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentPath, buffer);
|
||||
printf(" path: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentParams, buffer);
|
||||
printf(" params: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentQuery, buffer);
|
||||
printf(" query: %s\n", buffer);
|
||||
|
||||
URLComponentGetC(url, &data, URLComponentFragment, buffer);
|
||||
printf(" fragment: %s\n", buffer);
|
||||
|
||||
free(buffer);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; ++i)
|
||||
{
|
||||
test(argv[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user