-
Notifications
You must be signed in to change notification settings - Fork 1
/
stream_test.go
59 lines (57 loc) · 1.29 KB
/
stream_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
package tta
import (
"bytes"
"crypto/sha256"
"io/ioutil"
"os"
"testing"
)
func TestComprehensive(t *testing.T) {
t.Parallel()
testfile := "tta_comprehensive_test.wav"
if info, err := os.Stat(testfile); err == nil {
if !info.IsDir() {
fd, err := os.Open(testfile)
if err != nil {
t.Fatal(err)
}
defer fd.Close()
p, err := ioutil.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
fd.Seek(0, os.SEEK_SET)
sum := sha256.Sum256(p)
tmpfile1 := os.TempDir() + "/tta_comprehensive_test_compressed.tta"
tmpfile2 := os.TempDir() + "/tta_comprehensive_test_decompressed.wav"
outfile, err := os.Create(tmpfile1)
if err != nil {
t.Fatal(err)
}
defer outfile.Close()
defer os.Remove(tmpfile1)
if err = Compress(fd, outfile, "", nil); err != nil {
t.Error(err)
}
outfile.Seek(0, os.SEEK_SET)
outfile2, err := os.Create(tmpfile2)
if err != nil {
t.Fatal(err)
}
defer outfile2.Close()
defer os.Remove(tmpfile2)
if err = Decompress(outfile, outfile2, "", nil); err != nil {
t.Error(err)
}
outfile2.Seek(0, os.SEEK_SET)
p, err = ioutil.ReadAll(outfile2)
if err != nil {
t.Fatal(err)
}
sum2 := sha256.Sum256(p)
if bytes.Compare(sum2[:], sum[:]) != 0 {
t.Errorf("Checksum fail, expected: %x\n", sum)
}
}
}
}