Path: blob/master/test/jdk/java/awt/GraphicsDevice/CloneConfigsTest.java
41149 views
/*1* Copyright (c) 2009, 2018, 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 6822057 7124400 8059848 819861327*28* @summary Test verifies that list of supported graphics configurations29* can not be changed via modification of elements of an array30* returned by getConfiguration() method.31*32* @run main CloneConfigsTest33* @run main/othervm -Dsun.java2d.d3d=true CloneConfigsTest34* @run main/othervm -Dsun.java2d.noddraw=true CloneConfigsTest35*/3637import java.awt.GraphicsConfiguration;38import java.awt.GraphicsDevice;39import java.awt.GraphicsEnvironment;40import java.awt.Rectangle;41import java.awt.geom.AffineTransform;42import java.awt.image.BufferedImage;43import java.awt.image.ColorModel;4445public class CloneConfigsTest {4647public static void main(String[] args) {48GraphicsEnvironment env =49GraphicsEnvironment.getLocalGraphicsEnvironment();5051GraphicsDevice[] devices = env.getScreenDevices();5253GraphicsConfiguration c = new TestConfig();5455for (GraphicsDevice gd : devices) {56System.out.println("Device: " + gd);5758GraphicsConfiguration[] configs = gd.getConfigurations();5960for (int i = 0; i < configs.length; i++) {61GraphicsConfiguration gc = configs[i];62System.out.println("\tConfig: " + gc);6364configs[i] = c;65}6667// verify whether array of configs was modified68configs = gd.getConfigurations();69for (GraphicsConfiguration gc : configs) {70if (gc == c) {71throw new RuntimeException("Test failed.");72}73}74System.out.println("Test passed.");75}76}7778private static class TestConfig extends GraphicsConfiguration {7980@Override81public GraphicsDevice getDevice() {82throw new UnsupportedOperationException("Not supported yet.");83}8485@Override86public BufferedImage createCompatibleImage(int width, int height) {87throw new UnsupportedOperationException("Not supported yet.");88}8990@Override91public ColorModel getColorModel() {92throw new UnsupportedOperationException("Not supported yet.");93}9495@Override96public ColorModel getColorModel(int transparency) {97throw new UnsupportedOperationException("Not supported yet.");98}99100@Override101public AffineTransform getDefaultTransform() {102throw new UnsupportedOperationException("Not supported yet.");103}104105@Override106public AffineTransform getNormalizingTransform() {107throw new UnsupportedOperationException("Not supported yet.");108}109110@Override111public Rectangle getBounds() {112throw new UnsupportedOperationException("Not supported yet.");113}114115}116117}118119120