示例#1
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);
}
示例#2
0
}END_TEST

START_TEST(test_comps_doc_setfeats)
{
    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"}};
    const char *envs_ids[] = {"env1", "env2", "env3"};
    const char *envs_names[] = {"environment 1", "environment 2", "environment3"};
    const char *env_gids[][3] = {{"g1","g2","g3"},
                                 {"g2", "g3", "g4"},
                                 {"g1", "g2", "g4"}};
    const char *env_opts[][4] = {{"opt1","opt2","opt3","opt4"},
                                 {"o1", "o2", "opt3", "o4"},
                                 {"op1", "o2", "opt3", "op4"},
                                 {"opt1", "2", "3", "op4"}};

    const char *groups_ids2[] = {"g1", "g22", "g32", "g4"};
    const char *groups_names2[] = {"group1", "group22", "group32", "group4"};
    const char *group_mpackages2[][4] = {{"pkg21","pkg2","pkg23","pkg4"},
                                      {"p1", "p2", "p3", "pkg4"},
                                      {"package1", "package2", "pkg3", "p4"},
                                      {"pack1", "pack22","p3","pkg4"}};
    const char *group_opackages2[][4] = {{"opkg1","opkg2","opkg3","opkg4"},
                                      {"op1", "op2", "op3", "opkg4"},
                                      {"opackage1", "opackage2", "opkg3", "op4"},
                                      {"opack1", "opack2","op3","opkg4"}};
    const char *cats_ids2[] = {"c1", "c2", "c32"};
    const char *cats_names2[] = {"cat1", "cat2", "cat32"};
    const char *cat_gids2[][3] = {{"g1","g2","g32"},
                                 {"g22", "g3", "g4"},
                                 {"g21", "g2", "g4"}};
    const char *envs_ids2[] = {"env21", "env2", "env3"};
    const char *envs_names2[] = {"environment 21", "environment 2", "environment3"};
    const char *env_gids2[][3] = {{"g21","g2","g3"},
                                 {"g2", "g23", "g4"},
                                 {"g1", "g2", "g24"}};
    const char *env_opts2[][4] = {{"opt21","opt2","opt3","opt4"},
                                 {"o1", "o22", "opt3", "o4"},
                                 {"op1", "o2", "opt23", "op4"},
                                 {"opt1", "2", "3", "op24"}};

    COMPS_Doc *doc, *doc2, *tmpdoc;
    COMPS_DocCategory *c, *c1, *c2;
    COMPS_DocEnv *e, *e1, *e2;
    COMPS_DocGroup *g, *g1, *g2;
    COMPS_DocGroupPackage *p;
    //COMPS_List *tmplist;

    doc = comps_doc_create("UTF-8");
    comps_doc_init(doc);
    for (int i=0; i<4; 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++) {
        e = comps_docenv_create();
        comps_docenv_set_id(e, (char*)envs_ids[i], 1);
        comps_docenv_set_name(e, (char*)envs_names[i], 1);
        for (int x=0; x<3; x++) {
            comps_docenv_add_groupid(e, (char*)env_gids[i][x], 1);
        }
        for (int x=0; x<4; x++) {
            comps_docenv_add_optionid(e, (char*)env_opts[i][x], 1);
        }
        comps_doc_add_env(doc, e);
    }
    for (int i=0; i<3; i++) {
        c = comps_doccategory_create("UTF-8");
        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);
    }

    doc2 = comps_doc_create("UTF-8");
    comps_doc_init(doc2);
    for (int i=0; i<4; i++) {
        g = comps_docgroup_create();
        comps_docgroup_set_id(g, (char*)groups_ids2[i], 1);
        comps_docgroup_set_name(g, (char*)groups_names2[i], 1);
        for (int x=0; x<4; x++) {
            p = comps_docpackage_create();
            comps_docpackage_set_name(p, (char*)group_mpackages2[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_opackages2[i][x], 1);
            comps_docpackage_set_type(p, COMPS_PACKAGE_OPTIONAL);
            comps_docgroup_add_package(g, p);
        }
        comps_doc_add_group(doc2, g);
    }
    for (int i=0; i<3; i++) {
        e = comps_docenv_create();
        comps_docenv_set_id(e, (char*)envs_ids2[i], 1);
        comps_docenv_set_name(e, (char*)envs_names2[i], 1);
        for (int x=0; x<3; x++) {
            comps_docenv_add_groupid(e, (char*)env_gids2[i][x], 1);
        }
        for (int x=0; x<4; x++) {
            comps_docenv_add_optionid(e, (char*)env_opts2[i][x], 1);
        }
        comps_doc_add_env(doc2, e);
    }
    for (int i=0; i<3; i++) {
        c = comps_doccategory_create();
        comps_doccategory_set_id(c, (char*)cats_ids2[i], 1);
        comps_doccategory_set_name(c, (char*)cats_names2[i], 1);
        for (int x=0; x<3; x++) {
            comps_doccategory_add_groupid(c, (char*)cat_gids2[i][x], 1);
        }
        comps_doc_add_category(doc2, c);
    }


    g1 = (COMPS_DocGroup*)comps_doc_groups(doc)->first->data;
    g2 = (COMPS_DocGroup*)comps_doc_groups(doc)->first->next->data;
    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);
    comps_docgroup_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);
    comps_docgroup_destroy(g);

    g1 = (COMPS_DocGroup*)comps_doc_groups(doc)->first->next->data;
    g2 = (COMPS_DocGroup*)comps_doc_groups(doc)->first->next->next->data;
    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);
    comps_docgroup_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);
    comps_docgroup_destroy(g);

    c1 = (COMPS_DocCategory*)comps_doc_categories(doc)->first->data;
    c2 = (COMPS_DocCategory*)comps_doc_categories(doc)->first->next->data;
    c = comps_doccategory_union(c1, c2);
    fail_if(c->group_ids->len != 4, "Union of (c1 v c2) should have 4 "
            "group ids, have %d", c->group_ids->len);
    comps_doccategory_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);
    comps_doccategory_destroy(c);

    c1 = (COMPS_DocCategory*)comps_doc_categories(doc)->first->next->data;
    c2 = (COMPS_DocCategory*)comps_doc_categories(doc)->first->next->next->data;
    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);
    comps_doccategory_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);
    comps_doccategory_destroy(c);

    e1 = (COMPS_DocEnv*)comps_doc_environments(doc)->first->data;
    e2 = (COMPS_DocEnv*)comps_doc_environments(doc)->first->next->data;
    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 "
            "groud ids have %d", e->option_list->len);
    comps_docenv_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);
    comps_docenv_destroy(e);

    e1 = (COMPS_DocEnv*)comps_doc_environments(doc)->first->next->data;
    e2 = (COMPS_DocEnv*)comps_doc_environments(doc)->first->next->next->data;
    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);
    comps_docenv_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);
    comps_docenv_destroy(e);

    tmpdoc = comps_doc_union(doc, doc2);
    fail_if(comps_doc_groups(tmpdoc)->len != 6, "Union of (doc ^ doc2) should have 6 "
            "groups  have %d", comps_doc_groups(tmpdoc)->len);
    fail_if(comps_doc_categories(tmpdoc)->len != 4, "Union of (doc ^ doc2) "
            "should have 4 categories  have %d",
            comps_doc_categories(tmpdoc)->len);
    fail_if(comps_doc_environments(tmpdoc)->len != 4, "Union of (doc ^ doc2) "
            "should have 4 environments  have %d",
            comps_doc_environments(tmpdoc)->len);
    comps_doc_destroy(&tmpdoc);
    tmpdoc = comps_doc_intersect(doc, doc2);
    fail_if(comps_doc_groups(tmpdoc)->len != 2, "Intersect of (doc ^ doc2) "
            "should have 2 groups  have %d", comps_doc_groups(tmpdoc)->len);
    fail_if(comps_doc_categories(tmpdoc)->len != 2, "Intersect of (doc ^ doc2)"
            " should have 2 categories  have %d",
            comps_doc_categories(tmpdoc)->len);
    fail_if(comps_doc_environments(tmpdoc)->len != 2, "Intersect of "
            "(doc ^ doc2) should have 2 environments  have %d",
            comps_doc_environments(tmpdoc)->len);
    comps_doc_destroy(&tmpdoc);


    comps_doc_destroy(&doc2);
    comps_doc_destroy(&doc);
}