Merge mozilla-central into mozilla-inbound:

This commit is contained in:
Ehsan Akhgari 2011-10-14 13:58:40 -04:00
commit 53dac2fab8
347 changed files with 4402 additions and 12488 deletions

0
accessible/tests/mochitest/textselection/Makefile.in Executable file → Normal file
View File

View File

View File

@ -84,10 +84,10 @@ var Scratchpad = {
executionContext: SCRATCHPAD_CONTEXT_CONTENT,
/**
* Retrieve the xul:notificationbox DOM element. It notifies the user when
* the current code execution context is SCRATCHPAD_CONTEXT_BROWSER.
* Retrieve the xul:statusbarpanel DOM element. The status bar tells the
* current code execution context.
*/
get notificationBox() document.getElementById("scratchpad-notificationbox"),
get statusbarStatus() document.getElementById("scratchpad-status"),
/**
* Get the selected text from the editor.
@ -599,15 +599,11 @@ var Scratchpad = {
*/
setContentContext: function SP_setContentContext()
{
if (this.executionContext == SCRATCHPAD_CONTEXT_CONTENT) {
return;
}
let content = document.getElementById("sp-menu-content");
document.getElementById("sp-menu-browser").removeAttribute("checked");
content.setAttribute("checked", true);
this.executionContext = SCRATCHPAD_CONTEXT_CONTENT;
this.notificationBox.removeAllNotifications(false);
this.statusbarStatus.label = content.getAttribute("label");
this.resetContext();
},
@ -616,20 +612,11 @@ var Scratchpad = {
*/
setBrowserContext: function SP_setBrowserContext()
{
if (this.executionContext == SCRATCHPAD_CONTEXT_BROWSER) {
return;
}
let browser = document.getElementById("sp-menu-browser");
document.getElementById("sp-menu-content").removeAttribute("checked");
browser.setAttribute("checked", true);
this.executionContext = SCRATCHPAD_CONTEXT_BROWSER;
this.notificationBox.appendNotification(
this.strings.GetStringFromName("browserContext.notification"),
SCRATCHPAD_CONTEXT_BROWSER,
null,
this.notificationBox.PRIORITY_WARNING_HIGH,
null);
this.statusbarStatus.label = browser.getAttribute("label");
this.resetContext();
},
@ -670,14 +657,17 @@ var Scratchpad = {
return;
}
let chromeContextMenu = document.getElementById("sp-menu-browser");
let errorConsoleMenu = document.getElementById("sp-menu-errorConsole");
let errorConsoleCommand = document.getElementById("sp-cmd-errorConsole");
let chromeContextCommand = document.getElementById("sp-cmd-browserContext");
let chrome = Services.prefs.getBoolPref(DEVTOOLS_CHROME_ENABLED);
if (chrome) {
let environmentMenu = document.getElementById("sp-environment-menu");
let errorConsoleCommand = document.getElementById("sp-cmd-errorConsole");
let chromeContextCommand = document.getElementById("sp-cmd-browserContext");
environmentMenu.removeAttribute("hidden");
chromeContextCommand.removeAttribute("disabled");
chromeContextMenu.removeAttribute("hidden");
errorConsoleMenu.removeAttribute("hidden");
errorConsoleCommand.removeAttribute("disabled");
chromeContextCommand.removeAttribute("disabled");
}
this.editor = new SourceEditor();

View File

@ -261,18 +261,12 @@
accesskey="&display.accesskey;"
key="sp-key-display"
command="sp-cmd-display"/>
<menuseparator/>
<menuitem id="sp-text-resetContext"
label="&resetContext.label;"
accesskey="&resetContext.accesskey;"
command="sp-cmd-resetContext"/>
</menupopup>
</menu>
<menu id="sp-environment-menu"
label="&environmentMenu.label;"
accesskey="&environmentMenu.accesskey;"
hidden="true">
accesskey="&environmentMenu.accesskey;">
<menupopup id="sp-menu-environment">
<menuitem id="sp-menu-content"
label="&contentContext.label;"
@ -280,11 +274,33 @@
command="sp-cmd-contentContext"
checked="true"
type="radio"/>
<menuitem id="sp-menu-browser"
<menuitem id="sp-menu-browser" hidden="true"
command="sp-cmd-browserContext"
label="&browserContext.label;"
accesskey="&browserContext.accesskey;"
type="radio"/>
<menuseparator/>
<menuitem id="sp-menu-resetContext"
command="sp-cmd-resetContext"
label="&resetContext.label;"
accesskey="&resetContext.accesskey;"/>
</menupopup>
</menu>
<menu id="sp-tools-menu"
label="&toolsMenu.label;"
accesskey="&toolsMenu.accesskey;">
<menupopup id="sp-menu-tools">
<menuitem id="sp-menu-errorConsole" hidden="true"
label="&errorConsoleCmd.label;"
accesskey="&errorConsoleCmd.accesskey;"
key="sp-key-errorConsole"
command="sp-cmd-errorConsole"/>
<menuitem id="sp-menu-webConsole"
label="&webConsoleCmd.label;"
accesskey="&webConsoleCmd.accesskey;"
key="sp-key-webConsole"
command="sp-cmd-webConsole"/>
</menupopup>
</menu>
</menubar>
@ -313,16 +329,15 @@
accesskey="&display.accesskey;"
key="sp-key-display"
command="sp-cmd-display"/>
<menuseparator/>
<menuitem id="sp-text-resetContext"
label="&resetContext.label;"
accesskey="&resetContext.accesskey;"
command="sp-cmd-resetContext"/>
</menupopup>
</popupset>
<notificationbox id="scratchpad-notificationbox" flex="1">
<hbox id="scratchpad-editor" flex="1" context="scratchpad-text-popup" />
</notificationbox>
<hbox id="scratchpad-editor" flex="1" context="scratchpad-text-popup" />
<statusbar id="scratchpad-statusbar" align="end">
<statusbarpanel id="scratchpad-status"
label="&contentContext.label;"
class="statusbarpanel-iconic-text"/>
<spacer flex="1"/>
</statusbar>
</window>

View File

@ -35,11 +35,11 @@ function runTests()
let sp = gScratchpadWindow.Scratchpad;
ok(sp, "Scratchpad object exists in new window");
let environmentMenu = gScratchpadWindow.document.
getElementById("sp-environment-menu");
ok(environmentMenu, "Environment menu element exists");
ok(!environmentMenu.hasAttribute("hidden"),
"Environment menu is visible");
let chromeContextMenu = gScratchpadWindow.document.
getElementById("sp-menu-browser");
ok(chromeContextMenu, "Chrome context menuitem element exists");
ok(!chromeContextMenu.hasAttribute("hidden"),
"Chrome context menuitem is visible");
let errorConsoleCommand = gScratchpadWindow.document.
getElementById("sp-cmd-errorConsole");
@ -47,6 +47,12 @@ function runTests()
ok(!errorConsoleCommand.hasAttribute("disabled"),
"Error console command is enabled");
let errorConsoleMenu = gScratchpadWindow.document.
getElementById("sp-menu-errorConsole");
ok(errorConsoleMenu, "Error console menu element exists");
ok(!errorConsoleMenu.hasAttribute("hidden"),
"Error console menuitem is visible");
let chromeContextCommand = gScratchpadWindow.document.
getElementById("sp-cmd-browserContext");
ok(chromeContextCommand, "Chrome context command element exists");

View File

@ -28,11 +28,11 @@ function runTests()
let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
let chromeMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
let notificationBox = sp.notificationBox;
let statusbar = sp.statusbarStatus;
ok(contentMenu, "found #sp-menu-content");
ok(chromeMenu, "found #sp-menu-browser");
ok(notificationBox, "found Scratchpad.notificationBox");
ok(statusbar, "found Scratchpad.statusbarStatus");
sp.setContentContext();
@ -45,8 +45,8 @@ function runTests()
ok(!chromeMenu.hasAttribute("checked"),
"chrome menuitem is not checked");
ok(!notificationBox.currentNotification,
"there is no notification in content context");
is(statusbar.getAttribute("label"), contentMenu.getAttribute("label"),
"statusbar label is correct");
sp.setText("window.foobarBug636725 = 'aloha';");
@ -69,8 +69,8 @@ function runTests()
ok(!contentMenu.hasAttribute("checked"),
"content menuitem is not checked");
ok(notificationBox.currentNotification,
"there is a notification in browser context");
is(statusbar.getAttribute("label"), chromeMenu.getAttribute("label"),
"statusbar label is correct");
sp.setText("2'", 31, 33);

View File

@ -32,11 +32,11 @@ function runTests()
is(typeof sp.inspect, "function", "Scratchpad.inspect() exists");
is(typeof sp.display, "function", "Scratchpad.display() exists");
let environmentMenu = gScratchpadWindow.document.
getElementById("sp-environment-menu");
ok(environmentMenu, "Environment menu element exists");
ok(environmentMenu.hasAttribute("hidden"),
"Environment menu is not visible");
let chromeContextMenu = gScratchpadWindow.document.
getElementById("sp-menu-browser");
ok(chromeContextMenu, "Chrome context menuitem element exists");
is(chromeContextMenu.getAttribute("hidden"), "true",
"Chrome context menuitem is hidden");
let errorConsoleCommand = gScratchpadWindow.document.
getElementById("sp-cmd-errorConsole");
@ -44,6 +44,12 @@ function runTests()
is(errorConsoleCommand.getAttribute("disabled"), "true",
"Error console command is disabled");
let errorConsoleMenu = gScratchpadWindow.document.
getElementById("sp-menu-errorConsole");
ok(errorConsoleMenu, "Error console menu element exists");
is(errorConsoleMenu.getAttribute("hidden"), "true",
"Error console menu item is hidden");
let chromeContextCommand = gScratchpadWindow.document.
getElementById("sp-cmd-browserContext");
ok(chromeContextCommand, "Chrome context command element exists");

View File

@ -38,11 +38,11 @@ function runTests()
let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
let notificationBox = sp.notificationBox;
let statusbar = sp.statusbarStatus;
ok(contentMenu, "found #sp-menu-content");
ok(browserMenu, "found #sp-menu-browser");
ok(notificationBox, "found Scratchpad.notificationBox");
ok(statusbar, "found Scratchpad.statusbarStatus");
sp.setContentContext();
@ -55,8 +55,8 @@ function runTests()
ok(!browserMenu.hasAttribute("checked"),
"chrome menuitem is not checked");
is(notificationBox.currentNotification, null,
"there is no notification currently shown for content context");
is(statusbar.getAttribute("label"), contentMenu.getAttribute("label"),
"statusbar label is correct");
sp.setText("window.foosbug653108 = 'aloha';");

View File

@ -36,9 +36,11 @@ function runTests()
"sp-text-run": "run",
"sp-text-inspect": "inspect",
"sp-text-display": "display",
"sp-text-resetContext": "resetContext",
"sp-menu-content": "setContentContext",
"sp-menu-browser": "setBrowserContext",
"sp-menu-resetContext": "resetContext",
"sp-menu-errorConsole": "openErrorConsole",
"sp-menu-webConsole": "openWebConsole",
"sp-menu-undo": "undo",
"sp-menu-redo": "redo",
};

View File

@ -98,14 +98,19 @@
<!-- LOCALIZATION NOTE (resetContext.label): This command allows the developer
- to reset/clear the global object of the environment where the code executes.
-->
<!ENTITY resetContext.label "Reset Variables">
<!ENTITY resetContext.accesskey "T">
<!ENTITY resetContext.label "Reset">
<!ENTITY resetContext.accesskey "R">
<!ENTITY executeMenu.label "Execute">
<!ENTITY executeMenu.accesskey "X">
<!ENTITY toolsMenu.label "Tools">
<!ENTITY toolsMenu.accesskey "T">
<!ENTITY errorConsoleCmd.label "Error Console">
<!ENTITY errorConsoleCmd.accesskey "C">
<!ENTITY errorConsoleCmd.commandkey "j">
<!ENTITY webConsoleCmd.label "Web Console">
<!ENTITY webConsoleCmd.accesskey "W">
<!ENTITY webConsoleCmd.commandkey "k">

View File

@ -33,7 +33,3 @@ saveFile.failed=The file save operation failed.
# how to use the Scratchpad. Note that this should be a valid JavaScript
# comment inside /* and */.
scratchpadIntro=/*\n * This is a JavaScript Scratchpad.\n *\n * Enter some JavaScript, then Right Click or choose from the Execute Menu:\n * 1. Run to evaluate the selected text,\n * 2. Inspect to bring up an Object Inspector on the result, or,\n * 3. Display to insert the result in a comment after the selection.\n */\n\n
# LOCALIZATION NOTE (notification.browserContext): This is the message displayed
# over the top of the editor when the user has switched to browser context.
browserContext.notification=This scratchpad executes in the Browser context.

View File

@ -53,7 +53,7 @@
<!ENTITY netInterrupt.longDesc "&sharedLongDesc;">
<!ENTITY notCached.title "Document Expired">
<!ENTITY notCached.longDesc "<p>The requested document is not available in Firefox's cache.</p><ul><li>As a security precuation, Firefox does not automatically re-request sensitive documents.</li><li>Click Try Again to re-request the document from the website.</li></ul>">
<!ENTITY notCached.longDesc "<p>The requested document is not available in Firefox's cache.</p><ul><li>As a security precaution, Firefox does not automatically re-request sensitive documents.</li><li>Click Try Again to re-request the document from the website.</li></ul>">
<!ENTITY netOffline.title "Offline mode">
<!ENTITY netOffline.longDesc2 "

View File

@ -61,6 +61,6 @@ CPPSRCS = \
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../include \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/dom/base

View File

@ -72,7 +72,7 @@ EXPORTS_mozilla/dom = \
Link.h \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)/js/src/xpconnect/src
LOCAL_INCLUDES = -I$(srcdir)/js/xpconnect/src
CPPSRCS = \
mozSanitizingSerializer.cpp \
@ -202,7 +202,7 @@ INCLUDES += \
-I$(srcdir)/../../xml/document/src \
-I$(topsrcdir)/xpcom/io \
-I$(topsrcdir)/dom/ipc \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/caps/include \
-I$(topsrcdir)/netwerk/base/src \
$(NULL)

View File

@ -78,7 +78,7 @@
#include "mozilla/Preferences.h"
#include "xpcprivate.h"
#include "xpcpublic.h"
#include "xpcquickstubs.h"
#include "XPCQuickStubs.h"
#include "jstypedarray.h"
#include "nsDOMJSUtils.h"

View File

@ -2152,8 +2152,8 @@ WebGLContext::GetConcreteObject(const char *info,
#ifdef DEBUG
{
// once bug 694114 is implemented, we want to replace this by a static assertion, without #ifdef DEBUG
nsresult rv;
do_QueryInterface(aInterface, &rv);
nsresult rv = NS_OK;
nsCOMPtr<ConcreteObjectType> tmp(do_QueryInterface(aInterface, &rv));
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv),
"QueryInterface failed. WebGL objects are builtinclass, so this should never happen. "
"Please file a bug at bugzilla.mozilla.org -> Core -> Canvas:WebGL and link to the present page.");

View File

@ -148,7 +148,7 @@ INCLUDES += \
-I$(srcdir)/../../../../editor/libeditor/text \
-I$(srcdir) \
-I$(topsrcdir)/xpcom/ds \
-I$(srcdir)/../../../../js/src/xpconnect/src \
-I$(srcdir)/../../../../js/xpconnect/src \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

View File

@ -89,7 +89,7 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../../../layout/style \
-I$(srcdir)/../../../dom/base \
-I$(topsrcdir)/xpcom/ds \
-I$(srcdir)/../../../js/src/xpconnect/src \
-I$(srcdir)/../../../js/xpconnect/src \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

View File

@ -119,6 +119,6 @@ LOCAL_INCLUDES += \
-I$(srcdir)/../shistory/src \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/layout/base \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/xpcom/ds \
$(NULL)

View File

@ -136,8 +136,8 @@ include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
LOCAL_INCLUDES += \
-I$(srcdir)/../../js/src/xpconnect/src \
-I$(srcdir)/../../js/src/xpconnect/wrappers \
-I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/wrappers \
-I$(topsrcdir)/xpcom/ds \
$(NULL)

View File

@ -97,7 +97,7 @@ LOCAL_INCLUDES = \
DEFINES += -D_IMPL_NS_LAYOUT
# Make sure to quickstub as much as possible here! See
# js/src/xpconnect/src/dom_quickstubs.qsconf.
# js/xpconnect/src/dom_quickstubs.qsconf.
XPIDLSRCS = \
nsIIDBCursor.idl \
nsIIDBCursorWithValue.idl \

View File

@ -25,7 +25,7 @@
<!ENTITY netInterrupt.longDesc "<p>The browser connected successfully, but the connection was interrupted while transferring information. Please try again.</p><ul><li>Are you unable to browse other sites? Check the computer's network connection.</li><li>Still having trouble? Consult your network administrator or Internet provider for assistance.</li></ul>">
<!ENTITY notCached.title "Document Expired">
<!ENTITY notCached.longDesc "<p>The requested document is not available in the browser's cache.</p><ul><li>As a security precuation, the browser does not automatically re-request sensitive documents.</li><li>Click Try Again to re-request the document from the website.</li></ul>">
<!ENTITY notCached.longDesc "<p>The requested document is not available in the browser's cache.</p><ul><li>As a security precaution, the browser does not automatically re-request sensitive documents.</li><li>Click Try Again to re-request the document from the website.</li></ul>">
<!ENTITY netOffline.title "Offline Mode">
<!ENTITY netOffline.longDesc2 "<p>The browser is operating in its offline mode and cannot connect to the requested item.</p><ul><li>Is the computer connected to an active network?</li><li>Press &quot;Try Again&quot; to switch to online mode and reload the page.</li></ul>">

View File

@ -49,7 +49,7 @@
#include "nsJSUtils.h"
#include "nsStringGlue.h"
#include "xpcprivate.h"
#include "xpcquickstubs.h"
#include "XPCQuickStubs.h"
#include "Exceptions.h"
#include "WorkerInlines.h"

View File

@ -77,7 +77,7 @@ LOCAL_INCLUDES = \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/events/src \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/js/xpconnect/src \
-I$(topsrcdir)/xpcom/build \
$(NULL)

View File

@ -64,7 +64,7 @@ CPPSRCS += \
# For xpcshell error messages and nsDependentJSString
LOCAL_INCLUDES += \
-I$(topsrcdir)/js/src/xpconnect/shell \
-I$(topsrcdir)/js/xpconnect/shell \
-I$(topsrcdir)/dom/base \
$(NULL)

View File

@ -1,67 +0,0 @@
#!gmake
#
# ***** 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 Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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@
MODULE=xpcsample
LIBRARY_NAME = xpcsample
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = xpconnect_sample
MOZILLA_INTERNAL_API = 1
XPIDLSRCS = \
xpcsample1.idl \
$(NULL)
CPPSRCS= \
xpcsample1.cpp \
$(NULL)
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_JS_LIBS) \
$(NULL)
include $(topsrcdir)\config\rules.mk

View File

