1 /*
   2  * Copyright (c) 2010, 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 javafx.scene.image;
  27 
  28 import static javafx.scene.image.ImageViewConfig.config;
  29 import static javafx.scene.image.TestImages.TEST_IMAGE_100x200;
  30 import static javafx.scene.image.TestImages.TEST_IMAGE_200x100;
  31 import static org.junit.Assert.assertEquals;
  32 
  33 import java.util.Arrays;
  34 import java.util.Collection;
  35 
  36 import org.junit.After;
  37 import org.junit.Before;
  38 import org.junit.Test;
  39 import org.junit.runner.RunWith;
  40 import org.junit.runners.Parameterized;
  41 import org.junit.runners.Parameterized.Parameters;
  42 
  43 @RunWith(Parameterized.class)
  44 public class ImageView_verifyContains_Test {
  45 
  46     private final ImageViewConfig imageViewConfig;
  47     private final float x;
  48     private final float y;
  49     private final boolean expectedContainsResult;
  50 
  51     private ImageView imageView;
  52 
  53     /*
  54      * Parameters: [image view config], [x], [y], [result]
  55      *
  56      * Note:
  57      * Every test image has the following hit test pattern:
  58      *
  59      * TTT|FFF
  60      * TTT|FFF
  61      * ---+---
  62      * FFF|TTT
  63      * FFF|TTT
  64      */
  65     @Parameters
  66     public static Collection data() {
  67         return Arrays.asList(new Object[][] {
  68             { config(null, 0, 0), 0, 0, false },
  69             { config(TEST_IMAGE_100x200, 0, 0), 25, 50, true },
  70             { config(TEST_IMAGE_100x200, 25, 50), 25 + 75, 50 + 50, false },
  71             { config(TEST_IMAGE_100x200, 25, 0), 25 + 25, 150, false },
  72             { config(TEST_IMAGE_100x200, 0, 50), 75, 50 + 150, true },
  73             { config(TEST_IMAGE_200x100, 0, 0), 250, 75, false },
  74             { config(TEST_IMAGE_200x100, 50, 25), 50 + 150, 25 + 125, false },
  75             { config(TEST_IMAGE_200x100, 50, 0), 0, 25, false },
  76             { config(TEST_IMAGE_200x100, 0, 25), 50, 0, false },
  77             {
  78                 config(null, 0, 0, 400, 400, false),
  79                 200, 200, false
  80             },
  81             {
  82                 config(TEST_IMAGE_100x200, 50, 0, 0, 400, false),
  83                 50 + 25, 100, true
  84             },
  85             {
  86                 config(TEST_IMAGE_200x100, 0, 50, 400, 0, false),
  87                 300, 50 + 75, true
  88             },
  89             {
  90                 config(TEST_IMAGE_100x200, 0, 200, 400, 400, true),
  91                 150, 200 + 300, true
  92             },
  93             {
  94                 config(TEST_IMAGE_200x100, 200, 0, 400, 400, true),
  95                 200 + 100, 50, true
  96             },
  97             {
  98                 config(TEST_IMAGE_100x200, 0, 0,
  99                        50, 0, 100, 200,
 100                        0, 400, true),
 101                 50, 300, true
 102             },
 103             {
 104                 config(TEST_IMAGE_100x200, 0, 0,
 105                        -50, 0, 100, 200,
 106                        400, 400, true),
 107                 50, 100, false
 108             },
 109             {
 110                 config(TEST_IMAGE_100x200, 0, 0,
 111                        50, 50, 50, 150,
 112                        400, 400, false),
 113                 395, 395, true
 114             },
 115             {
 116                 config(TEST_IMAGE_200x100, 20, 10,
 117                        0, 50, 200, 100,
 118                        400, 0, true),
 119                 300, 50, true
 120             },
 121             {
 122                 config(TEST_IMAGE_200x100, 20, 10,
 123                        0, -50, 200, 100,
 124                        400, 0, true),
 125                 100, 50, false
 126             },
 127 //            /* tests for invalid viewport */
 128 //            {
 129 //                config(TEST_IMAGE_200x100, 0, 0,
 130 //                       0, 0, 0, 100,
 131 //                       400, 400, true),
 132 //                0, 0, false
 133 //            },
 134 //            {
 135 //                config(TEST_IMAGE_100x200, 0, 0,
 136 //                       0, 0, 100, 0,
 137 //                       400, 400, true),
 138 //                0, 0, false
 139 //            }
 140         });
 141     }
 142 
 143     public ImageView_verifyContains_Test(final ImageViewConfig imageViewConfig,
 144                                          final float x,
 145                                          final float y,
 146                                          final boolean expectedContainsResult) {
 147         this.imageViewConfig = imageViewConfig;
 148         this.x = x;
 149         this.y = y;
 150         this.expectedContainsResult = expectedContainsResult;
 151     }
 152 
 153     @Before
 154     public void setUp() {
 155         imageView = new ImageView();
 156         imageViewConfig.applyTo(imageView);
 157     }
 158 
 159     @After
 160     public void tearDown() {
 161         imageView = null;
 162     }
 163 
 164     @Test
 165     public void verifyContains() {
 166         assertEquals(expectedContainsResult,
 167                      imageView.contains(x, y));
 168     }
 169 }