1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/*
* Copyright (C) 2020 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "testlib-compositor.h"
#include "layersurface-priv.h"
#include <gdk/gdkwayland.h>
#include <glib.h>
static void
on_layer_surface_notify (PhoshLayerSurface *surface,
GParamSpec *pspec,
guint *count)
{
(*count)++;
}
static void
test_layer_surface_new (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
PhoshMonitor *monitor = phosh_test_get_monitor (fixture->state);
GtkWidget *surface = phosh_layer_surface_new (phosh_wayland_get_zwlr_layer_shell_v1(
fixture->state->wl),
monitor->wl_output);
g_assert_true (PHOSH_IS_LAYER_SURFACE (surface));
gtk_widget_destroy (surface);
}
static void
test_layer_surface_g_object_new (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
g_autofree char *namespace = g_strdup_printf ("phosh test %s", __func__);
PhoshMonitor *monitor = phosh_test_get_monitor (fixture->state);
GtkWidget *surface = g_object_new (PHOSH_TYPE_LAYER_SURFACE,
"layer-shell", phosh_wayland_get_zwlr_layer_shell_v1(
fixture->state->wl),
"wl-output", monitor->wl_output,
"width", 10,
"height", 10,
"layer", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"kbd-interactivity", FALSE,
"exclusive-zone", -1,
"namespace", namespace,
NULL);
g_assert_true (PHOSH_IS_LAYER_SURFACE (surface));
gtk_widget_set_visible (surface, TRUE);
/* Run the unmapped code path */
g_assert_true (gtk_widget_get_visible (surface));
g_assert_true (gtk_widget_get_mapped (surface));
gtk_widget_set_visible (surface, FALSE);
g_assert_false (gtk_widget_get_visible (surface));
g_assert_false (gtk_widget_get_mapped (surface));
gtk_widget_destroy (surface);
}
static void
on_layer_surface_notify_width (PhoshLayerSurface *surface,
GParamSpec *pspec,
guint *count)
{
(*count)++;
}
static void
test_layer_surface_set_size (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
guint width_count = 0, height_count = 0;
g_autofree char *namespace = g_strdup_printf ("phosh test %s", __func__);
PhoshMonitor *monitor = phosh_test_get_monitor (fixture->state);
GtkWidget *surface = g_object_new (PHOSH_TYPE_LAYER_SURFACE,
"layer-shell", phosh_wayland_get_zwlr_layer_shell_v1(fixture->state->wl),
"wl-output", monitor->wl_output,
"layer", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"kbd-interactivity", FALSE,
"exclusive-zone", -1,
"namespace", namespace,
NULL);
g_assert_true (PHOSH_IS_LAYER_SURFACE (surface));
g_signal_connect (surface,
"notify::height",
G_CALLBACK (on_layer_surface_notify),
&height_count);
g_signal_connect (surface,
"notify::width",
G_CALLBACK (on_layer_surface_notify_width),
&width_count);
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (surface), 10, 10);
g_assert_cmpint (width_count, ==, 1);
g_assert_cmpint (height_count, ==, 1);
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (surface), 10, 11);
g_assert_cmpint (width_count, ==, 1);
g_assert_cmpint (height_count, ==, 2);
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (surface), 11, -1);
g_assert_cmpint (width_count, ==, 2);
g_assert_cmpint (height_count, ==, 2);
g_object_set (surface, "width", 12, NULL);
g_assert_cmpint (width_count, ==, 3);
g_assert_cmpint (height_count, ==, 2);
g_object_set (surface, "height", 12, NULL);
g_assert_cmpint (width_count, ==, 3);
g_assert_cmpint (height_count, ==, 3);
gtk_widget_set_visible (surface, TRUE);
gtk_widget_set_visible (surface, FALSE);
gtk_widget_destroy (surface);
}
static void
test_layer_surface_set_kbd_interactivity (PhoshTestCompositorFixture *fixture, gconstpointer unused)
{
guint count = 0;
gboolean kbd_interacivity;
g_autofree char *namespace = g_strdup_printf ("phosh test %s", __func__);
PhoshMonitor *monitor = phosh_test_get_monitor (fixture->state);
GtkWidget *surface = g_object_new (PHOSH_TYPE_LAYER_SURFACE,
"layer-shell", phosh_wayland_get_zwlr_layer_shell_v1(fixture->state->wl),
"wl-output", monitor->wl_output,
"layer", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"kbd-interactivity", FALSE,
"exclusive-zone", -1,
"namespace", namespace,
NULL);
g_assert_true (PHOSH_IS_LAYER_SURFACE (surface));
g_signal_connect (surface,
"notify::kbd-interactivity",
G_CALLBACK (on_layer_surface_notify),
&count);
g_object_get (surface, "kbd-interactivity", &kbd_interacivity, NULL);
g_assert_false (kbd_interacivity);
phosh_layer_surface_set_kbd_interactivity (PHOSH_LAYER_SURFACE (surface), TRUE);
g_object_get (surface, "kbd-interactivity", &kbd_interacivity, NULL);
g_assert_true (kbd_interacivity);
g_assert_cmpint (count, ==, 1);
phosh_layer_surface_set_kbd_interactivity (PHOSH_LAYER_SURFACE (surface), TRUE);
g_object_get (surface, "kbd-interactivity", &kbd_interacivity, NULL);
g_assert_true (kbd_interacivity);
g_assert_cmpint (count, ==, 1);
phosh_layer_surface_set_kbd_interactivity (PHOSH_LAYER_SURFACE (surface), FALSE);
g_object_get (surface, "kbd-interactivity", &kbd_interacivity, NULL);
g_assert_false (kbd_interacivity);
g_assert_cmpint (count, ==, 2);
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
PHOSH_COMPOSITOR_TEST_ADD ("/phosh/layer-surface/new", test_layer_surface_new);
PHOSH_COMPOSITOR_TEST_ADD ("/phosh/layer-surface/g_object_new", test_layer_surface_g_object_new);
PHOSH_COMPOSITOR_TEST_ADD ("/phosh/layer-surface/set_size", test_layer_surface_set_size);
PHOSH_COMPOSITOR_TEST_ADD ("/phosh/layer-surface/set_kbd_interactivity",
test_layer_surface_set_kbd_interactivity);
return g_test_run ();
}
|