package main import "testing" // TestReplyLayouts checks reply containers against the independent packet-size // walker and pins list-view classification for representative replies. func TestReplyLayouts(t *testing.T) { kinds := map[string]map[string]string{ "xproto.GetPropertyReply": {"Value": "bytes"}, "xproto.QueryTreeReply": {"Children": "scalar"}, "xproto.ListExtensionsReply": {"Names": "iter"}, "xproto.QueryFontReply": {"Properties": "struct", "CharInfos": "struct"}, "xproto.ListHostsReply": {"Hosts": "iter"}, "render.QueryPictFormatsReply": {"Formats": "struct", "Screens": "iter", "Subpixels": "scalar"}, "xfixes.GetCursorImageAndNameReply": {"CursorImage": "scalar", "Name": "bytes"}, } for _, m := range testModules(t) { replies, _, err := resolveReplies(m) if err != nil { t.Fatal(err) } for _, r := range replies { var node *Node for _, n := range m.Root.Children { if n.Kind == "request" && goName(n.Attr["name"]) == r.Req { for _, c := range n.Children { if c.Kind == "reply" { node = c } } } } want, err := packetFixed(m, node, true) if err != nil { t.Fatal(err) } if got := max(r.C.Fixed, 32); got != want { t.Errorf("%s.%s fixed %d, packet walker %d", m.Pkg, r.C.Name, got, want) } for _, mem := range r.C.Members { if exp, ok := kinds[m.Pkg+"."+r.C.Name]; ok && mem.Kind == "list" { if exp[mem.Method] != mem.ListKind { t.Errorf("%s.%s.%s kind %s want %s", m.Pkg, r.C.Name, mem.Method, mem.ListKind, exp[mem.Method]) } delete(exp, mem.Method) } } } } for name, rest := range kinds { if len(rest) != 0 { t.Errorf("%s: unchecked lists %v", name, rest) } } } func TestReplyReservedGetter(t *testing.T) { m := &Module{Pkg: "x", Symbols: map[string]*Type{}, Names: map[string]*Node{}} nodes := []*Node{ {Kind: "pad", Attr: map[string]string{"bytes": "1"}}, {Kind: "field", Attr: map[string]string{"name": "raw", "type": "CARD32"}}, } c, err := buildContainer(m, "XReply", "r", nodes, layoutReply, "Raw") if err != nil { t.Fatal(err) } if c.Members[1].Method != "Raw_" || c.Members[1].Static != 8 || c.Fixed != 12 { t.Fatalf("%+v", c.Members[1]) } }