Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
test_test_component Namespace Reference

Functions

def print_error
def _test_value
def test_attribute
def test_string_attribute
def test_attribute_failure
def test_method
def test_int_method
def test_constant
def test_base_interface
def test_derived_interface
def do_test_failures
def test_failures
def test_all
def gettotalrefcount
def test_from_js
def doit

Variables

 gc = None
int num_errors = 0
tuple component_iid = xpcom.components.ID("{7EE4BDC6-CB53-42c1-A9E4-616B8E012ABA}")
tuple new_iid = xpcom.components.ID("{2AF747D3-ECBC-457b-9AF9-5C5D80EDC360}")
string contractid = "Python.TestComponent"
string really_big_string = "This is really repetitive!"
string really_big_wstring = u"This is really repetitive!"
string extended_unicode_string = u"The Euro Symbol is '\u20ac'"
 UnsignedMismatchException = TypeError
 i = xpcom.components.interfaces.nsIPythonTestInterface
 test_method(c.do_nsISupportsIs2, (xpcom.components.interfaces.nsIPythonTestInterface,c), (xpcom.components.interfaces.nsIPythonTestInterface,c)) test_method(c.do_nsISupportsIs3, (c,), (xpcom.components.interfaces.nsIPythonTestInterface,c)) test_method(c.do_nsISupportsIs4, (), (xpcom.components.interfaces.nsIPythonTestInterface,c)) Test the constants.
int num_iters = 1
tuple ni = xpcom._xpcom._GetInterfaceCount()
tuple ng = xpcom._xpcom._GetGatewayCount()

Function Documentation

def test_test_component._test_value (   what,
  got,
  expecting 
) [private]

Definition at line 71 of file test_test_component.py.

00071 
00072 def _test_value(what, got, expecting):
00073     ok = got == expecting
00074     if type(got)==type(expecting)==type(0.0):
00075         ok = abs(got-expecting) < 0.001
00076     if not ok:
00077         print_error("*** Error %s - got '%r', but expecting '%r'" % (what, got, expecting))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 439 of file test_test_component.py.

00439 
00440 def do_test_failures():
00441     c = xpcom.client.Component(contractid, xpcom.components.interfaces.nsIPythonTestInterfaceExtra)
00442     try:
00443         ret = c.do_nsISupportsIs( xpcom._xpcom.IID_nsIInterfaceInfoManager )
00444         print "*** got", ret, "***"
00445         raise RuntimeError, "We worked when using an IID we dont support!?!"
00446     except xpcom.Exception, details:
00447         if details.errno != xpcom.nsError.NS_ERROR_NO_INTERFACE:
00448             raise RuntimeError, "Wrong COM exception type: %r" % (details,)

Here is the caller graph for this function:

def test_test_component.doit (   num_loops = -1)

Definition at line 511 of file test_test_component.py.

00511 
00512 def doit(num_loops = -1):
00513     if "-v" in sys.argv: # Hack the verbose flag for the server
00514         xpcom.verbose = 1
00515     # Do the test lots of times - can help shake-out ref-count bugs.
00516     print "Testing the Python.TestComponent component"
00517     if num_loops == -1: num_loops = 10
00518     for i in xrange(num_loops):
00519         test_all()
00520 
00521         if i==0:
00522             # First loop is likely to "leak" as we cache things.
00523             # Leaking after that is a problem.
00524             if gc is not None:
00525                 gc.collect()
00526             num_refs = gettotalrefcount()
00527             mem_usage = getmemusage()
00528 
00529         if num_errors:
00530             break
00531 
00532     if gc is not None:
00533         gc.collect()
00534 
00535     lost = gettotalrefcount() - num_refs
00536     # Sometimes we get spurious counts off by 1 or 2.
00537     # This can't indicate a real leak, as we have looped
00538     # more than twice!
00539     if abs(lost)>2:
00540         print "*** Lost %d references" % (lost,)
00541 
00542     # sleep to allow the OS to recover
00543     time.sleep(1)
00544     mem_lost = getmemusage() - mem_usage
00545     # working set size is fickle, and when we were leaking strings, this test
00546     # would report a leak of 100MB.  So we allow a 2MB buffer - but even this
00547     # may still occasionally report spurious warnings.  If you are really
00548     # worried, bump the counter to a huge value, and if there is a leak it will
00549     # show.
00550     if mem_lost > 2000000:
00551         print "*** Lost %.6f MB of memory" % (mem_lost/1000000.0,)
00552 
00553     if num_errors:
00554         print "There were", num_errors, "errors testing the Python component :-("
00555     else:
00556         print "The Python test component worked!"
00557 
# regrtest doesnt like if __name__=='__main__' blocks - it fails when running as a test!

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 479 of file test_test_component.py.

