1//go:build linux
2
3package protocol_test
4
5import (
6 "encoding/binary"
7 "errors"
8 "testing"
9
10 "github.com/bnema/wlturbo"
11 "github.com/bnema/wlturbo/protocol/xdgshell"
12)
13
14func TestAnnouncedVersionNegotiation(t *testing.T) {
15 c, p := pair(t)
16 d, e := wlturbo.ConnectFromConn(c)
17 noerr(t, e)
18 defer d.Close()
19 request(t, p)
20 iface := xdgshell.XdgWmBaseInterface
21 if v, e := d.Registry().BindNegotiated(iface, 6, xdgshell.NewXdgWmBase(d.Context())); v != 0 || !errors.Is(e, wlturbo.ErrGlobalNotFound) {
22 t.Fatalf("missing: %d %v", v, e)
23 }
24 if v, e := d.Registry().BindNegotiated(iface, 0, xdgshell.NewXdgWmBase(d.Context())); v != 0 || e == nil || errors.Is(e, wlturbo.ErrGlobalNotFound) {
25 t.Fatalf("unsupported zero: %d %v", v, e)
26 }
27 for i, version := range []uint32{2, 9} {
28 name := uint32(30 + i)
29 announcement := append(msg(0, 0, name)[8:], str(iface)...)
30 announcement = append(announcement, msg(0, 0, version)[8:]...)
31 send(t, p, payload(d.Registry().ID(), 0, announcement...))
32 noerr(t, d.Dispatch())
33 proxy := xdgshell.NewXdgWmBase(d.Context())
34 if v, e := d.Registry().BindNegotiated(iface, 0, proxy); v != 0 || e == nil || errors.Is(e, wlturbo.ErrGlobalNotFound) {
35 t.Fatalf("supported zero with global: %d %v", v, e)
36 }
37 negotiated, e := d.Registry().BindNegotiated(iface, 6, proxy)
38 noerr(t, e)
39 want := version
40 if want > 6 {
41 want = 6
42 }
43 _, op, body := request(t, p)
44 if op != 0 || negotiated != want || binary.NativeEndian.Uint32(body) != name || binary.NativeEndian.Uint32(body[len(body)-8:]) != want || binary.NativeEndian.Uint32(body[len(body)-4:]) != proxy.ID() {
45 t.Fatalf("server=%d negotiated=%d wire=%x", version, negotiated, body)
46 }
47 send(t, p, msg(d.Registry().ID(), 1, name))
48 noerr(t, d.Dispatch())
49 }
50}