File: test_system_packages.c

package info (click to toggle)
libdebian-installer 0.50etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,900 kB
  • ctags: 702
  • sloc: sh: 8,766; ansic: 4,577; makefile: 211
file content (97 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (9)
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <autounit/autounit.h>

#include <debian-installer/package.h>
#include <debian-installer/string.h>
#include <debian-installer/system/packages.h>

#define DOWNLOAD_PACKAGES       "Packages"

static di_packages *packages = NULL;
static di_packages_allocator *packages_allocator = NULL;

gint test_size(autounit_test_t *t) {
    di_slist_node *node;
    di_package *package;
    int count;

    count =0;
    for (node = (packages)->list.head; node; node = node->next) {
      package = node->data;
      count++;
    }

    au_assert(t,di_hash_table_size(packages->table) == count,
	      "hash table size is different with the number of data inserted");
 
    return TRUE;
}

gint test_dependencies(autounit_test_t *t) {

    di_slist_node *node;
    di_package *package;

    /* verify packages initial status_want */
    for (node = (packages)->list.head; node; node = node->next) {
      package = node->data;
      au_assert(t, package->status_want == di_package_status_want_unknown,
		"package initial status_want is not status_want_unknown");
    }

    /* we want to install countrychooser */
    node = (packages)->list.head;
    package = node->data;
    package->status_want = di_package_status_want_install;

    /* check dependencies */
    di_system_packages_resolve_dependencies_mark_anna(packages,NULL,NULL);

    /* verify packages status_want is status_want_install*/
    for (node = (packages)->list.head; node; node = node->next) {
      package = node->data;
      au_assert(t, package->status_want == di_package_status_want_install,
		"package status_want is not status_want_install");
    }

  return TRUE;
}

gint setup(autounit_test_t *t) {
  packages_allocator = di_system_packages_allocator_alloc();
  packages = di_system_packages_read_file(DOWNLOAD_PACKAGES, packages_allocator);

  return TRUE;
}

gint teardown(autounit_test_t *t) {
  di_packages_free(packages);
  di_packages_allocator_free(packages_allocator);
  packages = NULL;
  packages_allocator = NULL;

  return TRUE;
}

autounit_test_group_t test_system_packages_tests[] = {
  {"test_size", test_size, TRUE, TRUE},
  {"test_dependencies", test_dependencies, TRUE, TRUE},
  {0, 0, FALSE, FALSE}
};

int test_system_packages_run() {
  autounit_suite_t *c_unit_test_suite;
  int result;

  c_unit_test_suite =
    au_new_suite(g_string_new("test di_system_packages"), setup, teardown);
  au_add_test_group(c_unit_test_suite, test_system_packages_tests);

  result = au_run_suite(c_unit_test_suite);

  au_delete_suite(c_unit_test_suite);

  return result;
};