diff --git a/Makefile b/Makefile index ef064c6..2d6ba6c 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ SRC = src/xmlparser.c \ OBJ = $(SRC:%.c=%.o) -TESTS = tests/test_basics.c +TESTS = tests/test_basics.c \ + tests/tests_realxml.c TEST_MAIN = tests/test_main.c diff --git a/src/xmlparser.c b/src/xmlparser.c index 25d8743..1346b61 100644 --- a/src/xmlparser.c +++ b/src/xmlparser.c @@ -32,6 +32,7 @@ int xml_handle_prolog(char **nodestr) free(strconst); return (-1); } + *nodestr += 2; return (0); } @@ -71,9 +72,10 @@ node *xmlparse(char *path) if (fd < 0) return (NULL); fstat(fd, &stats); - nodestr = malloc(stats.st_size); + nodestr = malloc(stats.st_size + 1); if (nodestr) { count = read(fd, nodestr, stats.st_size); + nodestr[stats.st_size + 1] = '\0'; if (count == stats.st_size) n = xml_parsestr(nodestr); } diff --git a/tests/xmltest.txt b/tests/testprolog.txt similarity index 100% rename from tests/xmltest.txt rename to tests/testprolog.txt diff --git a/tests/tests_realxml.c b/tests/tests_realxml.c index e69de29..cc66597 100644 --- a/tests/tests_realxml.c +++ b/tests/tests_realxml.c @@ -0,0 +1,23 @@ +/* +** EPITECH PROJECT, 2019 +** xmlparser +** File description: +** tests_realxml +*/ + +#include "xml.h" +#include +#include + +Test(xml, complete) +{ + node *n = xmlparse("tests/testprolog.txt"); + + cr_assert_str_eq(n->name, "yes"); + cr_assert_eq(n->next, NULL); + cr_assert_eq(n->properties, NULL); + cr_assert_str_eq(n->child->name, "nop"); + cr_assert_eq(n->child->child, NULL); + cr_assert_eq(n->child->properties, NULL); + cr_assert_eq(n->child->next, NULL); +} \ No newline at end of file