ac6173829e3920f53dbecd1cacf57a06c683ef93
[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 int
30 main (int argc, char **argv)
31 {
32   opkg_t *opkg;
33   int err;
34   
35   opkg = opkg_new ();
36
37   opkg_set_option (opkg, "offline_root", "/tmp/");
38
39   opkg_read_config_files (opkg);
40
41   err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
42   printf ("\nopkg_update_package_lists returned %d\n", err);
43
44   err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
45   printf ("\nopkg_install_package returned %d\n", err);
46
47   err = opkg_upgrade_package (opkg, "aspell", progress_callback, "Upgrading...");
48   printf ("\nopkg_upgrade_package returned %d\n", err);
49
50   err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
51   printf ("\nopkg_upgrade_package returned %d\n", err);
52
53   err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
54   printf ("\nopkg_remove_package returned %d\n", err);
55
56   opkg_list_packages (opkg, package_list_callback, NULL);
57   printf ("\n");
58
59   opkg_free (opkg);
60 }