1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.webp;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.File;
25 import java.io.IOException;
26
27 import org.apache.commons.imaging.ImageInfo;
28 import org.apache.commons.imaging.Imaging;
29 import org.apache.commons.imaging.ImagingException;
30 import org.apache.commons.imaging.bytesource.ByteSource;
31 import org.apache.commons.imaging.common.ImageMetadata;
32 import org.apache.commons.imaging.formats.webp.chunks.WebPChunkIccp;
33 import org.apache.commons.imaging.internal.Debug;
34 import org.junit.jupiter.api.Assertions;
35 import org.junit.jupiter.api.Test;
36 import org.junit.jupiter.params.ParameterizedTest;
37 import org.junit.jupiter.params.provider.MethodSource;
38
39
40
41
42 public class WebPReadTest extends WebPBaseTest {
43
44
45
46
47
48
49 @Test
50 public void testBufferedImageNotSupported() throws IOException {
51 final File emptyWebP = new File(WebPReadTest.class.getResource("/images/webp/empty/empty-100x100.webp").getFile());
52 final WebPImageParser parser = new WebPImageParser();
53 final ImagingException exception = assertThrows(ImagingException.class, () -> {
54 parser.getBufferedImage(ByteSource.file(emptyWebP), parser.getDefaultParameters());
55 });
56 assertTrue(exception.getMessage().contains("Reading WebP files is currently not supported"));
57 }
58
59
60
61
62 @Test
63 public void testParser() {
64 final WebPImageParser parser = new WebPImageParser();
65 assertEquals("WebP-Custom", parser.getName());
66 assertEquals("webp", parser.getDefaultExtension());
67 }
68
69
70
71
72
73 @ParameterizedTest
74 @MethodSource("images")
75 public void testRead(final File imageFile) throws Exception {
76 Debug.debug("start");
77
78 Debug.debug("imageFile", imageFile);
79
80 final ImageMetadata metadata = Imaging.getMetadata(imageFile);
81 Assertions.assertFalse(metadata instanceof File);
82
83 final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
84 assertNotNull(imageInfo);
85
86 Debug.debug("ICC profile", Imaging.getIccProfileBytes(imageFile));
87 }
88
89
90
91
92 @Test
93 public void testWebPChunkInvalidSizeBytes() {
94 final ImagingException exception = assertThrows(ImagingException.class, () -> {
95 new WebPChunkIccp(0, 10, new byte[] {});
96 });
97 assertEquals("Chunk size must match bytes length", exception.getMessage());
98 }
99 }