Blame tests/pixbuf-jpeg.c

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 "gdk-pixbuf/gdk-pixbuf.h"
Packit a4058c
#include "test-common.h"
Packit a4058c
#include <string.h>
Packit a4058c
Packit a4058c
static void
Packit a4058c
test_inverted_cmyk_jpeg (void)
Packit a4058c
{
Packit a4058c
  GError *error = NULL;
Packit a4058c
  GdkPixbuf *ref, *ref2;
Packit a4058c
  gboolean ret;
Packit a4058c
Packit a4058c
  if (!format_supported ("jpeg") || !format_supported ("png"))
Packit a4058c
    {
Packit a4058c
      g_test_skip ("format not supported");
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  ref = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "premature-end.jpg", NULL), &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
Packit a4058c
  ref2 = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "premature-end.png", NULL), &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
Packit a4058c
  ret = pixdata_equal (ref, ref2, &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
  g_assert (ret);
Packit a4058c
Packit a4058c
  g_object_unref (ref);
Packit a4058c
  g_object_unref (ref2);
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
test_type9_rotation_exif_tag (void)
Packit a4058c
{
Packit a4058c
  GError *error = NULL;
Packit a4058c
  GdkPixbuf *ref, *ref1, *ref2;
Packit a4058c
  gboolean ret;
Packit a4058c
Packit a4058c
  if (!format_supported ("jpeg") || !format_supported ("png"))
Packit a4058c
    {
Packit a4058c
      g_test_skip ("format not supported");
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  ref = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "bug725582-testrotate.jpg", NULL), &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
  ref1 = gdk_pixbuf_apply_embedded_orientation (ref);
Packit a4058c
Packit a4058c
  ref2 = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "bug725582-testrotate.png", NULL), &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
Packit a4058c
  ret = pixdata_equal (ref1, ref2, &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
  g_assert (ret);
Packit a4058c
Packit a4058c
  g_assert_cmpstr (gdk_pixbuf_get_option (ref, "orientation"), ==, "6");
Packit a4058c
Packit a4058c
  g_object_unref (ref);
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
test_bug_775218 (void)
Packit a4058c
{
Packit a4058c
  GError *error = NULL;
Packit a4058c
  GdkPixbuf *ref;
Packit a4058c
Packit a4058c
  if (!format_supported ("jpeg"))
Packit a4058c
    {
Packit a4058c
      g_test_skip ("format not supported");
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  ref = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "bug775218.jpg", NULL), &error);
Packit a4058c
  g_assert_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE);
Packit a4058c
  g_clear_object (&ref;;
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
test_comment(void)
Packit a4058c
{
Packit a4058c
  GError *error = NULL;
Packit a4058c
  GdkPixbuf *ref;
Packit a4058c
Packit a4058c
  if (!format_supported ("jpeg") || !format_supported ("png"))
Packit a4058c
    {
Packit a4058c
      g_test_skip ("format not supported");
Packit a4058c
      return;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  ref = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "bug143608-comment.jpg", NULL), &error);
Packit a4058c
  g_assert_no_error (error);
Packit a4058c
Packit a4058c
  g_assert_cmpstr (gdk_pixbuf_get_option (ref, "comment"), ==, "COMMENT HERE");
Packit a4058c
  g_object_unref (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/jpeg/inverted_cmyk_jpeg", test_inverted_cmyk_jpeg);
Packit a4058c
  g_test_add_func ("/pixbuf/jpeg/type9_rotation_exif_tag", test_type9_rotation_exif_tag);
Packit a4058c
  g_test_add_func ("/pixbuf/jpeg/bug775218", test_bug_775218);
Packit a4058c
  g_test_add_func ("/pixbuf/jpeg/comment", test_comment);
Packit a4058c
Packit a4058c
  return g_test_run ();
Packit a4058c
}