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.

test_win32event.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import unittest
  2. import pywintypes
  3. import win32event
  4. class TestWaitableTimer(unittest.TestCase):
  5. def testWaitableFire(self):
  6. h = win32event.CreateWaitableTimer(None, 0, None)
  7. dt = -160 # 160 ns.
  8. win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
  9. rc = win32event.WaitForSingleObject(h, 1000)
  10. self.assertEqual(rc, win32event.WAIT_OBJECT_0)
  11. def testCreateWaitableTimerEx(self):
  12. h = win32event.CreateWaitableTimerEx(
  13. None,
  14. None,
  15. win32event.CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
  16. win32event.TIMER_ALL_ACCESS,
  17. )
  18. dt = -160 # 160 ns.
  19. win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
  20. rc = win32event.WaitForSingleObject(h, 1000)
  21. self.assertEqual(rc, win32event.WAIT_OBJECT_0)
  22. def testWaitableTrigger(self):
  23. h = win32event.CreateWaitableTimer(None, 0, None)
  24. # for the sake of this, pass a long that doesn't fit in an int.
  25. dt = -2000000000
  26. win32event.SetWaitableTimer(h, dt, 0, None, None, 0)
  27. rc = win32event.WaitForSingleObject(h, 10) # 10 ms.
  28. self.assertEqual(rc, win32event.WAIT_TIMEOUT)
  29. def testWaitableError(self):
  30. h = win32event.CreateWaitableTimer(None, 0, None)
  31. h.close()
  32. self.assertRaises(
  33. pywintypes.error, win32event.SetWaitableTimer, h, -42, 0, None, None, 0
  34. )
  35. class TestWaitFunctions(unittest.TestCase):
  36. def testMsgWaitForMultipleObjects(self):
  37. # this function used to segfault when called with an empty list
  38. res = win32event.MsgWaitForMultipleObjects([], 0, 0, 0)
  39. self.assertEqual(res, win32event.WAIT_TIMEOUT)
  40. def testMsgWaitForMultipleObjects2(self):
  41. # test with non-empty list
  42. event = win32event.CreateEvent(None, 0, 0, None)
  43. res = win32event.MsgWaitForMultipleObjects([event], 0, 0, 0)
  44. self.assertEqual(res, win32event.WAIT_TIMEOUT)
  45. def testMsgWaitForMultipleObjectsEx(self):
  46. # this function used to segfault when called with an empty list
  47. res = win32event.MsgWaitForMultipleObjectsEx([], 0, 0, 0)
  48. self.assertEqual(res, win32event.WAIT_TIMEOUT)
  49. def testMsgWaitForMultipleObjectsEx2(self):
  50. # test with non-empty list
  51. event = win32event.CreateEvent(None, 0, 0, None)
  52. res = win32event.MsgWaitForMultipleObjectsEx([event], 0, 0, 0)
  53. self.assertEqual(res, win32event.WAIT_TIMEOUT)
  54. class TestEvent(unittest.TestCase):
  55. def assertSignaled(self, event):
  56. self.assertEqual(
  57. win32event.WaitForSingleObject(event, 0), win32event.WAIT_OBJECT_0
  58. )
  59. def assertNotSignaled(self, event):
  60. self.assertEqual(
  61. win32event.WaitForSingleObject(event, 0), win32event.WAIT_TIMEOUT
  62. )
  63. def testCreateEvent(self):
  64. event = win32event.CreateEvent(None, False, False, None)
  65. self.assertNotSignaled(event)
  66. event = win32event.CreateEvent(None, False, True, None)
  67. self.assertSignaled(event)
  68. self.assertNotSignaled(event)
  69. event = win32event.CreateEvent(None, True, True, None)
  70. self.assertSignaled(event)
  71. self.assertSignaled(event)
  72. def testSetEvent(self):
  73. event = win32event.CreateEvent(None, True, False, None)
  74. self.assertNotSignaled(event)
  75. res = win32event.SetEvent(event)
  76. self.assertEqual(res, None)
  77. self.assertSignaled(event)
  78. event.close()
  79. self.assertRaises(pywintypes.error, win32event.SetEvent, event)
  80. def testResetEvent(self):
  81. event = win32event.CreateEvent(None, True, True, None)
  82. self.assertSignaled(event)
  83. res = win32event.ResetEvent(event)
  84. self.assertEqual(res, None)
  85. self.assertNotSignaled(event)
  86. event.close()
  87. self.assertRaises(pywintypes.error, win32event.ResetEvent, event)
  88. class TestMutex(unittest.TestCase):
  89. def testReleaseMutex(self):
  90. mutex = win32event.CreateMutex(None, True, None)
  91. res = win32event.ReleaseMutex(mutex)
  92. self.assertEqual(res, None)
  93. res = win32event.WaitForSingleObject(mutex, 0)
  94. self.assertEqual(res, win32event.WAIT_OBJECT_0)
  95. mutex.close()
  96. self.assertRaises(pywintypes.error, win32event.ReleaseMutex, mutex)
  97. if __name__ == "__main__":
  98. unittest.main()