6f28a86c455a58322811e7296d3b81a9b0828cef
[test/generic/wayland-fits.git] / src / test / core / shell_surface.cpp
1 /*
2  * Copyright © 2013 Intel Corporation
3  *
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  */
22
23 #include "shell_surface.h"
24
25 ShellSurface::ShellSurface(const Shell& shell, const Surface& surface)
26         : shell_(shell)
27         , surface_(surface)
28         , wl_shell_surface_(
29                 wl_shell_get_shell_surface(shell, surface))
30 {
31         ASSERT(wl_shell_surface_ != NULL);
32
33         wl_shell_surface_set_user_data(*this, this);
34         
35         static const wl_shell_surface_listener listener = {
36                 ping, configure, popupDone};
37
38         wl_shell_surface_add_listener(*this, &listener, this);
39
40         wl_shell_surface_set_toplevel(*this);
41
42         shell.display().roundtrip();
43 }
44
45 ShellSurface::~ShellSurface()
46 {
47         wl_shell_surface_destroy(*this);
48 }
49
50 /*static*/ void ShellSurface::ping(
51         void *data, wl_shell_surface *wl_shell_surface, uint32_t serial)
52 {
53         ShellSurface* shellSurface = static_cast<ShellSurface*>(data);
54         ASSERT(wl_shell_surface == *shellSurface);
55
56         wl_shell_surface_pong(wl_shell_surface, serial);
57 }
58
59 /*static*/ void ShellSurface::configure(
60         void *data, wl_shell_surface *wl_shell_surface, uint32_t edges,
61         int32_t width, int32_t height)
62 {
63         ShellSurface* shellSurface = static_cast<ShellSurface*>(data);
64         ASSERT(wl_shell_surface == *shellSurface);
65 }
66
67 /*static*/ void ShellSurface::popupDone(
68         void *data, wl_shell_surface *wl_shell_surface)
69 {
70         ShellSurface* shellSurface = static_cast<ShellSurface*>(data);
71         ASSERT(wl_shell_surface == *shellSurface);
72 }
73
74 TEST(ShellSurface, "Core/Wrapper")
75 {
76         Display display;
77         Compositor compositor(display);
78         Shell shell(display);
79         Surface surface(compositor);
80         ShellSurface ss(shell, surface);
81
82         FAIL_UNLESS_EQUAL(&ss.shell(), &shell);
83         FAIL_UNLESS_EQUAL(&ss.surface(), &surface);
84         FAIL_IF((wl_shell_surface*)ss == NULL);
85         FAIL_UNLESS_EQUAL(wl_shell_surface_get_user_data(ss), &ss);
86 }
87