[gtk+/wip/baedert/gtkimageview: 230/232] add imageview sizing tests



commit 4b968475c172d04cafd31903e02404e3499433ea
Author: Timm Bäder <mail baedert org>
Date:   Sat May 14 08:39:07 2016 +0200

    add imageview sizing tests

 testsuite/gtk/Makefile.am      |    1 +
 testsuite/gtk/imageview-size.c |  181 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am
index a0f290d..1a93685 100644
--- a/testsuite/gtk/Makefile.am
+++ b/testsuite/gtk/Makefile.am
@@ -76,6 +76,7 @@ TEST_PROGS +=                         \
        window                  \
        displayclose            \
        revealer-size \
+       imageview-size \
        $(NULL)
 
 if OS_UNIX
diff --git a/testsuite/gtk/imageview-size.c b/testsuite/gtk/imageview-size.c
new file mode 100644
index 0000000..a990402
--- /dev/null
+++ b/testsuite/gtk/imageview-size.c
@@ -0,0 +1,181 @@
+#include <gtk/gtk.h>
+
+
+void
+empty ()
+{
+  int min, nat;
+  GtkWidget *iv = gtk_image_view_new ();
+  gtk_widget_show (iv);
+
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, 0);
+  g_assert_cmpint (nat, ==, 0);
+
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, 0);
+  g_assert_cmpint (nat, ==, 0);
+}
+
+void
+image_fit_allocation ()
+{
+  int min, nat;
+  GtkWidget *iv;
+  GdkPixbuf *pic;
+
+  iv = gtk_image_view_new ();
+  pic = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 200);
+  gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (iv), pic, 1);
+  gtk_image_view_set_fit_allocation (GTK_IMAGE_VIEW (iv), TRUE);
+
+  gtk_widget_show (iv);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, 0);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic));
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, 0);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic));
+}
+
+void
+image_no_fit_allocation ()
+{
+  int min, nat;
+  GtkWidget *iv;
+  GdkPixbuf *pic;
+
+  iv = gtk_image_view_new ();
+  pic = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 200);
+  gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (iv), pic, 1);
+
+  gtk_widget_show (iv);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic));
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic));
+}
+
+void
+image_scaled ()
+{
+  int min, nat;
+  GtkWidget *iv;
+  GdkPixbuf *pic;
+
+  iv = gtk_image_view_new ();
+  pic = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 200);
+  gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (iv), pic, 1);
+
+  gtk_widget_show (iv);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic));
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic));
+
+  gtk_image_view_set_scale (GTK_IMAGE_VIEW (iv), 2.0);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic) * 2.0);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic) * 2.0);
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic) * 2.0);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic) * 2.0);
+
+
+  gtk_image_view_set_scale (GTK_IMAGE_VIEW (iv), 0.5);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic) * 0.5);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic) * 0.5);
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic) * 0.5);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic) * 0.5);
+}
+
+void
+image_rotated ()
+{
+  int min, nat;
+  GtkWidget *iv;
+  GdkPixbuf *pic;
+
+  iv = gtk_image_view_new ();
+  pic = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 200);
+  gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (iv), pic, 1);
+  gtk_image_view_set_angle (GTK_IMAGE_VIEW (iv), 90.0);
+
+  gtk_widget_show (iv);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic));
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic));
+}
+
+void
+image_rotated_scaled ()
+{
+  int min, nat;
+  GtkWidget *iv;
+  GdkPixbuf *pic;
+
+  iv = gtk_image_view_new ();
+  pic = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 200);
+  gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (iv), pic, 1);
+  gtk_image_view_set_angle (GTK_IMAGE_VIEW (iv), 90.0);
+
+  gtk_widget_show (iv);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic));
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic));
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic));
+
+  gtk_image_view_set_scale (GTK_IMAGE_VIEW (iv), 0.5);
+
+  gtk_widget_get_preferred_width (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_height (pic) * 0.5);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_height (pic) * 0.5);
+
+  gtk_widget_get_preferred_height (iv, &min, &nat);
+  g_assert_cmpint (min, ==, gdk_pixbuf_get_width (pic) * 0.5);
+  g_assert_cmpint (nat, ==, gdk_pixbuf_get_width (pic) * 0.5);
+}
+
+int
+main (int argc, char **argv)
+{
+  gtk_init (&argc, &argv);
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/sizing/imageview/empty", empty);
+  g_test_add_func ("/sizing/imageview/image-fit-allocation", image_fit_allocation);
+  g_test_add_func ("/sizing/imageview/image-no-fit-allocation", image_no_fit_allocation);
+  g_test_add_func ("/sizing/imageview/image-scaled", image_scaled);
+  g_test_add_func ("/sizing/imageview/image-rotated", image_rotated);
+  g_test_add_func ("/sizing/imageview/image-rotated-scaled", image_rotated_scaled);
+
+
+  return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]