Debian Codegraph @

testsuite/gdk/visual.c

raw
1 #include <gdk/gdk.h>
2
3 /* We don't technically guarantee that the visual returned by
4 * gdk_screen_get_rgba_visual is ARGB8888. But if it isn't, lots
5 * of code will break, so test this here anyway.
6 * The main point of this test is to ensure that the pixel_details
7 * functions return meaningful values for TrueColor visuals.
8 */
9 static void
10 test_rgba_visual (void)
11 {
12 GdkScreen *screen;
13 GdkVisual *visual;
14 guint32 r_mask, g_mask, b_mask;
15 gint r_shift, g_shift, b_shift;
16 gint r_precision, g_precision, b_precision;
17 gint depth;
18 GdkVisualType type;
19
20 g_test_bug ("764210");
21
22 screen = gdk_screen_get_default ();
23 visual = gdk_screen_get_rgba_visual (screen);
24
25 if (visual == NULL)
26 {
27 g_test_skip ("no rgba visual");
28 return;
29 }
30
31 depth = gdk_visual_get_depth (visual);
32 type = gdk_visual_get_visual_type (visual);
33 gdk_visual_get_red_pixel_details (visual, &r_mask, &r_shift, &r_precision);
34 gdk_visual_get_green_pixel_details (visual, &g_mask, &g_shift, &g_precision);
35 gdk_visual_get_blue_pixel_details (visual, &b_mask, &b_shift, &b_precision);
36
37 g_assert_cmpint (depth, ==, 32);
38 g_assert_cmpint (type, ==, GDK_VISUAL_TRUE_COLOR);
39
40 g_assert_cmphex (r_mask, ==, 0x00ff0000);
41 g_assert_cmphex (g_mask, ==, 0x0000ff00);
42 g_assert_cmphex (b_mask, ==, 0x000000ff);
43
44 g_assert_cmpint (r_shift, ==, 16);
45 g_assert_cmpint (g_shift, ==, 8);
46 g_assert_cmpint (b_shift, ==, 0);
47
48 g_assert_cmpint (r_precision, ==, 8);
49 g_assert_cmpint (g_precision, ==, 8);
50 g_assert_cmpint (b_precision, ==, 8);
51 }
52
53 static void
54 test_list_visuals (void)
55 {
56 GdkScreen *screen;
57 GdkVisual *visual;
58 GdkVisual *rgba_visual;
59 GdkVisual *system_visual;
60 GList *list, *l;
61 gboolean found_system, found_rgba;
62
63 screen = gdk_screen_get_default ();
64 system_visual = gdk_screen_get_system_visual (screen);
65 rgba_visual = gdk_screen_get_rgba_visual (screen);
66
67 found_system = FALSE;
68 found_rgba = FALSE;
69
70 list = gdk_screen_list_visuals (screen);
71 for (l = list; l; l = l->next)
72 {
73 visual = l->data;
74 if (visual == system_visual)
75 found_system = TRUE;
76 if (visual == rgba_visual)
77 found_rgba = TRUE;
78 g_assert_true (GDK_IS_VISUAL (visual));
79
80 g_assert_true (gdk_visual_get_screen (visual) == screen);
81 }
82 g_list_free (list);
83
84 g_assert (system_visual != NULL && found_system);
85 g_assert (rgba_visual == NULL || found_rgba);
86 }
87
88 static void
89 test_depth (void)
90 {
91 GdkVisual *visual;
92 gint *depths;
93 gint n_depths;
94 gint i, j;
95 gboolean is_depth;
96
97 gdk_query_depths (&depths, &n_depths);
98 g_assert_cmpint (n_depths, >, 0);
99 for (i = 0; i < n_depths; i++)
100 {
101 g_assert_cmpint (depths[i], >, 0);
102 g_assert_cmpint (depths[i], <=, 32);
103
104 visual = gdk_visual_get_best_with_depth (depths[i]);
105
106 g_assert_nonnull (visual);
107 g_assert_cmpint (gdk_visual_get_depth (visual), ==, depths[i]);
108 }
109
110 for (i = 1; i <= 32; i++)
111 {
112 is_depth = FALSE;
113 for (j = 0; j < n_depths; j++)
114 {
115 if (i == depths[j])
116 is_depth = TRUE;
117 }
118
119 visual = gdk_visual_get_best_with_depth (i);
120 if (!is_depth)
121 g_assert_null (visual);
122 else
123 {
124 g_assert_nonnull (visual);
125 g_assert_cmpint (gdk_visual_get_depth (visual), ==, i);
126 }
127 }
128 }
129
130 static void
131 test_type (void)
132 {
133 GdkVisual *visual;
134 GdkVisualType *types;
135 gint n_types;
136 gint i, j;
137 gboolean is_type;
138
139 gdk_query_visual_types (&types, &n_types);
140 g_assert_cmpint (n_types, >, 0);
141 for (i = 0; i < n_types; i++)
142 {
143 g_assert_cmpint (types[i], >=, GDK_VISUAL_STATIC_GRAY);
144 g_assert_cmpint (types[i], <=, GDK_VISUAL_DIRECT_COLOR);
145
146 visual = gdk_visual_get_best_with_type (types[i]);
147
148 g_assert_nonnull (visual);
149 g_assert_cmpint (gdk_visual_get_visual_type (visual), ==, types[i]);
150 }
151
152 for (i = GDK_VISUAL_STATIC_GRAY; i <= GDK_VISUAL_DIRECT_COLOR; i++)
153 {
154 is_type = FALSE;
155 for (j = 0; j < n_types; j++)
156 {
157 if (i == types[j])
158 is_type = TRUE;
159 }
160
161 visual = gdk_visual_get_best_with_type (i);
162 if (!is_type)
163 g_assert_null (visual);
164 else
165 {
166 g_assert_nonnull (visual);
167 g_assert_cmpint (gdk_visual_get_visual_type (visual), ==, i);
168 }
169 }
170 }
171
172
173 int
174 main (int argc, char *argv[])
175 {
176 g_test_init (&argc, &argv, NULL);
177
178 gdk_init (NULL, NULL);
179
180 g_test_bug_base ("http://bugzilla.gnome.org/");
181
182 g_test_add_func ("/visual/list", test_list_visuals);
183 g_test_add_func ("/visual/rgba", test_rgba_visual);
184 g_test_add_func ("/visual/depth", test_depth);
185 g_test_add_func ("/visual/type", test_type);
186
187 return g_test_run ();
188 }