Debian Codegraph @

internal/warpc/avif_integration_test.go

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