add url test code.

This commit is contained in:
Kelvin Sherlock 2012-04-06 20:14:06 -04:00
parent 5b1c6f48f5
commit 3c51fb869c
2 changed files with 77 additions and 0 deletions

View File

@ -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
View 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;
}