-
Notifications
You must be signed in to change notification settings - Fork 140
/
WebpTest.kt
48 lines (40 loc) · 1.66 KB
/
WebpTest.kt
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
package com.sksamuel.scrimage.webp
import com.sksamuel.scrimage.ImmutableImage
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import java.io.IOException
// these tests cannot run on the server as we cannot include webp with our code
class WebpTest : FunSpec() {
init {
test("webp reader") {
val image = ImmutableImage.loader().fromResource("/test.webp")
image.width shouldBe 2000
image.height shouldBe 2000
}
test("webp writer") {
ImmutableImage.loader().fromResource("/spacedock.jpg").scale(0.5)
.bytes(WebpWriter.MAX_LOSSLESS_COMPRESSION) shouldBe
javaClass.getResourceAsStream("/spacedock.webp").readBytes()
}
test("no alpha") {
val webpWriter = WebpWriter.DEFAULT.withoutAlpha()
ImmutableImage.loader().fromResource("/alpha.png")
.bytes(webpWriter) shouldBe
javaClass.getResourceAsStream("/noAlpha.webp").readBytes()
}
test("render with multi thread") {
val webpWriter = WebpWriter.MAX_LOSSLESS_COMPRESSION.withMultiThread()
ImmutableImage.loader().fromResource("/spacedock.jpg").scale(0.5)
.bytes(webpWriter) shouldBe
javaClass.getResourceAsStream("/spacedock.webp").readBytes()
}
test("dwebp should capture error on failure") {
val dwebpPath = WebpHandler.getBinaryPaths("dwebp")[2]
shouldThrow<IOException> {
ImmutableImage.loader().fromResource(dwebpPath)
}.message.shouldContain("BITSTREAM_ERROR")
}
}
}