diff --git a/mozilla/extensions/java/xpcom/tests/Foo.java b/mozilla/extensions/java/xpcom/tests/Foo.java index 13a43bd0433..fe87e119573 100644 --- a/mozilla/extensions/java/xpcom/tests/Foo.java +++ b/mozilla/extensions/java/xpcom/tests/Foo.java @@ -37,7 +37,6 @@ import org.mozilla.xpcom.*; - public class Foo implements IFoo { static int gCount; @@ -63,7 +62,7 @@ public class Foo implements IFoo { } // IFoo implementation - public int id() + public int getId() { return mID; } diff --git a/mozilla/extensions/java/xpcom/tests/IFoo.java b/mozilla/extensions/java/xpcom/tests/IFoo.idl similarity index 90% rename from mozilla/extensions/java/xpcom/tests/IFoo.java rename to mozilla/extensions/java/xpcom/tests/IFoo.idl index 01eb3898018..b8383b557e5 100644 --- a/mozilla/extensions/java/xpcom/tests/IFoo.java +++ b/mozilla/extensions/java/xpcom/tests/IFoo.idl @@ -35,11 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -import org.mozilla.xpcom.*; +#include "nsISupports.idl" -public interface IFoo extends nsISupports { - public static final String IFOO_IID = - "{9e70a320-be02-11d1-8031-006008159b5a}"; - - public int id(); -} +[scriptable, uuid(9e70a320-be02-11d1-8031-006008159b5a)] +interface IFoo : nsISupports +{ + readonly attribute long id; +}; diff --git a/mozilla/extensions/java/xpcom/tests/Makefile.in b/mozilla/extensions/java/xpcom/tests/Makefile.in index 6ec1d6ab0bf..e2bb217acfc 100644 --- a/mozilla/extensions/java/xpcom/tests/Makefile.in +++ b/mozilla/extensions/java/xpcom/tests/Makefile.in @@ -41,12 +41,39 @@ srcdir = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -include $(topsrcdir)/config/config.mk -TestArray:: - javac -classpath .:./..:$(srcdir) -d . $(srcdir)/TestArray.java +XPIDL_MODULE = javaxpcomtest + +XPIDLSRCS = \ + IFoo.idl \ + $(NULL) + +JAVA_SRCS_ = \ + TestArray.java \ + $(NULL) + +SEP = : + +JAVA_CLASSPATH = ./..$(SEP)$(XPIDL_GEN_DIR) GARBAGE += *.class include $(topsrcdir)/config/rules.mk +$(XPIDL_GEN_DIR)/%.java: %.idl $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done + $(REPORT_BUILD) + $(ELOG) $(XPIDL_COMPILE) -m java -w -I$(srcdir) -I$(IDL_DIR) -o $(XPIDL_GEN_DIR)/$* $(_VPATH_SRCS) + +ifdef JAVA_CLASSPATH +_JAVA_CLASSPATH = .$(SEP)$(srcdir)$(SEP)$(JAVA_CLASSPATH) +else +_JAVA_CLASSPATH = .$(SEP)$(srcdir) +endif + +%.class: %.java Makefile Makefile.in + $(REPORT_BUILD) + $(ELOG) javac -classpath $(_JAVA_CLASSPATH) -d . $(_VPATH_SRCS) + +export:: $(XPIDL_GEN_DIR)/$(XPIDLSRCS:.idl=.java) + +libs:: $(JAVA_SRCS_:.java=.class) diff --git a/mozilla/extensions/java/xpcom/tests/TestArray.java b/mozilla/extensions/java/xpcom/tests/TestArray.java index 532f25bb2f5..694320e9766 100644 --- a/mozilla/extensions/java/xpcom/tests/TestArray.java +++ b/mozilla/extensions/java/xpcom/tests/TestArray.java @@ -44,12 +44,24 @@ import org.mozilla.xpcom.*; * - Creating an XPCOM object in Java, and calling its methods. * - Calling several of the Gecko embedding funtions. * - Passing Java class objects to XPCOM. + * - Have XPCOM call Java class' queryInterface() method. * - Catching GeckoException. + * - Lifetime of JNI structures and Java objects (everything should be + * garbage collected or destroyed at the appropriate time). + * + * NOTE: The System.gc() calls throughout the testcase are used to tell the + * JVM that now would be a good time to garbage collect. This helps us see + * if everything is getting freed properly. However, since the System.gc() + * call is only a suggestion to the JVM (you can't force garbage collection), + * this testcase may not work the same on every system. On my system, it + * usually works as expected (that is, Java objects that are no longer in + * use are destroyed whenever System.gc() is called). But I have seen some + * instances where the garbage collector ran later in the testcase. */ public class TestArray { public static void main(String [] args) { - System.loadLibrary ("javaxpcom"); + System.loadLibrary("javaxpcom"); String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME"); if (mozillaPath == null) { @@ -110,29 +122,36 @@ public class TestArray { System.out.println("ReplaceElementAt(8):"); replaceElementAt(array, foo, 8); + System.gc(); int replaceResult[] = {3, 0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3}; dumpArray(array, 13, replaceResult, 9); System.out.println("RemoveElementAt(0):"); array.removeElementAt(0); + System.gc(); int removeResult[] = {0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3}; dumpArray(array, 12, removeResult, 9); System.out.println("RemoveElementAt(7):"); array.removeElementAt(7); + System.gc(); int removeResult2[] = {0, 1, 2, 3, 4, 3, 5, 7, 8, 9, 3}; dumpArray(array, 11, removeResult2, 9); System.out.println("RemoveElement(foo):"); removeElement(array, foo); + System.gc(); int removeResult3[] = {0, 1, 2, 4, 3, 5, 7, 8, 9, 3}; dumpArray(array, 10, removeResult3, 9); System.out.println("RemoveLastElement(foo):"); removeLastElement(array, foo); + System.gc(); int removeResult4[] = {0, 1, 2, 4, 3, 5, 7, 8, 9}; dumpArray(array, 9, removeResult4, 9); // test clear + foo = null; // remove ref now, so everything is cleared System.out.println("clear array:"); array.clear(); + System.gc(); dumpArray(array, 0, null, 0); System.out.println("add 4 new:"); fillArray(array, 4); @@ -170,9 +189,9 @@ public class TestArray { for (int index = 0; (index < count) && (index < aExpectedCount); index++) { IFoo foo = (IFoo) aArray.queryElementAt(index, IFoo.IFOO_IID); - System.out.println(index + ": " + aElementIDs[index] + "=" + foo.id() + - " (" + foo.hashCode() + ") " + - assertEqual(foo.id(), aElementIDs[index])); + System.out.println(index + ": " + aElementIDs[index] + "=" + + foo.getId() + " (" + foo.hashCode() + ") " + + assertEqual(foo.getId(), aElementIDs[index])); foo = null; } }