From cc9a8c8f246035c5d99c01f684b7b1b87bf43e46 Mon Sep 17 00:00:00 2001 From: Thomas Geppert Date: Fri, 28 Jun 2024 14:54:10 +0200 Subject: [PATCH] Changed the dispatch interface test to use the 'IDispSafearrayParamTest' interface of the C++ COM test server instead of the 'IDictionary' interface of the Microsoft Script Runtime. --- comtypes/test/test_midl_safearray_create.py | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/comtypes/test/test_midl_safearray_create.py b/comtypes/test/test_midl_safearray_create.py index f0d20979..093724b0 100644 --- a/comtypes/test/test_midl_safearray_create.py +++ b/comtypes/test/test_midl_safearray_create.py @@ -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): @@ -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):