1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.tiff;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import java.io.File;
22
23 import org.apache.commons.imaging.ImageInfo;
24 import org.apache.commons.imaging.Imaging;
25 import org.apache.commons.imaging.ImagingTestConstants;
26 import org.junit.jupiter.api.Test;
27
28
29
30
31
32 public class TiffReadImageInfoTest extends TiffBaseTest {
33
34
35
36
37
38 static final String[][] testSet = { { "1/matthew2.tif", "Color Type", "Black and White" },
39 { "7/Oregon Scientific DS6639 - DSC_0307 - small - CMYK.tiff", "Color Type", "CMYK" }, { "10/Imaging247.TIFF", "Uses Palette", "true" },
40 { "12/TransparencyTestStripAssociated.tif", "Is Transparent", "true" }, { "14/TestJpegStrips.tiff", "Color Type", "YCbCr" } };
41
42 private File getTiffFile(final String name) {
43 final File tiffFolder = new File(ImagingTestConstants.TEST_IMAGE_FOLDER, "tiff");
44 return new File(tiffFolder, name);
45 }
46
47
48
49
50
51
52
53
54
55 private String getValue(final ImageInfo info, final String target) {
56 final String s = info.toString();
57 final int i = s.indexOf(target);
58 if (i < 0) {
59 return "";
60 }
61 final int j = s.indexOf(':', i);
62 if (j < 0) {
63 return "";
64 }
65 final int k = s.indexOf('\n', j);
66 if (k < j) {
67 return "";
68 }
69 return s.substring(j + 1, k).trim();
70 }
71
72 @Test
73 public void testImageInfoElements() throws Exception {
74 for (final String[] testTarget : testSet) {
75 final File targetFile = getTiffFile(testTarget[0]);
76 final ImageInfo info = Imaging.getImageInfo(targetFile);
77 final String value = getValue(info, testTarget[1]);
78 final String identifier = targetFile.getName() + ": " + testTarget[1];
79 assertEquals(value.toLowerCase(), testTarget[2].toLowerCase(), identifier);
80 }
81 }
82
83 }