Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testStorage.py 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import unittest
  2. import pythoncom
  3. import win32api
  4. import win32com.test.util
  5. from win32com import storagecon
  6. class TestEnum(win32com.test.util.TestCase):
  7. def testit(self):
  8. fname, tmp = win32api.GetTempFileName(win32api.GetTempPath(), "stg")
  9. m = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE
  10. ## file, mode, format, attrs (always 0), IID (IStorage or IPropertySetStorage, storage options(only used with STGFMT_DOCFILE)
  11. pss = pythoncom.StgOpenStorageEx(
  12. fname, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage
  13. )
  14. ### {"Version":2,"reserved":0,"SectorSize":512,"TemplateFile":u'somefilename'})
  15. ## FMTID_SummaryInformation FMTID_DocSummaryInformation FMTID_UserDefinedProperties
  16. psuser = pss.Create(
  17. pythoncom.FMTID_UserDefinedProperties,
  18. pythoncom.IID_IPropertySetStorage,
  19. storagecon.PROPSETFLAG_DEFAULT,
  20. storagecon.STGM_READWRITE
  21. | storagecon.STGM_CREATE
  22. | storagecon.STGM_SHARE_EXCLUSIVE,
  23. ) ## its very picky about flag combinations!
  24. psuser.WriteMultiple((3, 4), ("hey", "bubba"))
  25. psuser.WritePropertyNames((3, 4), ("property3", "property4"))
  26. expected_summaries = []
  27. expected_summaries.append(("property3", 3, pythoncom.VT_BSTR))
  28. expected_summaries.append(("property4", 4, pythoncom.VT_BSTR))
  29. psuser = None
  30. pssum = pss.Create(
  31. pythoncom.FMTID_SummaryInformation,
  32. pythoncom.IID_IPropertySetStorage,
  33. storagecon.PROPSETFLAG_DEFAULT,
  34. storagecon.STGM_READWRITE
  35. | storagecon.STGM_CREATE
  36. | storagecon.STGM_SHARE_EXCLUSIVE,
  37. )
  38. pssum.WriteMultiple(
  39. (storagecon.PIDSI_AUTHOR, storagecon.PIDSI_COMMENTS), ("me", "comment")
  40. )
  41. pssum = None
  42. 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
  43. pssread = pythoncom.StgOpenStorageEx(
  44. fname,
  45. storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE,
  46. storagecon.STGFMT_FILE,
  47. 0,
  48. pythoncom.IID_IPropertySetStorage,
  49. )
  50. found_summaries = []
  51. for psstat in pssread:
  52. ps = pssread.Open(
  53. psstat[0], storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE
  54. )
  55. for p in ps:
  56. p_val = ps.ReadMultiple((p[1],))[0]
  57. if (p[1] == storagecon.PIDSI_AUTHOR and p_val == "me") or (
  58. p[1] == storagecon.PIDSI_COMMENTS and p_val == "comment"
  59. ):
  60. pass
  61. else:
  62. self.fail("Uxexpected property %s/%s" % (p, p_val))
  63. ps = None
  64. ## FMTID_UserDefinedProperties can't exist without FMTID_DocSummaryInformation, and isn't returned independently from Enum
  65. ## also can't be open at same time
  66. if psstat[0] == pythoncom.FMTID_DocSummaryInformation:
  67. ps = pssread.Open(
  68. pythoncom.FMTID_UserDefinedProperties,
  69. storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE,
  70. )
  71. for p in ps:
  72. found_summaries.append(p)
  73. ps = None
  74. psread = None
  75. expected_summaries.sort()
  76. found_summaries.sort()
  77. self.assertEqual(expected_summaries, found_summaries)
  78. if __name__ == "__main__":
  79. unittest.main()