1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.bmp;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import java.awt.image.BufferedImage;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.Collection;
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.ImagingTestConstants;
31 import org.apache.commons.imaging.bytesource.ByteSource;
32 import org.apache.commons.imaging.test.TestResources;
33 import org.junit.jupiter.api.Disabled;
34 import org.junit.jupiter.api.Test;
35 import org.junit.jupiter.params.ParameterizedTest;
36 import org.junit.jupiter.params.provider.MethodSource;
37
38 public class BmpReadTest extends AbstractBmpTest {
39
40 public static Collection<File> data() throws Exception {
41 return getBmpImages();
42 }
43
44 @ParameterizedTest
45 @MethodSource("data")
46 public void testBufferedImage(final File imageFile) throws Exception {
47 final BufferedImage image = Imaging.getBufferedImage(imageFile);
48 assertNotNull(image);
49
50 }
51
52
53
54
55
56
57
58 @Test
59 public void testGetMaskShiftZeroMask() throws ImagingException, IOException {
60 final File inputFile = new File(ImagingTestConstants.TEST_IMAGE_FOLDER + "/bmp/5/@broken/timeout-bd15dbfa26b4e88070de540c6603039e8a88626f");
61 new BmpImageParser().dumpImageFile(ByteSource.file(inputFile));
62 }
63
64 @ParameterizedTest
65 @MethodSource("data")
66 public void testImageInfo(final File imageFile) throws ImagingException, IOException {
67 final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
68 assertNotNull(imageInfo);
69
70 }
71
72 @Disabled(value = "RoundtripTest has to be fixed before implementation can throw UnsupportedOperationException")
73 @ParameterizedTest
74 @MethodSource("data")
75 public void testMetaData(final File imageFile) {
76 assertThrows(UnsupportedOperationException.class, () -> Imaging.getMetadata(imageFile));
77 }
78
79 @Test
80 public void testNegativePaletteLength() {
81 final File inputFile = TestResources.resourceToFile("/images/bmp/IMAGING-325/crash-3afb569de74522535ef65922233e1920455cdc14.bmp");
82 assertThrows(ImagingException.class, () -> new BmpImageParser().dumpImageFile(ByteSource.file(inputFile)));
83 }
84 }