Skip to content

Commit

Permalink
Change to use std int for Interop tests (#95040)
Browse files Browse the repository at this point in the history
* Change to use std int for Interop tests
  • Loading branch information
AaronRobinsonMSFT committed Nov 23, 2023
1 parent ac1ddb9 commit e6ffc6c
Show file tree
Hide file tree
Showing 47 changed files with 686 additions and 723 deletions.
19 changes: 12 additions & 7 deletions src/tests/Common/Platform/platformdefines.cpp
Expand Up @@ -331,10 +331,15 @@ DWORD TP_GetFullPathName(LPWSTR fileName, DWORD nBufferLength, LPWSTR lpBuffer)
#define INTSAFE_E_ARITHMETIC_OVERFLOW ((HRESULT)0x80070216L) // 0x216 = 534 = ERROR_ARITHMETIC_OVERFLOW
#define ULONG_ERROR (0xffffffffUL)
#define WIN32_ALLOC_ALIGN (16 - 1)

#ifndef UInt32x32To64
#define UInt32x32To64(a, b) ((uint64_t)((ULONG)(a)) * (uint64_t)((ULONG)(b)))
#endif // UInt32x32To64

//
// ULONGLONG -> ULONG conversion
// uint64_t -> ULONG conversion
//
HRESULT ULongLongToULong(ULONGLONG ullOperand, ULONG* pulResult)
static HRESULT UInt64ToULong(uint64_t ullOperand, ULONG* pulResult)
{
HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
*pulResult = ULONG_ERROR;
Expand All @@ -348,7 +353,7 @@ HRESULT ULongLongToULong(ULONGLONG ullOperand, ULONG* pulResult)
return hr;
}

HRESULT ULongAdd(ULONG ulAugend, ULONG ulAddend,ULONG* pulResult)
static HRESULT ULongAdd(ULONG ulAugend, ULONG ulAddend,ULONG* pulResult)
{
HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
*pulResult = ULONG_ERROR;
Expand All @@ -362,14 +367,14 @@ HRESULT ULongAdd(ULONG ulAugend, ULONG ulAddend,ULONG* pulResult)
return hr;
}

HRESULT ULongMult(ULONG ulMultiplicand, ULONG ulMultiplier, ULONG* pulResult)
static HRESULT ULongMult(ULONG ulMultiplicand, ULONG ulMultiplier, ULONG* pulResult)
{
ULONGLONG ull64Result = UInt32x32To64(ulMultiplicand, ulMultiplier);
uint64_t ull64Result = UInt32x32To64(ulMultiplicand, ulMultiplier);

return ULongLongToULong(ull64Result, pulResult);
return UInt64ToULong(ull64Result, pulResult);
}

HRESULT CbSysStringSize(ULONG cchSize, BOOL isByteLen, ULONG *result)
static HRESULT CbSysStringSize(ULONG cchSize, BOOL isByteLen, ULONG *result)
{
if (result == NULL)
return E_INVALIDARG;
Expand Down
29 changes: 10 additions & 19 deletions src/tests/Common/Platform/platformdefines.h
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <cstdint>
#include <cinttypes>
#include <minipal/utils.h>

#ifndef _PLATFORMDEFINES__H
Expand Down Expand Up @@ -50,7 +51,7 @@
#define L(t) L##t
#define W(str) L##str

typedef unsigned error_t;
typedef uint32_t error_t;
typedef HANDLE THREAD_ID;

#define DLL_EXPORT __declspec(dllexport)
Expand All @@ -59,44 +60,34 @@ typedef HANDLE THREAD_ID;
#include <pthread.h>

typedef char16_t WCHAR;
typedef unsigned int DWORD;
typedef uint32_t DWORD;

#ifdef OBJC_TESTS
// The Objective-C headers define the BOOL type to be unsigned char or bool.
// As a result, we can't redefine it here. So instead, define WINBOOL to be int-sized.
typedef int WINBOOL;
typedef int32_t WINBOOL;
#else
typedef int BOOL;
typedef int32_t BOOL;
#endif
typedef WCHAR *LPWSTR, *PWSTR;
typedef const WCHAR *LPCWSTR, *PCWSTR;

typedef int HRESULT;
#define LONGLONG long long
#define ULONGLONG unsigned LONGLONG
typedef unsigned int ULONG, *PULONG;
typedef int32_t HRESULT;

typedef int32_t LONG, *PLONG;
typedef uint32_t ULONG, *PULONG;

#define S_OK 0x0
#define SUCCEEDED(_hr) ((HRESULT)(_hr) >= 0)
#define FAILED(_hr) ((HRESULT)(_hr) < 0)

#define CCH_BSTRMAX 0x7FFFFFFF // 4 + (0x7ffffffb + 1 ) * 2 ==> 0xFFFFFFFC
#define CB_BSTRMAX 0xFFFFFFFa // 4 + (0xfffffff6 + 2) ==> 0xFFFFFFFC

#ifdef RC_INVOKED
#define _HRESULT_TYPEDEF_(_sc) _sc
#else // RC_INVOKED
#define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
#endif // RC_INVOKED
#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L)

#ifdef HOST_64BIT
#define __int64 long
#else // HOST_64BIT
#define __int64 long long
#endif // HOST_64BIT

#define UInt32x32To64(a, b) ((unsigned __int64)((ULONG)(a)) * (unsigned __int64)((ULONG)(b)))

#ifndef TRUE
#define TRUE 1
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/tests/Interop/ArrayMarshalling/SafeArray/RecordNative.cpp
Expand Up @@ -51,12 +51,12 @@ class BlittableRecordInfo : public IRecordInfo
}

rgBstrNames[0] = TP_SysAllocString(W("a"));

for(size_t i = 1; i < *pcNames; i++)
{
rgBstrNames[i] = nullptr;
}

return S_OK;
}

