go-hep.org/x/hep@v0.38.1/rio/record_test.go (about) 1 // Copyright ©2018 The go-hep Authors. 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 5 package rio 6 7 import ( 8 "compress/flate" 9 "testing" 10 ) 11 12 func TestRecord(t *testing.T) { 13 for _, tc := range []struct { 14 name string 15 compr CompressorKind 16 want CompressorKind 17 level int 18 codec int 19 }{ 20 { 21 name: "zlib", 22 compr: CompressZlib, 23 level: flate.DefaultCompression, 24 codec: 3, 25 }, 26 { 27 name: "gzip", 28 compr: CompressGzip, 29 level: 9, 30 codec: 4, 31 }, 32 { 33 name: "lza", 34 compr: CompressLZA, 35 level: flate.BestCompression, 36 codec: 4, 37 }, 38 { 39 name: "lzo", 40 compr: CompressLZO, 41 level: flate.BestSpeed, 42 codec: 0, 43 }, 44 { 45 name: "snappy", 46 compr: CompressSnappy, 47 level: flate.DefaultCompression, 48 codec: 0, 49 }, 50 { 51 name: "none", 52 compr: CompressNone, 53 level: 0, 54 codec: 0, 55 }, 56 { 57 name: "default", 58 compr: CompressDefault, 59 want: CompressZlib, 60 level: flate.DefaultCompression, 61 codec: 0, 62 }, 63 } { 64 t.Run(tc.name, func(t *testing.T) { 65 66 rec := newRecord("name", NewOptions(tc.compr, tc.level, tc.codec)) 67 if got, want := rec.Name(), "name"; got != want { 68 t.Fatalf("got=%q, want=%q", got, want) 69 } 70 71 switch tc.compr { 72 case CompressNone: 73 if rec.Compress() { 74 t.Fatalf("record compressed") 75 } 76 default: 77 if !rec.Compress() { 78 t.Fatalf("record not compressed") 79 } 80 } 81 82 if rec.Unpack() { 83 t.Fatalf("record unpacked") 84 } 85 86 rec.SetUnpack(true) 87 if !rec.Unpack() { 88 t.Fatalf("record not unpacked") 89 } 90 91 opts := rec.Options() 92 tc.want = tc.compr 93 if tc.want == CompressDefault { 94 tc.want = CompressZlib 95 } 96 if got, want := opts.CompressorKind(), tc.want; got != want { 97 t.Fatalf("invalid compressor kind: got=%v, want=%v", got, want) 98 } 99 100 if got, want := opts.CompressorLevel(), tc.level; got != want { 101 t.Fatalf("invalid compressor level: got=%v, want=%v", got, want) 102 } 103 104 if got, want := opts.CompressorCodec(), tc.codec; got != want { 105 t.Fatalf("invalid compressor codec: got=%v, want=%v", got, want) 106 } 107 }) 108 } 109 }