Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/jpeg/JpegNumThumbnailsTest.java
41152 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
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 4954348
27
* @summary Checks whether JpegImageWriter returns -1 as recommended by the
28
* specification when getNumThumbnailsSupported method is invoked
29
* with insufficient data.
30
* @run main JpegNumThumbnailsTest
31
*/
32
import javax.imageio.ImageIO;
33
import javax.imageio.ImageTypeSpecifier;
34
import javax.imageio.ImageWriter;
35
import javax.imageio.metadata.IIOMetadata;
36
import java.awt.image.BufferedImage;
37
import java.util.Iterator;
38
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
39
40
public class JpegNumThumbnailsTest {
41
42
public static void main(String args[]) {
43
// Test variables.
44
Iterator<ImageWriter> iterWriter = null;
45
ImageWriter jpgWriter = null;
46
IIOMetadata imgMetadata = null;
47
BufferedImage testImage = null;
48
ImageTypeSpecifier imgType = null;
49
int numThumbnails = 0;
50
51
iterWriter = ImageIO.getImageWritersByFormatName("JPEG");
52
if (iterWriter.hasNext()) {
53
try {
54
// JpegImageWriter requires either image type or image metadata
55
// to determine the number of thumbnails that could be
56
// supported. Hence we test for all possible input combinations
57
// and observe the result.
58
jpgWriter = iterWriter.next();
59
testImage = new BufferedImage(32, 32, TYPE_INT_RGB);
60
imgType = ImageTypeSpecifier.createFromRenderedImage(testImage);
61
imgMetadata = jpgWriter.getDefaultImageMetadata(imgType, null);
62
63
// Observe the result with insufficient data.
64
numThumbnails = jpgWriter.getNumThumbnailsSupported(null,
65
null, null, null);
66
if (numThumbnails != -1) {
67
reportException("Incorrect number of thumbnails returned.");
68
}
69
70
// Observe the result with valid image type.
71
numThumbnails = jpgWriter.getNumThumbnailsSupported(imgType,
72
null, null, null);
73
if (numThumbnails != Integer.MAX_VALUE) {
74
reportException("Incorrect number of thumbnails returned.");
75
}
76
77
// Observe the result with valid image metadata.
78
numThumbnails = jpgWriter.getNumThumbnailsSupported(null,
79
null, null, imgMetadata);
80
if (numThumbnails != Integer.MAX_VALUE) {
81
reportException("Incorrect number of thumbnails returned.");
82
}
83
84
// Observe the result with valid image type and metadata.
85
numThumbnails = jpgWriter.getNumThumbnailsSupported(imgType,
86
null, null, imgMetadata);
87
if (numThumbnails != Integer.MAX_VALUE) {
88
reportException("Incorrect number of thumbnails returned.");
89
}
90
} finally {
91
// Dispose the writer
92
jpgWriter.dispose();
93
}
94
}
95
}
96
97
private static void reportException(String message) {
98
// Report a runtime exception with the required message.
99
throw new RuntimeException("Test Failed. " + message);
100
}
101
}
102
103