Skip to content

Commit d9c4b48

Browse files
committed
fix: Eliminate the testcase.
1 parent a3cea96 commit d9c4b48

File tree

1 file changed

+0
-31
lines changed

1 file changed

+0
-31
lines changed

comtypes/malloc.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import unittest
32
from ctypes import (
43
HRESULT,
54
POINTER,
@@ -18,7 +17,6 @@
1817
wstring_at,
1918
)
2019
from ctypes.wintypes import DWORD, LPVOID
21-
from unittest.mock import patch
2220

2321
from comtypes import COMMETHOD, GUID, IUnknown
2422
from comtypes.GUID import _CoTaskMemFree
@@ -77,32 +75,3 @@ def comstring(text, typ=c_wchar_p):
7775
ptr = cast(mem, typ)
7876
memmove(mem, text, size)
7977
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

Comments
 (0)