summaryrefslogtreecommitdiff
path: root/tests/gvariant-iter.c
blob: ff36db7a06780c87659413ef9247e69ab1f1825e (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
/* Template: gvariant */

/*
 * No error
 */
{
	GVariant *dictionary;
	GVariantIter iter;
	GVariant *value;
	gchar *key;

	dictionary = g_variant_new_array ((const GVariantType *) "{sv}", NULL, 0);
	g_variant_iter_init (&iter, dictionary);
	while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
		/* Something */
	}
	g_variant_unref (dictionary);
}

/*
 *  Expected a GVariant variadic argument of type 'GVariant **' (aka 'struct _GVariant **') but saw one of type 'gchar **' (aka 'char **').
 *         while (g_variant_iter_loop (&iter, "{sv}", &key, &not_a_value)) {
 *                                                          ^
 */
{
	GVariant *dictionary;
	GVariantIter iter;
	gchar *not_a_value;
	gchar *key;

	dictionary = g_variant_new_array ((const GVariantType *) "{sv}", NULL, 0);
	g_variant_iter_init (&iter, dictionary);
	while (g_variant_iter_loop (&iter, "{sv}", &key, &not_a_value)) {
		/* Something */
	}
	g_variant_unref (dictionary);
}

/*
 * No error
 */
{
	GVariant *dictionary;
	GVariantIter iter;
	GVariant *value;
	gchar *key;

	dictionary = g_variant_new_array ((const GVariantType *) "{sv}", NULL, 0);
	g_variant_iter_init (&iter, dictionary);
	while (g_variant_iter_next (&iter, "{sv}", &key, &value)) {
		/* Something */

		g_variant_unref (value);
		g_free (key);
	}
	g_variant_unref (dictionary);
}

/*
 * Expected a GVariant variadic argument of type 'GVariant **' (aka 'struct _GVariant **') but saw one of type 'gchar **' (aka 'char **').
 *         while (g_variant_iter_next (&iter, "{sv}", &key, &not_a_value)) {
 *                                                          ^
 */
{
	GVariant *dictionary;
	GVariantIter iter;
	gchar *not_a_value;
	gchar *key;

	dictionary = g_variant_new_array ((const GVariantType *) "{sv}", NULL, 0);
	g_variant_iter_init (&iter, dictionary);
	while (g_variant_iter_next (&iter, "{sv}", &key, &not_a_value)) {
		/* Something */

		g_free (not_a_value);
		g_free (key);
	}
	g_variant_unref (dictionary);
}