1 /*
   2  * Copyright (c) 2016, 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     8153943
  27  * @summary Test verifies whether equals() and hashCode() methods in
  28  *          BandedSampleModel works properly.
  29  * @run     main BandedSampleModelEqualsTest
  30  */
  31 
  32 import java.awt.image.BandedSampleModel;
  33 import java.awt.image.DataBuffer;
  34 
  35 public class BandedSampleModelEqualsTest {
  36 
  37     private static void testConstructor1() {
  38         /*
  39          * verify equality with constructor
  40          * BandedSampleModel(int dataType, int w, int h, int numBands)
  41          */
  42         BandedSampleModel model1 =
  43                 new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 1);
  44         BandedSampleModel model2 =
  45                 new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 1);
  46         if (model1.equals(null)) {
  47             throw new RuntimeException("equals(null) returns true");
  48         }
  49         if (!(model1.equals(model2))) {
  50             throw new RuntimeException("equals() method is not working"
  51                     + " properly");
  52         }
  53         if (!(model2.equals(model1))) {
  54             throw new RuntimeException("equals() method is not working"
  55                     + " properly");
  56         }
  57         if (model1.hashCode() != model2.hashCode()) {
  58             throw new RuntimeException("HashCode is not same for same"
  59                     + " BandedSampleModels");
  60         }
  61     }
  62 
  63     private static void testConstructor2() {
  64         /*
  65          * verify equality with constructor
  66          * BandedSampleModel(int dataType, int w, int h, int scanlineStride,
  67          * int[] bankIndices, int[] bandOffsets)
  68          */
  69         BandedSampleModel model1 =
  70                 new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 50,
  71                 new int[] {0}, new int[] {0});
  72         BandedSampleModel model2 =
  73                 new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 50,
  74                 new int[] {0}, new int[] {0});
  75         if (model1.equals(null)) {
  76             throw new RuntimeException("equals(null) returns true");
  77         }
  78         if (!(model1.equals(model2))) {
  79             throw new RuntimeException("equals() method is not working"
  80                     + " properly");
  81         }
  82         if (!(model2.equals(model1))) {
  83             throw new RuntimeException("equals() method is not working"
  84                     + " properly");
  85         }
  86         if (model1.hashCode() != model2.hashCode()) {
  87             throw new RuntimeException("HashCode is not same for same"
  88                     + " BandedSampleModels");
  89         }
  90     }
  91 
  92     public static void testSameBandedSampleModel() {
  93         testConstructor1();
  94         testConstructor2();
  95     }
  96     public static void main(String[] args) {
  97         /* 
  98          * verify BandedSampleModel equality using different
  99          * constructors.
 100          */
 101         testSameBandedSampleModel();
 102     }
 103 }