00479 
00480     def gettotalrefcount():
00481         return 0

Here is the caller graph for this function:

Definition at line 66 of file test_test_component.py.

00066 
00067 def print_error(error):
00068     print error
00069     global num_errors
00070     num_errors = num_errors + 1

Here is the caller graph for this function:

Definition at line 453 of file test_test_component.py.

00453 
00454 def test_all():
00455     c = xpcom.client.Component(contractid, xpcom.components.interfaces.nsIPythonTestInterface)
00456     test_base_interface(c)
00457     # Now create an instance using the derived IID, and test that.
00458     c = xpcom.client.Component(contractid, xpcom.components.interfaces.nsIPythonTestInterfaceExtra)
00459     test_base_interface(c)
00460     test_derived_interface(c)
00461     # Now create an instance and test interface flattening.
00462     c = xpcom.components.classes[contractid].createInstance()
00463     test_base_interface(c)
00464     test_derived_interface(c, test_flat=1)
00465 
00466     # We had a bug where a "set" of an attribute before a "get" failed.
00467     # Don't let it happen again :)
00468     c = xpcom.components.classes[contractid].createInstance()
00469     c.boolean_value = 0
00470     
00471     # This name is used in exceptions etc - make sure we got it from nsIClassInfo OK.
00472     assert c._object_name_ == "Python.TestComponent"
00473 
00474     test_failures()
00475 
00476 try:
    from sys import gettotalrefcount

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_attribute (   ob,
  attr_name,
  expected_init,
  new_value,
  new_value_really = None 
)

Definition at line 78 of file test_test_component.py.

00078 
00079 def test_attribute(ob, attr_name, expected_init, new_value, new_value_really = None):
00080     if xpcom.verbose:
00081         print "Testing attribute %s" % (attr_name,)
00082     if new_value_really is None:
00083         new_value_really = new_value # Handy for eg bools - set a BOOL to 2, you still get back 1!
00084         
00085     _test_value( "getting initial attribute value (%s)" % (attr_name,), getattr(ob, attr_name), expected_init)
00086     setattr(ob, attr_name, new_value)
00087     _test_value( "getting new attribute value (%s)" % (attr_name,), getattr(ob, attr_name), new_value_really)
00088     # And set it back to the expected init.
00089     setattr(ob, attr_name, expected_init)
00090     _test_value( "getting back initial attribute value after change (%s)" % (attr_name,), getattr(ob, attr_name), expected_init)

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_attribute_failure (   ob,
  attr_name,
  new_value,
  expected_exception 
)

Definition at line 113 of file test_test_component.py.

00113 
00114 def test_attribute_failure(ob, attr_name, new_value, expected_exception):
00115     try:
00116         setattr(ob, attr_name, new_value)
00117         print_error("*** Setting attribute '%s' to '%r' didnt yield an exception!" % (attr_name, new_value) )
00118     except:
00119         exc_typ = sys.exc_info()[0]
00120         exc_val = sys.exc_info()[1]
00121         ok = issubclass(exc_typ, expected_exception)
00122         if not ok:
00123             print_error("*** Wrong exception setting '%s' to '%r'- got '%s: %s', expected '%s'" % (attr_name, new_value, exc_typ, exc_val, expected_exception))
00124 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 148 of file test_test_component.py.

