1package main
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestUntypedNewIDEvent(t *testing.T) {
9 g := &gen{owners: map[string]string{"test_device": ""}, imports: map[string]string{}}
10 b, err := g.generate(protocol{Interfaces: []iface{{Name: "test_device", Version: 1, Events: []message{{Name: "created", Args: []arg{{Name: "id", Type: "new_id"}}}}}}}, "test")
11 if err != nil {
12 t.Fatal(err)
13 }
14 s := string(b)
15 if !strings.Contains(s, `Signature: "sun"`) || !strings.Contains(s, `server.String(&p, id.Iface().Name, false), server.Uint(uint32(id.Version())), server.NewID(id)`) {
16 t.Fatalf("untyped new_id event missing wire args:\n%s", s)
17 }
18}
19
20func TestSignature(t *testing.T) {
21 cases := []struct {
22 m message
23 want string
24 }{
25 {message{Name: "bind", Args: []arg{{Type: "uint"}, {Type: "new_id"}}}, "usun"},
26 {message{Since: 2, Args: []arg{{Type: "object", Nullable: true}, {Type: "fd"}, {Type: "fixed"}}}, "2?ohf"},
27 {message{Args: []arg{{Type: "new_id", Interface: "wl_surface"}}}, "n"},
28 }
29 for _, c := range cases {
30 if got := signature(c.m); got != c.want {
31 t.Errorf("signature(%+v)=%q, want %q", c.m, got, c.want)
32 }
33 }
34}