Merge extensions/python/xpcom changes from DOM_AGNOSTIC2_BRANCH into the
trunk. git-svn-id: svn://10.0.0.236/trunk@187878 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
52
mozilla/extensions/python/xpcom/test/Makefile.in
Normal file
52
mozilla/extensions/python/xpcom/test/Makefile.in
Normal file
@@ -0,0 +1,52 @@
|
||||
# ***** 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.org code
|
||||
#
|
||||
# The Initial Developer of the Original Code is mozilla.org.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2005
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Mark Hammond: author
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH =../../../..
|
||||
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
DIRS = test_component $(NULL)
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
check::
|
||||
@echo "Running Python XPCOM tests"
|
||||
@$(PYTHON)$(PYTHON_DEBUG_SUFFIX) $(srcdir)/regrtest.py
|
||||
@@ -1,8 +0,0 @@
|
||||
test_com_exceptions
|
||||
** Unhandled exception calling 'int8 do_short(in int16, inout int16, out int16, out retval int16);'
|
||||
** Returning nsresult of NS_ERROR_FAILURE
|
||||
** Unhandled exception calling 'int8 do_unsigned_short(in uint16, inout uint16, out uint16, out retval uint16);'
|
||||
** Returning nsresult of NS_ERROR_FAILURE
|
||||
** Unhandled exception calling 'int8 do_unsigned_long_long(in uint64, inout uint64, out uint64, out retval uint64);'
|
||||
** Returning nsresult of NS_ERROR_FAILURE
|
||||
The xpcom exception tests passed
|
||||
@@ -1,7 +0,0 @@
|
||||
test_comfile
|
||||
Open as string test worked.
|
||||
Open as URL test worked.
|
||||
File test using buffers worked.
|
||||
Local file read test worked.
|
||||
Read the correct data.
|
||||
Chunks read the correct data.
|
||||
@@ -1,4 +0,0 @@
|
||||
test_components
|
||||
The interfaces object appeared to work!
|
||||
The classes object appeared to work!
|
||||
The ID function appeared to work!
|
||||
@@ -1,2 +0,0 @@
|
||||
test_isupports_primitives
|
||||
The nsISupports primitive interface tests appeared to work
|
||||
@@ -1 +0,0 @@
|
||||
test_streams
|
||||
@@ -1,4 +0,0 @@
|
||||
test_test_component
|
||||
Testing the Python.TestComponent component
|
||||
The Python test component worked!
|
||||
Javascript could successfully use the Python test component.
|
||||
@@ -1,2 +0,0 @@
|
||||
test_weakreferences
|
||||
Weak-reference tests appear to have worked!
|
||||
@@ -1,4 +1,6 @@
|
||||
# test tools for the pyxpcom
|
||||
# test tools for the pyxpcom bindings
|
||||
from xpcom import _xpcom
|
||||
import unittest
|
||||
|
||||
# export a "getmemusage()" function that returns a useful "bytes used" count
|
||||
# for the current process. Growth in this when doing the same thing over and
|
||||
@@ -70,3 +72,55 @@ if have_pdh:
|
||||
else:
|
||||
def getmemusage():
|
||||
return 0
|
||||
|
||||
# Test runner utilities, including some support for builtin leak tests.
|
||||
class TestLoader(unittest.TestLoader):
|
||||
def loadTestsFromTestCase(self, testCaseClass):
|
||||
"""Return a suite of all tests cases contained in testCaseClass"""
|
||||
leak_tests = []
|
||||
for name in self.getTestCaseNames(testCaseClass):
|
||||
real_test = testCaseClass(name)
|
||||
leak_test = self._getTestWrapper(real_test)
|
||||
leak_tests.append(leak_test)
|
||||
return self.suiteClass(leak_tests)
|
||||
def _getTestWrapper(self, test):
|
||||
# later! see pywin32's win32/test/util.py
|
||||
return test
|
||||
def loadTestsFromModule(self, mod):
|
||||
if hasattr(mod, "suite"):
|
||||
ret = mod.suite()
|
||||
else:
|
||||
ret = unittest.TestLoader.loadTestsFromModule(self, mod)
|
||||
assert ret.countTestCases() > 0, "No tests in %r" % (mod,)
|
||||
return ret
|
||||
def loadTestsFromName(self, name, module=None):
|
||||
test = unittest.TestLoader.loadTestsFromName(self, name, module)
|
||||
if isinstance(test, unittest.TestSuite):
|
||||
pass # hmmm? print "Don't wrap suites yet!", test._tests
|
||||
elif isinstance(test, unittest.TestCase):
|
||||
test = self._getTestWrapper(test)
|
||||
else:
|
||||
print "XXX - what is", test
|
||||
return test
|
||||
|
||||
# A base class our tests should derive from (well, one day it will be)
|
||||
TestCase = unittest.TestCase
|
||||
|
||||
def suite_from_functions(*funcs):
|
||||
suite = unittest.TestSuite()
|
||||
for func in funcs:
|
||||
suite.addTest(unittest.FunctionTestCase(func))
|
||||
return suite
|
||||
|
||||
def testmain(*args, **kw):
|
||||
new_kw = kw.copy()
|
||||
if not new_kw.has_key('testLoader'):
|
||||
new_kw['testLoader'] = TestLoader()
|
||||
try:
|
||||
unittest.main(*args, **new_kw)
|
||||
finally:
|
||||
_xpcom.NS_ShutdownXPCOM()
|
||||
ni = _xpcom._GetInterfaceCount()
|
||||
ng = _xpcom._GetGatewayCount()
|
||||
if ni or ng:
|
||||
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
||||
|
||||
@@ -42,28 +42,50 @@ import os
|
||||
import sys
|
||||
|
||||
import unittest
|
||||
import test.regrtest # The standard Python test suite.
|
||||
|
||||
path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
||||
# This sucks - python now uses "test." - so to worm around this,
|
||||
# we append our test path to the test packages!
|
||||
test.__path__.append(path)
|
||||
# A little magic to create a single "test suite" from all test_ files
|
||||
# in this dir. A single suite makes for prettier output test :)
|
||||
def suite():
|
||||
# Loop over all test_*.py files here
|
||||
try:
|
||||
me = __file__
|
||||
except NameError:
|
||||
me = sys.argv[0]
|
||||
me = os.path.abspath(me)
|
||||
files = os.listdir(os.path.dirname(me))
|
||||
suite = unittest.TestSuite()
|
||||
# XXX - add the others here!
|
||||
#suite.addTest(unittest.FunctionTestCase(import_all))
|
||||
for file in files:
|
||||
base, ext = os.path.splitext(file)
|
||||
if ext=='.py' and os.path.basename(base).startswith("test_"):
|
||||
mod = __import__(base)
|
||||
if hasattr(mod, "suite"):
|
||||
test = mod.suite()
|
||||
else:
|
||||
test = unittest.defaultTestLoader.loadTestsFromModule(mod)
|
||||
suite.addTest(test)
|
||||
return suite
|
||||
|
||||
class CustomLoader(unittest.TestLoader):
|
||||
def loadTestsFromModule(self, module):
|
||||
return suite()
|
||||
|
||||
tests = []
|
||||
for arg in sys.argv[1:]:
|
||||
if arg[0] not in "-/":
|
||||
tests.append(arg)
|
||||
tests = tests or test.regrtest.findtests(path, [])
|
||||
try:
|
||||
# unittest based tests first - hopefully soon this will be the default!
|
||||
if not sys.argv[1:]:
|
||||
for t in "test_misc test_streams".split():
|
||||
m = __import__(t)
|
||||
try:
|
||||
unittest.main(m)
|
||||
except SystemExit:
|
||||
pass
|
||||
test.regrtest.main(tests, path)
|
||||
unittest.TestProgram(testLoader=CustomLoader())(argv=sys.argv)
|
||||
finally:
|
||||
from xpcom import _xpcom
|
||||
_xpcom.NS_ShutdownXPCOM() # To get leak stats and otherwise ensure life is good.
|
||||
ni = _xpcom._GetInterfaceCount()
|
||||
ng = _xpcom._GetGatewayCount()
|
||||
if ni or ng:
|
||||
# The old 'regrtest' that was not based purely on unittest did not
|
||||
# do this check at the end - it relied on each module doing it itself.
|
||||
# Thus, these leaks are not new, just newly noticed :) Likely to be
|
||||
# something silly like module globals.
|
||||
if ni == 6 and ng == 1:
|
||||
print "Sadly, there are 6/1 leaks, but these appear normal and benign"
|
||||
else:
|
||||
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
||||
else:
|
||||
print "yay! Our leaks have all vanished!"
|
||||
|
||||
@@ -36,8 +36,12 @@
|
||||
|
||||
# Test pyxpcom exception.
|
||||
|
||||
from xpcom import components, nsError, ServerException, COMException
|
||||
from xpcom import components, nsError, ServerException, COMException, logger
|
||||
from xpcom.server import WrapObject
|
||||
from pyxpcom_test_tools import testmain
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
class PythonFailingComponent:
|
||||
# Re-use the test interface for this test.
|
||||
@@ -75,29 +79,46 @@ class PythonFailingComponent:
|
||||
# Report of a crash in this case - test it!
|
||||
raise ServerException, "A bad exception param"
|
||||
|
||||
def _testit(expected_errno, func, *args):
|
||||
try:
|
||||
apply(func, args)
|
||||
except COMException, what:
|
||||
if what.errno != expected_errno:
|
||||
raise
|
||||
class TestHandler(logging.Handler):
|
||||
def __init__(self, level=logging.ERROR): # only counting error records
|
||||
logging.Handler.__init__(self, level)
|
||||
self.records = []
|
||||
|
||||
def reset(self):
|
||||
self.records = []
|
||||
|
||||
def test():
|
||||
# For the benefit of the test suite, we print some reassuring messages.
|
||||
import sys
|
||||
sys.__stderr__.write("***** NOTE: Three tracebacks below this is normal\n")
|
||||
ob = WrapObject( PythonFailingComponent(), components.interfaces.nsIPythonTestInterfaceExtra)
|
||||
_testit(nsError.NS_ERROR_FAILURE, ob.do_boolean, 0, 0)
|
||||
_testit(nsError.NS_ERROR_NOT_IMPLEMENTED, ob.do_octet, 0, 0)
|
||||
_testit(nsError.NS_ERROR_FAILURE, ob.do_short, 0, 0)
|
||||
_testit(nsError.NS_ERROR_FAILURE, ob.do_unsigned_short, 0, 0)
|
||||
_testit(nsError.NS_ERROR_FAILURE, ob.do_long, 0, 0)
|
||||
_testit(nsError.NS_ERROR_NOT_IMPLEMENTED, ob.do_unsigned_long, 0, 0)
|
||||
_testit(nsError.NS_ERROR_NOT_IMPLEMENTED, ob.do_long_long, 0, 0)
|
||||
_testit(nsError.NS_ERROR_FAILURE, ob.do_unsigned_long_long, 0, 0)
|
||||
print "The xpcom exception tests passed"
|
||||
# For the benefit of the test suite, some more reassuring messages.
|
||||
sys.__stderr__.write("***** NOTE: Three tracebacks printed above this is normal\n")
|
||||
sys.__stderr__.write("***** It is testing the Python XPCOM Exception semantics\n")
|
||||
def handle(self, record):
|
||||
self.records.append(record)
|
||||
|
||||
test()
|
||||
class ExceptionTests(unittest.TestCase):
|
||||
|
||||
def _testit(self, expected_errno, num_tracebacks, func, *args):
|
||||
|
||||
# Screw with the logger
|
||||
old_handlers = logger.handlers
|
||||
test_handler = TestHandler()
|
||||
logger.handlers = [test_handler]
|
||||
|
||||
try:
|
||||
try:
|
||||
apply(func, args)
|
||||
except COMException, what:
|
||||
if what.errno != expected_errno:
|
||||
raise
|
||||
finally:
|
||||
logger.handlers = old_handlers
|
||||
self.failUnlessEqual(num_tracebacks, len(test_handler.records))
|
||||
|
||||
def testEmAll(self):
|
||||
ob = WrapObject( PythonFailingComponent(), components.interfaces.nsIPythonTestInterfaceExtra)
|
||||
self._testit(nsError.NS_ERROR_FAILURE, 0, ob.do_boolean, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_NOT_IMPLEMENTED, 0, ob.do_octet, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_FAILURE, 1, ob.do_short, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_FAILURE, 1, ob.do_unsigned_short, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_FAILURE, 0, ob.do_long, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_NOT_IMPLEMENTED, 0, ob.do_unsigned_long, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_NOT_IMPLEMENTED, 0, ob.do_long_long, 0, 0)
|
||||
self._testit(nsError.NS_ERROR_FAILURE, 1, ob.do_unsigned_long_long, 0, 0)
|
||||
|
||||
if __name__=='__main__':
|
||||
testmain()
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
"""Test the xpcom.file module."""
|
||||
# Called "test_comfile" as Python has a standard test called test_file :-(
|
||||
from pyxpcom_test_tools import suite_from_functions, testmain
|
||||
|
||||
import xpcom.file
|
||||
xpcom.file._TestAll()
|
||||
|
||||
# Make this test run under our std test suite
|
||||
def suite():
|
||||
return suite_from_functions(xpcom.file._TestAll)
|
||||
|
||||
if __name__=='__main__':
|
||||
testmain()
|
||||
|
||||
|
||||
@@ -212,6 +212,7 @@ interface nsIPythonTestInterfaceExtra : nsIPythonTestInterface
|
||||
void AppendArray(inout PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]inout PRInt32 array2);
|
||||
void AppendVariant(in nsIVariant variant, inout nsIVariant result);
|
||||
nsIVariant CopyVariant(in nsIVariant variant);
|
||||
nsIVariant SumVariants(in PRUint32 incount, [array, size_is(incount)]in nsIVariant variants);
|
||||
};
|
||||
|
||||
// DOM String support is a "recent" (01/2001) addition to XPCOM. These test
|
||||
|
||||
@@ -365,6 +365,14 @@ class PythonTestComponent:
|
||||
def CopyVariant(self, invar):
|
||||
return invar
|
||||
|
||||
def SumVariants(self, variants):
|
||||
if len(variants) == 0:
|
||||
return None
|
||||
result = variants[0]
|
||||
for v in variants[1:]:
|
||||
result += v
|
||||
return result
|
||||
|
||||
# Some tests for the "new" (Feb-2001) DOMString type.
|
||||
def GetDOMStringResult( self, length ):
|
||||
# Result: DOMString &
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"""
|
||||
|
||||
import xpcom.components
|
||||
from pyxpcom_test_tools import suite_from_functions, testmain
|
||||
|
||||
if not __debug__:
|
||||
raise RuntimeError, "This test uses assert, so must be run in debug mode"
|
||||
@@ -63,9 +64,7 @@ def test_interfaces():
|
||||
assert len(xpcom.components.interfaces.keys()) == len(xpcom.components.interfaces.values()) == \
|
||||
len(xpcom.components.interfaces.items()) == len(xpcom.components.interfaces) == \
|
||||
num_fetched, "The collection lengths were wrong"
|
||||
if num_nsisupports != 1:
|
||||
print "Didn't find exactly 1 nsiSupports!"
|
||||
print "The interfaces object appeared to work!"
|
||||
assert num_nsisupports == 1, "Didn't find exactly 1 nsiSupports!"
|
||||
|
||||
def test_classes():
|
||||
# Need a well-known contractID here?
|
||||
@@ -81,8 +80,7 @@ def test_classes():
|
||||
for name, klass in xpcom.components.classes.items():
|
||||
num_fetched = num_fetched + 1
|
||||
if name == prog_id:
|
||||
if klass.clsid != clsid:
|
||||
print "Eeek - didn't get the correct IID - got", klass.clsid
|
||||
assert klass.clsid == clsid, "Eeek - didn't get the correct IID - got %s" %klass.clsid
|
||||
num_mine = num_mine + 1
|
||||
|
||||
# xpcom appears to add charset info to the contractid!?
|
||||
@@ -98,15 +96,14 @@ def test_classes():
|
||||
raise RuntimeError, "Didn't get any classes!!!"
|
||||
if num_mine != 1:
|
||||
raise RuntimeError, "Didn't find exactly 1 of my contractid! (%d)" % (num_mine,)
|
||||
print "The classes object appeared to work!"
|
||||
|
||||
def test_id():
|
||||
id = xpcom.components.ID(str(xpcom._xpcom.IID_nsISupports))
|
||||
assert id == xpcom._xpcom.IID_nsISupports
|
||||
print "The ID function appeared to work!"
|
||||
|
||||
# Make this test run under our std test suite
|
||||
def suite():
|
||||
return suite_from_functions(test_interfaces, test_classes, test_id)
|
||||
|
||||
# regrtest doesn't like if __name__=='__main__' blocks - it fails when running as a test!
|
||||
test_interfaces()
|
||||
test_classes()
|
||||
test_id()
|
||||
if __name__=='__main__':
|
||||
testmain()
|
||||
|
||||
@@ -41,10 +41,13 @@
|
||||
# only if our class doesn't provide explicit support.
|
||||
|
||||
from xpcom import components
|
||||
from xpcom import primitives
|
||||
import xpcom.server, xpcom.client
|
||||
from pyxpcom_test_tools import testmain
|
||||
import unittest
|
||||
|
||||
class NoSupportsString:
|
||||
_com_interfaces_ = [components.interfaces.nsISupports]
|
||||
pass
|
||||
|
||||
class ImplicitSupportsString:
|
||||
_com_interfaces_ = [components.interfaces.nsISupports]
|
||||
@@ -52,13 +55,36 @@ class ImplicitSupportsString:
|
||||
return "<MyImplicitStrObject>"
|
||||
|
||||
class ExplicitSupportsString:
|
||||
_com_interfaces_ = [components.interfaces.nsISupports, components.interfaces.nsISupportsCString]
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPrimitive,
|
||||
components.interfaces.nsISupportsCString]
|
||||
type = components.interfaces.nsISupportsPrimitive.TYPE_CSTRING
|
||||
test_data = "<MyExplicitStrObject>"
|
||||
# __str__ will be ignored by XPCOM, as we have _explicit_ support.
|
||||
def __str__(self):
|
||||
return "<MyImplicitStrObject>"
|
||||
# This is the one that will be used.
|
||||
# These are the ones that will be used.
|
||||
def get_data(self):
|
||||
return self.test_data
|
||||
def toString(self):
|
||||
return "<MyExplicitStrObject>"
|
||||
return self.test_data
|
||||
|
||||
class ImplicitSupportsUnicode:
|
||||
_com_interfaces_ = [components.interfaces.nsISupports]
|
||||
test_data = u"Copyright \xa9 the initial developer"
|
||||
def __unicode__(self):
|
||||
# An extended character in unicode tests can't hurt!
|
||||
return self.test_data
|
||||
|
||||
class ExplicitSupportsUnicode:
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPrimitive,
|
||||
components.interfaces.nsISupportsString]
|
||||
type = components.interfaces.nsISupportsPrimitive.TYPE_STRING
|
||||
# __unicode__ will be ignored by XPCOM, as we have _explicit_ support.
|
||||
test_data = u"Copyright \xa9 the initial developer"
|
||||
def __unicode__(self):
|
||||
return self.test_data
|
||||
def get_data(self):
|
||||
return self.test_data
|
||||
|
||||
class ImplicitSupportsInt:
|
||||
_com_interfaces_ = [components.interfaces.nsISupports]
|
||||
@@ -66,7 +92,9 @@ class ImplicitSupportsInt:
|
||||
return 99
|
||||
|
||||
class ExplicitSupportsInt:
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPRInt32]
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPrimitive,
|
||||
components.interfaces.nsISupportsPRInt32]
|
||||
type = components.interfaces.nsISupportsPrimitive.TYPE_PRINT32
|
||||
def get_data(self):
|
||||
return 99
|
||||
|
||||
@@ -76,12 +104,16 @@ class ImplicitSupportsLong:
|
||||
return 99L
|
||||
|
||||
class ExplicitSupportsLong:
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPRInt64]
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPrimitive,
|
||||
components.interfaces.nsISupportsPRInt64]
|
||||
type = components.interfaces.nsISupportsPrimitive.TYPE_PRINT64
|
||||
def get_data(self):
|
||||
return 99
|
||||
|
||||
class ExplicitSupportsFloat:
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsDouble]
|
||||
_com_interfaces_ = [components.interfaces.nsISupportsPrimitive,
|
||||
components.interfaces.nsISupportsDouble]
|
||||
type = components.interfaces.nsISupportsPrimitive.TYPE_DOUBLE
|
||||
def get_data(self):
|
||||
return 99.99
|
||||
|
||||
@@ -90,61 +122,86 @@ class ImplicitSupportsFloat:
|
||||
def __float__(self):
|
||||
return 99.99
|
||||
|
||||
def test():
|
||||
import xpcom.server, xpcom.client
|
||||
ob = xpcom.server.WrapObject( NoSupportsString(), components.interfaces.nsISupports)
|
||||
if not str(ob).startswith("<XPCOM "):
|
||||
raise RuntimeError, "Wrong str() value: %s" % (ob,)
|
||||
class PrimitivesTestCase(unittest.TestCase):
|
||||
def testNoSupports(self):
|
||||
ob = xpcom.server.WrapObject( NoSupportsString(), components.interfaces.nsISupports)
|
||||
if not str(ob).startswith("<XPCOM "):
|
||||
raise RuntimeError, "Wrong str() value: %s" % (ob,)
|
||||
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsString(), components.interfaces.nsISupports)
|
||||
if str(ob) != "<MyImplicitStrObject>":
|
||||
raise RuntimeError, "Wrong str() value: %s" % (ob,)
|
||||
def testImplicitString(self):
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsString(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(str(ob), "<MyImplicitStrObject>")
|
||||
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsString(), components.interfaces.nsISupports)
|
||||
if str(ob) != "<MyExplicitStrObject>":
|
||||
raise RuntimeError, "Wrong str() value: %s" % (ob,)
|
||||
def testExplicitString(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsString(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(str(ob), "<MyExplicitStrObject>")
|
||||
|
||||
# Try our conversions.
|
||||
try:
|
||||
int(ob)
|
||||
raise RuntimeError, "Expected to get a ValueError converting this COM object to an int"
|
||||
except ValueError:
|
||||
pass
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsInt(), components.interfaces.nsISupports)
|
||||
if int(ob) != 99:
|
||||
raise RuntimeError, "Bad value: %s" % (int(ob),)
|
||||
if float(ob) != 99.0:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
def testImplicitUnicode(self):
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsUnicode(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(unicode(ob), ImplicitSupportsUnicode.test_data)
|
||||
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsInt(), components.interfaces.nsISupports)
|
||||
if int(ob) != 99:
|
||||
raise RuntimeError, "Bad value: %s" % (int(ob),)
|
||||
if float(ob) != 99.0:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
def testExplicitUnicode(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsUnicode(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(unicode(ob), ExplicitSupportsUnicode.test_data)
|
||||
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsLong(), components.interfaces.nsISupports)
|
||||
if long(ob) != 99 or not repr(long(ob)).endswith("L"):
|
||||
raise RuntimeError, "Bad value: %s" % (repr(long(ob)),)
|
||||
if float(ob) != 99.0:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
def testConvertInt(self):
|
||||
# Try our conversions.
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsString(), components.interfaces.nsISupports)
|
||||
self.failUnlessRaises( ValueError, int, ob)
|
||||
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsLong(), components.interfaces.nsISupports)
|
||||
if long(ob) != 99 or not repr(long(ob)).endswith("L"):
|
||||
raise RuntimeError, "Bad value: %s" % (repr(long(ob)),)
|
||||
if float(ob) != 99.0:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
def testExplicitInt(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsInt(), components.interfaces.nsISupports)
|
||||
self.failUnlessAlmostEqual(float(ob), 99.0)
|
||||
self.failUnlessEqual(int(ob), 99)
|
||||
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsFloat(), components.interfaces.nsISupports)
|
||||
if float(ob) != 99.99:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
if int(ob) != 99:
|
||||
raise RuntimeError, "Bad value: %s" % (int(ob),)
|
||||
def testImplicitInt(self):
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsInt(), components.interfaces.nsISupports)
|
||||
self.failUnlessAlmostEqual(float(ob), 99.0)
|
||||
self.failUnlessEqual(int(ob), 99)
|
||||
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsFloat(), components.interfaces.nsISupports)
|
||||
if float(ob) != 99.99:
|
||||
raise RuntimeError, "Bad value: %s" % (float(ob),)
|
||||
if int(ob) != 99:
|
||||
raise RuntimeError, "Bad value: %s" % (int(ob),)
|
||||
def testExplicitLong(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsLong(), components.interfaces.nsISupports)
|
||||
if long(ob) != 99 or not repr(long(ob)).endswith("L"):
|
||||
raise RuntimeError, "Bad value: %s" % (repr(long(ob)),)
|
||||
self.failUnlessAlmostEqual(float(ob), 99.0)
|
||||
|
||||
print "The nsISupports primitive interface tests appeared to work"
|
||||
test()
|
||||
def testImplicitLong(self):
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsLong(), components.interfaces.nsISupports)
|
||||
if long(ob) != 99 or not repr(long(ob)).endswith("L"):
|
||||
raise RuntimeError, "Bad value: %s" % (repr(long(ob)),)
|
||||
self.failUnlessAlmostEqual(float(ob), 99.0)
|
||||
|
||||
def testExplicitFloat(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsFloat(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(float(ob), 99.99)
|
||||
self.failUnlessEqual(int(ob), 99)
|
||||
|
||||
def testImplicitFloat(self):
|
||||
ob = xpcom.server.WrapObject( ImplicitSupportsFloat(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(float(ob), 99.99)
|
||||
self.failUnlessEqual(int(ob), 99)
|
||||
|
||||
class PrimitivesModuleTestCase(unittest.TestCase):
|
||||
def testExplicitString(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsString(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(primitives.GetPrimitive(ob), "<MyExplicitStrObject>")
|
||||
|
||||
def testExplicitUnicode(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsUnicode(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(primitives.GetPrimitive(ob), ExplicitSupportsUnicode.test_data)
|
||||
self.failUnlessEqual(type(primitives.GetPrimitive(ob)), unicode)
|
||||
|
||||
def testExplicitInt(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsInt(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(primitives.GetPrimitive(ob), 99)
|
||||
|
||||
def testExplicitLong(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsLong(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(primitives.GetPrimitive(ob), 99)
|
||||
|
||||
def testExplicitFloat(self):
|
||||
ob = xpcom.server.WrapObject( ExplicitSupportsFloat(), components.interfaces.nsISupports)
|
||||
self.failUnlessEqual(primitives.GetPrimitive(ob), 99.99)
|
||||
|
||||
if __name__=='__main__':
|
||||
testmain()
|
||||
|
||||
@@ -41,6 +41,7 @@ import xpcom.server
|
||||
import xpcom._xpcom
|
||||
import xpcom.components
|
||||
import string
|
||||
from pyxpcom_test_tools import testmain
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -223,10 +224,13 @@ class TestUnwrap(unittest.TestCase):
|
||||
return
|
||||
self.failUnlessRaises(ValueError, xpcom.server.UnwrapObject, ob)
|
||||
|
||||
class TestNonScriptable(unittest.TestCase):
|
||||
def testQI(self):
|
||||
# Test we can QI for a non-scriptable interface. We can't *do* much
|
||||
# with it (other than pass it on), but we should still work and get
|
||||
# a basic wrapper.
|
||||
ob = xpcom.components.classes["Python.TestComponent"].createInstance()
|
||||
ob = ob.queryInterface(xpcom._xpcom.IID_nsIInternalPython)
|
||||
|
||||
if __name__=='__main__':
|
||||
unittest.main()
|
||||
xpcom._xpcom.NS_ShutdownXPCOM()
|
||||
ni = xpcom._xpcom._GetInterfaceCount()
|
||||
ng = xpcom._xpcom._GetGatewayCount()
|
||||
if ni or ng:
|
||||
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
||||
testmain()
|
||||
|
||||
@@ -39,6 +39,7 @@ import xpcom
|
||||
from xpcom import _xpcom, components, COMException, ServerException, nsError
|
||||
from StringIO import StringIO
|
||||
import unittest
|
||||
from pyxpcom_test_tools import testmain
|
||||
|
||||
test_data = "abcdefeghijklmnopqrstuvwxyz"
|
||||
|
||||
@@ -92,4 +93,4 @@ class StreamTests(unittest.TestCase):
|
||||
# stream observer mechanism has changed - we should test that.
|
||||
|
||||
if __name__=='__main__':
|
||||
unittest.main()
|
||||
testmain()
|
||||
|
||||
@@ -130,5 +130,9 @@ v2[3] = 6;
|
||||
if (c.SumArrays(v.length, v, v2) != 21)
|
||||
throw("Could not sum an array of integers!");
|
||||
|
||||
var count = new Object();
|
||||
count.value = 0;
|
||||
var out = [];
|
||||
c.DoubleStringArray(count, out);
|
||||
|
||||
print("javascript successfully tested the Python test component.");
|
||||
|
||||
@@ -40,6 +40,8 @@ import xpcom.components
|
||||
import xpcom._xpcom
|
||||
import xpcom.nsError
|
||||
|
||||
MakeVariant = xpcom._xpcom.MakeVariant
|
||||
|
||||
try:
|
||||
import gc
|
||||
except ImportError:
|
||||
@@ -406,11 +408,19 @@ def test_derived_interface(c, test_flat = 0):
|
||||
test_method(c.CopyVariant, (("foo","bar"),), ["foo", "bar"])
|
||||
test_method(c.CopyVariant, ((component_iid,component_iid),), [component_iid,component_iid])
|
||||
test_method(c.CopyVariant, ((c,c),), [c,c])
|
||||
sup = c.queryInterface(xpcom.components.interfaces.nsISupports)._comobj_
|
||||
test_method(c.CopyVariant, ((sup, sup),), [sup,sup])
|
||||
test_method(c.AppendVariant, (1,2), 3)
|
||||
test_method(c.AppendVariant, ((1,2),(3,4)), 10)
|
||||
test_method(c.AppendVariant, ("bar", "foo"), "foobar")
|
||||
test_method(c.AppendVariant, (None, None), None)
|
||||
|
||||
test_method(c.SumVariants, ([],), None)
|
||||
# Array's dont expose their interface, so we are unable to auto-wrap
|
||||
# variant arrays, as they aren't aware if the IID of the array
|
||||
test_method(c.SumVariants, ([MakeVariant(1),MakeVariant(2),MakeVariant(3)],), 6)
|
||||
test_method(c.SumVariants, ([MakeVariant('foo'), MakeVariant('bar')],), 'foobar')
|
||||
|
||||
if not test_flat:
|
||||
c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)
|
||||
# NULL DOM strings don't work yet.
|
||||
@@ -491,29 +501,20 @@ def test_from_js():
|
||||
raise RuntimeError, "Can not find '%s'" % (fname,)
|
||||
# Note we _dont_ pump the test output out, as debug "xpcshell" spews
|
||||
# extra debug info that will cause our output comparison to fail.
|
||||
try:
|
||||
data = os.popen('xpcshell "' + fname + '"').readlines()
|
||||
good = 0
|
||||
for line in data:
|
||||
if line.strip() == "javascript successfully tested the Python test component.":
|
||||
good = 1
|
||||
if good:
|
||||
print "Javascript could successfully use the Python test component."
|
||||
else:
|
||||
print "** The javascript test appeared to fail! Test output follows **"
|
||||
print "".join(data)
|
||||
print "** End of javascript test output **"
|
||||
|
||||
except os.error, why:
|
||||
print "Error executing the javascript test program:", why
|
||||
|
||||
data = os.popen('xpcshell "' + fname + '"').readlines()
|
||||
good = 0
|
||||
for line in data:
|
||||
if line.strip() == "javascript successfully tested the Python test component.":
|
||||
good = 1
|
||||
if not good:
|
||||
print "** The javascript test appeared to fail! Test output follows **"
|
||||
print "".join(data)
|
||||
print "** End of javascript test output **"
|
||||
raise RuntimeError, "test failed"
|
||||
|
||||
def doit(num_loops = -1):
|
||||
if "-v" in sys.argv: # Hack the verbose flag for the server
|
||||
xpcom.verbose = 1
|
||||
# Do the test lots of times - can help shake-out ref-count bugs.
|
||||
print "Testing the Python.TestComponent component"
|
||||
if num_loops == -1: num_loops = 10
|
||||
if num_loops == -1: num_loops = 5
|
||||
for i in xrange(num_loops):
|
||||
test_all()
|
||||
|
||||
@@ -535,38 +536,40 @@ def doit(num_loops = -1):
|
||||
# Sometimes we get spurious counts off by 1 or 2.
|
||||
# This can't indicate a real leak, as we have looped
|
||||
# more than twice!
|
||||
if abs(lost)>2:
|
||||
if abs(lost)>3: # 2 or 3 :)
|
||||
print "*** Lost %d references" % (lost,)
|
||||
|
||||
# sleep to allow the OS to recover
|
||||
time.sleep(1)
|
||||
mem_lost = getmemusage() - mem_usage
|
||||
# working set size is fickle, and when we were leaking strings, this test
|
||||
# would report a leak of 100MB. So we allow a 2MB buffer - but even this
|
||||
# would report a leak of 100MB. So we allow a 3MB buffer - but even this
|
||||
# may still occasionally report spurious warnings. If you are really
|
||||
# worried, bump the counter to a huge value, and if there is a leak it will
|
||||
# show.
|
||||
if mem_lost > 2000000:
|
||||
if mem_lost > 3000000:
|
||||
print "*** Lost %.6f MB of memory" % (mem_lost/1000000.0,)
|
||||
|
||||
if num_errors:
|
||||
print "There were", num_errors, "errors testing the Python component :-("
|
||||
else:
|
||||
print "The Python test component worked!"
|
||||
assert num_errors==0, "There were %d errors testing the Python component" % (num_errors,)
|
||||
|
||||
# regrtest doesn't like if __name__=='__main__' blocks - it fails when running as a test!
|
||||
num_iters = -1
|
||||
if __name__=='__main__' and len(sys.argv) > 1:
|
||||
num_iters = int(sys.argv[1])
|
||||
|
||||
doit(num_iters)
|
||||
test_from_js()
|
||||
def suite():
|
||||
from pyxpcom_test_tools import suite_from_functions
|
||||
return suite_from_functions(doit, test_from_js)
|
||||
|
||||
if __name__=='__main__':
|
||||
# But we can only do this if _not_ testing - otherwise we
|
||||
# screw up any tests that want to run later.
|
||||
num_iters = 10 # times times is *lots* - we do a fair bit of work!
|
||||
if __name__=='__main__' and len(sys.argv) > 1:
|
||||
num_iters = int(sys.argv[1])
|
||||
|
||||
if "-v" in sys.argv: # Hack the verbose flag for the server
|
||||
xpcom.verbose = 1
|
||||
|
||||
print "Testing the Python.TestComponent component"
|
||||
doit(num_iters)
|
||||
print "The Python test component worked."
|
||||
test_from_js()
|
||||
print "JS successfully used our Python test component."
|
||||
xpcom._xpcom.NS_ShutdownXPCOM()
|
||||
ni = xpcom._xpcom._GetInterfaceCount()
|
||||
ng = xpcom._xpcom._GetGatewayCount()
|
||||
if ni or ng:
|
||||
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
||||
print "test completed with %d interfaces and %d objects." % (ni, ng)
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
# test_weakreferences.py - Test our weak reference implementation.
|
||||
from xpcom import components, _xpcom
|
||||
import xpcom.server, xpcom.client
|
||||
from pyxpcom_test_tools import suite_from_functions, testmain
|
||||
|
||||
try:
|
||||
from sys import gettotalrefcount
|
||||
@@ -104,13 +105,10 @@ def test_refcount(num_loops=-1):
|
||||
# more than twice!
|
||||
if abs(lost)>2:
|
||||
print "*** Lost %d references" % (lost,)
|
||||
|
||||
test_refcount()
|
||||
|
||||
print "Weak-reference tests appear to have worked!"
|
||||
# Make this test run under our std test suite
|
||||
def suite():
|
||||
return suite_from_functions(test_refcount)
|
||||
|
||||
if __name__=='__main__':
|
||||
_xpcom.NS_ShutdownXPCOM()
|
||||
ni = xpcom._xpcom._GetInterfaceCount()
|
||||
ng = xpcom._xpcom._GetGatewayCount()
|
||||
if ni or ng:
|
||||
print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
||||
testmain()
|
||||
|
||||
Reference in New Issue
Block a user