File: test-async-failure.c

package info (click to toggle)
gtk4-layer-shell 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 832 kB
  • sloc: ansic: 5,618; xml: 417; python: 407; makefile: 14
file content (69 lines) | stat: -rw-r--r-- 2,056 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "integration-test-common.h"

#include "ext-session-lock-v1-client.h"

enum lock_state_t state = 0;
struct ext_session_lock_manager_v1* global;
GtkSessionLockInstance* lock;

static void wl_registry_handle_global(
    void* _data,
    struct wl_registry* registry,
    uint32_t id,
    const char* interface,
    uint32_t version
) {
    (void)_data;

    if (strcmp(interface, ext_session_lock_manager_v1_interface.name) == 0) {
        global = wl_registry_bind(registry, id, &ext_session_lock_manager_v1_interface, version);
    }
}

static void wl_registry_handle_global_remove(void* _data, struct wl_registry* _registry, uint32_t _id) {
    (void)_data;
    (void)_registry;
    (void)_id;
}

static const struct wl_registry_listener wl_registry_listener = {
    .global = wl_registry_handle_global,
    .global_remove = wl_registry_handle_global_remove,
};

static void bind_global(struct wl_display* display) {
    struct wl_registry* registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &wl_registry_listener, NULL);
    wl_display_roundtrip(display);
    wl_registry_destroy(registry);
}

static void callback_0() {
    // We lock the display without going through the library in order to simulate a lock being held by another process
    bind_global(gdk_wayland_display_get_wl_display(gdk_display_get_default()));
    ASSERT(global);
    struct ext_session_lock_v1* session_lock = ext_session_lock_manager_v1_lock(global);
    (void)session_lock;
}

static void callback_1() {
    EXPECT_MESSAGE(ext_session_lock_manager_v1 .lock);
    EXPECT_MESSAGE(ext_session_lock_v1 .get_lock_surface);
    EXPECT_MESSAGE(ext_session_lock_v1 .finished);

    lock = gtk_session_lock_instance_new();
    connect_lock_signals(lock, &state);

    // This may return true or false depending on if the monitor signal handler roundtrips
    gtk_session_lock_instance_lock(lock);
}

static void callback_2() {
    ASSERT_EQ(state, LOCK_STATE_FAILED, "%d");
}

TEST_CALLBACKS(
    callback_0,
    callback_1,
    callback_2,
)