Add interface flattening to Python XPCOM bindings.

Not part of the build, but a=drivers@mozilla.org anyway!


git-svn-id: svn://10.0.0.236/trunk@95969 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
markh%activestate.com
2001-05-27 02:51:18 +00:00
parent fe15e59b3c
commit 031bf2a05c
24 changed files with 649 additions and 199 deletions

View File

@@ -1,9 +1,10 @@
test_misc
Running all tests - use '-h' to see command-line options...
The netscape sample worked!
Dumping every interface I can find - please wait
(verbosity is turned off, so I'm not actually going to print them)
Finished dumping all the interfaces.
Enumerated all the ContractIDs
xpcom object hashing tests seemed to work
Dumping every interface I can find - please wait
(verbosity is turned off, so Im not actually going to print them)
Finished dumping all the interfaces.
The IID tests seemed to work
The netscape sample worked!
The netscape sample worked with interface flattening!

View File

@@ -49,8 +49,8 @@ def test_interfaces():
def test_classes():
# Need a well-known contractID here?
prog_id = "@mozilla.org/filelocator;1"
clsid = xpcom.components.ID("{78043e01-e603-11d2-915f-f08a208628fc}")
prog_id = "@mozilla.org/supports-array;1"
clsid = xpcom.components.ID("{bda17d50-0d6b-11d3-9331-00104ba0fd40}")
# Check we can create the instance (dont check we can do anything with it tho!)
klass = xpcom.components.classes[prog_id]

View File

@@ -73,7 +73,7 @@ class ImplicitSupportsFloat:
def test():
import xpcom.server, xpcom.client
ob = xpcom.server.WrapObject( NoSupportsString(), components.interfaces.nsISupports)
if not str(ob).startswith("<XPCOM interface"):
if not str(ob).startswith("<XPCOM "):
raise RuntimeError, "Wrong str() value: %s" % (ob,)
ob = xpcom.server.WrapObject( ImplicitSupportsString(), components.interfaces.nsISupports)

View File

@@ -32,7 +32,7 @@ def DumpEveryInterfaceUnderTheSun():
print "Dumping every interface I can find - please wait"
if verbose_level == 0:
print "(verbosity is turned off, so Im not actually going to print them)"
print "(verbosity is turned off, so I'm not actually going to print them)"
enum = iim.EnumerateInterfaces()
rc = enum.First()
num = 0
@@ -70,19 +70,27 @@ def EnumContractIDs():
print "Only found", n, "ContractIDs - this seems unusually low!"
print "Enumerated all the ContractIDs"
def TestSampleComponent():
def TestSampleComponent(test_flat = 0):
"""Test the standard Netscape 'sample' sample"""
# contractid = "mozilla.jssample.1" # the JS version
contractid = "@mozilla.org/sample;1" # The C++ version.
c = xpcom.components.classes[contractid].createInstance() \
.queryInterface(xpcom.components.interfaces.nsISample)
c = xpcom.components.classes[contractid].createInstance()
if not test_flat:
c = c.queryInterface(xpcom.components.interfaces.nsISample)
assert c.value == "initial value"
c.value = "new value"
assert c.value == "new value"
c.poke("poked value")
assert c.value == "poked value"
c.writeValue("Python just poked:")
print "The netscape sample worked!"
if test_flat:
print "The netscape sample worked with interface flattening!"
else:
print "The netscape sample worked!"
def TestSampleComponentFlat():
"""Test the standard Netscape 'sample' sample using interface flattening"""
TestSampleComponent(1)
def TestHash():
"Test that hashing COM objects works"
@@ -140,6 +148,8 @@ def main():
for ob in globals().values():
if type(ob)==type(main) and ob.__doc__:
tests.append(ob)
# Ensure consistent test order.
tests.sort(lambda a,b:cmp(a.__name__, b.__name__))
if __name__ == '__main__': # Only process args when not running under the test suite!
opts, args = getopt.getopt(sys.argv[1:], "hv")
for opt, val in opts:

View File

@@ -264,7 +264,7 @@ def test_base_interface(c):
test_constant(i, "BigLong", 0x7FFFFFFF)
test_constant(i, "BigULong", 0xFFFFFFFF)
def test_derived_interface(c):
def test_derived_interface(c, test_flat = 0):
val = "Hello\0there"
expected = val * 2
@@ -329,7 +329,8 @@ def test_derived_interface(c):
test_method(c.AppendArray, ([1,2,3],), [1,2,3])
test_method(c.AppendArray, ([1,2,3],[4,5,6]), [1,2,3,4,5,6])
c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)
if not test_flat:
c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)
# NULL DOM strings don't work yet.
# test_method(c.GetDOMStringResult, (-1,), None)
test_method(c.GetDOMStringResult, (3,), "PPP")
@@ -374,6 +375,13 @@ def test_all():
c = xpcom.client.Component(contractid, xpcom.components.interfaces.nsIPythonTestInterfaceExtra)
test_base_interface(c)
test_derived_interface(c)
# Now create an instance and test interface flattening.
c = xpcom.components.classes[contractid].createInstance()
test_base_interface(c)
test_derived_interface(c, test_flat=1)
# This name is used in exceptions etc - make sure we got it from nsIClassInfo OK.
assert c._object_name_ == "Python.TestComponent"
test_failures()
try: