END_TEST START_TEST(test_comps_fedora_parse) { COMPS_Parsed *parsed; //COMPS_HSList *list; //COMPS_ListItem *it; FILE *fp; //char *tmp; fprintf(stderr, "## Running test_parse fedora\n"); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 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"); //printf("log len:%d\n", parsed->log->logger_data->len); //err_str = comps_log_str(parsed->log); //printf("parsed err log: %s", err_str); //free(err_str); //printf("fedora comps groups:%d\n", comps_doc_groups(parsed->comps_doc)->len); //printf("fedora comps categories:%d\n", comps_doc_categories(parsed->comps_doc)->len); //print_all_str(((COMPS_DocGroup*)comps_doc_groups(parsed->comps_doc) // ->first->data)->name_by_lang); comps2xml_f(parsed->comps_doc, "fed2.xml", 0, NULL, NULL); //printf("%s\n", tmp); //free(tmp); comps_parse_parsed_destroy(parsed); }
END_TEST START_TEST(test_comps_fedora_parse) { COMPS_Parsed *parsed; COMPS_HSList *list; //COMPS_ListItem *it; FILE *fp; char *tmp; //char *err_str; parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 1); fp = fopen("fedora_comps.xml", "r"); comps_parse_file(parsed, fp); printf("log len:%d\n", parsed->log->logger_data->len); //err_str = comps_log_str(parsed->log); //printf("parsed err log: %s", err_str); //free(err_str); printf("fedora comps groups:%d\n", comps_doc_groups(parsed->comps_doc)->len); printf("fedora comps categories:%d\n", comps_doc_categories(parsed->comps_doc)->len); //print_all_str(((COMPS_DocGroup*)comps_doc_groups(parsed->comps_doc) // ->first->data)->name_by_lang); comps2xml_f(parsed->comps_doc, "fed2.xml", 1); //printf("%s\n", tmp); //free(tmp); comps_parse_parsed_destroy(parsed); }
END_TEST START_TEST(test_comps_doc_xml) { const char *groups_ids[] = {"g1", "g2", "g3", "g4"}; const char *groups_names[] = {"group1", "group2", "group3", "group4"}; const char *group_mpackages[][4] = {{"pkg1","pkg2","pkg3","pkg4"}, {"p1", "p2", "p3", "pkg4"}, {"package1", "package2", "pkg3", "p4"}, {"pack1", "pack2","p3","pkg4"}}; const char *group_opackages[][4] = {{"opkg1","opkg2","opkg3","opkg4"}, {"op1", "op2", "op3", "opkg4"}, {"opackage1", "opackage2", "opkg3", "op4"}, {"opack1", "opack2","op3","opkg4"}}; const char *cats_ids[] = {"c1", "c2", "c3"}; const char *cats_names[] = {"cat1", "cat2", "cat3"}; const char *cat_gids[][3] = {{"g1","g2","g3"}, {"g2", "g3", "g4"}, {"g1", "g2", "g4"}}; COMPS_Doc *doc; COMPS_DocGroup *g; COMPS_DocCategory *c; COMPS_DocGroupPackage *p; //COMPS_List *tmplist; doc = comps_doc_create("UTF-8"); comps_doc_init(doc); for (int i=0; i<2; i++) { g = comps_docgroup_create(); comps_docgroup_set_id(g, (char*)groups_ids[i], 1); comps_docgroup_set_name(g, (char*)groups_names[i], 1); for (int x=0; x<4; x++) { p = comps_docpackage_create(); comps_docpackage_set_name(p, (char*)group_mpackages[i][x], 1); comps_docpackage_set_type(p, COMPS_PACKAGE_MANDATORY); comps_docgroup_add_package(g, p); p = comps_docpackage_create(); comps_docpackage_set_name(p, (char*)group_opackages[i][x], 1); comps_docpackage_set_type(p, COMPS_PACKAGE_OPTIONAL); comps_docgroup_add_package(g, p); } comps_doc_add_group(doc, g); } for (int i=0; i<3; i++) { c = comps_doccategory_create(); comps_doccategory_set_id(c, (char*)cats_ids[i], 1); comps_doccategory_set_name(c, (char*)cats_names[i], 1); for (int x=0; x<3; x++) { comps_doccategory_add_groupid(c, (char*)cat_gids[i][x], 1); } comps_doc_add_category(doc, c); } comps2xml_f(doc, "testfile.xml", 1); comps_doc_destroy(&doc); }
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; }