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.png.chunks;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertThrows;
21  
22  import org.apache.commons.imaging.ImagingException;
23  import org.junit.jupiter.api.Test;
24  
25  public class PngChunkScalTest {
26      private static final double delta = 0.001;
27      private static final int chunkType = 1933787468;
28  
29      @Test
30      public void testConstruct_InvalidDblValue() {
31          assertThrows(ImagingException.class, () -> new PngChunkScal(10, chunkType, 0, new byte[] { 2, 65, 46, 48, 49, 0, 48, 46, 48, 50 }));
32      }
33  
34      @Test
35      public void testConstruct_InvalidUnitSpecifier() {
36          assertThrows(ImagingException.class, () -> new PngChunkScal(10, chunkType, 0, new byte[] { 3, 48, 46, 48, 49, 0, 48, 46, 48, 50 }));
37      }
38  
39      @Test
40      public void testConstruct_MissingSeparator() {
41          assertThrows(ImagingException.class, () -> new PngChunkScal(9, chunkType, 0, new byte[] { 1, 48, 46, 48, 49, 48, 46, 48, 50 }));
42      }
43  
44      @Test
45      public void testConstruct_MissingXValue() {
46          assertThrows(ImagingException.class, () -> new PngChunkScal(2, chunkType, 0, new byte[] { 2, 0 }));
47      }
48  
49      @Test
50      public void testConstruct_MissingYValue() {
51          assertThrows(ImagingException.class, () -> new PngChunkScal(6, chunkType, 0, new byte[] { 2, 48, 46, 48, 49, 0 }));
52      }
53  
54      @Test
55      public void testConstructMeters() throws ImagingException {
56          final PngChunkScal pngChunkScal = new PngChunkScal(10, chunkType, 0, new byte[] { 1, 48, 46, 48, 49, 0, 48, 46, 48, 50 });
57  
58          assertEquals(pngChunkScal.getUnitSpecifier(), 1);
59          assertEquals(pngChunkScal.getUnitsPerPixelXAxis(), 0.01, delta);
60          assertEquals(pngChunkScal.getUnitsPerPixelYAxis(), 0.02, delta);
61      }
62  
63      @Test
64      public void testConstructRadians() throws ImagingException {
65          final PngChunkScal pngChunkScal = new PngChunkScal(10, chunkType, 0, new byte[] { 2, 48, 46, 48, 49, 0, 48, 46, 48, 50 });
66  
67          assertEquals(pngChunkScal.getUnitSpecifier(), 2);
68          assertEquals(pngChunkScal.getUnitsPerPixelXAxis(), 0.01, delta);
69          assertEquals(pngChunkScal.getUnitsPerPixelYAxis(), 0.02, delta);
70      }
71  }