4be7480bc24465b29bbd794ba4a83539a0847bbb
[govpp.git] / vendor / github.com / google / gopacket / layers / base_test.go
1 // Copyright 2012, Google, Inc. All rights reserved.
2 //
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
5 // tree.
6
7 // This file contains some test helper functions.
8
9 package layers
10
11 import (
12         "github.com/google/gopacket"
13         "testing"
14 )
15
16 func min(a, b int) int {
17         if a < b {
18                 return a
19         }
20         return b
21 }
22
23 func checkLayers(p gopacket.Packet, want []gopacket.LayerType, t *testing.T) {
24         layers := p.Layers()
25         t.Log("Checking packet layers, want", want)
26         for _, l := range layers {
27                 t.Logf("  Got layer %v, %d bytes, payload of %d bytes", l.LayerType(),
28                         len(l.LayerContents()), len(l.LayerPayload()))
29         }
30         t.Log(p)
31         if len(layers) != len(want) {
32                 t.Errorf("  Number of layers mismatch: got %d want %d", len(layers),
33                         len(want))
34                 return
35         }
36         for i, l := range layers {
37                 if l.LayerType() != want[i] {
38                         t.Errorf("  Layer %d mismatch: got %v want %v", i, l.LayerType(),
39                                 want[i])
40                 }
41         }
42 }