|
Packit |
a4058c |
/* -*- Mode: C; c-basic-offset: 2; -*- */
|
|
Packit |
a4058c |
/* GdkPixbuf library - test loaders
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Copyright (C) 2013 Red Hat, Inc.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
a4058c |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
a4058c |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
a4058c |
* (at your option) any later version.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
a4058c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4058c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
a4058c |
* GNU General Public License for more details.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* You should have received a copy of the GNU General Public License
|
|
Packit |
a4058c |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Author: Matthias Clasen
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf/gdk-pixbuf.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf/gdk-pixdata.h"
|
|
Packit |
a4058c |
#include "test-common.h"
|
|
Packit |
a4058c |
#include <string.h>
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_pixdata_deserialize (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *filename = data;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
GdkPixdata pixdata;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
gchar *contents;
|
|
Packit |
a4058c |
gsize size;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_file_get_contents (g_test_get_filename (G_TEST_DIST, filename, NULL), &contents, &size, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
gdk_pixdata_deserialize (&pixdata, size, (const guint8 *) contents, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_from_pixdata (&pixdata, TRUE, &error);
|
|
Packit |
a4058c |
g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
|
|
Packit |
a4058c |
g_clear_error (&error);
|
|
Packit |
a4058c |
g_free (contents);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_from_pixdata (&pixdata, FALSE, &error);
|
|
Packit |
a4058c |
g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
|
|
Packit |
a4058c |
g_clear_error (&error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_clear_object (&pixbuf);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_pixdata_success (void)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
GdkPixdata pixdata1, pixdata2;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
gchar *contents;
|
|
Packit |
a4058c |
gsize size;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, "test-image.png", NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "test-image.pixdata", NULL), &contents, &size, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
gdk_pixdata_deserialize (&pixdata1, size, (const guint8 *) contents, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_from_pixdata (&pixdata1, FALSE, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixdata_equal (ref, pixbuf, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
g_free (contents);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "test-image-rle.pixdata", NULL), &contents, &size, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
gdk_pixdata_deserialize (&pixdata2, size, (const guint8 *) contents, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_from_pixdata (&pixdata2, FALSE, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixdata_equal (ref, pixbuf, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
g_free (contents);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_pixdata (void)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.pixdata", &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile-compressed.pixdata", &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, "test-image.pixdata", NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_UNKNOWN_TYPE);
|
|
Packit |
a4058c |
g_clear_error (&error);
|
|
Packit |
a4058c |
g_clear_object (&ref;;
|
|
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/pixdata", test_pixdata);
|
|
Packit |
a4058c |
g_test_add_func ("/pixbuf/pixdata/success", test_pixdata_success);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/pixdata/bug775693", "bug775693.pixdata", test_pixdata_deserialize);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return g_test_run ();
|
|
Packit |
a4058c |
}
|