@ -1,39 +0,0 @@
xpcsample1.* is a set of files that show a sample of implementing some simple
xpcom classes and relecting them into JavaScript as a chain of properties on the
global object.
xpcsample1.idl declares four interfaces: nsIXPCSample_ClassA,
nsIXPCSample_ClassB, nsIXPCSample_ClassC, and nsIXPCSample_HookerUpper. 'A' has
an integer value (called 'someValue') and a 'B'. 'B' has an integer value and a
'C'. 'C' just has an integer value. nsIXPCSample_HookerUpper just has one method
that when called will attach an instance of 'A' to the global object.
Confused? This is quite contrived. It will make more sense after examining the
code.
So, this means that after calling the method
nsIXPCSample_HookerUpper::createSampleObjectAtGlobalScope in JavaScript one can
access:
A.someValue, A.B.someValue, and A.B.C.someValue.
see xpcsample.js (or run 'xpcshell xpcsample.js').
The point of all this is to show how to build a hierarchy of native xpcom
objects
with properties and methods reflected into JavaScript. Of course, in real
life these interfaces and native objects would be much more interesting.
The only direct jsapi calls required are those that will 'root' the hierarchy
into the JavaSCript namespace. 'createSampleObjectAtGlobalScope' shows an
example of doing this.
Most native objects can be satisfactorily reflected using these mechanisms.
However, some fancy stuff might require the extended support found in
nsIXPCScriptable.h. For example, relecting objects that act like constructor
functions, receiving 'finalize' calls on the native object, or reflecting
'dynamically' named properties (i.e. those not declared in xpidl). Native xpcom
objects that implement nsIXPCScriptable are given much more control over how
they are reflected into JavaScript. There should be few situations where this
additional control is needed.

View File

@ -1,337 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* xpconnect api sample */
#include "xpcsample1.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "nsIGenericFactory.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
/***************************************************************************/
// forward declare the below classes for clarity
class nsXPCSample_ClassA;
class nsXPCSample_ClassB;
class nsXPCSample_ClassC;
/***************************************************************************/
// declare the classes
class nsXPCSample_ClassA : public nsIXPCSample_ClassA
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPCSAMPLE_CLASSA
nsXPCSample_ClassA(PRInt32 aValue);
virtual ~nsXPCSample_ClassA();
private:
PRInt32 mValue;
nsCOMPtr<nsIXPCSample_ClassB> mClassB;
};
/********************************/
class nsXPCSample_ClassB : public nsIXPCSample_ClassB
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPCSAMPLE_CLASSB
nsXPCSample_ClassB(PRInt32 aValue);
virtual ~nsXPCSample_ClassB();
private:
PRInt32 mValue;
nsCOMPtr<nsIXPCSample_ClassC> mClassC;
};
/********************************/
class nsXPCSample_ClassC : public nsIXPCSample_ClassC
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPCSAMPLE_CLASSC
nsXPCSample_ClassC(PRInt32 aValue);
virtual ~nsXPCSample_ClassC();
private:
PRInt32 mValue;
};
/***************************************************************************/
// implement the 'root' ClassA for this odd sample
NS_IMPL_ISUPPORTS1(nsXPCSample_ClassA, nsIXPCSample_ClassA)
nsXPCSample_ClassA::nsXPCSample_ClassA(PRInt32 aValue)
: mValue(aValue)
{
}
nsXPCSample_ClassA::~nsXPCSample_ClassA()
{
// empty
}
/* attribute PRInt32 someValue; */
NS_IMETHODIMP nsXPCSample_ClassA::GetSomeValue(PRInt32 *aSomeValue)
{
*aSomeValue = mValue;
return NS_OK;
}
NS_IMETHODIMP nsXPCSample_ClassA::SetSomeValue(PRInt32 aSomeValue)
{
mValue = aSomeValue;
return NS_OK;
}
/* readonly attribute nsIXPCSample_ClassB B; */
NS_IMETHODIMP nsXPCSample_ClassA::GetB(nsIXPCSample_ClassB * *aB)
{
if(!mClassB && !(mClassB = new nsXPCSample_ClassB(mValue)))
return NS_ERROR_FAILURE;
*aB = mClassB;
NS_ADDREF(*aB);
return NS_OK;
}
/***************************************************************************/
// implement ClassB for this odd sample
NS_IMPL_ISUPPORTS1(nsXPCSample_ClassB, nsIXPCSample_ClassB)
nsXPCSample_ClassB::nsXPCSample_ClassB(PRInt32 aValue)
: mValue(aValue)
{
}
nsXPCSample_ClassB::~nsXPCSample_ClassB()
{
// empty
}
/* attribute PRInt32 someValue; */
NS_IMETHODIMP nsXPCSample_ClassB::GetSomeValue(PRInt32 *aSomeValue)
{
*aSomeValue = mValue;
return NS_OK;
}
NS_IMETHODIMP nsXPCSample_ClassB::SetSomeValue(PRInt32 aSomeValue)
{
mValue = aSomeValue;
return NS_OK;
}
/* readonly attribute nsIXPCSample_ClassC C; */
NS_IMETHODIMP nsXPCSample_ClassB::GetC(nsIXPCSample_ClassC * *aC)
{
if(!mClassC && !(mClassC = new nsXPCSample_ClassC(mValue)))
return NS_ERROR_FAILURE;
*aC = mClassC;
NS_ADDREF(*aC);
return NS_OK;
}
/***************************************************************************/
// implement ClassC for this odd sample
NS_IMPL_ISUPPORTS1(nsXPCSample_ClassC, nsIXPCSample_ClassC)
nsXPCSample_ClassC::nsXPCSample_ClassC(PRInt32 aValue)
: mValue(aValue)
{
}
nsXPCSample_ClassC::~nsXPCSample_ClassC()
{
// empty
}
/* attribute PRInt32 someValue; */
NS_IMETHODIMP nsXPCSample_ClassC::GetSomeValue(PRInt32 *aSomeValue)
{
*aSomeValue = mValue;
return NS_OK;
}
NS_IMETHODIMP nsXPCSample_ClassC::SetSomeValue(PRInt32 aSomeValue)
{
mValue = aSomeValue;
return NS_OK;
}
/***************************************************************************/
// implement the hooker-upper (see the comment in the xpcsample1.idl)
class nsXPCSample_HookerUpper : public nsIXPCSample_HookerUpper
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPCSAMPLE_HOOKERUPPER
nsXPCSample_HookerUpper();
virtual ~nsXPCSample_HookerUpper();
};
NS_IMPL_ISUPPORTS1(nsXPCSample_HookerUpper, nsIXPCSample_HookerUpper)
nsXPCSample_HookerUpper::nsXPCSample_HookerUpper()
{
}
nsXPCSample_HookerUpper::~nsXPCSample_HookerUpper()
{
// empty
}
/* void createSampleObjectAtGlobalScope (in string name, in PRInt32 value); */
NS_IMETHODIMP
nsXPCSample_HookerUpper::CreateSampleObjectAtGlobalScope(const char *name, PRInt32 value)
{
// we use the xpconnect native call context stuff to get the current
// JSContext. Again, this would not be necessary if we were setting up
// our own JSContext instead of resonding to a call inside a running
// context.
// get the xpconnect service
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
if(NS_FAILED(rv))
return NS_ERROR_FAILURE;
// get the xpconnect native call context
nsAXPCNativeCallContext *callContext = nsnull;
xpc->GetCurrentNativeCallContext(&callContext);
if(!callContext)
return NS_ERROR_FAILURE;
// verify that we are being called from JS (i.e. the current call is
// to this object - though we don't verify that it is to this exact method)
nsCOMPtr<nsISupports> callee;
callContext->GetCallee(getter_AddRefs(callee));
if(!callee || callee.get() != (nsISupports*)this)
return NS_ERROR_FAILURE;
// Get JSContext of current call
JSContext* cx;
rv = callContext->GetJSContext(&cx);
if(NS_FAILED(rv) || !cx)
return NS_ERROR_FAILURE;
// Get the xpc wrapper (for 'this') so that we can get its JSObject
nsCOMPtr<nsIXPConnectWrappedNative> calleeWrapper;
callContext->GetCalleeWrapper(getter_AddRefs(calleeWrapper));
if(!calleeWrapper)
return NS_ERROR_FAILURE;
// Get the JSObject of the wrapper
JSObject* calleeJSObject;
rv = calleeWrapper->GetJSObject(&calleeJSObject);
if(NS_FAILED(rv) || !calleeJSObject)
return NS_ERROR_FAILURE;
// Now we walk the parent chain of the wrapper's JSObject to get at the
// global object to which we'd like to attack the new property (which is
// the point of this whole exercise!)
JSObject* tempJSObject;
JSObject* globalJSObject = calleeJSObject;
while(tempJSObject = JS_GetParent(cx, globalJSObject))
globalJSObject = tempJSObject;
// --- if we did this all at JSContext setup time then only the following
// is necessary...
// Create the new native object
nsXPCSample_ClassA* classA = new nsXPCSample_ClassA(value);
if(!classA)
return NS_ERROR_FAILURE;
// Build an xpconnect wrapper around the object
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
rv = xpc->WrapNative(cx, globalJSObject, classA,
NS_GET_IID(nsXPCSample_ClassA),
getter_AddRefs(wrapper));
if(NS_FAILED(rv) || !wrapper)
return NS_ERROR_FAILURE;
// Get the JSObject of the new wrapper we just built around our ClassA obj
JSObject* ourJSObject;
rv = wrapper->GetJSObject(&ourJSObject);
if(NS_FAILED(rv) || !ourJSObject)
return NS_ERROR_FAILURE;
// Now we can use the JSAPI to add this JSObject as a property of the
// global object.
if(!JS_DefineProperty(cx,
globalJSObject, // add property to this object
"A", // give property this name
OBJECT_TO_JSVAL(ourJSObject),
nsnull, nsnull,
JSPROP_PERMANENT | // these flags are optional
JSPROP_READONLY |
JSPROP_ENUMERATE))
return NS_ERROR_FAILURE;
// all is well - new object was added!
return NS_OK;
}
/***************************************************************************/
// generic factory and component registration stuff...
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCSample_HookerUpper)
static const nsModuleComponentInfo components[] = {
{ "sample xpc component",
{ 0x97380cf0, 0xc21b, 0x11d3, { 0x98, 0xc9, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } },
NS_NSXPCSAMPLE_HOOKERUPPER_CONTRACTID,
nsXPCSample_HookerUpperConstructor }
};
NS_IMPL_NSGETMODULE(xpconnect_samples, components)

View File

@ -1,82 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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"
// forward declare the below interfaces for clarity
interface nsIXPCSample_ClassA;
interface nsIXPCSample_ClassB;
interface nsIXPCSample_ClassC;
[scriptable, uuid(6bd0c120-c216-11d3-98c9-006008962422)]
interface nsIXPCSample_ClassA : nsISupports
{
attribute PRInt32 someValue;
readonly attribute nsIXPCSample_ClassB B;
};
[scriptable, uuid(c9c7bac0-c216-11d3-98c9-006008962422)]
interface nsIXPCSample_ClassB : nsISupports
{
attribute PRInt32 someValue;
readonly attribute nsIXPCSample_ClassC C;
};
[scriptable, uuid(df7bd080-c216-11d3-98c9-006008962422)]
interface nsIXPCSample_ClassC : nsISupports
{
attribute PRInt32 someValue;
};
// This is an interace for a funky object that can create an instance of the
// chain above in the global scope of the currently running JSContext. One
// might more normally do this automatically as the JSContext is created
// (or the 'request' serviced), but here I wanted to be able to show this
// activity from within an xpcom component.
[scriptable, uuid(15794370-c217-11d3-98c9-006008962422)]
interface nsIXPCSample_HookerUpper : nsISupports
{
void createSampleObjectAtGlobalScope(in string name, in PRInt32 value);
};
%{C++
#define NS_NSXPCSAMPLE_HOOKERUPPER_CONTRACTID "xpc.sample_hookerupper.1"
%}

View File

@ -1,21 +0,0 @@
var clazz = Components.classes["xpc.sample_hookerupper.1"];
var iface = Components.interfaces.nsIXPCSample_HookerUpper;
var hookerupper = clazz.createInstance(iface);
hookerupper.createSampleObjectAtGlobalScope("A",5);
dump("A = "+A+"\n");
dump("A.someValue = "+A.someValue+"\n");
A.someValue++ ;
dump("A.someValue = "+A.someValue+"\n");
dump("A.B = "+A.B+"\n");
dump("A.B.someValue = "+A.B.someValue+"\n");
A.B.someValue++ ;
dump("A.B.someValue = "+A.B.someValue+"\n");
dump("A.B.C = "+A.B.C+"\n");
dump("A.B.C.someValue = "+A.B.C.someValue+"\n");
A.B.C.someValue++ ;
dump("A.B.C.someValue = "+A.B.C.someValue+"\n");

View File

@ -1,82 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Get interfaces by ID, and compare to the interface returned by name
*
*/
StartTest( "Get interfaces by ID" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
}
function AddTestData() {
// positive test cases
for ( p in Components.interfaces ) {
AddTestCase(
"Components.interfaces[" +p +"].equals( Components.ID(" +
Components.interfaces[p].id +"))",
true,
Components.interfaces[p].equals(
Components.ID(Components.interfaces[p].id))
);
AddTestCase(
"Components.ID(" +Components.interfaces[p].id
+").equals( Components.interfaces["+p+"])",
true,
Components.interfaces[p].equals(
Components.ID(Components.interfaces[p].id))
);
}
if (0) {
// negative test cases
AddTestCase(
"Components.interfaces[0].equals( Components.ID("+
Components.interfaces[1].id +") )",
false,
Components.interfaces[0].equals(
Components.ID(Components.interfaces[1].id) )
);
}
}

View File

@ -1,311 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Try to throw a bunch of errors. Corresponds to
* the xpcTestCallJS in xpctest_calljs.cpp
*
*/
StartTest( "Evaluate JavaScript Throw Expressions" );
SetupTest();
AddTestData();
AddTestComment();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/CallJS;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestCallJS;
ERROR = Components.results;
caller = CLASS.QueryInterface(IFACE);
JSO = new Function();
JSO.prototype.Evaluate = new Function( "s",
"this.result = eval(s); return this.result" );
JSO.prototype.gotException = false;
JSO.prototype.exception = {};
JSO.prototype.EvaluateAndReturnError = new Function( "s", "r", "r = eval(s); return r;" );
// keep track of the errors we've tried to use.
ERRORS_WE_GOT = {};
for ( var p in Components.results ) {
ERRORS_WE_GOT[p] = false;
}
}
function AddTestData() {
var data = [
["3", 3, false],
["undefined", undefined, false],
["throw -1", undefined, true, null,true],
["throw 'str'", undefined, true, "NS_ERROR_XPC_JS_THREW_STRING"],
["throw {}", undefined, true, "NS_ERROR_XPC_JS_THREW_JS_OBJECT"],
["throw 1", undefined, true, "NS_ERROR_XPC_JS_THREW_NUMBER"],
["throw Components.results['NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT']",
undefined, true, "NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT"],
["throw {message:'error message'};",
undefined, true, "NS_ERROR_XPC_JS_THREW_JS_OBJECT"],
["throw null", undefined, true, "NS_ERROR_XPC_JS_THREW_NULL"],
["throw new JSException('msg', 'NS_ERROR_XPC_CANT_SET_OUT_VAL', true)",
undefined, true, "NS_ERROR_XPC_CANT_SET_OUT_VAL"],
["throw caller", undefined, true, "NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT"],
["boo", undefined, true, "NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS"],
["...ignore this sentinel entry..."]
];
for(var i = 0; i < data.length-1; i++)
TestEvaluate(data[i][0],
data[i][1],
data[i][2],
data[i][3],
null,
data[i][4]);
/*
* second argument is the out object. should throw an exception since the
* out argument needs to be an object.
*/
if (0) {
TestEvaluateToString(
1,
true,
undefined,
true,
"NS_ERROR_XPC_NEED_OUT_OBJECT" );
}
}
function TestEvaluate (evalArg, eResult, eGotException, eExceptionName, jso,
errorHasNoName) {
if ( !jso )
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.Evaluate(evalArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.name",
eExceptionName,
jso.exception.name );
if (errorHasNoName) {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.result",
jso.exception.result,
jso.exception.result );
} else {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
}
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateToString (evalArg, outArg, eResult, eGotException, eExceptionName ) {
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.EvaluateToString(evalArg, outArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); outArg ",
eResult,
outArg);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateArgs( argsArray, eResult, eGotException, eExceptionName ) {
var jso = new JSO;
caller.SetJSObject(jso);
try {
if ( argsArray.length > 0 ) {
eval( "caller.Evaluate("+argsArray.toString()+")" );
} else {
caller.Evaluate();
}
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"callerEvaluate(" +argsArray+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestSetJSObject( jso, eResult, eGotException, eExceptionName ) {
var exception = {};
var gotException = false;
var result;
try {
result = caller.SetJSObject( jso );
} catch (e) {
gotException = true;
exception = e;
} finally {
AddTestCase(
"caller.SetJSObject(" + jso +")",
eResult,
result );
AddTestCase(
"gotException? ",
eGotException,
gotException);
AddTestCase(
"exception.name",
eExceptionName,
exception.name );
if ( gotException ) {
ERRORS_WE_GOT[ exception.name ] = true;
}
}
}
function AddTestComment() {
var s = "This test exercised the exceptions defined in "+
"Components.results. The following errors were not exercised:\n";
for ( var p in ERRORS_WE_GOT ) {
if ( ERRORS_WE_GOT[p] == false ) {
s += p +"\n";
}
}
AddComment(s);
}
function JSException ( message, name, data ) {
this.message = message;
this.name = name;
this.result = Components.results[name];
this.location = 0;
this.data = (data) ? data : null;
this.initialize = new Function();
this.toString = new Function ( "return this.message" );
}
function TryIt(s) {
try {
eval(s);
} catch (e) {
Enumerate(e);
}
}

View File

@ -1,153 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test evaluation. Corresponds to the xpcTestCallJS in
* xpctest_calljs.cpp
*
* In order to see what exceptions may be thrown,
* Enumerate Components.results
*/
StartTest( "Evaluate JavaScript Expressions" );
SetupTest();
AddTestData();
AddTestComment();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/CallJS;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestCallJS;
ERROR = Components.results;
caller = CLASS.QueryInterface(IFACE);
JSO = new Function();
JSO.prototype.Evaluate = new Function( "s", "this.result = eval(s); return this.result" );
JSO.prototype.gotException = false;
JSO.prototype.exception = {};
// keep track of the errors we've tried to use.
ERRORS_WE_GOT = {};
for ( var p in Components.results ) {
ERRORS_WE_GOT[p] = false;
}
}
function AddTestData() {
for ( p in Components.results ) {
TestEvaluate(
"throw new Components.Exception('error message', "+Components.results[p]+")",
undefined,
true,
p);
}
}
function TestEvaluate (evalArg, eResult, eGotException, eExceptionName ) {
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.Evaluate(evalArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.result is ",
eResult,
jso.result);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function AddTestComment() {
var s = "This test exercised the exceptions defined in "+
"Components.results. The following errors were not exercised:\n";
for ( var p in ERRORS_WE_GOT ) {
if ( ERRORS_WE_GOT[p] == false ) {
s += p +"\n";
}
}
AddComment(s);
}
function JSException ( message, name, data ) {
this.message = message;
this.name = name;
this.code = Components.results[name];
this.location = 0;
this.data = (data) ? data : null;
this.initialize = new Function();
this.toString = new Function ( "return this.message" );
}
function TryIt(s) {
try {
eval(s);
} catch (e) {
Enumerate(e);
}
}

View File

@ -1,194 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Try to throw a bunch of errors. Corresponds to
* the xpcTestCallJS in xpctest_calljs.cpp
*
*/
StartTest( "Evaluate JavaScript Throw Expressions" );
SetupTest();
AddTestData();
AddTestComment();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/CallJS;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestCallJS;
ERROR = Components.results;
caller = CLASS.QueryInterface(IFACE);
JSO = new Function();
JSO.prototype.Evaluate = new Function( "s",
"this.result = eval(s); return this.result" );
JSO.prototype.gotException = false;
JSO.prototype.exception = {};
JSO.prototype.EvaluateAndReturnError = new Function( "s", "r", "r = eval(s); return r;" );
// keep track of the errors we've tried to use.
ERRORS_WE_GOT = {};
for ( var p in Components.results ) {
ERRORS_WE_GOT[p] = false;
}
}
function AddTestData() {
for ( p in Components.results ) {
if ( p == "NS_OK" ) {
TestEvaluateAndReturnError(
Components.results[p],
undefined,
false);
} else {
TestEvaluateAndReturnError(
Components.results[p],
undefined,
true,
p);
}
}
}
function TestEvaluateAndReturnError( code, eResult, eGotException, eName ) {
var result;
var jso = new JSO();
try {
result = caller.SetJSObject( jso );
caller.EvaluateAndReturnError( code );
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.EvaluateAndReturnError("+ code +")",
eResult,
jso.result
);
AddTestCase(
"caller.EvaluateAndReturnError("+ code +"); "+
"jso.gotException",
eGotException,
jso.gotException
);
AddTestCase(
"caller.EvaluateAndReturnError("+ code +"); "+
"jso.exception.code",
code,
jso.exception.result);
AddTestCase(
"caller.EvaluateAndReturnError("+ code +"); "+
"jso.exception.name",
eName,
jso.exception.name );
}
}
function TestSetJSObject( jso, eResult, eGotException, eExceptionName ) {
var exception = {};
var gotException = false;
var result;
try {
result = caller.SetJSObject( jso );
} catch (e) {
gotException = true;
exception = e;
} finally {
AddTestCase(
"caller.SetJSObject(" + jso +")",
eResult,
result );
AddTestCase(
"gotException? ",
eGotException,
gotException);
AddTestCase(
"exception.name",
eExceptionName,
exception.name );
if ( gotException ) {
ERRORS_WE_GOT[ exception.name ] = true;
}
}
}
function AddTestComment() {
var s = "This test exercised the exceptions defined in "+
"Components.results. The following errors were not exercised:\n";
for ( var p in ERRORS_WE_GOT ) {
if ( ERRORS_WE_GOT[p] == false ) {
s += p +"\n";
}
}
AddComment(s);
}
function JSException ( message, name, data ) {
this.message = message;
this.name = name;
this.code = Components.results[name];
this.location = 0;
this.data = (data) ? data : null;
this.initialize = new Function();
this.toString = new Function ( "return this.message" );
}
function TryIt(s) {
try {
eval(s);
} catch (e) {
Enumerate(e);
}
}

