diff --git a/sefht.geany b/sefht.geany index 6bf9294704e8e1a3c04eb27531406ef8f07b50a0..fc996b956245dfa3563f3590284786644be2af7d 100644 --- a/sefht.geany +++ b/sefht.geany @@ -43,9 +43,9 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp FILE_NAME_11=2558;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_12=20283;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_13=6032;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_14=5001;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8 -FILE_NAME_15=2988;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8 -FILE_NAME_16=3756;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8 +FILE_NAME_14=5204;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8 +FILE_NAME_15=3030;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8 +FILE_NAME_16=4151;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8 FILE_NAME_17=1116;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_data.h;0;8 FILE_NAME_18=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8 FILE_NAME_19=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8 @@ -61,7 +61,7 @@ FILE_NAME_28=533;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2 FILE_NAME_29=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8 FILE_NAME_30=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8 FILE_NAME_31=53309;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 -FILE_NAME_32=11726;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8 +FILE_NAME_32=15195;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8 FILE_NAME_33=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8 FILE_NAME_34=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 FILE_NAME_35=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 diff --git a/src/lib/sefht/attr.c b/src/lib/sefht/attr.c index 4bd8512f0cf5859c042a0a530e33dd04780c1995..db9cad23acf7c7f359aadb0f852f22230a865cbd 100644 --- a/src/lib/sefht/attr.c +++ b/src/lib/sefht/attr.c @@ -264,3 +264,11 @@ SH_Attr_is_equal (const struct SH_Attr * attr1, { return Attr_is_equal (attr1, attr2); } + +bool +SH_Attr_is_equal_name (const struct SH_Attr * attr1, + const struct SH_Attr * attr2) + /*@*/ +{ + return Attr_is_equal_name (attr1, attr2); +} diff --git a/src/lib/sefht/attr.h b/src/lib/sefht/attr.h index 73a6bfc021025ec03a15af1eb02fe08df01943ea..a5dabc64549c6a618ade89c19f709a6d65e88258 100644 --- a/src/lib/sefht/attr.h +++ b/src/lib/sefht/attr.h @@ -121,4 +121,8 @@ bool SH_Attr_is_equal (const SH_Attr * attr1, const SH_Attr * attr2) /*@*/; +bool +SH_Attr_is_equal_name (const SH_Attr * attr1, const SH_Attr * attr2) + /*@*/; + #endif /* SEFHT_ATTR_H */ diff --git a/src/lib/sefht/attr_static.c b/src/lib/sefht/attr_static.c index 48b2181af76d9525f8bd87accc412505526c176a..b089d8573728c1640260f5f9003c2400e4d7a0fb 100644 --- a/src/lib/sefht/attr_static.c +++ b/src/lib/sefht/attr_static.c @@ -199,4 +199,13 @@ Attr_is_equal (const struct SH_Attr * attr1, return (0 == strcmp (attr1->value, attr2->value)); } +static inline +bool +Attr_is_equal_name (const struct SH_Attr * attr1, + const struct SH_Attr * attr2) + /*@*/ +{ + return (0 == strcmp (attr1->name, attr2->name)); +} + #endif /* SEFHT_ATTR_STATIC_C */ diff --git a/tests/test_attr.c b/tests/test_attr.c index 91f1e781cb5cd6f276e828b530210711d9715805..f4d20bad2e31d0ace2281c18fabf1dacf3dc07da 100644 --- a/tests/test_attr.c +++ b/tests/test_attr.c @@ -520,6 +520,61 @@ START_TEST(test_attr_equal) } } +START_TEST(test_attr_equal_name) +{ + struct + { + struct + { + char * name; + char * value; + } _[2]; + bool result; + } tests[] = + { + {{{"name", NULL}, {"name", NULL}}, TRUE}, + {{{"name", "value"}, {"name", NULL}}, TRUE}, + {{{"name", "value"}, {"name", "value"}}, TRUE}, + {{{"name", "value1"}, {"name", "value2"}}, TRUE}, + {{{"name1", NULL}, {"name2", NULL}}, FALSE}, + {{{"name1", "value"}, {"name2", NULL}}, FALSE}, + {{{"name1", "value"}, {"name2", "value"}}, FALSE}, + {{{"name1", "value1"}, {"name2", "value2"}}, FALSE} + }; + const size_t size = sizeof (tests) / sizeof (tests[0]); + size_t index; + + for (index = 0; index < size; index++) + { + struct SH_Attr * attr1; + struct SH_Attr * attr2; + bool result; + + attr1 = SH_Attr_new (tests[index]._[0].name, + tests[index]._[0].value, NULL); + ck_assert_ptr_ne (NULL, attr1); + + attr2 = SH_Attr_new (tests[index]._[1].name, + tests[index]._[1].value, NULL); + ck_assert_ptr_ne (NULL, attr2); + + result = SH_Attr_is_equal_name (attr1, attr2); + ck_assert_int_eq (result, tests[index].result); + + result = SH_Attr_is_equal_name (attr2, attr1); + ck_assert_int_eq (result, tests[index].result); + + result = Attr_is_equal_name (attr1, attr2); + ck_assert_int_eq (result, tests[index].result); + + result = Attr_is_equal_name (attr2, attr1); + ck_assert_int_eq (result, tests[index].result); + + SH_Attr_free (attr1); + SH_Attr_free (attr2); + } +} + Suite * test_suite (void) { Suite *s; @@ -554,6 +609,7 @@ Suite * test_suite (void) tcase_add_test (tc_core, test_attr_value_raw); tcase_add_test (tc_core, test_attr_equal); + tcase_add_test (tc_core, test_attr_equal_name); suite_add_tcase (s, tc_core);