forked from enthought/comtypes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
test_comobject
(part 1). (enthought#709)
* Add `test_comobject.py` and first test cases. * Add `TYPE_CHECKING` only `GetTypeInfoCount` to `IDispatch`.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import unittest as ut | ||
|
||
import comtypes | ||
import comtypes.client | ||
from comtypes import IUnknown | ||
|
||
comtypes.client.GetModule("UIAutomationCore.dll") | ||
comtypes.client.GetModule("scrrun.dll") | ||
from comtypes.gen import Scripting as scrrun | ||
from comtypes.gen import UIAutomationClient as uiac | ||
|
||
|
||
class Test_QueryInterface(ut.TestCase): | ||
def test_custom_interface(self): | ||
iuia = uiac.CUIAutomation().QueryInterface(uiac.IUIAutomation) | ||
self.assertTrue(bool(iuia)) | ||
self.assertEqual(iuia.AddRef(), 2) | ||
punk = iuia.QueryInterface(IUnknown) | ||
self.assertEqual(iuia.AddRef(), 4) | ||
self.assertEqual(punk.AddRef(), 5) | ||
self.assertEqual(iuia.Release(), 4) | ||
del iuia | ||
self.assertEqual(punk.Release(), 2) | ||
self.assertEqual(punk.Release(), 1) | ||
|
||
def test_dispatch_interface(self): | ||
dic = scrrun.Dictionary().QueryInterface(scrrun.IDictionary) | ||
self.assertTrue(bool(dic)) | ||
self.assertEqual(dic.GetTypeInfoCount(), 1) | ||
self.assertEqual( | ||
dic.GetTypeInfo(0).GetTypeAttr().guid, | ||
scrrun.IDictionary._iid_, | ||
) | ||
self.assertEqual(dic.GetIDsOfNames("Add"), [1]) | ||
|
||
|
||
class Test_IPersist_GetClassID(ut.TestCase): | ||
def test(self): | ||
self.assertEqual( | ||
uiac.CUIAutomation().IPersist_GetClassID(), | ||
uiac.CUIAutomation._reg_clsid_, | ||
) |