1// Copyright 2014-2017 Ulrich Kunitz. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package lzma 6 7import "testing" 8 9func TestHeaderMarshalling(t *testing.T) { 10 tests := []header{ 11 {properties: Properties{3, 0, 2}, dictCap: 8 * 1024 * 1024, 12 size: -1}, 13 {properties: Properties{4, 3, 3}, dictCap: 4096, 14 size: 10}, 15 } 16 for _, h := range tests { 17 data, err := h.marshalBinary() 18 if err != nil { 19 t.Fatalf("marshalBinary error %s", err) 20 } 21 var g header 22 if err = g.unmarshalBinary(data); err != nil { 23 t.Fatalf("unmarshalBinary error %s", err) 24 } 25 if h != g { 26 t.Errorf("got header %#v; want %#v", g, h) 27 } 28 } 29} 30 31func TestValidHeader(t *testing.T) { 32 tests := []header{ 33 {properties: Properties{3, 0, 2}, dictCap: 8 * 1024 * 1024, 34 size: -1}, 35 {properties: Properties{4, 3, 3}, dictCap: 4096, 36 size: 10}, 37 } 38 for _, h := range tests { 39 data, err := h.marshalBinary() 40 if err != nil { 41 t.Fatalf("marshalBinary error %s", err) 42 } 43 if !ValidHeader(data) { 44 t.Errorf("ValidHeader returns false for header %v;"+ 45 " want true", h) 46 } 47 } 48 const a = "1234567890123" 49 if ValidHeader([]byte(a)) { 50 t.Errorf("ValidHeader returns true for %s; want false", a) 51 } 52} 53