2 * Copyright (C) 2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /* Test aspects of the private data area API. */
31 #define PREFIX "test_"
34 main (int argc, char *argv[])
41 g = guestfs_create ();
43 fprintf (stderr, "failed to create handle\n");
47 guestfs_set_private (g, PREFIX "a", (void *) 1);
48 guestfs_set_private (g, PREFIX "b", (void *) 2);
49 guestfs_set_private (g, PREFIX "c", (void *) 3);
50 guestfs_set_private (g, PREFIX "a", (void *) 4); /* overwrites previous */
52 /* Check we can fetch keys. */
53 assert (guestfs_get_private (g, PREFIX "a") == (void *) 4);
54 assert (guestfs_get_private (g, PREFIX "b") == (void *) 2);
55 assert (guestfs_get_private (g, PREFIX "c") == (void *) 3);
56 assert (guestfs_get_private (g, PREFIX "d") == NULL);
58 /* Check we can count keys by iterating. */
60 data = guestfs_first_private (g, &key);
61 while (data != NULL) {
62 if (strncmp (key, PREFIX, strlen (PREFIX)) == 0)
64 data = guestfs_next_private (g, &key);
68 /* Delete some keys. */
69 guestfs_set_private (g, PREFIX "a", NULL);
70 guestfs_set_private (g, PREFIX "b", NULL);
72 /* Count them again. */
74 data = guestfs_first_private (g, &key);
75 while (data != NULL) {
76 if (strncmp (key, PREFIX, strlen (PREFIX)) == 0)
78 data = guestfs_next_private (g, &key);