|
1 | 1 | import logging |
2 | | -import unittest |
3 | 2 | from ctypes import ( |
4 | 3 | HRESULT, |
5 | 4 | POINTER, |
|
18 | 17 | wstring_at, |
19 | 18 | ) |
20 | 19 | from ctypes.wintypes import DWORD, LPVOID |
21 | | -from unittest.mock import patch |
22 | 20 |
|
23 | 21 | from comtypes import COMMETHOD, GUID, IUnknown |
24 | 22 | from comtypes.GUID import _CoTaskMemFree |
@@ -77,32 +75,3 @@ def comstring(text, typ=c_wchar_p): |
77 | 75 | ptr = cast(mem, typ) |
78 | 76 | memmove(mem, text, size) |
79 | 77 | return ptr |
80 | | - |
81 | | - |
82 | | -class Test(unittest.TestCase): |
83 | | - @patch.object(c_wchar_p, "__ctypes_from_outparam__", from_outparam) |
84 | | - def test_c_char(self): |
85 | | - ptr = c_wchar_p("abc") |
86 | | - # The normal constructor does not allocate memory using `CoTaskMemAlloc`. |
87 | | - # Therefore, calling the patched `ptr.__ctypes_from_outparam__()` would |
88 | | - # attempt to free invalid memory, potentially leading to a crash. |
89 | | - self.assertEqual(malloc.DidAlloc(ptr), 0) |
90 | | - |
91 | | - x = comstring("Hello, World") |
92 | | - y = comstring("foo bar") |
93 | | - z = comstring("spam, spam, and spam") |
94 | | - |
95 | | - # The `__ctypes_from_outparam__` method is called to convert an output |
96 | | - # parameter into a Python object. In this test, the custom |
97 | | - # `from_outparam` function not only converts the `c_wchar_p` to a |
98 | | - # Python string but also frees the associated memory. Therefore, it can |
99 | | - # only be called once for each allocated memory block. |
100 | | - for wchar_ptr, expected in [ |
101 | | - (x, "Hello, World"), |
102 | | - (y, "foo bar"), |
103 | | - (z, "spam, spam, and spam"), |
104 | | - ]: |
105 | | - with self.subTest(wchar_ptr=wchar_ptr, expected=expected): |
106 | | - self.assertEqual(malloc.DidAlloc(wchar_ptr), 1) |
107 | | - self.assertEqual(wchar_ptr.__ctypes_from_outparam__(), expected) |
108 | | - self.assertEqual(malloc.DidAlloc(wchar_ptr), 0) |
0 commit comments