|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | +import java.awt.color.ColorSpace; |
| 25 | +import java.awt.color.ICC_Profile; |
| 26 | +import java.util.Arrays; |
| 27 | + |
| 28 | +/** |
| 29 | + * @test |
| 30 | + * @bug 8263622 |
| 31 | + * @summary The ICC_Profile#setData invert the order of bytes for the "head" tag |
| 32 | + */ |
| 33 | +public final class SetHeaderInfo { |
| 34 | + |
| 35 | + public static void main(String[] args) { |
| 36 | + int[] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_LINEAR_RGB, |
| 37 | + ColorSpace.CS_CIEXYZ, ColorSpace.CS_PYCC, |
| 38 | + ColorSpace.CS_GRAY}; |
| 39 | + for (int cspace : cspaces) { |
| 40 | + ICC_Profile icc = ICC_Profile.getInstance(cspace); |
| 41 | + testSame(icc); |
| 42 | + testCustom(icc); |
| 43 | + // some corner cases |
| 44 | + negative(icc, null); |
| 45 | + negative(icc, new byte[0]); |
| 46 | + negative(icc, new byte[1]); |
| 47 | + byte[] header = icc.getData(ICC_Profile.icSigHead); |
| 48 | + negative(icc, new byte[header.length - 1]); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + private static void testSame(ICC_Profile icc) { |
| 53 | + byte[] expected = icc.getData(ICC_Profile.icSigHead); |
| 54 | + icc.setData(ICC_Profile.icSigHead, expected); |
| 55 | + byte[] actual = icc.getData(ICC_Profile.icSigHead); |
| 56 | + if (!Arrays.equals(expected, actual)) { |
| 57 | + System.err.println("Expected: " + Arrays.toString(expected)); |
| 58 | + System.err.println("Actual: " + Arrays.toString(actual)); |
| 59 | + throw new RuntimeException(); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private static void testCustom(ICC_Profile icc) { |
| 64 | + byte[] expected = icc.getData(ICC_Profile.icSigHead); |
| 65 | + // small modification of the default profile |
| 66 | + expected[ICC_Profile.icHdrFlags + 3] = 1; |
| 67 | + expected[ICC_Profile.icHdrModel + 3] = 1; |
| 68 | + icc.setData(ICC_Profile.icSigHead, expected); |
| 69 | + byte[] actual = icc.getData(ICC_Profile.icSigHead); |
| 70 | + if (!Arrays.equals(expected, actual)) { |
| 71 | + System.err.println("Expected: " + Arrays.toString(expected)); |
| 72 | + System.err.println("Actual: " + Arrays.toString(actual)); |
| 73 | + throw new RuntimeException(); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private static void negative(ICC_Profile icc, byte[] tagData) { |
| 78 | + try { |
| 79 | + icc.setData(ICC_Profile.icSigHead, tagData); |
| 80 | + throw new RuntimeException("IllegalArgumentException expected"); |
| 81 | + } catch (IllegalArgumentException iae) { |
| 82 | + // expected |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments