Exemple #1
0
PyObject* PyCOMPSEnv_repr(PyObject *self) {
    char *x;
    COMPS_Object *id;
    PyObject *ret;
    id = comps_docenv_get_id(((PyCOMPS_Env*)self)->c_obj);
    x = comps_object_tostr(id);
    ret = PyUnicode_FromFormat("<libcomps.Environment object '%s' at %p>", x, self);
    free(x);
    comps_object_destroy(id);
    return ret;
}
Exemple #2
0
PyObject* PyCOMPSEnv_str(PyObject *self) {
    char *x;
    COMPS_Object *id;
    PyObject *ret;
    id = comps_docenv_get_id(((PyCOMPS_Env*)self)->c_obj);
    x = comps_object_tostr(id);
    ret = PyUnicode_FromFormat("%s", x);
    free(x);
    comps_object_destroy(id);
    return ret;
}
Exemple #3
0
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);
}
Exemple #4
0
int PyCOMPSEnv_print(PyObject *self, FILE *f, int flags) {
    COMPS_ObjListIt *it;
    COMPS_HSList *pairlist;
    COMPS_HSListItem *hsit;
    char *id, *name, *desc, *display_order;
    COMPS_Object *tmp_prop;

    #define _env_ ((PyCOMPS_Env*)self)->c_obj
    (void)flags;

    tmp_prop = (COMPS_Object*)comps_docenv_get_id(_env_);
    id = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_name(_env_);
    name = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_desc(_env_);
    desc = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;
    tmp_prop = (COMPS_Object*)comps_docenv_get_display_order(_env_);
    display_order = (tmp_prop)?comps_object_tostr(tmp_prop): NULL;

    fprintf(f, "<COMPS_Environment: id='%s'"
               "name='%s' description='%s' display_order=%s", id, name, desc,
                display_order);
    free(id);
    free(name);
    free(desc);
    free(display_order);

    fprintf(f, ", name_by_lang={");
    pairlist = comps_objrtree_pairs(_env_->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(_env_->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, ", group_list=[");
    if (_env_->group_list) {
        for (it = _env_->group_list->first;
             it != _env_->group_list->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, "]");
    fprintf(f, ", option_list=[");
    if (_env_->option_list) {
        for (it = _env_->option_list->first;
             it != _env_->option_list->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 _env_
}