This patch introduces a set of functions that can create a display
and clients for tests.
On server side the user can use functions:
display_create()
display_destroy()
create_client()
display_run()
display_resume()
and on client side the user can use:
client_connect()
client_disconnect()
stop_display()
The stop_display() and display_resume() are functions that serve as a barrier
and also allow the display to take some action after the display_run() was
called,
because after the display is stopped, it can run arbitrary code until it calls
display_resume().
client_connect() function connects to wayland display and creates a proxy to
test_compositor global object, so it can ask for stopping the display later
using stop_display().
An example:
void
client_main()
{
/* or client can use wl_display_connect(NULL)
* and do all the stuff manually */
struct client *c = client_connect();
/* do some stuff, ... */
/* stop the display so that it can
* do some other stuff */
stop_display(c, 1);
/* ... */
client_disconnect(c);
}
TEST(dummy_tst)
{
struct display *d = display_create();
/* set up the display */
wl_global_create(d-wl_display, ...);
/* ... */
create_client(d, client_main);
display_run();
/* if we are here, the display has been stopped
* and we can do some code, i. e. create another global or so */
wl_global_create(d-wl_display, ...);
/* ... */
display_resume(d); /* resume display and clients */
display_destroy(d);
}
v2:
added/changed message in few asserts that were not clear
fixed codying style issues and typo
client_create_with_name: fixed a condition in an assert
get_socket_name: use also pid
check_error: fix errno - err
Signed-off-by: Marek Chalupa mchqwe...@gmail.com
---
Makefile.am | 3 +-
tests/test-compositor.c | 467
tests/test-compositor.h | 97 ++
3 files changed, 566 insertions(+), 1 deletion(-)
create mode 100644 tests/test-compositor.c
create mode 100644 tests/test-compositor.h
diff --git a/Makefile.am b/Makefile.am
index fee19ab..dee95c2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,7 +142,8 @@ check_LTLIBRARIES = libtest-runner.la
libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
- tests/test-helpers.c
+ tests/test-helpers.c\
+ tests/test-compositor.c
libtest_runner_la_LIBADD = \
libwayland-util.la \
libwayland-client.la\
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
new file mode 100644
index 000..2f54276
--- /dev/null
+++ b/tests/test-compositor.c
@@ -0,0 +1,467 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided as
+ * is without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include assert.h
+#include errno.h
+#include stdio.h
+#include string.h
+#include stdlib.h
+#include unistd.h
+#include sys/time.h
+#include sys/socket.h
+#include sys/wait.h
+#include signal.h
+
+#include test-compositor.h
+
+/* --- Protocol --- */
+struct test_compositor;
+
+static const struct wl_message tc_requests[] = {
+ /* this request serves as a barrier for synchronizing*/
+ { stop_display, u, NULL }
+};
+
+static const struct wl_message tc_events[] = {
+ { display_resumed, , NULL }
+};
+
+const struct wl_interface test_compositor_interface = {
+ test, 1,
+ 1, tc_requests,
+ 1, tc_events
+};
+
+struct test_compositor_interface {
+ void (*stop_display)(struct wl_client *client,
+struct wl_resource *resource,
+