Bug 350886 - First pass at JavaXPCOM unit tests. r=bsmedberg.
This commit is contained in:
Родитель
7bee7f7e29
Коммит
11e7b61647
|
@ -1377,7 +1377,6 @@ if [ "$MOZ_JAVAXPCOM" ]; then
|
|||
extensions/java/xpcom/interfaces/Makefile
|
||||
extensions/java/xpcom/src/Makefile
|
||||
extensions/java/xpcom/glue/Makefile
|
||||
extensions/java/xpcom/tools/genifaces/Makefile
|
||||
"
|
||||
fi
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@ MOZ_MOCHITEST = @MOZ_MOCHITEST@
|
|||
|
||||
MOZ_JAVAXPCOM = @MOZ_JAVAXPCOM@
|
||||
JAVA_INCLUDE_PATH="@JAVA_INCLUDE_PATH@"
|
||||
JAVA="@JAVA@"
|
||||
JAVAC="@JAVAC@"
|
||||
JAR="@JAR@"
|
||||
|
||||
|
|
|
@ -766,7 +766,7 @@ install:: $(SDK_HEADERS)
|
|||
endif
|
||||
endif
|
||||
|
||||
install:: $(SHARED_LIBRARY) $(IMPORT_LIBRARY) $(LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
|
||||
install:: $(SHARED_LIBRARY) $(IMPORT_LIBRARY) $(LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(JAVA_LIBRARY)
|
||||
ifndef NO_INSTALL
|
||||
#ifdef LIBRARY
|
||||
#ifndef IS_COMPONENT
|
||||
|
|
|
@ -5603,10 +5603,11 @@ if test -n "${MOZ_JAVAXPCOM}"; then
|
|||
JAVA_PATH="$JAVA_HOME/bin:$PATH"
|
||||
fi
|
||||
|
||||
AC_PATH_PROG(JAVA, java, :, [$JAVA_PATH])
|
||||
AC_PATH_PROG(JAVAC, javac, :, [$JAVA_PATH])
|
||||
AC_PATH_PROG(JAR, jar, :, [$JAVA_PATH])
|
||||
if test -z "$JAVAC" || test "$JAVAC" = ":" || test -z "$JAR" || test "$JAR" = ":"; then
|
||||
AC_MSG_ERROR([The programs javac and jar were not found. Set \$JAVA_HOME to your java sdk directory, use --with-java-bin-path={java-bin-dir}, or reconfigure with --disable-javaxpcom.])
|
||||
if test -z "$JAVA" || test "$JAVA" = ":" || test -z "$JAVAC" || test "$JAVAC" = ":" || test -z "$JAR" || test "$JAR" = ":"; then
|
||||
AC_MSG_ERROR([The programs java, javac and jar were not found. Set \$JAVA_HOME to your java sdk directory, use --with-java-bin-path={java-bin-dir}, or reconfigure with --disable-javaxpcom.])
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -7714,6 +7715,7 @@ AC_SUBST(NS_PRINTING)
|
|||
|
||||
AC_SUBST(MOZ_JAVAXPCOM)
|
||||
AC_SUBST(JAVA_INCLUDE_PATH)
|
||||
AC_SUBST(JAVA)
|
||||
AC_SUBST(JAVAC)
|
||||
AC_SUBST(JAR)
|
||||
|
||||
|
|
|
@ -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) 2007
|
||||
# IBM Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
@ -42,9 +41,17 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = src
|
||||
DIRS = interfaces glue
|
||||
|
||||
TOOL_DIRS = glue
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# Build the implementation Java classes
|
||||
libs::
|
||||
make -C src jar-libs
|
||||
|
||||
install::
|
||||
make -C src jar-install
|
||||
|
|
|
@ -45,6 +45,7 @@ JAVA_LIBRARY_NAME = MozillaGlue
|
|||
|
||||
# Don't install MozillaGlue.jar in $(DIST)/bin
|
||||
NO_DIST_INSTALL=1
|
||||
NO_INSTALL=1
|
||||
|
||||
PACKAGE_DIR = org/mozilla/xpcom
|
||||
|
||||
|
@ -116,8 +117,7 @@ $(IFACES_DIR)/$(JAVA_IFACES_PKG_NAME)/nsISupports.class: $(IFACES_DIR) Makefile
|
|||
@echo Compiling Java interfaces
|
||||
find $(JAVA_DIST_DIR)/default -name "*.java" $(IGNORE_IFACES) > java.files
|
||||
$(CYGWIN_WRAPPER) $(JAVAC) $(JAVAC_FLAGS) -classpath $(IFACES_DIR) \
|
||||
-d $(IFACES_DIR) -sourcepath $(JAVA_DIST_DIR) \
|
||||
-sourcepath $(JAVA_DIST_DIR)/default @java.files
|
||||
-d $(IFACES_DIR) -sourcepath $(JAVA_DIST_DIR)/default @java.files
|
||||
|
||||
$(IFACES_JAR): $(IFACES_DIR)/$(JAVA_IFACES_PKG_NAME)/nsISupports.class Makefile
|
||||
$(JAR) cf $@ -C $(IFACES_DIR) org
|
||||
|
@ -126,12 +126,6 @@ $(IFACES_JAR_SRC): $(IFACES_JAR)
|
|||
$(JAR) cf $@ -C $(JAVA_DIST_DIR)/default org
|
||||
$(ZIP) -d $@ $(patsubst %, $(JAVA_IFACES_PKG_NAME)/%.java, $(IGNORE_IFACES_NAMES))
|
||||
|
||||
##
|
||||
# Build the implementation Java classes, which depend on these interfaces
|
||||
##
|
||||
export:: $(IFACES_JAR) $(IFACES_JAR_SRC) $(JAVA_LIBRARY)
|
||||
$(MAKE) -C ../src jarfile
|
||||
|
||||
# Since we set NO_DIST_INSTALL above, the jars don't get copied into the SDK.
|
||||
# Handle that here.
|
||||
libs:: $(SDK_LIBRARY) $(SDK_LIB_DIR)
|
||||
|
|
|
@ -112,5 +112,8 @@ include $(topsrcdir)/config/rules.mk
|
|||
$(JARFILE): $(addprefix $(_JAVA_DIR)/,$(JAVA_SRCS:.java=.class)) Makefile Makefile.in
|
||||
$(JAR) cf $@ -C $(_JAVA_DIR) .
|
||||
|
||||
jarfile:: $(JARFILE) $(JARFILE_SRC)
|
||||
$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin
|
||||
jar-libs:: $(JARFILE)
|
||||
$(INSTALL) $(IFLAGS1) $(JARFILE) $(FINAL_TARGET)
|
||||
|
||||
jar-install:: $(JARFILE)
|
||||
$(SYSINSTALL) $(IFLAGS2) $(JARFILE) $(DESTDIR)$(mozappdir)
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/* ***** 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) 2007
|
||||
* 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 ***** */
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mozilla.xpcom.IAppFileLocProvider;
|
||||
|
||||
|
||||
public class LocationProvider implements IAppFileLocProvider {
|
||||
|
||||
private File libXULPath;
|
||||
private File profile;
|
||||
private File history;
|
||||
|
||||
public LocationProvider(File aBinPath, File aProfileDir)
|
||||
throws IOException {
|
||||
libXULPath = aBinPath;
|
||||
profile = aProfileDir;
|
||||
|
||||
if (!libXULPath.exists() || !libXULPath.isDirectory()) {
|
||||
throw new FileNotFoundException("libxul directory specified is not valid: "
|
||||
+ libXULPath.getAbsolutePath());
|
||||
}
|
||||
if (profile != null && (!profile.exists() || !profile.isDirectory())) {
|
||||
throw new FileNotFoundException("profile directory specified is not valid: "
|
||||
+ profile.getAbsolutePath());
|
||||
}
|
||||
|
||||
// create history file
|
||||
if (profile != null) {
|
||||
setupProfile();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupProfile() throws IOException {
|
||||
history = new File(profile, "history.dat");
|
||||
if (!history.exists()) {
|
||||
history.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile(String aProp, boolean[] aPersistent) {
|
||||
File file = null;
|
||||
if (aProp.equals("GreD") || aProp.equals("GreComsD")) {
|
||||
file = libXULPath;
|
||||
if (aProp.equals("GreComsD")) {
|
||||
file = new File(file, "components");
|
||||
}
|
||||
}
|
||||
else if (aProp.equals("MozBinD") ||
|
||||
aProp.equals("CurProcD") ||
|
||||
aProp.equals("ComsD"))
|
||||
{
|
||||
file = libXULPath;
|
||||
if (aProp.equals("ComsD")) {
|
||||
file = new File(file, "components");
|
||||
}
|
||||
}
|
||||
else if (aProp.equals("ProfD")) {
|
||||
return profile;
|
||||
}
|
||||
else if (aProp.equals("UHist")) {
|
||||
return history;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public File[] getFiles(String aProp) {
|
||||
File[] files = null;
|
||||
if (aProp.equals("APluginsDL")) {
|
||||
files = new File[1];
|
||||
files[0] = new File(libXULPath, "plugins");
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
}
|
|
@ -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) 2007
|
||||
# IBM Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
@ -42,40 +41,42 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPIDL_MODULE = javaxpcomtest
|
||||
|
||||
# In order for XPCOM to reference these interfaces, they need to be compiled
|
||||
# into XPT files.
|
||||
XPIDLSRCS = \
|
||||
ITestParams.idl \
|
||||
DIRS = \
|
||||
testparams \
|
||||
$(NULL)
|
||||
|
||||
JAVA_LIBRARY_NAME = test_javaxpcom
|
||||
|
||||
JAVA_SRCS = \
|
||||
Foo.java \
|
||||
LocationProvider.java \
|
||||
TestINIParser.java \
|
||||
TestQI.java \
|
||||
TestVersionComparator.java \
|
||||
TestArray.java \
|
||||
TestJavaProxy.java \
|
||||
TestProps.java \
|
||||
$(NULL)
|
||||
# TestProps.java \
|
||||
# TestQI.java \
|
||||
# TestParams.java \
|
||||
|
||||
DIRS += dll
|
||||
|
||||
ifneq (,$(filter WINNT OS2,$(OS_ARCH)))
|
||||
SEP = \;
|
||||
else
|
||||
SEP = :
|
||||
endif
|
||||
|
||||
_JAVA_CLASSPATH = .$(SEP)./../interfaces/MozillaInterfaces.jar$(SEP)$(XPIDL_GEN_DIR)
|
||||
|
||||
GARBAGE += *.class $(REBUILD_JAR)
|
||||
JAVA_CLASSPATH = \
|
||||
../interfaces/MozillaInterfaces.jar \
|
||||
../interfaces/MozillaGlue.jar \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
%.class: %.java Makefile Makefile.in
|
||||
$(REPORT_BUILD)
|
||||
$(ELOG) $(CYGWIN_WRAPPER) $(JAVAC) $(JAVAC_FLAGS) \
|
||||
-classpath $(_JAVA_CLASSPATH) -d . $(_VPATH_SRCS)
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
DIST_BIN = $(PWD)/$(DIST)/XUL.framework/Versions/Current
|
||||
else
|
||||
DIST_BIN = $(PWD)/$(DIST)/bin
|
||||
endif
|
||||
|
||||
libs:: $(JAVA_SRCS:.java=.class)
|
||||
check::
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestINIParser
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestQI $(DIST_BIN)
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestVersionComparator
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestArray $(DIST_BIN)
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestProps $(DIST_BIN)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* 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) 2006
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* IBM Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -35,15 +35,15 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Properties;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
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;
|
||||
import org.mozilla.interfaces.nsIComponentManager;
|
||||
import org.mozilla.interfaces.nsIMutableArray;
|
||||
import org.mozilla.interfaces.nsIServiceManager;
|
||||
import org.mozilla.interfaces.nsISupports;
|
||||
|
||||
/**
|
||||
* Adapted from xpcom/tests/TestArray.cpp
|
||||
|
@ -68,208 +68,304 @@ import org.mozilla.xpcom.nsISupports;
|
|||
*/
|
||||
|
||||
public class TestArray {
|
||||
public static final String NS_ARRAY_CONTRACTID = "@mozilla.org/array;1";
|
||||
|
||||
public static void main(String [] args) {
|
||||
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");
|
||||
public static final String NS_ARRAY_CONTRACTID = "@mozilla.org/array;1";
|
||||
|
||||
nsIComponentManager componentManager = Moz.getComponentManager();
|
||||
nsIMutableArray array = (nsIMutableArray)
|
||||
componentManager.createInstanceByContractID(NS_ARRAY_CONTRACTID,
|
||||
null, nsIMutableArray.NS_IMUTABLEARRAY_IID);
|
||||
if (array == null) {
|
||||
throw new RuntimeException("Failed to create nsIMutableArray.");
|
||||
}
|
||||
private static File grePath;
|
||||
|
||||
fillArray(array, 10);
|
||||
System.out.println("Array created:");
|
||||
int fillResult[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
dumpArray(array, 10, fillResult, 10);
|
||||
/**
|
||||
* @param args 0 - full path to XULRunner binary directory
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
checkArgs(args);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// test insert
|
||||
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};
|
||||
dumpArray(array, 11, insertResult, 10);
|
||||
System.out.println("insert 3 at 0:");
|
||||
array.insertElementAt(foo, 0, false);
|
||||
int insertResult2[] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
|
||||
dumpArray(array, 12, insertResult2, 10);
|
||||
System.out.println("append 3:");
|
||||
array.appendElement(foo, false);
|
||||
int appendResult[] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 3};
|
||||
dumpArray(array, 13, appendResult, 10);
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
mozilla.initialize(grePath);
|
||||
|
||||
// test IndexOf && LastIndexOf
|
||||
int expectedIndex[] = {0, 4, 6, 12, -1};
|
||||
int count = 0;
|
||||
long index = array.indexOf(0, foo);
|
||||
System.out.println("IndexOf(foo): " + index + "=" + expectedIndex[count] +
|
||||
" " + assertEqual(index, expectedIndex[count]));
|
||||
try {
|
||||
do {
|
||||
count++;
|
||||
index = array.indexOf(index + 1, foo);
|
||||
System.out.println("IndexOf(foo): " + index + "=" +
|
||||
expectedIndex[count] + " " +
|
||||
assertEqual(index, expectedIndex[count]));
|
||||
} while (true);
|
||||
} catch (XPCOMException e) {
|
||||
// If array.indexOf() did not find the element, it returns
|
||||
// NS_ERROR_FAILURE.
|
||||
if (e.errorcode != Mozilla.NS_ERROR_FAILURE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
File profile = null;
|
||||
nsIServiceManager servMgr = null;
|
||||
try {
|
||||
profile = createTempProfileDir();
|
||||
LocationProvider locProvider = new LocationProvider(grePath,
|
||||
profile);
|
||||
servMgr = mozilla.initXPCOM(grePath, locProvider);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
index = lastIndexOf(array, foo);
|
||||
count--;
|
||||
System.out.println("LastIndexOf(foo): " + index + "=" +
|
||||
expectedIndex[count] + " " +
|
||||
assertEqual(index, expectedIndex[count]));
|
||||
System.out.println("\n--> initialized\n");
|
||||
|
||||
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);
|
||||
try {
|
||||
runTest();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
System.gc();
|
||||
|
||||
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);
|
||||
// cleanup
|
||||
mozilla.shutdownXPCOM(servMgr);
|
||||
deleteDir(profile);
|
||||
|
||||
// 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);
|
||||
dumpArray(array, 4, fillResult, 4);
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
|
||||
// test deleting of array
|
||||
System.out.println("release array:");
|
||||
array = null;
|
||||
System.gc();
|
||||
dumpArray(array, 0, null, 0);
|
||||
private static void checkArgs(String[] args) {
|
||||
if (args.length != 1) {
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
componentManager = null;
|
||||
System.gc();
|
||||
Moz.shutdownXPCOM(null);
|
||||
grePath = new File(args[0]);
|
||||
if (!grePath.exists() || !grePath.isDirectory()) {
|
||||
System.err.println("ERROR: given path doesn't exist");
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
private static void printUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
static void fillArray(nsIMutableArray aArray, int aCount)
|
||||
{
|
||||
for (int index = 0; index < aCount; index++) {
|
||||
nsISupports foo = new Foo(index);
|
||||
aArray.appendElement(foo, false);
|
||||
}
|
||||
}
|
||||
private static File createTempProfileDir() throws IOException {
|
||||
// Get name of temporary profile directory
|
||||
File profile = File.createTempFile("mozilla-test-", null);
|
||||
profile.delete();
|
||||
|
||||
static String assertEqual(long aValue1, long aValue2)
|
||||
{
|
||||
if (aValue1 == aValue2)
|
||||
return "OK";
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
static void dumpArray(nsIMutableArray aArray, int aExpectedCount,
|
||||
int[] aElementIDs, int aExpectedTotal)
|
||||
{
|
||||
long count = 0;
|
||||
if (aArray != null)
|
||||
count = aArray.getLength();
|
||||
// On some operating systems (particularly Windows), the previous
|
||||
// temporary profile may not have been deleted. Delete them now.
|
||||
File[] files = profile.getParentFile()
|
||||
.listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.getName().startsWith("mozilla-test-")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
|
||||
System.out.println("object count " + Foo.gCount + " = " + aExpectedTotal +
|
||||
" " + assertEqual(Foo.gCount, aExpectedTotal));
|
||||
System.out.println("array count " + count + " = " + aExpectedCount + " " +
|
||||
assertEqual(count, aExpectedCount));
|
||||
// Create temporary profile directory
|
||||
profile.mkdir();
|
||||
|
||||
for (int index = 0; (index < count) && (index < aExpectedCount); index++) {
|
||||
Foo foo = (Foo) aArray.queryElementAt(index, nsISupports.NS_ISUPPORTS_IID);
|
||||
System.out.println(index + ": " + aElementIDs[index] + "=" +
|
||||
foo.getId() + " (" +
|
||||
Integer.toHexString(foo.hashCode()) + ") " +
|
||||
assertEqual(foo.getId(), aElementIDs[index]));
|
||||
foo = null;
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
static long lastIndexOf(nsIMutableArray aArray, nsISupports aElement)
|
||||
{
|
||||
for (long i = aArray.getLength() - 1; i >= 0; i--) {
|
||||
Foo foo = (Foo) aArray.queryElementAt(i, nsISupports.NS_ISUPPORTS_IID);
|
||||
if (foo == aElement)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private static void deleteDir(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDirectory()) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
files[i].delete();
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
static void replaceElementAt(nsIMutableArray aArray, nsISupports aElement,
|
||||
int aIndex)
|
||||
{
|
||||
aArray.removeElementAt(aIndex);
|
||||
aArray.insertElementAt(aElement, aIndex, false);
|
||||
}
|
||||
private static void runTest() {
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
nsIComponentManager componentManager = mozilla.getComponentManager();
|
||||
nsIMutableArray array = (nsIMutableArray) componentManager
|
||||
.createInstanceByContractID(NS_ARRAY_CONTRACTID, null,
|
||||
nsIMutableArray.NS_IMUTABLEARRAY_IID);
|
||||
if (array == null) {
|
||||
throw new RuntimeException("Failed to create nsIMutableArray.");
|
||||
}
|
||||
|
||||
/* Removes first instance of given element */
|
||||
static void removeElement(nsIMutableArray aArray, nsISupports aElement)
|
||||
{
|
||||
long index = aArray.indexOf(0, aElement);
|
||||
aArray.removeElementAt(index);
|
||||
}
|
||||
fillArray(array, 10);
|
||||
System.out.println("Array created:");
|
||||
int fillResult[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
dumpArray(array, 10, fillResult, 10);
|
||||
|
||||
static void removeLastElement(nsIMutableArray aArray, nsISupports aElement)
|
||||
{
|
||||
long index = lastIndexOf(aArray, aElement);
|
||||
aArray.removeElementAt(index);
|
||||
}
|
||||
// test insert
|
||||
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};
|
||||
dumpArray(array, 11, insertResult, 10);
|
||||
System.out.println("insert 3 at 0:");
|
||||
array.insertElementAt(foo, 0, false);
|
||||
int insertResult2[] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
|
||||
dumpArray(array, 12, insertResult2, 10);
|
||||
System.out.println("append 3:");
|
||||
array.appendElement(foo, false);
|
||||
int appendResult[] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 3};
|
||||
dumpArray(array, 13, appendResult, 10);
|
||||
|
||||
// test IndexOf && LastIndexOf
|
||||
int expectedIndex[] = {0, 4, 6, 12, -1};
|
||||
int count = 0;
|
||||
long index = array.indexOf(0, foo);
|
||||
System.out.println("IndexOf(foo): " + index + "=" + expectedIndex[count] +
|
||||
" " + assertEqual(index, expectedIndex[count]));
|
||||
try {
|
||||
do {
|
||||
count++;
|
||||
index = array.indexOf(index + 1, foo);
|
||||
System.out.println("IndexOf(foo): " + index + "=" +
|
||||
expectedIndex[count] + " " +
|
||||
assertEqual(index, expectedIndex[count]));
|
||||
} while (true);
|
||||
} catch (XPCOMException e) {
|
||||
// If array.indexOf() did not find the element, it returns
|
||||
// NS_ERROR_FAILURE.
|
||||
if (e.errorcode != Mozilla.NS_ERROR_FAILURE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
index = lastIndexOf(array, foo);
|
||||
count--;
|
||||
System.out.println("LastIndexOf(foo): " + index + "=" +
|
||||
expectedIndex[count] + " " +
|
||||
assertEqual(index, expectedIndex[count]));
|
||||
|
||||
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);
|
||||
dumpArray(array, 4, fillResult, 4);
|
||||
|
||||
// test deleting of array
|
||||
System.out.println("release array:");
|
||||
array = null;
|
||||
System.gc();
|
||||
dumpArray(array, 0, null, 0);
|
||||
|
||||
componentManager = null;
|
||||
}
|
||||
|
||||
static void fillArray(nsIMutableArray aArray, int aCount) {
|
||||
for (int index = 0; index < aCount; index++) {
|
||||
nsISupports foo = new Foo(index);
|
||||
aArray.appendElement(foo, false);
|
||||
}
|
||||
}
|
||||
|
||||
static String assertEqual(long aValue1, long aValue2) {
|
||||
if (aValue1 == aValue2)
|
||||
return "OK";
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
static void dumpArray(nsIMutableArray aArray, int aExpectedCount,
|
||||
int[] aElementIDs, int aExpectedTotal) {
|
||||
long count = 0;
|
||||
if (aArray != null)
|
||||
count = aArray.getLength();
|
||||
|
||||
System.out.println("object count " + Foo.gCount + " = " + aExpectedTotal +
|
||||
" " + assertEqual(Foo.gCount, aExpectedTotal));
|
||||
System.out.println("array count " + count + " = " + aExpectedCount + " " +
|
||||
assertEqual(count, aExpectedCount));
|
||||
|
||||
for (int index = 0; (index < count) && (index < aExpectedCount); index++) {
|
||||
Foo foo = (Foo) aArray.queryElementAt(index, nsISupports.NS_ISUPPORTS_IID);
|
||||
System.out.println(index + ": " + aElementIDs[index] + "=" +
|
||||
foo.getId() + " (" +
|
||||
Integer.toHexString(foo.hashCode()) + ") " +
|
||||
assertEqual(foo.getId(), aElementIDs[index]));
|
||||
foo = null;
|
||||
}
|
||||
}
|
||||
|
||||
static long lastIndexOf(nsIMutableArray aArray, nsISupports aElement) {
|
||||
for (long i = aArray.getLength() - 1; i >= 0; i--) {
|
||||
Foo foo = (Foo) aArray.queryElementAt(i, nsISupports.NS_ISUPPORTS_IID);
|
||||
if (foo == aElement)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void replaceElementAt(nsIMutableArray aArray, nsISupports aElement,
|
||||
int aIndex) {
|
||||
aArray.removeElementAt(aIndex);
|
||||
aArray.insertElementAt(aElement, aIndex, false);
|
||||
}
|
||||
|
||||
/* Removes first instance of given element */
|
||||
static void removeElement(nsIMutableArray aArray, nsISupports aElement) {
|
||||
long index = aArray.indexOf(0, aElement);
|
||||
aArray.removeElementAt(index);
|
||||
}
|
||||
|
||||
static void removeLastElement(nsIMutableArray aArray, nsISupports aElement) {
|
||||
long index = lastIndexOf(aArray, aElement);
|
||||
aArray.removeElementAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
class Foo implements nsISupports {
|
||||
|
||||
static int gCount;
|
||||
int mID;
|
||||
|
||||
public Foo(int aID)
|
||||
{
|
||||
mID = aID;
|
||||
++gCount;
|
||||
System.out.println("init: " + mID + " (" +
|
||||
Integer.toHexString(this.hashCode()) + "), " +
|
||||
gCount +" total");
|
||||
}
|
||||
|
||||
// nsISupports implementation
|
||||
public nsISupports queryInterface(String aIID)
|
||||
{
|
||||
return Mozilla.queryInterface(this, aIID);
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
--gCount;
|
||||
System.out.println("destruct: " + mID + " (" +
|
||||
Integer.toHexString(this.hashCode()) + "), " +
|
||||
gCount +" remain");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* 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) 2006
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* IBM Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -40,10 +40,10 @@ 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;
|
||||
import org.mozilla.interfaces.nsIFile;
|
||||
import org.mozilla.interfaces.nsILocalFile;
|
||||
import org.mozilla.interfaces.nsISimpleEnumerator;
|
||||
import org.mozilla.interfaces.nsISupports;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) 2007
|
||||
* IBM Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -35,9 +34,17 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.mozilla.xpcom.Mozilla;
|
||||
import org.mozilla.interfaces.nsIComponentManager;
|
||||
import org.mozilla.interfaces.nsILocalFile;
|
||||
import org.mozilla.interfaces.nsIProperties;
|
||||
import org.mozilla.interfaces.nsIServiceManager;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -47,83 +54,174 @@ import java.util.*;
|
|||
*/
|
||||
|
||||
public class TestProps {
|
||||
public static final String NS_PROPERTIES_CONTRACTID = "@mozilla.org/properties;1";
|
||||
|
||||
public static void main(String [] args) throws Exception {
|
||||
System.loadLibrary("javaxpcom");
|
||||
public static final String NS_PROPERTIES_CONTRACTID =
|
||||
"@mozilla.org/properties;1";
|
||||
|
||||
String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME");
|
||||
if (mozillaPath == null) {
|
||||
throw new RuntimeException("MOZILLA_FIVE_HOME system property not set.");
|
||||
}
|
||||
private static File grePath;
|
||||
|
||||
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);
|
||||
/**
|
||||
* @param args 0 - full path to XULRunner binary directory
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
checkArgs(args);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
nsIComponentManager componentManager = XPCOM.getComponentManager();
|
||||
nsIProperties props = (nsIProperties)
|
||||
componentManager.createInstanceByContractID(NS_PROPERTIES_CONTRACTID, null,
|
||||
nsIProperties.NS_IPROPERTIES_IID);
|
||||
if (props == null) {
|
||||
throw new RuntimeException("Failed to create nsIProperties.");
|
||||
}
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
mozilla.initialize(grePath);
|
||||
|
||||
// create the nsISupports objects we will use
|
||||
nsILocalFile localFile1 = XPCOM.newLocalFile("/user/local/share", false);
|
||||
nsILocalFile localFile2 = XPCOM.newLocalFile("/home/foo", false);
|
||||
nsILocalFile localFile3 = XPCOM.newLocalFile("/home/foo/bar", false);
|
||||
File profile = null;
|
||||
nsIServiceManager servMgr = null;
|
||||
try {
|
||||
profile = createTempProfileDir();
|
||||
LocationProvider locProvider = new LocationProvider(grePath,
|
||||
profile);
|
||||
servMgr = mozilla.initXPCOM(grePath, locProvider);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// set the properties and associate with the created objects
|
||||
props.set("File One", localFile1);
|
||||
props.set("File Two", localFile2);
|
||||
props.set("File One Repeated", localFile1);
|
||||
props.set("File Three", localFile3);
|
||||
try {
|
||||
runTest();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// test the "has" method
|
||||
boolean hasProp = props.has("File One");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException("Could not find property 'File One'.");
|
||||
hasProp = props.has("File One Repeated");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException("Could not find property 'File One Repeated'.");
|
||||
hasProp = props.has("Nonexistant Property");
|
||||
if (hasProp == true)
|
||||
throw new Exception("Found property that doesn't exist.");
|
||||
System.out.println("Test Passed.");
|
||||
|
||||
// test the "get" method
|
||||
nsILocalFile tempLocalFile = (nsILocalFile) props.get("File One Repeated",
|
||||
nsILocalFile.NS_ILOCALFILE_IID);
|
||||
if (tempLocalFile == null)
|
||||
throw new NoSuchElementException("Property 'File One Repeated' not found.");
|
||||
if (tempLocalFile != localFile1)
|
||||
throw new Exception("Object returned by 'get' not the same as object passed to 'set'.");
|
||||
// cleanup
|
||||
mozilla.shutdownXPCOM(servMgr);
|
||||
deleteDir(profile);
|
||||
}
|
||||
|
||||
// test the "undefine" method
|
||||
hasProp = props.has("File Two");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException();
|
||||
props.undefine("File Two");
|
||||
hasProp = props.has("File Two");
|
||||
if (hasProp == true)
|
||||
throw new NoSuchElementException();
|
||||
private static void checkArgs(String[] args) {
|
||||
if (args.length != 1) {
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
// test the "getKeys" method
|
||||
long[] count = new long[1];
|
||||
String[] keys = props.getKeys(count);
|
||||
if (keys == null || keys.length != 3) {
|
||||
System.out.println("getKeys returned incorrect array.");
|
||||
}
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
System.out.println("key " + i + ": " + keys[i]);
|
||||
}
|
||||
grePath = new File(args[0]);
|
||||
if (!grePath.exists() || !grePath.isDirectory()) {
|
||||
System.err.println("ERROR: given path doesn't exist");
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
XPCOM.shutdownXPCOM(null);
|
||||
// GeckoEmbed.termEmbedding();
|
||||
private static void printUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
private static File createTempProfileDir() throws IOException {
|
||||
// Get name of temporary profile directory
|
||||
File profile = File.createTempFile("mozilla-test-", null);
|
||||
profile.delete();
|
||||
|
||||
// On some operating systems (particularly Windows), the previous
|
||||
// temporary profile may not have been deleted. Delete them now.
|
||||
File[] files = profile.getParentFile()
|
||||
.listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.getName().startsWith("mozilla-test-")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
|
||||
// Create temporary profile directory
|
||||
profile.mkdir();
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static void deleteDir(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDirectory()) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
files[i].delete();
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
private static void runTest() throws Exception {
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
nsIComponentManager componentManager = mozilla.getComponentManager();
|
||||
nsIProperties props = (nsIProperties) componentManager
|
||||
.createInstanceByContractID(NS_PROPERTIES_CONTRACTID, null,
|
||||
nsIProperties.NS_IPROPERTIES_IID);
|
||||
if (props == null) {
|
||||
throw new RuntimeException("Failed to create nsIProperties.");
|
||||
}
|
||||
|
||||
// create the nsISupports objects we will use
|
||||
nsILocalFile localFile1 = mozilla.newLocalFile("/user/local/share",
|
||||
false);
|
||||
nsILocalFile localFile2 = mozilla.newLocalFile("/home/foo", false);
|
||||
nsILocalFile localFile3 = mozilla.newLocalFile("/home/foo/bar", false);
|
||||
|
||||
// set the properties and associate with the created objects
|
||||
props.set("File One", localFile1);
|
||||
props.set("File Two", localFile2);
|
||||
props.set("File One Repeated", localFile1);
|
||||
props.set("File Three", localFile3);
|
||||
|
||||
// test the "has" method
|
||||
boolean hasProp = props.has("File One");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException("Could not find property " +
|
||||
"'File One'.");
|
||||
hasProp = props.has("File One Repeated");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException("Could not find property " +
|
||||
"'File One Repeated'.");
|
||||
hasProp = props.has("Nonexistant Property");
|
||||
if (hasProp == true)
|
||||
throw new Exception("Found property that doesn't exist.");
|
||||
|
||||
// test the "get" method
|
||||
nsILocalFile tempLocalFile = (nsILocalFile) props
|
||||
.get("File One Repeated", nsILocalFile.NS_ILOCALFILE_IID);
|
||||
if (tempLocalFile == null)
|
||||
throw new NoSuchElementException("Property 'File One Repeated' " +
|
||||
"not found.");
|
||||
if (tempLocalFile != localFile1)
|
||||
throw new Exception("Object returned by 'get' not the same as " +
|
||||
"object passed to 'set'.");
|
||||
|
||||
// test the "undefine" method
|
||||
hasProp = props.has("File Two");
|
||||
if (hasProp == false)
|
||||
throw new NoSuchElementException();
|
||||
props.undefine("File Two");
|
||||
hasProp = props.has("File Two");
|
||||
if (hasProp == true)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
// test the "getKeys" method
|
||||
long[] count = new long[1];
|
||||
String[] propKeys = props.getKeys(count);
|
||||
if (propKeys == null || propKeys.length != 3) {
|
||||
System.out.println("getKeys returned incorrect array.");
|
||||
}
|
||||
Vector activeKeys = new Vector(3);
|
||||
activeKeys.add("File One");
|
||||
activeKeys.add("File One Repeated");
|
||||
activeKeys.add("File Three");
|
||||
for (int i = 0; i < propKeys.length; i++) {
|
||||
if (!activeKeys.remove(propKeys[i])) {
|
||||
throw new RuntimeException("Found unknown key.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) 2007
|
||||
* IBM Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -35,9 +34,17 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.mozilla.xpcom.Mozilla;
|
||||
import org.mozilla.interfaces.nsIFile;
|
||||
import org.mozilla.interfaces.nsIFileURL;
|
||||
import org.mozilla.interfaces.nsIServiceManager;
|
||||
import org.mozilla.interfaces.nsISupports;
|
||||
import org.mozilla.interfaces.nsIURI;
|
||||
import org.mozilla.interfaces.nsIURL;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -50,46 +57,130 @@ import java.util.*;
|
|||
|
||||
public class TestQI {
|
||||
|
||||
public static void main(String [] args) throws Exception {
|
||||
System.loadLibrary("javaxpcom");
|
||||
private static File grePath;
|
||||
|
||||
String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME");
|
||||
if (mozillaPath == null) {
|
||||
throw new RuntimeException("MOZILLA_FIVE_HOME system property not set.");
|
||||
}
|
||||
/**
|
||||
* @param args 0 - full path to XULRunner binary directory
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
checkArgs(args);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
File localFile = new File(mozillaPath);
|
||||
XPCOM.initXPCOM(localFile, null);
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
mozilla.initialize(grePath);
|
||||
|
||||
FooFile foo = new FooFile();
|
||||
File profile = null;
|
||||
nsIServiceManager servMgr = null;
|
||||
try {
|
||||
profile = createTempProfileDir();
|
||||
LocationProvider locProvider = new LocationProvider(grePath,
|
||||
profile);
|
||||
servMgr = mozilla.initXPCOM(grePath, locProvider);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
nsIFileURL fileURL = (nsIFileURL) foo.queryInterface(nsIFileURL.NS_IFILEURL_IID);
|
||||
if (fileURL == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIFileURL.");
|
||||
}
|
||||
try {
|
||||
runTest();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
nsIURL url = (nsIURL) foo.queryInterface(nsIURL.NS_IURL_IID);
|
||||
if (url == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIURL.");
|
||||
}
|
||||
System.out.println("Test Passed.");
|
||||
|
||||
nsIURI uri = (nsIURI) foo.queryInterface(nsIURI.NS_IURI_IID);
|
||||
if (uri == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIURI.");
|
||||
}
|
||||
// cleanup
|
||||
mozilla.shutdownXPCOM(servMgr);
|
||||
deleteDir(profile);
|
||||
}
|
||||
|
||||
nsISupports supp = (nsISupports) foo.queryInterface(nsISupports.NS_ISUPPORTS_IID);
|
||||
if (supp == null) {
|
||||
throw new RuntimeException("Failed to QI to nsISupports.");
|
||||
}
|
||||
private static void runTest() {
|
||||
FooFile foo = new FooFile();
|
||||
|
||||
XPCOM.shutdownXPCOM(null);
|
||||
nsIFileURL fileURL = (nsIFileURL) foo
|
||||
.queryInterface(nsIFileURL.NS_IFILEURL_IID);
|
||||
if (fileURL == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIFileURL.");
|
||||
}
|
||||
|
||||
nsIURL url = (nsIURL) foo.queryInterface(nsIURL.NS_IURL_IID);
|
||||
if (url == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIURL.");
|
||||
}
|
||||
|
||||
nsIURI uri = (nsIURI) foo.queryInterface(nsIURI.NS_IURI_IID);
|
||||
if (uri == null) {
|
||||
throw new RuntimeException("Failed to QI to nsIURI.");
|
||||
}
|
||||
|
||||
nsISupports supp = (nsISupports) foo
|
||||
.queryInterface(nsISupports.NS_ISUPPORTS_IID);
|
||||
if (supp == null) {
|
||||
throw new RuntimeException("Failed to QI to nsISupports.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkArgs(String[] args) {
|
||||
if (args.length != 1) {
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
grePath = new File(args[0]);
|
||||
if (!grePath.exists() || !grePath.isDirectory()) {
|
||||
System.err.println("ERROR: given path doesn't exist");
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
private static File createTempProfileDir() throws IOException {
|
||||
// Get name of temporary profile directory
|
||||
File profile = File.createTempFile("mozilla-test-", null);
|
||||
profile.delete();
|
||||
|
||||
// On some operating systems (particularly Windows), the previous
|
||||
// temporary profile may not have been deleted. Delete them now.
|
||||
File[] files = profile.getParentFile()
|
||||
.listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.getName().startsWith("mozilla-test-")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
|
||||
// Create temporary profile directory
|
||||
profile.mkdir();
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static void deleteDir(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDirectory()) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
files[i].delete();
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dummy class that implements nsIFileUrl. The inheritance chain for
|
||||
* nsIFileURL is as follows:
|
||||
|
@ -105,9 +196,9 @@ public class TestQI {
|
|||
*/
|
||||
class FooFile implements nsIFileURL {
|
||||
|
||||
public nsISupports queryInterface(String aIID) {
|
||||
return XPCOM.queryInterface(this, aIID);
|
||||
}
|
||||
public nsISupports queryInterface(String aIID) {
|
||||
return Mozilla.queryInterface(this, aIID);
|
||||
}
|
||||
|
||||
public nsIFile getFile() {
|
||||
return null;
|
||||
|
@ -247,7 +338,7 @@ class FooFile implements nsIFileURL {
|
|||
public void setPath(String aPath) {
|
||||
}
|
||||
|
||||
public boolean equals(nsIURI other) {
|
||||
public boolean _equals(nsIURI other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -255,7 +346,7 @@ class FooFile implements nsIFileURL {
|
|||
return false;
|
||||
}
|
||||
|
||||
public nsIURI clone_() {
|
||||
public nsIURI _clone() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -275,4 +366,3 @@ class FooFile implements nsIFileURL {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
# ***** 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) 2007
|
||||
# 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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = test_jxtestparams
|
||||
|
||||
# This module makes use of the interfaces from the XPConnect tests.
|
||||
# Make sure they have been built.
|
||||
DIRS = $(DEPTH)/js/src/xpconnect/tests/idl
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIJXTestParams.idl \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
nsJXTestParams.js \
|
||||
xpctests.js \
|
||||
$(NULL)
|
||||
|
||||
JAVA_LIBRARY_NAME = test_jxtestparams
|
||||
|
||||
JAVA_SRCS = \
|
||||
TestParams.java \
|
||||
$(NULL)
|
||||
|
||||
JAVA_CLASSPATH = \
|
||||
../../interfaces/MozillaInterfaces.jar \
|
||||
../../interfaces/MozillaGlue.jar \
|
||||
$(NULL)
|
||||
|
||||
JAVA_SOURCEPATH = $(srcdir)/.. # to pick up LocationProvider.java
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH),Darwin)
|
||||
DIST_BIN = $(PWD)/$(DIST)/XUL.framework/Versions/Current
|
||||
else
|
||||
DIST_BIN = $(PWD)/$(DIST)/bin
|
||||
endif
|
||||
|
||||
check::
|
||||
$(CYGWIN_WRAPPER) $(JAVA) -classpath $(_JAVA_CLASSPATH)$(SEP)$(JAVA_LIBRARY) \
|
||||
TestParams $(DIST_BIN)
|
|
@ -0,0 +1,787 @@
|
|||
/* ***** 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) 2007
|
||||
* 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 ***** */
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.mozilla.xpcom.Mozilla;
|
||||
import org.mozilla.xpcom.XPCOMException;
|
||||
import org.mozilla.interfaces.nsIEcho;
|
||||
import org.mozilla.interfaces.nsIJXTestParams;
|
||||
import org.mozilla.interfaces.nsIStackFrame;
|
||||
import org.mozilla.interfaces.nsISupports;
|
||||
import org.mozilla.interfaces.nsITestXPCFunctionCallback;
|
||||
import org.mozilla.interfaces.nsITestXPCSomeUselessThing;
|
||||
import org.mozilla.interfaces.nsIXPCTestIn;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the marshalling and unmarshalling of method parameters using the
|
||||
* XPConnect testcases from mozilla/js/src/xpconnect/tests.
|
||||
*/
|
||||
public class TestParams {
|
||||
|
||||
private static File grePath;
|
||||
|
||||
private static String testString = "this is a test string";
|
||||
private static String emptyString = "";
|
||||
private static String utf8String =
|
||||
"Non-Ascii 1 byte chars: Ž‰ŠˆŒ<CB86>, 2 byte chars: \u1234 \u1235 \u1236";
|
||||
//private static String sharedString = "a shared string";
|
||||
|
||||
|
||||
/**
|
||||
* @param args 0 - full path to XULRunner binary directory
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
checkArgs(args);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
Mozilla mozilla = Mozilla.getInstance();
|
||||
mozilla.initialize(grePath);
|
||||
|
||||
File profile = null;
|
||||
try {
|
||||
profile = createTempProfileDir();
|
||||
LocationProvider locProvider = new LocationProvider(grePath,
|
||||
profile);
|
||||
mozilla.initEmbedding(grePath, grePath, locProvider);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
try {
|
||||
runEchoTests();
|
||||
|
||||
runInTests();
|
||||
} catch (RunTestsException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
nsIJXTestParams jstest = (nsIJXTestParams) Mozilla.getInstance()
|
||||
.getComponentManager()
|
||||
.createInstanceByContractID("@mozilla.org/javaxpcom/tests/params;1",
|
||||
null, nsIJXTestParams.NS_IJXTESTPARAMS_IID);
|
||||
try {
|
||||
jstest.runTests(new JavaTests());
|
||||
} catch (XPCOMException e) {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// cleanup
|
||||
mozilla.termEmbedding();
|
||||
deleteDir(profile);
|
||||
}
|
||||
|
||||
private static void checkArgs(String[] args) {
|
||||
if (args.length != 1) {
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
grePath = new File(args[0]);
|
||||
if (!grePath.exists() || !grePath.isDirectory()) {
|
||||
System.err.println("ERROR: given path doesn't exist");
|
||||
printUsage();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printUsage() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
private static File createTempProfileDir() throws IOException {
|
||||
// Get name of temporary profile directory
|
||||
File profile = File.createTempFile("mozilla-test-", null);
|
||||
profile.delete();
|
||||
|
||||
// On some operating systems (particularly Windows), the previous
|
||||
// temporary profile may not have been deleted. Delete them now.
|
||||
File[] files = profile.getParentFile()
|
||||
.listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.getName().startsWith("mozilla-test-")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
|
||||
// Create temporary profile directory
|
||||
profile.mkdir();
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static void deleteDir(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDirectory()) {
|
||||
deleteDir(files[i]);
|
||||
}
|
||||
files[i].delete();
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aCallee
|
||||
* @param aTests An array of tests to run. The format looks like this:
|
||||
* index 0: method name of test to run
|
||||
* 1: Object array of method arguments
|
||||
* 2: expected result
|
||||
* 3: comment to use when logging test result; if
|
||||
* <code>null</code>, uses method name
|
||||
* @throws RunTestsException if any of the tests fails
|
||||
*/
|
||||
private static void runTestsArray(Object aCallee, Object[][] aTests)
|
||||
throws RunTestsException {
|
||||
boolean succeeded = true;
|
||||
for (int i = 0; i < aTests.length; i++) {
|
||||
Method method = getMethod(aCallee.getClass(), (String) aTests[i][0]);
|
||||
|
||||
String comment = (aTests[i][3] != null) ? (String) aTests[i][3] :
|
||||
(String) aTests[i][0];
|
||||
|
||||
Object result = null;
|
||||
boolean passed = false;
|
||||
try {
|
||||
result = method.invoke(aCallee, (Object[]) aTests[i][1]);
|
||||
if (result != null) {
|
||||
passed = (result.equals(aTests[i][2]));
|
||||
} else {
|
||||
passed = (result == aTests[i][2]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
succeeded = false;
|
||||
System.err.println("*** TEST " + comment + " threw exception:");
|
||||
e.printStackTrace();
|
||||
logResult(comment, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
logResult(comment, passed);
|
||||
|
||||
if (!passed) {
|
||||
succeeded = false;
|
||||
System.err.println("*** TEST " + comment + " FAILED: expected "
|
||||
+ aTests[i][2] + ", returned " + result);
|
||||
}
|
||||
}
|
||||
|
||||
if (!succeeded) {
|
||||
throw new RunTestsException();
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getMethod(Class aClass, String aMethodName) {
|
||||
Method[] methods = aClass.getMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (methods[i].getName().equals(aMethodName)) {
|
||||
return methods[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void logResult(String comment, boolean passed) {
|
||||
System.out.println(comment + "\t\t" + (passed ? "passed" : "FAILED"));
|
||||
}
|
||||
|
||||
private static void runEchoTests() throws RunTestsException {
|
||||
nsIEcho nativeEcho = (nsIEcho) Mozilla.getInstance()
|
||||
.getComponentManager()
|
||||
.createInstanceByContractID("@mozilla.org/javaxpcom/tests/xpc;1",
|
||||
null, nsIEcho.NS_IECHO_IID);
|
||||
|
||||
Object[][] tests = new Object[][] {
|
||||
/* test DOMString */
|
||||
{ "in2OutOneDOMString", new Object[] { testString }, testString,
|
||||
"in2OutOneDOMString w/ '" + testString + "'" },
|
||||
{ "in2OutOneDOMString", new Object[] { emptyString }, emptyString,
|
||||
"in2OutOneDomString w/ empty string" },
|
||||
{ "in2OutOneDOMString", new Object[] { null }, null,
|
||||
"in2OutOneDOMString w/ null value" },
|
||||
/* test AString */
|
||||
{ "in2OutOneAString", new Object[] { testString }, testString,
|
||||
"in2OutOneAString w/ '" + testString + "'" },
|
||||
{ "in2OutOneAString", new Object[] { emptyString }, emptyString,
|
||||
"in2OutOneAString w/ empty string" },
|
||||
{ "in2OutOneAString", new Object[] { utf8String }, utf8String,
|
||||
"in2OutOneAString w/ '" + utf8String + "'" },
|
||||
{ "in2OutOneAString", new Object[] { null }, null,
|
||||
"in2OutOneAString w/ null value" },
|
||||
/* test AUTF8String */
|
||||
{ "in2OutOneUTF8String", new Object[] { testString }, testString,
|
||||
"in2OutOneUTF8String w/ '" + testString + "'" },
|
||||
{ "in2OutOneUTF8String", new Object[] { emptyString }, emptyString,
|
||||
"in2OutOneUTF8String w/ empty string" },
|
||||
{ "in2OutOneUTF8String", new Object[] { utf8String }, utf8String,
|
||||
"in2OutOneUTF8String w/ '" + utf8String + "'" },
|
||||
{ "in2OutOneUTF8String", new Object[] { null }, null,
|
||||
"in2OutOneUTF8String w/ null value" },
|
||||
/* test ACString */
|
||||
{ "in2OutOneCString", new Object[] { testString }, testString,
|
||||
"in2OutOneCString w/ '" + testString + "'" },
|
||||
{ "in2OutOneCString", new Object[] { emptyString }, emptyString,
|
||||
"in2OutOneCString w/ empty string" },
|
||||
{ "in2OutOneCString", new Object[] { null }, null,
|
||||
"in2OutOneCString w/ null value" },
|
||||
/* test normal strings */
|
||||
{ "in2OutOneString", new Object[] { testString }, testString,
|
||||
"in2OutOneString w/ '" + testString + "'" },
|
||||
{ "in2OutOneString", new Object[] { emptyString }, emptyString,
|
||||
"in2OutOneString w/ empty string" }
|
||||
};
|
||||
|
||||
runTestsArray(nativeEcho, tests);
|
||||
|
||||
do {
|
||||
Object result = null;
|
||||
boolean passed = false;
|
||||
String comment = "in2OutOneString w/ null value";
|
||||
try {
|
||||
result = nativeEcho.in2OutOneString(null);
|
||||
passed = (result == null);
|
||||
} catch (Exception e) {
|
||||
// Calling nativeEcho.in2OutOneString(null) should throw an
|
||||
// exception, with errorcode == NS_ERROR_FAILURE.
|
||||
if (e instanceof XPCOMException &&
|
||||
((XPCOMException) e).errorcode == Mozilla.NS_ERROR_FAILURE) {
|
||||
passed = true;
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
System.err.println("*** TEST " + comment +
|
||||
" threw exception:");
|
||||
e.printStackTrace();
|
||||
logResult(comment, false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
logResult(comment, passed);
|
||||
|
||||
if (!passed) {
|
||||
System.err.println("*** TEST " + comment +
|
||||
" FAILED: expected null, returned " + result);
|
||||
}
|
||||
} while (false);
|
||||
|
||||
tests = new Object[][] {
|
||||
{ "setAString", new Object[] { testString }, null,
|
||||
"setAString w/ '" + testString + "'" },
|
||||
{ "getAString", null, testString,
|
||||
"getAString w/ '" + testString + "'" },
|
||||
{ "setAString", new Object[] { emptyString }, null,
|
||||
"setAString w/ empty string" },
|
||||
{ "getAString", null, emptyString,
|
||||
"getAString w/ empty string" },
|
||||
{ "setAString", new Object[] { null }, null,
|
||||
"setAString w/ null value" },
|
||||
{ "getAString", null, null,
|
||||
"getAString w/ null value" },
|
||||
/* Is the 'shared' attribute even used in scriptable functions?
|
||||
{ "sharedString", null, sharedString, null } */
|
||||
};
|
||||
|
||||
runTestsArray(nativeEcho, tests);
|
||||
}
|
||||
|
||||
private static void runInTests() throws RunTestsException {
|
||||
nsIXPCTestIn nativeInTest = (nsIXPCTestIn) Mozilla.getInstance()
|
||||
.getComponentManager()
|
||||
.createInstanceByContractID("@mozilla.org/javaxpcom/tests/xpc;1",
|
||||
null, nsIXPCTestIn.NS_IXPCTESTIN_IID);
|
||||
|
||||
/* XPConnect converts 64-bit values into doubles when calling into
|
||||
* Javascript. If we use Long.MIN_VALUE or Long.MAX_VALUE, the values
|
||||
* are rounded 'up' when converted to double. Then, when converted back
|
||||
* to a 64-bit integer, the conversion overflows, always resulting in
|
||||
* Long.MIN_VALUE. To workaround that, we just call with very large
|
||||
* values, but ones that won't overflow in conversion.
|
||||
*/
|
||||
//Object minLong = new Long(Long.MIN_VALUE);
|
||||
//Object maxLong = new Long(Long.MAX_VALUE);
|
||||
Object minLong = new Long(-9223372036854774784L);
|
||||
Object maxLong = new Long(9223372036854774784L);
|
||||
Object zeroLong = new Long(0);
|
||||
Object negLong = new Long(-1);
|
||||
Object minInt = new Integer(Integer.MIN_VALUE);
|
||||
Object maxInt = new Integer(Integer.MAX_VALUE);
|
||||
Object zeroInt = new Integer(0);
|
||||
Object negInt = new Integer(-1);
|
||||
Object maxUInt = new Long(4294967295L);
|
||||
Object minShort = new Short(Short.MIN_VALUE);
|
||||
Object maxShort = new Short(Short.MAX_VALUE);
|
||||
Object zeroShort = new Short((short) 0);
|
||||
Object negShort = new Short((short) -1);
|
||||
Object maxUShort = new Integer(65535);
|
||||
Object charA = new Character('a');
|
||||
Object charZ = new Character('Z');
|
||||
Object charWide = new Character('\u1234');
|
||||
Object maxUByte = new Short((short) 255);
|
||||
Object minFloat = new Float(Float.MIN_VALUE);
|
||||
Object maxFloat = new Float(Float.MAX_VALUE);
|
||||
Object minDouble = new Double(Double.MIN_VALUE);
|
||||
Object maxDouble = new Double(Double.MAX_VALUE);
|
||||
|
||||
Object[][] tests = new Object[][] {
|
||||
{ "echoLong", new Object[] { minInt }, minInt,
|
||||
"echoLong w/ " + minInt },
|
||||
{ "echoLong", new Object[] { maxInt }, maxInt,
|
||||
"echoLong w/ " + maxInt },
|
||||
{ "echoShort", new Object[] { minShort }, minShort,
|
||||
"echoShort w/ " + minShort },
|
||||
{ "echoShort", new Object[] { maxShort }, maxShort,
|
||||
"echoShort w/ " + maxShort },
|
||||
{ "echoChar", new Object[] { charA }, charA,
|
||||
"echoChar w/ " + charA },
|
||||
{ "echoChar", new Object[] { charZ }, charZ,
|
||||
"echoChar w/ " + charZ },
|
||||
{ "echoBoolean", new Object[] { Boolean.FALSE }, Boolean.FALSE,
|
||||
"echoBoolean w/ " + Boolean.FALSE},
|
||||
{ "echoBoolean", new Object[] { Boolean.TRUE }, Boolean.TRUE,
|
||||
"echoBoolean w/ " + Boolean.TRUE },
|
||||
/* XXX bug 367793
|
||||
{ "echoOctet", new Object[] { zeroShort }, zeroShort,
|
||||
"echoOctet w/ zero"},
|
||||
{ "echoOctet", new Object[] { maxUByte }, maxUByte,
|
||||
"echoOctet w/ " + maxUByte },
|
||||
*/
|
||||
{ "echoLongLong", new Object[] { minLong }, minLong,
|
||||
"echoLongLong w/ " + minLong },
|
||||
{ "echoLongLong", new Object[] { maxLong }, maxLong,
|
||||
"echoLongLong w/ " + maxLong },
|
||||
{ "echoUnsignedShort", new Object[] { maxUShort }, maxUShort,
|
||||
"echoUnsignedShort w/ " + maxUShort },
|
||||
{ "echoUnsignedShort", new Object[] { zeroInt }, zeroInt,
|
||||
"echoUnsignedShort w/ zero" },
|
||||
// is this test case correct/valid?
|
||||
{ "echoUnsignedShort", new Object[] { negInt }, maxUShort,
|
||||
"echoUnsignedShort w/ -1" },
|
||||
{ "echoUnsignedLong", new Object[] { maxUInt }, maxUInt,
|
||||
"echoUnsignedLong w/ " + maxUInt },
|
||||
{ "echoUnsignedLong", new Object[] { zeroLong }, zeroLong,
|
||||
"echoUnsignedLong w/ zero" },
|
||||
{ "echoUnsignedLong", new Object[] { negLong }, maxUInt,
|
||||
"echoUnsignedLong w/ -1" },
|
||||
{ "echoFloat", new Object[] { minFloat }, minFloat,
|
||||
"echoFloat w/ " + minFloat },
|
||||
{ "echoFloat", new Object[] { maxFloat }, maxFloat,
|
||||
"echoFloat w/ " + maxFloat },
|
||||
{ "echoDouble", new Object[] { minDouble }, minDouble,
|
||||
"echoDouble w/ " + minDouble },
|
||||
{ "echoDouble", new Object[] { maxDouble }, maxDouble,
|
||||
"echoDouble w/ " + maxDouble },
|
||||
{ "echoWchar", new Object[] { charA }, charA,
|
||||
"echoWchar w/ " + charA },
|
||||
{ "echoWchar", new Object[] { charZ }, charZ,
|
||||
"echoWchar w/ " + charZ },
|
||||
{ "echoWchar", new Object[] { charWide }, charWide,
|
||||
"echoWchar w/ " + charWide },
|
||||
{ "echoString", new Object[] { testString }, testString,
|
||||
"echoString w/ '" + testString + "'" },
|
||||
{ "echoString", new Object[] { emptyString }, emptyString,
|
||||
"echoString w/ empty string" },
|
||||
{ "echoString", new Object[] { utf8String }, utf8String,
|
||||
"echoString w/ '" + utf8String + "'" },
|
||||
{ "echoString", new Object[] { null }, null,
|
||||
"echoString w/ null value" },
|
||||
};
|
||||
|
||||
runTestsArray(nativeInTest, tests);
|
||||
|
||||
// Max unsigned long long = 18446744073709551615UL
|
||||
Object maxULong = new Double(1.8446744073709550E19);
|
||||
Object zeroDouble = new Double(0.0);
|
||||
|
||||
tests = new Object[][] {
|
||||
{ "echoPRBool", new Object[] { Boolean.FALSE }, Boolean.FALSE,
|
||||
"echoPRBool w/ false" },
|
||||
{ "echoPRBool", new Object[] { Boolean.TRUE }, Boolean.TRUE,
|
||||
"echoPRBool w/ true" },
|
||||
{ "echoPRInt32", new Object[] { minInt }, minInt,
|
||||
"echoPRInt32 w/ " + minInt },
|
||||
{ "echoPRInt32", new Object[] { maxInt }, maxInt,
|
||||
"echoPRInt32 w/ " + maxInt },
|
||||
{ "echoPRInt16", new Object[] { minShort }, minShort,
|
||||
"echoPRInt16 w/ " + minShort },
|
||||
{ "echoPRInt16", new Object[] { maxShort }, maxShort,
|
||||
"echoPRInt16 w/ " + maxShort },
|
||||
{ "echoPRInt64", new Object[] { minLong }, minLong,
|
||||
"echoPRInt64 w/ " + minLong },
|
||||
{ "echoPRInt64", new Object[] { maxLong }, maxLong,
|
||||
"echoPRInt64 w/ " + maxLong },
|
||||
{ "echoPRUint8", new Object[] { maxUByte }, maxUByte,
|
||||
"echoPRUint8 w/ " + maxUByte },
|
||||
{ "echoPRUint8", new Object[] { zeroShort }, zeroShort,
|
||||
"echoPRUint8 w/ zero" },
|
||||
{ "echoPRUint8", new Object[] { negShort }, maxUByte,
|
||||
"echoPRUint8 w/ -1" },
|
||||
{ "echoPRUint16", new Object[] { maxUShort }, maxUShort,
|
||||
"echoPRUint16 w/ " + maxUShort },
|
||||
{ "echoPRUint16", new Object[] { zeroInt }, zeroInt,
|
||||
"echoPRUint16 w/ zero" },
|
||||
{ "echoPRUint16", new Object[] { negInt }, maxUShort,
|
||||
"echoPRUint16 w/ -1" },
|
||||
{ "echoPRUint32", new Object[] { maxUInt }, maxUInt,
|
||||
"echoPRUint32 w/ " + maxUInt },
|
||||
{ "echoPRUint32", new Object[] { zeroLong }, zeroLong,
|
||||
"echoPRUint32 w/ zero" },
|
||||
{ "echoPRUint32", new Object[] { negLong }, maxUInt,
|
||||
"echoPRUint32 w/ -1" },
|
||||
{ "echoPRUint64", new Object[] { maxULong }, maxULong,
|
||||
"echoPRUint64 w/ " + maxULong },
|
||||
{ "echoPRUint64", new Object[] { zeroDouble }, zeroDouble,
|
||||
"echoPRUint64 w/ zero" },
|
||||
/* XXX
|
||||
{ "echoPRUint64", new Object[] { negInt }, maxULong,
|
||||
"echoPRUint64 w/ -1" }, */
|
||||
};
|
||||
|
||||
runTestsArray(nativeInTest, tests);
|
||||
}
|
||||
}
|
||||
|
||||
class RunTestsException extends Exception {
|
||||
private static final long serialVersionUID = -2865653674109284035L;
|
||||
}
|
||||
|
||||
class JavaTests implements nsIEcho, nsIXPCTestIn {
|
||||
|
||||
private nsIEcho receiver;
|
||||
private String savedString;
|
||||
private Object[] results = new Object[8];
|
||||
|
||||
/* nsISupports */
|
||||
|
||||
public nsISupports queryInterface(String aIID) {
|
||||
return Mozilla.queryInterface(this, aIID);
|
||||
}
|
||||
|
||||
/* nsIEcho */
|
||||
|
||||
public void callFunction(nsITestXPCFunctionCallback callback, String s) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void callFunctionWithThis(nsITestXPCFunctionCallback callback,
|
||||
nsISupports self, String s) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void callReceiverSometimeLater() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void debugDumpJSStack() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public String echoIn2OutOneAString(String input) {
|
||||
if (receiver != null) {
|
||||
return receiver.echoIn2OutOneAString(input);
|
||||
}
|
||||
return in2OutOneAString(input);
|
||||
}
|
||||
|
||||
public String echoIn2OutOneCString(String input) {
|
||||
if (receiver != null) {
|
||||
return receiver.echoIn2OutOneCString(input);
|
||||
}
|
||||
return in2OutOneCString(input);
|
||||
}
|
||||
|
||||
public String echoIn2OutOneDOMString(String input) {
|
||||
if (receiver != null) {
|
||||
return receiver.echoIn2OutOneDOMString(input);
|
||||
}
|
||||
return in2OutOneDOMString(input);
|
||||
}
|
||||
|
||||
public String echoIn2OutOneUTF8String(String input) {
|
||||
if (receiver != null) {
|
||||
return receiver.echoIn2OutOneUTF8String(input);
|
||||
}
|
||||
return in2OutOneUTF8String(input);
|
||||
}
|
||||
|
||||
public void failInJSTest(int fail) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public String getAString() {
|
||||
return savedString;
|
||||
}
|
||||
|
||||
public int getSomeValue() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public nsIStackFrame getStack() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public short getThrowInGetter() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public int in2OutAddTwoInts(int input1, int input2, int[] output1,
|
||||
int[] output2) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public String in2OutOneAString(String input) {
|
||||
if (input != null)
|
||||
return new String(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String in2OutOneCString(String input) {
|
||||
if (input != null)
|
||||
return new String(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String in2OutOneDOMString(String input) {
|
||||
if (input != null)
|
||||
return new String(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int in2OutOneInt(int input) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public String in2OutOneString(String input) {
|
||||
if (input != null)
|
||||
return new String(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String in2OutOneUTF8String(String input) {
|
||||
if (input != null)
|
||||
return new String(input);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void methodWithForwardDeclaredParam(nsITestXPCSomeUselessThing sut) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void printArgTypes() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public nsISupports pseudoQueryInterface(String uuid) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void returnCode(int code) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void returnCode_NS_ERROR_NULL_POINTER() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void returnCode_NS_ERROR_OUT_OF_MEMORY() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void returnCode_NS_ERROR_UNEXPECTED() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void returnCode_NS_OK() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public nsISupports returnInterface(nsISupports obj) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void sendInOutManyTypes(byte[] p1, short[] p2, int[] p3, long[] p4,
|
||||
byte[] p5, int[] p6, long[] p7, double[] p8, float[] p9,
|
||||
double[] p10, boolean[] p11, char[] p12, char[] p13, String[] p14,
|
||||
String[] p15, String[] p16) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void sendManyTypes(byte p1, short p2, int p3, long p4, byte p5,
|
||||
int p6, long p7, double p8, float p9, double p10, boolean p11,
|
||||
char p12, char p13, String p14, String p15, String p16) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void sendOneString(String str) {
|
||||
if (receiver != null) {
|
||||
receiver.sendOneString(str);
|
||||
}
|
||||
results[0] = str;
|
||||
}
|
||||
|
||||
public void setAString(String aAString) {
|
||||
savedString = aAString;
|
||||
}
|
||||
|
||||
public void setReceiver(nsIEcho aReceiver) {
|
||||
System.out.println("Setting receiver to nsIEcho impl = " + aReceiver);
|
||||
receiver = aReceiver;
|
||||
}
|
||||
|
||||
public void setReceiverReturnOldReceiver(nsIEcho[] aReceiver) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void setSomeValue(int aSomeValue) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public String sharedString() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void simpleCallNoEcho() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
public void throwArg() {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/* nsIXPCTestIn */
|
||||
|
||||
public boolean echoBoolean(boolean b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
public char echoChar(char c) {
|
||||
return c;
|
||||
}
|
||||
|
||||
public double echoDouble(double d) {
|
||||
return d;
|
||||
}
|
||||
|
||||
public float echoFloat(float f) {
|
||||
return f;
|
||||
}
|
||||
|
||||
public int echoLong(int l) {
|
||||
return l;
|
||||
}
|
||||
|
||||
public long echoLongLong(long ll) {
|
||||
return ll;
|
||||
}
|
||||
|
||||
public byte echoOctet(byte o) {
|
||||
return o;
|
||||
}
|
||||
|
||||
public boolean echoPRBool(boolean b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
public short echoPRInt16(short l) {
|
||||
return l;
|
||||
}
|
||||
|
||||
public int echoPRInt32(int l) {
|
||||
return l;
|
||||
}
|
||||
|
||||
public long echoPRInt64(long i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public int echoPRUint16(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public long echoPRUint32(long i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public long echoPRUint32_2(long i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public double echoPRUint64(double i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public short echoPRUint8(short i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public short echoShort(short a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
public String echoString(String ws) {
|
||||
return ws;
|
||||
|
||||
}
|
||||
public long echoUnsignedLong(long ul) {
|
||||
return ul;
|
||||
}
|
||||
|
||||
public int echoUnsignedShort(int us) {
|
||||
return us;
|
||||
}
|
||||
|
||||
public void echoVoid() {
|
||||
}
|
||||
|
||||
public char echoWchar(char wc) {
|
||||
return wc;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/* ***** 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) 2007
|
||||
* 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(529d2d15-028e-438f-9007-b3d7ebbe132f)]
|
||||
interface nsIJXTestParams : nsISupports
|
||||
{
|
||||
void runTests(in nsISupports tests);
|
||||
};
|
|
@ -0,0 +1,341 @@
|
|||
/* ***** 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) 2007
|
||||
* 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 ***** */
|
||||
|
||||
function logResult(testname, passed) {
|
||||
dump(testname + "\t\t" + (passed ? "passed" : "FAILED") + "\n");
|
||||
}
|
||||
|
||||
function runTestsArray(callee, tests) {
|
||||
var succeeded = true;
|
||||
for (i in tests) {
|
||||
var result;
|
||||
var passed = false;
|
||||
var comment = tests[i][3] ? tests[i][3] : tests[i][0];
|
||||
|
||||
try {
|
||||
result = callee[tests[i][0]](tests[i][1]);
|
||||
passed = (result == tests[i][2] ? true : false);
|
||||
} catch (e) {
|
||||
succeeded = false;
|
||||
dump("*** TEST " + comment + " threw exception: " + e + "\n");
|
||||
logResult(comment, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
logResult(comment, passed);
|
||||
|
||||
if (!passed) {
|
||||
succeeded = false;
|
||||
dump("*** TEST " + comment + " FAILED: expected " + tests[i][2] +
|
||||
", returned " + result + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!succeeded) {
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
function runEchoTests(tests) {
|
||||
var javaEcho = tests.QueryInterface(Components.interfaces.nsIEcho);
|
||||
|
||||
var testString = "this is a test string";
|
||||
var emptyString = "";
|
||||
var utf8String =
|
||||
"Non-Ascii 1 byte chars: éâäàåç, 2 byte chars: \u1234 \u1235 \u1236";
|
||||
|
||||
var tests = new Array(
|
||||
/* test DOMString */
|
||||
[ "In2OutOneDOMString", testString, testString,
|
||||
"In2OutOneDOMString w/ '" + testString + "'"],
|
||||
[ "In2OutOneDOMString", emptyString, emptyString,
|
||||
"In2OutOneDOMString w/ empty string" ],
|
||||
[ "In2OutOneDOMString", null, null,
|
||||
"In2OutOneDOMString w/ null value" ],
|
||||
/* test AString */
|
||||
[ "In2OutOneAString", testString, testString,
|
||||
"In2OutOneAString w/ '" + testString + "'" ],
|
||||
[ "In2OutOneAString", emptyString, emptyString,
|
||||
"In2OutOneAString w/ empty string" ],
|
||||
[ "In2OutOneAString", utf8String, utf8String,
|
||||
"In2OutOneAString w/ '" + utf8String + "'" ],
|
||||
[ "In2OutOneAString", null, null,
|
||||
"In2OutOneAString w/ null value" ],
|
||||
/* test AUTF8String */
|
||||
[ "In2OutOneUTF8String", testString, testString,
|
||||
"In2OutOneUTF8String w/ '" + testString + "'" ],
|
||||
[ "In2OutOneUTF8String", emptyString, emptyString,
|
||||
"In2OutOneUTF8String w/ empty string" ],
|
||||
[ "In2OutOneUTF8String", utf8String, utf8String,
|
||||
"In2OutOneUTF8String w/ '" + utf8String + "'" ],
|
||||
[ "In2OutOneUTF8String", null, null,
|
||||
"In2OutOneUTF8String w/ null value" ],
|
||||
/* test ACString */
|
||||
[ "In2OutOneCString", testString, testString,
|
||||
"In2OutOneCString w/ '" + testString + "'" ],
|
||||
[ "In2OutOneCString", emptyString, emptyString,
|
||||
"In2OutOneCString w/ empty string" ],
|
||||
[ "In2OutOneCString", null, null,
|
||||
"In2OutOneCString w/ null value" ],
|
||||
/* test normal strings */
|
||||
[ "In2OutOneString", testString, testString,
|
||||
"In2OutOneString w/ '" + testString + "'" ],
|
||||
[ "In2OutOneString", emptyString, emptyString,
|
||||
"In2OutOneString w/ empty string" ],
|
||||
[ "In2OutOneString", null, null,
|
||||
"In2OutOneString w/ null value" ]
|
||||
);
|
||||
|
||||
runTestsArray(javaEcho, tests);
|
||||
|
||||
var passed = false;
|
||||
try {
|
||||
javaEcho.aString = testString;
|
||||
if (javaEcho.aString == testString)
|
||||
passed = true;
|
||||
} catch(e) { alert("exception: " + e); }
|
||||
logResult("set/getAString w/ '" + testString + "'", passed);
|
||||
|
||||
passed = false;
|
||||
try {
|
||||
javaEcho.aString = emptyString;
|
||||
if (javaEcho.aString == emptyString)
|
||||
passed = true;
|
||||
} catch(e) { }
|
||||
logResult("set/getAString w/ empty string", passed);
|
||||
|
||||
passed = false;
|
||||
try {
|
||||
javaEcho.aString = null;
|
||||
if (javaEcho.aString == null)
|
||||
passed = true;
|
||||
} catch(e) { }
|
||||
logResult("set/getAString w/ null value", passed);
|
||||
}
|
||||
|
||||
function runInTests(tests) {
|
||||
var javaIn = tests.QueryInterface(Components.interfaces.nsIXPCTestIn);
|
||||
|
||||
var testString = "this is a test string";
|
||||
var emptyString = "";
|
||||
var utf8String =
|
||||
"Non-Ascii 1 byte chars: éâäàåç, 2 byte chars: \u1234 \u1235 \u1236";
|
||||
|
||||
var minInt = -Math.pow(2,31);
|
||||
var maxInt = Math.pow(2,31) - 1;
|
||||
var maxUInt = Math.pow(2,32) - 1;
|
||||
var minShort = -Math.pow(2,15);
|
||||
var maxShort = Math.pow(2,15) - 1;
|
||||
var maxUShort = Math.pow(2,16) - 1;
|
||||
var charA = 'a';
|
||||
var charZ = 'Z';
|
||||
var charWide = '\u1234';
|
||||
var maxOctet = Math.pow(2,8) - 1;
|
||||
// Since 64 bit integers are treated as doubles in Javascript, rounding
|
||||
// issues prevent us from actually using the max signed 64 bit values.
|
||||
//var lowLong = -Math.pow(2,63);
|
||||
//var highLong = Math.pow(2,63) - 1;
|
||||
var lowLong = -9223372036854775000;
|
||||
var highLong = 9223372036854775000;
|
||||
var minFloat = 1.40129846432481707e-45;
|
||||
var maxFloat = 3.40282346638528860e+38;
|
||||
var minDouble = 2.2250738585072014e-308;
|
||||
var maxDouble = 1.7976931348623157e+308;
|
||||
|
||||
tests = new Array(
|
||||
[ "EchoLong", minInt, minInt, "EchoLong w/ " + minInt ],
|
||||
[ "EchoLong", maxInt, maxInt, "EchoLong w/ " + maxInt ],
|
||||
[ "EchoShort", minShort, minShort, "EchoShort w/ " + minShort ],
|
||||
[ "EchoShort", maxShort, maxShort, "EchoShort w/ " + maxShort ],
|
||||
[ "EchoChar", charA, charA, "EchoChar w/ " + charA ],
|
||||
[ "EchoChar", charZ, charZ, "EchoChar w/ " + charZ ],
|
||||
[ "EchoBoolean", true, true, "EchoBoolean w/ " + true ],
|
||||
[ "EchoBoolean", false, false, "EchoBoolean w/ " + false ],
|
||||
/* XXX bug 367793
|
||||
[ "EchoOctet", 0, 0, "EchoOctet w/ " + 0 ],
|
||||
[ "EchoOctet", maxOctet, maxOctet, "EchoOctet w/ " + maxOctet ],
|
||||
*/
|
||||
[ "EchoLongLong", lowLong, lowLong, "EchoLongLong w/ " + lowLong ],
|
||||
[ "EchoLongLong", highLong, highLong, "EchoLongLong w/ " + highLong ],
|
||||
[ "EchoUnsignedShort", maxUShort, maxUShort,
|
||||
"EchoUnsignedShort w/ " + maxUShort ],
|
||||
[ "EchoUnsignedShort", 0, 0, "EchoUnsignedShort w/ zero" ],
|
||||
// XXX is this test case correct/valid?
|
||||
[ "EchoUnsignedShort", -1, maxUShort, "EchoUnsignedShort w/ -1" ],
|
||||
[ "EchoUnsignedLong", maxUInt, maxUInt, "EchoUnsignedLong w/ " + maxUInt ],
|
||||
[ "EchoUnsignedLong", 0, 0, "EchoUnsignedLong w/ zero" ],
|
||||
[ "EchoUnsignedLong", -1, maxUInt, "EchoUnsignedLong w/ -1" ],
|
||||
[ "EchoFloat", minFloat, minFloat, "EchoFloat w/ " + minFloat ],
|
||||
[ "EchoFloat", maxFloat, maxFloat, "EchoFloat w/ " + maxFloat ],
|
||||
[ "EchoDouble", minDouble, minDouble, "EchoDouble w/ " + minDouble ],
|
||||
[ "EchoDouble", maxDouble, maxDouble, "EchoDouble w/ " + maxDouble ],
|
||||
[ "EchoWchar", charA, charA, "EchoWchar w/ " + charA ],
|
||||
[ "EchoWchar", charZ, charZ, "EchoWchar w/ " + charZ ],
|
||||
[ "EchoWchar", charWide, charWide, "EchoWchar w/ " + charWide ],
|
||||
[ "EchoString", testString, testString,
|
||||
"EchoString w/ '" + testString + "'" ],
|
||||
[ "EchoString", emptyString, emptyString, "EchoString w/ empty string" ],
|
||||
[ "EchoString", utf8String, utf8String,
|
||||
"EchoString w/ '" + utf8String + "'" ],
|
||||
[ "EchoString", null, null, "EchoString w/ null value" ]
|
||||
);
|
||||
|
||||
runTestsArray(javaIn, tests);
|
||||
|
||||
// Since 64 bit integers are treated as doubles in Javascript, rounding
|
||||
// issues prevent us from actually using the max unsigned 64 bit value.
|
||||
// var highULong = Math.pow(2,64) - 1;
|
||||
var highULong = 18446744073709550000;
|
||||
|
||||
tests = new Array(
|
||||
[ "EchoPRBool", false, false, "EchoPRBool w/ false" ],
|
||||
[ "EchoPRBool", true, true, "EchoPRBool w/ true" ],
|
||||
[ "EchoPRInt32", minInt, minInt, "EchoPRInt32 w/ " + minInt ],
|
||||
[ "EchoPRInt32", maxInt, maxInt, "EchoPRInt32 w/ " + maxInt ],
|
||||
[ "EchoPRInt16", minShort , minShort, "EchoPRInt16 w/ " + minShort ],
|
||||
[ "EchoPRInt16", maxShort, maxShort, "EchoPRInt16 w/ " + maxShort ],
|
||||
[ "EchoPRInt64", lowLong, lowLong, "EchoPRInt64 w/ " + lowLong ],
|
||||
[ "EchoPRInt64", highLong, highLong, "EchoPRInt64 w/ " + highLong ],
|
||||
[ "EchoPRUint8", maxOctet, maxOctet, "EchoPRUint8 w/ " + maxOctet ],
|
||||
[ "EchoPRUint8", 0, 0, "EchoPRUint8 w/ zero" ],
|
||||
[ "EchoPRUint8", -1, maxOctet, "EchoPRUint8 w/ -1" ],
|
||||
[ "EchoPRUint16", maxUShort, maxUShort, "EchoPRUint16 w/ " + maxUShort ],
|
||||
[ "EchoPRUint16", 0, 0, "EchoPRUint16 w/ zero" ],
|
||||
[ "EchoPRUint16", -1, maxUShort, "EchoPRUint16 w/ -1" ],
|
||||
[ "EchoPRUint32", maxUInt, maxUInt, "EchoPRUint32 w/ " + maxUInt ],
|
||||
[ "EchoPRUint32", 0, 0, "EchoPRUint32 w/ zero" ],
|
||||
[ "EchoPRUint32", -1, maxUInt, "EchoPRUint32 w/ -1" ],
|
||||
/* XXX bug 351871
|
||||
[ "EchoPRUint64", highULong, highULong, "EchoPRUint64 w/ " + highULong ],
|
||||
*/
|
||||
[ "EchoPRUint64", 0, 0, "EchoPRUint64 w/ zero" ]
|
||||
);
|
||||
|
||||
runTestsArray(javaIn, tests);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
constants
|
||||
***********************************************************/
|
||||
|
||||
const nsIJXTestParams = Components.interfaces.nsIJXTestParams;
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
|
||||
const CLASS_ID = Components.ID("{f0882957-bcc1-4854-a2cb-94051bad4193}");
|
||||
const CLASS_NAME = "JavaXPCOM Test Params Javascript XPCOM Component";
|
||||
const CONTRACT_ID = "@mozilla.org/javaxpcom/tests/params;1";
|
||||
|
||||
/***********************************************************
|
||||
class definition
|
||||
***********************************************************/
|
||||
|
||||
//class constructor
|
||||
function TestParams() {
|
||||
};
|
||||
|
||||
// class definition
|
||||
TestParams.prototype = {
|
||||
|
||||
// define the function we want to expose in our interface
|
||||
runTests: function(tests) {
|
||||
runEchoTests(tests);
|
||||
runInTests(tests);
|
||||
},
|
||||
|
||||
QueryInterface: function(aIID) {
|
||||
if (!aIID.equals(nsIJXTestParams) &&
|
||||
!aIID.equals(nsISupports))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
class factory
|
||||
***********************************************************/
|
||||
var TestParamsFactory = {
|
||||
createInstance: function (aOuter, aIID)
|
||||
{
|
||||
if (aOuter != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return (new TestParams()).QueryInterface(aIID);
|
||||
}
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
module definition (xpcom registration)
|
||||
***********************************************************/
|
||||
var TestParamsModule = {
|
||||
_firstTime: true,
|
||||
registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
|
||||
{
|
||||
aCompMgr = aCompMgr.
|
||||
QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME,
|
||||
CONTRACT_ID, aFileSpec, aLocation, aType);
|
||||
},
|
||||
|
||||
unregisterSelf: function(aCompMgr, aLocation, aType)
|
||||
{
|
||||
aCompMgr = aCompMgr.
|
||||
QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
|
||||
},
|
||||
|
||||
getClassObject: function(aCompMgr, aCID, aIID)
|
||||
{
|
||||
if (!aIID.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (aCID.equals(CLASS_ID))
|
||||
return TestParamsFactory;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
canUnload: function(aCompMgr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
module initialization
|
||||
***********************************************************/
|
||||
function NSGetModule(aCompMgr, aFileSpec)
|
||||
{
|
||||
return TestParamsModule;
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
/* ***** 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) 2007
|
||||
* 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 ***** */
|
||||
|
||||
/***********************************************************
|
||||
constants
|
||||
***********************************************************/
|
||||
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
const nsIEcho = Components.interfaces.nsIEcho;
|
||||
const nsIXPCTestIn = Components.interfaces.nsIXPCTestIn;
|
||||
|
||||
const CLASS_ID = Components.ID("{9e45a36d-7cf7-4f2a-a415-d0b07e54945b}");
|
||||
const CLASS_NAME = "XPConnect Tests in Javascript";
|
||||
const CONTRACT_ID = "@mozilla.org/javaxpcom/tests/xpc;1";
|
||||
|
||||
/***********************************************************
|
||||
class definition
|
||||
***********************************************************/
|
||||
|
||||
//class constructor
|
||||
function XPCTests() {
|
||||
};
|
||||
|
||||
// class definition
|
||||
XPCTests.prototype = {
|
||||
|
||||
// ----------------------------------
|
||||
// nsISupports
|
||||
// ----------------------------------
|
||||
|
||||
QueryInterface: function(aIID) {
|
||||
if (!aIID.equals(nsIEcho) &&
|
||||
!aIID.equals(nsIXPCTestIn) &&
|
||||
!aIID.equals(nsISupports))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return this;
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// nsIEcho
|
||||
// ----------------------------------
|
||||
|
||||
In2OutOneString: function(input) {
|
||||
return input;
|
||||
},
|
||||
|
||||
In2OutOneDOMString: function(input) {
|
||||
return input;
|
||||
},
|
||||
|
||||
In2OutOneAString: function(input) {
|
||||
return input;
|
||||
},
|
||||
|
||||
In2OutOneUTF8String: function(input) {
|
||||
return input;
|
||||
},
|
||||
|
||||
In2OutOneCString: function(input) {
|
||||
return input;
|
||||
},
|
||||
|
||||
_string: null,
|
||||
|
||||
SetAString: function(str) {
|
||||
_string = str;
|
||||
},
|
||||
|
||||
GetAString: function() {
|
||||
return _string;
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// nsIXPCTestIn
|
||||
// ----------------------------------
|
||||
|
||||
EchoLong: function(l) {
|
||||
return l;
|
||||
},
|
||||
|
||||
EchoShort: function(a) {
|
||||
return a;
|
||||
},
|
||||
|
||||
EchoChar: function(c) {
|
||||
return c;
|
||||
},
|
||||
|
||||
EchoBoolean: function(b) {
|
||||
return b;
|
||||
},
|
||||
|
||||
EchoOctet: function(o) {
|
||||
return o;
|
||||
},
|
||||
|
||||
EchoLongLong: function(ll) {
|
||||
return ll;
|
||||
},
|
||||
|
||||
EchoUnsignedShort: function(us) {
|
||||
return us;
|
||||
},
|
||||
|
||||
EchoUnsignedLong: function(ul) {
|
||||
return ul;
|
||||
},
|
||||
|
||||
EchoFloat: function(f) {
|
||||
return f;
|
||||
},
|
||||
|
||||
EchoDouble: function(d) {
|
||||
return d;
|
||||
},
|
||||
|
||||
EchoWchar: function(wc) {
|
||||
return wc;
|
||||
},
|
||||
|
||||
EchoString: function(ws) {
|
||||
return ws;
|
||||
},
|
||||
|
||||
EchoPRBool: function(b) {
|
||||
return b;
|
||||
},
|
||||
|
||||
EchoPRInt32: function(l) {
|
||||
return l;
|
||||
},
|
||||
|
||||
EchoPRInt16: function(l) {
|
||||
return l;
|
||||
},
|
||||
|
||||
EchoPRInt64: function(i) {
|
||||
return i;
|
||||
},
|
||||
|
||||
EchoPRUint8: function(i) {
|
||||
return i;
|
||||
},
|
||||
|
||||
EchoPRUint16: function(i) {
|
||||
return i;
|
||||
},
|
||||
|
||||
EchoPRUint32: function(i) {
|
||||
return i;
|
||||
},
|
||||
|
||||
EchoPRUint64: function(i) {
|
||||
return i;
|
||||
},
|
||||
|
||||
EchoVoid: function() {}
|
||||
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
class factory
|
||||
***********************************************************/
|
||||
var XPCTestsFactory = {
|
||||
createInstance: function (aOuter, aIID)
|
||||
{
|
||||
if (aOuter != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return (new XPCTests()).QueryInterface(aIID);
|
||||
}
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
module definition (xpcom registration)
|
||||
***********************************************************/
|
||||
var XPCTestsModule = {
|
||||
_firstTime: true,
|
||||
registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
|
||||
{
|
||||
aCompMgr = aCompMgr.
|
||||
QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME,
|
||||
CONTRACT_ID, aFileSpec, aLocation, aType);
|
||||
},
|
||||
|
||||
unregisterSelf: function(aCompMgr, aLocation, aType)
|
||||
{
|
||||
aCompMgr = aCompMgr.
|
||||
QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
|
||||
},
|
||||
|
||||
getClassObject: function(aCompMgr, aCID, aIID)
|
||||
{
|
||||
if (!aIID.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
if (aCID.equals(CLASS_ID))
|
||||
return XPCTestsFactory;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
canUnload: function(aCompMgr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/***********************************************************
|
||||
module initialization
|
||||
***********************************************************/
|
||||
function NSGetModule(aCompMgr, aFileSpec)
|
||||
{
|
||||
return XPCTestsModule;
|
||||
}
|
|
@ -42,8 +42,8 @@
|
|||
#include "xpctest_in.h"
|
||||
#include "nsISupports.h"
|
||||
#define NS_IXPCTESTIN_IID \
|
||||
{0x318d6f6a, 0x5411, 0x11d3, \
|
||||
{ 0x82, 0xef, 0x00, 0x60, 0xb0, 0xeb, 0x59, 0x6f }}
|
||||
{0xa3cab49d, 0xae83, 0x4e63, \
|
||||
{ 0xa7, 0x35, 0x00, 0x9b, 0x9a, 0x75, 0x92, 0x04 }}
|
||||
|
||||
|
||||
class xpcTestIn : public nsIXPCTestIn {
|
||||
|
@ -104,7 +104,7 @@ NS_IMETHODIMP xpcTestIn :: EchoWchar(PRUnichar wc, PRUnichar *_retval) {
|
|||
*_retval = wc;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP xpcTestIn :: EchoString(const PRUnichar *ws, char **_retval) {
|
||||
NS_IMETHODIMP xpcTestIn :: EchoString(const PRUnichar *ws, PRUnichar **_retval) {
|
||||
/* const char s[] = *ws;
|
||||
**_retval= (char*) nsMemory::Clone(s,
|
||||
sizeof(char)*(strlen(s)+1));
|
||||
|
|
|
@ -101,8 +101,8 @@
|
|||
{ 0x82, 0xef, 0x00, 0x60, 0xb0, 0xeb, 0x59, 0x6f }}
|
||||
|
||||
#define NS_XPCTESTIN_CID \
|
||||
{0x318d6f6a, 0x5411, 0x11d3, \
|
||||
{ 0x82, 0xef, 0x00, 0x60, 0xb0, 0xeb, 0x59, 0x6f }}
|
||||
{0xa3cab49d, 0xae83, 0x4e63, \
|
||||
{ 0xa7, 0x35, 0x00, 0x9b, 0x9a, 0x75, 0x92, 0x04 }}
|
||||
|
||||
#define NS_XPCTESTOUT_CID \
|
||||
{0x4105ae88, 0x5599, 0x11d3, \
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(318d6f6a-5411-11d3-82ef-0060b0eb596f)]
|
||||
[scriptable, uuid(a3cab49d-ae83-4e63-a735-009b9a759204)]
|
||||
interface nsIXPCTestIn : nsISupports {
|
||||
long EchoLong( in long l);
|
||||
short EchoShort( in short a );
|
||||
|
@ -57,7 +57,7 @@ interface nsIXPCTestIn : nsISupports {
|
|||
float EchoFloat( in float f );
|
||||
double EchoDouble( in double d );
|
||||
wchar EchoWchar ( in wchar wc );
|
||||
string EchoString( in wstring ws );
|
||||
wstring EchoString( in wstring ws );
|
||||
|
||||
PRBool EchoPRBool( in PRBool b );
|
||||
PRInt32 EchoPRInt32( in PRInt32 l );
|
||||
|
|
|
@ -237,8 +237,9 @@ ifdef MOZ_PREF_EXTENSIONS
|
|||
tier_toolkit_dirs += extensions/pref
|
||||
endif
|
||||
|
||||
# JavaXPCOM JNI code is compiled into libXUL
|
||||
ifdef MOZ_JAVAXPCOM
|
||||
tier_toolkit_dirs += extensions/java
|
||||
tier_toolkit_dirs += extensions/java/xpcom/src
|
||||
endif
|
||||
|
||||
ifndef BUILD_STATIC_LIBS
|
||||
|
|
|
@ -69,9 +69,8 @@ tier_app_dirs += embedding/tests
|
|||
endif
|
||||
endif
|
||||
|
||||
tier_app_dirs += xulrunner
|
||||
|
||||
# This should be built last, after all IDL files in the tree have been processed
|
||||
ifdef MOZ_JAVAXPCOM
|
||||
tier_app_dirs += extensions/java/xpcom/interfaces
|
||||
tier_app_dirs += extensions/java
|
||||
endif
|
||||
|
||||
tier_app_dirs += xulrunner
|
||||
|
|
Загрузка…
Ссылка в новой задаче