00148 
00149 def test_base_interface(c):
00150     test_attribute(c, "boolean_value", 1, 0)
00151     test_attribute(c, "boolean_value", 1, -1, 1) # Set a bool to anything, you should always get back 0 or 1
00152     test_attribute(c, "boolean_value", 1, 4, 1) # Set a bool to anything, you should always get back 0 or 1
00153     test_attribute(c, "boolean_value", 1, "1", 1) # This works by virtual of PyNumber_Int - not sure I agree, but...
00154     test_attribute_failure(c, "boolean_value", "boo", ValueError)
00155     test_attribute_failure(c, "boolean_value", test_base_interface, TypeError)
00156 
00157     test_attribute(c, "octet_value", 2, 5)
00158     test_attribute(c, "octet_value", 2, 0)
00159     test_attribute(c, "octet_value", 2, 128) # octet is unsigned 8 bit
00160     test_attribute(c, "octet_value", 2, 255) # octet is unsigned 8 bit
00161     test_attribute(c, "octet_value", 2, -1, 255) # octet is unsigned 8 bit
00162     test_attribute_failure(c, "octet_value", "boo", ValueError)
00163 
00164     test_attribute(c, "short_value", 3, 10)
00165     test_attribute(c, "short_value", 3, -1) # 16 bit signed
00166     test_attribute(c, "short_value", 3, 0xFFFF, -1) # 16 bit signed
00167     test_attribute(c, "short_value", 3, 0L)
00168     test_attribute(c, "short_value", 3, 1L)
00169     test_attribute(c, "short_value", 3, -1L)
00170     test_attribute(c, "short_value", 3, 0xFFFFL, -1)
00171     test_attribute_failure(c, "short_value", "boo", ValueError)
00172 
00173     test_attribute(c, "ushort_value",  4, 5)
00174     test_attribute(c, "ushort_value",  4, 0)
00175     test_attribute(c, "ushort_value",  4, -1, 0xFFFF) # 16 bit signed
00176     test_attribute(c, "ushort_value",  4, 0xFFFF) # 16 bit signed
00177     test_attribute(c, "ushort_value",  4, 0L)
00178     test_attribute(c, "ushort_value",  4, 1L)
00179     test_attribute(c, "ushort_value",  4, -1L, 0xFFFF)
00180     test_attribute_failure(c, "ushort_value", "boo", ValueError)
00181 
00182     test_attribute(c, "long_value",  5, 7)
00183     test_attribute(c, "long_value",  5, 0)
00184     test_attribute(c, "long_value",  5, 0xFFFFFFFF, -1) # 32 bit signed.
00185     test_attribute(c, "long_value",  5, -1) # 32 bit signed.
00186     test_attribute(c, "long_value",  5, 0L)
00187     test_attribute(c, "long_value",  5, 1L)
00188     test_attribute(c, "long_value",  5, -1L)
00189     test_attribute_failure(c, "long_value", 0xFFFFL * 0xFFFF, OverflowError) # long int too long to convert
00190     test_attribute_failure(c, "long_value", "boo", ValueError)
00191 
00192     test_attribute(c, "ulong_value", 6, 7)
00193     test_attribute(c, "ulong_value", 6, 0)
00194     test_attribute(c, "ulong_value", 6, 0xFFFFFFFF) # 32 bit signed.
00195     test_attribute_failure(c, "ulong_value", "boo", ValueError)
00196     
00197     test_attribute(c, "long_long_value", 7, 8)
00198     test_attribute(c, "long_long_value", 7, 0)
00199     test_attribute(c, "long_long_value", 7, -1)
00200     test_attribute(c, "long_long_value", 7, 0xFFFF)
00201     test_attribute(c, "long_long_value", 7, 0xFFFFL * 2)
00202     test_attribute_failure(c, "long_long_value", 0xFFFFL * 0xFFFF * 0xFFFF * 0xFFFF, OverflowError) # long int too long to convert
00203     test_attribute_failure(c, "long_long_value", "boo", ValueError)
00204     
00205     test_attribute(c, "ulong_long_value", 8, 9)
00206     test_attribute(c, "ulong_long_value", 8, 0)
00207     test_attribute_failure(c, "ulong_long_value", "boo", ValueError)
00208     test_attribute_failure(c, "ulong_long_value", -1, UnsignedMismatchException) # can't convert negative value to unsigned long)
00209     
00210     test_attribute(c, "float_value", 9.0, 10.2)
00211     test_attribute(c, "float_value", 9.0, 0)
00212     test_attribute(c, "float_value", 9.0, -1)
00213     test_attribute(c, "float_value", 9.0, 1L)
00214     test_attribute_failure(c, "float_value", "boo", ValueError)
00215 
00216     test_attribute(c, "double_value", 10.0, 9.0)
00217     test_attribute(c, "double_value", 10.0, 0)
00218     test_attribute(c, "double_value", 10.0, -1)
00219     test_attribute(c, "double_value", 10.0, 1L)
00220     test_attribute_failure(c, "double_value", "boo", ValueError)
00221     
00222     test_attribute(c, "char_value", "a", "b")
00223     test_attribute(c, "char_value", "a", "\0")
00224     test_attribute_failure(c, "char_value", "xy", ValueError)
00225     test_attribute(c, "char_value", "a", u"c")
00226     test_attribute(c, "char_value", "a", u"\0")
00227     test_attribute_failure(c, "char_value", u"xy", ValueError)
00228     
00229     test_attribute(c, "wchar_value", "b", "a")
00230     test_attribute(c, "wchar_value", "b", "\0")
00231     test_attribute_failure(c, "wchar_value", "hi", ValueError)
00232     test_attribute(c, "wchar_value", "b", u"a")
00233     test_attribute(c, "wchar_value", "b", u"\0")
00234     test_attribute_failure(c, "wchar_value", u"hi", ValueError)
00235     
00236     test_string_attribute(c, "string_value", "cee", is_dumb_sz = True, ascii_only = True)
00237     test_string_attribute(c, "wstring_value", "dee", is_dumb_sz = True)
00238     test_string_attribute(c, "astring_value", "astring")
00239     test_string_attribute(c, "acstring_value", "acstring", ascii_only = True)
00240 
00241     test_string_attribute(c, "utf8string_value", "utf8string")
00242     # Test a string already encoded gets through correctly.
00243     test_attribute(c, "utf8string_value", "utf8string", extended_unicode_string.encode("utf8"), extended_unicode_string)
00244 
00245     # This will fail internal string representation :(  Test we don't crash
00246     try:
00247         c.wstring_value = "a big char >" + chr(129) + "<"
00248         print_error("strings with chars > 128 appear to have stopped failing?")
00249     except UnicodeError:
00250         pass
00251 
00252     test_attribute(c, "iid_value", component_iid, new_iid)
00253     test_attribute(c, "iid_value", component_iid, str(new_iid), new_iid)
00254     test_attribute(c, "iid_value", component_iid, xpcom._xpcom.IID(new_iid))
00255 
00256     test_attribute_failure(c, "no_attribute", "boo", AttributeError)
00257 
00258     test_attribute(c, "interface_value", None, c)
00259     test_attribute_failure(c, "interface_value", 2, TypeError)
00260 
00261     test_attribute(c, "isupports_value", None, c)
00262 
00263     # The methods
00264     test_method(c.do_boolean, (0,1), (1,0,1))
00265     test_method(c.do_boolean, (1,0), (1,0,1))
00266     test_method(c.do_boolean, (1,1), (0,1,0))
00267 
00268     test_int_method(c.do_octet)
00269     test_int_method(c.do_short)
00270 
00271     test_int_method(c.do_unsigned_short)
00272     test_int_method(c.do_long)
00273     test_int_method(c.do_unsigned_long)
00274     test_int_method(c.do_long_long)
00275     test_int_method(c.do_unsigned_long)
00276     test_int_method(c.do_float)
00277     test_int_method(c.do_double)
00278 
00279     test_method(c.do_char, ("A", " "), (chr(ord("A")+ord(" ")), " ","A") )
00280     test_method(c.do_char, ("A", "\0"), ("A", "\0","A") )
00281     test_method(c.do_wchar, ("A", " "), (chr(ord("A")+ord(" ")), " ","A") )
00282     test_method(c.do_wchar, ("A", "\0"), ("A", "\0","A") )
00283 
00284     test_method(c.do_string, ("Hello from ", "Python"), ("Hello from Python", "Hello from ", "Python") )
00285     test_method(c.do_string, (u"Hello from ", u"Python"), ("Hello from Python", "Hello from ", "Python") )
00286     test_method(c.do_string, (None, u"Python"), ("Python", None, "Python") )
00287     test_method(c.do_string, (None, really_big_string), (really_big_string, None, really_big_string) )
00288     test_method(c.do_string, (None, really_big_wstring), (really_big_string, None, really_big_string) )
00289     test_method(c.do_wstring, ("Hello from ", "Python"), ("Hello from Python", "Hello from ", "Python") )
00290     test_method(c.do_wstring, (u"Hello from ", u"Python"), ("Hello from Python", "Hello from ", "Python") )
00291     test_method(c.do_string, (None, really_big_wstring), (really_big_wstring, None, really_big_wstring) )
00292     test_method(c.do_string, (None, really_big_string), (really_big_wstring, None, really_big_wstring) )
00293     test_method(c.do_nsIIDRef, (component_iid, new_iid), (component_iid, component_iid, new_iid))
00294     test_method(c.do_nsIIDRef, (new_iid, component_iid), (new_iid, component_iid, component_iid))
00295     test_method(c.do_nsIPythonTestInterface, (None, None), (None, None, c))
00296     test_method(c.do_nsIPythonTestInterface, (c, c), (c, c, c))
00297     test_method(c.do_nsISupports, (None, None), (c, None, None))
00298     test_method(c.do_nsISupports, (c,c), (c, c, c))
00299     test_method(c.do_nsISupportsIs, (xpcom._xpcom.IID_nsISupports,), c)
    test_method(c.do_nsISupportsIs, (xpcom.components.interfaces.nsIPythonTestInterface,), c)

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_constant (   ob,
  cname,
  val 
)

