fix weston launch error
[platform/upstream/weston.git] / tests / xwayland-test.c
1 /*
2  * Copyright © 2015 Samsung Electronics Co., Ltd
3  *
4  * 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:
11  *
12  * 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.
24  *
25  * xwayland-test: Confirm that we can map a window and we're running
26  *                under Xwayland, not just X.
27  *
28  *                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
32  */
33
34 #include "config.h"
35
36 #include <unistd.h>
37 #include <assert.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <X11/Xlib.h>
41 #include <X11/Xatom.h>
42 #include <string.h>
43
44 #include "weston-test-runner.h"
45
46 TEST(xwayland_client_test)
47 {
48         Display *display;
49         Window window, root, *support;
50         XEvent event;
51         int screen, status, actual_format;
52         unsigned long nitems, bytes;
53         Atom atom, type_atom, actual_type;
54         char *wm_name;
55
56         if (access(XSERVER_PATH, X_OK) != 0)
57                 exit(77);
58
59         display = XOpenDisplay(NULL);
60         if (!display)
61                 exit(EXIT_FAILURE);
62
63         atom = XInternAtom(display, "WL_SURFACE_ID", True);
64         assert(atom != None);
65
66         atom = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", True);
67         assert(atom != None);
68
69         screen = DefaultScreen(display);
70         root = RootWindow(display, screen);
71
72         status = XGetWindowProperty(display, root, atom, 0L, ~0L,
73                                     False, XA_WINDOW, &actual_type,
74                                     &actual_format, &nitems, &bytes,
75                                     (void *)&support);
76         assert(status == Success);
77
78         atom = XInternAtom(display, "_NET_WM_NAME", True);
79         assert(atom != None);
80         type_atom = XInternAtom(display, "UTF8_STRING", True);
81         assert(atom != None);
82         status = XGetWindowProperty(display, *support, atom, 0L, BUFSIZ,
83                                     False, type_atom, &actual_type,
84                                     &actual_format, &nitems, &bytes,
85                                     (void *)&wm_name);
86         assert(status == Success);
87         assert(nitems);
88         assert(strcmp("Weston WM", wm_name) == 0);
89         free(support);
90         free(wm_name);
91
92         window = XCreateSimpleWindow(display, root, 100, 100, 300, 300, 1,
93                                      BlackPixel(display, screen),
94                                      WhitePixel(display, screen));
95         XSelectInput(display, window, ExposureMask);
96         XMapWindow(display, window);
97
98         alarm(4);
99         while (1) {
100                 XNextEvent(display, &event);
101                 if (event.type == Expose)
102                         break;
103         }
104
105         XCloseDisplay(display);
106         exit(EXIT_SUCCESS);
107 }