6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8152183 8149562
27 * @author a.stepanov
28 * @summary Some checks for TIFFField methods
29 * @run main TIFFFieldTest
30 */
31
32 import java.util.List;
33 import java.util.ArrayList;
34 import javax.imageio.metadata.IIOMetadataNode;
35 import javax.imageio.plugins.tiff.*;
36 import org.w3c.dom.NamedNodeMap;
37 import org.w3c.dom.Node;
38
39 public class TIFFFieldTest {
40
41 private final static String NAME = "tag"; // tag name
42 private final static int NUM = 12345; // tag number
43 private final static int MIN_TYPE = TIFFTag.MIN_DATATYPE;
44 private final static int MAX_TYPE = TIFFTag.MAX_DATATYPE;
45 private final static String CONSTRUCT = "can construct TIFFField with ";
46
48 if (!ok) { throw new RuntimeException(msg); }
49 }
50
51 private void testConstructors() {
52
53 // test constructors
54
55 TIFFTag tag = new TIFFTag(
56 NAME, NUM, 1 << TIFFTag.TIFF_SHORT | 1 << TIFFTag.TIFF_LONG);
57 TIFFField f;
58
59 // constructor: TIFFField(tag, value)
60 boolean ok = false;
61 try { new TIFFField(null, 0); }
62 catch (NullPointerException e) { ok = true; }
63 check(ok, CONSTRUCT + "null tag");
64
65 ok = false;
66 try { new TIFFField(tag, -1); }
67 catch (IllegalArgumentException e) { ok = true; }
68 check(ok, CONSTRUCT + "invalid count");
69
70 // check value type recognition
71 int v = 1 << 16;
72 f = new TIFFField(tag, v - 1);
73 check(f.getType() == TIFFTag.TIFF_SHORT, "must be treated as short");
74 check(f.isIntegral(), "must be integral");
75 f = new TIFFField(tag, v);
76 check(f.getType() == TIFFTag.TIFF_LONG, "must be treated as long");
77
78 // other checks
79 check(f.getAsLongs().length == 1, "invalid long[] size");
80 check(f.isIntegral(), "must be integral");
81 check((f.getDirectory() == null) && !f.hasDirectory(),
82 "must not have directory");
83 check(f.getValueAsString(0).equals(String.valueOf(v)),
84 "invalid string representation of value");
85 check(f.getTag().getNumber() == f.getTagNumber(),
86 "invalid tag number");
87 check(f.getCount() == 1, "invalid count");
88 check(f.getTagNumber() == NUM, "invalid tag number");
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8152183 8149562 8169725
27 * @author a.stepanov
28 * @summary Some checks for TIFFField methods
29 * @run main TIFFFieldTest
30 */
31
32 import java.util.List;
33 import java.util.ArrayList;
34 import javax.imageio.metadata.IIOMetadataNode;
35 import javax.imageio.plugins.tiff.*;
36 import org.w3c.dom.NamedNodeMap;
37 import org.w3c.dom.Node;
38
39 public class TIFFFieldTest {
40
41 private final static String NAME = "tag"; // tag name
42 private final static int NUM = 12345; // tag number
43 private final static int MIN_TYPE = TIFFTag.MIN_DATATYPE;
44 private final static int MAX_TYPE = TIFFTag.MAX_DATATYPE;
45 private final static String CONSTRUCT = "can construct TIFFField with ";
46
48 if (!ok) { throw new RuntimeException(msg); }
49 }
50
51 private void testConstructors() {
52
53 // test constructors
54
55 TIFFTag tag = new TIFFTag(
56 NAME, NUM, 1 << TIFFTag.TIFF_SHORT | 1 << TIFFTag.TIFF_LONG);
57 TIFFField f;
58
59 // constructor: TIFFField(tag, value)
60 boolean ok = false;
61 try { new TIFFField(null, 0); }
62 catch (NullPointerException e) { ok = true; }
63 check(ok, CONSTRUCT + "null tag");
64
65 ok = false;
66 try { new TIFFField(tag, -1); }
67 catch (IllegalArgumentException e) { ok = true; }
68 check(ok, CONSTRUCT + "negative value");
69
70 ok = false;
71 try { new TIFFField(tag, 1L << 32); }
72 catch (IllegalArgumentException e) { ok = true; }
73 check(ok, CONSTRUCT + "value > 0xffffffff");
74
75 ok = false;
76 try {
77 TIFFTag t = new TIFFTag(NAME, NUM, 1 << TIFFTag.TIFF_SHORT);
78 new TIFFField(t, 0x10000);
79 } catch (IllegalArgumentException e) { ok = true; }
80 check(ok, CONSTRUCT + "value 0x10000 incompatible with TIFF_SHORT");
81
82 ok = false;
83 try {
84 TIFFTag t = new TIFFTag(NAME, NUM, 1 << TIFFTag.TIFF_LONG);
85 new TIFFField(t, 0xffff);
86 } catch (IllegalArgumentException e) { ok = true; }
87 check(ok, CONSTRUCT + "value 0xffff incompatible with TIFF_LONG");
88
89 // check value type recognition
90 int v = 1 << 16;
91 f = new TIFFField(tag, v - 1);
92 check(f.getType() == TIFFTag.TIFF_SHORT, "must be treated as short");
93 check(f.isIntegral(), "must be integral");
94 f = new TIFFField(tag, v);
95 check(f.getType() == TIFFTag.TIFF_LONG, "must be treated as long");
96
97 // other checks
98 check(f.getAsLongs().length == 1, "invalid long[] size");
99 check(f.isIntegral(), "must be integral");
100 check((f.getDirectory() == null) && !f.hasDirectory(),
101 "must not have directory");
102 check(f.getValueAsString(0).equals(String.valueOf(v)),
103 "invalid string representation of value");
104 check(f.getTag().getNumber() == f.getTagNumber(),
105 "invalid tag number");
106 check(f.getCount() == 1, "invalid count");
107 check(f.getTagNumber() == NUM, "invalid tag number");
|