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_win32gui.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # tests for win32gui
  2. import array
  3. import operator
  4. import unittest
  5. import pywin32_testutil
  6. import win32gui
  7. class TestPyGetString(unittest.TestCase):
  8. def test_get_string(self):
  9. # test invalid addresses cause a ValueError rather than crash!
  10. self.assertRaises(ValueError, win32gui.PyGetString, 0)
  11. self.assertRaises(ValueError, win32gui.PyGetString, 1)
  12. self.assertRaises(ValueError, win32gui.PyGetString, 1, 1)
  13. class TestPyGetMemory(unittest.TestCase):
  14. def test_ob(self):
  15. # Check the PyGetMemory result and a bytes string can be compared
  16. test_data = b"\0\1\2\3\4\5\6"
  17. c = array.array("b", test_data)
  18. addr, buflen = c.buffer_info()
  19. got = win32gui.PyGetMemory(addr, buflen)
  20. self.assertEqual(len(got), len(test_data))
  21. self.assertEqual(bytes(got), test_data)
  22. def test_memory_index(self):
  23. # Check we can index into the buffer object returned by PyGetMemory
  24. test_data = b"\0\1\2\3\4\5\6"
  25. c = array.array("b", test_data)
  26. addr, buflen = c.buffer_info()
  27. got = win32gui.PyGetMemory(addr, buflen)
  28. self.assertEqual(got[0], 0)
  29. def test_memory_slice(self):
  30. # Check we can slice the buffer object returned by PyGetMemory
  31. test_data = b"\0\1\2\3\4\5\6"
  32. c = array.array("b", test_data)
  33. addr, buflen = c.buffer_info()
  34. got = win32gui.PyGetMemory(addr, buflen)
  35. self.assertEqual(list(got[0:3]), [0, 1, 2])
  36. def test_real_view(self):
  37. # Do the PyGetMemory, then change the original memory, then ensure
  38. # the initial object we fetched sees the new value.
  39. test_data = b"\0\1\2\3\4\5\6"
  40. c = array.array("b", test_data)
  41. addr, buflen = c.buffer_info()
  42. got = win32gui.PyGetMemory(addr, buflen)
  43. self.assertEqual(got[0], 0)
  44. c[0] = 1
  45. self.assertEqual(got[0], 1)
  46. def test_memory_not_writable(self):
  47. # Check the buffer object fetched by PyGetMemory isn't writable.
  48. test_data = b"\0\1\2\3\4\5\6"
  49. c = array.array("b", test_data)
  50. addr, buflen = c.buffer_info()
  51. got = win32gui.PyGetMemory(addr, buflen)
  52. self.assertRaises(TypeError, operator.setitem, got, 0, 1)
  53. if __name__ == "__main__":
  54. unittest.main()