1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008 Red Hat, Inc.
5 * This work is provided "as is"; redistribution and modification
6 * in whole or in part, in any medium, physical or electronic is
7 * permitted without restriction.
9 * This work 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.
13 * In no event shall the authors or contributors be liable for any
14 * direct, indirect, incidental, special, exemplary, or consequential
15 * damages (including, but not limited to, procurement of substitute
16 * goods or services; loss of use, data, or profits; or business
17 * interruption) however caused and on any theory of liability, whether
18 * in contract, strict liability, or tort (including negligence or
19 * otherwise) arising in any way out of the use of this software, even
20 * if advised of the possibility of such damage.
22 * Authors: David Zeuthen <davidz@redhat.com>
25 #include <glib/glib.h>
31 test_g_icon_serialize (void)
47 /* check that GFileIcon and GThemedIcon serialize to the encoding specified */
49 uri
= "file:///some/native/path/to/an/icon.png";
50 location
= g_file_new_for_uri (uri
);
51 icon
= g_file_icon_new (location
);
52 data
= g_icon_to_string (icon
);
53 g_assert_cmpstr (data
, ==, "/some/native/path/to/an/icon.png");
54 icon2
= g_icon_new_for_string (data
, &error
);
55 g_assert_no_error (error
);
56 g_assert (g_icon_equal (icon
, icon2
));
58 g_object_unref (icon
);
59 g_object_unref (icon2
);
60 g_object_unref (location
);
62 uri
= "file:///some/native/path/to/an/icon with spaces.png";
63 location
= g_file_new_for_uri (uri
);
64 icon
= g_file_icon_new (location
);
65 data
= g_icon_to_string (icon
);
66 g_assert_cmpstr (data
, ==, "/some/native/path/to/an/icon with spaces.png");
67 icon2
= g_icon_new_for_string (data
, &error
);
68 g_assert_no_error (error
);
69 g_assert (g_icon_equal (icon
, icon2
));
71 g_object_unref (icon
);
72 g_object_unref (icon2
);
73 g_object_unref (location
);
75 uri
= "sftp:///some/non-native/path/to/an/icon.png";
76 location
= g_file_new_for_uri (uri
);
77 icon
= g_file_icon_new (location
);
78 data
= g_icon_to_string (icon
);
79 g_assert_cmpstr (data
, ==, "sftp:///some/non-native/path/to/an/icon.png");
80 icon2
= g_icon_new_for_string (data
, &error
);
81 g_assert_no_error (error
);
82 g_assert (g_icon_equal (icon
, icon2
));
84 g_object_unref (icon
);
85 g_object_unref (icon2
);
86 g_object_unref (location
);
89 uri
= "sftp:///some/non-native/path/to/an/icon with spaces.png";
90 location
= g_file_new_for_uri (uri
);
91 icon
= g_file_icon_new (location
);
92 data
= g_icon_to_string (icon
);
93 g_assert_cmpstr (data
, ==, "sftp:///some/non-native/path/to/an/icon%20with%20spaces.png");
94 icon2
= g_icon_new_for_string (data
, &error
);
95 g_assert_no_error (error
);
96 g_assert (g_icon_equal (icon
, icon2
));
98 g_object_unref (icon
);
99 g_object_unref (icon2
);
100 g_object_unref (location
);
103 icon
= g_themed_icon_new ("network-server");
104 data
= g_icon_to_string (icon
);
105 g_assert_cmpstr (data
, ==, "network-server");
106 icon2
= g_icon_new_for_string (data
, &error
);
107 g_assert_no_error (error
);
108 g_assert (g_icon_equal (icon
, icon2
));
110 g_object_unref (icon
);
111 g_object_unref (icon2
);
113 /* Check that we can serialize from well-known specified formats */
114 icon
= g_icon_new_for_string ("network-server%", &error
);
115 g_assert_no_error (error
);
116 icon2
= g_themed_icon_new ("network-server%");
117 g_assert (g_icon_equal (icon
, icon2
));
118 g_object_unref (icon
);
119 g_object_unref (icon2
);
121 icon
= g_icon_new_for_string ("/path/to/somewhere.png", &error
);
122 g_assert_no_error (error
);
123 location
= g_file_new_for_commandline_arg ("/path/to/somewhere.png");
124 icon2
= g_file_icon_new (location
);
125 g_assert (g_icon_equal (icon
, icon2
));
126 g_object_unref (icon
);
127 g_object_unref (icon2
);
128 g_object_unref (location
);
130 icon
= g_icon_new_for_string ("/path/to/somewhere with whitespace.png", &error
);
131 g_assert_no_error (error
);
132 data
= g_icon_to_string (icon
);
133 g_assert_cmpstr (data
, ==, "/path/to/somewhere with whitespace.png");
135 location
= g_file_new_for_commandline_arg ("/path/to/somewhere with whitespace.png");
136 icon2
= g_file_icon_new (location
);
137 g_assert (g_icon_equal (icon
, icon2
));
138 g_object_unref (location
);
139 g_object_unref (icon2
);
140 location
= g_file_new_for_commandline_arg ("/path/to/somewhere%20with%20whitespace.png");
141 icon2
= g_file_icon_new (location
);
142 g_assert (!g_icon_equal (icon
, icon2
));
143 g_object_unref (location
);
144 g_object_unref (icon2
);
145 g_object_unref (icon
);
147 icon
= g_icon_new_for_string ("sftp:///path/to/somewhere.png", &error
);
148 g_assert_no_error (error
);
149 data
= g_icon_to_string (icon
);
150 g_assert_cmpstr (data
, ==, "sftp:///path/to/somewhere.png");
152 location
= g_file_new_for_commandline_arg ("sftp:///path/to/somewhere.png");
153 icon2
= g_file_icon_new (location
);
154 g_assert (g_icon_equal (icon
, icon2
));
155 g_object_unref (icon
);
156 g_object_unref (icon2
);
157 g_object_unref (location
);
160 icon
= g_icon_new_for_string ("sftp:///path/to/somewhere with whitespace.png", &error
);
161 g_assert_no_error (error
);
162 data
= g_icon_to_string (icon
);
163 g_assert_cmpstr (data
, ==, "sftp:///path/to/somewhere%20with%20whitespace.png");
165 location
= g_file_new_for_commandline_arg ("sftp:///path/to/somewhere with whitespace.png");
166 icon2
= g_file_icon_new (location
);
167 g_assert (g_icon_equal (icon
, icon2
));
168 g_object_unref (location
);
169 g_object_unref (icon2
);
170 location
= g_file_new_for_commandline_arg ("sftp:///path/to/somewhere%20with%20whitespace.png");
171 icon2
= g_file_icon_new (location
);
172 g_assert (g_icon_equal (icon
, icon2
));
173 g_object_unref (location
);
174 g_object_unref (icon2
);
175 g_object_unref (icon
);
178 /* Check that GThemedIcon serialization works */
180 icon
= g_themed_icon_new ("network-server");
181 g_themed_icon_append_name (G_THEMED_ICON (icon
), "computer");
182 data
= g_icon_to_string (icon
);
183 icon2
= g_icon_new_for_string (data
, &error
);
184 g_assert_no_error (error
);
185 g_assert (g_icon_equal (icon
, icon2
));
187 g_object_unref (icon
);
188 g_object_unref (icon2
);
190 icon
= g_themed_icon_new ("icon name with whitespace");
191 g_themed_icon_append_name (G_THEMED_ICON (icon
), "computer");
192 data
= g_icon_to_string (icon
);
193 icon2
= g_icon_new_for_string (data
, &error
);
194 g_assert_no_error (error
);
195 g_assert (g_icon_equal (icon
, icon2
));
197 g_object_unref (icon
);
198 g_object_unref (icon2
);
200 icon
= g_themed_icon_new_with_default_fallbacks ("network-server-xyz");
201 g_themed_icon_append_name (G_THEMED_ICON (icon
), "computer");
202 data
= g_icon_to_string (icon
);
203 icon2
= g_icon_new_for_string (data
, &error
);
204 g_assert_no_error (error
);
205 g_assert (g_icon_equal (icon
, icon2
));
207 g_object_unref (icon
);
208 g_object_unref (icon2
);
210 /* Check that GEmblemedIcon serialization works */
212 icon
= g_themed_icon_new ("face-smirk");
213 icon2
= g_themed_icon_new ("emblem-important");
214 g_themed_icon_append_name (G_THEMED_ICON (icon2
), "emblem-shared");
215 location
= g_file_new_for_uri ("file:///some/path/somewhere.png");
216 icon3
= g_file_icon_new (location
);
217 g_object_unref (location
);
218 emblem1
= g_emblem_new_with_origin (icon2
, G_EMBLEM_ORIGIN_DEVICE
);
219 emblem2
= g_emblem_new_with_origin (icon3
, G_EMBLEM_ORIGIN_LIVEMETADATA
);
220 icon4
= g_emblemed_icon_new (icon
, emblem1
);
221 g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon4
), emblem2
);
222 data
= g_icon_to_string (icon4
);
223 icon5
= g_icon_new_for_string (data
, &error
);
224 g_assert_no_error (error
);
225 g_assert (g_icon_equal (icon4
, icon5
));
226 g_object_unref (emblem1
);
227 g_object_unref (emblem2
);
228 g_object_unref (icon
);
229 g_object_unref (icon2
);
230 g_object_unref (icon3
);
231 g_object_unref (icon4
);
232 g_object_unref (icon5
);
240 g_test_init (&argc
, &argv
, NULL
);
242 g_test_add_func ("/g-icon/serialize", test_g_icon_serialize
);