summaryrefslogtreecommitdiffstats
path: root/t/test_transaction.c
blob: 2f11a2736e4d90f1169736886cef052df95fc827 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "test_transaction.h"
extern slapt_pkg_info_t pkg;

START_TEST(test_transaction)
{
    slapt_transaction_t *t = slapt_init_transaction();
    fail_if(t == NULL);

    slapt_add_install_to_transaction(t, &pkg);
    fail_unless(t->install_pkgs->size == 1);
    fail_unless(slapt_search_transaction(t, "gslapt"));
    fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
    t = slapt_remove_from_transaction(t, &pkg);

    slapt_add_remove_to_transaction(t, &pkg);
    fail_unless(t->remove_pkgs->size == 1);
    fail_unless(slapt_search_transaction(t, "gslapt"));
    fail_unless(slapt_search_transaction_by_pkg(t, &pkg));
    t = slapt_remove_from_transaction(t, &pkg);

    slapt_add_exclude_to_transaction(t, &pkg);
    fail_unless(t->exclude_pkgs->size == 1);

    slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
    /* fail_unless (slapt_search_upgrade_transaction(t, &pkg)); */

    slapt_free_transaction(t);
}
END_TEST

START_TEST(test_handle_transaction)
{
    slapt_transaction_t *t = slapt_init_transaction();
    slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");

    /*
    download and install/remove/upgrade packages as defined in the transaction
    returns 0 on success
  int slapt_handle_transaction(const slapt_rc_config *,slapt_transaction_t *);
  */

    slapt_free_transaction(t);
    slapt_free_rc_config(rc);
}
END_TEST

START_TEST(test_transaction_dependencies)
{
    slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");

    FILE *fh = fopen("data/avail_deps", "r");
    fail_unless(fh != NULL);
    slapt_vector_t *avail = slapt_parse_packages_txt(fh);
    fclose(fh);

    fh = fopen("data/installed_deps", "r");
    fail_unless(fh != NULL);
    slapt_vector_t *installed = slapt_parse_packages_txt(fh);
    fclose(fh);

    slapt_transaction_t *t = slapt_init_transaction();

    /*
    add dependencies for package to transaction, returns -1 on error, 0 otherwise
  int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
                              slapt_transaction_t *tran,
                              struct slapt_pkg_list *avail_pkgs,
                              struct slapt_pkg_list *installed_pkgs, slapt_pkg_info_t *pkg);
  */

    /*
    check to see if a package has a conflict already present in the transaction
    returns conflicted package or NULL if none
  slapt_pkg_info_t *slapt_is_conflicted(slapt_transaction_t *tran,
                                        struct slapt_pkg_list *avail_pkgs,
                                        struct slapt_pkg_list *installed_pkgs,
                                        slapt_pkg_info_t *pkg);
  */

    /*
    generate a list of suggestions based on the current packages
    in the transaction
  void slapt_generate_suggestions(slapt_transaction_t *tran);
  */
    slapt_pkg_info_t *p = slapt_get_newest_pkg(avail, "scim");
    slapt_pkg_info_t *installed_p = slapt_get_newest_pkg(installed, "scim");
    (void)installed_p;

    slapt_vector_t *conflicts = slapt_is_conflicted(t, avail, installed, p);
    if (conflicts->size > 0) {
        slapt_add_install_to_transaction(t, conflicts->items[0]);
        slapt_add_deps_to_trans(rc, t, avail, installed, conflicts->items[0]);
    }

    slapt_add_deps_to_trans(rc, t, avail, installed, p);
    slapt_add_install_to_transaction(t, p);

    slapt_generate_suggestions(t);

    slapt_free_transaction(t);
    slapt_free_rc_config(rc);
}
END_TEST

Suite *transaction_test_suite()
{
    Suite *s = suite_create("Transaction");
    TCase *tc = tcase_create("Transaction");

    tcase_add_test(tc, test_transaction);
    tcase_add_test(tc, test_handle_transaction);
    tcase_add_test(tc, test_transaction_dependencies);

    suite_add_tcase(s, tc);
    return s;
}