1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.util.HashSet ; 23 import java.util.Set ; 24 import junit.framework.TestCase; 25 26 30 public class TabStateTest extends TestCase { 31 32 public TabStateTest(String testName) { 33 super(testName); 34 } 35 36 private TS ts = null; 37 public void setUp() { 38 ts = new TS(); 39 } 40 41 52 53 56 public void testSetPressed() { 57 System.out.println("testSetPressed"); 58 59 policy = 0; 60 ts.setPressed (5); 61 ts.assertChange("Initial set of selected index should trigger a call to change"); 62 ts.assertNoTabsRepainted("No tabs should have been repainted with a 0 policy, after pressing a tab"); 63 64 policy = TabState.REPAINT_ON_MOUSE_PRESSED; 65 ts.setPressed (6); 66 ts.assertChange ("Changing index from 5 to 6 should cause a call to change"); 68 69 policy = TabState.REPAINT_ON_MOUSE_PRESSED | TabState.REPAINT_ON_SELECTION_CHANGE | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED; 70 } 71 72 75 public void testSetContainsMouse() { 76 System.out.println("testSetContainsMouse"); 77 78 } 79 80 83 public void testSetCloseButtonContainsMouse() { 84 System.out.println("testSetCloseButtonContainsMouse"); 85 86 } 87 88 91 public void testSetMousePressedInCloseButton() { 92 System.out.println("testSetMousePressedInCloseButton"); 93 94 } 95 96 99 public void testSetSelected() { 100 System.out.println("testSetSelected"); 101 102 } 103 104 107 public void testSetMouseInTabsArea() { 108 System.out.println("testSetMouseInTabsArea"); 109 110 } 111 112 115 public void testSetActive() { 116 System.out.println("testSetActive"); 117 118 } 119 120 123 public void testClearTransientStates() { 124 System.out.println("testClearTransientStates"); 125 126 } 127 128 129 private class TS extends TabState { 130 private int possibleChangeLastTab = Integer.MIN_VALUE; 131 private int possibleChangeCurrTab = Integer.MIN_VALUE; 132 private int possibleChangeType = Integer.MIN_VALUE; 133 private Boolean possibleChangePrevValue = null; 134 private Boolean possibleChangeCurrValue = null; 135 private int possibleChangeBoolType = Integer.MIN_VALUE; 136 137 138 private void clear() { 139 possibleChangeLastTab = Integer.MIN_VALUE; 140 possibleChangeCurrTab = Integer.MIN_VALUE; 141 possibleChangeType = Integer.MIN_VALUE; 142 possibleChangePrevValue = null; 143 possibleChangeCurrValue = null; 144 possibleChangeBoolType = Integer.MIN_VALUE; 145 } 146 147 public void assertPossibleChange (String msg) { 148 int _possibleChangeLastTab = possibleChangeLastTab; 149 int _possibleChangeCurrTab = possibleChangeCurrTab; 150 int _possibleChangeType = possibleChangeType; 151 Boolean _possibleChangePrevValue = possibleChangePrevValue; 152 Boolean _possibleChangeCurrValue = possibleChangeCurrValue; 153 int _possibleChangeBoolType = possibleChangeBoolType; 154 clear(); 155 156 if (_possibleChangeLastTab == Integer.MIN_VALUE && _possibleChangePrevValue == null) { 157 fail ("no event occured - " + msg); 158 } 159 } 160 161 public void assertPossibleChange (String msg, int lastTab, int currTab, int type) { 162 int _possibleChangeLastTab = possibleChangeLastTab; 163 int _possibleChangeCurrTab = possibleChangeCurrTab; 164 int _possibleChangeType = possibleChangeType; 165 Boolean _possibleChangePrevValue = possibleChangePrevValue; 166 Boolean _possibleChangeCurrValue = possibleChangeCurrValue; 167 int _possibleChangeBoolType = possibleChangeBoolType; 168 clear(); 169 170 if (_possibleChangeLastTab == Integer.MIN_VALUE || _possibleChangeLastTab == Integer.MIN_VALUE) { 171 fail ("no event occurred - " + msg); 172 } 173 174 if (_possibleChangeLastTab != lastTab || _possibleChangeCurrTab != currTab || _possibleChangeType != type) { 175 fail ("wrong event occured - " + msg + " lastTab " + _possibleChangeLastTab + " currTab " + _possibleChangeCurrTab + " type " + _possibleChangeType); 176 } 177 } 178 179 180 public void assertPossibleChange (String msg, boolean prevVal, boolean currVal, int type) { 181 int _possibleChangeLastTab = possibleChangeLastTab; 182 int _possibleChangeCurrTab = possibleChangeCurrTab; 183 int _possibleChangeType = possibleChangeType; 184 Boolean _possibleChangePrevValue = possibleChangePrevValue; 185 Boolean _possibleChangeCurrValue = possibleChangeCurrValue; 186 int _possibleChangeBoolType = possibleChangeBoolType; 187 clear(); 188 if (_possibleChangePrevValue == null || _possibleChangeCurrValue == null) { 189 fail ("no event occured - " + msg); 190 } 191 192 if (_possibleChangePrevValue.booleanValue() != prevVal || _possibleChangeCurrValue.booleanValue() != currVal || _possibleChangeBoolType != type) { 193 fail ("wrong event occured - " + msg + " prevVal: " + _possibleChangePrevValue + " currVal " + _possibleChangeCurrValue + " type " + _possibleChangeBoolType); 194 } 195 } 196 197 protected void possibleChange(int lastTab, int currTab, int type) { 198 possibleChangeLastTab = lastTab; 199 possibleChangeCurrTab = currTab; 200 possibleChangeType = type; 201 super.possibleChange (lastTab, currTab, type); 202 } 203 204 protected void possibleChange(boolean prevVal, boolean currVal, int type) { 205 possibleChangePrevValue = prevVal ? Boolean.TRUE : Boolean.FALSE; 206 possibleChangeCurrValue = prevVal ? Boolean.TRUE : Boolean.FALSE; 207 possibleChangeBoolType = type; 208 super.possibleChange (prevVal, currVal, type); 209 } 210 211 private int repaintTabInt = Integer.MAX_VALUE; 212 private Set repaintedTabs = null; 213 214 public void assertNoTabsRepainted(String msg) { 215 if (repaintedTabs != null) { 216 fail ("Tabs were repainted: " + repaintedTabs); 217 } 218 assertAllTabsNotRepainted(msg); 219 } 220 221 private void assertTabRepainted (String msg, int tab) { 222 if (repaintedTabs == null) { 223 fail ("No tabs repainted - " + msg); 224 } 225 Set set = new HashSet (repaintedTabs); 226 repaintedTabs = null; 227 assertTrue ("Number of tabs repainted should be 1 but is " + set.size() + " - contents: " + set, set.size() == 1); 228 Integer in = (Integer ) set.iterator().next(); 229 assertTrue ("Wrong tab repainted - should be " + tab + " but is " + in + " - " + msg, in.intValue() == tab); 230 } 231 232 private void assertTabsRepainted (String msg, int[] tabs) { 233 if (repaintedTabs == null) { 234 fail ("No tabs repainted - " + msg ); 235 } 236 Set set = new HashSet (repaintedTabs); 237 repaintedTabs = null; 238 for (int i=0; i < tabs.length; i++) { 239 if (!set.contains(new Integer (tabs[i]))) { 240 fail (msg + " Tab " + tabs[i] + " was not repainted - repainted tabs were " + set); 241 } 242 } 243 } 244 245 protected void repaintTab(int tab) { 246 if (repaintedTabs == null) { 247 repaintedTabs = new HashSet (); 248 } 249 repaintedTabs.add (new Integer (tab)); 250 } 251 252 public void assertAllTabsRepainted(String msg) { 253 Boolean b = allTabsRepainted; 254 allTabsRepainted = null; 255 assertTrue ("repaintAllTabs not called - " + msg, b.booleanValue()); 256 } 257 258 public void assertAllTabsNotRepainted (String msg) { 259 assertTrue ("All tabs repainted - " + msg, allTabsRepainted == null); 260 } 261 262 private Boolean allTabsRepainted = null; 263 protected void repaintAllTabs() { 264 allTabsRepainted = Boolean.TRUE; 265 } 266 267 private int changeLastTab = Integer.MIN_VALUE; 268 private int changeCurrTab = Integer.MIN_VALUE; 269 private int changeType = Integer.MIN_VALUE; 270 private int typeOfChange = Integer.MIN_VALUE; 271 272 public void assertChange (String msg) { 273 if (changeLastTab == Integer.MIN_VALUE || changeCurrTab == Integer.MIN_VALUE || changeType == Integer.MIN_VALUE || typeOfChange == Integer.MIN_VALUE) { 274 fail ("Change not called - " + msg); 275 } 276 } 277 278 public void assertNoChange (String msg) { 279 if (changeLastTab == Integer.MIN_VALUE || changeCurrTab == Integer.MIN_VALUE || changeType == Integer.MIN_VALUE || typeOfChange == Integer.MIN_VALUE) { 280 281 } else { 282 fail (msg); 283 } 284 } 285 286 public void assertChange (String msg, int lastTab, int currTab) { 287 assertChange (msg); 288 if (lastTab != changeLastTab || currTab != changeCurrTab) { 289 fail (msg + " - Wrong arguments for call to change: " + "lastTab " + changeLastTab + " currTab " + changeCurrTab); 290 } 291 changeLastTab = Integer.MIN_VALUE; 292 changeCurrTab = Integer.MIN_VALUE; 293 typeOfChange = Integer.MIN_VALUE; 294 changeType = Integer.MIN_VALUE; 295 } 296 297 public void assertChange (String msg, int lastTab, int currTab, int type, int cType) { 298 int t = changeType; 299 int tc = typeOfChange; 300 assertChange (msg, lastTab, currTab); 301 if (type != t || tc != cType) { 302 fail (msg + " - Wrong arguments for call to change: " + stateToString (t) + " - " + changeToString(cType)); 303 } 304 } 305 306 307 protected void change(int lastTab, int currTab, int type, int changeType) { 308 changeLastTab = lastTab; 309 changeCurrTab = currTab; 310 typeOfChange = type; 311 this.changeType = changeType; 312 super.change (lastTab, currTab, type, changeType); 313 } 314 315 public int getRepaintPolicy(int tab) { 316 return policy; 317 } 318 } 319 320 private int policy = 0; 321 } 322 | Popular Tags |