END_TEST START_TEST(test_comps_parse5) { FILE *fp; //char *err_log; COMPS_Parsed *parsed; //COMPS_ListItem *it; //int ret int i; fprintf(stderr, "## Running test_parse5\n\n"); COMPS_LogEntry* known_errors[2]; known_errors[0] = __log_entry_x(COMPS_ERR_TEXT_BETWEEN, 3, comps_str("some stray"), comps_num(6), comps_num(4)); known_errors[1] = __log_entry_x(COMPS_ERR_TEXT_BETWEEN, 3, comps_str(" some stray"), comps_num(189), comps_num(2)); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 1); 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); check_errors(parsed->log, known_errors, 2); //comps2xml_f(parsed->comps_doc, "fed2.xml", 0); for (i = 0; i < 2; i++) { comps_log_entry_destroy(known_errors[i]); } comps_parse_parsed_destroy(parsed); }
END_TEST START_TEST(test_comps_parse3) { FILE *fp; //char *err_log, char *tmp_ch; COMPS_Parsed *parsed; COMPS_ObjListIt *it; int i; COMPS_ObjList *tmplist; COMPS_LogEntry* known_errors[3]; char *str; COMPS_Object *tmpobj; fprintf(stderr, "## Running test_parse3\n\n"); known_errors[0] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3, comps_str("id"), comps_num(188), comps_num(2)); known_errors[1] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3, comps_str("name"), comps_num(188), comps_num(2)); known_errors[2] = __log_entry_x(COMPS_ERR_ELEM_REQUIRED, 3, comps_str("description"), comps_num(188), comps_num(2)); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 1); fp = fopen("sample_comps_bad1.xml", "r"); comps_parse_file(parsed, fp, NULL); fail_if(parsed->log->entries->first == NULL); check_errors(parsed->log, known_errors, 3); for (i = 0; i < 3; i++) { comps_log_entry_destroy(known_errors[i]); } tmplist = comps_doc_groups(parsed->comps_doc); it = tmplist->first; /*pairlist = comps_rtree_pairs(((COMPS_DocCategory*)it->data)->properties); for (hsit = pairlist->first; hsit != NULL; hsit = hsit->next){ printf("%s = %s\n", ((COMPS_RTreePair*)hsit->data)->key, ((COMPS_RTreePair*)hsit->data)->data); }*/ 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); tmpobj = comps_docgroup_get_name((COMPS_DocGroup*)it->comps_obj); fail_if(tmpobj, "%d. category should have NULL name\n"); COMPS_OBJECT_DESTROY(tmpobj); tmpobj = comps_docgroup_get_desc((COMPS_DocGroup*)it->comps_obj); fail_if(tmpobj, "%d. category should have NULL description\n"); COMPS_OBJECT_DESTROY(tmpobj); comps_parse_parsed_destroy(parsed); }
COMPS_ObjList* comps_docgroup_get_packages(COMPS_DocGroup *group, char *name, COMPS_PackageType type) { COMPS_ObjListIt *it; COMPS_ObjList *ret; unsigned int matched, matched_max; matched_max = 0; #define package ((COMPS_DocGroupPackage*)it->comps_obj) COMPS_Str *objname = comps_str(name); if (!group) return NULL; ret = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); if (name != NULL) matched_max++; if (type != COMPS_PACKAGE_UNKNOWN) matched_max++; for (it = (group->packages)?group->packages->first:NULL; it != NULL; it = it->next) { matched = 0; if ((name != NULL) && COMPS_OBJECT_CMP(package->name, objname)) matched++; if ((type != COMPS_PACKAGE_UNKNOWN) && package->type == type) matched++; if (matched == matched_max) { comps_objlist_append(ret, (COMPS_Object*)package); } } COMPS_OBJECT_DESTROY(objname); return ret; }
void __comps_check_allready_set(COMPS_Object *param, char *param_name, COMPS_Parsed *parsed) { if (param) { comps_log_error_x(parsed->log, COMPS_ERR_ELEM_ALREADYSET, 3, comps_str(param_name), comps_num(parser_line), comps_num(parser_col)); } COMPS_OBJECT_DESTROY(param); }
void __comps_check_required_param(COMPS_Object *param, char *param_name, COMPS_Parsed *parsed) { if (!param) { comps_log_error_x(parsed->log, COMPS_ERR_ELEM_REQUIRED, 3, comps_str(param_name), comps_num(parser_line), comps_num(parser_col)); } COMPS_OBJECT_DESTROY(param); }
COMPS_ObjList * __comps_split_arches(char *arches) { COMPS_ObjList *list; char *pch; list = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); pch = strtok(arches, " ,"); while (pch != NULL) { comps_objlist_append_x(list, (COMPS_Object*)comps_str(pch)); pch = strtok(NULL, " ,"); } return list; }
PyObject* PyCOMPS_fromxml_f(PyObject *self, PyObject *args, PyObject* kwds) { FILE *f; COMPS_Parsed *parsed; char *fname = NULL; signed char parsed_ret; PyCOMPS *self_comps = (PyCOMPS*)self; COMPS_Object *tmpstr; COMPS_DefaultsOptions *options = NULL; char* keywords[] = {"fname", "options", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&", keywords, &fname, __pycomps_dict_to_def_opts, &options)) { PyErr_SetString(PyExc_TypeError, "function accept string and optional xml_options dict"); return NULL; } parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 0); f = fopen(fname, "r"); if (!f) { PyErr_Format(PyExc_IOError, "Cannot open %s for reading", fname); //free(fname); comps_parse_parsed_destroy(parsed); if (options) free(options); return NULL; } parsed_ret = comps_parse_file(parsed, f, options); Py_CLEAR(self_comps->p_groups); Py_CLEAR(self_comps->p_categories); Py_CLEAR(self_comps->p_environments); Py_CLEAR(self_comps->p_langpacks); Py_CLEAR(self_comps->p_blacklist); Py_CLEAR(self_comps->p_whiteout); COMPS_OBJECT_DESTROY(self_comps->comps_doc); if (options) free(options); if (parsed->comps_doc) { self_comps->comps_doc = parsed->comps_doc; } else { tmpstr = (COMPS_Object*)comps_str("UTF-8"); self_comps->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc, (COMPS_Object*[]) { tmpstr }); COMPS_OBJECT_DESTROY(tmpstr); }
PyObject* PyCOMPS_toxml_f(PyObject *self, PyObject *args, PyObject *kwds) { const char *errors = NULL; char *tmps, *fname = NULL; int i; signed char genret; COMPS_XMLOptions *xml_options = NULL; COMPS_DefaultsOptions *def_options = NULL; COMPS_HSListItem *it; PyObject *ret, *tmp; char* keywords[] = {"fname", "xml_options", "def_options", NULL}; PyCOMPS *self_comps = (PyCOMPS*)self; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&O&", keywords, &fname, __pycomps_dict_to_xml_opts, &xml_options, __pycomps_dict_to_def_opts, &def_options)) { PyErr_SetString(PyExc_TypeError, "function accept string and optional xml_options dict " "and def_options dict"); return NULL; } if (!self_comps->comps_doc->encoding) self_comps->comps_doc->encoding = comps_str("UTF-8"); comps_hslist_clear(self_comps->comps_doc->log->entries); genret = comps2xml_f(self_comps->comps_doc, fname, 0, xml_options, def_options); if (xml_options) free(xml_options); if (def_options) free(def_options); if (genret == -1) { PyErr_SetString(PyCOMPSExc_XMLGenError, "Error during generating xml"); } //free(fname); for (i = 0, it = self_comps->comps_doc->log->entries->first; it != NULL; it = it->next, i++); ret = PyList_New(i); for (i = 0, it = self_comps->comps_doc->log->entries->first; it != NULL; it = it->next, i++) { tmps = comps_log_entry_str(it->data); tmp = PyUnicode_DecodeUTF8(tmps, strlen(tmps), errors); PyList_SetItem(ret, i, tmp); free(tmps); } return ret; }
void comps_elem_doc_preproc(COMPS_Parsed* parsed, COMPS_Elem *elem) { (void)elem; COMPS_Object *prop = (COMPS_Object*)comps_str(parsed->enc); parsed->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc, (COMPS_Object*[]) { prop });
END_TEST START_TEST(test_arch) { COMPS_Parsed *parsed; COMPS_Doc *doc2; COMPS_ObjList *arches, *list, *list2; COMPS_DocGroup *g; COMPS_DocCategory *c; COMPS_DocEnv *e; COMPS_DocGroupPackage *p; COMPS_Str *str; int x; COMPS_ObjListIt *it; char *grps[3][5] = {{"group1", "group3", "group4", NULL, NULL}, {"group1", "group2", "group3", "group4", NULL}, {"group3", "group4", NULL, NULL, NULL}}; char *g1_pkgs[3][8] = {{"pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL, NULL, NULL}, {"pkg3", "pkg4", "pkg7", NULL, NULL, NULL, NULL, NULL}, {"pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL}}; char *cats[3][5] = {{"cat1", "cat4", NULL, NULL, NULL}, {"cat1", "cat2", "cat4", NULL, NULL}, {"cat3", "cat4", NULL, NULL, NULL}}; char *c1_gids[3][9] = {{"g1", "g3", "g4", "g6", "g7", NULL, NULL, NULL, NULL}, {"g1", "g2", "g4", "g5", "g7", NULL, NULL, NULL, NULL}, {"g4", "g5", "g6", "g7", NULL, NULL, NULL, NULL, NULL}}; char *envs[3][5] = {{"env1", "env4", NULL, NULL, NULL}, {"env1", "env2", "env3", "env4", NULL}, {"env1", "env2", "env4", NULL, NULL}}; char *e1_gids[3][8] = {{"g1", "g3", "g4", NULL, NULL, NULL, NULL, NULL}, {"g1", "g2", "g5", NULL, NULL, NULL, NULL, NULL}, {"g2", "g4", NULL, NULL, NULL,NULL, NULL, NULL}}; char *e1_oids[3][8] = {{"o1", "o3", "o4", NULL, NULL, NULL, NULL, NULL}, {"o1", "o2", "o5", NULL, NULL, NULL, NULL, NULL}, {"o2", "o4", NULL, NULL, NULL,NULL, NULL, NULL}}; FILE *fp; //char *tmp; fprintf(stderr, "## Running test_parse arch\n"); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 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"); //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")); doc2 = comps_doc_arch_filter(parsed->comps_doc, arches); COMPS_OBJECT_DESTROY(arches); list = comps_doc_groups(doc2); ck_assert(list->len == 3); 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]); COMPS_OBJECT_DESTROY(str); } g = (COMPS_DocGroup*)list->first->comps_obj; list2 = g->packages; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //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); } COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(doc2); ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocCategory*)it->comps_obj; str = (COMPS_Str*)comps_doccategory_get_id(g); 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; list2 = c->group_ids; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //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); } COMPS_OBJECT_DESTROY(list); list = comps_doc_environments(doc2); ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocEnv*)it->comps_obj; str = (COMPS_Str*)comps_docenv_get_id(g); 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; list2 = e->group_list; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //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]); } 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); } COMPS_OBJECT_DESTROY(list); COMPS_OBJECT_DESTROY(doc2); comps_parse_parsed_destroy(parsed); }
END_TEST START_TEST(test_comps_parse4) { FILE *fp; //char *err_log; COMPS_Parsed *parsed; //COMPS_ListItem *it; //int ret, int i; //COMPS_List * tmplist; COMPS_LogEntry* known_errors[15]; fprintf(stderr, "## Running test_parse4\n\n"); known_errors[0] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("id"), comps_num(4), comps_num(2)); known_errors[1] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("packagereq"), comps_num(158), comps_num(4)); known_errors[2] = __log_entry_x(COMPS_ERR_ELEM_ALREADYSET, 3, comps_str("langonly"), comps_num(274), comps_num(16)); known_errors[3] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(588), comps_num(4)); known_errors[4] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("grouplist"), comps_num(880), comps_num(2)); known_errors[5] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(881), comps_num(4)); known_errors[6] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(882), comps_num(4)); known_errors[7] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(883), comps_num(4)); known_errors[8] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(884), comps_num(4)); known_errors[9] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(885), comps_num(4)); known_errors[10] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(886), comps_num(4)); known_errors[11] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(887), comps_num(4)); known_errors[12] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("id"), comps_num(1210), comps_num(2)); known_errors[13] = __log_entry_x(COMPS_ERR_NOPARENT, 3, comps_str("groupid"), comps_num(1228), comps_num(4)); known_errors[14] = __log_entry_x(COMPS_ERR_ELEM_ALREADYSET, 3, comps_str("optionlist"), comps_num(1244), comps_num(4)); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 1); fp = fopen("sample_comps_bad2.xml", "r"); comps_parse_file(parsed, fp, NULL); fail_if(parsed->log->entries->first == NULL); check_errors(parsed->log, known_errors, 15); for (i = 0; i < 15; i++) { comps_log_entry_destroy(known_errors[i]); } comps_parse_parsed_destroy(parsed); }
void comps_docgroupid_set_name(COMPS_DocGroupId *gid, char *name, char copy) { (void)copy; if (gid->name) COMPS_OBJECT_DESTROY(gid->name); gid->name = comps_str(name); }
void comps_docpackage_set_requires(COMPS_DocGroupPackage *pkg, char *requires, char copy) { (void)copy; if (pkg->requires) comps_object_destroy((COMPS_Object*)pkg->requires); pkg->requires = comps_str(requires); }
void comps_docpackage_set_name(COMPS_DocGroupPackage *pkg, char *name, char copy) { (void)copy; if (pkg->name) comps_object_destroy((COMPS_Object*)pkg->name); pkg->name = comps_str(name); }