forked from mirrors/treebird
Unit Test
FossilOrigin-Name: 675e4fefe4a49d87caba1b0a44ff9382eb7e5abe4cfe8e8a7863df4fbeccd82a
This commit is contained in:
parent
c5c5ea7b72
commit
0b70dba7b8
5 changed files with 126 additions and 0 deletions
21
test/Makefile
Normal file
21
test/Makefile
Normal file
|
@ -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
|
44
test/test.h
Normal file
44
test/test.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
BIN
test/tests
Executable file
BIN
test/tests
Executable file
Binary file not shown.
32
test/unit/main.c
Normal file
32
test/unit/main.c
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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]));
|
||||
}
|
29
test/unit/mime_multipart.c
Normal file
29
test/unit/mime_multipart.c
Normal file
|
@ -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"
|
||||
|
||||
"<!DOCTYPE html><title>Content of a.html.</title>\r\n\r\n"
|
||||
|
||||
"-----------------------------9051914041544843365972754266--"
|
||||
|
||||
|
||||
int mime_multipart_test(void)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue