Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
test_weakreferences Namespace Reference

Classes

class  koTestSimple

Functions

def test
def test_refcount

Variables

int gettotalrefcount = 0
int num_alive = 0
tuple ni = xpcom._xpcom._GetInterfaceCount()
tuple ng = xpcom._xpcom._GetGatewayCount()

Function Documentation

Definition at line 61 of file test_weakreferences.py.

00061 
00062 def test():
00063     ob = xpcom.server.WrapObject( koTestSimple(), components.interfaces.nsIInputStream)
00064 
00065     if num_alive != 1: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00066 
00067     # Check we can create a weak reference to our object.
00068     wr = xpcom.client.WeakReference(ob)
00069     if num_alive != 1: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00070 
00071     # Check we can call methods via the weak reference.
00072     if wr() is None: raise RuntimeError, "Our weak-reference is returning None before it should!"
00073     wr().close()
00074 
00075     ob  = None # This should kill the object.    
00076     if num_alive != 0: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00077     if wr() is not None: raise RuntimeError, "Our weak-reference is not returning None when it should!"
00078 
00079     # Now a test that we can get a _new_ interface from the weak reference - ie,
00080     # an IID the real object has never previously been queried for
00081     # (this behaviour previously caused a bug - never again ;-)
00082     ob = xpcom.server.WrapObject( koTestSimple(), components.interfaces.nsISupports)
00083     if num_alive != 1: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00084     wr = xpcom.client.WeakReference(ob, components.interfaces.nsIInputStream)
00085     if num_alive != 1: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00086     wr() # This would die once upon a time ;-)
00087     ob  = None # This should kill the object.    
00088     if num_alive != 0: raise RuntimeError, "Eeek - there are %d objects alive" % (num_alive,)
00089     if wr() is not None: raise RuntimeError, "Our weak-reference is not returning None when it should!"

Here is the call graph for this function:

def test_weakreferences.test_refcount (   num_loops = -1)

Definition at line 90 of file test_weakreferences.py.

00090 
00091 def test_refcount(num_loops=-1):
00092     # Do the test lots of times - can help shake-out ref-count bugs.
00093     if num_loops == -1: num_loops = 10
00094     for i in xrange(num_loops):
00095         test()
00096 
00097         if i==0:
00098             # First loop is likely to "leak" as we cache things.
00099             # Leaking after that is a problem.
00100             num_refs = gettotalrefcount()
00101 
00102     lost = gettotalrefcount() - num_refs
00103     # Sometimes we get spurious counts off by 1 or 2.
00104     # This can't indicate a real leak, as we have looped
00105     # more than twice!
00106     if abs(lost)>2:
00107         print "*** Lost %d references" % (lost,)
00108     
00109 test_refcount()


Variable Documentation

Definition at line 46 of file test_weakreferences.py.

tuple test_weakreferences.ng = xpcom._xpcom._GetGatewayCount()

Definition at line 114 of file test_weakreferences.py.

tuple test_weakreferences.ni = xpcom._xpcom._GetInterfaceCount()

Definition at line 113 of file test_weakreferences.py.

Definition at line 48 of file test_weakreferences.py.