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
11 "github.com/google/gopacket"
16 func TestWriteHeader(t *testing.T) {
19 w.WriteFileHeader(0x1234, 0x56)
21 0xd4, 0xc3, 0xb2, 0xa1, 0x02, 0x00, 0x04, 0x00,
22 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23 0x34, 0x12, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00,
25 if got := buf.Bytes(); !bytes.Equal(got, want) {
26 t.Errorf("buf mismatch:\nwant: %+v\ngot: %+v", want, got)
30 func TestWritePacket(t *testing.T) {
31 ci := gopacket.CaptureInfo{
32 Timestamp: time.Unix(0x01020304, 0xAA*1000),
36 data := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
39 w.WritePacket(ci, data)
41 0x04, 0x03, 0x02, 0x01, 0xAA, 0x00, 0x00, 0x00,
42 0x0A, 0x00, 0x00, 0x00, 0xCD, 0xAB, 0x00, 0x00,
43 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
45 if got := buf.Bytes(); !bytes.Equal(got, want) {
46 t.Errorf("buf mismatch:\nwant: %+v\ngot: %+v", want, got)
50 func TestCaptureInfoErrors(t *testing.T) {
51 data := []byte{1, 2, 3, 4}
53 for _, test := range []gopacket.CaptureInfo{
67 if err := w.WritePacket(test, data); err == nil {
68 t.Errorf("CaptureInfo %+v should have error", test)