Blame


1 4b33cdd0 2015-11-30 stephen.d package p9p
2 4b33cdd0 2015-11-30 stephen.d
3 4b33cdd0 2015-11-30 stephen.d import (
4 4b33cdd0 2015-11-30 stephen.d "bytes"
5 4b33cdd0 2015-11-30 stephen.d "errors"
6 4b33cdd0 2015-11-30 stephen.d "reflect"
7 4b33cdd0 2015-11-30 stephen.d "testing"
8 4b33cdd0 2015-11-30 stephen.d "time"
9 4b33cdd0 2015-11-30 stephen.d )
10 4b33cdd0 2015-11-30 stephen.d
11 4b33cdd0 2015-11-30 stephen.d func TestEncodeDecode(t *testing.T) {
12 4b33cdd0 2015-11-30 stephen.d codec := NewCodec()
13 4b33cdd0 2015-11-30 stephen.d for _, testcase := range []struct {
14 4b33cdd0 2015-11-30 stephen.d description string
15 4b33cdd0 2015-11-30 stephen.d target interface{}
16 4b33cdd0 2015-11-30 stephen.d marshaled []byte
17 4b33cdd0 2015-11-30 stephen.d }{
18 4b33cdd0 2015-11-30 stephen.d {
19 4b33cdd0 2015-11-30 stephen.d description: "uint8",
20 4b33cdd0 2015-11-30 stephen.d target: uint8('U'),
21 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{0x55},
22 4b33cdd0 2015-11-30 stephen.d },
23 4b33cdd0 2015-11-30 stephen.d {
24 4b33cdd0 2015-11-30 stephen.d description: "uint16",
25 4b33cdd0 2015-11-30 stephen.d target: uint16(0x5544),
26 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{0x44, 0x55},
27 4b33cdd0 2015-11-30 stephen.d },
28 4b33cdd0 2015-11-30 stephen.d {
29 4b33cdd0 2015-11-30 stephen.d description: "string",
30 4b33cdd0 2015-11-30 stephen.d target: "asdf",
31 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{0x4, 0x0, 0x61, 0x73, 0x64, 0x66},
32 4b33cdd0 2015-11-30 stephen.d },
33 4b33cdd0 2015-11-30 stephen.d {
34 4b33cdd0 2015-11-30 stephen.d description: "[]string",
35 4b33cdd0 2015-11-30 stephen.d target: []string{"asdf", "qwer", "zxcv"},
36 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
37 4b33cdd0 2015-11-30 stephen.d 0x3, 0x0, // len(target)
38 4b33cdd0 2015-11-30 stephen.d 0x4, 0x0, 0x61, 0x73, 0x64, 0x66,
39 4b33cdd0 2015-11-30 stephen.d 0x4, 0x0, 0x71, 0x77, 0x65, 0x72,
40 4b33cdd0 2015-11-30 stephen.d 0x4, 0x0, 0x7a, 0x78, 0x63, 0x76},
41 4b33cdd0 2015-11-30 stephen.d },
42 4b33cdd0 2015-11-30 stephen.d {
43 4b33cdd0 2015-11-30 stephen.d description: "Qid",
44 4b33cdd0 2015-11-30 stephen.d target: Qid{
45 4b33cdd0 2015-11-30 stephen.d Type: QTDIR,
46 4b33cdd0 2015-11-30 stephen.d Version: 0x10203040,
47 4b33cdd0 2015-11-30 stephen.d Path: 0x1020304050607080},
48 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
49 4b33cdd0 2015-11-30 stephen.d byte(QTDIR), // qtype
50 4b33cdd0 2015-11-30 stephen.d 0x40, 0x30, 0x20, 0x10, // version
51 4b33cdd0 2015-11-30 stephen.d 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, // path
52 4b33cdd0 2015-11-30 stephen.d },
53 4b33cdd0 2015-11-30 stephen.d },
54 4b33cdd0 2015-11-30 stephen.d // Dir
55 4b33cdd0 2015-11-30 stephen.d {
56 4b33cdd0 2015-11-30 stephen.d description: "Tversion fcall",
57 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
58 4b33cdd0 2015-11-30 stephen.d Type: Tversion,
59 4b33cdd0 2015-11-30 stephen.d Tag: 2255,
60 4b33cdd0 2015-11-30 stephen.d Message: MessageTversion{
61 4b33cdd0 2015-11-30 stephen.d MSize: uint32(1024),
62 4b33cdd0 2015-11-30 stephen.d Version: "9PTEST",
63 4b33cdd0 2015-11-30 stephen.d },
64 4b33cdd0 2015-11-30 stephen.d },
65 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
66 4b33cdd0 2015-11-30 stephen.d 0x64, 0xcf, 0x8, 0x0, 0x4, 0x0, 0x0,
67 4b33cdd0 2015-11-30 stephen.d 0x6, 0x0, 0x39, 0x50, 0x54, 0x45, 0x53, 0x54},
68 4b33cdd0 2015-11-30 stephen.d },
69 4b33cdd0 2015-11-30 stephen.d {
70 4b33cdd0 2015-11-30 stephen.d description: "Rversion fcall",
71 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
72 4b33cdd0 2015-11-30 stephen.d Type: Rversion,
73 4b33cdd0 2015-11-30 stephen.d Tag: 2255,
74 4b33cdd0 2015-11-30 stephen.d Message: MessageRversion{
75 4b33cdd0 2015-11-30 stephen.d MSize: uint32(1024),
76 4b33cdd0 2015-11-30 stephen.d Version: "9PTEST",
77 4b33cdd0 2015-11-30 stephen.d },
78 4b33cdd0 2015-11-30 stephen.d },
79 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
80 4b33cdd0 2015-11-30 stephen.d 0x65, 0xcf, 0x8, 0x0, 0x4, 0x0, 0x0,
81 4b33cdd0 2015-11-30 stephen.d 0x6, 0x0, 0x39, 0x50, 0x54, 0x45, 0x53, 0x54},
82 4b33cdd0 2015-11-30 stephen.d },
83 4b33cdd0 2015-11-30 stephen.d {
84 4b33cdd0 2015-11-30 stephen.d description: "Twalk fcall",
85 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
86 4b33cdd0 2015-11-30 stephen.d Type: Twalk,
87 4b33cdd0 2015-11-30 stephen.d Tag: 5666,
88 4b33cdd0 2015-11-30 stephen.d Message: MessageTwalk{
89 4b33cdd0 2015-11-30 stephen.d Fid: 1010,
90 4b33cdd0 2015-11-30 stephen.d Newfid: 1011,
91 4b33cdd0 2015-11-30 stephen.d Wnames: []string{"a", "b", "c"},
92 4b33cdd0 2015-11-30 stephen.d },
93 4b33cdd0 2015-11-30 stephen.d },
94 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
95 4b33cdd0 2015-11-30 stephen.d 0x6e, 0x22, 0x16, 0xf2, 0x3, 0x0, 0x0, 0xf3, 0x3, 0x0, 0x0,
96 4b33cdd0 2015-11-30 stephen.d 0x3, 0x0, // len(wnames)
97 4b33cdd0 2015-11-30 stephen.d 0x1, 0x0, 0x61, // "a"
98 4b33cdd0 2015-11-30 stephen.d 0x1, 0x0, 0x62, // "b"
99 4b33cdd0 2015-11-30 stephen.d 0x1, 0x0, 0x63}, // "c"
100 4b33cdd0 2015-11-30 stephen.d },
101 4b33cdd0 2015-11-30 stephen.d {
102 4b33cdd0 2015-11-30 stephen.d description: "Rwalk call",
103 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
104 4b33cdd0 2015-11-30 stephen.d Type: Rwalk,
105 4b33cdd0 2015-11-30 stephen.d Tag: 5556,
106 4b33cdd0 2015-11-30 stephen.d Message: MessageRwalk{
107 4b33cdd0 2015-11-30 stephen.d Qids: []Qid{
108 4b33cdd0 2015-11-30 stephen.d Qid{
109 4b33cdd0 2015-11-30 stephen.d Type: QTDIR,
110 4b33cdd0 2015-11-30 stephen.d Path: 1111,
111 4b33cdd0 2015-11-30 stephen.d Version: 11112,
112 4b33cdd0 2015-11-30 stephen.d },
113 4b33cdd0 2015-11-30 stephen.d Qid{Type: QTFILE,
114 4b33cdd0 2015-11-30 stephen.d Version: 1112,
115 4b33cdd0 2015-11-30 stephen.d Path: 11114},
116 4b33cdd0 2015-11-30 stephen.d },
117 4b33cdd0 2015-11-30 stephen.d },
118 4b33cdd0 2015-11-30 stephen.d },
119 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
120 4b33cdd0 2015-11-30 stephen.d 0x6f, 0xb4, 0x15,
121 4b33cdd0 2015-11-30 stephen.d 0x2, 0x0,
122 4b33cdd0 2015-11-30 stephen.d 0x80, 0x68, 0x2b, 0x0, 0x0, 0x57, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
123 4b33cdd0 2015-11-30 stephen.d 0x0, 0x58, 0x4, 0x0, 0x0, 0x6a, 0x2b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
124 4b33cdd0 2015-11-30 stephen.d },
125 4b33cdd0 2015-11-30 stephen.d {
126 4b33cdd0 2015-11-30 stephen.d description: "Rread fcall",
127 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
128 4b33cdd0 2015-11-30 stephen.d Type: Rread,
129 4b33cdd0 2015-11-30 stephen.d Tag: 5556,
130 4b33cdd0 2015-11-30 stephen.d Message: MessageRread{
131 4b33cdd0 2015-11-30 stephen.d Data: []byte("a lot of byte data"),
132 4b33cdd0 2015-11-30 stephen.d },
133 4b33cdd0 2015-11-30 stephen.d },
134 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
135 4b33cdd0 2015-11-30 stephen.d 0x75, 0xb4, 0x15,
136 4b33cdd0 2015-11-30 stephen.d 0x12, 0x0, 0x0, 0x0,
137 4b33cdd0 2015-11-30 stephen.d 0x61, 0x20, 0x6c, 0x6f, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x62, 0x79, 0x74, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61},
138 4b33cdd0 2015-11-30 stephen.d },
139 4b33cdd0 2015-11-30 stephen.d {
140 4b33cdd0 2015-11-30 stephen.d description: "",
141 4b33cdd0 2015-11-30 stephen.d target: &Fcall{
142 4b33cdd0 2015-11-30 stephen.d Type: Rstat,
143 4b33cdd0 2015-11-30 stephen.d Tag: 5556,
144 4b33cdd0 2015-11-30 stephen.d Message: MessageRstat{
145 4b33cdd0 2015-11-30 stephen.d Stat: Dir{
146 4b33cdd0 2015-11-30 stephen.d Type: ^uint16(0),
147 4b33cdd0 2015-11-30 stephen.d Dev: ^uint32(0),
148 4b33cdd0 2015-11-30 stephen.d Qid: Qid{
149 4b33cdd0 2015-11-30 stephen.d Type: QTDIR,
150 4b33cdd0 2015-11-30 stephen.d Version: ^uint32(0),
151 4b33cdd0 2015-11-30 stephen.d Path: ^uint64(0),
152 4b33cdd0 2015-11-30 stephen.d },
153 4b33cdd0 2015-11-30 stephen.d Mode: DMDIR | DMREAD,
154 4b33cdd0 2015-11-30 stephen.d AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
155 4b33cdd0 2015-11-30 stephen.d ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
156 4b33cdd0 2015-11-30 stephen.d Length: ^uint64(0),
157 4b33cdd0 2015-11-30 stephen.d Name: "somedir",
158 4b33cdd0 2015-11-30 stephen.d UID: "uid",
159 4b33cdd0 2015-11-30 stephen.d GID: "gid",
160 4b33cdd0 2015-11-30 stephen.d MUID: "muid",
161 4b33cdd0 2015-11-30 stephen.d },
162 4b33cdd0 2015-11-30 stephen.d },
163 4b33cdd0 2015-11-30 stephen.d },
164 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
165 4b33cdd0 2015-11-30 stephen.d 0x7d, 0xb4, 0x15,
166 4b33cdd0 2015-11-30 stephen.d 0x42, 0x0, // TODO(stevvooe): Include Dir size. Not straightforward.
167 4b33cdd0 2015-11-30 stephen.d 0x40, 0x0, // TODO(stevvooe): Include Dir size. Not straightforward.
168 4b33cdd0 2015-11-30 stephen.d 0xff, 0xff, // type
169 4b33cdd0 2015-11-30 stephen.d 0xff, 0xff, 0xff, 0xff, // dev
170 4b33cdd0 2015-11-30 stephen.d 0x80, 0xff, 0xff, 0xff, 0xff, // qid.type, qid.version
171 4b33cdd0 2015-11-30 stephen.d 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path
172 4b33cdd0 2015-11-30 stephen.d 0x4, 0x0, 0x0, 0x80, // mode
173 4b33cdd0 2015-11-30 stephen.d 0x25, 0x98, 0xb8, 0x43, // atime
174 4b33cdd0 2015-11-30 stephen.d 0x25, 0x98, 0xb8, 0x43, // mtime
175 4b33cdd0 2015-11-30 stephen.d 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // length
176 4b33cdd0 2015-11-30 stephen.d 0x7, 0x0, 0x73, 0x6f, 0x6d, 0x65, 0x64, 0x69, 0x72,
177 4b33cdd0 2015-11-30 stephen.d 0x3, 0x0, 0x75, 0x69, 0x64, // uid
178 4b33cdd0 2015-11-30 stephen.d 0x3, 0x0, 0x67, 0x69, 0x64, // gid
179 4b33cdd0 2015-11-30 stephen.d 0x4, 0x0, 0x6d, 0x75, 0x69, 0x64}, // muid
180 961194b3 2015-12-04 stevvooe },
181 961194b3 2015-12-04 stevvooe {
182 961194b3 2015-12-04 stevvooe description: "Dir[]",
183 961194b3 2015-12-04 stevvooe target: []Dir{
184 961194b3 2015-12-04 stevvooe {
185 961194b3 2015-12-04 stevvooe Type: uint16(0),
186 961194b3 2015-12-04 stevvooe Dev: uint32(0),
187 961194b3 2015-12-04 stevvooe Qid: Qid{
188 961194b3 2015-12-04 stevvooe Type: QTDIR,
189 961194b3 2015-12-04 stevvooe Version: uint32(0),
190 961194b3 2015-12-04 stevvooe Path: ^uint64(0),
191 961194b3 2015-12-04 stevvooe },
192 961194b3 2015-12-04 stevvooe Mode: DMDIR | DMREAD,
193 961194b3 2015-12-04 stevvooe AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
194 961194b3 2015-12-04 stevvooe ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
195 961194b3 2015-12-04 stevvooe Length: 0x88,
196 961194b3 2015-12-04 stevvooe Name: ".",
197 961194b3 2015-12-04 stevvooe UID: "501",
198 961194b3 2015-12-04 stevvooe GID: "20",
199 961194b3 2015-12-04 stevvooe MUID: "none",
200 961194b3 2015-12-04 stevvooe },
201 961194b3 2015-12-04 stevvooe {
202 961194b3 2015-12-04 stevvooe Type: uint16(0),
203 961194b3 2015-12-04 stevvooe Dev: uint32(0),
204 961194b3 2015-12-04 stevvooe Qid: Qid{
205 961194b3 2015-12-04 stevvooe Type: QTDIR,
206 961194b3 2015-12-04 stevvooe Version: uint32(0),
207 961194b3 2015-12-04 stevvooe Path: ^uint64(0),
208 961194b3 2015-12-04 stevvooe },
209 961194b3 2015-12-04 stevvooe Mode: DMDIR | DMREAD,
210 961194b3 2015-12-04 stevvooe AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
211 961194b3 2015-12-04 stevvooe ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
212 961194b3 2015-12-04 stevvooe Length: 0x63e,
213 961194b3 2015-12-04 stevvooe Name: "..",
214 961194b3 2015-12-04 stevvooe UID: "501",
215 961194b3 2015-12-04 stevvooe GID: "20",
216 961194b3 2015-12-04 stevvooe MUID: "none",
217 961194b3 2015-12-04 stevvooe },
218 961194b3 2015-12-04 stevvooe {
219 961194b3 2015-12-04 stevvooe Type: uint16(0),
220 961194b3 2015-12-04 stevvooe Dev: uint32(0),
221 961194b3 2015-12-04 stevvooe Qid: Qid{
222 961194b3 2015-12-04 stevvooe Type: QTDIR,
223 961194b3 2015-12-04 stevvooe Version: uint32(0),
224 961194b3 2015-12-04 stevvooe Path: ^uint64(0),
225 961194b3 2015-12-04 stevvooe },
226 961194b3 2015-12-04 stevvooe Mode: DMDIR | DMREAD,
227 961194b3 2015-12-04 stevvooe AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
228 961194b3 2015-12-04 stevvooe ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
229 961194b3 2015-12-04 stevvooe Length: 0x44,
230 961194b3 2015-12-04 stevvooe Name: "hello",
231 961194b3 2015-12-04 stevvooe UID: "501",
232 961194b3 2015-12-04 stevvooe GID: "20",
233 961194b3 2015-12-04 stevvooe MUID: "none",
234 961194b3 2015-12-04 stevvooe },
235 961194b3 2015-12-04 stevvooe {
236 961194b3 2015-12-04 stevvooe Type: uint16(0),
237 961194b3 2015-12-04 stevvooe Dev: uint32(0),
238 961194b3 2015-12-04 stevvooe Qid: Qid{
239 961194b3 2015-12-04 stevvooe Type: QTDIR,
240 961194b3 2015-12-04 stevvooe Version: uint32(0),
241 961194b3 2015-12-04 stevvooe Path: ^uint64(0),
242 961194b3 2015-12-04 stevvooe },
243 961194b3 2015-12-04 stevvooe Mode: DMDIR | DMREAD,
244 961194b3 2015-12-04 stevvooe AccessTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
245 961194b3 2015-12-04 stevvooe ModTime: time.Date(2006, 01, 02, 03, 04, 05, 0, time.UTC),
246 961194b3 2015-12-04 stevvooe Length: 0x44,
247 961194b3 2015-12-04 stevvooe Name: "there",
248 961194b3 2015-12-04 stevvooe UID: "501",
249 961194b3 2015-12-04 stevvooe GID: "20",
250 961194b3 2015-12-04 stevvooe MUID: "none",
251 961194b3 2015-12-04 stevvooe },
252 961194b3 2015-12-04 stevvooe },
253 961194b3 2015-12-04 stevvooe marshaled: []byte{
254 961194b3 2015-12-04 stevvooe 0x39, 0x0, // size
255 961194b3 2015-12-04 stevvooe 0x0, 0x0, // type
256 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // dev
257 961194b3 2015-12-04 stevvooe 0x80, // qid.type == QTDIR
258 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // qid.vers
259 961194b3 2015-12-04 stevvooe 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path
260 961194b3 2015-12-04 stevvooe 0x4, 0x0, 0x0, 0x80, // mode
261 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // atime
262 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // mtime
263 961194b3 2015-12-04 stevvooe 0x88, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length
264 961194b3 2015-12-04 stevvooe 0x1, 0x0,
265 961194b3 2015-12-04 stevvooe 0x2e, // .
266 961194b3 2015-12-04 stevvooe 0x3, 0x0,
267 961194b3 2015-12-04 stevvooe 0x35, 0x30, 0x31, // 501
268 961194b3 2015-12-04 stevvooe 0x2, 0x0,
269 961194b3 2015-12-04 stevvooe 0x32, 0x30, // 20
270 961194b3 2015-12-04 stevvooe 0x4, 0x0,
271 961194b3 2015-12-04 stevvooe 0x6e, 0x6f, 0x6e, 0x65, // none
272 961194b3 2015-12-04 stevvooe
273 961194b3 2015-12-04 stevvooe 0x3a, 0x0,
274 961194b3 2015-12-04 stevvooe 0x0, 0x0, // type
275 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // dev
276 961194b3 2015-12-04 stevvooe 0x80, // qid.type == QTDIR
277 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // qid.vers
278 961194b3 2015-12-04 stevvooe 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path
279 961194b3 2015-12-04 stevvooe 0x4, 0x0, 0x0, 0x80, // mode
280 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // atime
281 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // mtime
282 961194b3 2015-12-04 stevvooe 0x3e, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length
283 961194b3 2015-12-04 stevvooe 0x2, 0x0,
284 961194b3 2015-12-04 stevvooe 0x2e, 0x2e, // ..
285 961194b3 2015-12-04 stevvooe 0x3, 0x0,
286 961194b3 2015-12-04 stevvooe 0x35, 0x30, 0x31, // 501
287 961194b3 2015-12-04 stevvooe 0x2, 0x0,
288 961194b3 2015-12-04 stevvooe 0x32, 0x30, // 20
289 961194b3 2015-12-04 stevvooe 0x4, 0x0,
290 961194b3 2015-12-04 stevvooe 0x6e, 0x6f, 0x6e, 0x65, // none
291 961194b3 2015-12-04 stevvooe
292 961194b3 2015-12-04 stevvooe 0x3d, 0x0,
293 961194b3 2015-12-04 stevvooe 0x0, 0x0, // type
294 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // dev
295 961194b3 2015-12-04 stevvooe 0x80, // qid.type == QTDIR
296 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // qid.vers
297 961194b3 2015-12-04 stevvooe 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.Path
298 961194b3 2015-12-04 stevvooe 0x4, 0x0, 0x0, 0x80, // mode
299 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // atime
300 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // mtime
301 961194b3 2015-12-04 stevvooe 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length
302 961194b3 2015-12-04 stevvooe 0x5, 0x0,
303 961194b3 2015-12-04 stevvooe 0x68, 0x65, 0x6c, 0x6c, 0x6f, // hello
304 961194b3 2015-12-04 stevvooe 0x3, 0x0,
305 961194b3 2015-12-04 stevvooe 0x35, 0x30, 0x31, // 501
306 961194b3 2015-12-04 stevvooe 0x2, 0x0,
307 961194b3 2015-12-04 stevvooe 0x32, 0x30, // 20
308 961194b3 2015-12-04 stevvooe 0x4, 0x0,
309 961194b3 2015-12-04 stevvooe 0x6e, 0x6f, 0x6e, 0x65, // none
310 961194b3 2015-12-04 stevvooe
311 961194b3 2015-12-04 stevvooe 0x3d, 0x0,
312 961194b3 2015-12-04 stevvooe 0x0, 0x0, // type
313 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, // dev
314 961194b3 2015-12-04 stevvooe 0x80, // qid.type == QTDIR
315 961194b3 2015-12-04 stevvooe 0x0, 0x0, 0x0, 0x0, //qid.vers
316 961194b3 2015-12-04 stevvooe 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // qid.path
317 961194b3 2015-12-04 stevvooe 0x4, 0x0, 0x0, 0x80, // mode
318 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // atime
319 961194b3 2015-12-04 stevvooe 0x25, 0x98, 0xb8, 0x43, // mtime
320 961194b3 2015-12-04 stevvooe 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // length
321 961194b3 2015-12-04 stevvooe 0x5, 0x0,
322 961194b3 2015-12-04 stevvooe 0x74, 0x68, 0x65, 0x72, 0x65, // there
323 961194b3 2015-12-04 stevvooe 0x3, 0x0,
324 961194b3 2015-12-04 stevvooe 0x35, 0x30, 0x31, // 501
325 961194b3 2015-12-04 stevvooe 0x2, 0x0,
326 961194b3 2015-12-04 stevvooe 0x32, 0x30, // 20
327 961194b3 2015-12-04 stevvooe 0x4, 0x0,
328 961194b3 2015-12-04 stevvooe 0x6e, 0x6f, 0x6e, 0x65, // none
329 961194b3 2015-12-04 stevvooe },
330 4b33cdd0 2015-11-30 stephen.d },
331 4b33cdd0 2015-11-30 stephen.d {
332 4b33cdd0 2015-11-30 stephen.d description: "Rerror fcall",
333 4b33cdd0 2015-11-30 stephen.d target: newErrorFcall(5556, errors.New("A serious error")),
334 4b33cdd0 2015-11-30 stephen.d marshaled: []byte{
335 4b33cdd0 2015-11-30 stephen.d 0x6b, // Rerror
336 4b33cdd0 2015-11-30 stephen.d 0xb4, 0x15, // Tag
337 4b33cdd0 2015-11-30 stephen.d 0xf, 0x0, // String size.
338 4b33cdd0 2015-11-30 stephen.d 0x41, 0x20, 0x73, 0x65, 0x72, 0x69, 0x6f, 0x75, 0x73, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72},
339 4b33cdd0 2015-11-30 stephen.d },
340 4b33cdd0 2015-11-30 stephen.d } {
341 4b33cdd0 2015-11-30 stephen.d t.Logf("target under test: %#v %T", testcase.target, testcase.target)
342 4b33cdd0 2015-11-30 stephen.d fatalf := func(format string, args ...interface{}) {
343 4b33cdd0 2015-11-30 stephen.d t.Fatalf(testcase.description+": "+format, args...)
344 4b33cdd0 2015-11-30 stephen.d }
345 4b33cdd0 2015-11-30 stephen.d
346 4b33cdd0 2015-11-30 stephen.d p, err := codec.Marshal(testcase.target)
347 4b33cdd0 2015-11-30 stephen.d if err != nil {
348 4b33cdd0 2015-11-30 stephen.d fatalf("error writing fcall: %v", err)
349 4b33cdd0 2015-11-30 stephen.d }
350 4b33cdd0 2015-11-30 stephen.d
351 4b33cdd0 2015-11-30 stephen.d if !bytes.Equal(p, testcase.marshaled) {
352 4b33cdd0 2015-11-30 stephen.d fatalf("unexpected bytes for fcall: \n%#v != \n%#v", p, testcase.marshaled)
353 4b33cdd0 2015-11-30 stephen.d }
354 4b33cdd0 2015-11-30 stephen.d
355 4b33cdd0 2015-11-30 stephen.d if size9p(testcase.target) == 0 {
356 4b33cdd0 2015-11-30 stephen.d fatalf("size of target should never be zero")
357 4b33cdd0 2015-11-30 stephen.d }
358 4b33cdd0 2015-11-30 stephen.d
359 4b33cdd0 2015-11-30 stephen.d // check that size9p is working correctly
360 4b33cdd0 2015-11-30 stephen.d if int(size9p(testcase.target)) != len(testcase.marshaled) {
361 4b33cdd0 2015-11-30 stephen.d fatalf("size not correct: %v != %v", int(size9p(testcase.target)), len(testcase.marshaled))
362 4b33cdd0 2015-11-30 stephen.d }
363 4b33cdd0 2015-11-30 stephen.d
364 4b33cdd0 2015-11-30 stephen.d var v interface{}
365 4b33cdd0 2015-11-30 stephen.d targetType := reflect.TypeOf(testcase.target)
366 4b33cdd0 2015-11-30 stephen.d
367 4b33cdd0 2015-11-30 stephen.d if targetType.Kind() == reflect.Ptr {
368 4b33cdd0 2015-11-30 stephen.d v = reflect.New(targetType.Elem()).Interface()
369 4b33cdd0 2015-11-30 stephen.d } else {
370 4b33cdd0 2015-11-30 stephen.d v = reflect.New(targetType).Interface()
371 4b33cdd0 2015-11-30 stephen.d }
372 4b33cdd0 2015-11-30 stephen.d
373 4b33cdd0 2015-11-30 stephen.d if err := codec.Unmarshal(p, v); err != nil {
374 4b33cdd0 2015-11-30 stephen.d fatalf("error reading: %v", err)
375 4b33cdd0 2015-11-30 stephen.d }
376 4b33cdd0 2015-11-30 stephen.d
377 4b33cdd0 2015-11-30 stephen.d if targetType.Kind() != reflect.Ptr {
378 4b33cdd0 2015-11-30 stephen.d v = reflect.Indirect(reflect.ValueOf(v)).Interface()
379 4b33cdd0 2015-11-30 stephen.d }
380 4b33cdd0 2015-11-30 stephen.d
381 4b33cdd0 2015-11-30 stephen.d if !reflect.DeepEqual(v, testcase.target) {
382 4b33cdd0 2015-11-30 stephen.d fatalf("not equal: %v != %v (\n%#v\n%#v\n)",
383 4b33cdd0 2015-11-30 stephen.d v, testcase.target,
384 4b33cdd0 2015-11-30 stephen.d v, testcase.target)
385 4b33cdd0 2015-11-30 stephen.d }
386 4b33cdd0 2015-11-30 stephen.d
387 4b33cdd0 2015-11-30 stephen.d t.Logf("%#v", v)
388 4b33cdd0 2015-11-30 stephen.d
389 4b33cdd0 2015-11-30 stephen.d }
390 4b33cdd0 2015-11-30 stephen.d }