Update of /cvsroot/pywin32/pywin32/com/win32com/demos
In directory sc8-pr-cvs1:/tmp/cvs-serv23586
Modified Files:
connect.py
Log Message:
Add some checks rather than relying on 'eyeballing' the results. Add
unicode tests.
Index: connect.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/demos/connect.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** connect.py 1 Sep 1999 22:59:21 -0000 1.1
--- connect.py 9 Nov 2003 11:01:18 -0000 1.2
***************
*** 39,42 ****
--- 39,44 ----
# Normally some explicit DISPID->Method mapping is required.
_public_methods_ = ["OnDoneIt"]
+ def __init__(self):
+ self.last_event_arg = None
# A client must implement QI, and respond to a query for the Event interface.
# In addition, it must provide a COM object (which server.util.wrap) does.
***************
*** 48,67 ****
# And here is our event method which gets called.
def OnDoneIt(self, arg):
! print "OnDoneIt with ", repr(arg)
# A simple test script for all this.
# In the real world, it is likely that the code controlling the server
# will be in the same class as that getting the notifications.
! def test():
import win32com.client.dynamic, win32com.client.connect
import win32com.server.policy
server = win32com.client.dynamic.Dispatch(win32com.server.util.wrap(ConnectableServer()))
connection = win32com.client.connect.SimpleConnection()
! connection.Connect(server, ConnectableClient(),IID_IConnectDemoEvents)
! server.DoIt("Hello")
! server.DoIt("Here is a null>"+chr(0)+"<")
# Aggressive memory leak checking (ie, do nothing!) :-) All should cleanup OK???
if __name__=='__main__':
! test()
!
--- 50,82 ----
# And here is our event method which gets called.
def OnDoneIt(self, arg):
! self.last_event_arg = arg
!
! def CheckEvent(server, client, val, verbose):
! client.last_event_arg = None
! server.DoIt(val)
! if client.last_event_arg != val:
! raise RuntimeError, "Sent %r, but got back %r" % (val, client.last_event_arg)
! if verbose:
! print "Sent and received %r" % val
# A simple test script for all this.
# In the real world, it is likely that the code controlling the server
# will be in the same class as that getting the notifications.
! def test(verbose=0):
import win32com.client.dynamic, win32com.client.connect
import win32com.server.policy
server = win32com.client.dynamic.Dispatch(win32com.server.util.wrap(ConnectableServer()))
connection = win32com.client.connect.SimpleConnection()
! client = ConnectableClient()
! connection.Connect(server, client, IID_IConnectDemoEvents)
! CheckEvent(server, client, "Hello", verbose)
! CheckEvent(server, client, "Here is a null>"+chr(0)+"<", verbose)
! CheckEvent(server, client, u"Here is a null>"+unichr(0)+"<", verbose)
! val = unicode("test-\xe0\xf2", "latin-1") # 2 latin characters.
! CheckEvent(server, client, val, verbose)
! if verbose:
! print "Everything seemed to work!"
# Aggressive memory leak checking (ie, do nothing!) :-) All should cleanup OK???
if __name__=='__main__':
! test(1)
|