2 * IGameStatisticsMgr tests
4 * Copyright (C) 2010 Mariusz PluciĆski
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
29 /*******************************************************************************
32 static IGameExplorer *ge = NULL;
33 static WCHAR sExeName[MAX_PATH] = {0};
34 static GUID gameInstanceId;
35 /*******************************************************************************
37 * Registers test suite executable as game in Games Explorer. Required to test
40 static HRESULT _registerGame(void) {
42 WCHAR sExePath[MAX_PATH];
43 BSTR bstrExeName, bstrExePath;
46 /* prepare path to binary */
47 dwExeNameLen = GetModuleFileNameW(NULL, sExeName, sizeof (sExeName) / sizeof (sExeName[0]));
48 hr = (dwExeNameLen!= 0 ? S_OK : E_FAIL);
49 lstrcpynW(sExePath, sExeName, StrRChrW(sExeName, NULL, '\\') - sExeName + 1);
51 bstrExeName = SysAllocString(sExeName);
52 if(!bstrExeName) hr = E_OUTOFMEMORY;
54 bstrExePath = SysAllocString(sExePath);
55 if(!bstrExePath) hr = E_OUTOFMEMORY;
59 gameInstanceId = GUID_NULL;
60 hr = CoCreateInstance(&CLSID_GameExplorer, NULL, CLSCTX_INPROC_SERVER,
61 &IID_IGameExplorer, (LPVOID*)&ge);
65 hr = IGameExplorer_AddGame(ge, bstrExeName, bstrExePath,
66 GIS_CURRENT_USER, &gameInstanceId);
70 IGameExplorer_Release(ge);
74 SysFreeString(bstrExeName);
75 SysFreeString(bstrExePath);
78 /*******************************************************************************
80 * Unregisters test suite from Games Explorer.
82 static HRESULT _unregisterGame(void) {
85 if(!ge) return E_FAIL;
87 hr = IGameExplorer_RemoveGame(ge, gameInstanceId);
89 IGameExplorer_Release(ge);
94 /*******************************************************************************
97 static void test_create(BOOL* gameStatisticsAvailable)
101 IGameStatisticsMgr* gsm = NULL;
102 *gameStatisticsAvailable = FALSE;
104 /* interface available up from Win7 */
105 hr = CoCreateInstance( &CLSID_GameStatistics, NULL, CLSCTX_INPROC_SERVER, &IID_IGameStatisticsMgr, (LPVOID*)&gsm);
108 ok( hr == S_OK, "IGameStatisticsMgr creating failed (result: 0x%08x)\n", hr);
109 *gameStatisticsAvailable = TRUE;
110 IGameStatisticsMgr_Release(gsm);
113 win_skip("IGameStatisticsMgr cannot be created\n");
115 static void test_gamestatisticsmgr( void )
120 IGameStatisticsMgr* gsm = NULL;
121 IGameStatistics* gs = NULL;
123 hr = CoCreateInstance( &CLSID_GameStatistics, NULL, CLSCTX_INPROC_SERVER, &IID_IGameStatisticsMgr, (LPVOID*)&gsm);
124 ok(hr == S_OK, "IGameStatisticsMgr creating failed (result false)\n");
126 /* test trying to create interface IGameStatistics using GetGameStatistics method */
127 hr = IGameStatisticsMgr_GetGameStatistics(gsm, sExeName, GAMESTATS_OPEN_OPENORCREATE, &dwOpenResult, &gs);
128 todo_wine ok(SUCCEEDED(hr), "GetGameStatistics returned error: 0x%x\n", hr);
129 todo_wine ok(gs!=NULL, "GetGameStatistics did not return valid interface pointer\n");
132 hr = IGameStatistics_Release(gs);
133 ok(SUCCEEDED(hr), "releasing IGameStatistics returned error: 0x%x\n", hr);
135 /* test of removing game statistics from underlying storage */
136 hr = IGameStatisticsMgr_RemoveGameStatistics(gsm, sExeName);
137 todo_wine ok(SUCCEEDED(hr), "cannot remove game statistics, error: 0x%x\n", hr);
140 hr = IGameStatisticsMgr_Release(gsm);
141 ok(SUCCEEDED(hr), "releasing IGameStatisticsMgr returned error: 0x%x\n", hr);
144 START_TEST(gamestatistics)
147 BOOL gameStatisticsAvailable;
149 hr = CoInitialize( NULL );
150 ok( hr == S_OK, "failed to init COM\n");
152 test_create(&gameStatisticsAvailable);
154 if(gameStatisticsAvailable)
156 hr = _registerGame();
157 ok( hr == S_OK, "cannot register game in Game Explorer (error: 0x%x)\n", hr);
159 test_gamestatisticsmgr();
161 hr = _unregisterGame();
162 ok( hr == S_OK, "cannot unregister game from Game Explorer (error: 0x%x)\n", hr);