Definition at line 138 of file test_test_component.py.

00138 
00139 def test_constant(ob, cname, val):
00140     v = getattr(ob, cname)
00141     if v != val:
00142         print_error("Bad value for constant '%s' - got '%r'" % (cname, v))
00143     try:
00144         setattr(ob, cname, 0)
00145         print_error("The object allowed us to set the constant '%s'" % (cname,))
00146     except AttributeError:
00147         pass

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_derived_interface (   c,
  test_flat = 0 
)

Definition at line 318 of file test_test_component.py.

00318 
00319 def test_derived_interface(c, test_flat = 0):
00320     val = "Hello\0there"
00321     expected = val * 2
00322 
00323     test_method(c.DoubleString, (val,), expected)
00324     test_method(c.DoubleString2, (val,), expected)
00325     test_method(c.DoubleString3, (val,), expected)
00326     test_method(c.DoubleString4, (val,), expected)
00327     test_method(c.UpString, (val,), val.upper())
00328     test_method(c.UpString2, (val,), val.upper())
00329     test_method(c.GetFixedString, (20,), "A"*20)
00330     val = u"Hello\0there"
00331     expected = val * 2
00332     test_method(c.DoubleWideString, (val,), expected)
00333     test_method(c.DoubleWideString2, (val,), expected)
00334     test_method(c.DoubleWideString3, (val,), expected)
00335     test_method(c.DoubleWideString4, (val,), expected)
00336     test_method(c.UpWideString, (val,), val.upper())
00337     test_method(c.UpWideString2, (val,), val.upper())
00338     test_method(c.GetFixedWideString, (20,), u"A"*20)
00339     val = extended_unicode_string
00340     test_method(c.CopyUTF8String, ("foo",), "foo")
00341     test_method(c.CopyUTF8String, (u"foo",), "foo")
00342     test_method(c.CopyUTF8String, (val,), val)
00343     test_method(c.CopyUTF8String, (val.encode("utf8"),), val)
00344     test_method(c.CopyUTF8String2, ("foo",), "foo")
00345     test_method(c.CopyUTF8String2, (u"foo",), "foo")
00346     test_method(c.CopyUTF8String2, (val,), val)
00347     test_method(c.CopyUTF8String2, (val.encode("utf8"),), val)
00348     items = [1,2,3,4,5]
00349     test_method(c.MultiplyEachItemInIntegerArray, (3, items,), map(lambda i:i*3, items))
00350 
00351     test_method(c.MultiplyEachItemInIntegerArrayAndAppend, (3, items), items + map(lambda i:i*3, items))
00352     items = "Hello from Python".split()
00353     expected = map( lambda x: x*2, items)
00354     test_method(c.DoubleStringArray, (items,), expected)
00355 
00356     test_method(c.CompareStringArrays, (items, items), cmp(items, items))
00357     # Can we pass lists and tuples correctly?
00358     test_method(c.CompareStringArrays, (items, tuple(items)), cmp(items, items))
00359     items2 = ["Not", "the", "same"]
00360     test_method(c.CompareStringArrays, (items, items2), cmp(items, items2))
00361 
00362     expected = items[:]
00363     expected.reverse()
00364     test_method(c.ReverseStringArray, (items,), expected)
00365 
00366     expected = "Hello from the Python test component".split()
00367     test_method(c.GetStrings, (), expected)
00368 
00369     val = "Hello\0there"
00370     test_method(c.UpOctetArray, (val,), val.upper())
00371     test_method(c.UpOctetArray, (unicode(val),), val.upper())
00372     # Passing Unicode objects here used to cause us grief.
00373     test_method(c.UpOctetArray2, (val,), val.upper())
00374 
00375     test_method(c.CheckInterfaceArray, ((c, c),), 1)
00376     test_method(c.CheckInterfaceArray, ((c, None),), 0)
00377     test_method(c.CheckInterfaceArray, ((),), 1)
00378     test_method(c.CopyInterfaceArray, ((c, c),), [c,c])
00379 
00380     test_method(c.GetInterfaceArray, (), [c,c,c, None])
00381     test_method(c.ExtendInterfaceArray, ((c,c,c, None),), [c,c,c,None,c,c,c,None] )
00382 
00383     expected = [xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings, xpcom.components.classes[contractid].clsid]
00384     test_method(c.GetIIDArray, (), expected)
00385 
00386     val = [xpcom.components.interfaces.nsIPythonTestInterfaceExtra, xpcom.components.classes[contractid].clsid]
00387     expected = val * 2
00388     test_method(c.ExtendIIDArray, (val,), expected)
00389 
00390     test_method(c.GetArrays, (), ( [1,2,3], [4,5,6] ) )
00391     test_method(c.CopyArray, ([1,2,3],), [1,2,3] )
00392     test_method(c.CopyAndDoubleArray, ([1,2,3],), [1,2,3,1,2,3] )
00393     test_method(c.AppendArray, ([1,2,3],), [1,2,3])
00394     test_method(c.AppendArray, ([1,2,3],[4,5,6]), [1,2,3,4,5,6])
00395 
00396     test_method(c.CopyVariant, (None,), None)
00397     test_method(c.CopyVariant, (1,), 1)
00398     test_method(c.CopyVariant, (1.0,), 1.0)
00399     test_method(c.CopyVariant, (-1,), -1)
00400     test_method(c.CopyVariant, (sys.maxint+1,), sys.maxint+1)
00401     test_method(c.CopyVariant, ("foo",), "foo")
00402     test_method(c.CopyVariant, (u"foo",), u"foo")
00403     test_method(c.CopyVariant, (c,), c)
00404     test_method(c.CopyVariant, (component_iid,), component_iid)
00405     test_method(c.CopyVariant, ((1,2),), [1,2])
00406     test_method(c.CopyVariant, ((1.2,2.1),), [1.2,2.1])
00407     test_method(c.CopyVariant, (("foo","bar"),), ["foo", "bar"])
00408     test_method(c.CopyVariant, ((component_iid,component_iid),), [component_iid,component_iid])
00409     test_method(c.CopyVariant, ((c,c),), [c,c])
00410     test_method(c.AppendVariant, (1,2), 3)
00411     test_method(c.AppendVariant, ((1,2),(3,4)), 10)
00412     test_method(c.AppendVariant, ("bar", "foo"), "foobar")
00413     test_method(c.AppendVariant, (None, None), None)
00414 
00415     if not test_flat:
00416         c = c.queryInterface(xpcom.components.interfaces.nsIPythonTestInterfaceDOMStrings)
00417 # NULL DOM strings don't work yet.
00418 #    test_method(c.GetDOMStringResult, (-1,), None)
00419     test_method(c.GetDOMStringResult, (3,), "PPP")
00420 #    test_method(c.GetDOMStringOut, (-1,), None)
00421     test_method(c.GetDOMStringOut, (4,), "yyyy")
00422     val = "Hello there"
00423     test_method(c.GetDOMStringLength, (val,), len(val))
00424     test_method(c.GetDOMStringRefLength, (val,), len(val))
00425     test_method(c.GetDOMStringPtrLength, (val,), len(val))
00426     test_method(c.ConcatDOMStrings, (val,val), val+val)
00427     test_attribute(c, "domstring_value", "dom", "new dom")
00428     if c.domstring_value_ro != "dom":
00429         print "Read-only DOMString not correct - got", c.domstring_ro
00430     try:
00431         c.dom_string_ro = "new dom"
00432         print "Managed to set a readonly attribute - eek!"
00433     except AttributeError:
00434         pass
00435     except:
00436         print "Unexpected exception when setting readonly attribute: %s: %s" % (sys.exc_info()[0], sys.exc_info()[1])
00437     if c.domstring_value_ro != "dom":
00438         print "Read-only DOMString not correct after failed set attempt - got", c.domstring_ro

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 449 of file test_test_component.py.

