Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test\test_basic.py] Use OleDLL instead of windll #764

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions comtypes/test/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
##import ut
import unittest as ut
from ctypes import windll, POINTER, byref, HRESULT
from ctypes import POINTER, byref, HRESULT
from comtypes import IUnknown, STDMETHOD, GUID
from comtypes.typeinfo import _CreateTypeLib2, ICreateTypeLib2

# XXX leaks references!

Expand All @@ -20,17 +21,21 @@ def test_release(self):
POINTER(IUnknown)()

def test_refcounts(self):
p = POINTER(IUnknown)()
windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
# Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the previous code demonstrates, QueryInterface and refcount tests can be performed with this package’s IUnknown.

To better reflect the accurate situation, I think a comments like “COM interfaces can use AddRef, Release, and QueryInterface inherited from IUnknown” would be more appropriate.

# Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown.
p = POINTER(ICreateTypeLib2)()
_CreateTypeLib2(1, "blabla", byref(p))
# initial refcount is 2
for i in range(2, 10):
self.assertEqual(p.AddRef(), i)
for i in range(8, 0, -1):
self.assertEqual(p.Release(), i)

def test_qi(self):
p = POINTER(IUnknown)()
windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
# Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly.
# Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown.
p = POINTER(ICreateTypeLib2)()
_CreateTypeLib2(1, "blabla", byref(p))
self.assertEqual(p.AddRef(), 2)
self.assertEqual(p.Release(), 1)

Expand Down