# HG changeset patch # User Jaroslav Tulach # Date 1213430078 -7200 # Node ID f2b6057a33765bf0d86f3d36b3b28d2770f60886 # Parent 64308321f7bd9538758bb5957997170ed5f1302b Memory tests diff -r 64308321f7bd -r f2b6057a3376 samples/gc/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/build.xml Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,69 @@ + + + + + + Builds, tests, and runs the project gc. + + + diff -r 64308321f7bd -r f2b6057a3376 samples/gc/nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/nbproject/build-impl.xml Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,627 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff -r 64308321f7bd -r f2b6057a3376 samples/gc/nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/nbproject/genfiles.properties Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=70895030 +build.xml.script.CRC32=68c5d084 +build.xml.stylesheet.CRC32=be360661 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=70895030 +nbproject/build-impl.xml.script.CRC32=0f2f8102 +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 64308321f7bd -r f2b6057a3376 samples/gc/nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/nbproject/project.properties Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,65 @@ +application.title=gc +application.vendor=jarda +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/gc.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.junit-4.4.jar=../libs/dist/junit-4.4.jar +file.reference.org-netbeans-insane.jar=../libs/dist/org-netbeans-insane.jar +file.reference.org-netbeans-modules-nbjunit.jar=../libs/dist/org-netbeans-modules-nbjunit.jar +file.reference.org-openide-util.jar=../libs/dist/org-openide-util.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.org-openide-util.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${file.reference.org-netbeans-insane.jar}:\ + ${file.reference.org-netbeans-modules-nbjunit.jar}:\ + ${file.reference.junit-4.4.jar} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r 64308321f7bd -r f2b6057a3376 samples/gc/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/nbproject/project.xml Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + gc + 1.6.5 + + + + + + + + + diff -r 64308321f7bd -r f2b6057a3376 samples/gc/src/org/apidesign/gc/WeakListeners.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/src/org/apidesign/gc/WeakListeners.java Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,13 @@ +package org.apidesign.gc; + +import java.util.EventListener; + +public final class WeakListeners { + private WeakListeners() { } + + // BEGIN: gc.weaklistener.create + public static T create(Class type, T listener, Object source) { + return org.openide.util.WeakListeners.create(type, listener, source); + } + // END: gc.weaklistener.create +} diff -r 64308321f7bd -r f2b6057a3376 samples/gc/test/org/apidesign/gc/SizeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/test/org/apidesign/gc/SizeTest.java Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,32 @@ +package org.apidesign.gc; + +import org.junit.Test; +import org.netbeans.junit.NbTestCase; + +public class SizeTest { + public SizeTest() { + } + + + @Test + public void measureIsDataLowerThan8No() { + Data d = new Data(); + + NbTestCase.assertSize("The size of the data instance is higher than 8, fail", 8, d); + } + + @Test + public void measureIsDataLowerThan16Yes() { + // BEGIN: size.measure + Data d = new Data(); + NbTestCase.assertSize("The size of the data instance is higher than 16", 16, d); + // END: size.measure + } + + + // BEGIN: size.Data + private static final class Data { + int data; + } + // END: size.Data +} diff -r 64308321f7bd -r f2b6057a3376 samples/gc/test/org/apidesign/gc/WeakListenersTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/gc/test/org/apidesign/gc/WeakListenersTest.java Sat Jun 14 09:54:38 2008 +0200 @@ -0,0 +1,76 @@ +package org.apidesign.gc; + +import java.awt.Color; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.ref.WeakReference; +import javax.swing.JPanel; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.netbeans.junit.NbTestCase; +import static org.junit.Assert.*; + +public class WeakListenersTest { + + private static JPanel longLivingBean; + + public WeakListenersTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + longLivingBean = new JPanel(); + } + + @Before + public void setUp() { + longLivingBean.setBackground(Color.BLACK); + } + + @Test + public void listenWithoutWeakReference() { + PropL listener = new PropL(); + longLivingBean.addPropertyChangeListener(listener); + longLivingBean.setBackground(Color.WHITE); + assertEquals("background property change notified", "background", listener.propName); + WeakReference ref = new WeakReference(listener); + listener = null; + try { + NbTestCase.assertGC( + "Of course, this listener cannot disappear, because it is held from long living JavaBean", + ref + ); + } catch (Exception ex) { + ex.printStackTrace(); + // of course it cannot + return; + } + fail("The listener cannot be GCed as it is held from long living JavaBean"); + } + + @Test + public void listenViaWeakListener() { + PropL listener = new PropL(); + + PropertyChangeListener weakL = WeakListeners.create(PropertyChangeListener.class, listener, longLivingBean); + longLivingBean.addPropertyChangeListener(weakL); + longLivingBean.setBackground(Color.WHITE); + assertEquals("background property change notified", "background", listener.propName); + // BEGIN: gc.assertGC + WeakReference ref = new WeakReference(listener); + listener = null; + NbTestCase.assertGC("This listener can disappear", ref); + // END: gc.assertGC + } + + + private static class PropL implements PropertyChangeListener { + String propName; + public void propertyChange(PropertyChangeEvent evt) { + propName = evt.getPropertyName(); + } + } +} \ No newline at end of file