1package main
2
3import "testing"
4
5// TestReplyLayouts checks reply containers against the independent packet-size
6// walker and pins list-view classification for representative replies.
7func TestReplyLayouts(t *testing.T) {
8 kinds := map[string]map[string]string{
9 "xproto.GetPropertyReply": {"Value": "bytes"},
10 "xproto.QueryTreeReply": {"Children": "scalar"},
11 "xproto.ListExtensionsReply": {"Names": "iter"},
12 "xproto.QueryFontReply": {"Properties": "struct", "CharInfos": "struct"},
13 "xproto.ListHostsReply": {"Hosts": "iter"},
14 "render.QueryPictFormatsReply": {"Formats": "struct", "Screens": "iter", "Subpixels": "scalar"},
15 "xfixes.GetCursorImageAndNameReply": {"CursorImage": "scalar", "Name": "bytes"},
16 }
17 for _, m := range testModules(t) {
18 replies, _, err := resolveReplies(m)
19 if err != nil {
20 t.Fatal(err)
21 }
22 for _, r := range replies {
23 var node *Node
24 for _, n := range m.Root.Children {
25 if n.Kind == "request" && goName(n.Attr["name"]) == r.Req {
26 for _, c := range n.Children {
27 if c.Kind == "reply" {
28 node = c
29 }
30 }
31 }
32 }
33 want, err := packetFixed(m, node, true)
34 if err != nil {
35 t.Fatal(err)
36 }
37 if got := max(r.C.Fixed, 32); got != want {
38 t.Errorf("%s.%s fixed %d, packet walker %d", m.Pkg, r.C.Name, got, want)
39 }
40 for _, mem := range r.C.Members {
41 if exp, ok := kinds[m.Pkg+"."+r.C.Name]; ok && mem.Kind == "list" {
42 if exp[mem.Method] != mem.ListKind {
43 t.Errorf("%s.%s.%s kind %s want %s", m.Pkg, r.C.Name, mem.Method, mem.ListKind, exp[mem.Method])
44 }
45 delete(exp, mem.Method)
46 }
47 }
48 }
49 }
50 for name, rest := range kinds {
51 if len(rest) != 0 {
52 t.Errorf("%s: unchecked lists %v", name, rest)
53 }
54 }
55}
56
57func TestReplyReservedGetter(t *testing.T) {
58 m := &Module{Pkg: "x", Symbols: map[string]*Type{}, Names: map[string]*Node{}}
59 nodes := []*Node{
60 {Kind: "pad", Attr: map[string]string{"bytes": "1"}},
61 {Kind: "field", Attr: map[string]string{"name": "raw", "type": "CARD32"}},
62 }
63 c, err := buildContainer(m, "XReply", "r", nodes, layoutReply, "Raw")
64 if err != nil {
65 t.Fatal(err)
66 }
67 if c.Members[1].Method != "Raw_" || c.Members[1].Static != 8 || c.Fixed != 12 {
68 t.Fatalf("%+v", c.Members[1])
69 }
70}