00449 
00450 def test_failures():
00451     # This extra stack-frame ensures Python cleans up sys.last_traceback etc
00452     do_test_failures()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 484 of file test_test_component.py.

00484 
00485 def test_from_js():
00486     # Ensure we can find the js test script - same dir as this!
00487     # Assume the path of sys.argv[0] is where we can find the js test code.
00488     # (Running under the regression test is a little painful)
00489     script_dir = os.path.split(sys.argv[0])[0]
00490     fname = os.path.join( script_dir, "test_test_component.js")
00491     if not os.path.isfile(fname):
00492         raise RuntimeError, "Can not find '%s'" % (fname,)
00493     # Note we _dont_ pump the test output out, as debug "xpcshell" spews
00494     # extra debug info that will cause our output comparison to fail.
00495     try:
00496         data = os.popen('xpcshell "' + fname + '"').readlines()
00497         good = 0
00498         for line in data:
00499             if line.strip() == "javascript successfully tested the Python test component.":
00500                 good = 1
00501         if good:
00502             print "Javascript could successfully use the Python test component."
00503         else:
00504             print "** The javascript test appeared to fail!  Test output follows **"
00505             print "".join(data)
00506             print "** End of javascript test output **"
00507 
00508     except os.error, why:
00509         print "Error executing the javascript test program:", why
00510         

