1 // Copyright 2016, 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
12 "github.com/google/gopacket"
15 func TestTCPOptionKindString(t *testing.T) {
16 testData := []struct {
21 OptionType: TCPOptionKindNop,
26 OptionType: TCPOptionKindMSS,
28 OptionData: []byte{0x12, 0x34},
30 "TCPOption(MSS:4660 0x1234)"},
32 OptionType: TCPOptionKindTimestamps,
34 OptionData: []byte{0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01},
36 "TCPOption(Timestamps:2/1 0x0000000200000001)"}}
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)
45 func TestTCPSerializePadding(t *testing.T) {
47 tcp.Options = append(tcp.Options, TCPOption{
48 OptionType: TCPOptionKindNop,
51 buf := gopacket.NewSerializeBuffer()
52 opts := gopacket.SerializeOptions{FixLengths: true}
53 err := gopacket.SerializeLayers(buf, opts, tcp)
57 if len(buf.Bytes())%4 != 0 {
58 t.Errorf("TCP data of len %d not padding to 32 bit boundary", len(buf.Bytes()))