Path: blob/master/test/jdk/sun/java2d/cmm/ProfileOp/SetDataTest.java
41153 views
/*1* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 7042594 802820626* @summary Test verifies that ICC_Profile.setData() conforms the spec.27*28* @run main SetDataTest29*/303132import java.util.ArrayList;33import java.util.List;34import java.awt.color.ICC_Profile;35import static java.awt.color.ICC_ColorSpace.CS_GRAY;36import static java.awt.color.ICC_Profile.icSigGrayTRCTag;37import static java.awt.color.ICC_Profile.icSigRedTRCTag;38import static java.awt.color.ICC_Profile.icSigGreenTRCTag;3940public class SetDataTest {4142static class TestCase {4344static ICC_Profile profile;45static byte[] validTRCdata;46static byte[] invalidTRCData;4748static {49profile = ICC_Profile.getInstance(CS_GRAY);50validTRCdata = profile.getData(icSigGrayTRCTag);51invalidTRCData = new byte[]{0x42, 0x42, 0x42, 0x42, 1, 3, 4, 6,};52}53String desciption;54int signature;55boolean useValidData;56Throwable err;57boolean isIAEexpected;5859public TestCase(String descr, int sig,60boolean useValidData,61boolean isIAEexpected) {62this.desciption = descr;63this.signature = sig;6465this.useValidData = useValidData;66this.isIAEexpected = isIAEexpected;6768}6970public void doTest() {71System.out.println(desciption);72byte[] data = useValidData73? validTRCdata : invalidTRCData;74err = null;75try {76profile.setData(signature, data);77} catch (Throwable e) {78err = e;79System.out.println("Got exception: " +80e.getClass().getName() + ": " +81e.getMessage());82}8384if (isIAEexpected) {85if (err == null) {86throw new RuntimeException(87"Test failed: expected exception was not thrown");88}89if (!(err instanceof IllegalArgumentException)) {90throw new RuntimeException(91"Unexpected exception was thrown: " +92err.getMessage(), err);93}94} else {95if (err != null) {96throw new RuntimeException(97"Unexpected exception was thrown: " +98err.getMessage(), err);99}100}101System.out.println("Testcase PASSED");102}103}104105public static void main(String[] args) {106List<TestCase> tests = new ArrayList<TestCase>();107108TestCase selfupdate = new TestCase(109"Selfupdate: update grayTRC with the same data.",110icSigGrayTRCTag, true, false);111tests.add(selfupdate);112113TestCase newValdTag = new TestCase(114"Insert new valid tag",115icSigRedTRCTag,116true, false);117tests.add(newValdTag);118119TestCase newInvalidTag = new TestCase(120"Insert new tag with invalid contet",121icSigGreenTRCTag,122false, true);123tests.add(newInvalidTag);124125TestCase newUnknowInvalidTag = new TestCase(126"Insert new tag with invalid data and unknown signature",1270x41414141,128false, true);129tests.add(newUnknowInvalidTag);130131TestCase newUnknownValidTag = new TestCase(132"Insert new tag with valid data and unknown signatiure",1330x41414141,134true, true);135tests.add(newUnknownValidTag);136137for (TestCase t: tests) {138t.doTest();139}140System.out.println("Test passed!.");141}142}143144145