View File

@ -1,297 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Try to throw a bunch of errors. Corresponds to
* the xpcTestCallJS in xpctest_calljs.cpp
*
*/
StartTest( "Evaluate JavaScript Throw Expressions" );
SetupTest();
AddTestData();
AddTestComment();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/CallJS;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestCallJS;
ERROR = Components.results;
caller = CLASS.QueryInterface(IFACE);
JSO = new Function();
JSO.prototype.Evaluate = new Function( "s",
"this.result = eval(s); return this.result" );
JSO.prototype.gotException = false;
JSO.prototype.exception = {};
JSO.prototype.EvaluateAndReturnError = new Function( "s", "r", "r = eval(s); return r;" );
// keep track of the errors we've tried to use.
ERRORS_WE_GOT = {};
for ( var p in Components.results ) {
ERRORS_WE_GOT[p] = false;
}
}
function AddTestData() {
var jso2 = new JSO();
jso2.Evaluate = new Function( "return NS_ERROR_XPC_JS_THREW_EXCEPTION" );
TestEvaluate(
"3",
undefined,
true,
"NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS",
jso2 );
/*
* Throw args based on the number of args
*/
TestEvaluateArgs(
[],
undefined,
true,
"NS_ERROR_XPC_NOT_ENOUGH_ARGS" );
TestEvaluateArgs(
[3,2],
3,
false);
/*
* Set the JSOobject to something that is not an instance of nsIXPCTestCallJS
*
*/
TestSetJSObject(
true,
undefined,
true,
"NS_ERROR_XPC_BAD_CONVERT_JS");
}
function TestEvaluate (evalArg, eResult, eGotException, eExceptionName, jso ) {
if ( !jso )
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.Evaluate(evalArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateToString (evalArg, outArg, eResult, eGotException, eExceptionName ) {
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.EvaluateToString(evalArg, outArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); outArg ",
eResult,
outArg);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateArgs( argsArray, eResult, eGotException, eExceptionName ) {
var jso = new JSO;
caller.SetJSObject(jso);
try {
if ( argsArray.length > 0 ) {
eval( "caller.Evaluate("+argsArray.toString()+")" );
} else {
caller.Evaluate();
}
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"callerEvaluate(" +argsArray+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestSetJSObject( jso, eResult, eGotException, eExceptionName ) {
var exception = {};
var gotException = false;
var result;
try {
result = caller.SetJSObject( jso );
} catch (e) {
gotException = true;
exception = e;
} finally {
AddTestCase(
"caller.SetJSObject(" + jso +")",
eResult,
result );
AddTestCase(
"gotException? ",
eGotException,
gotException);
AddTestCase(
"exception.name",
eExceptionName,
exception.name );
if ( gotException ) {
ERRORS_WE_GOT[ exception.name ] = true;
}
}
}
function AddTestComment() {
var s = "This test exercised the exceptions defined in "+
"Components.results. The following errors were not exercised:\n";
for ( var p in ERRORS_WE_GOT ) {
if ( ERRORS_WE_GOT[p] == false ) {
s += p +"\n";
}
}
AddComment(s);
}
function JSException ( message, name, data ) {
this.message = message;
this.name = name;
this.result = Components.results[name];
this.location = 0;
this.data = (data) ? data : null;
this.initialize = new Function();
this.toString = new Function ( "return this.message" );
}
function TryIt(s) {
try {
eval(s);
} catch (e) {
Enumerate(e);
}
}

View File

@ -1,343 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Try to throw a bunch of errors. Corresponds to
* the xpcTestCallJS in xpctest_calljs.cpp
*
*/
StartTest( "Evaluate JavaScript Throw Expressions" );
SetupTest();
AddTestData();
AddTestComment();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/CallJS;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestCallJS;
ERROR = Components.results;
caller = CLASS.QueryInterface(IFACE);
JSO = new Function();
JSO.prototype.Evaluate = new Function( "s",
"this.result = eval(s); return this.result" );
JSO.prototype.gotException = false;
JSO.prototype.exception = {};
JSO.prototype.EvaluateAndReturnError = new Function( "s", "r", "r = eval(s); return r;" );
// keep track of the errors we've tried to use.
ERRORS_WE_GOT = {};
for ( var p in Components.results ) {
ERRORS_WE_GOT[p] = false;
}
}
function AddTestData() {
TestEvaluate( "3", 3, false);
TestEvaluate( "undefined", undefined, false );
TestEvaluate(
"throw -1",
undefined,
true,
null );
TestEvaluate(
"throw \'An error occurred.\'",
undefined,
true,
"NS_ERROR_XPC_JS_THREW_STRING" );
TestEvaluate(
"throw {}",
undefined,
true,
"NS_ERROR_XPC_JS_THREW_JS_OBJECT" );
TestEvaluate(
"throw 0",
undefined,
true,
"NS_ERROR_FAILURE" );
TestEvaluate(
"throw 1",
undefined,
true,
"NS_ERROR_FAILURE" );
TestEvaluate(
"throw Components.results['NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT']",
undefined,
true,
"NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS" );
TestEvaluate(
"throw {message:\"error message\"}",
undefined,
true,
"NS_ERROR_XPC_JS_THREW_JS_OBJECT" );
TestEvaluate(
"throw null",
undefined,
true,
"NS_ERROR_XPC_JS_THREW_NULL" );
TestEvaluate(
"throw new JSException( \"error message\", \"NS_ERROR_XPC_CANT_SET_OUT_VAL\", true)",
undefined,
true,
"NS_ERROR_XPC_CANT_SET_OUT_VAL");
TestEvaluate(
"throw caller",
undefined,
true,
"NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT" );
TestEvaluate(
"boo",
undefined,
true,
"NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS");
/*
* second argument is the out object. should throw an exception since the
* out argument needs to be an object.
*/
if (0) {
TestEvaluateToString(
1,
true,
undefined,
true,
"NS_ERROR_XPC_NEED_OUT_OBJECT" );
}
}
function TestEvaluate (evalArg, eResult, eGotException, eExceptionName, jso ) {
if ( !jso )
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.Evaluate(evalArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"caller.Evaluate(" +evalArg+ "); jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateToString (evalArg, outArg, eResult, eGotException, eExceptionName ) {
var jso = new JSO();
caller.SetJSObject(jso);
try {
caller.EvaluateToString(evalArg, outArg);
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); jso.result ",
eResult,
jso.result);
AddTestCase(
"caller.EvaluateToString(" +evalArg+","+outArg+"); outArg ",
eResult,
outArg);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestEvaluateArgs( argsArray, eResult, eGotException, eExceptionName ) {
var jso = new JSO;
caller.SetJSObject(jso);
try {
if ( argsArray.length > 0 ) {
eval( "caller.Evaluate("+argsArray.toString()+")" );
} else {
caller.Evaluate();
}
} catch (e) {
jso.gotException = true;
jso.exception = e;
} finally {
AddTestCase(
"callerEvaluate(" +argsArray+ "); jso.result ",
eResult,
jso.result);
AddTestCase(
"jso.gotException ",
eGotException,
jso.gotException );
AddTestCase(
"jso.exception.result",
Components.results[eExceptionName],
jso.exception.result );
AddTestCase(
"jso.exception.name",
eExceptionName,
jso.exception.name );
if ( jso.gotException ) {
ERRORS_WE_GOT[ jso.exception.name ] = true;
}
}
}
function TestSetJSObject( jso, eResult, eGotException, eExceptionName ) {
var exception = {};
var gotException = false;
var result;
try {
result = caller.SetJSObject( jso );
} catch (e) {
gotException = true;
exception = e;
} finally {
AddTestCase(
"caller.SetJSObject(" + jso +")",
eResult,
result );
AddTestCase(
"gotException? ",
eGotException,
gotException);
AddTestCase(
"exception.name",
eExceptionName,
exception.name );
if ( gotException ) {
ERRORS_WE_GOT[ exception.name ] = true;
}
}
}
function AddTestComment() {
var s = "This test exercised the exceptions defined in "+
"Components.results. The following errors were not exercised:\n";
for ( var p in ERRORS_WE_GOT ) {
if ( ERRORS_WE_GOT[p] == false ) {
s += p +"\n";
}
}
AddComment(s);
}
function JSException ( message, name, data ) {
this.message = message;
this.name = name;
this.result = Components.results[name];
this.location = 0;
this.data = (data) ? data : null;
this.initialize = new Function();
this.toString = new Function ( "return this.message" );
}
function TryIt(s) {
try {
eval(s);
} catch (e) {
Enumerate(e);
}
}

View File

@ -1,230 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test the in keyword. See xpctest_in.cpp and xpctest_in.idl for
* function names and parameters.
*/
StartTest( "Exceptions" );
var CLASS = Components.classes["@mozilla.org/js/xpc/test/Echo;1"];
var IFACE = Components.interfaces.nsIEcho;
var nativeEcho = CLASS.createInstance(IFACE);
var localEcho = {
SendOneString : function() {throw this.result;},
result : 0
};
nativeEcho.SetReceiver(localEcho);
PASS = "PASSED!";
FAIL = "FAILED!";
var result = PASS;
var error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
error = e;
result = FAIL;
}
AddTestCase(
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = new Components.Exception("hi", Components.results.NS_ERROR_ABORT);
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
}
AddTestCase(
"localEcho.result = new Components.Exception(\"hi\")," +
"Components.results.NS_ERROR_ABORT);"+
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = {message : "pretending to be NS_OK", result : 0};
result = PASS;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
error = e;
result = FAIL;
}
AddTestCase(
"localEcho.result = {message : \"pretending to be NS_OK\", result : 0};"+
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = {message : "pretending to be NS_ERROR_NO_INTERFACE",
result : Components.results.NS_ERROR_NO_INTERFACE};
result = PASS;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
error = e;
result = PASS;
}
AddTestCase(
"localEcho.result = {message : \"pretending to be NS_ERROR_NO_INTERFACE\", "+
"result : Components.results.NS_ERROR_NO_INTERFACE};"+
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = "just a string";
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.result = localEcho.result = \"just a string\";"+
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = Components.results.NS_ERROR_NO_INTERFACE;
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.result = Components.results.NS_ERROR_NO_INTERFACE;" +
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = "NS_OK";
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.result = \"NS_OK\"" +
"nativeEcho.SendOneString(\"foo\");" + error,
PASS,
result );
localEcho.result = Components;
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.result = Components;" +
"nativeEcho.sendOneString(\"foo\") " + error,
PASS,
result);
/* make this function have a JS runtime error */
localEcho.SendOneString = function(){return Components.foo.bar;};
result = FAIL;
error = "";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.SendOneString = function(){return Components.foo.bar;};" +
"nativeEcho.sendOneString(\"foo\") " + error,
PASS,
result);
/* make this function have a JS compiletime error */
localEcho.SendOneString = function(){new Function("","foo ===== 1")};
result = FAIL;
error = ""
try {
nativeEcho.SendOneString("foo");
} catch(e) {
result = PASS;
error = e;
}
AddTestCase(
"localEcho.SendOneString = function(){new Function(\"\",\"foo ===== 1\")};" +
"nativeEcho.sendOneString(\"foo\") " + error,
PASS,
result);
StopTest();

View File

@ -1,96 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Get and set properties on a XPCOM object and verify that they are
* JavaScripty.
*
*/
StartTest( "Get and Set Properties on a native object" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/ObjectReadWrite;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestObjectReadWrite;
testObject = CLASS.QueryInterface(IFACE);
}
function AddTestData() {
// add a property to the object.
testObject.newProperty = "PASS",
AddTestCase(
"testObject.newProperty = \"PASS\"; testObject.newProperty",
"PASS",
testObject.newProperty );
// delete a property from an object
var result = delete testObject.newProperty;
AddTestCase(
"delete testObject.newProperty",
true,
result );
AddTestCase(
"delete testObject.newProperty; testObject.newProperty",
undefined,
testObject.newProperty );
// add a function
testObject.newFunction = new Function( "return \"PASSED\"" );
AddTestCase(
"testObject.newFunction = new Function(\"return 'PASSED'\"); " +
"typeof testObject.newFunction",
"function",
typeof testObject.newFunction );
var s = "testObject.newFunction()"
AddTestCase(
"testObject.newFunction()",
"PASSED",
eval(s));
}

View File

@ -1,151 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test classes that inherit from multiple interfaces. This differs
* from classes that inherit from interfaces other than nsISupports,
* in that you can't have an object with all the
*
* See xpctest_multiple.idl and xpctest_multiple.cpp.
*/
StartTest( "Classes that inherit from multiple interfaces" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
try {
// xpcTestChild2 inherits from nsIXPCTestChild2 nsIXPCTestParentOne,
// and nsIXPCTestParentTwo but implements all the interfaces itself
iChild = Components.interfaces.nsIXPCTestChild2;
iParentOne = Components.interfaces.nsIXPCTestParentOne;
iParentTwo = Components.interfaces.nsIXPCTestParentTwo;
CONTRACTID = "@mozilla.org/js/xpc/test/Child2;1";
cChild = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentOne;1";
cParentOne = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentTwo;1";
cParentTwo = Components.classes[CONTRACTID].createInstance();
c_c2 = cChild.QueryInterface(iChild);
c_p1 = cChild.QueryInterface(iParentOne);
c_p2 = cChild.QueryInterface(iParentTwo);
parentOne = cParentOne.QueryInterface(iParentOne);
parentTwo = cParentTwo.QueryInterface(iParentTwo);
} catch (e) {
WriteLine(e);
AddTestCase(
"Setting up the test",
"PASSED",
"FAILED: " + e.message +" "+ e.location +". ");
}
}
function AddTestData() {
Check( cChild, "@mozilla.org/js/xpc/test/Child2;1", c_c2);
Check( parentOne, "@mozilla.org/js/xpc/test/Child2;1", c_p1);
Check( parentTwo, "@mozilla.org/js/xpc/test/Child2;1", c_p2);
}
function Check( parent, parentName, child) {
// child should have all the properties and methods of parentOne
parentProps = {};
for ( p in parent ) parentProps[p] = true;
for ( p in child ) if ( parentProps[p] ) parentProps[p] = false;
for ( p in parentProps ) {
AddTestCase(
"child has property " + p,
true,
(parentProps[p] ? false : true )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName+" attribute",
child[p] );
}
}
var result = true;
for ( p in parentProps ) {
if ( parentProps[p] == true )
result == false;
}
AddTestCase(
"child has all parent properties?",
true,
result );
for ( p in child ) {
AddTestCase(
"child has property " + p,
true,
(child[p] ? true : false )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName +" attribute",
child[p] );
}
}
}

View File

@ -1,148 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test classes that inherit from multiple interfaces. This differs
* from classes that inherit from interfaces other than nsISupports,
* in that you can't have an object with all the
*
* See xpctest_multiple.idl and xpctest_multiple.cpp.
*/
StartTest( "Classes that inherit from other implemenations" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
try {
iChild = Components.interfaces.nsIXPCTestChild4;
iParentOne = Components.interfaces.nsIXPCTestParentOne;
iParentTwo = Components.interfaces.nsIXPCTestParentTwo;
CONTRACTID = "@mozilla.org/js/xpc/test/Child4;1";
cChild = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentOne;1";
cParentOne = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentTwo;1";
cParentTwo = Components.classes[CONTRACTID].createInstance();
c_c4 = cChild.QueryInterface(iChild);
c_p1 = cChild.QueryInterface(iParentOne);
c_p2 = cChild.QueryInterface(iParentTwo);
parentOne = cParentOne.QueryInterface(iParentOne);
parentTwo = cParentTwo.QueryInterface(iParentTwo);
} catch (e) {
WriteLine(e);
AddTestCase(
"Setting up the test",
"PASSED",
"FAILED: " + e.message +" "+ e.location +". ");
}
}
function AddTestData() {
Check( parentOne, "@mozilla.org/js/xpc/test/ParentOne;1", c_p1 );
Check( parentTwo, "@mozilla.org/js/xpc/test/ParentTwo;1", c_p2 );
Check( cChild, "@mozilla.org/js/xpc/test/Child4;1", c_c4 );
}
function Check(parent,parentName,child) {
// child should have all the properties and methods of parentOne
parentProps = {};
for ( p in parent ) parentProps[p] = true;
for ( p in child ) if ( parent[p] ) parentProps[p] = false;
for ( p in parentProps ) {
AddTestCase(
"child has property " + p,
true,
(parentProps[p] ? false : true )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName +" attribute",
child[p] );
}
}
var result = true;
for ( p in parentProps ) {
if ( parentProps[p] == true )
result == false;
}
AddTestCase(
"child has all parent properties?",
true,
result );
for ( p in child ) {
AddTestCase(
"child has property " + p,
true,
(child[p] ? true : false )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName +" attribute",
child[p] );
}
}
}

