From d1e1b1e7df3a5106db5873614241c37d99a13b24 Mon Sep 17 00:00:00 2001 From: Dave Cantrell Date: Thu, 2 Oct 2025 15:04:22 -0400 Subject: [PATCH 1/3] Fix compiler warnings in comps_parse.c Mark a function argument as unused and change the type of err in comps_parse_validate_dtd() to match what libxml returns. Signed-off-by: Dave Cantrell --- libcomps/src/comps_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcomps/src/comps_parse.c b/libcomps/src/comps_parse.c index 7b4bf3c..983ad25 100644 --- a/libcomps/src/comps_parse.c +++ b/libcomps/src/comps_parse.c @@ -130,7 +130,7 @@ void comps_parse_start_doctype(void *userData, const XML_Char *doctypeName, const XML_Char *sysid, const XML_Char *pubid, - int standalone) { + int standalone __attribute__((unused))) { #define parsed ((COMPS_Parsed*)userData) parsed->doctype_name = comps_str(doctypeName); parsed->doctype_sysid = comps_str(sysid); @@ -143,7 +143,7 @@ int comps_parse_validate_dtd(char *filename, char *dtd_file) { xmlDtdPtr dtd_ptr; xmlValidCtxtPtr vctxt; int ret; - xmlErrorPtr err; + const xmlError *err; fptr = xmlReadFile(filename, NULL, 0); if (fptr == NULL) { From 6761a53b8d9af322ca85c09a81a68bdd2badd1ed Mon Sep 17 00:00:00 2001 From: Dave Cantrell Date: Thu, 2 Oct 2025 15:05:52 -0400 Subject: [PATCH 2/3] Modernize the Python bindings to eliminate compiler warnings Mark some function attributes as unused and make some inline functions static, but primarily change from directly casting functions using (PyCFunction) to using _PyCFunction_CAST() in the PyMethodDef arrays. Signed-off-by: Dave Cantrell --- libcomps/src/python/src/pycomps.c | 26 ++++++++++---------- libcomps/src/python/src/pycomps_categories.c | 2 +- libcomps/src/python/src/pycomps_dict.c | 10 ++++---- libcomps/src/python/src/pycomps_envs.c | 2 +- libcomps/src/python/src/pycomps_gids.c | 2 +- libcomps/src/python/src/pycomps_groups.c | 6 ++--- libcomps/src/python/src/pycomps_mdict.c | 14 +++++------ libcomps/src/python/src/pycomps_sequence.c | 4 +-- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libcomps/src/python/src/pycomps.c b/libcomps/src/python/src/pycomps.c index c6c234c..c86caf9 100644 --- a/libcomps/src/python/src/pycomps.c +++ b/libcomps/src/python/src/pycomps.c @@ -198,7 +198,7 @@ void pycomps_clear(PyObject *self) { COMPS_OBJECT_DESTROY(((PyCOMPS*)self)->comps_doc); } -PyObject* PyCOMPS_clear(PyObject *self) { +PyObject* PyCOMPS_clear(PyObject *self, PyObject *args __attribute__((unused))) { COMPS_Str *enc; enc = (COMPS_Str*) @@ -772,27 +772,27 @@ PyDoc_STRVAR(PyCOMPS_arch_filter__doc__, ":return: new :py:class:`libcomps.Comps` instace"); static PyMethodDef PyCOMPS_methods[] = { - {"groups_match", (PyCFunction)PyCOMPS_groups_match, METH_VARARGS | METH_KEYWORDS, + {"groups_match", _PyCFunction_CAST(PyCOMPS_groups_match), METH_VARARGS | METH_KEYWORDS, PyCOMPS_validate__doc__}, - {"categories_match", (PyCFunction)PyCOMPS_categories_match, METH_VARARGS | METH_KEYWORDS, + {"categories_match", _PyCFunction_CAST(PyCOMPS_categories_match), METH_VARARGS | METH_KEYWORDS, PyCOMPS_validate__doc__}, - {"environments_match", (PyCFunction)PyCOMPS_envs_match, METH_VARARGS | METH_KEYWORDS, + {"environments_match", _PyCFunction_CAST(PyCOMPS_envs_match), METH_VARARGS | METH_KEYWORDS, PyCOMPS_validate__doc__}, - {"validate", (PyCFunction)PyCOMPS_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPS_validate), METH_NOARGS, PyCOMPS_validate__doc__}, - {"validate_nf", (PyCFunction)PyCOMPS_validate_nf, METH_NOARGS, + {"validate_nf", _PyCFunction_CAST(PyCOMPS_validate_nf), METH_NOARGS, PyCOMPS_validate_nf__doc__}, - {"xml_f", (PyCFunction)PyCOMPS_toxml_f, METH_VARARGS | METH_KEYWORDS, + {"xml_f", _PyCFunction_CAST(PyCOMPS_toxml_f), METH_VARARGS | METH_KEYWORDS, PyCOMPS_xml_f__doc__}, - {"xml_str", (PyCFunction)PyCOMPS_toxml_str, METH_VARARGS | METH_KEYWORDS, + {"xml_str", _PyCFunction_CAST(PyCOMPS_toxml_str), METH_VARARGS | METH_KEYWORDS, PyCOMPS_xml_str__doc__}, - {"toxml_f", (PyCFunction)PyCOMPS_toxml_f, METH_VARARGS | METH_KEYWORDS, + {"toxml_f", _PyCFunction_CAST(PyCOMPS_toxml_f), METH_VARARGS | METH_KEYWORDS, PyCOMPS_toxml_f__doc__}, - {"toxml_str", (PyCFunction)PyCOMPS_toxml_str, METH_VARARGS | METH_KEYWORDS, + {"toxml_str", _PyCFunction_CAST(PyCOMPS_toxml_str), METH_VARARGS | METH_KEYWORDS, PyCOMPS_toxml_str__doc__}, - {"fromxml_f", (PyCFunction)PyCOMPS_fromxml_f, METH_VARARGS | METH_KEYWORDS, + {"fromxml_f", _PyCFunction_CAST(PyCOMPS_fromxml_f), METH_VARARGS | METH_KEYWORDS, PyCOMPS_fromxml_f__doc__}, - {"fromxml_str", (PyCFunction)PyCOMPS_fromxml_str, METH_VARARGS | METH_KEYWORDS, + {"fromxml_str", _PyCFunction_CAST(PyCOMPS_fromxml_str), METH_VARARGS | METH_KEYWORDS, PyCOMPS_fromxml_str__doc__}, {"clear", (PyCFunction)PyCOMPS_clear, METH_NOARGS, "Clear Comps"}, @@ -928,7 +928,7 @@ PyTypeObject PyCOMPS_Type = { 0, /* tp_alloc */ PyCOMPS_new, /* tp_new */}; -PyObject* Libcomps_xml_default(PyObject *self) { +PyObject* Libcomps_xml_default(PyObject *self, PyObject *args __attribute__((unused))) { const char *keys[] = {"empty_groups", "empty_categories", "empty_environments", "empty_langpacks", "empty_blacklist", "empty_whiteout", diff --git a/libcomps/src/python/src/pycomps_categories.c b/libcomps/src/python/src/pycomps_categories.c index e7ffe3b..fd66d7c 100644 --- a/libcomps/src/python/src/pycomps_categories.c +++ b/libcomps/src/python/src/pycomps_categories.c @@ -199,7 +199,7 @@ PyMemberDef PyCOMPSCat_members[] = { {NULL}}; PyMethodDef PyCOMPSCat_methods[] = { - {"validate", (PyCFunction)PyCOMPSCat_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPSCat_validate), METH_NOARGS, "validate inner category structure"}, {NULL} /* Sentinel */ }; diff --git a/libcomps/src/python/src/pycomps_dict.c b/libcomps/src/python/src/pycomps_dict.c index 73e93b6..d030ada 100644 --- a/libcomps/src/python/src/pycomps_dict.c +++ b/libcomps/src/python/src/pycomps_dict.c @@ -391,15 +391,15 @@ PyMethodDef PyCOMPSDict_methods[] = { {"get", (PyCFunction)PyCOMPSDict_get_, METH_O, PyCOMPSDict_get__doc__}, {"has_key", (PyCFunction)PyCOMPSDict_has_key, METH_O, PyCOMPSDict_has_key__doc__}, - {"items", (PyCFunction)PyCOMPSDict_getiteritems, METH_NOARGS, + {"items", _PyCFunction_CAST(PyCOMPSDict_getiteritems), METH_NOARGS, "return iterator returning (key, value) tuple"}, - {"values", (PyCFunction)PyCOMPSDict_getitervalues, METH_NOARGS, + {"values", _PyCFunction_CAST(PyCOMPSDict_getitervalues), METH_NOARGS, "return iterator returning item's value"}, - {"keys", (PyCFunction)PyCOMPSDict_getiter, METH_NOARGS, + {"keys", _PyCFunction_CAST(PyCOMPSDict_getiter), METH_NOARGS, "return iterator returning item's key"}, - {"clear", (PyCFunction)PyCOMPSDict_clear, METH_NOARGS, + {"clear", _PyCFunction_CAST(PyCOMPSDict_clear), METH_NOARGS, "clear the dict"}, - {"copy", (PyCFunction)PyCOMPSDict_copy, METH_NOARGS, + {"copy", _PyCFunction_CAST(PyCOMPSDict_copy), METH_NOARGS, "return shallow copy of dict"}, {"update", (PyCFunction)PyCOMPSDict_update, METH_O, PyCOMPSDict_update__doc__}, diff --git a/libcomps/src/python/src/pycomps_envs.c b/libcomps/src/python/src/pycomps_envs.c index 8c3795f..edb26e5 100644 --- a/libcomps/src/python/src/pycomps_envs.c +++ b/libcomps/src/python/src/pycomps_envs.c @@ -165,7 +165,7 @@ PyMemberDef PyCOMPSEnv_members[] = { {NULL}}; PyMethodDef PyCOMPSEnv_methods[] = { - {"validate", (PyCFunction)PyCOMPSEnv_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPSEnv_validate), METH_NOARGS, PyCOMPS_env_validate__doc__}, {NULL} /* Sentinel */ }; diff --git a/libcomps/src/python/src/pycomps_gids.c b/libcomps/src/python/src/pycomps_gids.c index f418f4a..a6c07f1 100644 --- a/libcomps/src/python/src/pycomps_gids.c +++ b/libcomps/src/python/src/pycomps_gids.c @@ -196,7 +196,7 @@ PyMemberDef PyCOMPSGID_members[] = { {NULL}}; PyMethodDef PyCOMPSGID_methods[] = { - {"validate", (PyCFunction)PyCOMPSGID_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPSGID_validate), METH_NOARGS, "validate inner Group ID structure"}, {NULL} /* Sentinel */ }; diff --git a/libcomps/src/python/src/pycomps_groups.c b/libcomps/src/python/src/pycomps_groups.c index 3dce9c1..f5b5680 100644 --- a/libcomps/src/python/src/pycomps_groups.c +++ b/libcomps/src/python/src/pycomps_groups.c @@ -210,9 +210,9 @@ PyDoc_STRVAR(PyCOMPS_group_packages_match__doc__, ":return: List of packages\n\n"); PyMethodDef PyCOMPSGroup_methods[] = { - {"validate", (PyCFunction)PyCOMPSGroup_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPSGroup_validate), METH_NOARGS, PyCOMPS_group_validate__doc__}, - {"packages_match", (PyCFunction)PyCOMPSGroup_packages_match, + {"packages_match", _PyCFunction_CAST(PyCOMPSGroup_packages_match), METH_VARARGS | METH_KEYWORDS, PyCOMPS_group_packages_match__doc__}, {NULL} /* Sentinel */ @@ -842,7 +842,7 @@ PyDoc_STRVAR(PyCOMPS_package_validate__doc__, ":raises ValueError: on first occured error"); PyMethodDef PyCOMPSPack_methods[] = { - {"validate", (PyCFunction)PyCOMPSPackage_validate, METH_NOARGS, + {"validate", _PyCFunction_CAST(PyCOMPSPackage_validate), METH_NOARGS, PyCOMPS_package_validate__doc__}, {NULL} /* Sentinel */ }; diff --git a/libcomps/src/python/src/pycomps_mdict.c b/libcomps/src/python/src/pycomps_mdict.c index ef79fa6..38c1430 100644 --- a/libcomps/src/python/src/pycomps_mdict.c +++ b/libcomps/src/python/src/pycomps_mdict.c @@ -166,11 +166,11 @@ PyObject* PyCOMPSMDict_cmp(PyObject *self, PyObject *other, int op) { Py_ssize_t PyCOMPSMDict_len(PyObject *self) { return ((PyCOMPS_MDict*)self)->dict->len; } -PyObject* PyCOMPSMDict_clear(PyObject *self) { +PyObject* PyCOMPSMDict_clear(PyObject *self, PyObject *args __attribute__((unused))) { comps_objmrtree_clear(((PyCOMPS_MDict*)self)->dict); Py_RETURN_NONE; } -PyObject* PyCOMPSMDict_copy(PyObject *self) { +PyObject* PyCOMPSMDict_copy(PyObject *self, PyObject *args __attribute__((unused))) { PyObject *ret; ret = PyCOMPSDict_new(Py_TYPE(self), NULL, NULL); Py_TYPE(self)->tp_init(ret, NULL, NULL); @@ -411,15 +411,15 @@ PyMethodDef PyCOMPSMDict_methods[] = { {"get", (PyCFunction)PyCOMPSMDict_get, METH_O, PyCOMPSMDict_get__doc__}, {"has_key", (PyCFunction)PyCOMPSMDict_has_key, METH_O, PyCOMPSMDict_has_key__doc__}, - {"items", (PyCFunction)PyCOMPSMDict_getiteritems, METH_NOARGS, + {"items", _PyCFunction_CAST(PyCOMPSMDict_getiteritems), METH_NOARGS, "return iterator returning (key, value) tuple"}, - {"values", (PyCFunction)PyCOMPSMDict_getitervalues, METH_NOARGS, + {"values", _PyCFunction_CAST(PyCOMPSMDict_getitervalues), METH_NOARGS, "return iterator returning item's value"}, - {"keys", (PyCFunction)PyCOMPSMDict_getiter, METH_NOARGS, + {"keys", _PyCFunction_CAST(PyCOMPSMDict_getiter), METH_NOARGS, "return iterator returning item's key"}, - {"clear", (PyCFunction)PyCOMPSMDict_clear, METH_NOARGS, + {"clear", _PyCFunction_CAST(PyCOMPSMDict_clear), METH_NOARGS, "clear the dict"}, - {"copy", (PyCFunction)PyCOMPSMDict_copy, METH_NOARGS, + {"copy", _PyCFunction_CAST(PyCOMPSMDict_copy), METH_NOARGS, "return shallow copy of dict"}, {"update", (PyCFunction)PyCOMPSMDict_update, METH_O, PyCOMPSMDict_update__doc__}, diff --git a/libcomps/src/python/src/pycomps_sequence.c b/libcomps/src/python/src/pycomps_sequence.c index 17f8f72..5a998b6 100644 --- a/libcomps/src/python/src/pycomps_sequence.c +++ b/libcomps/src/python/src/pycomps_sequence.c @@ -90,7 +90,7 @@ inline PyObject* list_getitem_byid(PyObject *self, PyObject *id) { #undef _seq_ } -inline COMPS_Object *list_setitem_convert(PyObject *self, PyObject *item) { +static inline COMPS_Object *list_setitem_convert(PyObject *self, PyObject *item) { #define _seq_ ((PyCOMPS_Sequence*)self) COMPS_Object *ret = NULL; if (!item) @@ -643,7 +643,7 @@ PyMethodDef PyCOMPSSeq_methods[] = { "Append item to new of the list"}, {"remove", (PyCFunction)PyCOMPSSeq_remove, METH_O, PyCOMPSSeq_remove__doc__}, - {"clear", (PyCFunction)PyCOMPSSeq_clear, METH_NOARGS, + {"clear", _PyCFunction_CAST(PyCOMPSSeq_clear), METH_NOARGS, "Clear the list"}, {"insert", (PyCFunction)PyCOMPSSeq_insert, METH_VARARGS, PyCOMPSSeq_insert__doc__}, From 3d8cd4197f9d2a0c2d4794e3d9cec89eda552afa Mon Sep 17 00:00:00 2001 From: Dave Cantrell Date: Thu, 2 Oct 2025 15:52:53 -0400 Subject: [PATCH 3/3] Fix compiler warnings and replace deprecated libcheck usage in tests Fix a number of compiler warnings in the test suite. This is mostly from type mismatches that the compiler casted anyway. Also, replace the use of the deprecated fail_if() macro from libcheck with the proper ck_assert macro. Signed-off-by: Dave Cantrell --- libcomps/tests/check_comps.c | 77 ++++++------------ libcomps/tests/check_parse.c | 137 ++++++++++++-------------------- libcomps/tests/check_validate.c | 2 +- 3 files changed, 78 insertions(+), 138 deletions(-) diff --git a/libcomps/tests/check_comps.c b/libcomps/tests/check_comps.c index e14fd43..a081a6a 100644 --- a/libcomps/tests/check_comps.c +++ b/libcomps/tests/check_comps.c @@ -87,23 +87,20 @@ START_TEST(test_comps_doc_basic) comps_doc_add_category(doc, c); } tmplist = comps_doc_groups(doc); - fail_if(tmplist->len == 0, "No groups found"); + ck_assert_msg(tmplist->len != 0, "No groups found"); g = (COMPS_DocGroup*)tmplist->first->comps_obj; COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_doc_get_groups(doc, "g1", NULL, NULL, NULL, 0); - fail_if(tmplist->len == 0, "Group with id 'g1' should be in groups, but" - "cant get it"); + ck_assert_msg(tmplist->len != 0, "Group with id 'g1' should be in groups, but cant get it"); g = (COMPS_DocGroup*)tmplist->first->comps_obj; COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_docgroup_get_packages(g, NULL, COMPS_PACKAGE_OPTIONAL); - fail_if(tmplist->len != 4, "Group with id 'g1' should have 4 optional " - "packages. But have %d.", tmplist->len); + ck_assert_msg(tmplist->len == 4, "Group with id 'g1' should have 4 optional packages. But have %lu.", tmplist->len); COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_docgroup_get_packages(g, NULL, COMPS_PACKAGE_MANDATORY); - fail_if(tmplist->len != 4, "Group with id 'g1' should have 4 optional " - "packages. But have %d.", tmplist->len); + ck_assert_msg(tmplist->len == 4, "Group with id 'g1' should have 4 optional packages. But have %lu.", tmplist->len); COMPS_OBJECT_DESTROY(tmplist); COMPS_OBJECT_DESTROY(doc); }END_TEST @@ -276,22 +273,18 @@ START_TEST(test_comps_doc_setfeats) g1 = (COMPS_DocGroup*)list->first->comps_obj; g2 = (COMPS_DocGroup*)list->first->next->comps_obj; g = comps_docgroup_union(g1, g2); - fail_if(g->packages->len != 14, "Union of (g1 v g2) should have 14 packages" - " have %d", g->packages->len); + ck_assert_msg(g->packages->len == 14, "Union of (g1 v g2) should have 14 packages have %lu", g->packages->len); COMPS_OBJECT_DESTROY(g); g = comps_docgroup_intersect(g1, g2); - fail_if(g->packages->len != 2, "Intersect of (g1 ^ g2) should have 2" - "packages, have %d", g->packages->len); + ck_assert_msg(g->packages->len == 2, "Intersect of (g1 ^ g2) should have 2 packages, have %lu", g->packages->len); COMPS_OBJECT_DESTROY(g); g1 = (COMPS_DocGroup*)list->first->next->comps_obj; g2 = (COMPS_DocGroup*)list->first->next->next->comps_obj; g = comps_docgroup_union(g1, g2); - fail_if(g->packages->len != 16, "Union of (g2 v g3) should have 16 packages" - " have %d", g->packages->len); + ck_assert_msg(g->packages->len == 16, "Union of (g2 v g3) should have 16 packages have %lu", g->packages->len); COMPS_OBJECT_DESTROY(g); g = comps_docgroup_intersect(g1, g2); - fail_if(g->packages->len != 0, "Intersect of (g2 ^ g3) should have 0" - "packages, have %d", g->packages->len); + ck_assert_msg(g->packages->len == 0, "Intersect of (g2 ^ g3) should have 0 packages, have %lu", g->packages->len); COMPS_OBJECT_DESTROY(g); COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(doc); @@ -300,24 +293,20 @@ START_TEST(test_comps_doc_setfeats) c = comps_doccategory_union(c1, c2); //print_category(c); - fail_if(c->group_ids->len != 4, "Union of (c1 v c2) should have 4 " - "group ids, have %d", c->group_ids->len); + ck_assert_msg(c->group_ids->len == 4, "Union of (c1 v c2) should have 4 group ids, have %lu", c->group_ids->len); COMPS_OBJECT_DESTROY(c); c = comps_doccategory_intersect(c1, c2); - fail_if(c->group_ids->len != 2, "Intersect of (c1 ^ c2) should have 2" - "group ids, have %d", c->group_ids->len); + ck_assert_msg(c->group_ids->len == 2, "Intersect of (c1 ^ c2) should have 2 group ids, have %lu", c->group_ids->len); COMPS_OBJECT_DESTROY(c); c1 = (COMPS_DocCategory*)list->first->next->comps_obj; c2 = (COMPS_DocCategory*)list->first->next->next->comps_obj; c = comps_doccategory_union(c1, c2); - fail_if(c->group_ids->len != 4, "Union of (c2 v c3) should have 4 " - "group ids, have %d", c->group_ids->len); + ck_assert_msg(c->group_ids->len == 4, "Union of (c2 v c3) should have 4 group ids, have %lu", c->group_ids->len); COMPS_OBJECT_DESTROY(c); c = comps_doccategory_intersect(c1, c2); - fail_if(c->group_ids->len != 2, "Intersect of (c2 ^ c3) should have 2" - "group ids, have %d", c->group_ids->len); + ck_assert_msg(c->group_ids->len == 2, "Intersect of (c2 ^ c3) should have 2 group ids, have %lu", c->group_ids->len); COMPS_OBJECT_DESTROY(c); COMPS_OBJECT_DESTROY(list); @@ -325,60 +314,46 @@ START_TEST(test_comps_doc_setfeats) e1 = (COMPS_DocEnv*)list->first->comps_obj; e2 = (COMPS_DocEnv*)list->first->next->comps_obj; e = comps_docenv_union(e1, e2); - fail_if(e->group_list->len != 4, "Union of (e1 v e2) should have 4 " - "groud ids have %d", e->group_list->len); - fail_if(e->option_list->len != 7, "Union of (e1 v e2) should have 7 " - "option ids have %d", e->option_list->len); + ck_assert_msg(e->group_list->len == 4, "Union of (e1 v e2) should have 4 groud ids have %lu", e->group_list->len); + ck_assert_msg(e->option_list->len == 7, "Union of (e1 v e2) should have 7 option ids have %lu", e->option_list->len); COMPS_OBJECT_DESTROY(e); e = comps_docenv_intersect(e1, e2); - fail_if(e->group_list->len != 2, "Intersect of (e1 ^ e2) should have 2" - "group ids have %d", e->group_list->len); - fail_if(e->option_list->len != 1, "Union of (e1 v e2) should have 1 " - "option ids have %d", e->option_list->len); + ck_assert_msg(e->group_list->len == 2, "Intersect of (e1 ^ e2) should have 2 group ids have %lu", e->group_list->len); + ck_assert_msg(e->option_list->len == 1, "Union of (e1 v e2) should have 1 option ids have %lu", e->option_list->len); COMPS_OBJECT_DESTROY(e); e1 = (COMPS_DocEnv*)list->first->next->comps_obj; e2 = (COMPS_DocEnv*)list->first->next->next->comps_obj; e = comps_docenv_union(e1, e2); - fail_if(e->group_list->len != 4, "Union of (e2 v e3) should have 4 " - "groud ids have %d", e->group_list->len); - fail_if(e->option_list->len != 6, "Union of (e2 v e3) should have 7 " - "option ids have %d", e->option_list->len); + ck_assert_msg(e->group_list->len == 4, "Union of (e2 v e3) should have 4 groud ids have %lu", e->group_list->len); + ck_assert_msg(e->option_list->len == 6, "Union of (e2 v e3) should have 7 option ids have %lu", e->option_list->len); COMPS_OBJECT_DESTROY(e); e = comps_docenv_intersect(e1, e2); - fail_if(e->group_list->len != 2, "Intersect of (e2 ^ e3) should have 2 " - "groupids have %d", e->group_list->len); - fail_if(e->option_list->len != 2, "Intersect of (e2 v e3) should have 2 " - "option ids have %d", e->option_list->len); + ck_assert_msg(e->group_list->len == 2, "Intersect of (e2 ^ e3) should have 2 groupids have %lu", e->group_list->len); + ck_assert_msg(e->option_list->len == 2, "Intersect of (e2 v e3) should have 2 option ids have %lu", e->option_list->len); COMPS_OBJECT_DESTROY(e); COMPS_OBJECT_DESTROY(list); tmpdoc = comps_doc_union(doc, doc2); list = comps_doc_groups(tmpdoc); - fail_if(list->len != 6, "Union of (doc ^ doc2) should have 6 " - "groups have %d", list->len); + ck_assert_msg(list->len == 6, "Union of (doc ^ doc2) should have 6 groups have %lu", list->len); COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(tmpdoc); - fail_if(list->len != 4, "Union of (doc ^ doc2) " - "should have 4 categories have %d", list->len); + ck_assert_msg(list->len == 4, "Union of (doc ^ doc2) should have 4 categories have %lu", list->len); COMPS_OBJECT_DESTROY(list); list = comps_doc_environments(tmpdoc); - fail_if(list->len != 4, "Union of (doc ^ doc2) " - "should have 4 environments have %d", list->len); + ck_assert_msg(list->len == 4, "Union of (doc ^ doc2) should have 4 environments have %lu", list->len); COMPS_OBJECT_DESTROY(list); COMPS_OBJECT_DESTROY(tmpdoc); tmpdoc = comps_doc_intersect(doc, doc2); list = comps_doc_groups(tmpdoc); - fail_if(list->len != 2, "Intersect of (doc ^ doc2) " - "should have 2 groups have %d", list->len); + ck_assert_msg(list->len == 2, "Intersect of (doc ^ doc2) should have 2 groups have %lu", list->len); COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(tmpdoc); - fail_if(list->len != 2, "Intersect of (doc ^ doc2)" - " should have 2 categories have %d", list->len); + ck_assert_msg(list->len == 2, "Intersect of (doc ^ doc2) should have 2 categories have %lu", list->len); COMPS_OBJECT_DESTROY(list); list = comps_doc_environments(tmpdoc); - fail_if(list->len != 2, "Intersect of " - "(doc ^ doc2) should have 2 environments have %d", list->len); + ck_assert_msg(list->len == 2, "Intersect of (doc ^ doc2) should have 2 environments have %lu", list->len); COMPS_OBJECT_DESTROY(list); COMPS_OBJECT_DESTROY(tmpdoc); COMPS_OBJECT_DESTROY(doc2); diff --git a/libcomps/tests/check_parse.c b/libcomps/tests/check_parse.c index f279708..2d4f5e0 100644 --- a/libcomps/tests/check_parse.c +++ b/libcomps/tests/check_parse.c @@ -72,7 +72,7 @@ START_TEST(test_comps_parse1) fprintf(stderr, "## Running test_parse1\n"); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("sample-comps.xml", "r"); @@ -81,64 +81,50 @@ START_TEST(test_comps_parse1) if (parsed->log->entries->first != NULL) { //err_log = comps_log_str(parsed->log); - ck_assert_msg(parsed->log->entries->first != NULL, - "Some errors have been found (and shouldn't have) during parsing"); + ck_assert_msg(parsed->log->entries->first != NULL, "Some errors have been found (and shouldn't have) during parsing"); //free(err_log); } tmplist = comps_doc_groups(parsed->comps_doc); - ck_assert_msg(tmplist->len == 3, "Should have 3 groups parsed." - "Have %d", tmplist->len); + ck_assert_msg(tmplist->len == 3, "Should have 3 groups parsed. Have %lu", tmplist->len); COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_doc_categories(parsed->comps_doc); - ck_assert_msg(tmplist->len == 2, "Should have 2 categories" - "parsed. Have %d", tmplist->len); + ck_assert_msg(tmplist->len == 2, "Should have 2 categories parsed. Have %lu", tmplist->len); COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_doc_environments(parsed->comps_doc); - fail_if(tmplist->len != 1, - "Should have 1 environment parsed. Have %d", tmplist->len); + ck_assert_msg(tmplist->len == 1, "Should have 1 environment parsed. Have %lu", tmplist->len); COMPS_OBJECT_DESTROY(tmplist); for (int i=0; i<3; i++) { tmplist = comps_doc_groups(parsed->comps_doc); tmpobj2 = comps_objlist_get_x(tmplist, i); - fail_if(tmpobj2 == NULL, "Group not found"); + ck_assert_msg(tmpobj2 != NULL, "Group not found"); tmpobj = comps_docgroup_get_id((COMPS_DocGroup*)tmpobj2); tmpstr = comps_object_tostr(tmpobj); - fail_if(strcmp(tmpstr, groups_ids[i]) != 0, - "%d.group should have id:%s not %s", - i, groups_ids[i], tmpstr); + ck_assert_msg(strcmp(tmpstr, groups_ids[i]) == 0, "%d.group should have id:%s not %s", i, groups_ids[i], tmpstr); free(tmpstr); COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_docgroup_get_name((COMPS_DocGroup*)tmpobj2); tmpstr = comps_object_tostr(tmpobj); - fail_if(strcmp(tmpstr, groups_names[i]) != 0, - "%d.group should have name:%s not %s", - i, groups_names[i], tmpstr); + ck_assert_msg(strcmp(tmpstr, groups_names[i]) == 0, "%d.group should have name:%s not %s", i, groups_names[i], tmpstr); free(tmpstr); COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_docgroup_get_desc((COMPS_DocGroup*)tmpobj2); tmpstr = comps_object_tostr(tmpobj); - fail_if(strcmp(tmpstr, groups_descs[i]) != 0, - "%d.group should have desc:%s not %s", - i, groups_descs[i], tmpstr); + ck_assert_msg(strcmp(tmpstr, groups_descs[i]) == 0, "%d.group should have desc:%s not %s", i, groups_descs[i], tmpstr); free(tmpstr); COMPS_OBJECT_DESTROY(tmpobj); COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_docgroup_get_packages((COMPS_DocGroup*)tmpobj2, NULL, COMPS_PACKAGE_DEFAULT); - fail_if(group_packages[i][0] != tmplist->len, "Group #%d should have" - " %d default packages, Have %d", i, group_packages[i][0], - tmplist->len); + ck_assert_msg((size_t) group_packages[i][0] == tmplist->len, "Group #%d should have %d default packages, Have %lu", i, group_packages[i][0], tmplist->len); COMPS_OBJECT_DESTROY(tmplist); tmplist = comps_docgroup_get_packages((COMPS_DocGroup*)tmpobj2, NULL, COMPS_PACKAGE_OPTIONAL); - fail_if(group_packages[i][1] != tmplist->len, "Group #%d should have" - " %d optional packages, Have %d", i, group_packages[i][1], - tmplist->len); + ck_assert_msg((size_t) group_packages[i][1] == tmplist->len, "Group #%d should have %d optional packages, Have %lu", i, group_packages[i][1], tmplist->len); COMPS_OBJECT_DESTROY(tmplist); } for (int i=0; i<2; i++) { @@ -146,23 +132,18 @@ START_TEST(test_comps_parse1) tmpobj2 = comps_objlist_get(tmplist, i); tmpobj = comps_doccategory_get_id((COMPS_DocCategory*)tmpobj2); tmpstr = comps_object_tostr(tmpobj); - fail_if(strcmp(tmpstr, cats_ids[i]) != 0, - "%s. category should have id:%s not %s", - i, cats_ids[i], tmpstr); + ck_assert_msg(strcmp(tmpstr, cats_ids[i]) == 0, "%d. category should have id:%s not %s", i, cats_ids[i], tmpstr); free(tmpstr); COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_doccategory_get_name((COMPS_DocCategory*)tmpobj2); tmpstr = comps_object_tostr(tmpobj); - fail_if(strcmp(tmpstr, cats_names[i]) != 0, - "%s. category should have name:%s not %s", - i, cats_names[i], tmpstr); + ck_assert_msg(strcmp(tmpstr, cats_names[i]) == 0, "%d. category should have name:%s not %s", i, cats_names[i], tmpstr); free(tmpstr); COMPS_OBJECT_DESTROY(tmpobj); - fail_if(((COMPS_DocCategory*)tmpobj2)->group_ids->len != cats_gids[i], - "Category #%d should have %d groupids, have %d", i, - cats_gids[i], ((COMPS_DocCategory*)tmpobj2)->group_ids->len); + ck_assert_msg(((COMPS_DocCategory*)tmpobj2)->group_ids->len == (size_t)cats_gids[i], + "Category #%d should have %d groupids, have %lu", i, cats_gids[i], ((COMPS_DocCategory*)tmpobj2)->group_ids->len); COMPS_OBJECT_DESTROY(tmpobj2); COMPS_OBJECT_DESTROY(tmplist); } @@ -171,15 +152,14 @@ START_TEST(test_comps_parse1) comps_parse_parsed_destroy(parsed); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); comps_parse_file(parsed, fp, NULL); ret = comps_parse_validate_dtd("sample-bad-elem.xml", "comps.dtd"); - fail_if(ret >0, "XML shouldn't be valid. Validation returned: %d", ret); + ck_assert_msg(ret <= 0, "XML shouldn't be valid. Validation returned: %d", ret); if (parsed->log->entries->first != NULL) { //err_log = comps_log_str(parsed->log); - ck_assert_msg(parsed->log->entries->first != NULL, - "No errors have found during parsing (and should have)"); + ck_assert_msg(parsed->log->entries->first != NULL, "No errors have found during parsing (and should have)"); //free(err_log); } comps_parse_parsed_destroy(parsed); @@ -193,22 +173,15 @@ int check_errors(COMPS_Log *log, COMPS_LogEntry ** known_errors, it = log->entries->first; for (i = 0; it != NULL && i != known_len; it = it->next, i++) { - fail_if(((COMPS_LogEntry*)it->data)->arg_count != - known_errors[i]->arg_count, - "%d err opt_message doesn't match (%d != %d)", i, - ((COMPS_LogEntry*)it->data)->arg_count, - known_errors[i]->arg_count); - fail_if(((COMPS_LogEntry*)it->data)->code != - known_errors[i]->code, "%d. err code different\n (%d != %d)", - i, ((COMPS_LogEntry*)it->data)->code, - known_errors[i]->code); + ck_assert_msg(((COMPS_LogEntry*)it->data)->arg_count == known_errors[i]->arg_count, + "%d err opt_message doesn't match (%d != %d)", i, ((COMPS_LogEntry*)it->data)->arg_count, known_errors[i]->arg_count); + ck_assert_msg(((COMPS_LogEntry*)it->data)->code == known_errors[i]->code, + "%d. err code different\n (%d != %d)", i, ((COMPS_LogEntry*)it->data)->code, known_errors[i]->code); for (int x = 0; x < known_errors[i]->arg_count; x++) { char *_x, *_y; _x = comps_object_tostr(((COMPS_LogEntry*)it->data)->args[x]); _y = comps_object_tostr(known_errors[i]->args[x]); - fail_if(comps_object_cmp(((COMPS_LogEntry*)it->data)->args[x], - known_errors[i]->args[x]) == 0, "%d. %s != %s", - x, _x, _y); + ck_assert_msg(comps_object_cmp(((COMPS_LogEntry*)it->data)->args[x], known_errors[i]->args[x]) != 0, "%d. %s != %s", x, _x, _y); free(_x); free(_y); } @@ -280,14 +253,14 @@ START_TEST(test_comps_parse2) // COMPS_ERR_ELEM_REQUIRED, 1201, 2, 0); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("sample_comps.xml", "r"); comps_parse_file(parsed, fp, NULL); - fail_if(parsed->log->entries->first == NULL); + ck_assert(parsed->log->entries->first != NULL); i = check_errors(parsed->log, known_errors, 10); - fail_if(i != 10); + ck_assert(i == 10); comps_parse_parsed_destroy(parsed); for (i = 0; i < 10; i++) { @@ -320,11 +293,11 @@ START_TEST(test_comps_parse3) comps_num(188), comps_num(2)); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("sample_comps_bad1.xml", "r"); comps_parse_file(parsed, fp, NULL); - fail_if(parsed->log->entries->first == NULL); + ck_assert(parsed->log->entries->first != NULL); check_errors(parsed->log, known_errors, 3); for (i = 0; i < 3; i++) { @@ -341,13 +314,13 @@ START_TEST(test_comps_parse3) COMPS_OBJECT_DESTROY(tmplist); tmpobj = comps_docgroup_get_id((COMPS_DocGroup*)it->comps_obj); - fail_if(tmpobj, "%d. category should have NULL id\n"); - COMPS_OBJECT_DESTROY(tmpobj); + ck_assert_msg(tmpobj == NULL, "group should have NULL id\n"); + if (tmpobj) COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_docgroup_get_name((COMPS_DocGroup*)it->comps_obj); - fail_if(tmpobj, "%d. category should have NULL name\n"); - COMPS_OBJECT_DESTROY(tmpobj); + ck_assert_msg(tmpobj == NULL, "group should have NULL name\n"); + if (tmpobj) COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_docgroup_get_desc((COMPS_DocGroup*)it->comps_obj); - fail_if(tmpobj, "%d. category should have NULL description\n"); + ck_assert_msg(tmpobj == NULL, "group should have NULL description\n"); COMPS_OBJECT_DESTROY(tmpobj); comps_parse_parsed_destroy(parsed); } @@ -413,11 +386,11 @@ START_TEST(test_comps_parse4) comps_num(1244), comps_num(4)); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("sample_comps_bad2.xml", "r"); comps_parse_file(parsed, fp, NULL); - fail_if(parsed->log->entries->first == NULL); + ck_assert(parsed->log->entries->first != NULL); check_errors(parsed->log, known_errors, 15); for (i = 0; i < 15; i++) { @@ -446,12 +419,12 @@ START_TEST(test_comps_parse5) comps_num(2)); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("sample_comps_bad3.xml", "r"); comps_parse_file(parsed, fp, NULL); //comps_log_print(parsed->log); - fail_if(parsed->log->entries->first == NULL); + ck_assert(parsed->log->entries->first != NULL); check_errors(parsed->log, known_errors, 2); //comps2xml_f(parsed->comps_doc, "fed2.xml", 0); @@ -472,11 +445,11 @@ START_TEST(test_comps_fedora_parse) //char *tmp; fprintf(stderr, "## Running test_parse fedora\n"); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("fedora_comps.xml", "r"); comps_parse_file(parsed, fp, NULL); //printf("log len:%d\n", parsed->log->logger_data->len); - fail_if(parsed->fatal_error != 0, "Some fatal errors found after parsing"); + ck_assert_msg(parsed->fatal_error == 0, "Some fatal errors found after parsing"); //printf("log len:%d\n", parsed->log->logger_data->len); //err_str = comps_log_str(parsed->log); //printf("parsed err log: %s", err_str); @@ -501,10 +474,10 @@ START_TEST(test_main2) //char *tmp; fprintf(stderr, "## Running test_parse main2\n"); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("main_comps2.xml", "r"); comps_parse_file(parsed, fp, NULL); - fail_if(parsed->fatal_error != 0, "Some fatal errors found after parsing"); + ck_assert_msg(parsed->fatal_error == 0, "Some fatal errors found after parsing"); //comps2xml_f(parsed->comps_doc, "fed2.xml", 0); comps_parse_parsed_destroy(parsed); } @@ -550,11 +523,11 @@ START_TEST(test_arch) //char *tmp; fprintf(stderr, "## Running test_parse arch\n"); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) == 0); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 0); fp = fopen("main_arches.xml", "r"); comps_parse_file(parsed, fp, NULL); //comps_log_print(parsed->log); - fail_if(parsed->fatal_error != 0, "Some fatal errors found after parsing"); + ck_assert_msg(parsed->fatal_error == 0, "Some fatal errors found after parsing"); //comps2xml_f(parsed->comps_doc, "fed2.xml", 0); arches = (COMPS_ObjList*)comps_object_create(&COMPS_ObjList_ObjInfo, NULL); comps_objlist_append_x(arches, (COMPS_Object*)comps_str("x86")); @@ -567,8 +540,7 @@ START_TEST(test_arch) for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocGroup*)it->comps_obj; str = (COMPS_Str*)comps_docgroup_get_id(g); - ck_assert_msg(strcmp(str->val, grps[0][x]) == 0, "%s != %s", - str->val, grps[0][x]); + ck_assert_msg(strcmp(str->val, grps[0][x]) == 0, "%s != %s", str->val, grps[0][x]); COMPS_OBJECT_DESTROY(str); } g = (COMPS_DocGroup*)list->first->comps_obj; @@ -577,8 +549,7 @@ START_TEST(test_arch) //printf("%s\n", ((COMPS_DocGroupPackage*)it->comps_obj)->name->val); if (g1_pkgs[0][x] == NULL) break; - ck_assert(strcmp(((COMPS_DocGroupPackage*)it->comps_obj)->name->val, - g1_pkgs[0][x]) == 0); + ck_assert(strcmp(((COMPS_DocGroupPackage*)it->comps_obj)->name->val, g1_pkgs[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); @@ -587,8 +558,7 @@ START_TEST(test_arch) for (it = list->first, x=0; it != NULL; it = it->next, x++) { c = (COMPS_DocCategory*)it->comps_obj; str = (COMPS_Str*)comps_doccategory_get_id(c); - ck_assert_msg(strcmp(str->val, cats[0][x]) == 0, "%s != %s", - str->val, cats[0][x]); + ck_assert_msg(strcmp(str->val, cats[0][x]) == 0, "%s != %s", str->val, cats[0][x]); COMPS_OBJECT_DESTROY(str); } c = (COMPS_DocCategory*)list->first->comps_obj; @@ -597,8 +567,7 @@ START_TEST(test_arch) //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val); if (c1_gids[0][x] == NULL) break; - ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, - c1_gids[0][x]) == 0); + ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, c1_gids[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); @@ -607,8 +576,7 @@ START_TEST(test_arch) for (it = list->first, x=0; it != NULL; it = it->next, x++) { e = (COMPS_DocEnv*)it->comps_obj; str = (COMPS_Str*)comps_docenv_get_id(e); - ck_assert_msg(strcmp(str->val, envs[0][x]) == 0, "%s != %s", - str->val, envs[0][x]); + ck_assert_msg(strcmp(str->val, envs[0][x]) == 0, "%s != %s", str->val, envs[0][x]); COMPS_OBJECT_DESTROY(str); } e = (COMPS_DocEnv*)list->first->comps_obj; @@ -617,17 +585,14 @@ START_TEST(test_arch) //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val); if (e1_gids[0][x] == NULL) break; - ck_assert_msg(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, - e1_gids[0][x]) == 0, "%s != %s", - ((COMPS_DocGroupId*)it->comps_obj)->name->val, - e1_gids[0][x]); + ck_assert_msg(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_gids[0][x]) == 0, + "%s != %s", ((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_gids[0][x]); } list2 = e->option_list; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { if (e1_oids[0][x] == NULL) break; - ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, - e1_oids[0][x]) == 0); + ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_oids[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); diff --git a/libcomps/tests/check_validate.c b/libcomps/tests/check_validate.c index 170270d..eb98979 100644 --- a/libcomps/tests/check_validate.c +++ b/libcomps/tests/check_validate.c @@ -132,7 +132,7 @@ START_TEST(test_doc_validate) { fp = fopen("f21-rawhide-comps.xml", "r"); parsed = comps_parse_parsed_create(); - fail_if(comps_parse_parsed_init(parsed, "UTF-8", 0) != 1); + ck_assert(comps_parse_parsed_init(parsed, "UTF-8", 0) != 1); comps_parse_file(parsed, fp, NULL); doc = parsed->comps_doc; result = comps_validate_execute((COMPS_Object*)doc, COMPS_Doc_ValidateRules);