From 08f6066838dcb46712753fd2e16f5e922682b48e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonathan=20Sch=C3=B6bel?= <jonathan@xn--schbel-yxa.info>
Date: Mon, 5 Jun 2023 19:50:14 +0200
Subject: [PATCH] NodeFragment: restructered html generation test

---
 sefht.geany                |   4 +-
 tests/test_node_fragment.c | 182 ++++++++++++++++++++++++++++++-------
 2 files changed, 150 insertions(+), 36 deletions(-)

diff --git a/sefht.geany b/sefht.geany
index e7f7bad..264650f 100644
--- a/sefht.geany
+++ b/sefht.geany
@@ -28,7 +28,7 @@ long_line_behaviour=1
 long_line_column=72
 
 [files]
-current_page=14
+current_page=34
 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
@@ -63,7 +63,7 @@ FILE_NAME_30=555;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2
 FILE_NAME_31=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_32=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
 FILE_NAME_33=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
-FILE_NAME_34=109525;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
+FILE_NAME_34=114262;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
 FILE_NAME_35=15195;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
 FILE_NAME_36=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
 FILE_NAME_37=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
diff --git a/tests/test_node_fragment.c b/tests/test_node_fragment.c
index 7aa1e3b..be89c29 100644
--- a/tests/test_node_fragment.c
+++ b/tests/test_node_fragment.c
@@ -3637,67 +3637,178 @@ START_TEST(test_node_fragment_child_remove_pop_with_status)
 }
 END_TEST
 
-START_TEST(test_node_fragment_html)
+START_TEST(test_node_fragment_html_inline_no_status)
 {
-	struct SH_Status status;
-	struct SH_Fragment * fragment1;
-	struct SH_Fragment * fragment2;
+	struct SH_NodeFragment * fragment;
+	struct SH_Fragment * child;
 	struct SH_Data * data;
 	struct SH_Text * text;
 	char * string;
 	size_t length;
+	bool result;
 
+	/* setup */
 	data = SH_Data_new (NULL);
+	ck_assert_ptr_ne (NULL, data);
 
-	/* no error */
-	fragment1 = SH_NodeFragment_new ("html", data, NULL);
-	fragment2 = SH_NodeFragment_new ("body", data, NULL);
-	SH_NodeFragment_append_child (((struct SH_NodeFragment *) fragment1),
-				      fragment2, NULL);
+	fragment = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
+	                                                    NULL);
+	ck_assert_ptr_ne (NULL, fragment);
+
+	child = SH_NodeFragment_new ("body", data, NULL);
+	ck_assert_ptr_ne (NULL, child);
+
+	result = SH_NodeFragment_append_child (fragment, child, NULL);
+	ck_assert_int_eq (TRUE, result);
+
+	/* test */
+	text = SH_NodeFragment_to_html (fragment, INLINE,
+	                                0, 1, INDENT_TEXT,
+	                                NULL);
+	ck_assert_ptr_ne (NULL, text);
 
-	text = SH_Fragment_to_html (fragment1, INLINE, 0, 1, INDENT_TEXT,
-				    NULL);
 	string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
 	ck_assert_str_eq (string, "<html><body></body></html>");
-	free (string);
-	SH_Text_free (text);
 
-	text = SH_Fragment_to_html (fragment1, WRAP, 0, 1, INDENT_TEXT,
-				    NULL);
-	string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
-	ck_assert_str_eq (string,
-			  "<html>\n\t<body>\n\t</body>\n</html>\n");
+	/* cleanup */
 	free (string);
 	SH_Text_free (text);
+	SH_NodeFragment_free (fragment);
+	SH_Data_free (data);
+}
+END_TEST
+
+START_TEST(test_node_fragment_html_inline_with_status)
+{
+	struct SH_Status status;
+	struct SH_NodeFragment * fragment;
+	struct SH_Fragment * child;
+	struct SH_Data * data;
+	struct SH_Text * text;
+	char * string;
+	size_t length;
+	bool result;
+
+	/* setup */
+	data = SH_Data_new (NULL);
+	ck_assert_ptr_ne (NULL, data);
 
-	SH_Fragment_free (fragment1);
+	fragment = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
+	                                                    NULL);
+	ck_assert_ptr_ne (NULL, fragment);
 
-	/* error */
-	fragment1 = SH_NodeFragment_new ("html", data, NULL);
-	fragment2 = SH_NodeFragment_new ("body", data, NULL);
-	SH_NodeFragment_append_child (((struct SH_NodeFragment *) fragment1),
-				      fragment2, NULL);
+	child = SH_NodeFragment_new ("body", data, NULL);
+	ck_assert_ptr_ne (NULL, child);
+
+	result = SH_NodeFragment_append_child (fragment, child, NULL);
+	ck_assert_int_eq (TRUE, result);
 
