diff --git a/test/jdk/java/awt/color/GetInstanceNullData.java b/test/jdk/java/awt/color/GetInstanceNullData.java new file mode 100644 index 00000000000..9543455477a --- /dev/null +++ b/test/jdk/java/awt/color/GetInstanceNullData.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ICC_Profile; +import java.awt.color.ICC_ProfileGray; +import java.awt.color.ICC_ProfileRGB; + +/** + * @test + * @bug 4176618 7042594 + * @summary This interactive test verifies that passing null to + * ICC_ProfileRGB.getInstance() does not crash the VM. + * An IllegalArgumentException: Invalid ICC Profile Data should be + * generated. + */ +public final class GetInstanceNullData { + + public static void main(String[] argv) { + byte b[] = null; + try { + ICC_ProfileRGB p = (ICC_ProfileRGB) ICC_ProfileRGB.getInstance(b); + throw new RuntimeException("IllegalArgumentException is expected"); + } catch (IllegalArgumentException ignored) { + // expected + } + try { + ICC_ProfileGray p = (ICC_ProfileGray) ICC_ProfileGray.getInstance(b); + throw new RuntimeException("IllegalArgumentException is expected"); + } catch (IllegalArgumentException ignored) { + // expected + } + try { + ICC_Profile p = ICC_Profile.getInstance(b); + throw new RuntimeException("IllegalArgumentException is expected"); + } catch (IllegalArgumentException ignored) { + // expected + } + } +} diff --git a/test/jdk/java/awt/color/GetNameExceptionTest.java b/test/jdk/java/awt/color/GetNameExceptionTest.java new file mode 100644 index 00000000000..ffb861da9e5 --- /dev/null +++ b/test/jdk/java/awt/color/GetNameExceptionTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ColorSpace; + +/** + * @test + * @bug 4752851 + * @summary spec for ColorSpace.getName() does not describe case of wrong param + */ +public final class GetNameExceptionTest { + + public static void main(String[] args) { + test(ColorSpace.getInstance(ColorSpace.CS_sRGB)); + test(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)); + test(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ)); + test(ColorSpace.getInstance(ColorSpace.CS_PYCC)); + test(ColorSpace.getInstance(ColorSpace.CS_GRAY)); + } + + private static void test(ColorSpace cs) { + try { + cs.getName(cs.getNumComponents()); + throw new RuntimeException("Method ColorSpace.getName(int) should" + + " throw exception for incorrect input"); + } catch (IllegalArgumentException ignored) { + // expected + } + } +} diff --git a/test/jdk/java/awt/color/GetNameTest.java b/test/jdk/java/awt/color/GetNameTest.java new file mode 100644 index 00000000000..dd7966446f2 --- /dev/null +++ b/test/jdk/java/awt/color/GetNameTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ColorSpace; +import java.util.HashMap; +import java.util.Map; + +/** + * @test + * @bug 4967082 + * @summary ColorSpace.getName(int) should return significant values for some CS + */ +public final class GetNameTest { + + private static final Map colorSpaces = new HashMap<>(5); + + static { + colorSpaces.put(ColorSpace.CS_CIEXYZ, new String[] {"X", "Y", "Z"}); + colorSpaces.put(ColorSpace.CS_sRGB, + new String[] {"Red", "Green", "Blue"}); + colorSpaces.put(ColorSpace.CS_LINEAR_RGB, + new String[] {"Red", "Green", "Blue"}); + colorSpaces.put(ColorSpace.CS_GRAY, new String[] {"Gray"}); + colorSpaces.put(ColorSpace.CS_PYCC, + new String[] {"Unnamed color component(0)", + "Unnamed color component(1)", + "Unnamed color component(2)"}); + }; + + public static void main(String[] args) { + for (int csType : colorSpaces.keySet()) { + ColorSpace cs = ColorSpace.getInstance(csType); + String[] names = colorSpaces.get(csType); + for (int i = 0; i < cs.getNumComponents(); i++) { + String name = cs.getName(i); + if (!name.equals(names[i])) { + System.err.println("ColorSpace with type=" + cs.getType() + + " has wrong name of " + i + + " component"); + throw new RuntimeException("Wrong name of the component"); + } + } + } + } +} diff --git a/test/jdk/java/awt/color/ICC_ProfileSetNullDataTest.java b/test/jdk/java/awt/color/ICC_ProfileSetNullDataTest.java new file mode 100644 index 00000000000..a327fa791fb --- /dev/null +++ b/test/jdk/java/awt/color/ICC_ProfileSetNullDataTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ColorSpace; +import java.awt.color.ICC_Profile; + +/** + * @test + * @bug 4823896 7042594 + * @summary Test checks behavior of the ICC_Profile.setData(int, byte[]) + */ +public final class ICC_ProfileSetNullDataTest { + + public static void main(String[] args) { + test(ICC_Profile.getInstance(ColorSpace.CS_sRGB)); + test(ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB)); + test(ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ)); + test(ICC_Profile.getInstance(ColorSpace.CS_PYCC)); + test(ICC_Profile.getInstance(ColorSpace.CS_GRAY)); + } + + private static void test(ICC_Profile profile) { + byte[] tagData = null; + try { + profile.setData(ICC_Profile.icSigCmykData, tagData); + } catch (IllegalArgumentException e) { + return; + } + throw new RuntimeException("IllegalArgumentException expected"); + } +} diff --git a/test/jdk/java/awt/color/MultiThreadCMMTest.java b/test/jdk/java/awt/color/MultiThreadCMMTest.java new file mode 100644 index 00000000000..2db27665b93 --- /dev/null +++ b/test/jdk/java/awt/color/MultiThreadCMMTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.image.DirectColorModel; + +/** + * @test + * @bug 6245283 + * @summary Checks the behavior of the DirectColorModel.getRed(int) + * with multiple threads. + */ +public final class MultiThreadCMMTest extends Thread { + /* Number of concurent threads creating and accessing + * DirectColorModel object + */ + private static final int THREAD_COUNT = 100; + private static final int ITERATION_COUNT = 20; + + private static volatile boolean failed = false; + private static volatile Exception failureException = null; + + private static synchronized void setStatusFailed(Exception e) { + /* Store first occurred exception */ + if (!failed) { + failureException = e; + failed = true; + } + } + + public static void main(String [] args) throws Exception { + + Thread [] threadArray = new Thread [THREAD_COUNT]; + for (int i = 0; i < ITERATION_COUNT; i++) { + for (int j = 0; j < threadArray.length; j++) { + threadArray[j] = new MultiThreadCMMTest(); + }; + + for (int j = 0; j < threadArray.length; j++) { + threadArray[j].start(); + } + + /* Ensure that all threads are finished */ + for (int j = 0; j < threadArray.length; j++) { + threadArray[j].join(); + if (failed) { + throw new RuntimeException(failureException); + } + } + } + } + + public void run() { + int rMask16 = 0xF800; + int gMask16 = 0x07C0; + int bMask16 = 0x003E; + int r; + try { + for(int i=0; i < 1000; i++) { + DirectColorModel dcm = + new DirectColorModel(16, rMask16, gMask16, bMask16); + r = dcm.getRed(10); + } + } catch(Exception e) { + setStatusFailed(e); + } + } +} diff --git a/test/jdk/java/awt/color/StandardProfileTest.java b/test/jdk/java/awt/color/StandardProfileTest.java new file mode 100644 index 00000000000..24ff53b7dd7 --- /dev/null +++ b/test/jdk/java/awt/color/StandardProfileTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.color.ColorSpace; +import java.awt.color.ICC_Profile; + +/** + * @test + * @bug 5042429 + * @summary This test verifies if ICC_profile instances for standard ColorSpace + * types are created without security exceptions if access to file + * system is prohibited. + * @run main/othervm/policy=StandardProfileTest.policy StandardProfileTest + */ +public final class StandardProfileTest { + + public static void main(String[] args) { + if (System.getSecurityManager() == null) { + throw new RuntimeException("SecurityManager is null"); + } + + int[] types = { + ColorSpace.CS_CIEXYZ, + ColorSpace.CS_GRAY, + ColorSpace.CS_LINEAR_RGB, + ColorSpace.CS_PYCC, + ColorSpace.CS_sRGB } ; + + for (int t = 0; t 0.01f) || + (Math.abs(mxyz[1] - 1.0000f) > 0.01f) || + (Math.abs(mxyz[2] - 1.0891f) > 0.01f)) { + throw new Error("sRGB (1.0, 1.0, 1.0) doesn't convert " + + "correctly to CIEXYZ"); + } + } +}