diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..b51a52b --- /dev/null +++ b/test/Makefile @@ -0,0 +1,21 @@ +CC ?= cc +MASTODONT_DIR = mastodont-c/ +MASTODONT = $(MASTODONT_DIR)libmastodont.a +CFLAGS += -Wall -I ../$(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers -I/usr/include/ $(shell pkg-config --cflags libcurl libcjson libpcre) +LDFLAGS = -L./../$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre) -lfcgi +TARGET = tests +SRC = unit/main.c +OBJ = $(patsubst %.c,%.o,$(SRC)) + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) -o $(TARGET) $(OBJ) $(LDFLAGS) + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(TARGET) $(OBJ) + +.PHONY: all clean diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..89811e2 --- /dev/null +++ b/test/test.h @@ -0,0 +1,44 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_H +#define TEST_H + +struct test +{ + char* test_name; + int (*callback)(void); +}; + +int iterate_tests(struct test* tests, size_t tests_len) +{ + int status; + + for (size_t i = 0; i < tests_len; ++i) + { + printf("[ Test ] %04ld %s\n", i, tests->test_name); + status = tests->callback(); + printf("[ Test \"%s\" %s! ]\n", tests->test_name, !status ? "passed" : "failed"); + if (!status) + return 1; + } + + return 0; +} + +#endif // TEST_H diff --git a/test/tests b/test/tests new file mode 100755 index 0000000..4e2bbbb Binary files /dev/null and b/test/tests differ diff --git a/test/unit/main.c b/test/unit/main.c new file mode 100644 index 0000000..4349159 --- /dev/null +++ b/test/unit/main.c @@ -0,0 +1,32 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "../test.h" + +// Imports +#include "mime_multipart.c" + +int main() +{ + struct test tests[] = { + { "Mime multipart parser", mime_multipart_test } + }; + return iterate_tests(tests, sizeof(tests)/sizeof(tests[0])); +} diff --git a/test/unit/mime_multipart.c b/test/unit/mime_multipart.c new file mode 100644 index 0000000..4ac91d0 --- /dev/null +++ b/test/unit/mime_multipart.c @@ -0,0 +1,29 @@ +#include "../mine.h" +#define BOUNDARY_CONTENT_T1 "Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266" +#define BOUNDARY_CONTENT_T2 "Content-Type: multipart/form-data; boundary=\"---------------------------9051914041544843365972754266\"" +#define BOUNDARY_RES_T "---------------------------9051914041544843365972754266" + +#define MULTIPART_TEST "-----------------------------9051914041544843365972754266\r\n" +"Content-Disposition: form-data; name=\"text\"\r\n\r\n" + +"text default\r\n" +"-----------------------------9051914041544843365972754266\r\n" +"Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n" +"Content-Type: text/plain\r\n\r\n" + +"Content of a.txt.\r\n\r\n" + +"-----------------------------9051914041544843365972754266\r\n" +"Content-Disposition: form-data; name=\"file2\"; filename\"a.html\"\r\n" +"Content-Type: text/html\r\n\r\n" + +"Content of a.html.\r\n\r\n" + +"-----------------------------9051914041544843365972754266--" + + +int mime_multipart_test(void) +{ + + return 0; +}