1 19 20 package org.netbeans.spi.looks; 21 22 import java.beans.BeanInfo ; 23 24 import org.openide.util.Lookup; 25 import org.netbeans.spi.looks.*; 26 27 import org.netbeans.junit.*; 28 29 public class FilterLookMaskTest extends NbTestCase { 30 31 private static final String MSSG_UNEXPECTED_EXCEPTION = "Unexpected exception caught : "; 32 33 private Look filterLook; 35 36 private SampleLook sampleLook; 38 39 private SampleRepObject representedObject; 41 42 private GoldenValue[] goldenValues; 44 45 private GoldenValue[] results; 47 48 public static void main(java.lang.String [] args) { 49 junit.textui.TestRunner.run(suite()); 50 } 51 52 public static NbTest suite() { 53 NbTestSuite suite = new NbTestSuite(FilterLookMaskTest.class); 54 55 return suite; 56 } 57 58 60 public FilterLookMaskTest( String name ) { 61 super( name ); 62 } 63 64 protected void setUp() throws Exception { 65 super.setUp(); 66 67 sampleLook = new SampleLook( "FilterLookTest" ); 68 goldenValues = GoldenValue.createGoldenValues(); 70 representedObject = new SampleRepObject( goldenValues ); 71 72 73 } 75 76 protected void tearDown() throws Exception { 77 78 filterLook = null; 79 sampleLook = null; 80 81 super.tearDown(); 82 } 83 84 86 102 113 114 public void test_GET_DISPLAY_NAME() { 115 String message = doTestingWithMask( ProxyLook.GET_DISPLAY_NAME ); 116 assertTrue( message == null ? "" : message, message == null ); 117 } 118 119 public void test_GET_NAME() { 120 String message = doTestingWithMask( ProxyLook.GET_NAME ); 121 assertTrue( message == null ? "" : message, message == null ); 122 } 123 124 public void test_RENAME() { 125 String message = doTestingWithMask( ProxyLook.RENAME ); 126 assertTrue( message == null ? "" : message, message == null ); 127 } 128 129 public void test_GET_SHORT_DESCRIPTION () { 130 String message = doTestingWithMask( ProxyLook.GET_SHORT_DESCRIPTION ); 131 assertTrue( message == null ? "" : message, message == null ); 132 } 133 134 public void test_GET_ICON() { 135 String message = doTestingWithMask( ProxyLook.GET_ICON ); 136 assertTrue( message == null ? "" : message, message == null ); 137 } 138 139 public void test_GET_OPENED_ICON () { 140 String message = doTestingWithMask( ProxyLook.GET_OPENED_ICON ); 141 assertTrue( message == null ? "" : message, message == null ); 142 } 143 144 public void test_GET_HELP_CTX () { 145 String message = doTestingWithMask( ProxyLook.GET_HELP_CTX ); 146 assertTrue( message == null ? "" : message, message == null ); 147 } 148 149 public void test_GET_CHILD_OBJECTS () { 150 String message = doTestingWithMask( ProxyLook.GET_CHILD_OBJECTS ); 151 assertTrue( message == null ? "" : message, message == null ); 152 } 153 154 public void test_GET_NEW_TYPES () { 155 String message = doTestingWithMask( ProxyLook.GET_NEW_TYPES ); 156 assertTrue( message == null ? "" : message, message == null ); 157 } 158 159 public void test_GET_ACTIONS () { 160 String message = doTestingWithMask( ProxyLook.GET_ACTIONS ); 161 assertTrue( message == null ? "" : message, message == null ); 162 } 163 164 public void test_GET_CONTEXT_ACTIONS () { 165 String message = doTestingWithMask( ProxyLook.GET_CONTEXT_ACTIONS ); 166 assertTrue( message == null ? "" : message, message == null ); 167 } 168 169 public void test_GET_DEFAULT_ACTION () { 170 String message = doTestingWithMask( ProxyLook.GET_DEFAULT_ACTION ); 171 assertTrue( message == null ? "" : message, message == null ); 172 } 173 174 public void test_GET_PROPERTY_SETS () { 175 String message = doTestingWithMask( ProxyLook.GET_PROPERTY_SETS ); 176 assertTrue( message == null ? "" : message, message == null ); 177 } 178 179 public void test_GET_CUSTOMIZER () { 180 String message = doTestingWithMask( ProxyLook.GET_CUSTOMIZER ); 181 assertTrue( message == null ? "" : message, message == null ); 182 } 183 184 public void test_CAN_RENAME () { 185 String message = doTestingWithMask( ProxyLook.CAN_RENAME ); 186 assertTrue( message == null ? "" : message, message == null ); 187 } 188 189 public void test_CAN_DESTROY () { 190 String message = doTestingWithMask( ProxyLook.CAN_DESTROY ); 191 assertTrue( message == null ? "" : message, message == null ); 192 } 193 194 public void test_CAN_COPY () { 195 String message = doTestingWithMask( ProxyLook.CAN_COPY ); 196 assertTrue( message == null ? "" : message, message == null ); 197 } 198 199 public void test_CAN_CUT () { 200 String message = doTestingWithMask( ProxyLook.CAN_CUT ); 201 assertTrue( message == null ? "" : message, message == null ); 202 } 203 204 public void test_GET_PASTE_TYPES () { 205 String message = doTestingWithMask( ProxyLook.GET_PASTE_TYPES ); 206 assertTrue( message == null ? "" : message, message == null ); 207 } 208 209 public void test_GET_DROP_TYPE () { 210 String message = doTestingWithMask( ProxyLook.GET_DROP_TYPE ); 211 assertTrue( message == null ? "" : message, message == null ); 212 } 213 214 public void test_CLIPBOARD_COPY () { 215 String message = doTestingWithMask( ProxyLook.CLIPBOARD_COPY ); 216 assertTrue( message == null ? "" : message, message == null ); 217 } 218 219 public void test_CLIPBOARD_CUT () { 220 String message = doTestingWithMask( ProxyLook.CLIPBOARD_CUT ); 221 assertTrue( message == null ? "" : message, message == null ); 222 } 223 224 public void test_DRAG () { 225 String message = doTestingWithMask( ProxyLook.DRAG ); 226 assertTrue( message == null ? "" : message, message == null ); 227 } 228 229 public void test_DESTROY () { 230 String message = doTestingWithMask( ProxyLook.DESTROY ); 231 assertTrue( message == null ? "" : message, message == null ); 232 } 233 234 236 private String doTestingWithMask( long mask ) { 237 filterLook = Looks.filter( "TestFilter", sampleLook, mask ); 238 239 try { 240 results = readResults(); 241 } 242 catch ( Exception e ) { 243 return MSSG_UNEXPECTED_EXCEPTION; 244 } 245 246 for( int i = 0; i < goldenValues.length; i ++ ) { 247 248 if ( goldenValues[i].key == ProxyLook.GET_LOOKUP_ITEMS ) { 249 continue; 250 } 251 252 Object result = GoldenValue.get( goldenValues[i].key, results ); 253 254 if ( result instanceof Boolean && Boolean.FALSE.equals( result ) ) { 259 result = null; 260 } 261 262 if ( ( ( goldenValues[i].key & mask ) > 0 && result == null ) || 263 ( ( goldenValues[i].key & mask ) == 0 && result != null )) { 264 return getFailMessage( i ); 265 } 266 } 267 268 return null; 269 } 270 271 private static final Lookup NO_LOOKUP = null; 273 private GoldenValue[] readResults() throws Exception { 274 275 return new GoldenValue[] { 276 277 new GoldenValue( 278 ProxyLook.GET_DISPLAY_NAME, 279 filterLook.getDisplayName( representedObject, NO_LOOKUP ) ), 280 281 new GoldenValue( 282 ProxyLook.GET_NAME, 283 filterLook.getName( representedObject, NO_LOOKUP ) ), 284 285 287 new GoldenValue( 288 ProxyLook.GET_SHORT_DESCRIPTION, 289 filterLook.getShortDescription( representedObject, NO_LOOKUP ) ), 290 291 new GoldenValue( 292 ProxyLook.GET_ICON, 293 filterLook.getIcon( representedObject, BeanInfo.ICON_COLOR_16x16, NO_LOOKUP ) ), 294 295 new GoldenValue( 296 ProxyLook.GET_OPENED_ICON, 297 filterLook.getOpenedIcon( representedObject, BeanInfo.ICON_COLOR_16x16, NO_LOOKUP ) ), 298 299 new GoldenValue( 300 ProxyLook.GET_HELP_CTX, 301 filterLook.getHelpCtx( representedObject, NO_LOOKUP ) ), 302 303 new GoldenValue( 304 ProxyLook.GET_CHILD_OBJECTS, 305 filterLook.getChildObjects( representedObject, NO_LOOKUP ) ), 306 307 new GoldenValue( 308 ProxyLook.GET_NEW_TYPES, 309 filterLook.getNewTypes( representedObject, NO_LOOKUP ) ), 310 311 new GoldenValue( 312 ProxyLook.GET_ACTIONS, 313 filterLook.getActions( representedObject, NO_LOOKUP ) ), 314 315 new GoldenValue( 316 ProxyLook.GET_CONTEXT_ACTIONS, 317 filterLook.getContextActions( representedObject, NO_LOOKUP ) ), 318 319 new GoldenValue( 320 ProxyLook.GET_DEFAULT_ACTION, 321 filterLook.getDefaultAction( representedObject, NO_LOOKUP ) ), 322 323 new GoldenValue( 324 ProxyLook.GET_PROPERTY_SETS, 325 filterLook.getPropertySets( representedObject, NO_LOOKUP ) ), 326 327 new GoldenValue( 328 ProxyLook.GET_CUSTOMIZER, 329 filterLook.getCustomizer( representedObject, NO_LOOKUP ) ), 330 331 new GoldenValue( 332 ProxyLook.HAS_CUSTOMIZER, 333 new Boolean ( filterLook.hasCustomizer( representedObject, NO_LOOKUP ) ) ), 334 335 new GoldenValue( 336 ProxyLook.CAN_RENAME, 337 new Boolean ( filterLook.canRename( representedObject, NO_LOOKUP ) ) ), 338 339 new GoldenValue( 340 ProxyLook.CAN_DESTROY, 341 new Boolean ( filterLook.canDestroy( representedObject, NO_LOOKUP ) ) ), 342 343 new GoldenValue( 344 ProxyLook.CAN_COPY, 345 new Boolean ( filterLook.canCopy( representedObject, NO_LOOKUP ) ) ), 346 347 new GoldenValue( 348 ProxyLook.CAN_CUT, 349 new Boolean ( filterLook.canCut( representedObject, NO_LOOKUP ) ) ), 350 351 new GoldenValue( 352 ProxyLook.GET_PASTE_TYPES, 353 filterLook.getPasteTypes( representedObject, null, NO_LOOKUP ) ), 354 355 new GoldenValue( 356 ProxyLook.GET_DROP_TYPE, 357 filterLook.getDropType( representedObject, null, 0, 0, NO_LOOKUP ) ), 358 359 new GoldenValue( 360 ProxyLook.CLIPBOARD_COPY, 361 filterLook.clipboardCopy( representedObject, NO_LOOKUP ) ), 362 363 new GoldenValue( 364 ProxyLook.CLIPBOARD_CUT, 365 filterLook.clipboardCut( representedObject, NO_LOOKUP ) ), 366 367 new GoldenValue( 368 ProxyLook.DRAG, 369 filterLook.drag( representedObject, NO_LOOKUP ) ) 370 371 }; 373 } 374 375 private String getFailMessage( int failIndex ) { 376 return "Failed on method index : " + failIndex + " : " + 377 results[ failIndex ].key + " = " + 378 results[ failIndex ].result; 379 } 380 381 } 382 | Popular Tags |