+	/* test */
 	_status_preinit (status);
-	text = SH_Fragment_to_html (fragment1, INLINE, 0, 1, INDENT_TEXT,
-				    &status);
+	text = SH_NodeFragment_to_html (fragment, 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><body></body></html>");
+
+	/* cleanup */
 	free (string);
 	SH_Text_free (text);
-	ck_assert_int_eq (status.status, SUCCESS);
+	SH_NodeFragment_free (fragment);
+	SH_Data_free (data);
+}
+END_TEST
+
+START_TEST(test_node_fragment_html_wrap_no_status)
+{
+	struct SH_NodeFragment * fragment;
+	struct SH_Fragment * child;
+	struct SH_Data * data;
+	struct SH_Text * text;
+	char * string;
+	size_t length;
+	bool result;
+
+	/* setup */
+	data = SH_Data_new (NULL);
+	ck_assert_ptr_ne (NULL, data);
+
+	fragment = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
+	                                                    NULL);
+	ck_assert_ptr_ne (NULL, fragment);
+
+	child = SH_NodeFragment_new ("body", data, NULL);
+	ck_assert_ptr_ne (NULL, child);
+
+	result = SH_NodeFragment_append_child (fragment, child, NULL);
+	ck_assert_int_eq (TRUE, result);
+
+	/* test */
+	text = SH_NodeFragment_to_html (fragment, WRAP,
+	                                0, 1, INDENT_TEXT,
+	                                NULL);
+	ck_assert_ptr_ne (NULL, text);
 
-	_status_preinit (status);
-	text = SH_Fragment_to_html (fragment1, WRAP, 0, 1, INDENT_TEXT,
-				    &status);
 	string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
-	ck_assert_str_eq (string,
-			  "<html>\n\t<body>\n\t</body>\n</html>\n");
+	ck_assert_str_eq (string, "<html>\n"
+	                          "\t<body>\n"
+	                          "\t</body>\n"
+	                          "</html>\n");
+
+	/* cleanup */
 	free (string);
 	SH_Text_free (text);
+	SH_NodeFragment_free (fragment);
+	SH_Data_free (data);
+}
+END_TEST
+
+START_TEST(test_node_fragment_html_wrap_with_status)
+{
+	struct SH_Status status;
+	struct SH_NodeFragment * fragment;
+	struct SH_Fragment * child;
+	struct SH_Data * data;
+	struct SH_Text * text;
+	char * string;
+	size_t length;
+	bool result;
+
+	/* setup */
+	data = SH_Data_new (NULL);
+	ck_assert_ptr_ne (NULL, data);
+
+	fragment = (SH_NodeFragment *)SH_NodeFragment_new ("html", data,
+	                                                    NULL);
+	ck_assert_ptr_ne (NULL, fragment);
+
+	child = SH_NodeFragment_new ("body", data, NULL);
+	ck_assert_ptr_ne (NULL, child);
+
+	result = SH_NodeFragment_append_child (fragment, child, NULL);
+	ck_assert_int_eq (TRUE, result);
+
+	/* test */
+	_status_preinit (status);
+	text = SH_NodeFragment_to_html (fragment, WRAP,
+	                                0, 1, INDENT_TEXT,
+	                                &status);
+	ck_assert_ptr_ne (NULL, text);
 	ck_assert_int_eq (status.status, SUCCESS);
 
-	SH_Fragment_free (fragment1);
+	string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL);
+	ck_assert_str_eq (string, "<html>\n"
+	                          "\t<body>\n"
+	                          "\t</body>\n"
+	                          "</html>\n");
+
+	/* cleanup */
+	free (string);
+	SH_Text_free (text);
+	SH_NodeFragment_free (fragment);
 	SH_Data_free (data);
 }
 END_TEST
@@ -3771,7 +3882,10 @@ Suite * fragment_suite (void)
 	tcase_add_test (tc_core, test_node_fragment_child_remove_delete_with_status);
 	tcase_add_test (tc_core, test_node_fragment_child_remove_pop_no_status);
 	tcase_add_test (tc_core, test_node_fragment_child_remove_pop_with_status);
-	tcase_add_test (tc_core, test_node_fragment_html);
+	tcase_add_test (tc_core, test_node_fragment_html_inline_no_status);
+	tcase_add_test (tc_core, test_node_fragment_html_inline_with_status);
+	tcase_add_test (tc_core, test_node_fragment_html_wrap_no_status);
+	tcase_add_test (tc_core, test_node_fragment_html_wrap_with_status);
 	suite_add_tcase (s, tc_core);
 
 	return s;
-- 
GitLab