Expand Down Expand Up @@ -234,12 +234,12 @@ class NonBlittableRecordInfo : public IRecordInfo
}

rgBstrNames[0] = TP_SysAllocString(W("b"));

for(size_t i = 1; i < *pcNames; i++)
{
rgBstrNames[i] = nullptr;
}

return S_OK;
}

Expand Down Expand Up @@ -368,7 +368,7 @@ class NonBlittableRecordInfo : public IRecordInfo
}

private:
ULONG refCount;
uint32_t refCount;
} s_NonBlittableRecordInfo;

extern "C" DLL_EXPORT SAFEARRAY* STDMETHODCALLTYPE CreateSafeArrayOfRecords(BlittableRecord records[], int numRecords)
Expand Down
Expand Up @@ -38,8 +38,8 @@ namespace API
STDMETHOD(ReleaseDisconnectedReferenceSources)() = 0;
STDMETHOD(NotifyEndOfReferenceTrackingOnThread)() = 0;
STDMETHOD(GetTrackerTarget)(_In_ IUnknown* obj, _Outptr_ IReferenceTrackerTarget** ppNewReference) = 0;
STDMETHOD(AddMemoryPressure)(_In_ UINT64 bytesAllocated) = 0;
STDMETHOD(RemoveMemoryPressure)(_In_ UINT64 bytesAllocated) = 0;
STDMETHOD(AddMemoryPressure)(_In_ uint64_t bytesAllocated) = 0;
STDMETHOD(RemoveMemoryPressure)(_In_ uint64_t bytesAllocated) = 0;
};

//3cf184b4-7ccb-4dda-8455-7e6ce99a3298
Expand Down
8 changes: 4 additions & 4 deletions src/tests/Interop/COM/Dynamic/Server/DispatchImpl.cpp
Expand Up @@ -23,13 +23,13 @@ DispatchImpl::DispatchImpl(GUID guid, void *instance, const wchar_t* tlb)
throw hr;
}

HRESULT DispatchImpl::DoGetTypeInfoCount(UINT* pctinfo)
HRESULT DispatchImpl::DoGetTypeInfoCount(uint32_t* pctinfo)
{
*pctinfo = 1;
return S_OK;
}

