-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
cover_test.go
79 lines (69 loc) · 1.65 KB
/
cover_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (c) 2018 LI Zhennan
*
* Use of this work is governed by an MIT License.
* You may find a license copy in project root.
*
*/
package orly
import (
"math/rand"
"testing"
"golang.org/x/image/colornames"
"github.com/pkg/errors"
)
var coverFact *CoverFactory
const (
maxImageID = 3
)
func init() {
var err error
defer func() {
if err != nil {
panic(err)
}
}()
provider := NewImageProvider(LoadTIFFFromFolder("coverimage"))
normalFont, err := LoadFont("font/SourceHanSans-Medium.ttc")
if err != nil {
err = errors.Wrap(err, "LoadFont normalFont")
return
}
titleFont, err := LoadFont("font/SourceHanSerif-Bold.ttc")
if err != nil {
err = errors.Wrap(err, "LoadFont titleFont")
return
}
orlyFont, err := LoadFont("font/SourceHanSans-Heavy.ttc")
if err != nil {
err = errors.Wrap(err, "LoadFont orlyFont")
return
}
coverFact = NewCoverFactory(1000, 1400, provider, titleFont, normalFont, orlyFont)
// cache cover images
err = coverFact.PreheatCache(maxImageID)
if err != nil {
err = errors.Wrap(err, "PreheatCache")
return
}
}
func BenchmarkCoverFactory_Draw(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
var err error
for pb.Next() {
_, err = coverFact.Draw("思源宋體",
"Source Han Sans | 思源黑体 | 思源黑體 | 源ノ角ゴシック | 본고딕",
"nanmu42",
"思源黑體 | 源ノ角ゴシック | 본고딕",
"BR",
colornames.Red, rand.Intn(4))
if err != nil {
b.Fatal(err)
}
}
})
if coverFact.CoverProvider.Miss() > maxImageID+1 {
b.Fatalf("cache missed too much: got %v, want %v", coverFact.CoverProvider.Miss(), maxImageID+1)
}
}