Skip to content

Commit

Permalink
8255710: Opensource unit/regression tests for CMM
Browse files Browse the repository at this point in the history
Reviewed-by: pbansal, prr
  • Loading branch information
mrserb committed Jan 12, 2021
1 parent 61c5b95 commit 98ccfbf
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/jdk/java/awt/color/GetInstanceNullData.java
Original file line number Diff line number Diff line change
@@ -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
}
}
}
50 changes: 50 additions & 0 deletions test/jdk/java/awt/color/GetNameExceptionTest.java
Original file line number Diff line number Diff line change
@@ -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
}
}
}
65 changes: 65 additions & 0 deletions test/jdk/java/awt/color/GetNameTest.java
Original file line number Diff line number Diff line change
@@ -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<Integer, String[]> 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");
}
}
}
}
}
51 changes: 51 additions & 0 deletions test/jdk/java/awt/color/ICC_ProfileSetNullDataTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
87 changes: 87 additions & 0 deletions test/jdk/java/awt/color/MultiThreadCMMTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
55 changes: 55 additions & 0 deletions test/jdk/java/awt/color/StandardProfileTest.java
Original file line number Diff line number Diff line change
@@ -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<types.length; t++) {
System.out.println("type " + t);
ICC_Profile p = ICC_Profile.getInstance(types[t]);
p.getPCSType();
}
}
}
Loading

3 comments on commit 98ccfbf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb
Copy link
Member Author

@mrserb mrserb commented on 98ccfbf Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 98ccfbf Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb the backport was successfully created on the branch mrserb-backport-98ccfbf4 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 98ccfbf4 from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 12 Jan 2021 and was reviewed by Pankaj Bansal and Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev mrserb-backport-98ccfbf4:mrserb-backport-98ccfbf4
$ git checkout mrserb-backport-98ccfbf4
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev mrserb-backport-98ccfbf4

Please sign in to comment.