aboutsummaryrefslogtreecommitdiffstats
path: root/t/test_configuration.c
blob: e232b3576707e9d9c3009ef61bb6c2b7c6e7d177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "test_configuration.h"

START_TEST(test_struct_config)
{
    slapt_config_t *rc = NULL;

    rc = slapt_config_t_init();
    fail_if(rc == NULL);
    slapt_config_t_free(rc);
    rc = NULL;

    rc = slapt_config_t_read("./data/rc1");
    fail_if(rc == NULL);
    {
        slapt_vector_t *s = rc->sources;
        slapt_vector_t *e = rc->exclude_list;

        fail_if(s->size < 1);
        fail_if(e->size != 5);
    }
    slapt_config_t_free(rc);
    rc = NULL;
}
END_TEST

START_TEST(test_working_dir)
{
    DIR *d = NULL;
    slapt_config_t *rc = slapt_config_t_read("data/rc1");

    /* check that working_dir exists or make it if permissions allow */
    /* void slapt_working_dir_init(const slapt_config_t *global_config); */

    slapt_working_dir_init(rc);

    d = opendir("data/slapt-get");
    fail_if(d == NULL);
    closedir(d);
    rmdir("data/slapt-get");
}
END_TEST

START_TEST(test_source_trimming)
{
    slapt_source_t *src1 = slapt_source_t_init("http://www.test.org/dist ");
    slapt_source_t *src2 = slapt_source_t_init("http://www.test.org/dist:PREFERRED ");

    fail_if(strcmp(src1->url, "http://www.test.org/dist/") != 0);
    fail_if(strcmp(src2->url, "http://www.test.org/dist/") != 0);

    slapt_source_t_free(src1);
    slapt_source_t_free(src2);
}
END_TEST

Suite *configuration_test_suite()
{
    Suite *s = suite_create("Configuration");
    TCase *tc = tcase_create("Configuration");

    tcase_add_test(tc, test_struct_config);
    tcase_add_test(tc, test_working_dir);
    tcase_add_test(tc, test_source_trimming);

    suite_add_tcase(s, tc);
    return s;
}