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  *          PixelInterleavedSampleModel works properly.
  29  * @run     main PixelInterleavedSampleModelEqualsTest
  30  */
  31 
  32 import java.awt.image.DataBuffer;
  33 import java.awt.image.PixelInterleavedSampleModel;
  34 
  35 public class PixelInterleavedSampleModelEqualsTest {
  36 
  37     private static void testSamePixelInterleavedSampleModel() {
  38         /*
  39          * verify equality with only one present constructor
  40          * PixelInterleavedSampleModel(int dataType, int w, int h,
  41          * int pixelStride, int scanlineStride, int[] bandOffsets)
  42          */
  43         PixelInterleavedSampleModel model1 =
  44                 new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 50, 50,
  45                 1, 50, new int[] {0});
  46         PixelInterleavedSampleModel model2 =
  47                 new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 50, 50,
  48                 1, 50, new int[] {0});
  49         if (model1.equals(null)) {
  50             throw new RuntimeException("equals(null) returns true");
  51         }
  52         if (!(model1.equals(model2))) {
  53             throw new RuntimeException("equals() method is not working"
  54                     + " properly");
  55         }
  56         if (!(model2.equals(model1))) {
  57             throw new RuntimeException("equals() method is not working"
  58                     + " properly");
  59         }
  60         if (model1.hashCode() != model2.hashCode()) {
  61             throw new RuntimeException("HashCode is not same for same"
  62                     + " PixelInterleavedSampleModels");
  63         }
  64     }
  65 
  66     public static void main(String[] args) {
  67         /* 
  68          * verify PixelInterleavedSampleModel equality using different
  69          * constructors.
  70          */
  71         testSamePixelInterleavedSampleModel();
  72     }
  73 }