Skip to content

Commit 649de8a

Browse files
committed
Add a test for signature collision
1 parent 0df375b commit 649de8a

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

src/tests/Interop/COM/NETClients/IDispatch/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ static void Validate_ValueCoerce_ReturnToManaged()
346346
Assert.Equal("True", dispatchCoerceTesting.BoolToString());
347347
}
348348

349+
static void Validate_GetDispId_Methods()
350+
{
351+
var dispatchTesting = new DispatchTesting();
352+
353+
Console.WriteLine($"Calling {nameof(DispatchTesting.GetDispIdAsString)} ...");
354+
string result1 = dispatchTesting.GetDispIdAsString();
355+
Assert.Equal("1000", result1);
356+
357+
Console.WriteLine($"Calling {nameof(DispatchTesting.GetDispIdAsString2)} ...");
358+
string result2 = dispatchTesting.GetDispIdAsString2();
359+
Assert.Equal("1001", result2);
360+
}
361+
349362
[Fact]
350363
public static int TestEntryPoint()
351364
{
@@ -365,6 +378,7 @@ public static int TestEntryPoint()
365378
Validate_LCID_Marshaled();
366379
Validate_Enumerator();
367380
Validate_ValueCoerce_ReturnToManaged();
381+
Validate_GetDispId_Methods();
368382
}
369383
catch (Exception e)
370384
{

src/tests/Interop/COM/NETServer/DispatchTesting.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,16 @@ public object TriggerCustomMarshaler(object objIn, ref object objRef)
102102
objRef = objIn;
103103
return ret;
104104
}
105+
106+
[DispId(1000)]
107+
public string GetDispIdAsString()
108+
{
109+
return "1000";
110+
}
111+
112+
[DispId(1001)]
113+
public string GetDispIdAsString2()
114+
{
115+
return "1001";
116+
}
105117
}

src/tests/Interop/COM/NativeServer/DispatchTesting.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ class DispatchTesting : public UnknownImpl, public IDispatchTesting
184184
V_UNKNOWN(pVarResult) = new Enumerator(10);
185185
return S_OK;
186186
}
187+
case 1000:
188+
{
189+
return GetDispIdAsString_Proxy(pVarResult);
190+
}
191+
case 1001:
192+
{
193+
return GetDispIdAsString2_Proxy(pVarResult);
194+
}
187195
}
188196

189197
return E_NOTIMPL;
@@ -275,6 +283,20 @@ class DispatchTesting : public UnknownImpl, public IDispatchTesting
275283
return S_OK;
276284
}
277285

286+
HRESULT STDMETHODCALLTYPE GetDispIdAsString(
287+
/* [out,retval] */ BSTR *pRetVal)
288+
{
289+
*pRetVal = SysAllocString(W("1000"));
290+
return S_OK;
291+
}
292+
293+
HRESULT STDMETHODCALLTYPE GetDispIdAsString2(
294+
/* [out,retval] */ BSTR *pRetVal)
295+
{
296+
*pRetVal = SysAllocString(W("1001"));
297+
return S_OK;
298+
}
299+
278300
private:
279301
HRESULT DoubleNumeric_ReturnByRef_Proxy(_In_ DISPPARAMS *pDispParams)
280302
{
@@ -521,6 +543,30 @@ class DispatchTesting : public UnknownImpl, public IDispatchTesting
521543
return S_OK;
522544
}
523545

546+
HRESULT GetDispIdAsString_Proxy(_Inout_ VARIANT *pVarResult)
547+
{
548+
if (pVarResult == nullptr)
549+
return E_POINTER;
550+
551+
RETURN_IF_FAILED(::VariantChangeType(pVarResult, pVarResult, 0, VT_BSTR));
552+
BSTR result = nullptr;
553+
RETURN_IF_FAILED(GetDispIdAsString(&result));
554+
V_BSTR(pVarResult) = result;
555+
return S_OK;
556+
}
557+
558+
HRESULT GetDispIdAsString2_Proxy(_Inout_ VARIANT *pVarResult)
559+
{
560+
if (pVarResult == nullptr)
561+
return E_POINTER;
562+
563+
RETURN_IF_FAILED(::VariantChangeType(pVarResult, pVarResult, 0, VT_BSTR));
564+
BSTR result = nullptr;
565+
RETURN_IF_FAILED(GetDispIdAsString2(&result));
566+
V_BSTR(pVarResult) = result;
567+
return S_OK;
568+
}
569+
524570
public: // IUnknown
525571
STDMETHOD(QueryInterface)(
526572
/* [in] */ REFIID riid,

src/tests/Interop/COM/ServerContracts/Server.Contracts.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ void DoubleNumeric_ReturnByRef (
310310

311311
[DispId(/*DISPID_NEWENUM*/-4)]
312312
System.Collections.IEnumerator GetEnumerator();
313+
314+
// Test matching signatures and different metadata (ie DISPID)
315+
316+
[DispId(1000)]
317+
string GetDispIdAsString();
318+
319+
[DispId(1001)]
320+
string GetDispIdAsString2();
313321
}
314322

315323
[ComVisible(true)]

0 commit comments

Comments
 (0)