1 /* 2 * Copyright (c) 2011, 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 test.com.sun.javafx.geom; 27 28 import com.sun.javafx.geom.DirtyRegionContainer; 29 import com.sun.javafx.geom.RectBounds; 30 import junit.framework.Assert; 31 import org.junit.Test; 32 33 public class DirtyRegionContainerTest { 34 35 static RectBounds[] nonIntersecting_3_Regions = new RectBounds[] { 36 new RectBounds(0, 0, 20, 20), 37 new RectBounds(25, 25, 50, 50), 38 new RectBounds(60, 60, 100, 100) 39 }; 40 41 @Test 42 public void test_maxSpace() { 43 DirtyRegionContainer drc = new DirtyRegionContainer(10); 44 Assert.assertEquals(10, drc.maxSpace()); 45 } 46 47 @Test 48 public void test_size() { 49 DirtyRegionContainer drc = new DirtyRegionContainer(5); 50 drc.deriveWithNewRegions(nonIntersecting_3_Regions); 51 Assert.assertEquals(3, drc.size()); 52 } 53 54 @Test 55 public void test_deriveWithNewBounds() { 56 DirtyRegionContainer drc = new DirtyRegionContainer(5); 57 drc.deriveWithNewRegions(nonIntersecting_3_Regions); 58 for (int i = 0; i < drc.size(); i++) { 59 RectBounds rb = drc.getDirtyRegion(i); 60 Assert.assertEquals(nonIntersecting_3_Regions[i], rb); 61 } 62 } 63 64 @Test 65 public void test_deriveWithNewBounds_null() { 66 DirtyRegionContainer drc = getDRC_initialized(); 67 drc.deriveWithNewRegions(null); 68 for (int i = 0; i < drc.size(); i++) { 69 RectBounds rb = drc.getDirtyRegion(i); 70 Assert.assertEquals(nonIntersecting_3_Regions[i], rb); 71 } 72 } 73 74 @Test 75 public void test_deriveWithNewBounds_zero_length () { 76 DirtyRegionContainer drc = getDRC_initialized(); 77 drc.deriveWithNewRegions(new RectBounds[]{}); 78 for (int i = 0; i < drc.size(); i++) { 79 RectBounds rb = drc.getDirtyRegion(i); 80 Assert.assertEquals(nonIntersecting_3_Regions[i], rb); 81 } 82 } 83 84 @Test 85 public void test_deriveWithNewBounds_biger_length () { 86 DirtyRegionContainer drc = getDRC_initialized(); 87 RectBounds[] arry = new RectBounds[]{ 88 new RectBounds(1, 1, 10, 10), 89 new RectBounds(15, 15, 50, 50), 90 new RectBounds(60, 60, 100, 100), 91 new RectBounds(110, 110, 200, 200) 92 }; 93 drc.deriveWithNewRegions(arry); 94 for (int i = 0; i < drc.size(); i++) { 95 RectBounds rb = drc.getDirtyRegion(i); 96 Assert.assertEquals(arry[i], rb); 97 } 98 } 99 100 @Test 101 public void test_copy() { 102 DirtyRegionContainer drc = getDRC_initialized(); 103 DirtyRegionContainer copyDrc = drc.copy(); 104 Assert.assertTrue(copyDrc != drc); 105 Assert.assertEquals(copyDrc, drc); 106 } 107 108 @Test 109 public void test_getDirtyRegion() { 110 DirtyRegionContainer drc = getDRC_initialized(); 111 RectBounds dr = drc.getDirtyRegion(1); 112 Assert.assertEquals(new RectBounds(25, 25, 50, 50), dr); 113 } 114 115 @Test (expected=ArrayIndexOutOfBoundsException.class) 116 public void test_getDirtyRegion_AIOOBE() { 117 DirtyRegionContainer drc = getDRC_initialized(); 118 RectBounds dr = drc.getDirtyRegion(10); 119 Assert.fail("Expected AIOOBE"); 120 } 121 122 @Test 123 public void test_addDirtyRegion_non_intersecting() { 124 DirtyRegionContainer drc = getDRC_initialized(); 125 RectBounds newregion = new RectBounds(150, 150, 200, 200); 126 drc.addDirtyRegion(newregion); 127 128 Assert.assertEquals(4, drc.size()); 129 for(int i = 0; i < drc.size() - 1; i++) { 130 Assert.assertEquals(nonIntersecting_3_Regions[i], (drc.getDirtyRegion(i))); 131 } 132 Assert.assertEquals(drc.getDirtyRegion(drc.size() - 1), newregion); 133 } 134 135 @Test 136 public void test_addDirtyRegion_has_space_intersect_once() { 137 DirtyRegionContainer drc = getDRC_initialized(); 138 139 drc.addDirtyRegion(new RectBounds(10, 10, 22, 15)); 140 141 Assert.assertEquals(3, drc.size()); 142 Assert.assertEquals(new RectBounds(60, 60, 100, 100), drc.getDirtyRegion(0)); 143 Assert.assertEquals(new RectBounds(25, 25, 50, 50), drc.getDirtyRegion(1)); 144 Assert.assertEquals(new RectBounds(0, 0, 22, 20), drc.getDirtyRegion(2)); 145 } 146 147 @Test 148 public void test_addDirtyRegion_has_space_intersect_twice() { 149 DirtyRegionContainer drc = getDRC_initialized(); 150 151 drc.addDirtyRegion(new RectBounds(10, 10, 40, 40)); 152 153 Assert.assertEquals(2, drc.size()); 154 Assert.assertEquals(new RectBounds(60, 60, 100, 100), drc.getDirtyRegion(0)); 155 Assert.assertEquals(new RectBounds(0, 0, 50, 50), drc.getDirtyRegion(1)); 156 } 157 158 @Test 159 public void test_addDirtyRegion_has_space_intersect_all() { 160 DirtyRegionContainer drc = getDRC_initialized(); 161 drc.addDirtyRegion(new RectBounds(10, 10, 80, 80)); 162 163 Assert.assertEquals(1, drc.size()); 164 Assert.assertEquals(new RectBounds(0, 0, 100, 100), drc.getDirtyRegion(0)); 165 } 166 167 @Test 168 public void test_addDirtyRegion_no_space_intersect_once() { 169 DirtyRegionContainer drc = getDRC_initialized(); 170 drc.addDirtyRegion(new RectBounds(120, 120, 150, 150)); 171 172 drc.addDirtyRegion(new RectBounds(10, 10, 22, 15)); 173 174 Assert.assertEquals(4, drc.size()); 175 Assert.assertEquals(new RectBounds(120, 120, 150, 150), drc.getDirtyRegion(0)); 176 Assert.assertEquals(new RectBounds(25, 25, 50, 50), drc.getDirtyRegion(1)); 177 Assert.assertEquals(new RectBounds(60, 60, 100, 100), drc.getDirtyRegion(2)); 178 Assert.assertEquals(new RectBounds(0, 0, 22, 20), drc.getDirtyRegion(3)); 179 } 180 181 @Test 182 public void test_addDirtyRegion_no_space_intersect_twice() { 183 DirtyRegionContainer drc = getDRC_initialized(); 184 drc.addDirtyRegion(new RectBounds(120, 120, 150, 150)); 185 186 drc.addDirtyRegion(new RectBounds(10, 10, 40, 40)); 187 188 Assert.assertEquals(3, drc.size()); 189 Assert.assertEquals(new RectBounds(120, 120, 150, 150), drc.getDirtyRegion(0)); 190 Assert.assertEquals(new RectBounds(60, 60, 100, 100), drc.getDirtyRegion(1)); 191 Assert.assertEquals(new RectBounds(0, 0, 50, 50), drc.getDirtyRegion(2)); 192 } 193 194 private DirtyRegionContainer getDRC_initialized() { 195 DirtyRegionContainer drc = new DirtyRegionContainer(4); 196 return drc.deriveWithNewRegions(nonIntersecting_3_Regions); 197 } 198 }