01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.harmony.awt.tests.image;
18:
19: import java.awt.Frame;
20: import java.awt.Image;
21: import java.awt.MediaTracker;
22: import java.awt.Toolkit;
23: import java.awt.image.BufferedImage;
24: import java.net.URL;
25: import javax.swing.ImageIcon;
26: import junit.framework.TestCase;
27:
28: public class BufferedImageTest extends TestCase {
29:
30: private final int EXP_WIDTH = 320;
31: private final int EXP_HEIGHT = 182;
32:
33: public void testJpg() throws InterruptedException {
34: decodeImage("utest.jpg");
35: }
36:
37: public void testGif() throws InterruptedException {
38: decodeImage("utest.gif");
39: }
40:
41: public void testPng() throws InterruptedException {
42: decodeImage("utest.png");
43: }
44:
45: private final ClassLoader c = ClassLoader.getSystemClassLoader();
46:
47: private Image createImage(String name) {
48: final URL path = c.getResource("../resources/images/" + name);
49: assertNotNull("Resource not found: " + name, path); //$NON-NLS-1$
50: return Toolkit.getDefaultToolkit().createImage(path);
51: }
52:
53: private void decodeImage(String name) throws InterruptedException {
54: final Image im = createImage(name);
55: final BufferedImage bim = new BufferedImage(EXP_WIDTH,
56: EXP_HEIGHT, BufferedImage.TYPE_INT_RGB);
57: final Frame f = new Frame();
58: final MediaTracker t = new MediaTracker(f);
59:
60: t.addImage(im, 0);
61: t.waitForAll();
62:
63: assertEquals(EXP_WIDTH, im.getWidth(null));
64: assertEquals(EXP_HEIGHT, im.getHeight(null));
65:
66: bim.getGraphics().drawImage(im, 0, 0, null);
67: int rgbVal = bim.getRGB(0, 0);
68: assertEquals(0xFFFFFFFF, rgbVal);
69: }
70:
71: /**
72: * Regression test for HARMONY-3602
73: */
74: public void testTerminate() {
75: final Image img = createImage("test.gif");
76:
77: System.out.println(new ImageIcon(img)); // Loads the image.
78: img.flush(); // ERROR: Calls Thread.currentThread().interrupt().
79: assertFalse("Current thread is interrupted", Thread
80: .currentThread().isInterrupted());
81: }
82: }
|