Update testcases to work with new MozillaInterfaces.jar. No bug.

This commit is contained in:
pedemont@us.ibm.com
2006-04-12 21:24:03 +00:00
parent d4f2f43de5
commit 151271217c
5 changed files with 100 additions and 107 deletions

View File

@@ -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;
}