[SHLWAPI][SHLWAPI_APITEST][SDK] Implement SHPropertyBag_ReadDWORD etc. (#5479)

- Add VariantChangeTypeForRead helper function.
- Implement SHPropertyBag_ReadType, SHPropertyBag_ReadBOOL, SHPropertyBag_ReadBOOLOld, SHPropertyBag_ReadSHORT, 
SHPropertyBag_ReadLONG, and SHPropertyBag_ReadDWORD functions.
- SHPropertyBag_ReadInt is an alias to SHPropertyBag_ReadLONG.
CORE-9283
This commit is contained in:
Katayama Hirofumi MZ 2023-07-26 08:21:47 +09:00 committed by GitHub
parent 57ce30b85f
commit fe440f7514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 265 additions and 11 deletions

View file

@ -14,6 +14,7 @@
static LPCWSTR s_pszPropNames[4] = { NULL, NULL, NULL, NULL };
static VARTYPE s_vt;
static INT s_cRead = 0;
static INT s_cWrite = 0;
static void ResetTest(VARTYPE vt,
@ -21,17 +22,17 @@ static void ResetTest(VARTYPE vt,
LPCWSTR pszName2 = NULL, LPCWSTR pszName3 = NULL)
{
s_vt = vt;
s_cWrite = 0;
s_cRead = s_cWrite = 0;
s_pszPropNames[0] = pszName0;
s_pszPropNames[1] = pszName1;
s_pszPropNames[2] = pszName2;
s_pszPropNames[3] = pszName3;
}
class CDummyWritePropertyBag : public IPropertyBag
class CDummyPropertyBag : public IPropertyBag
{
public:
CDummyWritePropertyBag()
CDummyPropertyBag()
{
}
@ -55,7 +56,19 @@ public:
// IPropertyBag
STDMETHODIMP Read(LPCWSTR pszPropName, VARIANT *pvari, IErrorLog *pErrorLog) override
{
++s_cRead;
ok_int(s_vt, V_VT(pvari));
for (size_t i = 0; i < _countof(s_pszPropNames); ++i)
{
if (s_pszPropNames[i])
{
ok_wstr(pszPropName, s_pszPropNames[i]);
s_pszPropNames[i] = NULL;
goto Skip1;
}
}
ok_int(0, 1);
Skip1:
return S_OK;
}
@ -76,69 +89,115 @@ public:
s_pszPropNames[0] = L"RECTL2.right";
return E_FAIL;
}
break;
goto Skip2;
}
}
ok_int(0, 1);
Skip2:
return S_OK;
}
};
static void SHPropertyBag_ReadTest(void)
{
HRESULT hr;
CDummyPropertyBag dummy;
BOOL bValue = 0xDEADFACE;
SHORT sValue = 0xDEAD;
LONG lValue = 0xDEADDEAD;
DWORD dwValue = 0xFEEDF00D;
ResetTest(VT_BOOL, L"BOOL1");
hr = SHPropertyBag_ReadBOOL(&dummy, s_pszPropNames[0], &bValue);
ok_long(hr, S_OK);
ok_int(s_cRead, 1);
ok_int(s_cWrite, 0);
ResetTest(VT_UI2, L"SHORT1");
hr = SHPropertyBag_ReadSHORT(&dummy, s_pszPropNames[0], &sValue);
ok_long(hr, S_OK);
ok_int(s_cRead, 1);
ok_int(s_cWrite, 0);
ResetTest(VT_I4, L"LONG1");
hr = SHPropertyBag_ReadLONG(&dummy, s_pszPropNames[0], &lValue);
ok_long(hr, S_OK);
ok_int(s_cRead, 1);
ok_int(s_cWrite, 0);
ResetTest(VT_UI4, L"DWORD1");
hr = SHPropertyBag_ReadDWORD(&dummy, s_pszPropNames[0], &dwValue);
ok_long(hr, S_OK);
ok_int(s_cRead, 1);
ok_int(s_cWrite, 0);
}
static void SHPropertyBag_WriteTest(void)
{
HRESULT hr;
CDummyWritePropertyBag dummy;
CDummyPropertyBag dummy;
ResetTest(VT_EMPTY, L"EMPTY1");
hr = SHPropertyBag_Delete(&dummy, s_pszPropNames[0]);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_BOOL, L"BOOL1");
hr = SHPropertyBag_WriteBOOL(&dummy, s_pszPropNames[0], TRUE);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_UI2, L"SHORT1");
hr = SHPropertyBag_WriteSHORT(&dummy, s_pszPropNames[0], 1);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_I4, L"LONG1");
hr = SHPropertyBag_WriteLONG(&dummy, s_pszPropNames[0], 1);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_UI4, L"DWORD1");
hr = SHPropertyBag_WriteDWORD(&dummy, s_pszPropNames[0], 1);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_BSTR, L"Str1");
hr = SHPropertyBag_WriteStr(&dummy, s_pszPropNames[0], L"1");
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
ResetTest(VT_I4, L"POINTL1.x", L"POINTL1.y");
POINTL ptl = { 0xEEEE, 0xDDDD };
hr = SHPropertyBag_WritePOINTL(&dummy, L"POINTL1", &ptl);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 2);
ResetTest(VT_I4, L"POINTS1.x", L"POINTS1.y");
POINTS pts = { 0x2222, 0x3333 };
hr = SHPropertyBag_WritePOINTS(&dummy, L"POINTS1", &pts);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 2);
ResetTest(VT_I4, L"RECTL1.left", L"RECTL1.top", L"RECTL1.right", L"RECTL1.bottom");
RECTL rcl = { 123, 456, 789, 101112 };
hr = SHPropertyBag_WriteRECTL(&dummy, L"RECTL1", &rcl);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 4);
ResetTest(VT_I4, L"RECTL2.left", L"RECTL2.top", L"RECTL2.right", L"RECTL2.bottom");
hr = SHPropertyBag_WriteRECTL(&dummy, L"RECTL2", &rcl);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 5);
GUID guid;
@ -146,10 +205,12 @@ static void SHPropertyBag_WriteTest(void)
ResetTest(VT_BSTR, L"GUID1");
hr = SHPropertyBag_WriteGUID(&dummy, L"GUID1", &guid);
ok_long(hr, S_OK);
ok_int(s_cRead, 0);
ok_int(s_cWrite, 1);
}
START_TEST(SHPropertyBag)
{
SHPropertyBag_ReadTest();
SHPropertyBag_WriteTest();
}