opkg: implement opkg_list_upgradable_packages function
[oweals/opkg-lede.git] / tests / libopkg_test.c
1 #include <opkg.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 void
6 progress_callback (opkg_t *opkg, int percent, void *data)
7 {
8   printf ("\r%s %3d%%", (char*) data, percent);
9   fflush (stdout);
10 }
11
12 void
13 package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
14 {
15   static install_count = 0;
16   static total_count = 0;
17
18   if (pkg->installed)
19     install_count++;
20
21   total_count++;
22
23   printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
24   fflush (stdout);
25
26   opkg_package_free (pkg);
27 }
28
29 void
30 package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
31 {
32   printf ("%s - %s\n", pkg->name, pkg->version);
33 }
34
35 int
36 main (int argc, char **argv)
37 {
38   opkg_t *opkg;
39   int err;
40   
41   opkg = opkg_new ();
42
43   opkg_set_option (opkg, "offline_root", "/tmp/");
44
45   opkg_re_read_config_files (opkg);
46
47   err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
48   printf ("\nopkg_update_package_lists returned %d\n", err);
49
50   err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
51   printf ("\nopkg_install_package returned %d\n", err);
52
53   err = opkg_upgrade_package (opkg, "aspell", progress_callback, "Upgrading...");
54   printf ("\nopkg_upgrade_package returned %d\n", err);
55
56   err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
57   printf ("\nopkg_remove_package returned %d\n", err);
58
59   printf ("Listing upgradable packages...\n");
60   opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL);
61
62   err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
63   printf ("\nopkg_upgrade_all returned %d\n", err);
64
65   opkg_list_packages (opkg, package_list_callback, NULL);
66   printf ("\n");
67
68   opkg_free (opkg);
69 }