Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8255710: Opensource unit/regression tests for CMM
Reviewed-by: pbansal, prr
  • Loading branch information
mrserb committed Jan 12, 2021
1 parent 61c5b95 commit 98ccfbf46915791208f80b51f68f3916a68b8aaf
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 0 deletions.
@@ -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
}
}
}
@@ -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
}
}
}
@@ -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");
}
}
}
}
}
@@ -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");
}
}
@@ -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);
}
}
}
@@ -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();
}
}
}

0 comments on commit 98ccfbf

Please sign in to comment.