introduce the unit tests file
This commit is contained in:
parent
9cca2408c3
commit
4496e744e8
7
Makefile
7
Makefile
|
@ -13,6 +13,7 @@ all: vger
|
|||
|
||||
clean:
|
||||
find . \( -name vger -o \
|
||||
-name unit_test -o \
|
||||
-name "*.o" -o \
|
||||
-name "*.core" \) \
|
||||
-delete
|
||||
|
@ -24,5 +25,9 @@ install: vger
|
|||
install -o root -g wheel vger ${PREFIX}/bin/
|
||||
install -o root -g wheel vger.8 ${PREFIX}/man/man8/
|
||||
|
||||
test: vger
|
||||
unit_test: tests.c vger.o
|
||||
${CC} ${CFLAGS} -o $@ vger.o tests.c mimes.o utils.o
|
||||
|
||||
test: vger unit_test
|
||||
./unit_test
|
||||
cd tests && sh test.sh
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vger.h"
|
||||
|
||||
// to test
|
||||
void test_status(void);
|
||||
void test_status_error(void);
|
||||
void test_uridecode(char*, const int);
|
||||
|
||||
|
||||
void
|
||||
test_uridecode(char *str, const int result)
|
||||
{
|
||||
char reference[GEMINI_REQUEST_MAX] = {'\0'};
|
||||
strlcpy(reference, str, sizeof(reference));
|
||||
uridecode(str);
|
||||
if (strncmp(reference, str, strlen(str)) != result)
|
||||
{
|
||||
printf("uridecode error\n");
|
||||
printf("Strings should be %s\n", (result == 0) ? "identical" : "different");
|
||||
printf("passed %s\n", reference);
|
||||
printf("got %s\n", str);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_status(void)
|
||||
{
|
||||
status(20, "text/gemini");
|
||||
}
|
||||
|
||||
void
|
||||
test_status_error(void)
|
||||
{
|
||||
status_error(51, "file not found");
|
||||
status_error(50, "Forbidden path");
|
||||
status_error(50, "Internal server error");
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
test_status_error();
|
||||
test_status();
|
||||
//test_uridecode("host.name", 0);
|
||||
//test_uridecode("host.name/percent%25-encode%3.gmi", 1);
|
||||
return(0);
|
||||
}
|
Loading…
Reference in New Issue