Path: blob/master/test/jdk/sun/java2d/DrawXORModeTest.java
41145 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 803602227* @summary Test verifies that drawing shapes with XOR composite28* does not trigger an InternalError in GDI surface data.29* @run main/othervm -Dsun.java2d.d3d=True DrawXORModeTest30*/31import java.awt.BasicStroke;32import java.awt.Color;33import java.awt.Component;34import java.awt.Dimension;35import java.awt.Frame;36import java.awt.Graphics;37import java.awt.Graphics2D;38import java.awt.Stroke;39import java.awt.geom.Line2D;40import java.util.concurrent.CountDownLatch;4142public class DrawXORModeTest extends Component {4344public static void main(String[] args) {45final DrawXORModeTest c = new DrawXORModeTest();4647final Frame f = new Frame("XOR mode test");48f.add(c);49f.pack();5051f.setVisible(true);5253try {54c.checkResult();55} finally {56f.dispose();57}58}5960@Override61public void paint(Graphics g) {62if (g == null || !(g instanceof Graphics2D)) {63return;64}65g.setColor(Color.white);66g.setXORMode(Color.black);67Graphics2D dg = (Graphics2D) g;68Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,69BasicStroke.JOIN_MITER,7010.0f,71new float[]{1.0f, 1.0f},720.0f);73dg.setStroke(stroke);74try {75dg.draw(new Line2D.Float(10, 10, 20, 20));76} catch (Throwable e) {77synchronized (this) {78theError = e;79}80} finally {81didDraw.countDown();82}83}8485@Override86public Dimension getPreferredSize() {87return new Dimension(400, 100);88}8990public void checkResult() {91try {92didDraw.await();93} catch (InterruptedException e) {94}9596synchronized (this) {97if (theError != null) {98System.out.println("Error: " + theError);99100throw new RuntimeException("Test FAILED.");101}102}103System.out.println("Test PASSED.");104105}106107private Throwable theError = null;108109private final CountDownLatch didDraw = new CountDownLatch(1);110}111112113