File: header_test.go

package info (click to toggle)
golang-github-ulikunitz-xz 0.5.15-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 11,496 kB
  • sloc: makefile: 7; sh: 5
file content (52 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2014-2022 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package lzma

import "testing"

func TestHeaderMarshalling(t *testing.T) {
	tests := []Header{
		{Properties: Properties{3, 0, 2}, DictSize: 8 * 1024 * 1024,
			Size: -1},
		{Properties: Properties{4, 3, 3}, DictSize: 4096,
			Size: 10},
	}
	for _, h := range tests {
		data, err := h.marshalBinary()
		if err != nil {
			t.Fatalf("marshalBinary error %s", err)
		}
		var g Header
		if err = g.unmarshalBinary(data); err != nil {
			t.Fatalf("unmarshalBinary error %s", err)
		}
		if h != g {
			t.Errorf("got header %#v; want %#v", g, h)
		}
	}
}

func TestValidHeader(t *testing.T) {
	tests := []Header{
		{Properties: Properties{3, 0, 2}, DictSize: 8 * 1024 * 1024,
			Size: -1},
		{Properties: Properties{4, 3, 3}, DictSize: 4096,
			Size: 10},
	}
	for _, h := range tests {
		data, err := h.marshalBinary()
		if err != nil {
			t.Fatalf("marshalBinary error %s", err)
		}
		if !ValidHeader(data) {
			t.Errorf("ValidHeader returns false for header %v;"+
				" want true", h)
		}
	}
	const a = "1234567890123"
	if ValidHeader([]byte(a)) {
		t.Errorf("ValidHeader returns true for %s; want false", a)
	}
}