forked from n10v/id3v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
62 lines (51 loc) · 1.15 KB
/
util_test.go
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
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 Albert Nigmatzianov. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package id3v2
import (
"bufio"
"bytes"
"testing"
)
var (
sizeInt uint = 15351
sizeBytes = []byte{0, 0, 0x77, 0x77}
)
func TestWriteBytesSize(t *testing.T) {
t.Parallel()
buf := new(bytes.Buffer)
bw := bufio.NewWriter(buf)
if err := writeBytesSize(bw, sizeInt); err != nil {
t.Error(err)
}
bw.Flush()
if !bytes.Equal(buf.Bytes(), sizeBytes) {
t.Errorf("Expected: %v, got: %v", sizeBytes, buf.Bytes())
}
}
func TestParseSize(t *testing.T) {
t.Parallel()
size, err := parseSize(sizeBytes)
if err != nil {
t.Error(err)
}
if size != int64(sizeInt) {
t.Errorf("Expected: %v, got: %v", sizeInt, size)
}
}
func BenchmarkWriteBytesSize(b *testing.B) {
bw := bufio.NewWriter(new(bytes.Buffer))
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := writeBytesSize(bw, 268435454); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseSize(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := parseSize([]byte{127, 127, 127, 127}); err != nil {
b.Fatal(err)
}
}
}