1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
15 type embedded struct {
19 type embedding struct {
24 func TestDumpEmbedded(t *testing.T) {
25 e := embedding{embedded: embedded{A: 1, B: 2}, C: 3, D: 4}
26 if got, want := layerString(reflect.ValueOf(e), false, false), "{A=1 B=2 C=3 D=4}"; got != want {
27 t.Errorf("embedded dump mismatch:\n got: %v\n want: %v", got, want)
31 type singlePacketSource [1][]byte
33 func (s *singlePacketSource) ReadPacketData() ([]byte, CaptureInfo, error) {
35 return nil, CaptureInfo{}, io.EOF
39 return out, CaptureInfo{}, nil
42 func TestConcatPacketSources(t *testing.T) {
43 sourceA := &singlePacketSource{[]byte{1}}
44 sourceB := &singlePacketSource{[]byte{2}}
45 sourceC := &singlePacketSource{[]byte{3}}
46 concat := ConcatFinitePacketDataSources(sourceA, sourceB, sourceC)
47 a, _, err := concat.ReadPacketData()
48 if err != nil || len(a) != 1 || a[0] != 1 {
49 t.Errorf("expected [1], got %v/%v", a, err)
51 b, _, err := concat.ReadPacketData()
52 if err != nil || len(b) != 1 || b[0] != 2 {
53 t.Errorf("expected [2], got %v/%v", b, err)
55 c, _, err := concat.ReadPacketData()
56 if err != nil || len(c) != 1 || c[0] != 3 {
57 t.Errorf("expected [3], got %v/%v", c, err)
59 if _, _, err := concat.ReadPacketData(); err != io.EOF {
60 t.Errorf("expected io.EOF, got %v", err)