|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf/gdk-pixbuf.h"
|
|
Packit |
a4058c |
#include "test-common.h"
|
|
Packit |
a4058c |
#include <string.h>
|
|
Packit |
a4058c |
#include <glib.h>
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_serialize (void)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf2;
|
|
Packit |
a4058c |
GVariant *data;
|
|
Packit |
a4058c |
GIcon *icon;
|
|
Packit |
a4058c |
GInputStream *stream;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!format_supported ("png"))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("format not supported");
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "test-image.png", NULL), &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
g_assert (pixbuf != NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* turn it into a GVariant */
|
|
Packit |
a4058c |
data = g_icon_serialize (G_ICON (pixbuf));
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* back to a GIcon, but this will be a GBytesIcon, not GdkPixbuf */
|
|
Packit |
a4058c |
icon = g_icon_deserialize (data);
|
|
Packit |
a4058c |
g_assert (G_IS_BYTES_ICON (icon));
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* but since that is a GLoadableIcon, we can load it again */
|
|
Packit |
a4058c |
stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), 0, NULL, NULL, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
pixbuf2 = gdk_pixbuf_new_from_stream (stream, NULL, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* make sure that the pixels are the same.
|
|
Packit |
a4058c |
* our _serialize() uses png, so this should be perfect.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
guchar *pixels_a, *pixels_b;
|
|
Packit |
a4058c |
guint len_a, len_b;
|
|
Packit |
a4058c |
pixels_a = gdk_pixbuf_get_pixels_with_length (pixbuf, &len_a);
|
|
Packit |
a4058c |
pixels_b = gdk_pixbuf_get_pixels_with_length (pixbuf2, &len_b);
|
|
Packit |
a4058c |
g_assert (len_a == len_b);
|
|
Packit |
a4058c |
g_assert (memcmp (pixels_a, pixels_b, len_a) == 0);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (pixbuf2);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
g_object_unref (stream);
|
|
Packit |
a4058c |
g_variant_unref (data);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
int
|
|
Packit |
a4058c |
main (int argc, char **argv)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_init (&argc, &argv, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_add_func ("/pixbuf/icon/serialize", test_serialize);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return g_test_run ();
|
|
Packit |
a4058c |
}
|