|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
-
- import array
- import operator
- import unittest
-
- import pywin32_testutil
- import win32gui
-
-
- class TestPyGetString(unittest.TestCase):
- def test_get_string(self):
-
- self.assertRaises(ValueError, win32gui.PyGetString, 0)
- self.assertRaises(ValueError, win32gui.PyGetString, 1)
- self.assertRaises(ValueError, win32gui.PyGetString, 1, 1)
-
-
- class TestPyGetMemory(unittest.TestCase):
- def test_ob(self):
-
- test_data = b"\0\1\2\3\4\5\6"
- c = array.array("b", test_data)
- addr, buflen = c.buffer_info()
- got = win32gui.PyGetMemory(addr, buflen)
- self.assertEqual(len(got), len(test_data))
- self.assertEqual(bytes(got), test_data)
-
- def test_memory_index(self):
-
- test_data = b"\0\1\2\3\4\5\6"
- c = array.array("b", test_data)
- addr, buflen = c.buffer_info()
- got = win32gui.PyGetMemory(addr, buflen)
- self.assertEqual(got[0], 0)
-
- def test_memory_slice(self):
-
- test_data = b"\0\1\2\3\4\5\6"
- c = array.array("b", test_data)
- addr, buflen = c.buffer_info()
- got = win32gui.PyGetMemory(addr, buflen)
- self.assertEqual(list(got[0:3]), [0, 1, 2])
-
- def test_real_view(self):
-
-
- test_data = b"\0\1\2\3\4\5\6"
- c = array.array("b", test_data)
- addr, buflen = c.buffer_info()
- got = win32gui.PyGetMemory(addr, buflen)
- self.assertEqual(got[0], 0)
- c[0] = 1
- self.assertEqual(got[0], 1)
-
- def test_memory_not_writable(self):
-
- test_data = b"\0\1\2\3\4\5\6"
- c = array.array("b", test_data)
- addr, buflen = c.buffer_info()
- got = win32gui.PyGetMemory(addr, buflen)
- self.assertRaises(TypeError, operator.setitem, got, 0, 1)
-
-
- if __name__ == "__main__":
- unittest.main()
|