LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 package ssh |
6 | 6 |
7 import ( | 7 import ( |
8 "math/big" | 8 "math/big" |
9 "math/rand" | 9 "math/rand" |
10 "reflect" | 10 "reflect" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if err := unmarshal(m2, marshaled, msgIgnore); err != ni
l { | 68 if err := unmarshal(m2, marshaled, msgIgnore); err != ni
l { |
69 t.Errorf("#%d failed to unmarshal %#v: %s", i, m
1, err) | 69 t.Errorf("#%d failed to unmarshal %#v: %s", i, m
1, err) |
70 break | 70 break |
71 } | 71 } |
72 | 72 |
73 if !reflect.DeepEqual(v.Interface(), m2) { | 73 if !reflect.DeepEqual(v.Interface(), m2) { |
74 t.Errorf("#%d\ngot: %#v\nwant:%#v\n%x", i, m2, m
1, marshaled) | 74 t.Errorf("#%d\ngot: %#v\nwant:%#v\n%x", i, m2, m
1, marshaled) |
75 break | 75 break |
76 } | 76 } |
77 } | 77 } |
| 78 } |
| 79 } |
| 80 |
| 81 func TestUnmarshalEmptyPacket(t *testing.T) { |
| 82 var b []byte |
| 83 var m channelRequestSuccessMsg |
| 84 err := unmarshal(&m, b, msgChannelRequest) |
| 85 want := ParseError{msgChannelRequest} |
| 86 if _, ok := err.(ParseError); !ok { |
| 87 t.Fatalf("got %T, want %T", err, want) |
| 88 } |
| 89 if got := err.(ParseError); want != got { |
| 90 t.Fatal("got %#v, want %#v", got, want) |
| 91 } |
| 92 } |
| 93 |
| 94 func TestUnmarshalUnexpectedPacket(t *testing.T) { |
| 95 type S struct { |
| 96 I uint32 |
| 97 S string |
| 98 B bool |
| 99 } |
| 100 |
| 101 s := S{42, "hello", true} |
| 102 packet := marshal(42, s) |
| 103 roundtrip := S{} |
| 104 err := unmarshal(&roundtrip, packet, 43) |
| 105 if err == nil { |
| 106 t.Fatal("expected error, not nil") |
| 107 } |
| 108 want := UnexpectedMessageError{43, 42} |
| 109 if got, ok := err.(UnexpectedMessageError); !ok || want != got { |
| 110 t.Fatal("expected %q, got %q", want, got) |
78 } | 111 } |
79 } | 112 } |
80 | 113 |
81 func TestBareMarshalUnmarshal(t *testing.T) { | 114 func TestBareMarshalUnmarshal(t *testing.T) { |
82 type S struct { | 115 type S struct { |
83 I uint32 | 116 I uint32 |
84 S string | 117 S string |
85 B bool | 118 B bool |
86 } | 119 } |
87 | 120 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 marshal(msgKexDHInit, _kexDHInitMsg) | 223 marshal(msgKexDHInit, _kexDHInitMsg) |
191 } | 224 } |
192 } | 225 } |
193 | 226 |
194 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) { | 227 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) { |
195 m := new(kexDHInitMsg) | 228 m := new(kexDHInitMsg) |
196 for i := 0; i < b.N; i++ { | 229 for i := 0; i < b.N; i++ { |
197 unmarshal(m, _kexDHInit, msgKexDHInit) | 230 unmarshal(m, _kexDHInit, msgKexDHInit) |
198 } | 231 } |
199 } | 232 } |
LEFT | RIGHT |