View File

@ -1,152 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test classes that inherit from multiple interfaces. This differs
* from classes that inherit from interfaces other than nsISupports,
* in that you can't have an object with all the
*
* See xpctest_multiple.idl and xpctest_multiple.cpp.
*/
StartTest( "More inheritance tests" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
try {
// xpcTestChild5 inherits from nsIXPCTestChild5 (which inherits from
// nsIXPCTestParentOne) and xpcTestParentOne. so instances of
// xpcTestChild5 need to QueryInterface nsIXPCTestChild5 to get
// ParentOne methods, and nsIXPCTestParentTwo for ParentTwo methods.
iChild = Components.interfaces.nsIXPCTestChild5;
iParentOne = Components.interfaces.nsIXPCTestParentOne;
iParentTwo = Components.interfaces.nsIXPCTestParentTwo;
CONTRACTID = "@mozilla.org/js/xpc/test/Child5;1";
cChild = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentOne;1";
cParentOne = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentTwo;1";
cParentTwo = Components.classes[CONTRACTID].createInstance();
c_c5 = cChild.QueryInterface(iChild);
c_p2 = cChild.QueryInterface(iParentTwo);
parentOne = cParentOne.QueryInterface(iParentOne);
parentTwo = cParentTwo.QueryInterface(iParentTwo);
} catch (e) {
WriteLine(e);
AddTestCase(
"Setting up the test",
"PASSED",
"FAILED: " + e.message +" "+ e.location +". ");
}
}
function AddTestData() {
Check( parentOne, "@mozilla.org/js/xpc/test/Child5;1", c_c5 );
Check( cChild, "@mozilla.org/js/xpc/test/Child5;1", c_c5 );
Check( parentTwo, "@mozilla.org/js/xpc/test/ParentTwo;1", c_p2 );
}
function Check(parent,parentName,child) {
// child should have all the properties and methods of parentOne
parentProps = {};
for ( p in parent ) parentProps[p] = true;
for ( p in child ) if ( parent[p] ) parentProps[p] = false;
for ( p in parentProps ) {
AddTestCase(
"child has property " + p,
true,
(parentProps[p] ? false : true )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName +" attribute",
child[p] );
}
}
var result = true;
for ( p in parentProps ) {
if ( parentProps[p] == true )
result == false;
}
AddTestCase(
"child has all parent properties?",
true,
result );
for ( p in child ) {
AddTestCase(
"child has property " + p,
true,
(child[p] ? true : false )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
parentName +" method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
parentName +" attribute",
child[p] );
}
}
}

View File

@ -1,137 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test interfaces that inherit from interfaces other than nsISupports
* and classes that inherit from multiple interfaces.
*
* See xpctest_multiple.idl and xpctest_multiple.cpp.
*/
StartTest( "Interfaces that inherit from interfaces other than nsISupports" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
try {
iChild = Components.interfaces.nsIXPCTestChild3;
iParentOne = Components.interfaces.nsIXPCTestParentOne;
CONTRACTID = "@mozilla.org/js/xpc/test/Child3;1";
cChild = Components.classes[CONTRACTID].createInstance();
CONTRACTID = "@mozilla.org/js/xpc/test/ParentOne;1";
cParentOne = Components.classes[CONTRACTID].createInstance();
child = cChild.QueryInterface(iChild);
parentOne = cParentOne.QueryInterface(iParentOne);
} catch (e) {
WriteLine(e);
AddTestCase(
"Setting up the test",
"PASSED",
"FAILED: " + e.message +" "+ e.location +". ");
}
}
function AddTestData() {
// child should have all the properties and methods of parentOne
parentOneProps = {};
for ( p in parentOne ) parentOneProps[p] = true;
for ( p in child ) if ( parentOneProps[p] ) parentOneProps[p] = false;
for ( p in parentOneProps ) {
print( p );
AddTestCase(
"child has property " + p,
true,
(parentOneProps[p] ? false : true )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
"@mozilla.org/js/xpc/test/Child3;1 method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
"@mozilla.org/js/xpc/test/Child3;1 attribute",
child[p] );
}
}
var result = true;
for ( p in parentOneProps ) {
if ( parentOneProps[p] = true )
result == false;
}
AddTestCase(
"child has parentOne properties?",
true,
result );
for ( p in child ) {
AddTestCase(
"child has property " + p,
true,
(child[p] ? true : false )
);
if ( p.match(/Method/) ) {
AddTestCase(
"child."+p+"()",
"@mozilla.org/js/xpc/test/Child3;1 method",
child[p]() );
} else if (p.match(/Attribute/)) {
AddTestCase(
"child." +p,
"@mozilla.org/js/xpc/test/Child3;1 attribute",
child[p] );
}
}
}

View File

@ -1,104 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Get and set properties on a XPCOM object and verify that they are
* JavaScripty.
*
*/
StartTest( "Get and Set Properties on a native object that is not scriptable" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/ObjectReadWrite;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestObjectReadWrite;
testObject = CLASS.QueryInterface(IFACE);
}
function AddTestData() {
// add a property to the object.
testObject.newProperty = "PASS",
AddTestCase(
"testObject.newProperty = \"PASS\"; testObject.newProperty",
undefined,
testObject.newProperty );
// delete a property from an object
var result = delete testObject.newProperty;
AddTestCase(
"delete testObject.newProperty",
false,
result );
AddTestCase(
"delete testObject.newProperty; testObject.newProperty",
undefined,
testObject.newProperty );
// add a function
testObject.newFunction = new Function( "return \"PASSED\"" );
AddTestCase(
"testObject.newFunction = new Function(\"return 'PASSED'\"); " +
"typeof testObject.newFunction",
"undefined",
typeof testObject.newFunction );
// delete the function
result = delete testObject.newFunction;
AddTestCase(
"delete testObject.newFunction",
false,
result);
AddTestCase(
"typeof testObject.newFunction",
"undefined",
typeof testObject.newFunction);
}

View File

@ -1,36 +0,0 @@
print("Components.interfaces.nsIJSID = " +
Components.interfaces.nsIJSID);
print("Components = " +
Components);
print("Components.interfaces = " +
Components.interfaces);
print("Components.interfaces.nsISupports = " +
Components.interfaces.nsISupports);
print("Components.interfaces.nsISupports.name = " +
Components.interfaces.nsISupports.name);
print("Components.interfaces.nsISupports.number = " +
Components.interfaces.nsISupports.number);
print("Components.interfaces.nsISupports.id = " +
Components.interfaces.nsISupports.id);
print("Components.interfaces.nsISupports.valid = " +
Components.interfaces.nsISupports.valid);
var id1 = Components.interfaces.nsISupports;
var id2 = Components.interfaces.nsISupports;
var id3 = Components.interfaces.nsISupports.id;
print("identity test "+ (id1 == id2 ? "passed" : "failed"));
print("non-identity test "+ (id1 != id3 ? "passed" : "failed"));
print("equality test "+ (id1.equals(id2) ? "passed" : "failed"));
var NS_ISUPPORTS_IID = new Components.ID("{00000000-0000-0000-c000-000000000046}");
print("NS_ISUPPORTS_IID = " + NS_ISUPPORTS_IID);

View File

