blob: 7017eb00821ce95ad433f766ca30345d9e604391 [file] [log] [blame]
Tiago Vignatti19dadf22013-02-08 14:57:00 +02001/*
Bryce Harringtona20db382015-05-05 11:16:51 -07002 * Copyright © 2015 Samsung Electronics Co., Ltd
Tiago Vignatti19dadf22013-02-08 14:57:00 +02003 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Tiago Vignatti19dadf22013-02-08 14:57:00 +020011 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Tiago Vignatti19dadf22013-02-08 14:57:00 +020024 *
Derek Foreman8771a142015-01-29 16:44:55 -060025 * xwayland-test: Confirm that we can map a window and we're running
26 * under Xwayland, not just X.
Tiago Vignatti19dadf22013-02-08 14:57:00 +020027 *
Derek Foreman8771a142015-01-29 16:44:55 -060028 * This is done in steps:
29 * 1) Confirm that the WL_SURFACE_ID atom exists
30 * 2) Confirm that the window manager's name is "Weston WM"
31 * 3) Make sure we can map a window
Tiago Vignatti19dadf22013-02-08 14:57:00 +020032 */
33
Bryce Harrington12cc4052014-11-19 17:18:33 -080034#include "config.h"
Tiago Vignatti19dadf22013-02-08 14:57:00 +020035
Derek Foreman8771a142015-01-29 16:44:55 -060036#include <unistd.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020037#include <assert.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020038#include <stdlib.h>
39#include <stdio.h>
Derek Foreman8771a142015-01-29 16:44:55 -060040#include <X11/Xlib.h>
41#include <X11/Xatom.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020042#include <string.h>
Tiago Vignatti19dadf22013-02-08 14:57:00 +020043
Bryce Harrington12cc4052014-11-19 17:18:33 -080044#include "weston-test-runner.h"
Pekka Paalanen56b94b52019-11-13 16:41:46 +020045#include "weston-test-fixture-compositor.h"
46
47static enum test_result_code
48fixture_setup(struct weston_test_harness *harness)
49{
50 struct compositor_setup setup;
51
52 compositor_setup_defaults(&setup);
53 setup.xwayland = true;
54
55 return weston_test_harness_execute_as_client(harness, &setup);
56}
57DECLARE_FIXTURE_SETUP(fixture_setup);
Bryce Harrington12cc4052014-11-19 17:18:33 -080058
Tiago Vignatti19dadf22013-02-08 14:57:00 +020059TEST(xwayland_client_test)
60{
Derek Foreman8771a142015-01-29 16:44:55 -060061 Display *display;
62 Window window, root, *support;
63 XEvent event;
64 int screen, status, actual_format;
65 unsigned long nitems, bytes;
66 Atom atom, type_atom, actual_type;
67 char *wm_name;
68
Daniel Stone2295a622016-11-29 11:05:49 +000069 if (access(XSERVER_PATH, X_OK) != 0)
70 exit(77);
71
Derek Foreman8771a142015-01-29 16:44:55 -060072 display = XOpenDisplay(NULL);
73 if (!display)
74 exit(EXIT_FAILURE);
75
76 atom = XInternAtom(display, "WL_SURFACE_ID", True);
77 assert(atom != None);
78
79 atom = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", True);
80 assert(atom != None);
81
82 screen = DefaultScreen(display);
83 root = RootWindow(display, screen);
84
85 status = XGetWindowProperty(display, root, atom, 0L, ~0L,
86 False, XA_WINDOW, &actual_type,
87 &actual_format, &nitems, &bytes,
88 (void *)&support);
89 assert(status == Success);
90
91 atom = XInternAtom(display, "_NET_WM_NAME", True);
92 assert(atom != None);
93 type_atom = XInternAtom(display, "UTF8_STRING", True);
94 assert(atom != None);
95 status = XGetWindowProperty(display, *support, atom, 0L, BUFSIZ,
96 False, type_atom, &actual_type,
97 &actual_format, &nitems, &bytes,
98 (void *)&wm_name);
99 assert(status == Success);
100 assert(nitems);
101 assert(strcmp("Weston WM", wm_name) == 0);
102 free(support);
103 free(wm_name);
104
105 window = XCreateSimpleWindow(display, root, 100, 100, 300, 300, 1,
106 BlackPixel(display, screen),
107 WhitePixel(display, screen));
108 XSelectInput(display, window, ExposureMask);
109 XMapWindow(display, window);
110
Derek Foreman8771a142015-01-29 16:44:55 -0600111 while (1) {
112 XNextEvent(display, &event);
113 if (event.type == Expose)
114 break;
115 }
116
117 XCloseDisplay(display);
Tiago Vignatti19dadf22013-02-08 14:57:00 +0200118}