test_pycomtest.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # This is part of the Python test suite.
  2. # The object is registered when you first run the test suite.
  3. # (and hopefully unregistered once done ;-)
  4. # Ensure the vtables in the tlb are known.
  5. from win32com import universal
  6. from win32com.server.exception import COMException
  7. from win32com.client import gencache
  8. import winerror
  9. from win32com.client import constants
  10. from win32com.server.util import wrap
  11. import pythoncom
  12. pythoncom.__future_currency__ = True
  13. # We use the constants from the module, so must insist on a gencache.
  14. # Otherwise, use of gencache is not necessary (tho still advised)
  15. gencache.EnsureModule('{6BCDCB60-5605-11D0-AE5F-CADD4C000000}', 0, 1, 1)
  16. class PyCOMTest:
  17. _typelib_guid_ = "{6BCDCB60-5605-11D0-AE5F-CADD4C000000}"
  18. _typelib_version = 1,0
  19. _com_interfaces_ = ['IPyCOMTest']
  20. _reg_clsid_ = "{e743d9cd-cb03-4b04-b516-11d3a81c1597}"
  21. _reg_progid_ = "Python.Test.PyCOMTest"
  22. def DoubleString(self, str):
  23. return str*2
  24. def DoubleInOutString(self, str):
  25. return str*2
  26. def Fire(self, nID):
  27. raise COMException(hresult=winerror.E_NOTIMPL)
  28. def GetLastVarArgs(self):
  29. raise COMException(hresult=winerror.E_NOTIMPL)
  30. def GetMultipleInterfaces(self, outinterface1, outinterface2):
  31. raise COMException(hresult=winerror.E_NOTIMPL)
  32. def GetSafeArrays(self, attrs, attrs2, ints):
  33. raise COMException(hresult=winerror.E_NOTIMPL)
  34. def GetSetDispatch(self, indisp):
  35. raise COMException(hresult=winerror.E_NOTIMPL)
  36. # Result is of type IPyCOMTest
  37. def GetSetInterface(self, ininterface):
  38. return wrap(self)
  39. def GetSetVariant(self, indisp):
  40. return indisp
  41. def TestByRefVariant(self, v):
  42. return v * 2
  43. def TestByRefString(self, v):
  44. return v * 2
  45. # Result is of type IPyCOMTest
  46. def GetSetInterfaceArray(self, ininterface):
  47. raise COMException(hresult=winerror.E_NOTIMPL)
  48. def GetSetUnknown(self, inunk):
  49. raise COMException(hresult=winerror.E_NOTIMPL)
  50. # Result is of type ISimpleCounter
  51. def GetSimpleCounter(self):
  52. raise COMException(hresult=winerror.E_NOTIMPL)
  53. def GetSimpleSafeArray(self, ints):
  54. raise COMException(hresult=winerror.E_NOTIMPL)
  55. def GetStruct(self):
  56. raise COMException(hresult=winerror.E_NOTIMPL)
  57. def SetIntSafeArray(self, ints):
  58. return len(ints)
  59. def SetLongLongSafeArray(self, ints):
  60. return len(ints)
  61. def SetULongLongSafeArray(self, ints):
  62. return len(ints)
  63. def SetBinSafeArray(self, buf):
  64. return len(buf)
  65. def SetVarArgs(self, *args):
  66. raise COMException(hresult=winerror.E_NOTIMPL)
  67. def SetVariantSafeArray(self, vars):
  68. raise COMException(hresult=winerror.E_NOTIMPL)
  69. def Start(self):
  70. raise COMException(hresult=winerror.E_NOTIMPL)
  71. def Stop(self, nID):
  72. raise COMException(hresult=winerror.E_NOTIMPL)
  73. def StopAll(self):
  74. raise COMException(hresult=winerror.E_NOTIMPL)
  75. def TakeByRefDispatch(self, inout):
  76. raise COMException(hresult=winerror.E_NOTIMPL)
  77. def TakeByRefTypedDispatch(self, inout):
  78. raise COMException(hresult=winerror.E_NOTIMPL)
  79. def Test(self, key, inval):
  80. return not inval
  81. def Test2(self, inval):
  82. return inval
  83. def Test3(self, inval):
  84. raise COMException(hresult=winerror.E_NOTIMPL)
  85. def Test4(self, inval):
  86. raise COMException(hresult=winerror.E_NOTIMPL)
  87. def Test5(self, inout):
  88. if inout == constants.TestAttr1:
  89. return constants.TestAttr1_1
  90. elif inout == constants.TestAttr1_1:
  91. return constants.TestAttr1
  92. else:
  93. return -1
  94. def Test6(self, inval):
  95. return inval
  96. def TestInOut(self, fval, bval, lval):
  97. return winerror.S_OK, fval * 2, not bval, lval * 2
  98. def TestOptionals(self, strArg='def', sval=0, lval=1, dval=3.1400001049041748):
  99. raise COMException(hresult=winerror.E_NOTIMPL)
  100. def TestOptionals2(self, dval, strval='', sval=1):
  101. raise COMException(hresult=winerror.E_NOTIMPL)
  102. def CheckVariantSafeArray(self, data):
  103. return 1
  104. def LongProp(self):
  105. return self.longval
  106. def SetLongProp(self, val):
  107. self.longval = val
  108. def ULongProp(self):
  109. return self.ulongval
  110. def SetULongProp(self, val):
  111. self.ulongval = val
  112. def IntProp(self):
  113. return self.intval
  114. def SetIntProp(self, val):
  115. self.intval = val
  116. class PyCOMTestMI(PyCOMTest):
  117. _typelib_guid_ = "{6BCDCB60-5605-11D0-AE5F-CADD4C000000}"
  118. _typelib_version = 1,0
  119. # Interfaces with a interface name, a real IID, and an IID as a string
  120. _com_interfaces_ = ['IPyCOMTest',
  121. pythoncom.IID_IStream,
  122. str(pythoncom.IID_IStorage),
  123. ]
  124. _reg_clsid_ = "{F506E9A1-FB46-4238-A597-FA4EB69787CA}"
  125. _reg_progid_ = "Python.Test.PyCOMTestMI"
  126. if __name__ == '__main__':
  127. import win32com.server.register
  128. win32com.server.register.UseCommandLine(PyCOMTest)
  129. win32com.server.register.UseCommandLine(PyCOMTestMI)