From 2163ab35ff3de0263088dfb9828c561b395c97d8 Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 12 Apr 2006 21:24:03 +0000 Subject: [PATCH] Update testcases to work with new MozillaInterfaces.jar. No bug. git-svn-id: svn://10.0.0.236/trunk@194259 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/extensions/java/xpcom/tests/Foo.java | 13 ++-- mozilla/extensions/java/xpcom/tests/IFoo.idl | 44 ----------- .../extensions/java/xpcom/tests/Makefile.in | 18 ++--- .../java/xpcom/tests/TestArray.java | 74 ++++++++++++------- .../java/xpcom/tests/TestJavaProxy.java | 58 +++++++++++---- 5 files changed, 100 insertions(+), 107 deletions(-) delete mode 100644 mozilla/extensions/java/xpcom/tests/IFoo.idl diff --git a/mozilla/extensions/java/xpcom/tests/Foo.java b/mozilla/extensions/java/xpcom/tests/Foo.java index 8a197314a44..babb7d015e0 100644 --- a/mozilla/extensions/java/xpcom/tests/Foo.java +++ b/mozilla/extensions/java/xpcom/tests/Foo.java @@ -13,9 +13,8 @@ * * The Original Code is Java XPCOM Bindings. * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 + * The Initial Developer of the Original Code is IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2006 * IBM Corporation. All Rights Reserved. * * Contributor(s): @@ -35,9 +34,10 @@ * * ***** END LICENSE BLOCK ***** */ -import org.mozilla.xpcom.*; +import org.mozilla.xpcom.Mozilla; +import org.mozilla.xpcom.nsISupports; -public class Foo implements IFoo { +public class Foo implements nsISupports { static int gCount; int mID; @@ -54,10 +54,9 @@ public class Foo implements IFoo { // nsISupports implementation public nsISupports queryInterface(String aIID) { - return XPCOM.queryInterface(this, aIID); + return Mozilla.queryInterface(this, aIID); } - // IFoo implementation public int getId() { return mID; diff --git a/mozilla/extensions/java/xpcom/tests/IFoo.idl b/mozilla/extensions/java/xpcom/tests/IFoo.idl deleted file mode 100644 index b8383b557e5..00000000000 --- a/mozilla/extensions/java/xpcom/tests/IFoo.idl +++ /dev/null @@ -1,44 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Java XPCOM Bindings. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * IBM Corporation. All Rights Reserved. - * - * Contributor(s): - * Javier Pedemonte (jhpedemonte@gmail.com) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -[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 bb490f6c1ee..dbc922015af 100644 --- a/mozilla/extensions/java/xpcom/tests/Makefile.in +++ b/mozilla/extensions/java/xpcom/tests/Makefile.in @@ -47,18 +47,17 @@ XPIDL_MODULE = javaxpcomtest # In order for XPCOM to reference these interfaces, they need to be compiled # into XPT files. XPIDLSRCS = \ - IFoo.idl \ ITestParams.idl \ $(NULL) JAVA_SRCS = \ Foo.java \ TestArray.java \ - TestProps.java \ - TestQI.java \ TestJavaProxy.java \ - TestParams.java \ $(NULL) +# TestProps.java \ +# TestQI.java \ +# TestParams.java \ DIRS += dll @@ -68,9 +67,7 @@ else SEP = : endif -_JAVA_CLASSPATH = .$(SEP)./../build$(SEP)$(XPIDL_GEN_DIR) - -REBUILD_JAR = .rebuild_jar +_JAVA_CLASSPATH = .$(SEP)./../interfaces/MozillaInterfaces.jar$(SEP)$(XPIDL_GEN_DIR) GARBAGE += *.class $(REBUILD_JAR) @@ -81,9 +78,4 @@ include $(topsrcdir)/config/rules.mk $(ELOG) $(CYGWIN_WRAPPER) $(JAVAC) $(JAVAC_FLAGS) \ -classpath $(_JAVA_CLASSPATH) -d . $(_VPATH_SRCS) -# make sure to rebuild Java interfaces if our XPIDLSRCS change -$(REBUILD_JAR): $(XPIDLSRCS) - @cd ../build; make clean; make - @touch $@ - -libs:: $(REBUILD_JAR) $(JAVA_SRCS:.java=.class) +libs:: $(JAVA_SRCS:.java=.class) diff --git a/mozilla/extensions/java/xpcom/tests/TestArray.java b/mozilla/extensions/java/xpcom/tests/TestArray.java index e7d938f5afe..cb360e43d85 100644 --- a/mozilla/extensions/java/xpcom/tests/TestArray.java +++ b/mozilla/extensions/java/xpcom/tests/TestArray.java @@ -13,9 +13,8 @@ * * The Original Code is Java XPCOM Bindings. * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2005 + * The Initial Developer of the Original Code is IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2006 * IBM Corporation. All Rights Reserved. * * Contributor(s): @@ -35,8 +34,16 @@ * * ***** END LICENSE BLOCK ***** */ -import org.mozilla.xpcom.*; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Properties; + +import org.mozilla.xpcom.GREVersionRange; +import org.mozilla.xpcom.Mozilla; +import org.mozilla.xpcom.XPCOMException; +import org.mozilla.xpcom.nsIComponentManager; +import org.mozilla.xpcom.nsIMutableArray; +import org.mozilla.xpcom.nsISupports; /** * Adapted from xpcom/tests/TestArray.cpp @@ -64,23 +71,38 @@ public class TestArray { public static final String NS_ARRAY_CONTRACTID = "@mozilla.org/array;1"; public static void main(String [] args) { - System.loadLibrary("javaxpcom"); - - String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME"); - if (mozillaPath == null) { - throw new RuntimeException("MOZILLA_FIVE_HOME system property not set."); + GREVersionRange[] range = new GREVersionRange[1]; + range[0] = new GREVersionRange("1.8", true, "1.9+", true); + Properties props = null; + + File grePath = null; + try { + grePath = Mozilla.getGREPathWithProperties(range, props); + } catch (FileNotFoundException e) { } + + if (grePath == null) { + System.out.println("found no GRE PATH"); + return; } + System.out.println("GRE PATH = " + grePath.getPath()); + + Mozilla Moz = Mozilla.getInstance(); + try { + Moz.initXPCOM(grePath, null); + } catch (IllegalArgumentException e) { + System.out.println("no javaxpcom.jar found in given path"); + return; + } catch (Throwable t) { + System.out.println("initXPCOM failed"); + t.printStackTrace(); + return; + } + System.out.println("\n--> initialized\n"); - File localFile = new File(mozillaPath); - XPCOM.initXPCOM(localFile, null); - // XPCOM.initXPCOM() only initializes XPCOM. If you want to initialize - // Gecko, you would do the following instead: - // GeckoEmbed.initEmbedding(localFile, null); - - nsIComponentManager componentManager = XPCOM.getComponentManager(); + nsIComponentManager componentManager = Moz.getComponentManager(); nsIMutableArray array = (nsIMutableArray) - componentManager.createInstanceByContractID(NS_ARRAY_CONTRACTID, null, - nsIMutableArray.NS_IMUTABLEARRAY_IID); + componentManager.createInstanceByContractID(NS_ARRAY_CONTRACTID, + null, nsIMutableArray.NS_IMUTABLEARRAY_IID); if (array == null) { throw new RuntimeException("Failed to create nsIMutableArray."); } @@ -91,7 +113,7 @@ public class TestArray { dumpArray(array, 10, fillResult, 10); // test insert - IFoo foo = (IFoo) array.queryElementAt(3, IFoo.IFOO_IID); + Foo foo = (Foo) array.queryElementAt(3, nsISupports.NS_ISUPPORTS_IID); array.insertElementAt(foo, 5, false); System.out.println("insert 3 at 5:"); int insertResult[] = {0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9}; @@ -122,7 +144,7 @@ public class TestArray { } catch (XPCOMException e) { // If array.indexOf() did not find the element, it returns // NS_ERROR_FAILURE. - if (e.errorcode != XPCOM.NS_ERROR_FAILURE) { + if (e.errorcode != Mozilla.NS_ERROR_FAILURE) { throw e; } } @@ -176,11 +198,9 @@ public class TestArray { System.gc(); dumpArray(array, 0, null, 0); - localFile = null; componentManager = null; System.gc(); - XPCOM.shutdownXPCOM(null); - // GeckoEmbed.termEmbedding(); + Moz.shutdownXPCOM(null); System.out.println("Test Passed."); } @@ -188,7 +208,7 @@ public class TestArray { static void fillArray(nsIMutableArray aArray, int aCount) { for (int index = 0; index < aCount; index++) { - IFoo foo = new Foo(index); + nsISupports foo = new Foo(index); aArray.appendElement(foo, false); } } @@ -213,7 +233,7 @@ public class TestArray { assertEqual(count, aExpectedCount)); for (int index = 0; (index < count) && (index < aExpectedCount); index++) { - IFoo foo = (IFoo) aArray.queryElementAt(index, IFoo.IFOO_IID); + Foo foo = (Foo) aArray.queryElementAt(index, nsISupports.NS_ISUPPORTS_IID); System.out.println(index + ": " + aElementIDs[index] + "=" + foo.getId() + " (" + Integer.toHexString(foo.hashCode()) + ") " + @@ -225,7 +245,7 @@ public class TestArray { static long lastIndexOf(nsIMutableArray aArray, nsISupports aElement) { for (long i = aArray.getLength() - 1; i >= 0; i--) { - IFoo foo = (IFoo) aArray.queryElementAt(i, IFoo.IFOO_IID); + Foo foo = (Foo) aArray.queryElementAt(i, nsISupports.NS_ISUPPORTS_IID); if (foo == aElement) return i; } diff --git a/mozilla/extensions/java/xpcom/tests/TestJavaProxy.java b/mozilla/extensions/java/xpcom/tests/TestJavaProxy.java index dffd8596922..82686db8e86 100644 --- a/mozilla/extensions/java/xpcom/tests/TestJavaProxy.java +++ b/mozilla/extensions/java/xpcom/tests/TestJavaProxy.java @@ -13,9 +13,8 @@ * * The Original Code is Java XPCOM Bindings. * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 + * The Initial Developer of the Original Code is IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2006 * IBM Corporation. All Rights Reserved. * * Contributor(s): @@ -35,8 +34,16 @@ * * ***** END LICENSE BLOCK ***** */ -import org.mozilla.xpcom.*; import java.io.File; +import java.io.FileNotFoundException; +import java.util.Properties; + +import org.mozilla.xpcom.GREVersionRange; +import org.mozilla.xpcom.Mozilla; +import org.mozilla.xpcom.nsIFile; +import org.mozilla.xpcom.nsILocalFile; +import org.mozilla.xpcom.nsISimpleEnumerator; +import org.mozilla.xpcom.nsISupports; /** @@ -53,18 +60,37 @@ import java.io.File; */ public class TestJavaProxy { public static void main(String [] args) throws Exception { - System.loadLibrary("javaxpcom"); + GREVersionRange[] range = new GREVersionRange[1]; + range[0] = new GREVersionRange("1.8", true, "1.9+", true); + Properties props = null; + + File grePath = null; + try { + grePath = Mozilla.getGREPathWithProperties(range, props); + } catch (FileNotFoundException e) { } + + if (grePath == null) { + System.out.println("found no GRE PATH"); + return; + } + System.out.println("GRE PATH = " + grePath.getPath()); + + Mozilla Moz = Mozilla.getInstance(); + try { + Moz.initXPCOM(grePath, null); + } catch (IllegalArgumentException e) { + System.out.println("no javaxpcom.jar found in given path"); + return; + } catch (Throwable t) { + System.out.println("initXPCOM failed"); + t.printStackTrace(); + return; + } + System.out.println("\n--> initialized\n"); - String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME"); - if (mozillaPath == null) { - throw new RuntimeException("MOZILLA_FIVE_HOME system property not set."); - } - - File localFile = new File(mozillaPath); - XPCOM.initXPCOM(localFile, null); - - nsILocalFile directory = XPCOM.newLocalFile("/usr", false); - nsISimpleEnumerator entries = (nsISimpleEnumerator) directory.getDirectoryEntries(); + nsILocalFile directory = Moz.newLocalFile("/usr", false); + nsISimpleEnumerator entries = (nsISimpleEnumerator) + directory.getDirectoryEntries(); while (entries.hasMoreElements()) { nsISupports supp = entries.getNext(); nsIFile file = (nsIFile) supp.queryInterface(nsIFile.NS_IFILE_IID); @@ -75,6 +101,6 @@ public class TestJavaProxy { directory = null; entries = null; - XPCOM.shutdownXPCOM(null); + Moz.shutdownXPCOM(null); } }