Debian Codegraph @

internal/warpc/avif_integration_test.go

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 package warpc_test
2
3 import (
4 "strings"
5 "testing"
6
7 qt "github.com/frankban/quicktest"
8 "github.com/gohugoio/hugo/hugolib"
9 "github.com/gohugoio/hugo/resources/images/imagetesting"
10 )
11
12 func TestAvifBasic(t *testing.T) {
13 if imagetesting.SkipGoldenTests {
14 t.Skip("Skip golden test on this architecture")
15 }
16
17 files := `
18 -- hugo.toml --
19 -- assets/sunset.avif --
20 sourcefilename: ../../resources/testdata/bep/dock-75-hdr.avif
21 -- layouts/home.html --
22 {{ $image := resources.Get "sunset.avif" }}
23 Width/Height: {{ $image.Width }}/{{ $image.Height }}|
24 Decode avif: {{ $jpeg := $image.Process "jpeg" }}|{{ $jpeg.RelPermalink }}|
25 Encode avif from JPEG: {{ $avif := $jpeg.Process "avif" }}|{{ $avif.RelPermalink }}|
26 Encode avif from avif: {{ $avif := $image.Process "avif" }}|{{ $avif.RelPermalink }}|
27 `
28
29 b, err := hugolib.TestE(t, files)
30 b.Assert(err, qt.IsNil)
31 b.AssertFileContent("public/index.html", "Width/Height: 1024/683")
32 }
33
34 // giphy.avif is an animated AVIF transcoded from giphy.gif (14 frames @ 200ms,
35 // infinite loop) via avifenc. Verifies that decode preserves animation, the
36 // pipeline runs every frame through resize, the GIF encoder writes a multi-frame
37 // GIF, and the libavif "repetitionCount" → Go "LoopCount" inversion (libavif
38 // -1 = infinite, image/gif 0 = infinite) is handled at the AVIF decoder boundary.
39 func TestAvifAnimatedToGif(t *testing.T) {
40 if imagetesting.SkipGoldenTests {
41 t.Skip("Skip golden test on this architecture")
42 }
43
44 files := `
45 -- hugo.toml --
46 disableKinds = ["page", "section", "taxonomy", "term", "sitemap", "robotsTXT", "404"]
47 -- assets/giphy.avif --
48 sourcefilename: ../../resources/testdata/giphy.avif
49 -- layouts/home.html --
50 {{ $img := resources.Get "giphy.avif" }}
51 {{ $gif := $img.Resize "x60 gif" }}
52 {{ $gif.Publish }}
53 gif:{{ $gif.RelPermalink }}
54 `
55
56 b := hugolib.Test(t, files)
57 rel := b.FileContent("public/index.html")
58
59 var gifFile string
60 for line := range strings.SplitSeq(rel, "\n") {
61 if rest, ok := strings.CutPrefix(line, "gif:"); ok {
62 gifFile = "public" + rest
63 break
64 }
65 }
66 b.Assert(gifFile, qt.Not(qt.Equals), "")
67
68 durations := make([]int, 14)
69 for i := range durations {
70 durations[i] = 200
71 }
72 b.ImageHelper(gifFile).
73 AssertFormat("gif").
74 AssertIsAnimated(true).
75 AssertLoopCount(0).
76 AssertFrameDurations(durations)
77 }
78
79 // See issue 14987.
80 func TestAvifEncodeHintSubsampling(t *testing.T) {
81 files := `
82 -- hugo.toml --
83 -- assets/logo.png --
84 sourcefilename: ../../resources/testdata/gohugoio24.png
85 -- layouts/home.html --
86 {{ $img := resources.Get "logo.png" }}
87 default:{{ ($img.Process "avif photo").RelPermalink }}|
88 photo:{{ ($img.Process "avif photo").RelPermalink }}|
89 text:{{ ($img.Process "avif text").RelPermalink }}|
90 `
91
92 b := hugolib.Test(t, files)
93 b.AssertFileContent("public/index.html",
94 `
95 default:/logo_hu_72e150ce03376cfd.avif|
96 photo:/logo_hu_72e150ce03376cfd.avif|
97 text:/logo_hu_9de8f282912bc925.avif|
98 `)
99 }
100
101 // See issue 14985.
102 func TestAvifEncodeOutOfMemory(t *testing.T) {
103 files := `
104 -- assets/gopher.png --
105 sourcefilename: ../../resources/testdata/bw-gopher.png
106 -- layouts/home.html --
107 {{ $img := resources.Get "gopher.png" }}
108 {{ $r := try ($img.Resize "3000x3000 avif") }}
109 {{ with $r.Err }}BigErr: {{ . }}|{{ else }}BigOK|{{ end }}
110 {{ $small := $img.Resize "32x32 avif" }}
111 SmallAfter: {{ $small.RelPermalink }}|
112 `
113
114 b := hugolib.Test(t, files, hugolib.TestOptWithConfig(func(c *hugolib.IntegrationTestConfig) {
115 c.WarpcMemory = 8
116 }))
117
118 // The big resize must fail gracefully (caught by try) ...
119 b.AssertFileContent("public/index.html",
120 "BigErr:",
121 "out of memory allocating",
122 "for blob data",
123 // ... and the dispatcher must still process images afterwards.
124 "SmallAfter: /gopher_",
125 )
126 }