File: test-dnd.c

package info (click to toggle)
notify-osd 0.9.35%2B15.04.20150126-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 2,016 kB
  • ctags: 1,837
  • sloc: ansic: 17,819; python: 1,100; makefile: 457; cs: 335; sh: 103; xml: 48
file content (139 lines) | stat: -rw-r--r-- 3,964 bytes parent folder | download | duplicates (3)
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
/*******************************************************************************
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
**      10        20        30        40        50        60        70        80
**
** notify-osd
**
** test-dnd.c - test the do-not-disturb mode code
**
** Copyright 2009 Canonical Ltd.
**
** Authors:
**    Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
**    David Barth <david.barth@canonical.com>
**
** This program is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License version 3, as published
** by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranties of
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>

#include "dnd.h"
#include "util.h"

#include <libwnck/libwnck.h>

#define TEST_DBUS_NAME "org.freedesktop.Notificationstest"

static
void
test_dnd_screensaver (gpointer fixture, gconstpointer user_data)
{
	gboolean test = dnd_is_screensaver_inhibited();

	if (test)
		g_debug ("screensaver is inhibited");

	test = dnd_is_screensaver_active();

	if (test)
		g_debug ("screensaver is active");
}

static
gboolean
check_fullscreen (GMainLoop *loop)
{
	g_assert (dnd_has_one_fullscreen_window());
	g_main_loop_quit (loop);
	return FALSE;
}

static
gboolean
check_no_fullscreen (GMainLoop *loop)
{
	g_assert (!dnd_has_one_fullscreen_window());
	g_main_loop_quit (loop);
	return FALSE;
}

// FIXME: fails under compiz, needs to be able handle compiz' viewports
static
WnckWorkspace *
find_free_workspace (WnckScreen *screen)
{
	WnckWorkspace *active_workspace = wnck_screen_get_active_workspace (screen);
	GList *lst = wnck_screen_get_workspaces (screen);
	if (lst->data != active_workspace) {
		return WNCK_WORKSPACE(lst->data);
	}
	lst = g_list_next (lst);
	g_assert (lst);
	return WNCK_WORKSPACE(lst->data);
}

static
void
test_dnd_fullscreen (gpointer fixture, gconstpointer user_data)
{
	g_assert (!dnd_has_one_fullscreen_window());

	GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_fullscreen (GTK_WINDOW (window));
	gtk_widget_show_now (window);

	GMainLoop* loop = g_main_loop_new (NULL, FALSE);
	g_timeout_add (2000, (GSourceFunc) check_fullscreen, loop);
	g_main_loop_run (loop);

	// Move window to a free workspace, dnd_has_one_fullscreen_window should
	// not find it anymore
	WnckScreen *screen = wnck_screen_get_default ();
	WnckWindow *wnck_window = wnck_screen_get_active_window (screen);
	g_assert (wnck_window);
	WnckWorkspace *free_workspace = find_free_workspace (screen);
	g_assert (free_workspace);
	wnck_window_move_to_workspace (wnck_window, free_workspace);

	g_timeout_add (2000, (GSourceFunc) check_no_fullscreen, loop);
	g_main_loop_run (loop);

	gtk_widget_destroy (window);
}

GTestSuite *
test_dnd_create_test_suite (void)
{
	GTestSuite* ts      = NULL;
	gchar*      wm_name = NULL;

	ts = g_test_create_suite ("dnd");
#define TC(x) g_test_create_case(#x, 0, NULL, NULL, x, NULL)
	g_test_suite_add (ts, TC(test_dnd_screensaver));

	// FIXME: test_dnd_fullscreen() fails under compiz because of it using
	// viewports instead of workspaces
	wm_name = get_wm_name (gdk_x11_display_get_xdisplay (gdk_display_get_default ()));
	if (wm_name && g_ascii_strcasecmp (WM_NAME_COMPIZ, wm_name))
		g_test_suite_add (ts, TC(test_dnd_fullscreen));
	else
	{
		g_print ("*** WARNING: Skipping /dnd/test_dnd_fullscreen ");
		g_print ("because it does currently not work under compiz!\n");
	}

	return ts;
}