-
Notifications
You must be signed in to change notification settings - Fork 0
/
dxt_test.go
62 lines (48 loc) · 1.5 KB
/
dxt_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
package dxt
import (
"bytes"
"io/ioutil"
"testing"
)
// assertEqual fails if the two values are not equal
func assertEqual[T comparable](t testing.TB, got, want T) {
t.Helper()
if got != want {
t.Errorf("got: %v != want: %v", got, want)
}
}
func TestDecodeDXT1(t *testing.T) {
enc, err := ioutil.ReadFile("testdata/dxt1.encoded")
assertEqual(t, err == nil, true)
decg, err := DecodeDXT1(enc, 256, 256)
assertEqual(t, err == nil, true)
decw, err := ioutil.ReadFile("testdata/dxt1.decoded")
assertEqual(t, err == nil, true)
assertEqual(t, bytes.Compare(decg, decw), 0)
}
func TestDecodeDXT3(t *testing.T) {
enc, err := ioutil.ReadFile("testdata/dxt3.encoded")
assertEqual(t, err == nil, true)
decg, err := DecodeDXT3(enc, 128, 512)
assertEqual(t, err == nil, true)
decw, err := ioutil.ReadFile("testdata/dxt3.decoded")
assertEqual(t, err == nil, true)
assertEqual(t, bytes.Compare(decg, decw), 0)
}
func TestDecodeDXT5(t *testing.T) {
enc, err := ioutil.ReadFile("testdata/dxt5.encoded")
assertEqual(t, err == nil, true)
decg, err := DecodeDXT5(enc, 64, 64)
assertEqual(t, err == nil, true)
decw, err := ioutil.ReadFile("testdata/dxt5.decoded")
assertEqual(t, err == nil, true)
assertEqual(t, bytes.Compare(decg, decw), 0)
}
func TestDecodeErrors(t *testing.T) {
_, err := DecodeDXT1(make([]byte, 0), 4, 4)
assertEqual(t, err != nil, true)
_, err = DecodeDXT3(make([]byte, 0), 4, 4)
assertEqual(t, err != nil, true)
_, err = DecodeDXT5(make([]byte, 0), 4, 4)
assertEqual(t, err != nil, true)
}