Skip to content

Commit

Permalink
Changed the dispatch interface test to use the 'IDispSafearrayParamTest'
Browse files Browse the repository at this point in the history
interface of the C++ COM test server instead of the 'IDictionary' interface
of the Microsoft Script Runtime.
  • Loading branch information
geppi committed Jun 28, 2024
1 parent 9e2db22 commit cc9a8c8
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions comtypes/test/test_midl_safearray_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@

import comtypes
import comtypes.safearray
from comtypes import CLSCTX_INPROC_SERVER
from comtypes import CLSCTX_INPROC_SERVER, CLSCTX_LOCAL_SERVER
from comtypes.client import CreateObject, GetModule
import comtypes.typeinfo

GetModule("UIAutomationCore.dll")
from comtypes.gen.UIAutomationClient import CUIAutomation, IUIAutomation

GetModule("scrrun.dll")
from comtypes.gen.Scripting import Dictionary, IDictionary

ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}"

try:
GetModule((ComtypesCppTestSrvLib_GUID, 1, 0, 0))
from comtypes.gen.ComtypesCppTestSrvLib import StructRecordParamTest
from comtypes.gen.ComtypesCppTestSrvLib import IDispSafearrayParamTest

IMPORT_FAILED = False
except (ImportError, OSError):
Expand All @@ -43,19 +41,22 @@ def test_iunk(self):
(unpacked,) = sa.unpack()
self.assertIsInstance(unpacked, POINTER(IUIAutomation))

@unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.")
def test_idisp(self):
extra = pointer(IDictionary._iid_)
idic = CreateObject(Dictionary, interface=IDictionary)
idic["foo"] = "bar"
sa_type = comtypes.safearray._midlSAFEARRAY(POINTER(IDictionary))
extra = pointer(IDispSafearrayParamTest._iid_)
idisp = CreateObject(
"Comtypes.DispSafearrayParamTest",
clsctx=CLSCTX_LOCAL_SERVER,
interface=IDispSafearrayParamTest,
)
sa_type = comtypes.safearray._midlSAFEARRAY(POINTER(IDispSafearrayParamTest))
for ptn, sa in [
("with extra", sa_type.create([idic], extra=extra)),
("without extra", sa_type.create([idic])),
("with extra", sa_type.create([idisp], extra=extra)),
("without extra", sa_type.create([idisp])),
]:
with self.subTest(ptn=ptn):
(unpacked,) = sa.unpack()
self.assertIsInstance(unpacked, POINTER(IDictionary))
self.assertEqual(unpacked["foo"], "bar")
self.assertIsInstance(unpacked, POINTER(IDispSafearrayParamTest))

@unittest.skipIf(IMPORT_FAILED, "This depends on the out of process COM-server.")
def test_record(self):
Expand Down

0 comments on commit cc9a8c8

Please sign in to comment.