Skip to content

Commit

Permalink
Added a untitest for record pointers as [ in, out ] method parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
geppi committed Jul 31, 2024
1 parent 22b28ab commit 53ffdc3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@ HRESULT CPyCOMTest::GetStruct(TestStruct1 *ret)
*ret = r;
return S_OK;
}

HRESULT CPyCOMTest::ModifyStruct(TestStruct1 *prec)
{
prec->int_value = 100;
prec->str_value = SysAllocString(L"Nothing is as constant as change");
return S_OK;
}

HRESULT CPyCOMTest::DoubleString(BSTR in, BSTR *out)
{
*out = SysAllocStringLen(NULL, SysStringLen(in) * 2);
Expand Down
2 changes: 2 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class CPyCOMTest : public IDispatchImpl<IPyCOMTest, &IID_IPyCOMTest, &LIBID_PyCO
STDMETHOD(None)();
STDMETHOD(def)();

STDMETHOD(ModifyStruct)(TestStruct1 *prec);

// info associated to each session
struct PyCOMTestSessionData {
IStream *pStream; // Stream for marshalling the data to the new thread.
Expand Down
2 changes: 2 additions & 0 deletions com/TestSources/PyCOMTest/PyCOMTest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ library PyCOMTestLib
// reserved words etc
HRESULT None();
HRESULT def();
// Test struct byref as [ in, out ] parameter.
HRESULT ModifyStruct([ in, out ] TestStruct1 * prec);
};

// Define a new class to test how Python handles derived interfaces!
Expand Down
13 changes: 13 additions & 0 deletions com/win32com/test/testPyComTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ def TestCommon(o, is_generated):
progress("Checking structs")
r = o.GetStruct()
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
# Dynamic does not support struct byref as [ in, out ] parameters
if hasattr(o, "CLSID"):
progress("Checking struct byref as [ in, out ] parameter")
mod_r = o.ModifyStruct(r)
# We expect the input value to stay unchanged
assert r.int_value == 99 and str(r.str_value) == "Hello from C++"
# and the return value to reflect the modifications performed on the COM server side
assert mod_r.int_value == 100 and str(mod_r.str_value) == "Nothing is as constant as change"
assert (
mod_r.int_value == 100
and str(mod_r.str_value) == "Nothing is as constant as change"
)

assert o.DoubleString("foo") == "foofoo"

progress("Checking var args")
Expand Down

0 comments on commit 53ffdc3

Please sign in to comment.