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

Validator: added test for deregister_tag

Some bug was found: realloc may return NULL, if size is 0.
This should not be considered as if realloc has failed.
parent ee300891
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=54
current_page=53
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
......@@ -61,10 +61,10 @@ 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=1303;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=4198;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_32=10846;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=1068;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=1287;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=7484;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_35=15745;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
FILE_NAME_37=1413;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr_data.h;0;8
FILE_NAME_38=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
......@@ -82,9 +82,9 @@ 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=4963;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=16073;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=33431;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=548;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_55=630;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
FILE_NAME_57=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8
FILE_NAME_58=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4
......
......@@ -664,7 +664,7 @@ remove_attr (struct SH_Validator * validator,
sizeof (struct attr_info)
* (validator->attr_n - 1));
if (NULL == new_attrs)
if ((1 != validator->attr_n) && (NULL == new_attrs))
{
set_status (status, E_ALLOC, 3, "realloc failed");
......
......@@ -469,7 +469,7 @@ remove_tag (struct SH_Validator * validator,
new_tags = realloc (validator->tags, sizeof (struct tag_info)
* (validator->tag_n - 1));
if (NULL == new_tags)
if ((1 != validator->tag_n) && (NULL == new_tags))
{
set_status (status, E_ALLOC, 3, "realloc failed");
......
......@@ -373,6 +373,158 @@ START_TEST(test_validator_tag_register_with_status)
SH_Validator_free (validator);
}
START_TEST(test_validator_deregister_no_status)
{
struct SH_Validator * validator;
const char * tag1 = "tag1";
const char * tag2 = "tag2";
const char * tag3 = "tag3";
const char * attr = "attr";
bool result;
/* setup */
validator = SH_Validator_new (NULL);
ck_assert_ptr_ne (NULL, validator);
result = SH_Validator_register_tag (validator, tag1, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_tag (validator, tag2, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_tag (validator, tag3, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_attr (validator, tag1, attr,
NULL);
ck_assert_int_eq (TRUE, result);
/* test - consistency */
ck_assert_int_eq (3, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag2, validator->tags[1].name);
ck_assert_str_eq (tag3, validator->tags[2].name);
/* test - non existent */
result = SH_Validator_deregister_tag (validator, "notag", NULL);
ck_assert_int_eq (FALSE, result);
/* test - consistency */
ck_assert_int_eq (3, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag2, validator->tags[1].name);
ck_assert_str_eq (tag3, validator->tags[2].name);
/* test - existent #1 */
result = SH_Validator_deregister_tag (validator, tag2, NULL);
ck_assert_int_eq (TRUE, result);
/* test - consistency */
ck_assert_int_eq (2, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag3, validator->tags[1].name);
/* test - existent #2, automatic attr deregister */
result = SH_Validator_deregister_tag (validator, tag1, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_check_attr (validator, NULL, attr);
ck_assert_int_eq (FALSE, result);
/* test - consistency */
ck_assert_int_eq (1, validator->tag_n);
ck_assert_str_eq (tag3, validator->tags[0].name);
/* test - existent #3 */
result = SH_Validator_deregister_tag (validator, tag3, NULL);
ck_assert_int_eq (TRUE, result);
/* test - consistency */
ck_assert_int_eq (0, validator->tag_n);
SH_Validator_free (validator);
}
END_TEST
START_TEST(test_validator_deregister_with_status)
{
struct SH_Status status;
struct SH_Validator * validator;
const char * tag1 = "tag1";
const char * tag2 = "tag2";
const char * tag3 = "tag3";
const char * attr = "attr";
bool result;
/* setup */
validator = SH_Validator_new (NULL);
ck_assert_ptr_ne (NULL, validator);
result = SH_Validator_register_tag (validator, tag1, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_tag (validator, tag2, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_tag (validator, tag3, NULL);
ck_assert_int_eq (TRUE, result);
result = SH_Validator_register_attr (validator, tag1, attr,
NULL);
ck_assert_int_eq (TRUE, result);
/* test - consistency */
ck_assert_int_eq (3, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag2, validator->tags[1].name);
ck_assert_str_eq (tag3, validator->tags[2].name);
/* test - non existent */
_status_preinit (status);
result = SH_Validator_deregister_tag (validator, "notag",
&status);
ck_assert_int_eq (FALSE, result);
ck_assert_int_eq (E_VALUE, status.status);
/* test - consistency */
ck_assert_int_eq (3, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag2, validator->tags[1].name);
ck_assert_str_eq (tag3, validator->tags[2].name);
/* test - existent #1 */
_status_preinit (status);
result = SH_Validator_deregister_tag (validator, tag2, &status);
ck_assert_int_eq (TRUE, result);
ck_assert_int_eq (SUCCESS, status.status);
/* test - consistency */
ck_assert_int_eq (2, validator->tag_n);
ck_assert_str_eq (tag1, validator->tags[0].name);
ck_assert_str_eq (tag3, validator->tags[1].name);
/* test - existent #2, automatic attr deregister */
_status_preinit (status);
result = SH_Validator_deregister_tag (validator, tag1, &status);
ck_assert_int_eq (TRUE, result);
ck_assert_int_eq (SUCCESS, status.status);
result = SH_Validator_check_attr (validator, NULL, attr);
ck_assert_int_eq (FALSE, result);
/* test - consistency */
ck_assert_int_eq (1, validator->tag_n);
ck_assert_str_eq (tag3, validator->tags[0].name);
/* test - existent #3 */
_status_preinit (status);
result = SH_Validator_deregister_tag (validator, tag3, &status);
ck_assert_int_eq (TRUE, result);
ck_assert_int_eq (SUCCESS, status.status);
/* test - consistency */
ck_assert_int_eq (0, validator->tag_n);
SH_Validator_free (validator);
}
END_TEST
START_TEST(test_validator_tag_check)
{
struct SH_Validator * validator;
......@@ -421,6 +573,8 @@ Suite * test_suite (void)
tcase_add_test (tc_core, test_validator_spec_with_status);
tcase_add_test (tc_core, test_validator_tag_register_no_status);
tcase_add_test (tc_core, test_validator_tag_register_with_status);
tcase_add_test (tc_core, test_validator_deregister_no_status);
tcase_add_test (tc_core, test_validator_deregister_with_status);
tcase_add_test (tc_core, test_validator_tag_check);
suite_add_tcase (s, tc_core);
......
......@@ -22,4 +22,7 @@ Fragment:
- support for mapping special chars -> html entities
Validator:
- tests missing for deregister_tag
- fix tests: calloc, possible NULL
- support for global attributes
- add tag types
- fix cursed behaviour, when removing fails
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