Skip to content
Snippets Groups Projects
Commit 9acc29b4 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Fragment (base): added tests

The html generation for both TextFragment and NodeFragment combined is
tested. As the encoding semantics of the TextFragments are neither
defined nor implemented, some tests are marked as XFAIL.
parent 20b53be3
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=17
current_page=36
FILE_NAME_0=139;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2FREADME;0;8
FILE_NAME_1=134;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitignore;0;8
FILE_NAME_2=1751;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8
......@@ -61,16 +61,17 @@ FILE_NAME_28=4105;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_29=901;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Flog.h;0;4
FILE_NAME_30=907;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fmacro.h;0;8
FILE_NAME_31=1078;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fsefht.h;0;8
FILE_NAME_32=1907;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8
FILE_NAME_32=636;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8
FILE_NAME_33=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Fno_test.sh.in;0;8
FILE_NAME_34=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_35=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_36=132483;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_37=4771;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8
FILE_NAME_38=11319;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_39=16715;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_40=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_41=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_36=8232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8
FILE_NAME_37=132483;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_38=4771;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8
FILE_NAME_39=11319;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_40=16715;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_41=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_42=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
[VTE]
last_dir=/home/jonathan/Documents/projects/prgm/internet/web/SeFHT/tests
......
......@@ -14,10 +14,14 @@ check_PROGRAMS =
check_PROGRAMS += sefht_attr_test
check_PROGRAMS += sefht_cms_test
check_PROGRAMS += sefht_data_test
check_PROGRAMS += sefht_fragment_test
check_PROGRAMS += sefht_node_fragment_test
check_PROGRAMS += sefht_text_fragment_test
check_PROGRAMS += sefht_text_test
XFAIL_TESTS =
XFAIL_TESTS += sefht_fragment_test
endif
TESTS = $(check_SCRIPTS) $(check_PROGRAMS)
......@@ -46,6 +50,16 @@ sefht_data_test_LDADD =
sefht_data_test_LDADD += $(OBJECT_PREFIX)validator.o
sefht_data_test_LDADD += $(LDADD)
sefht_fragment_test_SOURCES = test_fragment.c
sefht_fragment_test_LDADD =
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)data.o
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)fragment.o
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)node_fragment.o
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)text_fragment.o
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)text.o
sefht_fragment_test_LDADD += $(OBJECT_PREFIX)validator.o
sefht_fragment_test_LDADD += $(LDADD)
sefht_node_fragment_test_SOURCES = test_node_fragment.c
sefht_node_fragment_test_LDADD =
sefht_node_fragment_test_LDADD += $(OBJECT_PREFIX)attr.o
......
/*
* test_fragment.c
*
* Copyright 2023 Jonathan Schöbel <jonathan@xn--schbel-yxa.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <check.h>
#include <stdbool.h>
#include <stdlib.h>
#include "macro.h"
#include "status.h"
#include "node_fragment.h"
#include "text_fragment.h"
#include "fragment_class.c"
START_TEST(test_fragment_type)
{
SH_Data * data;
struct SH_Fragment * node_fragment;
struct SH_Fragment * text_fragment;
enum SH_FRAGMENT_TYPE type;
/* setup */
data = SH_Data_new (NULL);
ck_assert_ptr_ne (NULL, data);
node_fragment = SH_NodeFragment_new ("html", data, NULL);
ck_assert_ptr_ne (NULL, node_fragment);
text_fragment = SH_TextFragment_new (data, NULL);
ck_assert_ptr_ne (NULL, text_fragment);
/* test */
type = get_type (node_fragment);
ck_assert_int_eq (NODE, type);
type = get_type (text_fragment);
ck_assert_int_eq (TEXT, type);
/* cleanup */
SH_Fragment_free (node_fragment);
SH_Fragment_free (text_fragment);
SH_Data_free (data);
}
END_TEST
START_TEST(test_fragment_html_inline_no_status)
{
SH_NodeFragment * parent;
SH_Fragment * child;
SH_Fragment * child_text;
SH_Data * data;
SH_Text * text;
char * string;
size_t length;
bool result;
/* setup */
data = SH_Data_new (NULL);
ck_assert_ptr_ne (NULL, data);
parent = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
NULL);
ck_assert_ptr_ne (NULL, parent);
result = SH_NodeFragment_append_attr_new (parent,
"lang", "de",
NULL);
ck_assert_int_eq (TRUE, result);
child = SH_NodeFragment_new ("body", data, NULL);
ck_assert_ptr_ne (NULL, child);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"id", "body",
NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"attr", NULL, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child (parent, child, NULL);
ck_assert_int_eq (TRUE, result);
child_text = SH_TextFragment_new (data, NULL);
ck_assert_ptr_ne (NULL, child_text);
result = SH_TextFragment_append_string ((SH_TextFragment *)child_text,
"Lorem ipsum ...", NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child ((SH_NodeFragment *)child,
child_text, NULL);
ck_assert_int_eq (TRUE, result);
/* test */
text = SH_NodeFragment_to_html (parent, INLINE,
0, 1, INDENT_TEXT,
NULL);
ck_assert_ptr_ne (NULL, text);
string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
ck_assert_str_eq (string, "<html lang=\"de\">"
"<body id=\"body\" attr>"
"Lorem ipsum ..."
"</body>"
"</html>");
/* cleanup */
free (string);
SH_Text_free (text);
SH_NodeFragment_free (parent);
SH_Data_free (data);
}
END_TEST
START_TEST(test_fragment_html_inline_with_status)
{
struct SH_Status status;
SH_NodeFragment * parent;
SH_Fragment * child;
SH_Fragment * child_text;
SH_Data * data;
SH_Text * text;
char * string;
size_t length;
bool result;
/* setup */
data = SH_Data_new (NULL);
ck_assert_ptr_ne (NULL, data);
parent = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
NULL);
ck_assert_ptr_ne (NULL, parent);
result = SH_NodeFragment_append_attr_new (parent,
"lang", "de",
NULL);
ck_assert_int_eq (TRUE, result);
child = SH_NodeFragment_new ("body", data, NULL);
ck_assert_ptr_ne (NULL, child);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"id", "body",
NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"attr", NULL, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child (parent, child, NULL);
ck_assert_int_eq (TRUE, result);
child_text = SH_TextFragment_new (data, NULL);
ck_assert_ptr_ne (NULL, child_text);
result = SH_TextFragment_append_string ((SH_TextFragment *)child_text,
"Lorem ipsum ...", NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child ((SH_NodeFragment *)child,
child_text, NULL);
ck_assert_int_eq (TRUE, result);
/* test */
_status_preinit (status);
text = SH_NodeFragment_to_html (parent, INLINE,
0, 1, INDENT_TEXT,
&status);
ck_assert_ptr_ne (NULL, text);
ck_assert_int_eq (status.status, SUCCESS);
string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
ck_assert_str_eq (string, "<html lang=\"de\">"
"<body id=\"body\" attr>"
"Lorem ipsum ..."
"</body>"
"</html>");
/* cleanup */
free (string);
SH_Text_free (text);
SH_NodeFragment_free (parent);
SH_Data_free (data);
}
END_TEST
START_TEST(test_fragment_html_wrap_no_status)
{
SH_NodeFragment * parent;
SH_Fragment * child;
SH_Fragment * child_text;
SH_Data * data;
SH_Text * text;
char * string;
size_t length;
bool result;
/* setup */
data = SH_Data_new (NULL);
ck_assert_ptr_ne (NULL, data);
parent = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
NULL);
ck_assert_ptr_ne (NULL, parent);
result = SH_NodeFragment_append_attr_new (parent,
"lang", "de",
NULL);
ck_assert_int_eq (TRUE, result);
child = SH_NodeFragment_new ("body", data, NULL);
ck_assert_ptr_ne (NULL, child);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"id", "body",
NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"attr", NULL, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child (parent, child, NULL);
ck_assert_int_eq (TRUE, result);
child_text = SH_TextFragment_new (data, NULL);
ck_assert_ptr_ne (NULL, child_text);
result = SH_TextFragment_append_string ((SH_TextFragment *)child_text,
"Lorem ipsum ...\n", NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child ((SH_NodeFragment *)child,
child_text, NULL);
ck_assert_int_eq (TRUE, result);
/* test */
text = SH_NodeFragment_to_html (parent, WRAP,
0, 1, INDENT_TEXT,
NULL);
ck_assert_ptr_ne (NULL, text);
string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
ck_assert_str_eq (string, "<html lang=\"de\">\n"
"\t<body id=\"body\" attr>\n"
"\t\tLorem ipsum ...\n"
"\t</body>\n"
"</html>\n");
/* cleanup */
free (string);
SH_Text_free (text);
SH_NodeFragment_free (parent);
SH_Data_free (data);
}
END_TEST
START_TEST(test_fragment_html_wrap_with_status)
{
struct SH_Status status;
SH_NodeFragment * parent;
SH_Fragment * child;
SH_Fragment * child_text;
SH_Data * data;
SH_Text * text;
char * string;
size_t length;
bool result;
/* setup */
data = SH_Data_new (NULL);
ck_assert_ptr_ne (NULL, data);
parent = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
NULL);
ck_assert_ptr_ne (NULL, parent);
result = SH_NodeFragment_append_attr_new (parent,
"lang", "de",
NULL);
ck_assert_int_eq (TRUE, result);
child = SH_NodeFragment_new ("body", data, NULL);
ck_assert_ptr_ne (NULL, child);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"id", "body",
NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child,
"attr", NULL, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child (parent, child, NULL);
ck_assert_int_eq (TRUE, result);
child_text = SH_TextFragment_new (data, NULL);
ck_assert_ptr_ne (NULL, child_text);
result = SH_TextFragment_append_string ((SH_TextFragment *)child_text,
"Lorem ipsum ...\n", NULL);
ck_assert_int_eq (TRUE, result);
result = SH_NodeFragment_append_child ((SH_NodeFragment *)child,
child_text, NULL);
ck_assert_int_eq (TRUE, result);
/* test */
_status_preinit (status);
text = SH_NodeFragment_to_html (parent, WRAP,
0, 1, INDENT_TEXT,
&status);
ck_assert_ptr_ne (NULL, text);
ck_assert_int_eq (status.status, SUCCESS);
string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
ck_assert_str_eq (string, "<html lang=\"de\">\n"
"\t<body id=\"body\" attr>\n"
"\t\tLorem ipsum ...\n"
"\t</body>\n"
"</html>\n");
/* cleanup */
free (string);
SH_Text_free (text);
SH_NodeFragment_free (parent);
SH_Data_free (data);
}
END_TEST
Suite * test_suite (void)
{
Suite *s;
TCase *tc_core;
s = suite_create ("Testsuite SeFHT Fragment");
/* Core test case */
tc_core = tcase_create ("Core");
tcase_add_test (tc_core, test_fragment_type);
tcase_add_test (tc_core, test_fragment_html_inline_no_status);
tcase_add_test (tc_core, test_fragment_html_inline_with_status);
tcase_add_test (tc_core, test_fragment_html_wrap_no_status);
tcase_add_test (tc_core, test_fragment_html_wrap_with_status);
suite_add_tcase (s, tc_core);
return s;
}
int main (void)
{
int number_failed;
Suite *s;
SRunner *sr;
s = test_suite ();
sr = srunner_create (s);
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment