1/* 2 * Copyright (c) 2014, 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 @bug 4157612 27 @summary tests that certain awt classes do not break basic hashCode() contract. 28 @author prs@sparc.spb.su: area= 29 @run main EqualHashCodeTest 30*/ 31 32import java.awt.*; 33import java.awt.color.ColorSpace; 34import java.awt.datatransfer.DataFlavor; 35import java.awt.image.ColorModel; 36import java.awt.image.ComponentColorModel; 37 38public class EqualHashCodeTest { 39 40 static DataFlavor df1, df2; 41 static Insets insets1, insets2; 42 static Dimension dim1, dim2; 43 static ColorModel cm1, cm2; 44 static int[] ColorModelBits = { 8, 8, 8, 8 }; 45 46 public static void main(String[] args) throws Exception { 47 boolean passed = true; 48 try { 49 df1 = new DataFlavor( "application/postscript" ); 50 df2 = new DataFlavor( "application/*" ); 51 } catch (ClassNotFoundException e1) { 52 throw new RuntimeException("Could not create DataFlavors. This should never happen."); 53 } catch (IllegalArgumentException e2) { 54 passed = false; 55 } 56 if (df1.hashCode() != df2.hashCode()) { 57 passed = false; 58 } 59 dim1 = new Dimension(3, 18); 60 dim2 = new Dimension(3, 18); 61 if (dim1.hashCode() != dim2.hashCode()) { 62 passed = false; 63 } 64 insets1 = new Insets(3, 4, 7, 11); 65 insets2 = new Insets(3, 4, 7, 11); 66 if (insets1.hashCode() != insets2.hashCode()) { 67 passed = false; 68 } 69 cm1 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 70 ColorModelBits, true, true, 71 Transparency.OPAQUE, 0); 72 cm2 = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 73 ColorModelBits, true, true, 74 Transparency.OPAQUE, 0); 75 if (cm1.hashCode() != cm2.hashCode()) { 76 passed = false; 77 } 78 if (!passed) 79 throw new RuntimeException("Test FAILED"); 80 } 81 82} 83 84