Definition at line 132 of file test_test_component.py.

00132 
00133 def test_int_method(meth):
00134     test_method(meth, (0,0), (0,0,0))
00135     test_method(meth, (1,1), (2,0,1))
00136     test_method(meth, (5,2), (7,3,10))
00137 #    test_method(meth, (2,5), (7,-3,10))

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_method (   method,
  args,
  expected_results 
)

Definition at line 125 of file test_test_component.py.

00125 
00126 def test_method(method, args, expected_results):
00127     if xpcom.verbose:
00128         print "Testing %s%s" % (method.__name__, `args`)
00129     ret = method(*args)
00130     if ret != expected_results:
00131         print_error("calling method %s - expected %r, but got %r" % (method.__name__, expected_results, ret))

Here is the call graph for this function:

Here is the caller graph for this function:

def test_test_component.test_string_attribute (   ob,
  attr_name,
  expected_init,
  is_dumb_sz = False,
  ascii_only = False 
)

Definition at line 91 of file test_test_component.py.

00091 
00092 def test_string_attribute(ob, attr_name, expected_init, is_dumb_sz = False, ascii_only = False):
00093     test_attribute(ob, attr_name, expected_init, "normal value")
00094     val = "a null >\0<"
00095     if is_dumb_sz:
00096         expected = "a null >" # dumb strings are \0 terminated.
00097     else:
00098         expected = val
00099     test_attribute(ob, attr_name, expected_init, val, expected)
00100     test_attribute(ob, attr_name, expected_init, "")
00101     test_attribute(ob, attr_name, expected_init, really_big_string)
00102     test_attribute(ob, attr_name, expected_init, u"normal unicode value")
00103     val = u"a null >\0<"
00104     if is_dumb_sz:
00105         expected = "a null >" # dumb strings are \0 terminated.
00106     else:
00107         expected = val
00108     test_attribute(ob, attr_name, expected_init, val, expected)
00109     test_attribute(ob, attr_name, expected_init, u"")
00110     test_attribute(ob, attr_name, expected_init, really_big_wstring)
00111     if not ascii_only:
00112         test_attribute(ob, attr_name, expected_init, extended_unicode_string)

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple test_test_component.component_iid = xpcom.components.ID("{7EE4BDC6-CB53-42c1-A9E4-616B8E012ABA}")

