[gtk/clipboard-test: 2/2] Compare images as pixels
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/clipboard-test: 2/2] Compare images as pixels
- Date: Thu, 29 Apr 2021 12:49:45 +0000 (UTC)
commit 1db999018283a80031cd13a8148b1588eaf1afb3
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Apr 29 08:48:40 2021 -0400
Compare images as pixels
The byte streams may be different because we
serialize and deserialize to png format a few
times here.
testsuite/gdk/clipboard.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
---
diff --git a/testsuite/gdk/clipboard.c b/testsuite/gdk/clipboard.c
index 03973c2103..9569de927b 100644
--- a/testsuite/gdk/clipboard.c
+++ b/testsuite/gdk/clipboard.c
@@ -88,6 +88,35 @@ read_upto_done (GObject *source,
g_main_context_wakeup (NULL);
}
+static void
+assert_texture_equal (GdkTexture *t1,
+ GdkTexture *t2)
+{
+ int width;
+ int height;
+ int stride;
+ guchar *d1;
+ guchar *d2;
+
+ width = gdk_texture_get_width (t1);
+ height = gdk_texture_get_height (t1);
+ stride = 4 * width;
+
+ g_assert_cmpint (width, ==, gdk_texture_get_width (t2));
+ g_assert_cmpint (height, ==, gdk_texture_get_height (t2));
+
+ d1 = g_malloc (stride * height);
+ d2 = g_malloc (stride * height);
+
+ gdk_texture_download (t1, d1, stride);
+ gdk_texture_download (t2, d2, stride);
+
+ g_assert_cmpmem (d1, stride * height, d2, stride * height);
+
+ g_free (d1);
+ g_free (d2);
+}
+
static void
test_clipboard_roundtrip (const char *type,
const char *value,
@@ -149,6 +178,26 @@ test_clipboard_roundtrip (const char *type,
{
g_test_fail ();
}
+ else if (g_str_has_suffix (value, ".png"))
+ {
+ GFile *f1, *f2;
+ GdkTexture *t1, *t2;
+
+ f1 = g_file_new_for_path (value);
+ f2 = g_file_new_for_path (stdout_buf);
+
+ t1 = gdk_texture_new_from_file (f1, &error);
+ g_assert_no_error (error);
+ t2 = gdk_texture_new_from_file (f2, &error);
+ g_assert_no_error (error);
+
+ assert_texture_equal (t1, t2);
+
+ g_object_unref (t1);
+ g_object_unref (t2);
+ g_object_unref (f1);
+ g_object_unref (f2);
+ }
else
{
char *m1, *m2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]