[gtk+] Add some more visual tests



commit 89973118f3a3624e36cdbe6ca8235f75e8281f8e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 26 14:56:36 2016 -0400

    Add some more visual tests
    
    These are just basic tests to ensure that the visual implementation
    of a backend is sound.

 testsuite/gdk/visual.c |  130 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 125 insertions(+), 5 deletions(-)
---
diff --git a/testsuite/gdk/visual.c b/testsuite/gdk/visual.c
index 8b8b2ee..ad905fa 100644
--- a/testsuite/gdk/visual.c
+++ b/testsuite/gdk/visual.c
@@ -50,16 +50,136 @@ test_rgba_visual (void)
   g_assert_cmpint (b_precision, ==, 8);
 }
 
+static void
+test_list_visuals (void)
+{
+  GdkScreen *screen;
+  GdkVisual *visual;
+  GdkVisual *rgba_visual;
+  GdkVisual *system_visual;
+  GList *list, *l;
+  gboolean found_system, found_rgba;
+
+  screen = gdk_screen_get_default ();
+  system_visual = gdk_screen_get_system_visual (screen);
+  rgba_visual = gdk_screen_get_rgba_visual (screen);
+
+  found_system = FALSE;
+  found_rgba = FALSE;
+
+  list = gdk_screen_list_visuals (screen);
+  for (l = list; l; l = l->next)
+    {
+      visual = l->data;
+      if (visual == system_visual)
+        found_system = TRUE;
+      if (visual == rgba_visual)
+        found_rgba = TRUE;
+    }
+  g_list_free (list);
+
+  g_assert (system_visual != NULL && found_system);
+  g_assert (rgba_visual == NULL || found_rgba);
+}
+
+static void
+test_depth (void)
+{
+  GdkVisual *visual;
+  gint *depths;
+  gint n_depths;
+  gint i, j;
+  gboolean is_depth;
+
+  gdk_query_depths (&depths, &n_depths);
+  g_assert_cmpint (n_depths, >, 0);
+  for (i = 0; i < n_depths; i++)
+    {
+      g_assert_cmpint (depths[i], >, 0);
+      g_assert_cmpint (depths[i], <=, 32);
+
+      visual = gdk_visual_get_best_with_depth (depths[i]);
+
+      g_assert_nonnull (visual);
+      g_assert_cmpint (gdk_visual_get_depth (visual), ==, depths[i]);
+    }
+
+  for (i = 1; i <= 32; i++)
+    {
+      is_depth = FALSE;
+      for (j = 0; j < n_depths; j++)
+        {
+          if (i == depths[j])
+            is_depth = TRUE;
+        }
+
+      visual = gdk_visual_get_best_with_depth (i);
+      if (!is_depth)
+        g_assert_null (visual);
+      else
+        {
+          g_assert_nonnull (visual);
+          g_assert_cmpint (gdk_visual_get_depth (visual), ==, i);
+        }
+    }
+}
+
+static void
+test_type (void)
+{
+  GdkVisual *visual;
+  GdkVisualType *types;
+  gint n_types;
+  gint i, j;
+  gboolean is_type;
+
+  gdk_query_visual_types (&types, &n_types);
+  g_assert_cmpint (n_types, >, 0);
+  for (i = 0; i < n_types; i++)
+    {
+      g_assert_cmpint (types[i], >=, GDK_VISUAL_STATIC_GRAY);
+      g_assert_cmpint (types[i], <=, GDK_VISUAL_DIRECT_COLOR);
+
+      visual = gdk_visual_get_best_with_type (types[i]);
+
+      g_assert_nonnull (visual);
+      g_assert_cmpint (gdk_visual_get_visual_type (visual), ==, types[i]);
+    }
+
+  for (i = GDK_VISUAL_STATIC_GRAY; i <= GDK_VISUAL_DIRECT_COLOR; i++)
+    {
+      is_type = FALSE;
+      for (j = 0; j < n_types; j++)
+        {
+          if (i == types[j])
+            is_type = TRUE;
+        }
+
+      visual = gdk_visual_get_best_with_type (i);
+      if (!is_type)
+        g_assert_null (visual);
+      else
+        {
+          g_assert_nonnull (visual);
+          g_assert_cmpint (gdk_visual_get_visual_type (visual), ==, i);
+        }
+    }
+}
+
+
 int
 main (int argc, char *argv[])
 {
-        g_test_init (&argc, &argv, NULL);
+  g_test_init (&argc, &argv, NULL);
 
-        gdk_init (NULL, NULL);
+  gdk_init (NULL, NULL);
 
-        g_test_bug_base ("http://bugzilla.gnome.org/";);
+  g_test_bug_base ("http://bugzilla.gnome.org/";);
 
-        g_test_add_func ("/visual/rgba", test_rgba_visual);
+  g_test_add_func ("/visual/list", test_list_visuals);
+  g_test_add_func ("/visual/rgba", test_rgba_visual);
+  g_test_add_func ("/visual/depth", test_depth);
+  g_test_add_func ("/visual/type", test_type);
 
-        return g_test_run ();
+  return g_test_run ();
 }


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