def DllRegisterServer(): # Enumerate each module implementing an object from comtypes.server.register import register for mod in com_modules: # register each class for cls in get_classes(mod): register(cls)
import unittest, sys from ctypes import * from ctypes.wintypes import * from comtypes.client import CreateObject, GetEvents, ShowEvents from comtypes.server.register import register #, unregister from comtypes.test import is_resource_enabled from comtypes.test.find_memleak import find_memleak ################################################################ import comtypes.test.TestComServer register(comtypes.test.TestComServer.TestComServer) class TestInproc(unittest.TestCase): def create_object(self): return CreateObject("TestComServerLib.TestComServer", clsctx=comtypes.CLSCTX_INPROC_SERVER) def _find_memleak(self, func): bytes = find_memleak(func) self.failIf(bytes, "Leaks %d bytes" % bytes) def test_mixedinout(self): o = self.create_object() self.failUnlessEqual(o.MixedInOut(2, 4), (3, 5)) def test_getname(self): from ctypes import byref, pointer from comtypes import BSTR # This tests a tricky bug, introduced with this patch:
import unittest from comtypes.server.register import register#, unregister from comtypes.test import is_resource_enabled ################################################################ import comtypes.test.TestDispServer register(comtypes.test.TestDispServer.TestDispServer) class Test(unittest.TestCase): if is_resource_enabled("pythoncom"): def test_win32com(self): # EnsureDispatch is case-sensitive from win32com.client.gencache import EnsureDispatch d = EnsureDispatch("TestDispServerLib.TestDispServer") self.assertEqual(d.eval("3.14"), 3.14) self.assertEqual(d.eval("1 + 2"), 3) self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, 'foo', None)) self.assertEqual(d.eval2("3.14"), 3.14) self.assertEqual(d.eval2("1 + 2"), 3) self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, 'foo', None)) d.eval("__import__('comtypes.client').client.CreateObject('MSScriptControl.ScriptControl')") server_id = d.eval("id(self)") self.assertEqual(d.id, server_id) self.assertEqual(d.name, "spam, spam, spam")
import unittest, sys from ctypes import * from ctypes.wintypes import * from comtypes.client import CreateObject, GetEvents, ShowEvents from comtypes.server.register import register#, unregister from comtypes.test import is_resource_enabled from comtypes.test.find_memleak import find_memleak ################################################################ import comtypes.test.TestComServer register(comtypes.test.TestComServer.TestComServer) class TestInproc(unittest.TestCase): def create_object(self): return CreateObject("TestComServerLib.TestComServer", clsctx = comtypes.CLSCTX_INPROC_SERVER) def _find_memleak(self, func): bytes = find_memleak(func) self.failIf(bytes, "Leaks %d bytes" % bytes) def test_mixedinout(self): o = self.create_object() self.failUnlessEqual(o.MixedInOut(2, 4), (3, 5)) def test_getname(self): from ctypes import byref, pointer from comtypes import BSTR # This tests a tricky bug, introduced with this patch:
import unittest from comtypes.server.register import register #, unregister from comtypes.test import is_resource_enabled ################################################################ import comtypes.test.TestDispServer register(comtypes.test.TestDispServer.TestDispServer) class Test(unittest.TestCase): if is_resource_enabled("pythoncom"): def test_win32com(self): # EnsureDispatch is case-sensitive from win32com.client.gencache import EnsureDispatch d = EnsureDispatch("TestDispServerLib.TestDispServer") self.assertEqual(d.eval("3.14"), 3.14) self.assertEqual(d.eval("1 + 2"), 3) self.assertEqual(d.eval("[1 + 2, 'foo', None]"), (3, 'foo', None)) self.assertEqual(d.eval2("3.14"), 3.14) self.assertEqual(d.eval2("1 + 2"), 3) self.assertEqual(d.eval2("[1 + 2, 'foo', None]"), (3, 'foo', None)) d.eval( "__import__('comtypes.client').client.CreateObject('Scripting.Dictionary')" )