From 3f1edad4e6ba0a7876750aea55507fae14d8badf Mon Sep 17 00:00:00 2001 From: Milan Lenco Date: Wed, 11 Oct 2017 16:40:58 +0200 Subject: ODPM 266: Go-libmemif + 2 examples. Change-Id: Icdb9b9eb2314eff6c96afe7996fcf2728291de4a Signed-off-by: Milan Lenco --- .../github.com/google/gopacket/layers/tcp_test.go | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vendor/github.com/google/gopacket/layers/tcp_test.go (limited to 'vendor/github.com/google/gopacket/layers/tcp_test.go') diff --git a/vendor/github.com/google/gopacket/layers/tcp_test.go b/vendor/github.com/google/gopacket/layers/tcp_test.go new file mode 100644 index 0000000..56a6aaa --- /dev/null +++ b/vendor/github.com/google/gopacket/layers/tcp_test.go @@ -0,0 +1,60 @@ +// Copyright 2016, Google, Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file in the root of the source +// tree. + +package layers + +import ( + "testing" + + "github.com/google/gopacket" +) + +func TestTCPOptionKindString(t *testing.T) { + testData := []struct { + o *TCPOption + s string + }{ + {&TCPOption{ + OptionType: TCPOptionKindNop, + OptionLength: 1, + }, + "TCPOption(NOP:)"}, + {&TCPOption{ + OptionType: TCPOptionKindMSS, + OptionLength: 4, + OptionData: []byte{0x12, 0x34}, + }, + "TCPOption(MSS:4660 0x1234)"}, + {&TCPOption{ + OptionType: TCPOptionKindTimestamps, + OptionLength: 10, + OptionData: []byte{0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}, + }, + "TCPOption(Timestamps:2/1 0x0000000200000001)"}} + + for _, tc := range testData { + if s := tc.o.String(); s != tc.s { + t.Errorf("expected %#v string to be %s, got %s", tc.o, tc.s, s) + } + } +} + +func TestTCPSerializePadding(t *testing.T) { + tcp := &TCP{} + tcp.Options = append(tcp.Options, TCPOption{ + OptionType: TCPOptionKindNop, + OptionLength: 1, + }) + buf := gopacket.NewSerializeBuffer() + opts := gopacket.SerializeOptions{FixLengths: true} + err := gopacket.SerializeLayers(buf, opts, tcp) + if err != nil { + t.Fatal(err) + } + if len(buf.Bytes())%4 != 0 { + t.Errorf("TCP data of len %d not padding to 32 bit boundary", len(buf.Bytes())) + } +} -- cgit 1.2.3-korg