1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary 27 * @summary com.apple.junit.java.graphics.color.ColorComponent 28 */ 29 30 /* 31 * Adapting simple color tests for the test harness. 32 * Testcase for 33 * <rdar://problem/3821083> JCK-Related: java.awt.java2d.awt.Color.GetColorComponentsTest fails with +ProtectJavaHeap 34 * 35 * OPENJDK-MIGRATED 36 * http://hg.openjdk.java.net/macosx-port/macosx-port/jdk/file/... 37 */ 38 39 import junit.framework.*; 40 import java.awt.*; 41 import java.awt.color.ColorSpace; 42 43 public class ColorComponent01 extends TestCase { 44 45 public void testColorComponents_CS_sRGB() { 46 47 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); 48 49 float[] cp = { 0.5f, 0.5f, 0.5f }; 50 Color c = new Color(cp[0], cp[1], cp[2]); 51 float[] returned = c.getColorComponents(cs, null); 52 53 for(int i = 0;i < returned.length;i++) { 54 returned[i] = (float)((Math.round(returned[i] * 10))) / 10; 55 String errorMessage = "Bad Result" + "\n"+ 56 "Problem with color component " + i + "\n"+ 57 "Requested " + cp[i] + ", rounded result is " + returned[i] +"\n"+ 58 "See <rdar://problem/3821083> before filing a new defect."; 59 60 assertTrue(errorMessage, returned[i] == cp[i]); 61 } 62 } 63 64 // boilerplate below 65 66 public static Test suite() { 67 return new TestSuite(ColorComponent01.class); 68 } 69 70 public static void main (String[] args) throws RuntimeException { 71 TestResult tr = junit.textui.TestRunner.run(suite()); 72 if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) { 73 throw new RuntimeException("### FAILED: unexpected JUnit errors or failures."); 74 } 75 } 76 }