1 19 20 package org.openide.loaders; 21 22 import java.lang.ref.WeakReference ; 23 import java.util.HashSet ; 24 import junit.textui.TestRunner; 25 import org.openide.filesystems.*; 26 import java.util.Enumeration ; 27 import org.openide.nodes.Node; 28 import org.openide.cookies.InstanceCookie; 29 import org.openide.filesystems.Repository; 30 import org.netbeans.junit.*; 31 32 35 public class DataObjectSizeTest extends NbTestCase { 36 static FileSystem lfs; 37 static DataObject original; 38 39 public DataObjectSizeTest(String name) { 40 super(name); 41 } 42 43 protected void setUp() throws java.lang.Exception { 44 if (original == null) { 45 String fsstruct [] = new String [] { 46 "folder/original.txt", 47 }; 48 TestUtilHid.destroyLocalFileSystem (getName()); 49 lfs = TestUtilHid.createLocalFileSystem (getWorkDir (), fsstruct); 50 FileObject fo = FileUtil.createData (lfs.getRoot (), "/folder/original.txt"); 51 assertNotNull(fo); 52 original = DataObject.find (fo); 53 54 assertFalse ("Not a folder", original instanceof DataFolder); 55 } 56 } 57 58 public void testThatThereIsJustOneItemIssue42857 () throws Exception { 59 Object [] exclude = { 60 original.getLoader (), 61 original.getPrimaryFile (), 62 org.openide.util.Utilities.activeReferenceQueue (), 63 }; 64 65 assertSize ("If we exclude all the static things, like loader and " + 66 " reference queue and things we do not have control upon like file object" + 67 " we should get some reasonable size for the data object. ", 68 java.util.Collections.singleton (original), 280, exclude 69 ); 70 } 71 72 public void testNumberOfDataObjectPoolItemsIssue42857 () throws Exception { 73 class CountItems implements MemoryFilter { 74 HashSet items = new HashSet (); 75 76 public boolean reject(java.lang.Object obj) { 77 if (obj instanceof DataObjectPool.Item) { 78 items.add (obj); 79 } 80 81 return false; 82 } 83 } 84 CountItems cnt = new CountItems (); 85 assertSize ( 86 "Just iterate thru all the objects available and count Items", 87 java.util.Collections.singleton (DataObjectPool.getPOOL ()), 88 Integer.MAX_VALUE, 89 cnt 90 ); 91 92 if (cnt.items.size () != 1) { 93 fail ("There should be one item, but was " + cnt.items.size () + "\n" + cnt.items); 94 } 95 } 96 } 97 | Popular Tags |