Beispiel #1
0
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);
}
Beispiel #2
0
int PyCOMPSGroup_print(PyObject *self, FILE *f, int flags) {
    #define _group_ ((PyCOMPS_Group*)self)
    COMPS_ObjListIt *it;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;
    char *id, *name, *desc, *lang, *def, *uservis, *disp_ord;
    COMPS_Object* tmp_prop;

    (void)flags;

    tmp_prop = comps_docgroup_get_id(_group_->group);
    id = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_name(_group_->group);
    name = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_desc(_group_->group);
    desc = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_display_order(_group_->group);
    disp_ord = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_langonly(_group_->group);
    lang = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_def(_group_->group);
    def = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;
    tmp_prop = comps_docgroup_get_uservisible(_group_->group);
    uservis = (tmp_prop)?comps_object_tostr(tmp_prop):NULL;


    fprintf(f, "<COMPS_Group: id='%s', name='%s', description='%s',  "
            "default='%s', uservisible='%s', lang_only='%s', display_order=%s ",
            id, name, desc, def, uservis, lang, disp_ord);
    free(id);
    free(name);
    free(desc);
    free(lang);
    free(def);
    free(uservis);
    free(disp_ord);

    fprintf(f, "name_by_lang={");
    pairlist = comps_objrtree_pairs(_group_->group->name_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", desc_by_lang={");
    pairlist = comps_objrtree_pairs(_group_->group->desc_by_lang);
    for (hsit = pairlist->first; hsit != pairlist->last; hsit = hsit->next) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s', ", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    }
    if (hsit) {
        name = comps_object_tostr(((COMPS_ObjRTreePair*)hsit->data)->data);
        printf("'%s': '%s'}", ((COMPS_ObjRTreePair*)hsit->data)->key, name);
        free(name);
    } else {
        printf("}");
    }
    comps_hslist_destroy(&pairlist);

    fprintf(f, ", packages=[");
    if (_group_->group->packages) {
        for (it = _group_->group->packages->first;
             it != _group_->group->packages->last; it = it->next){
            id = comps_object_tostr(it->comps_obj);
            fprintf(f,"%s, ", id);
            free(id);
        }
        if (it) {
            id = comps_object_tostr(it->comps_obj);
            fprintf(f,"%s", id);
            free(id);
        }
    }
    fprintf(f, "]>");
    return 0;
    #undef _group_
}