Module: wine Branch: master Commit: ce28a5f2621e7954241fa5df42d7c77ae47a2c39 URL: http://source.winehq.org/git/wine.git/?a=commit;h=ce28a5f2621e7954241fa5df42...
Author: Mariusz Pluciński vshader@gmail.com Date: Sun Sep 26 15:00:40 2010 +0200
gameux: Add implementation of IGameStatistics::SetStatistic.
---
dlls/gameux/gamestatistics.c | 44 ++++++++++++++++++++++++++++++++++- dlls/gameux/tests/gamestatistics.c | 26 ++++++++++---------- 2 files changed, 55 insertions(+), 15 deletions(-)
diff --git a/dlls/gameux/gamestatistics.c b/dlls/gameux/gamestatistics.c index 67bfc08..a4c88a4 100644 --- a/dlls/gameux/gamestatistics.c +++ b/dlls/gameux/gamestatistics.c @@ -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( diff --git a/dlls/gameux/tests/gamestatistics.c b/dlls/gameux/tests/gamestatistics.c index e62368a..491aecb 100644 --- a/dlls/gameux/tests/gamestatistics.c +++ b/dlls/gameux/tests/gamestatistics.c @@ -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); - - 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(hr == E_INVALIDARG, "setting statistic returned unexpected value: 0x%x)\n", hr); + + 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));