HRESULT DispatchImpl::DoGetTypeInfo(UINT iTInfo, ITypeInfo** ppTInfo)
HRESULT DispatchImpl::DoGetTypeInfo(uint32_t iTInfo, ITypeInfo** ppTInfo)
{
if (iTInfo != 0)
return DISP_E_BADINDEX;
Expand All @@ -38,12 +38,12 @@ HRESULT DispatchImpl::DoGetTypeInfo(UINT iTInfo, ITypeInfo** ppTInfo)
return _typeInfo->QueryInterface(__uuidof(*ppTInfo), (void**)ppTInfo);
}

HRESULT DispatchImpl::DoGetIDsOfNames(LPOLESTR* rgszNames, UINT cNames, DISPID* rgDispId)
HRESULT DispatchImpl::DoGetIDsOfNames(LPOLESTR* rgszNames, uint32_t cNames, DISPID* rgDispId)
{
return _typeInfo->GetIDsOfNames(rgszNames, cNames, rgDispId);
}

HRESULT DispatchImpl::DoInvoke(DISPID dispIdMember, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
HRESULT DispatchImpl::DoInvoke(DISPID dispIdMember, uint16_t wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint32_t* puArgErr)
{
return _typeInfo->Invoke(_instance, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
}
16 changes: 8 additions & 8 deletions src/tests/Interop/COM/Dynamic/Server/DispatchImpl.h
Expand Up @@ -20,10 +20,10 @@ class DispatchImpl : public UnknownImpl
DispatchImpl& operator=(DispatchImpl&&) = default;

protected:
HRESULT DoGetTypeInfoCount(UINT* pctinfo);
HRESULT DoGetTypeInfo(UINT iTInfo, ITypeInfo** ppTInfo);
HRESULT DoGetIDsOfNames(LPOLESTR* rgszNames, UINT cNames, DISPID* rgDispId);
HRESULT DoInvoke(DISPID dispIdMember, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);
HRESULT DoGetTypeInfoCount(uint32_t* pctinfo);
HRESULT DoGetTypeInfo(uint32_t iTInfo, ITypeInfo** ppTInfo);
HRESULT DoGetIDsOfNames(LPOLESTR* rgszNames, uint32_t cNames, DISPID* rgDispId);
HRESULT DoInvoke(DISPID dispIdMember, uint16_t wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint32_t* puArgErr);

private:
ComSmartPtr<ITypeLib> _typeLib;
Expand All @@ -33,11 +33,11 @@ class DispatchImpl : public UnknownImpl

// Macro to use for defining dispatch impls
#define DEFINE_DISPATCH() \
STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) \
STDMETHOD(GetTypeInfoCount)(uint32_t *pctinfo) \
{ return DispatchImpl::DoGetTypeInfoCount(pctinfo); } \
STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) \
STDMETHOD(GetTypeInfo)(uint32_t iTInfo, LCID lcid, ITypeInfo **ppTInfo) \
{ return DispatchImpl::DoGetTypeInfo(iTInfo, ppTInfo); } \
STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) \
STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, uint32_t cNames, LCID lcid, DISPID* rgDispId) \
{ return DispatchImpl::DoGetIDsOfNames(rgszNames, cNames, rgDispId); } \
STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) \
STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, uint16_t wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint32_t* puArgErr) \
{ return DispatchImpl::DoInvoke(dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); }
4 changes: 2 additions & 2 deletions src/tests/Interop/COM/Dynamic/Server/EventTest.cpp
Expand Up @@ -18,7 +18,7 @@ namespace
HRESULT STDMETHODCALLTYPE FireEventImpl(DISPID dispId, VARIANTARG *arg)
{
HRESULT hr;
for (UINT i = 0; i < _sinks.size(); ++i)
for (uint32_t i = 0; i < _sinks.size(); ++i)
{
IDispatch *handler = _sinks[i];
if (handler == nullptr)
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace
if (pUnkSink == nullptr || pdwCookie == nullptr)
return E_POINTER;

for (UINT i = 0; i < _sinks.size(); ++i)
for (uint32_t i = 0; i < _sinks.size(); ++i)
{
if (_sinks[i] != nullptr)
continue;
Expand Down
22 changes: 11 additions & 11 deletions src/tests/Interop/COM/NativeClients/Dispatch/Client.cpp
Expand Up @@ -79,20 +79,20 @@ void Validate_Numeric_In_ReturnByRef()
lcid,
&methodId));

BYTE b1 = 24;
BYTE b2;
SHORT s1 = 53;
SHORT s2;
USHORT us1 = 74;
USHORT us2;
uint8_t b1 = 24;
uint8_t b2;
int16_t s1 = 53;
int16_t s2;
uint16_t us1 = 74;
uint16_t us2;
LONG i1 = 34;
LONG i2;
ULONG ui1 = 854;
ULONG ui2;
LONGLONG l1 = 894;
LONGLONG l2;
ULONGLONG ul1 = 4168;
ULONGLONG ul2;
int64_t l1 = 894;
int64_t l2;
uint64_t ul1 = 4168;
uint64_t ul2;

{
DISPPARAMS params;
Expand Down Expand Up @@ -159,7 +159,7 @@ void Validate_Numeric_In_ReturnByRef()
l2 = 0;
ul2 = 0;

THROW_IF_FAILED(dispatchTesting->DoubleNumeric_ReturnByRef(b1, &b2, s1, &s2, us1, &us2, i1, (INT*)&i2, ui1, (UINT*)&ui2, l1, &l2, ul1, &ul2));
THROW_IF_FAILED(dispatchTesting->DoubleNumeric_ReturnByRef(b1, &b2, s1, &s2, us1, &us2, i1, (int32_t*)&i2, ui1, (uint32_t*)&ui2, l1, &l2, ul1, &ul2));

THROW_FAIL_IF_FALSE(b2 == b1 * 2);
THROW_FAIL_IF_FALSE(s2 == s1 * 2);
Expand Down
10 changes: 5 additions & 5 deletions src/tests/Interop/COM/NativeClients/Events/EventTests.cpp
Expand Up @@ -104,13 +104,13 @@ namespace

public: // IDispatch
virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(
/* [out] */ __RPC__out UINT* pctinfo)
/* [out] */ __RPC__out uint32_t* pctinfo)
{
return E_NOTIMPL;
}

virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(
/* [in] */ UINT iTInfo,
/* [in] */ uint32_t iTInfo,
/* [in] */ LCID lcid,
/* [out] */ __RPC__deref_out_opt ITypeInfo** ppTInfo)
{
Expand All @@ -120,7 +120,7 @@ namespace
virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(
/* [in] */ __RPC__in REFIID riid,
/* [size_is][in] */ __RPC__in_ecount_full(cNames) LPOLESTR* rgszNames,
/* [range][in] */ __RPC__in_range(0, 16384) UINT cNames,
/* [range][in] */ __RPC__in_range(0, 16384) uint32_t cNames,
/* [in] */ LCID lcid,
/* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID* rgDispId)
{
Expand All @@ -135,15 +135,15 @@ namespace
/* [annotation][in] */
_In_ LCID lcid,
/* [annotation][in] */
_In_ WORD wFlags,
_In_ uint16_t wFlags,
/* [annotation][out][in] */
_In_ DISPPARAMS* pDispParams,
/* [annotation][out] */
_Out_opt_ VARIANT* pVarResult,
/* [annotation][out] */
_Out_opt_ EXCEPINFO* pExcepInfo,
/* [annotation][out] */
_Out_opt_ UINT* puArgErr)
_Out_opt_ uint32_t* puArgErr)
{
//
// Note that arguments are received in reverse order for IDispatch::Invoke()
Expand Down
2 changes: 1 addition & 1 deletion src/tests/Interop/COM/NativeServer/ArrayTesting.h
Expand Up @@ -38,7 +38,7 @@ class ArrayTesting : public UnknownImpl, public IArrayTesting
switch (type)
{
case VT_UI1:
*r = Mean(*l, static_cast<unsigned char*>(d->pvData));
*r = Mean(*l, static_cast<uint8_t*>(d->pvData));
break;
case VT_I2:
*r = Mean(*l, static_cast<int16_t*>(d->pvData));
Expand Down

0 comments on commit e6ffc6c

Please sign in to comment.