From a8769e82935654b45ab9fd7eddb5f9d68c01dc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Sch=C3=B6bel?= <jonathan@xn--schbel-yxa.info> Date: Wed, 26 Jul 2023 18:08:39 +0200 Subject: [PATCH] Validator: added copy tests --- sefht.geany | 8 ++--- tests/test_validator.c | 43 +++++++++++++++++++++++ tests/test_validator_tag.c | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 4 deletions(-) diff --git a/sefht.geany b/sefht.geany index 6490eb6..1960fc8 100644 --- a/sefht.geany +++ b/sefht.geany @@ -28,7 +28,7 @@ long_line_behaviour=1 long_line_column=72 [files] -current_page=42 +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 @@ -71,7 +71,7 @@ FILE_NAME_38=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fpr FILE_NAME_39=18;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Flog.h;0;4 FILE_NAME_40=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fmacro.h;0;8 FILE_NAME_41=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fsefht.h;0;8 -FILE_NAME_42=702;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8 +FILE_NAME_42=3077;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8 FILE_NAME_43=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_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 @@ -81,8 +81,8 @@ FILE_NAME_48=5714;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp 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 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=2177;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 -FILE_NAME_53=10866;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.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=3880;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=536;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 FILE_NAME_55=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4 FILE_NAME_56=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8 diff --git a/tests/test_validator.c b/tests/test_validator.c index 2f1c2f7..b6be842 100644 --- a/tests/test_validator.c +++ b/tests/test_validator.c @@ -66,6 +66,47 @@ START_TEST(test_validator_with_status) } END_TEST +START_TEST(test_validator_copy_no_status) +{ + struct SH_Validator * validator; + struct SH_Validator * copy; + + /* setup */ + validator = SH_Validator_new (NULL); + ck_assert_ptr_ne (NULL, validator); + + /* test */ + copy = SH_Validator_copy (validator, NULL); + ck_assert_ptr_ne (NULL, copy); + + /* cleanup */ + SH_Validator_free (copy); + SH_Validator_free (validator); +} +END_TEST + +START_TEST(test_validator_copy_with_status) +{ + struct SH_Status status; + struct SH_Validator * validator; + struct SH_Validator * copy; + + /* setup */ + validator = SH_Validator_new (NULL); + ck_assert_ptr_ne (NULL, validator); + + /* test */ + _status_preinit (status); + copy = SH_Validator_copy (validator, &status); + ck_assert_ptr_ne (NULL, copy); + ck_assert_int_eq (SUCCESS, status.status); + + /* cleanup */ + SH_Validator_free (copy); + SH_Validator_free (validator); +} +END_TEST + START_TEST(test_validator_spec_no_status) { struct SH_Validator * validator; @@ -107,6 +148,8 @@ Suite * validator_suite (void) tcase_add_test (tc_core, test_validator_no_status); tcase_add_test (tc_core, test_validator_with_status); + tcase_add_test (tc_core, test_validator_copy_no_status); + tcase_add_test (tc_core, test_validator_copy_with_status); tcase_add_test (tc_core, test_validator_spec_no_status); tcase_add_test (tc_core, test_validator_spec_with_status); suite_add_tcase (s, tc_core); diff --git a/tests/test_validator_tag.c b/tests/test_validator_tag.c index 635c119..d045672 100644 --- a/tests/test_validator_tag.c +++ b/tests/test_validator_tag.c @@ -82,6 +82,75 @@ START_TEST(test_validator_with_status) } END_TEST +START_TEST(test_validator_copy_no_status) +{ + struct SH_Validator * validator; + struct SH_Validator * copy; + + /* setup */ + validator = SH_Validator_new_html5 (NULL); + ck_assert_ptr_ne (NULL, validator); + + /* test */ + copy = SH_Validator_copy (validator, NULL); + ck_assert_ptr_ne (NULL, copy); + + ck_assert_ptr_ne (NULL, copy->tags); + ck_assert_ptr_ne (validator->tags, copy->tags); + ck_assert_int_eq (validator->tag_n, copy->tag_n); + ck_assert_int_eq (validator->last_tag, copy->last_tag); + + for (size_t index = 0; index < copy->tag_n; index++) + { + ck_assert_int_eq (validator->tags[index].id, + copy->tags[index].id); + ck_assert_ptr_ne (validator->tags[index].name, + copy->tags[index].name); + ck_assert_str_eq (validator->tags[index].name, + copy->tags[index].name); + } + + SH_Validator_free (copy); + SH_Validator_free (validator); +} +END_TEST + +START_TEST(test_validator_copy_with_status) +{ + struct SH_Status status; + struct SH_Validator * validator; + struct SH_Validator * copy; + + /* setup */ + validator = SH_Validator_new_html5 (NULL); + ck_assert_ptr_ne (NULL, validator); + + /* test */ + _status_preinit (status); + copy = SH_Validator_copy (validator, &status); + ck_assert_ptr_ne (NULL, copy); + ck_assert_int_eq (status.status, SUCCESS); + + ck_assert_ptr_ne (NULL, copy->tags); + ck_assert_ptr_ne (validator->tags, copy->tags); + ck_assert_int_eq (validator->tag_n, copy->tag_n); + ck_assert_int_eq (validator->last_tag, copy->last_tag); + + for (size_t index = 0; index < copy->tag_n; index++) + { + ck_assert_int_eq (validator->tags[index].id, + copy->tags[index].id); + ck_assert_ptr_ne (validator->tags[index].name, + copy->tags[index].name); + ck_assert_str_eq (validator->tags[index].name, + copy->tags[index].name); + } + + SH_Validator_free (copy); + SH_Validator_free (validator); +} +END_TEST + START_TEST(test_validator_spec_no_status) { struct SH_Validator * validator; @@ -393,6 +462,8 @@ Suite * test_suite (void) tcase_add_test (tc_core, test_validator_no_status); tcase_add_test (tc_core, test_validator_with_status); + tcase_add_test (tc_core, test_validator_copy_no_status); + tcase_add_test (tc_core, test_validator_copy_with_status); tcase_add_test (tc_core, test_validator_spec_no_status); tcase_add_test (tc_core, test_validator_spec_with_status); tcase_add_test (tc_core, test_validator_tag_register_no_status); -- GitLab