Definition at line 50 of file test_test_component.py.

string test_test_component.contractid = "Python.TestComponent"

Definition at line 53 of file test_test_component.py.

Definition at line 57 of file test_test_component.py.

Definition at line 46 of file test_test_component.py.

test_test_component.i = xpcom.components.interfaces.nsIPythonTestInterface

test_method(c.do_nsISupportsIs2, (xpcom.components.interfaces.nsIPythonTestInterface,c), (xpcom.components.interfaces.nsIPythonTestInterface,c)) test_method(c.do_nsISupportsIs3, (c,), (xpcom.components.interfaces.nsIPythonTestInterface,c)) test_method(c.do_nsISupportsIs4, (), (xpcom.components.interfaces.nsIPythonTestInterface,c)) Test the constants.

Definition at line 311 of file test_test_component.py.

tuple test_test_component.new_iid = xpcom.components.ID("{2AF747D3-ECBC-457b-9AF9-5C5D80EDC360}")

Definition at line 51 of file test_test_component.py.

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

Definition at line 570 of file test_test_component.py.

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

Definition at line 569 of file test_test_component.py.

Definition at line 48 of file test_test_component.py.

Definition at line 558 of file test_test_component.py.

string test_test_component.really_big_string = "This is really repetitive!"

Definition at line 55 of file test_test_component.py.

string test_test_component.really_big_wstring = u"This is really repetitive!"

Definition at line 56 of file test_test_component.py.

Definition at line 62 of file test_test_component.py.