home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2736 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.3 KB  |  171 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import win32com.server.util as win32com
  6. import win32com.test.util as win32com
  7. import win32com.client as win32com
  8. import traceback
  9. import pythoncom
  10. import pywintypes
  11. import winerror
  12. L = pywintypes.Unicode
  13. import unittest
  14. error = 'collection test error'
  15.  
  16. def MakeEmptyEnum():
  17.     o = win32com.server.util.wrap(win32com.server.util.Collection())
  18.     return win32com.client.Dispatch(o)
  19.  
  20.  
  21. def MakeTestEnum():
  22.     sub = win32com.server.util.wrap(win32com.server.util.Collection([
  23.         'Sub1',
  24.         2,
  25.         'Sub3']))
  26.     o = win32com.server.util.wrap(win32com.server.util.Collection([
  27.         1,
  28.         'Two',
  29.         3,
  30.         sub]))
  31.     return win32com.client.Dispatch(o)
  32.  
  33.  
  34. def TestEnumAgainst(o, check):
  35.     for i in range(len(check)):
  36.         if o(i) != check[i]:
  37.             raise error, 'Using default method gave the incorrect value - %s/%s' % (`o(i)`, `check[i]`)
  38.         o(i) != check[i]
  39.     
  40.     for i in range(len(check)):
  41.         if o.Item(i) != check[i]:
  42.             raise error, 'Using Item method gave the incorrect value - %s/%s' % (`o(i)`, `check[i]`)
  43.         o.Item(i) != check[i]
  44.     
  45.     cmp = []
  46.     for s in o:
  47.         cmp.append(s)
  48.     
  49.     if cmp[:len(check)] != check:
  50.         raise error, 'Result after looping isnt correct - %s/%s' % (`cmp[:len(check)]`, `check`)
  51.     cmp[:len(check)] != check
  52.     for i in range(len(check)):
  53.         if o[i] != check[i]:
  54.             raise error, 'Using indexing gave the incorrect value'
  55.         o[i] != check[i]
  56.     
  57.  
  58.  
  59. def TestEnum(quiet = None):
  60.     if quiet is None:
  61.         quiet = '-v' not in sys.argv
  62.     
  63.     if not quiet:
  64.         print 'Simple enum test'
  65.     
  66.     o = MakeTestEnum()
  67.     check = [
  68.         1,
  69.         'Two',
  70.         3]
  71.     TestEnumAgainst(o, check)
  72.     if not quiet:
  73.         print 'sub-collection test'
  74.     
  75.     sub = o[3]
  76.     TestEnumAgainst(sub, [
  77.         'Sub1',
  78.         2,
  79.         'Sub3'])
  80.     o.Remove(o.Count() - 1)
  81.     if not quiet:
  82.         print 'Remove item test'
  83.     
  84.     del check[1]
  85.     o.Remove(1)
  86.     TestEnumAgainst(o, check)
  87.     if not quiet:
  88.         print 'Add item test'
  89.     
  90.     o.Add('New Item')
  91.     check.append('New Item')
  92.     TestEnumAgainst(o, check)
  93.     if not quiet:
  94.         print 'Insert item test'
  95.     
  96.     o.Insert(2, -1)
  97.     check.insert(2, -1)
  98.     TestEnumAgainst(o, check)
  99.     
  100.     try:
  101.         o()
  102.         raise error, 'default method with no args worked when it shouldnt have!'
  103.     except pythoncom.com_error:
  104.         (hr, desc, exc, argErr) = None
  105.         if hr != winerror.DISP_E_BADPARAMCOUNT:
  106.             raise error, 'Expected DISP_E_BADPARAMCOUNT - got %d (%s)' % (hr, desc)
  107.         hr != winerror.DISP_E_BADPARAMCOUNT
  108.  
  109.     
  110.     try:
  111.         o.Insert('foo', 2)
  112.         raise error, 'Insert worked when it shouldnt have!'
  113.     except pythoncom.com_error:
  114.         (hr, desc, exc, argErr) = None
  115.         if hr != winerror.DISP_E_TYPEMISMATCH:
  116.             raise error, 'Expected DISP_E_TYPEMISMATCH - got %d (%s)' % (hr, desc)
  117.         hr != winerror.DISP_E_TYPEMISMATCH
  118.  
  119.     
  120.     try:
  121.         o.Remove(o.Count())
  122.         raise error, 'Remove worked when it shouldnt have!'
  123.     except pythoncom.com_error:
  124.         (hr, desc, exc, argErr) = None
  125.         if hr != winerror.DISP_E_BADINDEX:
  126.             raise error, 'Expected DISP_E_BADINDEX - got %d (%s)' % (hr, desc)
  127.         hr != winerror.DISP_E_BADINDEX
  128.  
  129.     if not quiet:
  130.         print 'Empty collection test'
  131.     
  132.     o = MakeEmptyEnum()
  133.     for item in o:
  134.         raise error, 'Empty list performed an iteration'
  135.     
  136.     
  137.     try:
  138.         ob = o[1]
  139.         raise error, 'Empty list could be indexed'
  140.     except IndexError:
  141.         pass
  142.  
  143.     
  144.     try:
  145.         ob = o[0]
  146.         raise error, 'Empty list could be indexed'
  147.     except IndexError:
  148.         pass
  149.  
  150.     
  151.     try:
  152.         ob = o(0)
  153.         raise error, 'Empty list could be indexed'
  154.     except pythoncom.com_error:
  155.         (hr, fn, desc, arg) = None
  156.         if hr != winerror.DISP_E_BADINDEX:
  157.             raise error, 'Expected DISP_E_BADINDEX - got %d (%s)' % (hr, desc)
  158.         hr != winerror.DISP_E_BADINDEX
  159.  
  160.  
  161.  
  162. class TestCase(win32com.test.util.TestCase):
  163.     
  164.     def testEnum(self):
  165.         TestEnum()
  166.  
  167.  
  168. if __name__ == '__main__':
  169.     unittest.main()
  170.  
  171.