@@ -2,6 +2,7 @@ package libwebp
22
33import (
44 "bytes"
5+ "flag"
56 "image"
67 "image/draw"
78 "image/jpeg"
@@ -14,24 +15,29 @@ import (
1415 "runtime"
1516 "strings"
1617 "testing"
18+ "time"
1719
1820 "github.com/bep/gowebp/internal/libwebp"
1921
2022 "github.com/bep/gowebp/libwebp/options"
2123 "golang.org/x/image/webp"
2224)
2325
26+ type testCase struct {
27+ name string
28+ inputFile string
29+ opts options.EncodingOptions
30+ }
31+
32+ var testCases = []testCase {
33+ {"lossy" , "source.jpg" , options.EncodingOptions {Quality : 75 , EncodingPreset : options .PresetPhoto , UseSharpYuv : true }},
34+ {"lossless" , "source.jpg" , options.EncodingOptions {}},
35+ {"bw" , "bw-gopher.png" , options.EncodingOptions {Quality : 75 }},
36+ }
37+
2438func TestEncode (t * testing.T ) {
2539 writeGolden := false
26- for _ , test := range []struct {
27- name string
28- inputFile string
29- opts options.EncodingOptions
30- }{
31- {"lossy" , "source.jpg" , options.EncodingOptions {Quality : 75 , EncodingPreset : options .PresetPhoto , UseSharpYuv : true }},
32- {"lossless" , "source.jpg" , options.EncodingOptions {}},
33- {"bw" , "bw-gopher.png" , options.EncodingOptions {Quality : 75 }},
34- } {
40+ for _ , test := range testCases {
3541 t .Run (test .name , func (t * testing.T ) {
3642 r , err := os .Open (filepath .Join ("../test_data/images" , test .inputFile ))
3743 if err != nil {
@@ -81,17 +87,39 @@ func TestEncode(t *testing.T) {
8187 }
8288}
8389
90+ var longrunning = flag .Bool ("longrunning" , false , "Enable long running tests." )
91+
92+ // go test -v ./libwebp --longrunning
93+ func TestEncodeLongRunning (t * testing.T ) {
94+ if ! (* longrunning ) {
95+ t .Skip ("Skip long running test..." )
96+ }
97+ t .Log ("Start..." )
98+ for i := 0 ; i < 60 ; i ++ {
99+ for _ , test := range testCases {
100+ r , err := os .Open (filepath .Join ("../test_data/images" , test .inputFile ))
101+ if err != nil {
102+ t .Fatal (err )
103+ }
104+
105+ img , _ , err := image .Decode (r )
106+ if err != nil {
107+ t .Fatal (err )
108+ }
109+
110+ if err = Encode (ioutil .Discard , img , test .opts ); err != nil {
111+ t .Fatal (err )
112+ }
113+ }
114+
115+ time .Sleep (2 * time .Second )
116+ }
117+
118+ t .Log ("Done..." )
119+ }
120+
84121func BenchmarkEncode (b * testing.B ) {
85- for _ , test := range []struct {
86- name string
87- inputFile string
88- opts options.EncodingOptions
89- }{
90- {"lossy" , "source.jpg" , options.EncodingOptions {Quality : 75 , EncodingPreset : options .PresetPhoto }},
91- {"lossy-sharp-yuv" , "source.jpg" , options.EncodingOptions {Quality : 75 , EncodingPreset : options .PresetPhoto , UseSharpYuv : true }},
92- {"lossless" , "source.jpg" , options.EncodingOptions {}},
93- {"bw" , "bw-gopher.png" , options.EncodingOptions {Quality : 75 }},
94- } {
122+ for _ , test := range testCases {
95123 b .Run (test .name , func (b * testing.B ) {
96124 r , err := os .Open (filepath .Join ("../test_data/images" , test .inputFile ))
97125 if err != nil {
0 commit comments