|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.spi.looks; import org.netbeans.junit.*; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.swing.Action; import org.netbeans.modules.looks.LookListener; import org.openide.util.Lookup; import org.netbeans.spi.looks.*; import org.openide.filesystems.FileUtil; import org.openide.filesystems.FileObject; import org.openide.filesystems.Repository; /** Tests whether the DefaultLook returns proper values */ public class LookSizeTest extends NbTestCase { // Methods of testCase ----------------------------------------------------- public LookSizeTest(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static NbTest suite() { NbTestSuite suite = new NbTestSuite(LookSizeTest.class); return suite; } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } // Test methods ------------------------------------------------------------ /** Test the size of a look when large amount of objects is registered */ public void testLotOfObjectSize() { String bigArray[] = createLotOfStrings( 10, 1000 ); Look look = new SimpleStringLook(); LookListener listener = new SimpleStringLookListener(); LookListener listener2 = new SimpleStringLookListener(); for ( int i = 0; i < bigArray.length; i++ ) { org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener ); //org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener2 ); } Object[] subtract = bigArray; // Ignore the user data assertSize( "Size of the node " , Collections.singleton( look ), 131248, subtract ); } public void testLotOfObjectSizeComposite() { String bigArray[] = createLotOfStrings( 10, 1000 ); Look look1 = new SimpleStringLook(); Look look2 = new SimpleStringLook(); Look look3 = new SimpleStringLook(); Look look = Looks.composite( "KAREL", new Look[] { look1, look2, look3 } ); LookListener listener = new SimpleStringLookListener(); LookListener listener2 = new SimpleStringLookListener(); for ( int i = 0; i < bigArray.length; i++ ) { org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener ); //org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener2 ); } Object[] subtract = bigArray; // Ignore the user data // 150000 is just a guess from the test above however it should not // be those 500000 as it is now. To fix the problem we have to // separate attachTo calls and addListener calls. assertSize( "Size of the node " , Collections.singleton( look ), 150000, subtract ); } // Helper methods and classes ---------------------------------------------- private static String[] createLotOfStrings( int classes, int count ) { String[] bigArray = new String[ classes * count ]; for( int i = 0; i < count; i++ ) { for( int j = 0; j < classes; j++ ) { bigArray[ i * classes + j] = (char)('A' + j) + " " + ( i ); } } return bigArray; } private static class SimpleStringLookListener implements LookListener { public void change(org.netbeans.modules.looks.LookEvent evt) { } public void propertyChange(org.netbeans.modules.looks.LookEvent evt) { } } private static class SimpleStringLook extends Look { SimpleStringLook() { super( "SIMPLE_STRING_LOOK" ); } public String getName( Object representedObject, Lookup env ) { return representedObject.toString(); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.