View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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          // TODO assert more
50      }
51  
52      /**
53       * Test that when the value of the mask parameter is zero, getMaskShift won't get stuck in one of its while loops.
54       *
55       * @throws IOException
56       * @throws ImagingException
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          // TODO assert more
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  }