diff --git a/sefht.geany b/sefht.geany index e976bd0587dd9ed774946160f5339af1b6befeea..e2741478465fc5480112bf3046ec99448161c631 100644 --- a/sefht.geany +++ b/sefht.geany @@ -61,8 +61,8 @@ FILE_NAME_28=1867;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp FILE_NAME_29=2191;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8 FILE_NAME_30=1159;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.h;0;8 FILE_NAME_31=1008;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_html.h;0;8 -FILE_NAME_32=14105;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8 -FILE_NAME_33=1251;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8 +FILE_NAME_32=13800;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8 +FILE_NAME_33=2116;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8 FILE_NAME_34=1150;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8 FILE_NAME_35=22399;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8 FILE_NAME_36=1051;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.h;0;8 @@ -82,7 +82,7 @@ FILE_NAME_49=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprg 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 FILE_NAME_51=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8 FILE_NAME_52=2447;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 -FILE_NAME_53=9430;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8 +FILE_NAME_53=20787;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8 FILE_NAME_54=58751;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8 FILE_NAME_55=497;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 FILE_NAME_56=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4 diff --git a/src/lib/sefht/validator_tag.c b/src/lib/sefht/validator_tag.c index 388d90368a003826d7e744860648a756c7aca9bb..ef00fe1a99682346f287e96dd4486be86453afb0 100644 --- a/src/lib/sefht/validator_tag.c +++ b/src/lib/sefht/validator_tag.c @@ -587,6 +587,27 @@ SH_Validator_check_tag (struct SH_Validator * validator, return find_tag (validator, tag, &index); } +bool +SH_Validator_is_self_closing_tag (const struct SH_Validator * validator, + const char * tag, + /*@null@*/ /*@out@*/ + struct SH_Status * status) + /*@globals fileSystem@*/ + /*@modifies fileSystem@*/ + /*@modifies status@*/ +{ + size_t index; + + if (!find_tag (validator, tag, &index)) + { + set_status (status, E_VALUE, 2, "no such tag"); + return FALSE; + } + + set_success (status); + return (TAG_T_VOID == validator->tags[index].type); +} + bool /*@alt void@*/ SH_Validator_register_tag (struct SH_Validator * validator, diff --git a/src/lib/sefht/validator_tag.h b/src/lib/sefht/validator_tag.h index 83b5c1046d21325517a2d7097cdfce75cda9c389..4a77a3d7f02eea6877938db60953e98828cd743c 100644 --- a/src/lib/sefht/validator_tag.h +++ b/src/lib/sefht/validator_tag.h @@ -75,4 +75,13 @@ SH_Validator_check_tag (struct SH_Validator * validator, const char * tag) /*@*/; +bool +SH_Validator_is_self_closing_tag (const SH_Validator * validator, + const char * tag, + /*@null@*/ /*@out@*/ + struct SH_Status * status) + /*@globals fileSystem@*/ + /*@modifies fileSystem@*/ + /*@modifies status@*/; + #endif /* SEFHT_VALIDATOR_TAG_H */ diff --git a/tests/test_validator_tag.c b/tests/test_validator_tag.c index 800c1a9f77623e206226fd5446f5f75f22e18e89..61d9c5f0660ece201767b2e70095fa32f313da65 100644 --- a/tests/test_validator_tag.c +++ b/tests/test_validator_tag.c @@ -607,6 +607,85 @@ START_TEST(test_validator_tag_check) } END_TEST +START_TEST(test_validator_tag_self_closing_no_status) +{ + struct SH_Validator * validator; + bool result; + + /* setup */ + validator = SH_Validator_new (NULL); + ck_assert_ptr_ne (NULL, validator); + + result = SH_Validator_register_tag (validator, "html", + SH_TAG_TYPE_NORMAL, NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_Validator_register_tag (validator, "link", + SH_TAG_TYPE_VOID, NULL); + ck_assert_int_eq (TRUE, result); + + /* test - self closing */ + result = SH_Validator_is_self_closing_tag (validator, "link", + NULL); + ck_assert_int_eq (TRUE, result); + + /* test - not self closing */ + result = SH_Validator_is_self_closing_tag (validator, "html", + NULL); + ck_assert_int_eq (FALSE, result); + + /* test - invalid tag */ + result = SH_Validator_is_self_closing_tag (validator, "body", + NULL); + ck_assert_int_eq (FALSE, result); + + /* cleanup */ + SH_Validator_free (validator); +} + +START_TEST(test_validator_tag_self_closing_with_status) +{ + struct SH_Status status; + struct SH_Validator * validator; + bool result; + + /* setup */ + validator = SH_Validator_new (NULL); + ck_assert_ptr_ne (NULL, validator); + + result = SH_Validator_register_tag (validator, "html", + SH_TAG_TYPE_NORMAL, NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_Validator_register_tag (validator, "link", + SH_TAG_TYPE_VOID, NULL); + ck_assert_int_eq (TRUE, result); + + /* test - self closing */ + _status_preinit (status); + result = SH_Validator_is_self_closing_tag (validator, "link", + &status); + ck_assert_int_eq (TRUE, result); + ck_assert_int_eq (SUCCESS, status.status); + + /* test - not self closing */ + _status_preinit (status); + result = SH_Validator_is_self_closing_tag (validator, "html", + &status); + ck_assert_int_eq (FALSE, result); + ck_assert_int_eq (SUCCESS, status.status); + + /* test - invalid tag */ + _status_preinit (status); + result = SH_Validator_is_self_closing_tag (validator, "body", + &status); + ck_assert_int_eq (FALSE, result); + ck_assert_int_eq (E_VALUE, status.status); + + /* cleanup */ + SH_Validator_free (validator); +} + Suite * test_suite (void) { Suite *s; @@ -628,6 +707,8 @@ Suite * test_suite (void) tcase_add_test (tc_core, test_validator_tag_deregister_no_status); tcase_add_test (tc_core, test_validator_tag_deregister_with_status); tcase_add_test (tc_core, test_validator_tag_check); + tcase_add_test (tc_core, test_validator_tag_self_closing_no_status); + tcase_add_test (tc_core, test_validator_tag_self_closing_with_status); suite_add_tcase (s, tc_core); return s;