@ -1,60 +0,0 @@
print(".......................................");
print("simple speed tests...");
var iterations = 1000;
var receiver2 = new Object();
receiver2.SetReceiver = function() {};
receiver2.SendOneString = function(str) {/*print(str);*/};
var echoJS = new Object();
echoJS.SetReceiver = function(r) {this.r = r;};
echoJS.SendOneString = function(str) {if(this.r)this.r.SendOneString(str)};
echoJS.SimpleCallNoEcho = function(){}
/*********************************************/
/*********************************************/
print("\nEcho.SimpleCallNoEcho (just makes call with no params and no callback)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
/*
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
*/
/*********************************************/
print("\nEcho.SendOneString (calls a callback that does a call)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
/*
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
*/
print(".......................................");
echoJS.SetReceiver(null);

View File

@ -1,464 +0,0 @@
// tests...
var nsID = Components.ID;
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
var baz = foo.QueryInterface(NS_ITESTXPC_FOO_IID);
print("baz = "+baz);
print("distinct wrapper test "+ (foo != baz ? "passed" : "failed"));
var baz2 = foo.QueryInterface(NS_ITESTXPC_FOO_IID);
print("shared wrapper test "+ (baz == baz2 ? "passed" : "failed"));
print("root wrapper identity test "+
(foo.QueryInterface(NS_ISUPPORTS_IID) ==
baz.QueryInterface(NS_ISUPPORTS_IID) ?
"passed" : "failed"));
print("foo = "+foo);
foo.toString = new Function("return 'foo toString called';")
foo.toStr = new Function("return 'foo toStr called';")
print("foo = "+foo);
print("foo.toString() = "+foo.toString());
print("foo.toStr() = "+foo.toStr());
print("foo.five = "+ foo.five);
print("foo.six = "+ foo.six);
print("foo.bogus = "+ foo.bogus);
print("setting bogus explicitly to '5'...");
foo.bogus = 5;
print("foo.bogus = "+ foo.bogus);
print("foo.Test(10,20) returned: "+foo.Test(10,20));
function _Test(p1, p2)
{
print("test called in JS with p1 = "+p1+" and p2 = "+p2);
return p1+p2;
}
function _QI(iid)
{
print("QueryInterface called in JS with iid = "+iid);
return this;
}
print("creating bar");
bar = new Object();
bar.Test = _Test;
bar.QueryInterface = _QI;
// this 'bar' object is accessed from native code after this script is run
var some_string = "some string"
foo.Foo = some_string;
print("property set/get: "+ (foo.Foo == some_string ? "passed" : "FAILED"));
print("foo properties:");
for(i in foo)
print(" foo."+i+" = "+foo[i]);
print("Components = "+Components);
print("Components properties:");
for(i in Components)
print(" Components."+i+" = "+Components[i]);
/***************************************************************************/
print(".......................................");
print("echo tests...");
var receiver = new Object();
receiver.SetReceiver = function() {};
receiver.SendOneString = function(str) {receiver_results[0] = str;};
receiver.SendManyTypes = function()
{
for(var i = 0; i < arguments.length; i++)
receiver_results[i] = arguments[i];
};
echo.SetReceiver(receiver);
////////////////////
// SendOneString
var test_string = "some string";
var receiver_results = new Object();
echo.SendOneString(test_string);
print("SendOneString - "+(
receiver_results[0] == test_string
? "passed" : "failed"));
////////////////////
// In2OutOneInt
print("In2OutOneInt - "+(
echo.In2OutOneInt(102) == 102
? "passed" : "failed"));
////////////////////
// In2OutAddTwoInts
var in_out_results1 = new Object();
var in_out_results2 = new Object();
var in_out_results =
echo.In2OutAddTwoInts(123, 55, in_out_results1, in_out_results2);
print("In2OutAddTwoInts - "+(
in_out_results1.value == 123 &&
in_out_results2.value == 55 &&
in_out_results == 178
? "passed" : "failed"));
var test_string2 = "some other string";
print("In2OutOneString - "+(
echo.In2OutOneString(test_string2) == test_string2 &&
echo.In2OutOneString(echo.In2OutOneString(test_string2)) == test_string2
? "passed" : "failed"));
////////////////////
// SendManyTypes
var receiver_results = new Object();
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
echo.SendManyTypes(send_params[0],
send_params[1],
send_params[2],
send_params[3],
send_params[4],
send_params[5],
send_params[6],
send_params[7],
send_params[8],
send_params[9],
send_params[10],
send_params[11],
send_params[12],
send_params[13],
send_params[14],
send_params[15]);
var all_ok = true;
for(i = 0; i < 16; i++) {
if(((""+receiver_results[i]).toLowerCase()) !=
((""+send_params[i]).toLowerCase())) {
if(all_ok)
print("SendManyTypes - failed...");
all_ok = false;
print(" param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i])
}
}
if(all_ok)
print("SendManyTypes - passed");
////////////////////
// SendInOutManyTypes
var receiver_results = new Object();
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
var resend_params = [2,-3,-7,-10220,18,14,16,123,2.5,8.000008,false,'z','l',NS_ISUPPORTS_IID,"foo string","yet another string"];
receiver.SendInOutManyTypes = function()
{
for(var i = 0; i < arguments.length; i++) {
receiver_results[i] = arguments[i].value;
arguments[i].value = resend_params[i];
}
};
var inout_params = [{value:send_params[0] },
{value:send_params[1] },
{value:send_params[2] },
{value:send_params[3] },
{value:send_params[4] },
{value:send_params[5] },
{value:send_params[6] },
{value:send_params[7] },
{value:send_params[8] },
{value:send_params[9] },
{value:send_params[10]},
{value:send_params[11]},
{value:send_params[12]},
{value:send_params[13]},
{value:send_params[14]},
{value:send_params[15]}];
echo.SendInOutManyTypes(inout_params[0] ,
inout_params[1] ,
inout_params[2] ,
inout_params[3] ,
inout_params[4] ,
inout_params[5] ,
inout_params[6] ,
inout_params[7] ,
inout_params[8] ,
inout_params[9] ,
inout_params[10],
inout_params[11],
inout_params[12],
inout_params[13],
inout_params[14],
inout_params[15]);
var all_ok = true;
for(i = 0; i < 16; i++) {
if(((""+receiver_results[i]).toLowerCase()) !=
((""+send_params[i]).toLowerCase())) {
if(all_ok)
print("SendInOutManyTypes - failed...");
all_ok = false;
print(" sent param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i]);
}
}
for(i = 0; i < 16; i++) {
if(((""+resend_params[i]).toLowerCase()) !=
((""+inout_params[i].value).toLowerCase())) {
if(all_ok)
print("SendInOutManyTypes - failed...");
all_ok = false;
print(" resent param number "+i+" diff: "+resend_params[i]+" -> "+inout_params[i].value);
}
}
if(all_ok)
print("SendInOutManyTypes - passed");
////////////////////
// check exceptions on xpcom error code
try {
echo.ReturnCode(0);
print("ReturnCode(0) - passed");
}
catch(e) {
print("ReturnCode(0) exception text: "+e+" - failed");
}
try {
echo.ReturnCode(-1);
print("ReturnCode(-1) - failed");
}
catch(e) {
// print("ReturnCode(-1) exception text: "+e+" - passed");
print("ReturnCode(-1) - passed");
}
var all_ok = true;
echo.ReturnCode_NS_OK()
var lastResult = Components.lastResult;
if(Components.results.NS_OK != lastResult) {
all_ok = false;
print("expected: NS_OK = "+Components.results.NS_OK+" got: "+lastResult);
}
try {
echo.ReturnCode_NS_ERROR_NULL_POINTER()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_NULL_POINTER = "+Components.results.NS_ERROR_NULL_POINTER+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_NULL_POINTER != lastResult) {
all_ok = false;
print("expected: NS_ERROR_NULL_POINTER = "+Components.results.NS_ERROR_NULL_POINTER+" got: "+lastResult);
}
}
try {
echo.ReturnCode_NS_ERROR_UNEXPECTED()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_UNEXPECTED = "+Components.results.NS_ERROR_UNEXPECTED+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_UNEXPECTED != lastResult) {
all_ok = false;
print("expected: NS_ERROR_UNEXPECTED = "+Components.results.NS_ERROR_UNEXPECTED+" got: "+lastResult);
}
}
try {
echo.ReturnCode_NS_ERROR_OUT_OF_MEMORY()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_OUT_OF_MEMORY = "+Components.results.NS_ERROR_OUT_OF_MEMORY+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_OUT_OF_MEMORY != lastResult) {
all_ok = false;
print("expected: NS_ERROR_OUT_OF_MEMORY = "+Components.results.NS_ERROR_OUT_OF_MEMORY+" got: "+lastResult);
}
}
print("Components.lastResult test - "+ (all_ok ? "passed" : "failed") );
////////////////////
// check exceptions on too few args
try {
echo.ReturnCode(); // supposed to have one arg
print("Too few args test - failed");
}
catch(e) {
// print("Too few args test -- exception text: "+e+" - passed");
print("Too few args test - passed");
}
////////////////////
// check exceptions on can't convert
// XXX this is bad test since null is now convertable.
/*
try {
echo.SetReceiver(null);
// print("Can't convert arg to Native ("+out+")- failed");
print("Can't convert arg to Native - failed");
}
catch(e) {
// print("Can't convert arg to Native ("+e+") - passed");
print("Can't convert arg to Native - passed");
}
*/
////////////////////
// FailInJSTest
var receiver3 = new Object();
receiver3.SetReceiver = function() {};
receiver3.FailInJSTest = function(fail) {if(fail)throw("");};
echo.SetReceiver(receiver3);
var all_ok = true;
try {
echo.FailInJSTest(false);
}
catch(e) {
print("FailInJSTest - failed");
all_ok = false;
}
try {
echo.FailInJSTest(true);
print("FailInJSTest - failed");
all_ok = false;
}
catch(e) {
}
if(all_ok)
print("FailInJSTest - passed");
/***************************************************************************/
all_ok = echo.SharedString() == "a static string";
print("[shared] test - "+(all_ok ? "passed" : "failed"));
/***************************************************************************/
var e1 = new Object();
var e2 = new Object();
var v1 = new Object();
var v2 = new Object();
var v3 = new Object();
var v4 = new Object();
echo.SetReceiver(null);
all_ok = true;
v1.value = e1;
echo.SetReceiverReturnOldReceiver(v1);
all_ok = all_ok && v1.value == null;
v2.value = e2;
echo.SetReceiverReturnOldReceiver(v2);
all_ok = all_ok && v2.value == e1;
v3.value = null;
echo.SetReceiverReturnOldReceiver(v3);
all_ok = all_ok && v3.value == e2;
v4.value = e1;
echo.SetReceiverReturnOldReceiver(v4);
all_ok = all_ok && v4.value == null;
print("inout of interface tests - "+
(all_ok ? "passed" : "failed"));
echo.SetReceiver(null);
/***************************************************************************/
try {
echo.MethodWithForwardDeclaredParam(new Object());
print("method with forward declared param test - passed");
} catch(e) {
print("method with forward declared param test - failed");
}
/***************************************************************************/
print(".......................................");
print("simple speed tests...");
var iterations = 1000;
var receiver2 = new Object();
receiver2.SetReceiver = function() {};
receiver2.SendOneString = function(str) {/*print(str);*/};
var echoJS = new Object();
echoJS.SetReceiver = function(r) {this.r = r;};
echoJS.SendOneString = function(str) {if(this.r)this.r.SendOneString(str)};
echoJS.SimpleCallNoEcho = function(){}
/*********************************************/
/*********************************************/
print("\nEcho.SimpleCallNoEcho (just makes call with no params and no callback)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
/*********************************************/
print("\nEcho.SendOneString (calls a callback that does a call)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
print(".......................................");
echoJS.SetReceiver(null);
echo.SetReceiver(null);

View File

@ -1,27 +0,0 @@
var name = "@mozilla.org/messenger/server;1?type=pop3";
try {
var foo = Components.classes[name].createInstance();
print(foo);
print(name);
for(p in Components.interfaces) {
try {
iface = foo.QueryInterface(Components.interfaces[p]);
if(typeof(iface) == 'undefined')
continue;
print("\t"+p);
for(m in iface) {
print("\t\t"+m+" = "+typeof(iface[m]));
}
} catch(e) {
}
}
foo = null;
gc();
} catch(e) {
print("caught+e");
}

View File

@ -1,308 +0,0 @@
var iface = Components.interfaces.nsIXPCTestArray;
var clazz = Components.classes["@mozilla.org/js/xpc/test/ArrayTest;1"];
var obj = clazz.createInstance(iface);
var a = [-1,0,1,2,3,4,5,4,3,2,1,0,-1]
obj.PrintIntegerArray(a.length, a);
var b = ["this","is","an","array"];
obj.PrintStringArray(b.length, b);
var o = {
value : [1,2,3,4]
};
obj.MultiplyEachItemInIntegerArray(2, o.value.length, o);
print(o.value);
var len = {
value : o.value.length
};
obj.MultiplyEachItemInIntegerArrayAndAppend(2, len, o);
print(o.value+" : "+len.value);
var strs = {
value : ["this","is","to","be", "reversed"]
};
obj.ReverseStringArray(strs.value.length, strs);
print(strs.value);
var strs2 = {
value : ["double","me","please"]
};
var strslen2 = {
value : strs2.value.length
};
obj.DoubleStringArray(strslen2, strs2);
print(strs2.value);
print("-------------------------------------------");
var ech = {
SendOneString : function(s) {
print(s);
}
};
var iid = {
value : Components.interfaces.nsIEcho
};
var count = {
value : 3
};
var ifaces = {
value : [ech, ech, ech]
};
print("calling from JS...");
obj.CallEchoMethodOnEachInArray(iid, count, ifaces);
print(iid.value.equals(iface));
print(count.value);
for(i = 0; i < count.value; i++)
ifaces.value[i].PrintIntegerArray(a.length, a);
print("-------------------------------------------");
print("-------------------------------------------");
print("-------------------------------------------");
print("-------------------------------------------");
var jsobj = {
PrintIntegerArray : function(len, a) {
print("["+a+"]"+" : "+len);
},
PrintStringArray : function(len, a) {
print("["+a+"]"+" : "+len);
},
MultiplyEachItemInIntegerArray : function(val, len, a) {
for(var i = 0; i < len; i++)
a.value[i] *= val;
},
MultiplyEachItemInIntegerArrayAndAppend : function(val, len, a) {
var out = new Array(len.value*2);
for(var i = 0; i < len.value; i++)
{
out[i*2] = a.value[i];
out[i*2+1] = a.value[i] * val;
}
len.value *= 2;
a.value = out;
},
ReverseStringArray : function(len, a) {
for(var i = 0; i < len/2; i++) {
var temp = a.value[i];
a.value[i] = a.value[len-1-i];
a.value[len-1-i] = temp;
}
},
DoubleStringArray : function(len, a) {
var outArray = new Array();
for(var i = 0; i < len.value; i++) {
var inStr = a.value[i];
var outStr = new String();
for(var k = 0; k < inStr.length; k++) {
outStr += inStr[k];
outStr += inStr[k];
}
outArray.push(outStr);
outArray.push(outStr);
}
len.value *= 2;
a.value = outArray;
},
CallEchoMethodOnEachInArray : function(uuid, count, result) {
if(!Components.interfaces.nsIEcho.equals(uuid.value))
throw Components.results.NS_ERROR_FAILURE;
for(var i = 0; i < count.value; i++)
result.value[i].SendOneString("print this from JS");
uuid.value = Components.interfaces.nsIXPCTestArray;
result.value = [this, this];
count.value = 2;
},
CallEchoMethodOnEachInArray2 : function(count, result) {
for(var i = 0; i < count.value; i++)
result.value[i].SendOneString("print this from JS");
result.value = [this, this];
count.value = 2;
},
PrintStringWithSize : function(len, a) {
print("\""+a+"\""+" ; "+len);
},
DoubleString : function(len, s) {
var out = "";
for(var k = 0; k < s.value.length; k++) {
out += s.value.charAt(k);
out += s.value.charAt(k);
}
len.value *= 2;
s.value = out;
},
QueryInterface : function(iid) {
// print("+++++QI called for "+iid);
if(iid.equals(Components.interfaces.nsIEcho)) {
// print("+++++QI matched nsIEcho");
return this;
}
if(iid.equals(Components.interfaces.nsISupports)) {
// print("+++++QI matched nsISupports");
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
obj.SetReceiver(jsobj);
var a = [-1,0,1,2,3,4,5,4,3,2,1,0,-1]
obj.PrintIntegerArray(a.length, a);
var b = ["this","is","an","array"];
obj.PrintStringArray(b.length, b);
var o = {
value : [1,2,3,4]
};
obj.MultiplyEachItemInIntegerArray(2, o.value.length, o);
print(o.value);
var len = {
value : o.value.length
};
obj.MultiplyEachItemInIntegerArrayAndAppend(2, len, o);
print(o.value+" : "+len.value);
var strs = {
value : ["this","is","to","be", "reversed"]
};
obj.ReverseStringArray(strs.value.length, strs);
print(strs.value);
var strs2 = {
value : ["double","me","please", "sir"]
};
var strslen2 = {
value : strs2.value.length
};
obj.DoubleStringArray(strslen2, strs2);
print(strs2.value);
print("-------------------------------------------");
var ech = {
SendOneString : function(s) {
print(s);
}
};
var iid = {
value : Components.interfaces.nsIEcho
};
var count = {
value : 3
};
var ifaces = {
value : [ech, ech, ech]
};
print("calling from JS to native to JS...");
obj.CallEchoMethodOnEachInArray(iid, count, ifaces);
print(iid.value.equals(iface));
print(count.value);
for(i = 0; i < count.value; i++)
ifaces.value[i].PrintIntegerArray(a.length, a);
print("-------------------------------------------");
print("-------------------------------------------");
count = {
value : 3
};
ifaces = {
value : [ech, ech, ech]
};
print("calling from JS to native to JS 2...");
obj.SetReceiver(null);
obj.CallEchoMethodOnEachInArray2(count, ifaces);
count = {
value : 3
};
ifaces = {
value : [ech, ech, ech]
};
obj.SetReceiver(jsobj);
obj.CallEchoMethodOnEachInArray2(count, ifaces);
print("-------------------------------------------");
obj.SetReceiver(null);
str = "This is a string";
obj.PrintStringWithSize(str.length, str);
obj.SetReceiver(jsobj);
obj.PrintStringWithSize(str.length, str);
var str2 = {value : "double me baby"};
var len2 = {value : str2.value.length};
obj.SetReceiver(null);
print("\""+str2.value+"\""+" : "+len2.value);
obj.DoubleString(len2, str2);
print("\""+str2.value+"\""+" : "+len2.value);
var str2 = {value : "double me baby"};
var len2 = {value : str2.value.length};
obj.SetReceiver(jsobj);
print("\""+str2.value+"\""+" ; "+len2.value);
obj.DoubleString(len2, str2);
print("\""+str2.value+"\""+" ; "+len2.value);
print("-------------------------------------------");
print("GetStrings test...");
obj.SetReceiver(null);
var count = {};
var strings = obj.GetStrings(count);
print("count = "+ count.value);
print("strings = "+ strings);
print("-----------------------");
var gs = {
GetStrings : function(count) {
var s = ['red', 'green', 'blue'];
count.value = s.length;
return s;
}
};
obj.SetReceiver(gs);
var count = {};
var strings = obj.GetStrings(count);
print("count = "+ count.value);
print("strings = "+ strings);
print("\n");

View File

@ -1,68 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* more xpconnect testing using the nsIEcho interface. */
function nsNativeEcho()
{
var clazz = Components.classes["@mozilla.org/js/xpc/test/Echo;1"];
var iface = Components.interfaces.nsIEcho;
return new clazz(iface);
}
var e = nsNativeEcho();
e.printArgTypes();
e.printArgTypes(1);
e.printArgTypes(1,2);
e.printArgTypes(null, new Object(), 1.1, undefined);
try {
e.throwArg(1);
} catch(e) {
print(e);
}
try {
e.throwArg("this is a string to throw");
} catch(e) {
print(e);
}

View File

@ -1,636 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* xpconnect testing using the nsIEcho interface. */
function nsNativeEcho()
{
var clazz = Components.classes["@mozilla.org/js/xpc/test/Echo;1"];
var iface = Components.interfaces.nsIEcho;
return new clazz(iface);
}
var nsID = Components.ID;
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
print();
print("Components = "+Components);
print("Components properties:");
print(Components.QueryInterface);
print();
for(i in Components)
print(" Components."+i+" = "+Components[i]);
/***************************************************************************/
print(".......................................");
print("echo tests...");
var echo = new nsNativeEcho();
var receiver = new Object();
receiver.SetReceiver = function() {};
receiver.SendOneString = function(str) {receiver_results[0] = str;};
receiver.SendManyTypes = function()
{
for(var i = 0; i < arguments.length; i++)
receiver_results[i] = arguments[i];
};
receiver.EchoIn2OutOneDOMString = function(input)
{
// print("EchoIn2OutOneDOMString called with: "+input);
return input;
};
receiver.EchoIn2OutOneAString = function(input)
{
// print("EchoIn2OutOneAString called with: "+input);
return input;
};
receiver.EchoIn2OutOneUTF8String = function(input)
{
// print("EchoIn2OutOneUTF8String called with: "+input);
return input;
}
receiver.EchoIn2OutOneCString = function(input)
{
// print("EchoIn2OutOneCString called with: "+input);
return input;
}
echo.SetReceiver(receiver);
////////////////////
// SendOneString
var test_string = "some string";
var receiver_results = new Object();
echo.SendOneString(test_string);
print("SendOneString - "+(
receiver_results[0] == test_string
? "passed" : "failed"));
////////////////////
// In2OutOneInt
print("In2OutOneInt - "+(
echo.In2OutOneInt(102) == 102
? "passed" : "failed"));
////////////////////
// In2OutAddTwoInts
var in_out_results1 = new Object();
var in_out_results2 = new Object();
var in_out_results =
echo.In2OutAddTwoInts(123, 55, in_out_results1, in_out_results2);
print("In2OutAddTwoInts - "+(
in_out_results1.value == 123 &&
in_out_results2.value == 55 &&
in_out_results == 178
? "passed" : "failed"));
var test_string2 = "some other string";
print("In2OutOneString - "+(
echo.In2OutOneString(test_string2) == test_string2 &&
echo.In2OutOneString(echo.In2OutOneString(test_string2)) == test_string2
? "passed" : "failed"));
////////////////////
// SendManyTypes
var receiver_results = new Object();
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
echo.SendManyTypes(send_params[0],
send_params[1],
send_params[2],
send_params[3],
send_params[4],
send_params[5],
send_params[6],
send_params[7],
send_params[8],
send_params[9],
send_params[10],
send_params[11],
send_params[12],
send_params[13],
send_params[14],
send_params[15]);
var all_ok = true;
for(i = 0; i < 16; i++) {
if(((""+receiver_results[i]).toLowerCase()) !=
((""+send_params[i]).toLowerCase())) {
if(all_ok)
print("SendManyTypes - failed...");
all_ok = false;
print(" param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i])
}
}
if(all_ok)
print("SendManyTypes - passed");
////////////////////
// SendInOutManyTypes
var receiver_results = new Object();
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
var resend_params = [2,-3,-7,-10220,18,14,16,123,2.5,8.000008,false,'z','l',NS_ISUPPORTS_IID,"foo string","yet another string"];
receiver.SendInOutManyTypes = function()
{
for(var i = 0; i < arguments.length; i++) {
receiver_results[i] = arguments[i].value;
arguments[i].value = resend_params[i];
}
};
var inout_params = [{value:send_params[0] },
{value:send_params[1] },
{value:send_params[2] },
{value:send_params[3] },
{value:send_params[4] },
{value:send_params[5] },
{value:send_params[6] },
{value:send_params[7] },
{value:send_params[8] },
{value:send_params[9] },
{value:send_params[10]},
{value:send_params[11]},
{value:send_params[12]},
{value:send_params[13]},
{value:send_params[14]},
{value:send_params[15]}];
echo.SendInOutManyTypes(inout_params[0] ,
inout_params[1] ,
inout_params[2] ,
inout_params[3] ,
inout_params[4] ,
inout_params[5] ,
inout_params[6] ,
inout_params[7] ,
inout_params[8] ,
inout_params[9] ,
inout_params[10],
inout_params[11],
inout_params[12],
inout_params[13],
inout_params[14],
inout_params[15]);
var all_ok = true;
for(i = 0; i < 16; i++) {
if(((""+receiver_results[i]).toLowerCase()) !=
((""+send_params[i]).toLowerCase())) {
if(all_ok)
print("SendInOutManyTypes - failed...");
all_ok = false;
print(" sent param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i]);
}
}
for(i = 0; i < 16; i++) {
if(((""+resend_params[i]).toLowerCase()) !=
((""+inout_params[i].value).toLowerCase())) {
if(all_ok)
print("SendInOutManyTypes - failed...");
all_ok = false;
print(" resent param number "+i+" diff: "+resend_params[i]+" -> "+inout_params[i].value);
}
}
if(all_ok)
print("SendInOutManyTypes - passed");
////////////////////
// Test DOMString
var test_string3 = "And this is yet again some other string 3";
var test_string4 = "And this is yet again some other string 4";
print("In2OutOneDOMString - "+(
echo.In2OutOneDOMString(test_string3) == test_string3
? "passed" : "failed"));
print("EchoIn2OutOneDOMString - "+(
echo.EchoIn2OutOneDOMString(test_string4) == test_string4
? "passed" : "failed"));
print("EchoIn2OutOneDOMString of empty string - "+(
echo.EchoIn2OutOneDOMString("") == ""
? "passed" : "failed"));
print("EchoIn2OutOneDOMString of null - "+(
echo.EchoIn2OutOneDOMString(null) == null
? "passed" : "failed"));
print("EchoIn2OutOneDOMString of undefined - "+(
echo.EchoIn2OutOneDOMString(this.propertyThatDoesNotExist) == "undefined"
? "passed" : "failed"));
/////////////////////
// Test AString
print("In2OutOneAString - "+(
echo.In2OutOneAString(test_string3) == test_string3
? "passed" : "failed"));
print("EchoIn2OutOneAString - "+(
echo.EchoIn2OutOneAString(test_string4) == test_string4
? "passed" : "failed"));
print("EchoIn2OutOneAString of empty string - "+(
echo.EchoIn2OutOneAString("") == ""
? "passed" : "failed"));
print("EchoIn2OutOneAString of null - "+(
echo.EchoIn2OutOneAString(null) == null
? "passed" : "failed"));
print("EchoIn2OutOneAString of undefined - "+(
echo.EchoIn2OutOneAString(this.propertyThatDoesNotExist) == ""
? "passed" : "failed"));
/////////////////////
// Test AUTF8String
var test_utf8String =
"Non-Ascii 1 byte chars: éâäàåç, 2 byte chars: \u1234 \u1235 \u1236";
print("In2OutOneUTF8String - "+(
echo.In2OutOneUTF8String(test_utf8String) == test_utf8String
? "passed" : "failed"));
print("EchoIn2OutOneUTF8String - "+(
echo.EchoIn2OutOneUTF8String(test_utf8String) == test_utf8String
? "passed" : "failed"));
print("EchoIn2OutOneUTF8String of empty string - "+(
echo.EchoIn2OutOneUTF8String("") == ""
? "passed" : "failed"));
print("EchoIn2OutOneUTF8String of null - "+(
echo.EchoIn2OutOneUTF8String(null) == null
? "passed" : "failed"));
print("EchoIn2OutOneUTF8String of undefined - "+(
echo.EchoIn2OutOneUTF8String(this.propertyThatDoesNotExist) == ""
? "passed" : "failed"));
/////////////////////
// Test ACString
print("In2OutOneCString - "+(
echo.In2OutOneCString(test_string3) == test_string3
? "passed" : "failed"));
print("EchoIn2OutOneCString - "+(
echo.EchoIn2OutOneCString(test_string4) == test_string4
? "passed" : "failed"));
print("EchoIn2OutOneCString of empty string - "+(
echo.EchoIn2OutOneCString("") == ""
? "passed" : "failed"));
print("EchoIn2OutOneCString of null - "+(
echo.EchoIn2OutOneCString(null) == null
? "passed" : "failed"));
print("EchoIn2OutOneCString of undefined - "+(
echo.EchoIn2OutOneCString(this.propertyThatDoesNotExist) == ""
? "passed" : "failed"));
////////////////////
// check exceptions on xpcom error code
try {
echo.ReturnCode(0);
print("ReturnCode(0) - passed");
}
catch(e) {
print("ReturnCode(0) exception text: "+e+" - failed");
}
try {
echo.ReturnCode(-1);
print("ReturnCode(-1) - failed");
}
catch(e) {
// print("ReturnCode(-1) exception text: "+e+" - passed");
print("ReturnCode(-1) - passed");
}
var all_ok = true;
echo.ReturnCode_NS_OK()
var lastResult = Components.lastResult;
if(Components.results.NS_OK != lastResult) {
all_ok = false;
print("expected: NS_OK = "+Components.results.NS_OK+" got: "+lastResult);
}
try {
echo.ReturnCode_NS_ERROR_NULL_POINTER()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_NULL_POINTER = "+Components.results.NS_ERROR_NULL_POINTER+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_NULL_POINTER != lastResult) {
all_ok = false;
print("expected: NS_ERROR_NULL_POINTER = "+Components.results.NS_ERROR_NULL_POINTER+" got: "+lastResult);
}
}
try {
echo.ReturnCode_NS_ERROR_UNEXPECTED()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_UNEXPECTED = "+Components.results.NS_ERROR_UNEXPECTED+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_UNEXPECTED != lastResult) {
all_ok = false;
print("expected: NS_ERROR_UNEXPECTED = "+Components.results.NS_ERROR_UNEXPECTED+" got: "+lastResult);
}
}
try {
echo.ReturnCode_NS_ERROR_OUT_OF_MEMORY()
all_ok = false;
} catch(e) {
var lastResult = Components.lastResult;
if(e.result != lastResult) {
all_ok = false;
print("expected: NS_ERROR_OUT_OF_MEMORY = "+Components.results.NS_ERROR_OUT_OF_MEMORY+" e.result was: "+e.result+" Components.lastResult: "+lastResult);
}
if(Components.results.NS_ERROR_OUT_OF_MEMORY != lastResult) {
all_ok = false;
print("expected: NS_ERROR_OUT_OF_MEMORY = "+Components.results.NS_ERROR_OUT_OF_MEMORY+" got: "+lastResult);
}
}
print("Components.lastResult test - "+ (all_ok ? "passed" : "failed") );
////////////////////
// check exceptions on too few args
try {
echo.ReturnCode(); // supposed to have one arg
print("Too few args test - failed");
}
catch(e) {
// print("Too few args test -- exception text: "+e+" - passed");
print("Too few args test - passed");
}
////////////////////
// check exceptions on can't convert
// XXX this is bad test since null is now convertable.
/*
try {
echo.SetReceiver(null);
// print("Can't convert arg to Native ("+out+")- failed");
print("Can't convert arg to Native - failed");
}
catch(e) {
// print("Can't convert arg to Native ("+e+") - passed");
print("Can't convert arg to Native - passed");
}
*/
////////////////////
// FailInJSTest
var receiver3 = new Object();
receiver3.SetReceiver = function() {};
receiver3.FailInJSTest = function(fail) {if(fail)throw("");};
echo.SetReceiver(receiver3);
var all_ok = true;
try {
print("\nThe 'FailInJSTest' test is expected to throw an exception...\n");
echo.FailInJSTest(false);
}
catch(e) {
print("FailInJSTest - failed");
all_ok = false;
}
try {
echo.FailInJSTest(true);
print("FailInJSTest - failed");
all_ok = false;
}
catch(e) {
}
if(all_ok)
print("FailInJSTest - passed");
/***************************************************************************/
all_ok = echo.SharedString() == "a static string";
print("[shared] test - "+(all_ok ? "passed" : "failed"));
/***************************************************************************/
// test wrapper Service Identity
var iface = Components.interfaces["nsIScriptError"];
var clazz = Components.classes["@mozilla.org/scripterror;1"];
var foo = clazz.getService(iface);
var bar = clazz.getService(iface);
all_ok = foo === bar;
print("service identity test - "+(all_ok ? "passed" : "failed"));
foo = bar = iface = clazz = null;
/***************************************************************************/
var r = new Object();
r.SetReceiver = function() {};
r.SendOneString = function(str) {Components.returnCode = code; return null;}
echo.SetReceiver(r);
var all_ok = true;
var code = Components.results.NS_OK;
try {
echo.SendOneString("");
} catch(e) {
all_ok = false;
}
var code = Components.results.NS_ERROR_FAILURE;
try {
echo.SendOneString("");
all_ok = false;
} catch(e) {
if(e.result != code)
all_ok = false;
}
var code = Components.results.NS_ERROR_NULL_POINTER;
try {
echo.SendOneString("");
all_ok = false;
} catch(e) {
if(e.result != code)
all_ok = false;
}
print("returnCode test - "+(all_ok ? "passed" : "failed"));
echo.SetReceiver(null);
r = null;
/***************************************************************************/
print(".......................................");
print("simple speed tests...");
var iterations = 10000;
var receiver2 = new Object();
receiver2.SetReceiver = function() {};
receiver2.SendOneString = function(str) {/*print(str);*/};
var echoJS = new Object();
echoJS.SetReceiver = function(r) {this.r = r;};
echoJS.SendOneString = function(str) {if(this.r)this.r.SendOneString(str)};
echoJS.SimpleCallNoEcho = function(){}
/*********************************************/
/*********************************************/
print("\nEcho.SimpleCallNoEcho (just makes call with no params and no callback)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SimpleCallNoEcho();
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
/*********************************************/
print("\nEcho.SendOneString (calls a callback that does a call)");
var start_time = new Date().getTime()/1000;
echoJS.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echoJS.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
var start_time = new Date().getTime()/1000;
echo.SetReceiver(receiver2);
for(i = 0; i < iterations; i++)
echo.SendOneString("foo");
var end_time = new Date().getTime()/1000;
var interval = parseInt(100*(end_time - start_time),10)/100;
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
print(".......................................");
if(0){
print();
print("this = "+this);
print("global object properties:");
for(i in this)
print(" this."+i+" = "+ (typeof(this[i])!="function"? this[i] : "[function]"));
print();
}
if(echoJS)echoJS.SetReceiver(null);
if(echo)echo.SetReceiver(null);
// cleanup...
nsNativeEcho = null;
NS_ISUPPORTS_IID = null;
NS_ITESTXPC_FOO_IID = null;
echo = null;
echoJS = null;
in_out_results = null;
in_out_results1 = null;
in_out_results2 = null;
inout_params = null;
interval = null;
iterations = null;
lastResult = null;
nsID = null;
receiver = null;
receiver2 = null;
receiver3 = null;
receiver_results = null;
resend_params = null;
send_params = null;
start_time = null;
test_string = null;
test_string2 = null;
test_string3 = null;
test_string4 = null;
nsNativeEcho = null;
gc();
gc();
//dumpXPC(4);

View File

@ -1,28 +0,0 @@
function enum_and_sort(o) {
var all = [];
for(n in o) all.push(n);
all.sort();
for(n in all) print(all[n]);
print("total count: "+all.length);
}
print("enum_and_sort...\n");
print(enum_and_sort);
print("");
print("enum_and_sort(Components.results)...\n");
enum_and_sort(Components.results);
print("");
print("enum_and_sort(Components.interfaces)...\n");
enum_and_sort(Components.interfaces);
print("");
print("enum_and_sort(Components.classes)...\n");
enum_and_sort(Components.classes);
print("");
print("enum_and_sort(Components.classesByID)...\n");
enum_and_sort(Components.classesByID);
print("");

View File

@ -1,15 +0,0 @@
var iface_count = 0;
var constant_count = 0;
for(var iface_name in Components.interfaces) {
var iface = Components.interfaces[iface_name];
print(iface_name);
var iface_name;
for(var const_name in iface) {
print(" "+const_name+" = "+iface[const_name])
constant_count++;
}
iface_count++;
}
print("\n"+iface_count+" interfaces with "+constant_count+" constants");

View File

@ -1,200 +0,0 @@
if (typeof document == "undefined") /* in xpcshell */
dumpln = print;
else
dumpln = function (str) {dump (str + "\n");}
function dumpObject (o, pfx, sep)
{
var p;
var s = "";
sep = (typeof sep == "undefined") ? " = " : sep;
pfx = (typeof pfx == "undefined") ? "" : pfx;
for (p in o)
{
if (typeof (o[p]) != "function")
s += pfx + p + sep + o[p] + "\n";
else
s += pfx + p + sep + "function\n";
}
return s;
}
function bruteForceEnumeration(ignore)
{
var interfaceInfo = new Object();
loop: for (var c in Components.classes)
{
var cls = Components.classes[c];
dumpln ("**");
dumpln (" * ContractID: '" + cls.name + "'");
dumpln (" * CLSID: " + cls.number);
if(ignore) {
for(var i = 0; i < ignore.length; i++) {
if(0 == cls.name.indexOf(ignore[i])) {
dumpln (" * This one might cause a crash - SKIPPING");
continue loop;
}
}
}
try
{
var ins = cls.createInstance();
for (var i in Components.interfaces)
{
try
{
qi = ins.QueryInterface (Components.interfaces[i]);
dumpln (" * Supports Interface: " + i);
if (typeof interfaceInfo[i] == "undefined")
{
interfaceInfo[i] = dumpObject (qi, " ** ");
}
dumpln (interfaceInfo[i]);
}
catch (e)
{
/* nada */
}
}
}
catch (e)
{
dumpln (" * createInstance FAILED:");
dumpln (dumpObject (e));
}
dumpln ("");
}
dumpln ("**");
dumpln (" * Interface Information :");
dumpln ("");
// dump of giant string does not always work, split it up.
var bulk = dumpObject (interfaceInfo, (void 0), "::\n")
var lines = bulk.split("\n");
for(var i = 0; i < lines.length; i++)
dumpln (lines[i]);
}
/** tests **/
var totalClasses = 0,
nonameClasses = 0,
strangeClasses = 0,
totalIfaces = 0,
strangeIfaces = 0;
dumpln ("**> Enumerating Classes");
for (var c in Components.classes)
{
totalClasses++;
if (Components.classes[c].name == "")
{
dumpln ("CLSID " + c + " has no contractID.");
nonameClasses++;
}
else
if (c.search(/^component:\/\//) == -1)
{
dumpln ("Strange contractID '" + c + "'");
strangeClasses++;
}
}
dumpln ("**> Enumerating Interfaces");
for (var i in Components.interfaces)
{
if (i != "QueryInterface")
{
totalIfaces++;
if (i.search(/^nsI/) == -1)
{
dumpln ("Strange interface name '" + i + "'");
strangeIfaces++;
}
}
}
dumpln ("** Enumerated " + totalClasses + " classes");
dumpln (" * " + nonameClasses + " without contractIDs");
dumpln (" * " + strangeClasses + " with strange names");
dumpln ("");
dumpln ("** Enumerated " + totalIfaces + " interfaces");
dumpln (" * " + strangeIfaces + " with strange names");
var contractIDsTo_NOT_Create = [
// fixed "@mozilla.org/prefwindow;1", // nsPrefWindow::~nsPrefWindow() releases null service
// fixed /* BUG 11511 */ "@mozilla.org/rdf/datasource;1?name=addresscard", // nsAbRDFDataSource::~nsAbRDFDataSource calls mRDFService->UnregisterDataSource(this); even though it was not registered
// fixed /* BUG 11511 */ "@mozilla.org/rdf/datasource;1?name=addressdirectory", // nsAbRDFDataSource::~nsAbRDFDataSource calls mRDFService->UnregisterDataSource(this); even though it was not registered
// fixed "@mozilla.org/addressbook/directoryproperty;1", // fails to init refcount
// fixed "@mozilla.org/rdf/datasource;1?name=local-store", //NS_NewLocalStore calls stuff that asserts
// fixed "@mozilla.org/rdf/datasource;1?name=xpinstall-update-notifier", //RDFXMLDataSourceImpl::Refresh does CreateInstance of parser but fails to check the result (I think I've seen this elsewhere)
// fixed "@mozilla.org/rdf/xul-template-builder;1", //RDFXMLDataSourceImpl::Refresh does CreateInstance of parser but fails to check the result (I think I've seen this elsewhere)
// fixed "@mozilla.org/rdf/xul-content-sink;1", // nsXULContentSink.cpp, XULContentSinkImpl::XULContentSinkImpl needs to init mNameSpaceManager
/* dp claims to have fixes coming */ "@mozilla.org/image/decoder;1?type=image/", // PNGDecoder::QueryInterface and JPGDecoder::QueryInterface, do NS_INIT_ISUPPORTS() in QueryInterface! (npunn)
/* BUG 11507 */ "@mozilla.org/wallet;1", // WalletFactoryImpl::CreateInstance broken : calls "delete inst" then calls "NS_IF_RELEASE(inst)"
/* BUG 11509 */ "@mozilla.org/messengercompose/compose;1", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11509 */ "@mozilla.org/messenger;1", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11509 */ "@mozilla.org/rdf/datasource;1?name=msgaccountmanager", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11509 */ "@mozilla.org/rdf/datasource;1?name=mailnewsfolders", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11509 */ "@mozilla.org/rdf/datasource;1?name=msgnotifications", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11509 */ "@mozilla.org/rdf/datasource;1?name=mailnewsmessages", // ASSERTION in nsMsgAccountManager::prefService() (needs prefs service)
/* BUG 11510 */ "@mozilla.org/rdf/xul-key-listener;1", // RDFFactoryImpl::CreateInstance asserts when creating if requested interface is nsISupports!
/* BUG 11510 */ "@mozilla.org/rdf/xul-popup-listener;1", // RDFFactoryImpl::CreateInstance asserts when creating if requested interface is nsISupports!
/* BUG 11510 */ "@mozilla.org/rdf/xul-focus-tracker;1", // RDFFactoryImpl::CreateInstance asserts when creating if requested interface is nsISupports!
/* BUG 11512 */ "@mozilla.org/rdf/datasource;1?name=files", // FileSystemDataSource::~FileSystemDataSource calls gRDFService->UnregisterDataSource(this); even though it was not registered
/* BUG 11512 */ "@mozilla.org/rdf/datasource;1?name=find", // FindDataSource::~FindDataSource calls gRDFService->UnregisterDataSource(this) even if it was not actaully registered.
/* BUG 11514 */ "@mozilla.org/rdf/datasource;1?name=msgaccounts", // nsMsgAccountDataSource::QueryInterface is COMPLETELY <censor>screwed</censor> up
/* BUG 11516 */ "@mozilla.org/rdf/xul-sort-service;1", // XULSortServiceImpl releases itself in its own destructor!
/* BUG 11570 */ "componment://netscape/intl/charsetconvertermanager", // another case where CreateInstance returned NS_OK, but the instance pointer was null!
/* BUG 11571 */ "@mozilla.org/rdf/datasource;1?name=mail-messageview", // nsMessageViewDataSource::RemoveDataSource uses mDataSource without checking for validity
/* BUG 11575 */ "@mozilla.org/rdf/resource-factory;1", // calling a property - trying to copy a null value in nsRDFResource::GetValue
/* BUG 11579 */ "@mozilla.org/messenger/maildb;1", // calling a property - nsMsgDatabase::m_newSet used but not set
/* BUG 11580 */ "@mozilla.org/messenger/identity;1", // calling a property - nsMsgIdentity::getCharPref is null
/* BUG 11580 */ "@mozilla.org/messenger/server;1?type=", // calling a property - nsMsgIncomingServer::getCharPref uses m_prefs which is null
/* ASSERTION OK? */ "@mozilla.org/messenger/account;1", // calling a property - nsMsgAccount::GetIncomingServer asserts because m_accountKey is null
];
dumpln ("-------------------------------------------------------");
dumpln (" Now let's create every component we can find...");
if(contractIDsTo_NOT_Create.length) {
dumpln ("...except the following 'cuz they've been know to cause CRASHES!...")
for(var i = 0; i < contractIDsTo_NOT_Create.length; i++)
dumpln (" "+contractIDsTo_NOT_Create[i]);
dumpln ();
}
bruteForceEnumeration(contractIDsTo_NOT_Create);

View File

@ -1,167 +0,0 @@
function printExceptionDoubleData(e) {
if(!e || !e.data)
return;
if(e instanceof Components.interfaces.nsIXPCException) {
try {
var d = e.data.QueryInterface(Components.interfaces.nsISupportsDouble)
try {
print("e.data = "+d.data);
} catch(i) {
print("could not get double from e.data");
}
} catch(i) {
print("e.data was not an nsISupportsDouble");
}
}
else {
print("object was not an nsIXPCException");
}
}
var clazz = Components.classes["@mozilla.org/js/xpc/test/Echo;1"];
var iface = Components.interfaces.nsIEcho;
var nativeEcho = clazz.createInstance(iface);
var localEcho = {
SendOneString : function() {throw this.result;},
result : 0
};
nativeEcho.SetReceiver(localEcho);
localEcho.result = 0;
print("\n");
try {
nativeEcho.SendOneString("foo");
print("no error");
} catch(e) {
print("caught "+e);
printExceptionDoubleData(e);
}
localEcho.result = 1;
print("\n");
try {
nativeEcho.SendOneString("foo");
print("no error");
} catch(e) {
print("caught "+e);
printExceptionDoubleData(e);
}
localEcho.result = -1;
print("\n");
try {
nativeEcho.SendOneString("foo");
print("no error");
} catch(e) {
print("caught "+e);
printExceptionDoubleData(e);
}
localEcho.result = Components.results.NS_ERROR_NO_AGGREGATION;
print("\n");
try {
nativeEcho.SendOneString("foo");
print("no error");
} catch(e) {
print("caught "+e);
printExceptionDoubleData(e);
}
localEcho.result = 0x80040154;
print("\n");
try {
nativeEcho.SendOneString("foo");
print("no error");
} catch(e) {
print("caught "+e);
printExceptionDoubleData(e);
}
print("\n");
localEcho.result = new Components.Exception("hi", Components.results.NS_ERROR_ABORT);
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
localEcho.result = {message : "pretending to be NS_OK does not work", result : 0};
try {
nativeEcho.SendOneString("foo");
print("pretending 0 == NS_OK");
} catch(e) {
print("caught "+e);
}
print("\n");
localEcho.result = {message : "pretending to be NS_ERROR_NO_INTERFACE",
result : Components.results.NS_ERROR_NO_INTERFACE};
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e.message);
}
print("\n");
localEcho.result = "just a string";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
localEcho.result = Components.results.NS_ERROR_NO_INTERFACE;
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
localEcho.result = "NS_OK";
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
localEcho.result = Components;
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
/* make this function have a JS runtime error */
localEcho.SendOneString = function(){return Components.foo.bar;};
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}
print("\n");
/* make this function have a JS compiletime error */
localEcho.SendOneString = function(){new Function("","foo ===== 1")};
try {
nativeEcho.SendOneString("foo");
} catch(e) {
print("caught "+e);
}

View File

@ -1,135 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This is a test for nsIIDs and nsCIDs in JavaScript. */
// our standard print function
function println(s)
{
if(this.document === undefined)
print(s);
else
dump(s+"\n");
}
// alias this ctor for simplicity of use
var nsID = Components.ID;
// some explicit IDs
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
var NS_ECHO = new nsID("{ed132c20-eed1-11d2-baa4-00805f8a5dd7}");
var NS_ECHO_UPPER = new nsID("{ED132C20-EED1-11D2-BAA4-00805F8A5DD7}");
var NS_BOGUS_IID = new nsID("{15898420-4d11-11d3-9893-006008962422}");
// our test data array
data = [
// toString of bare id resolved to canonical form
[NS_ISUPPORTS_IID , "{00000000-0000-0000-c000-000000000046}"],
// name of bare id is empty string
[NS_ISUPPORTS_IID.name , ""],
// number of bare id resolved to canonical form
[NS_ISUPPORTS_IID.number , "{00000000-0000-0000-c000-000000000046}"],
// this one is made up so it only resolves to the number
[NS_BOGUS_IID , "{15898420-4d11-11d3-9893-006008962422}"],
// now we check those the 'Components' knows about
[Components.interfaces.nsISupports , "nsISupports"],
[Components.classes["@mozilla.org/js/xpc/test/Echo;1"]
, "@mozilla.org/js/xpc/test/Echo;1"],
[Components.classes["@mozilla.org/js/xpc/test/Echo;1"].number
, "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
// now a bogus one
[Components.interfaces.bogus , "undefined"],
// even though these 'exist', they are not addressable by canonical name
[Components.interfaces["{00000000-0000-0000-c000-000000000046}"] , "undefined"],
[Components.classes["@mozilla.org/js/xpc/test/Echo;1"]["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"], "undefined"],
// we *don't* expect bare CLSIDs to resolve to contractids
[NS_ECHO_UPPER , "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
[NS_ECHO , "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
[NS_ECHO_UPPER.number , "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
[NS_ECHO.number , "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
// classesByID requires canonical numbers
[Components.classesByID.nsEcho , "undefined"],
[Components.classesByID["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"], "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
[Components.classesByID["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"].number, "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
// works with valid CID
[Components.classesByID["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"], "{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"],
// does not work with bogus CID
[Components.classesByID["{35fb7000-4d23-11d3-9893-006008962422}"], "undefined"],
// classesByID should not resolve the number to the contractid
[Components.classesByID["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"].name, ""],
// ...though it is clearly the same object...
[Components.classesByID["{ed132c20-eed1-11d2-baa4-00805f8a5dd7}"].equals(
Components.classes["@mozilla.org/js/xpc/test/Echo;1"]), true],
// equals self
[Components.classes["@mozilla.org/js/xpc/test/Echo;1"].equals(
Components.classes["@mozilla.org/js/xpc/test/Echo;1"]), true],
// we could add tests for more of the ID properties here...
]
// do the tests
println("\nJavaScript nsID tests...\n");
var failureCount = 0;
for(var i = 0; i < data.length; i++) {
var item = data[i];
if(""+item[0] != ""+item[1]) {
println("failed for item "+i+" expected \""+item[1]+"\" got \""+item[0]+"\"");
failureCount ++;
}
}
// show the final results
println("");
if(failureCount)
println(failureCount+" FAILURES total");
else
println("all PASSED");

View File

@ -1,35 +0,0 @@
const observerInterface = Components.interfaces.nsIObserverService;
const observerClazz = Components.classes["@mozilla.org/observer-service;1"];
var observerService = observerClazz.getService(observerInterface);
var observer1 = {
observe : function(aSubject, aTopic, someData) {
print("observer1 notified for: "+aTopic+" with: "+someData);
},
QueryInterface: function (iid) {
if (iid.equals(Components.interfaces.nsISupportsWeakReference) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
}
var observer2 = {
observe : function(aSubject, aTopic, someData) {
print("observer2 notified for: "+aTopic+" with: "+someData);
}
}
const topic = "xpctest_observer_topic";
observerService.addObserver(observer1, topic, false);
observerService.addObserver(observer2, topic, false);
observerService.notifyObservers(null, topic, "notification 1");
gc();
observer1 = null;
observer2 = null;
observerService.notifyObservers(null, topic, "notification 2");
gc();
observerService.notifyObservers(null, topic, "notification 3");

View File

@ -1,14 +0,0 @@
var clazz = Components.classes["@mozilla.org/js/xpc/test/Overloaded;1"];
var iface = Components.interfaces.nsIXPCTestOverloaded;
foo = clazz.createInstance(iface);
try {
print("foo.Foo1(1)... "); foo.Foo1(1)
print("foo.Foo2(1,2)..."); foo.Foo2(1,2)
print("foo.Foo(3)... "); foo.Foo(3)
print("foo.Foo(3,4)... "); foo.Foo(3,4)
print("foo.Foo()... "); foo.Foo();
} catch(e) {
print("caught exception: "+e);
}

View File

@ -1,141 +0,0 @@
/*
* This is a test for the various nsISupports* 'Primitives' wrappers declared
* in nsISupportsPrimitives.idl. It is a data driven tests - more values can
* be added to the table. It creates instances of the 'wrapper' objects, sets
* a values and then does a 'Get' of the values and compares that to the
* original. It also exercises the 'toString' methods of the wrappers.
*
* The table has plugable compare functions to allows for 'equals' methods of
* comparison and to allow for 'close enough' comparison of floats and doubles
*/
// prefix used by all these contractids
contractid_prefix = "@mozilla.org/";
contractid_suffix = ";1";
// an iid to use to test nsISupportsID
var iface_test = Components.interfaces.nsISupports;
// the canonical number form for that iid (e.g. {xxx-xxx...})
var i_str = iface_test.number
// just a flag used to mean 'use the initial value to toString comparisons'
var same = Object;
// the table of data...
// columns are:
// 1) contractid suffix
// 2) interface name
// 3) value
// 4) string to use to compare for toString ('same' mans use original value)
// 5) function to use for comparing values (null means use default compare)
// 6) function to use for comparing strings (null means use default compare)
var data = [
["supports-id" ,"nsISupportsID" ,iface_test,i_str ,eqfn , null],
["supports-cstring" ,"nsISupportsCString" ,"foo" ,same ,null , null],
["supports-string" ,"nsISupportsString" ,"bar" ,same ,null , null],
["supports-PRBool" ,"nsISupportsPRBool" ,true ,same ,null , null],
["supports-PRBool" ,"nsISupportsPRBool" ,false ,same ,null , null],
["supports-PRUint8" ,"nsISupportsPRUint8" ,7 ,same ,null , null],
["supports-PRUint16","nsISupportsPRUint16",12345 ,same ,null , null],
["supports-PRUint32","nsISupportsPRUint32",123456 ,same ,null , null],
["supports-PRUint64","nsISupportsPRUint64",1234567 ,same ,null , null],
["supports-PRTime" ,"nsISupportsPRTime" ,12345678 ,same ,null , null],
["supports-char" ,"nsISupportsChar" ,'z' ,same ,null , null],
["supports-PRInt16" ,"nsISupportsPRInt16" ,-123 ,same ,null , null],
["supports-PRInt32" ,"nsISupportsPRInt32" ,-3456 ,same ,null , null],
["supports-PRInt64" ,"nsISupportsPRInt64" ,-1234566 ,same ,null , null],
["supports-float" ,"nsISupportsFloat" , 12.0001 ,same ,fcmp , fcmp],
["supports-double" ,"nsISupportsDouble" , 1.0029202,same ,fcmp , fcmp],
];
function println(s)
{
if(this.document === undefined)
print(s);
else
dump(s+"\n");
}
// use this to see if floats are fairly close
function fcmp(v1, v2)
{
var f1 = parseFloat(v1);
var f2 = parseFloat(v2);
var retval = ((f1 - f2) < 0.001) || ((f2 - f1) < 0.001);
// if(retval) println(v1+" is close enough to "+v2);
return retval;
}
function eqfn(v1, v2)
{
return v1.equals(v2);
}
function regular_compare(v1, v2)
{
return v1 == v2;
}
function test(contractid, iid, d, string_val, val_compare_fn, str_compare_fn)
{
var test1_result;
var test2_result;
var full_contractid = contractid_prefix+contractid+contractid_suffix;
// println("checking... "+full_contractid+" "+iid+ " with "+d);
var clazz = Components.classes[full_contractid];
if(!clazz) {
println(full_contractid+ " is not a valid contractid");
return false;
}
var v = clazz.createInstance(Components.interfaces[iid])
v.data = d;
if(!val_compare_fn)
val_compare_fn = regular_compare;
if(!str_compare_fn)
str_compare_fn = regular_compare;
test1_result = val_compare_fn(d,v.data);
if(string_val) {
if(string_val == same)
test2_result = str_compare_fn(""+v, ""+d);
else
test2_result = str_compare_fn(""+v, string_val);
}
else
test2_result = true;
if(!test1_result)
println("failed for... "+contractid+" with "+d+" returned "+v.data);
if(!test2_result)
println("failed toString for... "+contractid+" with "+d+" returned "+""+v);
return test1_result && test2_result;
}
var failureCount = 0;
var exception = null;
try {
println("\n\n starting test... \n");
for(i = 0; i < data.length; i++) {
var r = data[i];
if(!test(r[0], r[1], r[2], r[3], r[4], r[5])) {
failureCount++ ;
}
}
} catch(e) {
exception = e;
failureCount++ ;
}
if(exception)
println("caught exception... "+exception);
println("\n"+(failureCount == 0 ? "all tests PASSED" : ""+failureCount+" errors"));

View File

@ -1,36 +0,0 @@
const nsIVariant = Components.interfaces.nsIVariant;
const nsIProperty = Components.interfaces.nsIProperty;
const TestVariant = Components.Constructor("@mozilla.org/js/xpc/test/TestVariant;1",
"nsITestVariant");
var tv = new TestVariant;
var obj = {foo : "fooString",
five : "5",
bar : {},
6 : "six",
fun : function(){},
bignum : 1.2345678901234567890,
now : new Date().toString() };
print();
print(tv.getNamedProperty(obj, "foo"));
print(tv.getNamedProperty(obj, "five"));
print(tv.getNamedProperty(obj, "bar"));
print(tv.getNamedProperty(obj, 6));
print(tv.getNamedProperty(obj, "fun"));
print(tv.getNamedProperty(obj, "fun"));
print(tv.getNamedProperty(obj, "bignum"));
print(tv.getNamedProperty(obj, "now"));
print();
var e = tv.getEnumerator(obj);
while(e.hasMoreElements()) {
var prop = e.getNext().QueryInterface(nsIProperty)
print(prop.name+" = "+prop.value);
}
print();

View File

@ -1,339 +0,0 @@
const TestVariant = Components.Constructor("@mozilla.org/js/xpc/test/TestVariant;1",
"nsITestVariant");
var tv = new TestVariant;
const DataTypeArray = [
Components.interfaces.nsIDataType.VTYPE_INT8 ,
Components.interfaces.nsIDataType.VTYPE_INT16 ,
Components.interfaces.nsIDataType.VTYPE_INT32 ,
Components.interfaces.nsIDataType.VTYPE_INT64 ,
Components.interfaces.nsIDataType.VTYPE_UINT8 ,
Components.interfaces.nsIDataType.VTYPE_UINT16 ,
Components.interfaces.nsIDataType.VTYPE_UINT32 ,
Components.interfaces.nsIDataType.VTYPE_UINT64 ,
Components.interfaces.nsIDataType.VTYPE_FLOAT ,
Components.interfaces.nsIDataType.VTYPE_DOUBLE ,
Components.interfaces.nsIDataType.VTYPE_BOOL ,
Components.interfaces.nsIDataType.VTYPE_CHAR ,
Components.interfaces.nsIDataType.VTYPE_WCHAR ,
Components.interfaces.nsIDataType.VTYPE_VOID ,
Components.interfaces.nsIDataType.VTYPE_ID ,
Components.interfaces.nsIDataType.VTYPE_DOMSTRING ,
Components.interfaces.nsIDataType.VTYPE_CHAR_STR ,
Components.interfaces.nsIDataType.VTYPE_WCHAR_STR ,
Components.interfaces.nsIDataType.VTYPE_INTERFACE ,
Components.interfaces.nsIDataType.VTYPE_INTERFACE_IS ,
Components.interfaces.nsIDataType.VTYPE_ARRAY ,
Components.interfaces.nsIDataType.VTYPE_STRING_SIZE_IS ,
Components.interfaces.nsIDataType.VTYPE_WSTRING_SIZE_IS ,
Components.interfaces.nsIDataType.VTYPE_UTF8STRING ,
Components.interfaces.nsIDataType.VTYPE_CSTRING ,
Components.interfaces.nsIDataType.VTYPE_ASTRING ,
Components.interfaces.nsIDataType.VTYPE_EMPTY_ARRAY ,
Components.interfaces.nsIDataType.VTYPE_EMPTY
];
const ShortNames = [
{name: "I1", number: Components.interfaces.nsIDataType.VTYPE_INT8 },
{name: "I2", number: Components.interfaces.nsIDataType.VTYPE_INT16 },
{name: "I4", number: Components.interfaces.nsIDataType.VTYPE_INT32 },
{name: "I8", number: Components.interfaces.nsIDataType.VTYPE_INT64 },
{name: "U1", number: Components.interfaces.nsIDataType.VTYPE_UINT8 },
{name: "U2", number: Components.interfaces.nsIDataType.VTYPE_UINT16 },
{name: "U4", number: Components.interfaces.nsIDataType.VTYPE_UINT32 },
{name: "U8", number: Components.interfaces.nsIDataType.VTYPE_UINT64 },
{name: "FL", number: Components.interfaces.nsIDataType.VTYPE_FLOAT },
{name: "DB", number: Components.interfaces.nsIDataType.VTYPE_DOUBLE },
{name: "BO", number: Components.interfaces.nsIDataType.VTYPE_BOOL },
{name: "CH", number: Components.interfaces.nsIDataType.VTYPE_CHAR },
{name: "WC", number: Components.interfaces.nsIDataType.VTYPE_WCHAR },
{name: "VD", number: Components.interfaces.nsIDataType.VTYPE_VOID },
{name: "ID", number: Components.interfaces.nsIDataType.VTYPE_ID },
{name: "DS", number: Components.interfaces.nsIDataType.VTYPE_DOMSTRING },
{name: "ST", number: Components.interfaces.nsIDataType.VTYPE_CHAR_STR },
{name: "WS", number: Components.interfaces.nsIDataType.VTYPE_WCHAR_STR },
{name: "NS", number: Components.interfaces.nsIDataType.VTYPE_INTERFACE },
{name: "IF", number: Components.interfaces.nsIDataType.VTYPE_INTERFACE_IS },
{name: "AR", number: Components.interfaces.nsIDataType.VTYPE_ARRAY },
{name: "Ss", number: Components.interfaces.nsIDataType.VTYPE_STRING_SIZE_IS },
{name: "Ws", number: Components.interfaces.nsIDataType.VTYPE_WSTRING_SIZE_IS},
{name: "US", number: Components.interfaces.nsIDataType.VTYPE_UTF8STRING },
{name: "CS", number: Components.interfaces.nsIDataType.VTYPE_CSTRING },
{name: "AS", number: Components.interfaces.nsIDataType.VTYPE_ASTRING },
{name: "EA", number: Components.interfaces.nsIDataType.VTYPE_EMPTY_ARRAY },
{name: "EM", number: Components.interfaces.nsIDataType.VTYPE_EMPTY }
];
function getDataTypeName(number) {
var iface = Components.interfaces.nsIDataType
for(var n in iface)
if(iface[n] == number)
return n;
return "unknown type!";
}
function getDataTypeShortName(number) {
for(var i = 0; i < ShortNames.length; i++)
if(ShortNames[i].number == number)
return ShortNames[i].name;
return "???";
}
function eqOp(o1, o2) {return o1 == o2;}
function eqObj(o1, o2) {return o1.equals(o2);}
function eqNumber(o1, o2) {return parseFloat(o1) == parseFloat(o2);}
const eq = {string: "equal result"};
const _e = {string: "exception"};
const NE = {string: "un-equal result"};
const _0 = {string: "zero result"};
const _1 = {string: "one result"};
const _T = {string: "true result"};
const _F = {string: "false result"};
function TestSingleConvert(value, comment, eq_fun, table) {
print("<h3>convert test for: "+value+" "+comment+"</h3>");
print('<TABLE BORDER="1" COLS='+table.length+'>');
print('<TR>');
for(var i = 0; i < table.length; i++) {
print('<TH>'+getDataTypeShortName(DataTypeArray[i])+'</TH>');
}
print('</TR>');
print('<TR>');
for(var i = 0; i < table.length; i++) {
var exception = undefined;
var value2 = undefined;
try {
value2 = tv.copyVariantAsType(value, DataTypeArray[i]);
var same = eq_fun(value, value2);
success = (same && table[i] == eq) ||
(!same && table[i] == NE) ||
(table[i] == _0 && 0 == value2) ||
(table[i] == _T && true == value2) ||
(table[i] == _F && false == value2);
} catch(e) {
exception = e;
success = table[i] == _e;
}
if(success)
print('<TD><font color="green">OK</font></TD>');
else if(exception) {
var alertText = "Exception thrown. Expected: "+table[i].string;
print('<TD><font color="red"><A HREF="" '+
'onclick="alert(\''+alertText+'\'); return false;"'+
'>X</A></font></TD>');
}
else {
var alertText = "Result = "+value2+". Expected: "+table[i].string;
print('<TD><font color="red"><A HREF="" '+
'onclick="alert(\''+alertText+'\'); return false;"'+
'>X</A></font></TD>');
}
}
print('</TR>');
print('</TABLE>');
}
function TestDoubleConvert(value, comment, eq_fun, table) {
print("<h3>convert test for: "+value+" "+comment+"</h3>");
print('<TABLE BORDER="1" COLS='+table.length+2+'>');
print('<TR>');
print('<TH></TH>');
for(var i = 0; i < table.length; i++) {
print('<TH>'+getDataTypeShortName(DataTypeArray[i])+'</TH>');
}
print('<TH></TH>');
print('</TR>');
for(var i = 0; i < table.length; i++) {
print('<TR>');
print('<TD>'+getDataTypeShortName(DataTypeArray[i])+'</TD>');
for(var k = 0; k < table.length; k++) {
var exception = undefined;
var value2 = undefined;
var expected = table[i][k];
try {
value2 = tv.copyVariantAsTypeTwice(value,
DataTypeArray[k],
DataTypeArray[i]);
var same = eq_fun(value, value2);
success = (same && expected == eq) ||
(!same && expected == NE) ||
(expected == _0 && 0 == value2) ||
(expected == _T && true == value2) ||
(expected == _F && false == value2);
} catch(e) {
exception = e;
success = expected == _e;
}
if(success)
print('<TD><font color="green">OK</font></TD>');
else if(exception) {
var alertText = "Exception thrown. Expected: "+expected.string;
print('<TD><font color="red"><A HREF="" '+
'onclick="alert(\''+alertText+'\'); return false;"'+
'>X</A></font></TD>');
}
else {
var alertText = "Result = was wrong. Expected: "+expected.string;
print('<TD><font color="red"><A HREF="" '+
'onclick="alert(\''+alertText+'\'); return false;"'+
'>X</A></font></TD>');
}
}
print('<TD>'+getDataTypeShortName(DataTypeArray[i])+'</TD>');
print('</TR>');
}
print('</TABLE>');
}
//
const SingleConvertResultsTableFor_String_Foo = [
/*I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,DS,ST,WS,NS,IF,AR,Ss,Ws,US,CS,AS,EA,EM */
_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e
];
const SingleConvertResultsTableFor_String_5 = [
/*I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,DS,ST,WS,NS,IF,AR,Ss,Ws,US,CS,AS,EA,EM */
eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e
];
const SingleConvertResultsTableFor_Number_20 = [
/*I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,DS,ST,WS,NS,IF,AR,Ss,Ws,US,CS,AS,EA,EM */
eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e
];
const DoubleConvertResultsTableFor_String_Foo = [
/* I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,DS,ST,WS,NS,IF,AR,Ss,Ws,US,CS,AS,EA,EM */
/*I1*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*I1*/
/*I2*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*I2*/
/*I4*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*I4*/
/*I8*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*I8*/
/*U1*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*U1*/
/*U2*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*U2*/
/*U4*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*U4*/
/*U8*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*U8*/
/*FL*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*FL*/
/*DB*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*DB*/
/*BO*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*BO*/
/*CH*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*CH*/
/*WC*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*WC*/
/*VD*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*VD*/
/*ID*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*ID*/
/*DS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*DS*/
/*ST*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*ST*/
/*WS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*WS*/
/*NS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*NS*/
/*IF*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*IF*/
/*AR*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*AR*/
/*Ss*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*Ss*/
/*Ws*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*Ws*/
/*US*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*US*/
/*CS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*CS*/
/*AS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*AS*/
/*EA*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*EA*/
/*EM*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e] /*EM*/
];
const DoubleConvertResultsTableFor_String_Five = [
/* I1,I2,I4,I8,U1,U2,U4,U8,FL,DB,BO,CH,WC,VD,ID,DS,ST,WS,NS,IF,AR,Ss,Ws,US,CS,AS,EA,EM */
/*I1*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*I1*/
/*I2*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*I2*/
/*I4*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*I4*/
/*I8*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*I8*/
/*U1*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*U1*/
/*U2*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*U2*/
/*U4*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*U4*/
/*U8*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*U8*/
/*FL*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*FL*/
/*DB*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,_T,eq,eq,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*DB*/
/*BO*/[_T,_T,_T,_T,_T,_T,_T,_T,_T,_T,_T,NE,NE,_e,_e,_T,_T,_T,_e,_e,_e,_T,_T,_T,_T,_T,_e,_e],/*BO*/
/*CH*/[NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,_e,_e,NE,NE,NE,_e,_e,_e,NE,NE,NE,NE,NE,_e,_e],/*CH*/
/*WC*/[NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,_e,_e,NE,NE,NE,_e,_e,_e,NE,NE,NE,NE,NE,_e,_e],/*WC*/
/*VD*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*VD*/
/*ID*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*ID*/
/*DS*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*DS*/
/*ST*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*ST*/
/*WS*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*WS*/
/*NS*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*NS*/
/*IF*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*IF*/
/*AR*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*AR*/
/*Ss*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*Ss*/
/*Ws*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*Ws*/
/*US*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*US*/
/*CS*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*CS*/
/*AS*/[eq,eq,eq,eq,eq,eq,eq,eq,eq,eq,NE,NE,NE,_e,_e,eq,eq,eq,_e,_e,_e,eq,eq,eq,eq,eq,_e,_e],/*AS*/
/*EA*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e],/*EA*/
/*EM*/[_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e,_e] /*EM*/
];
var values = [
"foo",
0,
5,
1.01,
Components,
{},
Components.interfaces.nsISupports,
null,
true,
undefined
];
var i;
/***************************************************************************/
if(0){
print();
for(i = 0; i < values.length; i++)
print(getDataTypeName(tv.returnVariantType(values[i])));
print();
print();
for(i = 0; i < values.length; i++)
print(tv.passThruVariant(values[i]));
print();
print();
for(i = 0; i < values.length; i++)
print(tv.copyVariant(values[i]));
}
function RunSingleConvertTests() {
TestSingleConvert("foo", "a string", eqOp, SingleConvertResultsTableFor_String_Foo);
TestSingleConvert("5", "a string", eqNumber, SingleConvertResultsTableFor_String_5);
TestSingleConvert(20, "a number", eqNumber, SingleConvertResultsTableFor_Number_20);
print("<P>");
}
function RunDoubleConvertTests() {
TestDoubleConvert("foo", "a string", eqOp, DoubleConvertResultsTableFor_String_Foo);
TestDoubleConvert("5", "a string", eqNumber, DoubleConvertResultsTableFor_String_Five);
print("<P>");
}
// main...
print("<html><body>")
RunSingleConvertTests();
RunDoubleConvertTests();
print("</body></html>")

View File

@ -1,30 +0,0 @@
const TestVariant = Components.Constructor("@mozilla.org/js/xpc/test/TestVariant;1",
"nsITestVariant");
var tv = new TestVariant;
print("\npassThruVariant tests...\n");
print(tv.passThruVariant(["a","b","c"]));
print(tv.passThruVariant([1,2,3]));
print(tv.passThruVariant([1,2.1,3]));
print(tv.passThruVariant([{},{},{}]));
print(tv.passThruVariant([{},{},null]));
print(tv.passThruVariant([{},{},"foo"]));
print(tv.passThruVariant([[1,2,3],{},"foo"]));
print(tv.passThruVariant([[1,2,3],[4,5,6],["a","b","c"]]));
print("\ncopyVariant tests...\n");
print(tv.copyVariant(["a","b","c"]));
print(tv.copyVariant([1,2,3]));
print(tv.copyVariant([1,2.1,3]));
print(tv.copyVariant([{},{},{}]));
print(tv.copyVariant([{},{},null]));
print(tv.copyVariant([{},{},"foo"]));
print(tv.copyVariant([[1,2,3],{},"foo"]));
print(tv.copyVariant([[1,2,3],[4,5,6],["a","b","c"]]));
print("\ndone\n");

View File

@ -1,74 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Verify that we can access but not overwrite the values of read-only
* attributes.
*/
StartTest( "ReadOnly File Attributes" );
/*
* These values come from xpctest_attributes.idl and xpctest_attributes.cpp
*/
var CONTRACTID = "@mozilla.org/js/xpc/test/ObjectReadOnly;1";
var INAME = Components.interfaces["nsIXPCTestObjectReadOnly"];
var o = Components.classes[CONTRACTID].createInstance();
o = o.QueryInterface( INAME );
AddTestCase( "o.boolReadOnly", true, o.boolReadOnly );
AddTestCase( "o.shortReadOnly", 32767, o.shortReadOnly );
AddTestCase( "o.longReadOnly", 2147483647, o.longReadOnly );
AddTestCase( "o.charReadOnly", "X", o.charReadOnly );
// read only means we can't overwrite.
o.boolReadOnly = false;
o.shortReadOnly = -12345;
o.longReadOnly = 12345;
o.charReadOnly = "Z";
AddTestCase( "o.boolReadOnly", true, o.boolReadOnly );
AddTestCase( "o.shortReadOnly", 32767, o.shortReadOnly );
AddTestCase( "o.longReadOnly", 2147483647, o.longReadOnly );
AddTestCase( "o.charReadOnly", "X", o.charReadOnly );
StopTest();

View File

@ -1,120 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Get and set properties on a XPCOM object and verify that they are
* JavaScripty.
*
*/
StartTest( "Get and Set Properties on a native object" );
SetupTest();
AddTestData();
StopTest();
function SetupTest() {
CONTRACTID = "@mozilla.org/js/xpc/test/Overloaded;1";
CLASS = Components.classes[CONTRACTID].createInstance();
IFACE = Components.interfaces.nsIXPCTestScriptable;
testObject = CLASS.QueryInterface(IFACE);
}
function AddTestData() {
// add a property to the object.
testObject.newProperty = "PASS",
AddTestCase(
"testObject.newProperty = \"PASS\"; testObject.newProperty",
"PASS",
testObject.newProperty );
// delete a property from an object
var result = delete testObject.newProperty;
AddTestCase(
"delete testObject.newProperty",
true,
result );
AddTestCase(
"delete testObject.newProperty; testObject.newProperty",
undefined,
testObject.newProperty );
// add a function
testObject.newFunction = new Function( "return \"PASSED\"" );
AddTestCase(
"testObject.newFunction = new Function(\"return 'PASSED'\"); " +
"typeof testObject.newFunction",
"function",
typeof testObject.newFunction );
var s = "testObject.newFunction()"
AddTestCase(
"testObject.newFunction()",
"PASSED",
eval(s));
// try to call the function as a constructor
testObject.newFunction = new Function( "this.result = \"PASSED\"" );
AddTestCase(
"testObject.newFunction = new Function( 'this.result = \"PASSED\"'); "+
"new testObject.newFunction().result",
"PASSED",
new testObject.newFunction().result );
// delete the function
result = delete testObject.newFunction;
AddTestCase(
"delete testObject.newFunction",
true,
result);
AddTestCase(
"typeof testObject.newFunction",
"undefined",
typeof testObject.newFunction);
}

View File

@ -1,199 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* Test the in keyword. See xpctest_in.cpp and xpctest_in.idl for
* function names and parameters.
*/
StartTest( "Passing different types in" );
var CLASS = Components.classes["@mozilla.org/js/xpc/test/In;1"];
var IFACE = Components.interfaces["nsIXPCTestIn" ];
var C = CLASS.createInstance();
var c = C.QueryInterface(IFACE);
// different tests for each type. it would be easier to generate
// tests using eval. maybe later.
TestLong(
[0, 0, true, 1, "A", 0, new Boolean, 0, {}, 0,
[],0, new Date(987654321),987654321, new Number(2134), 2134,
-987654321, -987654321, undefined, 0, null, 0, void 0, 0,
NaN, 0, Function, 0 ]
);
TestLong(
[0.2134, 0, -0.2134, 0, Math.pow(2,16)-1, Math.pow(2,16)-1,
Math.pow(2,31)-1, Math.pow(2,31)-1, Math.pow(2,31), -Math.pow(2,31),
-(Math.pow(2,31)), (-Math.pow(2,31)),
(-Math.pow(2,31))+1, (-Math.pow(2,31))+1,
(-Math.pow(2,31))-1, (Math.pow(2,31))-1
] );
TestShort( [
new Number(Math.pow(2,15)-1), Math.pow(2,15)-1,
Math.pow(2,15)-1, Math.pow(2,15)-1,
Math.pow(2,15), -Math.pow(2,15)
]);
TestChar( [
"A", "A",
1, "1",
255, "2",
"XPConnect", "X",
String.fromCharCode(Math.pow(2,16)), String.fromCharCode(Math.pow(2,16))
]);
TestBoolean( [
]);
TestOctet( [
]);
TestLongLong( [
]);
TestUnsignedShort( [
]);
TestUnsignedLong( [
]);
TestFloat( [
]);
TestDouble( [
]);
TestWchar([
]);
TestString([
]);
TestPRInt32( [
]);
TestPRInt16( [
]);
TestPrInt64( [
]);
TestPRUint8( [
new Number(Math.pow(2,8)), 0,
Math.pow(2,8)-1, Math.pow(2,8)-1,
Math.pow(2,8), 0,
-Math.pow(2,8), 0,
]);
TestPRUint16( [
]);
TestPRUint32( [
]);
TestPRUint64( [
]);
TestVoidStar( [
]);
TestCharStar( [
]);
StopTest();
function TestLong( data ) {
for ( var i = 0; i < data.length; i+=2 ) {
AddTestCase( "c.EchoLong("+data[i]+")",
data[i+1],
c.EchoLong(data[i]));
}
}
function TestShort( data ) {
for ( var i = 0; i < data.length; i+=2 ) {
AddTestCase( "c.EchoShort("+data[i]+")",
data[i+1],
c.EchoShort(data[i]));
}
}
function TestChar( data ) {
for ( var i = 0; i < data.length; i+=2 ) {
AddTestCase( "c.EchoChar("+data[i]+")",
data[i+1],
c.EchoChar(data[i]));
}
}
function TestBoolean() {
}
function TestOctet() {
}
function TestLongLong() {
}
function TestUnsignedShort() {
}
function TestUnsignedLong() {
}
function TestFloat() {
}
function TestDouble() {
}
function TestWchar() {
}
function TestString() {
}
function TestPRInt32() {
}
function TestPRInt16() {
}
function TestPrInt64() {
}
function TestPRUint16() {
}
function TestPRUint32() {
}
function TestPRUint64() {
}
function TestPRUint8( data ) {
for ( var i = 0; i < data.length; i+=2 ) {
AddTestCase( "c.EchoPRUint8("+data[i]+")",
data[i+1],
c.EchoPRUint8(data[i]));
}
}
function TestVoidStar( data ) {
for ( var i = 0; i < data.length; i+=2 ) {
AddTestCase( "c.EchoVoidStar("+data[i]+")",
data[i+1],
c.EchoVoidStar(data[i]));
}
}
function TestCharStar() {
}

View File

@ -1,234 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/**
* This file contains functions used by all of the XPConnect tests.
* See http://www.mozilla.org/scriptable/tests/ for more information.
*/
/**
*
*
*/
var FILE_BUGNUMBERS = "";
var window;
var PASSED;
var FAILED;
function AddTestCase( s, e, a, n, b, i ) {
TESTCASES[TESTCASES.length] = new TestCase( s, e, a, b, n, i );
return TESTCASES[TESTCASES.length];
}
function TestCase( s, e, a, n, b, i ) {
this.id = ID++;
this.description = s;
this.expected = e;
this.actual = a;
if ( n )
this.negative = n;
if ( b )
this.bugnumber = b;
if ( i )
this.ignore = i;
this.passed = GetResult( e, a );
}
function StartTest( t ) {
TESTCASES = new Array();
FILE_FAILED_CASES = 0;
FILE_PASSED_CASES = 0;
FILE_PASSED = true;
COMPLETED = false;
ID = 0;
FILE_TITLE = t;
WriteLine("\n" + FILE_TITLE +"\n");
if ( window ) {
document.open();
PASSED = "<font color=\"#00cc00\">passed </font>";
FAILED = "<font color=\"#ff0000\">FAILED </font>";
} else {
PASSED = "passed ";
FAILED = "FAILED ";
}
}
function StopTest() {
// here, we will close up and print a summary of what happened
writeReadableResults();
//writeParseableResults();
writeTestFileSummary();
if ( window ) {
document.close();
}
}
function AddComment(s) {
WriteLine(s);
}
function writeReadableResults() {
for ( var i = 0; i < TESTCASES.length; i++ ) {
var tc = TESTCASES[i];
if (tc.passed && this.DONT_PRINT_PASSED_TESTS)
continue;
WriteLine(
(tc.passed ? PASSED : FAILED) +
tc.description + " = " +
tc.actual + " " +
(tc.passed ? "" : "expected " + tc.expected)
);
}
}
function writeParseableResults() {
WriteLine( "START TEST CASE RESULTS" );
for ( var i = 0; i < TESTCASES.length; i++ ) {
var tc = TESTCASES[i];
WriteLine( tc.id +","+
tc.description +","+
tc.expected +","+
tc.actual +","+
tc.bugnumber +","+
tc.negative +","+
tc.ignore +","+
tc.exception +","+
tc.passed );
}
}
function writeTestFileSummary() {
WriteLine ("\nTEST FILE SUMMARY" );
WriteLine( "Title: " + FILE_TITLE );
WriteLine( "Passed: " + FILE_PASSED );
WriteLine( "Testcases: " + TESTCASES.length );
WriteLine( "Passed Cases: " + FILE_PASSED_CASES );
WriteLine( "Failed Cases: " + FILE_FAILED_CASES );
// if we're in the shell, run the garbage collector.
var gc;
if ( typeof gc == "function") {
gc();
}
}
function GetResult(expect, actual) {
if ( actual != actual ) {
if ( typeof actual == "object" ){
actual = "NaN object";
} else {
actual = "NaN number";
}
}
if ( expect != expect ) {
if ( typeof expect == "object" ) {
expect = "NaN object";
} else {
expect = "NaN number";
}
}
var passed = ( expect == actual ) ? true : false;
if ( typeof(expect) != typeof(actual) ) {
passed = false;
}
if ( !passed ) {
FILE_PASSED = false;
FILE_FAILED_CASES++;
} else {
FILE_PASSED_CASES++;
}
return passed;
}
function PrintResult(e, a, s, p) {
}
function PrintHTMLFormattedResult( e, a, s, p ) {
}
function WriteLine( s ) {
if ( window ) {
document.write( s +"<br>");
} else {
print ( s );
}
}
function GetFailedCases() {
for ( var i = 0; i < TESTCASES.length; i++ ) {
var tc = TESTCASES[i];
if ( !tc.passed )
WriteLine(
(tc.passed ? "passed " : "FAILED! ") +
tc.description + " = " +
tc.actual + " " +
(tc.passed ? "" : "expected " + tc.expected)
);
}
}
/**
* Given an object, display all its properties and the value of that
* property.
*/
function Enumerate( o ) {
var p;
WriteLine( "Properties of object " + o );
for ( p in o ) {
WriteLine( p +": "+ (typeof o[p] == "function" ? "function" : o[p]) );
}
}
/**
* These are variables whose values depend on the host environment.
* The defaults here are correct for the JavaScript or XPConnect shell.
* In order to run the tests in the browser, need to override these
* values for the tests to execute correctly.
*
*/
var GLOBAL = "[object global]";

View File

@ -1,200 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** 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 Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/*
* This is a test for the various nsISupports* 'Primitives' wrappers declared
* in nsISupportsPrimitives.idl. It is a data driven tests - more values can
* be added to the table. It creates instances of the 'wrapper' objects, sets
* a values and then does a 'Get' of the values and compares that to the
* original. It also exercises the 'toString' methods of the wrappers.
*
* The table has plugable compare functions to allows for 'equals' methods of
* comparison and to allow for 'close enough' comparison of floats and doubles
*/
StartTest( "nsISupports Primitives" );
// prefix used by all these contractids
contractid_prefix = "@mozilla.org/";
// an iid to use to test nsISupportsID
var iface_test = Components.interfaces.nsISupports;
// the canonical number form for that iid (e.g. {xxx-xxx...})
var i_str = iface_test.number
// just a flag used to mean 'use the initial value to toString comparisons'
var same = Object;
// the table of data...
// columns are:
// 1) contractid suffix
// 2) interface name
// 3) value
// 4) string to use to compare for toString ('same' mans use original value)
// 5) function to use for comparing values (null means use default compare)
// 6) function to use for comparing strings (null means use default compare)
var data = [
["supports-id" ,"nsISupportsID" ,iface_test,i_str ,eqfn , null],
["supports-cstring" ,"nsISupportsCString" ,"foo" ,same ,null , null],
["supports-string" ,"nsISupportsString" ,"bar" ,same ,null , null],
["supports-PRBool" ,"nsISupportsPRBool" ,true ,same ,null , null],
["supports-PRBool" ,"nsISupportsPRBool" ,false ,same ,null , null],
["supports-PRUint8" ,"nsISupportsPRUint8" ,7 ,same ,null , null],
["supports-PRUint16","nsISupportsPRUint16",12345 ,same ,null , null],
["supports-PRUint32","nsISupportsPRUint32",123456 ,same ,null , null],
["supports-PRUint64","nsISupportsPRUint64",1234567 ,same ,null , null],
["supports-PRTime" ,"nsISupportsPRTime" ,12345678 ,same ,null , null],
["supports-char" ,"nsISupportsChar" ,'z' ,same ,null , null],
["supports-PRInt16" ,"nsISupportsPRInt16" ,-123 ,same ,null , null],
["supports-PRInt32" ,"nsISupportsPRInt32" ,-3456 ,same ,null , null],
["supports-PRInt64" ,"nsISupportsPRInt64" ,-1234566 ,same ,null , null],
["supports-float" ,"nsISupportsFloat" , 12.0001 ,same ,fcmp , fcmp],
["supports-double" ,"nsISupportsDouble" , 1.0029202,same ,fcmp , fcmp],
];
var failureCount = 0;
var exception = null;
try {
println("\n\n starting test... \n");
for(i = 0; i < data.length; i++) {
var r = data[i];
test(r[0], r[1], r[2], r[3], r[4], r[5]);
}
} catch(e) {
exception = e;
failureCount++ ;
}
if(exception)
println("caught exception... "+exception);
// println("\n"+(failureCount == 0 ? "all tests PASSED" : ""+failureCount+" errors"));
StopTest();
// use this to see if floats are fairly close
function fcmp(v1, v2)
{
var f1 = parseFloat(v1);
var f2 = parseFloat(v2);
var retval = ((f1 - f2) < 0.001) || ((f2 - f1) < 0.001);
// if(retval) println(v1+" is close enough to "+v2);
return retval;
}
function eqfn(v1, v2)
{
return v1.equals(v2);
}
function regular_compare(v1, v2)
{
return v1 == v2;
}
function test(contractid, iid, d, string_val, val_compare_fn, str_compare_fn)
{
var test1_result;
var test2_result;
var full_contractid = contractid_prefix+contractid;
// println("checking... "+contractid+" "+iid+ " with "+d);
var clazz = Components.classes[full_contractid];
var result1 = (clazz) ? true : false;
AddTestCase( "verifying class " + clazz + " is valid",
true,
result1);
if ( ! result1 ) {
// need to add empty test cases so that the # of test cases is
// constant
println("failed for... "+contractid+" with "+d+" returned "+v.data);
AddTestCase( "str_compare_fun", true, false );
AddTestCase( "val_compare_fun", true, false );
return;
}
try {
var v = clazz.createInstance(Components.interfaces[iid])
v.data = d;
if(!val_compare_fn)
val_compare_fn = regular_compare;
if(!str_compare_fn)
str_compare_fn = regular_compare;
AddTestCase( "compare values",
true,
val_compare_fn(d, v.data));
if(string_val) {
if(string_val == same)
AddTestCase( "str_compare_fun( "+v +","+d +")", true,
str_compare_fn(""+v, ""+d) );
else
AddTestCase( "str_compare_fn(" + v +", " + string_val +")",
true,
str_compare_fn(""+v, string_val) );
} else {
test2_result = true;
}
} catch ( e ) {
WriteLine ( "Ooh, caught exception: " + e );
}
return;
}
function println(s)
{
if(typeof(this.document) == "undefined")
print(s);
else
dump(s+"\n");
}

View File

@ -36,7 +36,7 @@
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

View File

Before

Width:  |  Height:  |  Size: 492 B

After

Width:  |  Height:  |  Size: 492 B

Some files were not shown because too many files have changed in this diff Show More