1 /*
   2  * Copyright (c) 2013, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.sg.prism;
  27 
  28 import com.sun.javafx.geom.RectBounds;
  29 import com.sun.prism.Image;
  30 import org.junit.Before;
  31 import org.junit.Test;
  32 import static org.junit.Assert.assertEquals;
  33 import static org.junit.Assert.assertFalse;
  34 import static org.junit.Assert.assertTrue;
  35 
  36 /**
  37  */
  38 public class NGImageViewTest extends NGTestBase {
  39     static final byte[] ICON_PIXELS = new byte[16*16];
  40     static final Image ICON = Image.fromByteRgbData(ICON_PIXELS, 16, 16);
  41 
  42     NGImageView imageView;
  43 
  44     @Before
  45     public void setup() {
  46         imageView = new NGImageView();
  47         imageView.setImage(ICON);
  48         imageView.setX(10);
  49         imageView.setY(10);
  50         imageView.setViewport(0, 0, 0, 0, 16, 16);
  51     }
  52 
  53     /**
  54      * ImageView always reports true for this
  55      */
  56     @Test
  57     public void testSupportsOpaqueRegion() {
  58         assertTrue(imageView.supportsOpaqueRegions());
  59     }
  60 
  61     /**
  62      * In the configured state it should report true
  63      */
  64     @Test
  65     public void hasOpaqueRegionWithNonEmptyImage() {
  66         assertTrue(imageView.hasOpaqueRegion());
  67     }
  68 
  69     /**
  70      * Tests when the view port is modified (not sure if I'm modifying the
  71      * view port exactly correctly...)
  72      */
  73     @Test
  74     public void hasOpaqueRegionIfViewPortGreaterThanOne() {
  75         assertTrue(imageView.hasOpaqueRegion());
  76         imageView.setViewport(0, 0, 2, 2, 16, 16);
  77         assertTrue(imageView.hasOpaqueRegion());
  78         imageView.setViewport(0, 0, 1, 1, 16, 16);
  79         assertTrue(imageView.hasOpaqueRegion());
  80         imageView.setViewport(0, 0, 0, 0, .1f, .1f);
  81         assertFalse(imageView.hasOpaqueRegion());
  82     }
  83 
  84     /**
  85      * Null images should return false for hasOpaqueImage
  86      */
  87     @Test
  88     public void doesNotHaveOpaqueRegionForNullImage() {
  89         imageView.setImage(null);
  90         assertFalse(imageView.hasOpaqueRegion());
  91     }
  92 
  93     /**
  94      * Simple test should match bounds for opaque image
  95      */
  96     @Test
  97     public void computeOpaqueRegionForWholeNumbers() {
  98         assertEquals(new RectBounds(10, 10, 26, 26), imageView.computeOpaqueRegion(new RectBounds()));
  99     }
 100 }