PyXR

c:\python24\lib\site-packages\win32 \ com \ test \ testStorage.py



0001 from win32com import storagecon
0002 import pythoncom, os, win32api
0003 import win32com.test.util
0004 
0005 import unittest
0006 
0007 class TestEnum(win32com.test.util.TestCase):
0008     def testit(self):
0009         fname, tmp = win32api.GetTempFileName(win32api.GetTempPath(),'stg')
0010         m=storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE
0011         ##  file, mode, format, attrs (always 0), IID (IStorage or IPropertySetStorage, storage options(only used with STGFMT_DOCFILE)
0012         pss=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0 , pythoncom.IID_IPropertySetStorage)
0013         ###                               {"Version":2,"reserved":0,"SectorSize":512,"TemplateFile":u'somefilename'})
0014         
0015         ## FMTID_SummaryInformation FMTID_DocSummaryInformation FMTID_UserDefinedProperties 
0016         psuser=pss.Create(pythoncom.FMTID_UserDefinedProperties,
0017                       pythoncom.IID_IPropertySetStorage,
0018                       storagecon.PROPSETFLAG_DEFAULT,
0019                       storagecon.STGM_READWRITE|storagecon.STGM_CREATE|storagecon.STGM_SHARE_EXCLUSIVE) ## its very picky about flag combinations!
0020         psuser.WriteMultiple((3,4),('hey','bubba'))
0021         psuser.WritePropertyNames((3,4),('property3','property4'))
0022         expected_summaries = []
0023         expected_summaries.append( ('property3', 3, pythoncom.VT_BSTR))
0024         expected_summaries.append( ('property4', 4, pythoncom.VT_BSTR))
0025         psuser=None
0026         
0027         pssum=pss.Create(pythoncom.FMTID_SummaryInformation,
0028                       pythoncom.IID_IPropertySetStorage,
0029                       storagecon.PROPSETFLAG_DEFAULT,
0030                       storagecon.STGM_READWRITE|storagecon.STGM_CREATE|storagecon.STGM_SHARE_EXCLUSIVE)
0031         pssum.WriteMultiple((storagecon.PIDSI_AUTHOR,storagecon.PIDSI_COMMENTS),('me', 'comment'))
0032         
0033         pssum=None
0034         pss=None    ## doesn't seem to be a close or release method, and you can't even reopen it from the same process until previous object is gone 
0035         
0036         pssread=pythoncom.StgOpenStorageEx(fname, storagecon.STGM_READ|storagecon.STGM_SHARE_EXCLUSIVE, storagecon.STGFMT_FILE, 0 , pythoncom.IID_IPropertySetStorage)
0037         found_summaries = []
0038         for psstat in pssread:
0039             ps=pssread.Open(psstat[0],storagecon.STGM_READ|storagecon.STGM_SHARE_EXCLUSIVE)
0040             for p in ps:
0041                 p_val = ps.ReadMultiple((p[1],))[0]
0042                 if (p[1]==storagecon.PIDSI_AUTHOR and p_val=='me') or \
0043                    (p[1]==storagecon.PIDSI_COMMENTS and p_val=='comment'):
0044                     pass
0045                 else:
0046                     self.fail("Uxexpected property %s/%s" % (p, p_val))
0047             ps=None
0048             ## FMTID_UserDefinedProperties can't exist without FMTID_DocSummaryInformation, and isn't returned independently from Enum
0049             ## also can't be open at same time
0050             if psstat[0]==pythoncom.FMTID_DocSummaryInformation:
0051                 ps=pssread.Open(pythoncom.FMTID_UserDefinedProperties,storagecon.STGM_READ|storagecon.STGM_SHARE_EXCLUSIVE)
0052                 for p in ps:
0053                     found_summaries.append(p)
0054                 ps=None
0055         psread=None
0056         expected_summaries.sort()
0057         found_summaries.sort()
0058         self.assertEqual(expected_summaries, found_summaries)
0059 
0060 if __name__=='__main__':
0061     unittest.main()
0062 

Generated by PyXR 0.9.4
SourceForge.net Logo