...
1
2
3
4
5 package s2
6
7 import (
8 "bytes"
9 "fmt"
10 "math"
11 "testing"
12 )
13
14 func TestEncodeHuge(t *testing.T) {
15 if true {
16 t.Skip("Takes too much memory")
17 }
18 test := func(t *testing.T, data []byte) {
19 comp := Encode(make([]byte, MaxEncodedLen(len(data))), data)
20 decoded, err := Decode(nil, comp)
21 if err != nil {
22 t.Error(err)
23 return
24 }
25 if !bytes.Equal(data, decoded) {
26 t.Error("block decoder mismatch")
27 return
28 }
29 if mel := MaxEncodedLen(len(data)); len(comp) > mel {
30 t.Error(fmt.Errorf("MaxEncodedLen Exceed: input: %d, mel: %d, got %d", len(data), mel, len(comp)))
31 return
32 }
33 comp = EncodeBetter(make([]byte, MaxEncodedLen(len(data))), data)
34 decoded, err = Decode(nil, comp)
35 if err != nil {
36 t.Error(err)
37 return
38 }
39 if !bytes.Equal(data, decoded) {
40 t.Error("block decoder mismatch")
41 return
42 }
43 if mel := MaxEncodedLen(len(data)); len(comp) > mel {
44 t.Error(fmt.Errorf("MaxEncodedLen Exceed: input: %d, mel: %d, got %d", len(data), mel, len(comp)))
45 return
46 }
47
48 comp = EncodeBest(make([]byte, MaxEncodedLen(len(data))), data)
49 decoded, err = Decode(nil, comp)
50 if err != nil {
51 t.Error(err)
52 return
53 }
54 if !bytes.Equal(data, decoded) {
55 t.Error("block decoder mismatch")
56 return
57 }
58 if mel := MaxEncodedLen(len(data)); len(comp) > mel {
59 t.Error(fmt.Errorf("MaxEncodedLen Exceed: input: %d, mel: %d, got %d", len(data), mel, len(comp)))
60 return
61 }
62 }
63 test(t, make([]byte, math.MaxInt32))
64 if math.MaxInt > math.MaxInt32 {
65 x := int64(math.MaxInt32 + math.MaxUint16)
66 test(t, make([]byte, x))
67 }
68 test(t, make([]byte, MaxBlockSize))
69 }
70
View as plain text