Skip to content

Commit 53ffdc3

Browse files
committed
Added a untitest for record pointers as [ in, out ] method parameters.
1 parent 22b28ab commit 53ffdc3

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

com/TestSources/PyCOMTest/PyCOMImpl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,14 @@ HRESULT CPyCOMTest::GetStruct(TestStruct1 *ret)
618618
*ret = r;
619619
return S_OK;
620620
}
621+
622+
HRESULT CPyCOMTest::ModifyStruct(TestStruct1 *prec)
623+
{
624+
prec->int_value = 100;
625+
prec->str_value = SysAllocString(L"Nothing is as constant as change");
626+
return S_OK;
627+
}
628+
621629
HRESULT CPyCOMTest::DoubleString(BSTR in, BSTR *out)
622630
{
623631
*out = SysAllocStringLen(NULL, SysStringLen(in) * 2);

com/TestSources/PyCOMTest/PyCOMImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class CPyCOMTest : public IDispatchImpl<IPyCOMTest, &IID_IPyCOMTest, &LIBID_PyCO
119119
STDMETHOD(None)();
120120
STDMETHOD(def)();
121121

122+
STDMETHOD(ModifyStruct)(TestStruct1 *prec);
123+
122124
// info associated to each session
123125
struct PyCOMTestSessionData {
124126
IStream *pStream; // Stream for marshalling the data to the new thread.

com/TestSources/PyCOMTest/PyCOMTest.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ library PyCOMTestLib
293293
// reserved words etc
294294
HRESULT None();
295295
HRESULT def();
296+
// Test struct byref as [ in, out ] parameter.
297+
HRESULT ModifyStruct([ in, out ] TestStruct1 * prec);
296298
};
297299

298300
// Define a new class to test how Python handles derived interfaces!

com/win32com/test/testPyComTest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ def TestCommon(o, is_generated):
198198
progress("Checking structs")
199199
r = o.GetStruct()
200200
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
201+
# Dynamic does not support struct byref as [ in, out ] parameters
202+
if hasattr(o, "CLSID"):
203+
progress("Checking struct byref as [ in, out ] parameter")
204+
mod_r = o.ModifyStruct(r)
205+
# We expect the input value to stay unchanged
206+
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
207+
# and the return value to reflect the modifications performed on the COM server side
208+
assert mod_r.int_value == 100 and str(mod_r.str_value) == "Nothing is as constant as change"
209+
assert (
210+
mod_r.int_value == 100
211+
and str(mod_r.str_value) == "Nothing is as constant as change"
212+
)
213+
201214
assert o.DoubleString("foo") == "foofoo"
202215

203216
progress("Checking var args")

0 commit comments

Comments
 (0)