From 0b70dba7b846a4bbb76d5934a65ff38d37016870 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 8 Apr 2022 02:05:09 +0000 Subject: [PATCH] Unit Test FossilOrigin-Name: 675e4fefe4a49d87caba1b0a44ff9382eb7e5abe4cfe8e8a7863df4fbeccd82a --- test/Makefile | 21 ++++++++++++++++++ test/test.h | 44 +++++++++++++++++++++++++++++++++++++ test/tests | Bin 0 -> 15768 bytes test/unit/main.c | 32 +++++++++++++++++++++++++++ test/unit/mime_multipart.c | 29 ++++++++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 test/Makefile create mode 100644 test/test.h create mode 100755 test/tests create mode 100644 test/unit/main.c create mode 100644 test/unit/mime_multipart.c 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 0000000000000000000000000000000000000000..4e2bbbb220ddf8b797e649e30fadad39bf7bf2b5 GIT binary patch literal 15768 zcmeHOZ){sv6~A_pChJ=>5$jdgvj7)rwTwwbcogP z{SmQAtN^)M>P&mc1hAUrn!6I~NM8krJReq;z>TI_FmewOk+)o##127W6m%TOt3d^3D?PEb$l>@@M3H zVovbWLHV>}0Bl$o?Ywc~*-??K^5K?qzwd25{z2LsAl?84wqumqW8|@Z9C$ReGB$p^#Mn}eyCsh|G)70Y} z;<<&IIg6f7b?I2L==oej!@NZ=e>bJK5DOMP&Q~tJkXhq7%zDM5|98$`<~!(Qz{!A< z0Ve}a2Am8y8E`W2pUr?e^`|;@y5{HGgiyaWtGkUW>eNr`&X*f8w!aA`qv!Xhc=e!Kd{dozYkpubI#Y8DmZj><>M9AH zuK?3nw;wpS>NoeGrSrQWs53P$Aw0UEZ-VYUhIQy(gE2Qc>aXAYj0}(cId7AJACvs; zpF`MsS1rz~=ic3^o?EC=T^H1=clC`B@V4I!=(PpBC*Fz928bgHpHinfF9Jynsl~VT zRqAx-O^`~f;gCxzd<|cyDS^Ue?~h%+egK>?1|(ili%*x-Vqs3b7+Jt0x-qFvM@s6n z7hpjxUVtnd@<2z67tf-(bo{Pim>!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jI+eYS^H0FaSSS$Q|9x! zigA`4xqbWbKSTU3^5b+im71;JD&mq+D`i_@1PIB{Jgw5S|O%AO8JC9rxWr7n6^e(l@yw XGTKB~6EDqgz}E$#;CkI!Y@+xl5u=Gu literal 0 HcmV?d00001 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; +}