blob: 10eea1611e279691c1f163caf2bbadcdb5fde6d1 [file] [log] [blame]
Tiago Vignatti19dadf22013-02-08 14:57:00 +02001/*
Derek Foreman8771a142015-01-29 16:44:55 -06002 * Copyright © 2015 Samsung
Tiago Vignatti19dadf22013-02-08 14:57:00 +02003 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
Derek Foreman8771a142015-01-29 16:44:55 -060022 * xwayland-test: Confirm that we can map a window and we're running
23 * under Xwayland, not just X.
Tiago Vignatti19dadf22013-02-08 14:57:00 +020024 *
Derek Foreman8771a142015-01-29 16:44:55 -060025 * This is done in steps:
26 * 1) Confirm that the WL_SURFACE_ID atom exists
27 * 2) Confirm that the window manager's name is "Weston WM"
28 * 3) Make sure we can map a window
Tiago Vignatti19dadf22013-02-08 14:57:00 +020029 */
30
Bryce Harrington12cc4052014-11-19 17:18:33 -080031#include "config.h"
Tiago Vignatti19dadf22013-02-08 14:57:00 +020032
Derek Foreman8771a142015-01-29 16:44:55 -060033#include <unistd.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020034#include <assert.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020035#include <stdlib.h>
36#include <stdio.h>
Derek Foreman8771a142015-01-29 16:44:55 -060037#include <X11/Xlib.h>
38#include <X11/Xatom.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020039#include <string.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020040
Bryce Harrington12cc4052014-11-19 17:18:33 -080041#include "weston-test-runner.h"
42
Tiago Vignatti19dadf22013-02-08 14:57:00 +020043TEST(xwayland_client_test)
44{
Derek Foreman8771a142015-01-29 16:44:55 -060045 Display *display;
46 Window window, root, *support;
47 XEvent event;
48 int screen, status, actual_format;
49 unsigned long nitems, bytes;
50 Atom atom, type_atom, actual_type;
51 char *wm_name;
52
53 display = XOpenDisplay(NULL);
54 if (!display)
55 exit(EXIT_FAILURE);
56
57 atom = XInternAtom(display, "WL_SURFACE_ID", True);
58 assert(atom != None);
59
60 atom = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", True);
61 assert(atom != None);
62
63 screen = DefaultScreen(display);
64 root = RootWindow(display, screen);
65
66 status = XGetWindowProperty(display, root, atom, 0L, ~0L,
67 False, XA_WINDOW, &actual_type,
68 &actual_format, &nitems, &bytes,
69 (void *)&support);
70 assert(status == Success);
71
72 atom = XInternAtom(display, "_NET_WM_NAME", True);
73 assert(atom != None);
74 type_atom = XInternAtom(display, "UTF8_STRING", True);
75 assert(atom != None);
76 status = XGetWindowProperty(display, *support, atom, 0L, BUFSIZ,
77 False, type_atom, &actual_type,
78 &actual_format, &nitems, &bytes,
79 (void *)&wm_name);
80 assert(status == Success);
81 assert(nitems);
82 assert(strcmp("Weston WM", wm_name) == 0);
83 free(support);
84 free(wm_name);
85
86 window = XCreateSimpleWindow(display, root, 100, 100, 300, 300, 1,
87 BlackPixel(display, screen),
88 WhitePixel(display, screen));
89 XSelectInput(display, window, ExposureMask);
90 XMapWindow(display, window);
91
92 alarm(4);
93 while (1) {
94 XNextEvent(display, &event);
95 if (event.type == Expose)
96 break;
97 }
98
99 XCloseDisplay(display);
Tiago Vignatti19dadf22013-02-08 14:57:00 +0200100 exit(EXIT_SUCCESS);
101}