Test that it is possible to implement and use an interface with a
symbol prefix.

Signed-off-by: Jonas Ådahl <[email protected]>
---
 .gitignore                        |   5 ++
 Makefile.am                       |  30 +++++++-
 tests/symbol-prefix-test-client.c |  77 ++++++++++++++++++++
 tests/symbol-prefix-test-server.c | 145 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+), 2 deletions(-)
 create mode 100644 tests/symbol-prefix-test-client.c
 create mode 100644 tests/symbol-prefix-test-server.c

diff --git a/.gitignore b/.gitignore
index 8da9861..d2f59e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,8 @@ exec-fd-leak-checker
 fixed-benchmark
 /wayland-scanner
 protocol/*.[ch]
+prefixed-wayland-protocol.c
+prefixed-wayland-server-protocol-core.h
+prefixed-wayland-client-protocol-core.h
+symbol-prefix-test-server
+symbol-prefix-test-client
diff --git a/Makefile.am b/Makefile.am
index fdc5689..dcb93a6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -114,7 +114,9 @@ protocol/%-client-protocol-core.h : 
$(top_srcdir)/protocol/%.xml
 BUILT_SOURCES =                                        \
        $(nodist_libwayland_server_la_SOURCES)  \
        $(nodist_libwayland_client_la_SOURCES)  \
-       $(nodist_headers_test_SOURCES)
+       $(nodist_headers_test_SOURCES)          \
+       $(nodist_symbol_prefix_test_server_SOURCES)     \
+       $(nodist_symbol_prefix_test_client_SOURCES)
 
 CLEANFILES = $(BUILT_SOURCES) doc/doxygen/doxygen_sqlite3.db
 DISTCLEANFILES = src/wayland-version.h
@@ -164,7 +166,11 @@ built_test_programs =                              \
        message-test                            \
        headers-test                            \
        compositor-introspection-test           \
-       protocol-logger-test
+       protocol-logger-test                    \
+       symbol-prefix-test-server
+
+built_test_program_helpers =                   \
+       symbol-prefix-test-client
 
 if ENABLE_CPP_TEST
 built_test_programs += cpp-compile-test
@@ -172,6 +178,7 @@ endif
 
 AM_TESTS_ENVIRONMENT =                                                 \
        export WAYLAND_SCANNER='$(top_builddir)/wayland-scanner'        \
+       export TOP_BUILDDIR='$(top_builddir)'                           \
        TEST_DATA_DIR='$(top_srcdir)/tests/data'                        \
        TEST_OUTPUT_DIR='$(top_builddir)/tests/output'                  \
        SED=$(SED)                                                      \
@@ -182,6 +189,7 @@ TESTS = $(built_test_programs)                      \
 
 noinst_PROGRAMS =                              \
        $(built_test_programs)                  \
+       $(built_test_program_helpers)           \
        exec-fd-leak-checker                    \
        fixed-benchmark
 
@@ -200,6 +208,14 @@ libtest_runner_la_LIBADD =                 \
        libwayland-server.la                    \
        -lrt -ldl $(FFI_LIBS)
 
+prefixed-wayland-protocol.c : protocol/wayland.xml
+       $(AM_V_GEN)$(wayland_scanner) -c -p prefix_ code $< $@
+
+prefixed-wayland-server-protocol-core.h : protocol/wayland.xml
+       $(AM_V_GEN)$(wayland_scanner) -c -p prefix_ server-header $< $@
+
+prefixed-wayland-client-protocol-core.h : protocol/wayland.xml
+       $(AM_V_GEN)$(wayland_scanner) -c -p prefix_ client-header $< $@
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -245,6 +261,16 @@ headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =                  \
        protocol/wayland-server-protocol-core.h \
        protocol/wayland-client-protocol-core.h
+symbol_prefix_test_server_SOURCES = tests/symbol-prefix-test-server.c
+nodist_symbol_prefix_test_server_SOURCES = \
+       prefixed-wayland-protocol.c \
+       prefixed-wayland-server-protocol-core.h
+symbol_prefix_test_server_LDADD = libtest-runner.la
+symbol_prefix_test_client_SOURCES = tests/symbol-prefix-test-client.c
+nodist_symbol_prefix_test_client_SOURCES = \
+       prefixed-wayland-protocol.c \
+       prefixed-wayland-client-protocol-core.h
+symbol_prefix_test_client_LDADD = libtest-runner.la
 
 if ENABLE_CPP_TEST
 cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
diff --git a/tests/symbol-prefix-test-client.c 
b/tests/symbol-prefix-test-client.c
new file mode 100644
index 0000000..6de1f53
--- /dev/null
+++ b/tests/symbol-prefix-test-client.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "wayland-client-core.h"
+#include "prefixed-wayland-client-protocol-core.h"
+
+static struct wl_display *display;
+
+static void
+registry_handle_global(void *data, struct wl_registry *registry,
+                      uint32_t id, const char *interface, uint32_t version)
+{
+       struct wl_compositor *compositor;
+       struct wl_surface *surface;
+
+       assert(strcmp(interface, "wl_compositor") == 0);
+
+       compositor = wl_registry_bind(registry, id,
+                                     &prefix_wl_compositor_interface,
+                                     version);
+       assert(compositor);
+       surface = wl_compositor_create_surface(compositor);
+       assert(surface);
+       wl_display_flush(display);
+}
+
+static const struct wl_registry_listener registry_listener = {
+       registry_handle_global,
+       NULL
+};
+
+int
+main(void)
+{
+       struct wl_registry *registry;
+
+       alarm(5);
+
+       display = wl_display_connect(NULL);
+       assert(display);
+
+       registry = wl_display_get_registry(display);
+       assert(registry);
+       wl_registry_add_listener(registry, &registry_listener, NULL);
+
+       while (!wl_display_dispatch(display));
+
+       return 0;
+}
diff --git a/tests/symbol-prefix-test-server.c 
b/tests/symbol-prefix-test-server.c
new file mode 100644
index 0000000..6b073f5
--- /dev/null
+++ b/tests/symbol-prefix-test-server.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "wayland-server-core.h"
+#include "prefixed-wayland-server-protocol-core.h"
+
+static bool surface_created;
+static struct wl_display *display;
+
+static void
+handle_create_surface(struct wl_client *client,
+                     struct wl_resource *resource, uint32_t id)
+{
+       struct wl_resource *surface_resource;
+
+       surface_resource =
+               wl_resource_create(client, &prefix_wl_surface_interface,
+                                  wl_resource_get_version(resource), id);
+       assert(surface_resource);
+
+       surface_created = true;
+       wl_display_terminate(display);
+}
+
+static const struct wl_compositor_interface compositor_implementation = {
+       handle_create_surface,
+       NULL
+};
+
+static void
+bind_compositor(struct wl_client *client, void *user_data,
+               uint32_t version, uint32_t id)
+{
+       struct wl_resource *resource;
+
+       resource = wl_resource_create(client, &prefix_wl_compositor_interface,
+                                     version, id);
+       assert(resource);
+
+       wl_resource_set_implementation(resource, &compositor_implementation,
+                                      NULL, NULL);
+}
+
+static pid_t
+spawn_client(void)
+{
+       int fds[2];
+       pid_t pid;
+       struct wl_client *client;
+
+       assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
+       pid = fork();
+       assert(pid != -1);
+
+       if (pid == 0) {
+               char fd_string[256];
+               char *builddir;
+               char test_client_path[2048];
+
+               close(fds[1]);
+               builddir = getenv("TOP_BUILDDIR");
+               assert(builddir && strlen(builddir) > 0);
+               snprintf(test_client_path, sizeof test_client_path,
+                        "%s/symbol-prefix-test-client",
+                        builddir);
+
+               snprintf(fd_string, sizeof fd_string, "%d", fds[0]);
+               setenv("WAYLAND_SOCKET", fd_string, 0);
+
+               execl(test_client_path, test_client_path, NULL);
+               assert(!"Failed to execute client");
+       }
+
+       close(fds[0]);
+       client = wl_client_create(display, fds[1]);
+       if (!client) {
+               kill(pid, SIGTERM);
+               assert(!"Failed to create client");
+       }
+
+       return pid;
+}
+
+int
+main(void)
+{
+       struct wl_global *compositor;
+       pid_t client_pid;
+       int client_status = 0;
+
+       alarm(5);
+
+       display = wl_display_create();
+       assert(display);
+
+       assert(!wl_display_add_socket(display, "symbol-prefix-test-display-0"));
+       compositor = wl_global_create(display, &prefix_wl_compositor_interface,
+                                     1, NULL, bind_compositor);
+
+       client_pid = spawn_client();
+
+       wl_display_run(display);
+       assert(surface_created);
+
+       assert(waitpid(client_pid, &client_status, 0) == client_pid);
+       assert(client_status == 0);
+
+       wl_global_destroy(compositor);
+       wl_display_destroy(display);
+
+       return 0;
+}
-- 
2.13.0

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to