diff --git a/sefht.geany b/sefht.geany index 49c6923c7ce0a37ffa07a5d1931e9b77f58b9cd8..bac865b9c62c1923cb51aeed5a7ad04481fa34c9 100644 --- a/sefht.geany +++ b/sefht.geany @@ -28,7 +28,7 @@ long_line_behaviour=1 long_line_column=72 [files] -current_page=9 +current_page=47 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=1737;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8 @@ -43,7 +43,7 @@ FILE_NAME_10=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprg FILE_NAME_11=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment.h;0;8 FILE_NAME_12=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_data.c;0;8 FILE_NAME_13=29;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8 -FILE_NAME_14=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8 +FILE_NAME_14=4785;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8 FILE_NAME_15=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8 FILE_NAME_16=6328;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.c;0;8 FILE_NAME_17=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.h;0;8 @@ -76,7 +76,7 @@ FILE_NAME_43=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp FILE_NAME_44=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8 FILE_NAME_45=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8 FILE_NAME_46=8232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8 -FILE_NAME_47=33;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 +FILE_NAME_47=4446;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 FILE_NAME_48=5714;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8 FILE_NAME_49=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8 FILE_NAME_50=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8 diff --git a/src/lib/sefht/node_fragment.c b/src/lib/sefht/node_fragment.c index f87f179cb8aaed05ff40ae2bbd96ee78e93b838f..0f98972d10a2fcb92f07db5c4fd8697fcf884f25 100644 --- a/src/lib/sefht/node_fragment.c +++ b/src/lib/sefht/node_fragment.c @@ -152,6 +152,14 @@ SH_NodeFragment_new (const char * tag, { struct SH_NodeFragment * fragment; + if (!SH_Data_check_tag (data, tag)) + { + set_status_ (status, E_VALUE, 2, strlen (tag), + "Tag %s isn't valid.\n", tag); + + return NULL; + } + fragment = malloc (sizeof (struct SH_NodeFragment)); if (fragment == NULL) { @@ -203,6 +211,14 @@ SH_NodeFragment_raw_new (/*@only@*/ char * tag, { struct SH_NodeFragment * fragment; + if (!SH_Data_check_tag (data, tag)) + { + set_status_ (status, E_VALUE, 2, strlen (tag), + "Tag %s isn't valid.\n", tag); + + return NULL; + } + fragment = malloc (sizeof (struct SH_NodeFragment)); if (fragment == NULL) { diff --git a/tests/test_node_fragment.c b/tests/test_node_fragment.c index 5d7f22f55d85944337ea87b8d6743069f72afb31..d64afc437c98dcfbb0edb43f7f7919591a1a60dc 100644 --- a/tests/test_node_fragment.c +++ b/tests/test_node_fragment.c @@ -31,18 +31,36 @@ #include "node_fragment.c" +/* TODO: keep in sync with data.c + * TODO: remove */ +struct SH_Data +{ + SH_Validator * validator; +}; START_TEST(test_node_fragment_no_status) { struct SH_NodeFragment * fragment; SH_Data * data; const char * tag = "tag"; + const char * no_tag = "no_tag"; + bool result; + /* setup */ data = SH_Data_new (NULL); + ck_assert_ptr_ne (NULL, data); + + result = SH_Validator_register_tag (data->validator, tag, NULL); + ck_assert_int_eq (TRUE, result); + /* test - invalid tag */ fragment = (struct SH_NodeFragment *) - SH_NodeFragment_new (tag, data, NULL); + SH_NodeFragment_new (no_tag, data, NULL); + ck_assert_ptr_eq (NULL, fragment); + /* test - valid tag */ + fragment = (struct SH_NodeFragment *) + SH_NodeFragment_new (tag, data, NULL); ck_assert_ptr_ne (NULL, fragment); ck_assert_ptr_eq (NULL, fragment->base.parent); @@ -54,8 +72,8 @@ START_TEST(test_node_fragment_no_status) ck_assert_int_eq (0, fragment->child_n); ck_assert_int_eq (0, fragment->child_s); + /* cleanup */ SH_NodeFragment_free (fragment); - SH_Data_free (data); } END_TEST @@ -66,13 +84,27 @@ START_TEST(test_node_fragment_with_status) struct SH_NodeFragment * fragment; SH_Data * data; const char * tag = "tag"; + const char * no_tag = "no_tag"; + bool result; + /* setup */ data = SH_Data_new (NULL); + ck_assert_ptr_ne (NULL, data); + + result = SH_Validator_register_tag (data->validator, tag, NULL); + ck_assert_int_eq (TRUE, result); + /* test - invalid tag */ _status_preinit (status); fragment = (struct SH_NodeFragment *) - SH_NodeFragment_new (tag, data, &status); + SH_NodeFragment_new (no_tag, data, &status); + ck_assert_ptr_eq (NULL, fragment); + ck_assert_int_eq (E_VALUE, status.status); + /* test - valid tag */ + _status_preinit (status); + fragment = (struct SH_NodeFragment *) + SH_NodeFragment_new (tag, data, &status); ck_assert_ptr_ne (NULL, fragment); ck_assert (succeed (&status)); @@ -85,8 +117,8 @@ START_TEST(test_node_fragment_with_status) ck_assert_int_eq (0, fragment->child_n); ck_assert_int_eq (0, fragment->child_s); + /* cleanup */ SH_NodeFragment_free (fragment); - SH_Data_free (data); } END_TEST @@ -96,12 +128,24 @@ START_TEST(test_node_fragment_raw_no_status) struct SH_NodeFragment * fragment; SH_Data * data; char * tag = strdup ("tag"); + char * no_tag = strdup ("no_tag"); + bool result; + /* setup */ data = SH_Data_new (NULL); + ck_assert_ptr_ne (NULL, data); + result = SH_Validator_register_tag (data->validator, tag, NULL); + ck_assert_int_eq (TRUE, result); + + /* test - invalid tag */ fragment = (struct SH_NodeFragment *) - SH_NodeFragment_raw_new (tag, data, NULL); + SH_NodeFragment_new (no_tag, data, NULL); + ck_assert_ptr_eq (NULL, fragment); + /* test - valid tag */ + fragment = (struct SH_NodeFragment *) + SH_NodeFragment_raw_new (tag, data, NULL); ck_assert_ptr_ne (NULL, fragment); ck_assert_ptr_eq (NULL, fragment->base.parent); @@ -113,9 +157,10 @@ START_TEST(test_node_fragment_raw_no_status) ck_assert_int_eq (0, fragment->child_n); ck_assert_int_eq (0, fragment->child_s); + /* cleanup */ SH_NodeFragment_free (fragment); - SH_Data_free (data); + free (no_tag); } END_TEST @@ -125,13 +170,27 @@ START_TEST(test_node_fragment_raw_with_status) struct SH_NodeFragment * fragment; SH_Data * data; char * tag = strdup ("tag"); + char * no_tag = strdup ("no_tag"); + bool result; + /* setup */ data = SH_Data_new (NULL); + ck_assert_ptr_ne (NULL, data); + + result = SH_Validator_register_tag (data->validator, tag, NULL); + ck_assert_int_eq (TRUE, result); + /* test - invalid tag */ _status_preinit (status); fragment = (struct SH_NodeFragment *) - SH_NodeFragment_raw_new (tag, data, &status); + SH_NodeFragment_raw_new (no_tag, data, &status); + ck_assert_ptr_eq (NULL, fragment); + ck_assert_int_eq (E_VALUE, status.status); + /* test - valid tag */ + _status_preinit (status); + fragment = (struct SH_NodeFragment *) + SH_NodeFragment_raw_new (tag, data, &status); ck_assert_ptr_ne (NULL, fragment); ck_assert (succeed (&status)); @@ -144,9 +203,10 @@ START_TEST(test_node_fragment_raw_with_status) ck_assert_int_eq (0, fragment->child_n); ck_assert_int_eq (0, fragment->child_s); + /* cleanup */ SH_NodeFragment_free (fragment); - SH_Data_free (data); + free (no_tag); } END_TEST