KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > looks > LookSizeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.looks;
21
22 import org.netbeans.junit.*;
23
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.List JavaDoc;
28 import javax.swing.Action JavaDoc;
29 import org.netbeans.modules.looks.LookListener;
30
31 import org.openide.util.Lookup;
32
33 import org.netbeans.spi.looks.*;
34 import org.openide.filesystems.FileUtil;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.Repository;
37
38
39 /** Tests whether the DefaultLook returns proper values
40  */

41 public class LookSizeTest extends NbTestCase {
42     
43     // Methods of testCase -----------------------------------------------------
44

45     public LookSizeTest(java.lang.String JavaDoc testName) {
46         super(testName);
47     }
48     
49     public static void main(java.lang.String JavaDoc[] args) {
50         junit.textui.TestRunner.run(suite());
51     }
52     
53     public static NbTest suite() {
54         NbTestSuite suite = new NbTestSuite(LookSizeTest.class);
55         return suite;
56     }
57     
58     protected void setUp() throws Exception JavaDoc {
59         super.setUp();
60     }
61     
62     protected void tearDown() throws Exception JavaDoc {
63         super.tearDown();
64     }
65     
66     
67     // Test methods ------------------------------------------------------------
68

69     /** Test the size of a look when large amount of objects is registered
70      */

71     public void testLotOfObjectSize() {
72         
73         String JavaDoc bigArray[] = createLotOfStrings( 10, 1000 );
74         Look look = new SimpleStringLook();
75         LookListener listener = new SimpleStringLookListener();
76         LookListener listener2 = new SimpleStringLookListener();
77         
78         for ( int i = 0; i < bigArray.length; i++ ) {
79             org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener );
80             //org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener2 );
81
}
82         
83         Object JavaDoc[] subtract = bigArray; // Ignore the user data
84
assertSize( "Size of the node " , Collections.singleton( look ), 131248, subtract );
85                 
86     }
87     
88     
89     public void testLotOfObjectSizeComposite() {
90         
91         String JavaDoc bigArray[] = createLotOfStrings( 10, 1000 );
92         Look look1 = new SimpleStringLook();
93         Look look2 = new SimpleStringLook();
94         Look look3 = new SimpleStringLook();
95         Look look = Looks.composite( "KAREL", new Look[] { look1, look2, look3 } );
96         LookListener listener = new SimpleStringLookListener();
97         LookListener listener2 = new SimpleStringLookListener();
98         
99         for ( int i = 0; i < bigArray.length; i++ ) {
100             org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener );
101             //org.netbeans.modules.looks.Accessor.DEFAULT.addLookListener( look, bigArray[i], listener2 );
102
}
103         
104         Object JavaDoc[] subtract = bigArray; // Ignore the user data
105
// 150000 is just a guess from the test above however it should not
106
// be those 500000 as it is now. To fix the problem we have to
107
// separate attachTo calls and addListener calls.
108
assertSize( "Size of the node " , Collections.singleton( look ), 150000, subtract );
109                 
110     }
111     
112     // Helper methods and classes ----------------------------------------------
113

114     private static String JavaDoc[] createLotOfStrings( int classes, int count ) {
115         
116         String JavaDoc[] bigArray = new String JavaDoc[ classes * count ];
117         
118         for( int i = 0; i < count; i++ ) {
119             for( int j = 0; j < classes; j++ ) {
120                 bigArray[ i * classes + j] = (char)('A' + j) + " " + ( i );
121             }
122         }
123         
124         return bigArray;
125     }
126     
127     private static class SimpleStringLookListener implements LookListener {
128         
129         public void change(org.netbeans.modules.looks.LookEvent evt) {
130         }
131         
132         public void propertyChange(org.netbeans.modules.looks.LookEvent evt) {
133         }
134         
135     }
136     
137     private static class SimpleStringLook extends Look {
138         
139         SimpleStringLook() {
140             super( "SIMPLE_STRING_LOOK" );
141         }
142         
143         public String JavaDoc getName( Object JavaDoc representedObject, Lookup env ) {
144             return representedObject.toString();
145         }
146                 
147     }
148     
149     
150 }
151
Popular Tags