gameux: Add implementation of IGameStatistics::SetStatistic.

oldstable
Mariusz Pluciński 2010-09-26 15:00:40 +02:00 committed by Alexandre Julliard
parent 35692e40b1
commit ce28a5f262
2 changed files with 54 additions and 14 deletions

View File

@ -251,8 +251,48 @@ static HRESULT WINAPI GameStatisticsImpl_SetStatistic(
LPCWSTR name,
LPCWSTR value)
{
FIXME("stub\n");
return E_NOTIMPL;
HRESULT hr = S_OK;
DWORD dwNameLen, dwValueLen;
GameStatisticsImpl *This = impl_from_IGameStatistics(iface);
TRACE("(%p, %d, %d, %s, %s)\n", This, categoryIndex, statIndex,
debugstr_w(name), debugstr_w(value));
if(!name)
return S_FALSE;
if(categoryIndex >= MAX_CATEGORIES || statIndex >= MAX_STATS_PER_CATEGORY)
return E_INVALIDARG;
dwNameLen = lstrlenW(name);
if(dwNameLen > MAX_NAME_LENGTH)
{
hr = S_FALSE;
dwNameLen = MAX_NAME_LENGTH;
}
lstrcpynW(This->stats.categories[categoryIndex].stats[statIndex].sName,
name, dwNameLen+1);
if(value)
{
dwValueLen = lstrlenW(value);
if(dwValueLen > MAX_VALUE_LENGTH)
{
hr = S_FALSE;
dwValueLen = MAX_VALUE_LENGTH;
}
lstrcpynW(This->stats.categories[categoryIndex].stats[statIndex].sValue,
value, dwValueLen+1);
}
else
/* Windows allows to pass NULL as value */
This->stats.categories[categoryIndex].stats[statIndex].sValue[0] = 0;
return hr;
}
static HRESULT WINAPI GameStatisticsImpl_Save(

View File

@ -292,39 +292,39 @@ static void test_gamestatisticsmgr( void )
/* check what happen if any string is NULL */
hr = IGameStatistics_SetStatistic(gs, 0, 0, NULL, sValue00);
todo_wine ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
hr = IGameStatistics_SetStatistic(gs, 0, 0, sStatistic00, NULL);
todo_wine ok(hr == S_OK, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == S_OK, "setting statistic returned unexpected value: 0x%x)\n", hr);
/* check what happen if any string is too long */
sTooLongString = CoTaskMemAlloc(sizeof(WCHAR)*(uMaxNameLength+2));
memset(sTooLongString, 'a', sizeof(WCHAR)*(uMaxNameLength+1));
sTooLongString[uMaxNameLength+1]=0;
hr = IGameStatistics_SetStatistic(gs, 0, 0, sTooLongString, sValue00);
todo_wine ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
CoTaskMemFree(sTooLongString);
sTooLongString = CoTaskMemAlloc(sizeof(WCHAR)*(uMaxValueLength+2));
memset(sTooLongString, 'a', sizeof(WCHAR)*(uMaxValueLength+1));
sTooLongString[uMaxValueLength+1]=0;
hr = IGameStatistics_SetStatistic(gs, 0, 0, sStatistic00, sTooLongString);
todo_wine ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == S_FALSE, "setting statistic returned unexpected value: 0x%x)\n", hr);
CoTaskMemFree(sTooLongString);
/* check what happen on too big index of category or statistic */
hr = IGameStatistics_SetStatistic(gs, wMaxCategories, 0, sStatistic00, sValue00);
todo_wine ok(hr == E_INVALIDARG, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == E_INVALIDARG, "setting statistic returned unexpected value: 0x%x)\n", hr);
hr = IGameStatistics_SetStatistic(gs, 0, wMaxStatsPerCategory, sStatistic00, sValue00);
todo_wine ok(hr == E_INVALIDARG, "setting statistic returned unexpected value: 0x%x)\n", hr);
ok(hr == E_INVALIDARG, "setting statistic returned unexpected value: 0x%x)\n", hr);
todo_wine ok(IGameStatistics_SetStatistic(gs, 0, 0, sStatistic00, sValue00)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic00), wine_dbgstr_w(sValue00));
todo_wine ok(IGameStatistics_SetStatistic(gs, 0, 1, sStatistic01, sValue01)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic01), wine_dbgstr_w(sValue01));
todo_wine ok(IGameStatistics_SetStatistic(gs, 1, 0, sStatistic10, sValue10)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic10), wine_dbgstr_w(sValue10));
todo_wine ok(IGameStatistics_SetStatistic(gs, 1, 1, sStatistic11, sValue11)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic11), wine_dbgstr_w(sValue11));
todo_wine ok(IGameStatistics_SetStatistic(gs, 2, 0, sStatistic20, sValue20)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic20), wine_dbgstr_w(sValue20));
todo_wine ok(IGameStatistics_SetStatistic(gs, 2, 1, sStatistic21, sValue21)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic21), wine_dbgstr_w(sValue21));
ok(IGameStatistics_SetStatistic(gs, 0, 0, sStatistic00, sValue00)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic00), wine_dbgstr_w(sValue00));
ok(IGameStatistics_SetStatistic(gs, 0, 1, sStatistic01, sValue01)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic01), wine_dbgstr_w(sValue01));
ok(IGameStatistics_SetStatistic(gs, 1, 0, sStatistic10, sValue10)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic10), wine_dbgstr_w(sValue10));
ok(IGameStatistics_SetStatistic(gs, 1, 1, sStatistic11, sValue11)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic11), wine_dbgstr_w(sValue11));
ok(IGameStatistics_SetStatistic(gs, 2, 0, sStatistic20, sValue20)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic20), wine_dbgstr_w(sValue20));
ok(IGameStatistics_SetStatistic(gs, 2, 1, sStatistic21, sValue21)==S_OK, "setting statistic failed: name=%s, value=%s\n", wine_dbgstr_w(sStatistic21), wine_dbgstr_w(sValue21));
ok(_isFileExists(lpStatisticsFile) == FALSE, "statistics file %s already exists\n", wine_dbgstr_w(lpStatisticsFile));