Blame tests/pixbuf-resource.c

Packit 979760
/* -*- Mode: C; c-basic-offset: 2; -*- */
Packit 979760
/* GdkPixbuf library - test loaders
Packit 979760
 *
Packit 979760
 * Copyright (C) 2013 Red Hat, Inc.
Packit 979760
 *
Packit 979760
 * This program is free software; you can redistribute it and/or modify
Packit 979760
 * it under the terms of the GNU General Public License as published by
Packit 979760
 * the Free Software Foundation; either version 2 of the License, or
Packit 979760
 * (at your option) any later version.
Packit 979760
 *
Packit 979760
 * This program is distributed in the hope that it will be useful,
Packit 979760
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 979760
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 979760
 * GNU General Public License for more details.
Packit 979760
 *
Packit 979760
 * You should have received a copy of the GNU General Public License
Packit 979760
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 979760
 *
Packit 979760
 * Author: Matthias Clasen
Packit 979760
 */
Packit 979760
Packit 979760
#include "config.h"
Packit 979760
#include "gdk-pixbuf/gdk-pixbuf.h"
Packit 979760
#include "test-common.h"
Packit 979760
#include <string.h>
Packit 979760
Packit 979760
#define compare_option(p1, p2, key) \
Packit 979760
  g_strcmp0 (gdk_pixbuf_get_option (p1, key), gdk_pixbuf_get_option (p2, key))
Packit 979760
Packit 979760
static gboolean
Packit 979760
pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
Packit 979760
{
Packit 979760
  if (!pixdata_equal (p1, p2, NULL))
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "Title") != 0)
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "Artist") != 0)
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "x_hot") != 0)
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "y_hot") != 0)
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "orientation") != 0)
Packit 979760
    return FALSE;
Packit 979760
  if (compare_option (p1, p2, "icc-profile") != 0)
Packit 979760
    return FALSE;
Packit 979760
Packit 979760
  return TRUE;
Packit 979760
}
Packit 979760
Packit 979760
static void
Packit 979760
test_resource (void)
Packit 979760
{
Packit 979760
  const gchar *path;
Packit 979760
  GError *error = NULL;
Packit 979760
  GdkPixbuf *pixbuf, *ref;
Packit 979760
Packit 979760
  if (!format_supported ("png"))
Packit 979760
    {
Packit 979760
      g_test_skip ("format not supported");
Packit 979760
      return;
Packit 979760
    }
Packit 979760
Packit 979760
  path = g_test_get_filename (G_TEST_DIST, "icc-profile.png", NULL);
Packit 979760
  ref = gdk_pixbuf_new_from_file (path, &error);
Packit 979760
  g_assert_no_error (error);
Packit 979760
Packit 979760
  pixbuf = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.png", &error);
Packit 979760
  g_assert_no_error (error);
Packit 979760
  g_assert (pixbuf_equal (pixbuf, ref));
Packit 979760
  g_object_unref (pixbuf);
Packit 979760
  
Packit 979760
  pixbuf = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.pixdata", &error);
Packit 979760
  g_assert_no_error (error);
Packit 979760
  g_assert (pixdata_equal (pixbuf, ref, NULL));
Packit 979760
  g_object_unref (pixbuf);
Packit 979760
Packit 979760
  pixbuf = gdk_pixbuf_new_from_resource ("/no/such/resource", &error);
Packit 979760
  g_assert (pixbuf == NULL);
Packit 979760
  g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
Packit 979760
  g_clear_error (&error);
Packit 979760
Packit 979760
  pixbuf = gdk_pixbuf_new_from_resource ("resource:///test/resource/icc-profile.png", &error);
Packit 979760
  g_assert (pixbuf == NULL);
Packit 979760
  g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
Packit 979760
  g_clear_error (&error);
Packit 979760
Packit 979760
  g_object_unref (ref);
Packit 979760
}
Packit 979760
Packit 979760
static void
Packit 979760
test_resource_at_scale (void)
Packit 979760
{
Packit 979760
  const gchar *path;
Packit 979760
  GError *error = NULL;
Packit 979760
  GdkPixbuf *pixbuf, *ref;
Packit 979760
Packit 979760
  if (!format_supported ("png"))
Packit 979760
    {
Packit 979760
      g_test_skip ("format not supported");
Packit 979760
      return;
Packit 979760
    }
Packit 979760
Packit 979760
  path = g_test_get_filename (G_TEST_DIST, "icc-profile.png", NULL);
Packit 979760
  ref = gdk_pixbuf_new_from_file_at_scale (path, 40, 10, FALSE, &error);
Packit 979760
  g_assert_no_error (error);
Packit 979760
Packit 979760
  pixbuf = gdk_pixbuf_new_from_resource_at_scale ("/test/resource/icc-profile.png", 40, 10, FALSE, &error);
Packit 979760
  g_assert_no_error (error);
Packit 979760
  g_assert (pixbuf_equal (pixbuf, ref));
Packit 979760
  g_object_unref (pixbuf);
Packit 979760
  
Packit 979760
  g_object_unref (ref);
Packit 979760
}
Packit 979760
Packit 979760
int
Packit 979760
main (int argc, char **argv)
Packit 979760
{
Packit 979760
  g_test_init (&argc, &argv, NULL);
Packit 979760
Packit 979760
  g_test_add_func ("/pixbuf/resource", test_resource);
Packit 979760
  g_test_add_func ("/pixbuf/resource/at-scale", test_resource_at_scale);
Packit 979760
Packit 979760
  return g_test_run ();
Packit 979760
}