001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.awt;
019:
020: import java.awt.image.BufferedImage;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import junit.framework.TestCase;
025:
026: public class Graphics2DTest extends TestCase {
027: private Frame frame;
028:
029: protected void setUp() throws Exception {
030: super .setUp();
031: frame = new Frame();
032: frame.addNotify();
033: }
034:
035: protected void tearDown() throws Exception {
036: if (frame != null) {
037: frame.dispose();
038: }
039: super .tearDown();
040: }
041:
042: public void testSetPaintScreen() {
043: // regression test for HARMONY-1448
044: Graphics2D g2d = (Graphics2D) frame.getGraphics();
045: Paint paint = g2d.getPaint();
046: assertNotNull(paint);
047: g2d.setPaint(null);
048: assertNotNull(g2d.getPaint());
049: }
050:
051: public void testSetPaintImage() {
052: // regression test for HARMONY-1448
053: int imgType = BufferedImage.TYPE_INT_ARGB;
054: BufferedImage img = new BufferedImage(100, 100, imgType);
055: Graphics2D g2d = (Graphics2D) img.getGraphics();
056: Paint paint = g2d.getPaint();
057: assertNotNull(paint);
058: g2d.setPaint(null);
059: assertNotNull(g2d.getPaint());
060: }
061:
062: public void testGetRenderingHint() {
063: // Regression test for HARMONY-4799
064: final Graphics2D g2d = (Graphics2D) frame.getGraphics();
065:
066: assertEquals(
067: g2d
068: .getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING),
069: RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
070: assertEquals(g2d
071: .getRenderingHint(RenderingHints.KEY_ANTIALIASING),
072: RenderingHints.VALUE_ANTIALIAS_OFF);
073: assertEquals(g2d
074: .getRenderingHint(RenderingHints.KEY_STROKE_CONTROL),
075: RenderingHints.VALUE_STROKE_DEFAULT);
076: }
077:
078: public void testSetRenderingHint() {
079: // Regression test for HARMONY-4920
080: final Graphics2D g2d = (Graphics2D) frame.getGraphics();
081: final Map<RenderingHints.Key, Object> m = new HashMap<RenderingHints.Key, Object>();
082:
083: m.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
084: RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
085: m.put(RenderingHints.KEY_TEXT_ANTIALIASING,
086: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
087:
088: g2d.setRenderingHints(m);
089:
090: assertEquals(
091: RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY,
092: g2d
093: .getRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION));
094: assertEquals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF, g2d
095: .getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
096: assertEquals(RenderingHints.VALUE_ANTIALIAS_OFF, g2d
097: .getRenderingHint(RenderingHints.KEY_ANTIALIASING));
098: assertEquals(RenderingHints.VALUE_STROKE_DEFAULT, g2d
099: .getRenderingHint(RenderingHints.KEY_STROKE_CONTROL));
100: }
101: }
|