added support for string type
[govpp.git] / vendor / github.com / google / gopacket / layers / tcp_test.go
1 // Copyright 2016, 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 package layers
8
9 import (
10         "testing"
11
12         "github.com/google/gopacket"
13 )
14
15 func TestTCPOptionKindString(t *testing.T) {
16         testData := []struct {
17                 o *TCPOption
18                 s string
19         }{
20                 {&TCPOption{
21                         OptionType:   TCPOptionKindNop,
22                         OptionLength: 1,
23                 },
24                         "TCPOption(NOP:)"},
25                 {&TCPOption{
26                         OptionType:   TCPOptionKindMSS,
27                         OptionLength: 4,
28                         OptionData:   []byte{0x12, 0x34},
29                 },
30                         "TCPOption(MSS:4660 0x1234)"},
31                 {&TCPOption{
32                         OptionType:   TCPOptionKindTimestamps,
33                         OptionLength: 10,
34                         OptionData:   []byte{0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01},
35                 },
36                         "TCPOption(Timestamps:2/1 0x0000000200000001)"}}
37
38         for _, tc := range testData {
39                 if s := tc.o.String(); s != tc.s {
40                         t.Errorf("expected %#v string to be %s, got %s", tc.o, tc.s, s)
41                 }
42         }
43 }
44
45 func TestTCPSerializePadding(t *testing.T) {
46         tcp := &TCP{}
47         tcp.Options = append(tcp.Options, TCPOption{
48                 OptionType:   TCPOptionKindNop,
49                 OptionLength: 1,
50         })
51         buf := gopacket.NewSerializeBuffer()
52         opts := gopacket.SerializeOptions{FixLengths: true}
53         err := gopacket.SerializeLayers(buf, opts, tcp)
54         if err != nil {
55                 t.Fatal(err)
56         }
57         if len(buf.Bytes())%4 != 0 {
58                 t.Errorf("TCP data of len %d not padding to 32 bit boundary", len(buf.Bytes()))
59         }
60 }