2 * IGameExplorer and IGameExplorer2 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
34 #include "wine/test.h"
36 static void test_create(BOOL
* gameExplorerAvailable
, BOOL
* gameExplorer2Available
)
40 IGameExplorer
* ge
= NULL
;
41 IGameExplorer2
* ge2
= NULL
;
43 /* interface available up from Vista */
44 hr
= CoCreateInstance( &CLSID_GameExplorer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGameExplorer
, (LPVOID
*)&ge
);
47 ok(hr
== S_OK
, "IGameExplorer creating failed (result false)\n");
48 *gameExplorerAvailable
= TRUE
;
49 IGameExplorer_Release(ge
);
52 win_skip("IGameExplorer cannot be created\n");
54 /* interface available up from Win7 */
55 hr
= CoCreateInstance( &CLSID_GameExplorer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGameExplorer2
, (LPVOID
*)&ge2
);
58 ok( hr
== S_OK
, "IGameExplorer2 creating failed (result false)\n");
59 *gameExplorer2Available
= TRUE
;
60 IGameExplorer2_Release(ge2
);
63 win_skip("IGameExplorer2 cannot be created\n");
66 static void test_add_remove_game(void)
68 static const GUID defaultGUID
= {0x01234567, 0x89AB, 0xCDEF,
69 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}};
73 IGameExplorer
* ge
= NULL
;
74 WCHAR sExeName
[MAX_PATH
];
75 WCHAR sExePath
[MAX_PATH
];
76 BSTR bstrExeName
= NULL
, bstrExePath
= NULL
;
80 hr
= CoCreateInstance(&CLSID_GameExplorer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGameExplorer
, (LPVOID
*) & ge
);
81 ok(ge
!= NULL
, "cannot create coclass IGameExplorer\n");
82 ok(hr
== S_OK
, "cannot create coclass IGameExplorer\n");
86 /* prepare path to binary */
87 dwExeNameLen
= GetModuleFileNameW(NULL
, sExeName
, ARRAY_SIZE(sExeName
));
88 ok(dwExeNameLen
!= 0, "GetModuleFileNameW returned invalid value\n");
89 lstrcpynW(sExePath
, sExeName
, StrRChrW(sExeName
, NULL
, '\\') - sExeName
+ 1);
90 bstrExeName
= SysAllocString(sExeName
);
91 ok(bstrExeName
!= NULL
, "cannot allocate string for exe name\n");
92 bstrExePath
= SysAllocString(sExePath
);
93 ok(bstrExePath
!= NULL
, "cannot allocate string for exe path\n");
95 if(bstrExeName
&& bstrExePath
)
97 trace("prepared EXE name: %s\n", wine_dbgstr_w(bstrExeName
));
98 trace("prepared EXE path: %s\n", wine_dbgstr_w(bstrExePath
));
101 /* try to register game with provided guid */
102 memcpy(&guid
, &defaultGUID
, sizeof (guid
));
104 hr
= IGameExplorer_AddGame(ge
, bstrExeName
, bstrExePath
, GIS_CURRENT_USER
, &guid
);
105 ok(SUCCEEDED(hr
), "IGameExplorer::AddGame failed (error 0x%08lx)\n", hr
);
106 ok(memcmp(&guid
, &defaultGUID
, sizeof (guid
)) == 0, "AddGame unexpectedly modified GUID\n");
110 hr
= IGameExplorer_RemoveGame(ge
, guid
);
111 ok(SUCCEEDED(hr
), "IGameExplorer::RemoveGame failed (error 0x%08lx)\n", hr
);
114 /* try to register game with empty guid */
115 memcpy(&guid
, &GUID_NULL
, sizeof (guid
));
117 hr
= IGameExplorer_AddGame(ge
, bstrExeName
, bstrExePath
, GIS_CURRENT_USER
, &guid
);
118 ok(SUCCEEDED(hr
), "IGameExplorer::AddGame failed (error 0x%08lx)\n", hr
);
122 hr
= IGameExplorer_RemoveGame(ge
, guid
);
123 ok(SUCCEEDED(hr
), "IGameExplorer::RemoveGame failed (error 0x%08lx)\n", hr
);
127 /* free allocated resources */
128 SysFreeString(bstrExePath
);
129 SysFreeString(bstrExeName
);
131 IGameExplorer_Release(ge
);
135 static void test_install_uninstall_game(void)
139 IGameExplorer2
* ge2
= NULL
;
140 WCHAR sExeName
[MAX_PATH
];
141 WCHAR sExePath
[MAX_PATH
];
144 hr
= CoCreateInstance(&CLSID_GameExplorer
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGameExplorer2
, (LPVOID
*)&ge2
);
145 ok(ge2
!= NULL
, "cannot create coclass IGameExplorer2\n");
146 ok(hr
== S_OK
, "cannot create coclass IGameExplorer2\n");
150 /* prepare path to binary */
151 dwExeNameLen
= GetModuleFileNameW(NULL
, sExeName
, ARRAY_SIZE(sExeName
));
152 ok(dwExeNameLen
!= 0, "GetModuleFileNameW returned invalid value\n");
153 lstrcpynW(sExePath
, sExeName
, StrRChrW(sExeName
, NULL
, '\\') - sExeName
+ 1);
155 trace("prepared EXE name: %s\n", wine_dbgstr_w(sExeName
));
156 trace("prepared EXE path: %s\n", wine_dbgstr_w(sExePath
));
159 hr
= IGameExplorer2_InstallGame(ge2
, sExeName
, sExePath
, GIS_CURRENT_USER
);
160 ok(SUCCEEDED(hr
), "IGameExplorer2::InstallGame failed (error 0x%08lx)\n", hr
);
164 hr
= IGameExplorer2_UninstallGame(ge2
, sExeName
);
165 ok(SUCCEEDED(hr
), "IGameExplorer2::UninstallGame failed (error 0x%08lx)\n", hr
);
168 IGameExplorer2_Release(ge2
);
172 static void run_tests(void)
174 BOOL gameExplorerAvailable
= FALSE
;
175 BOOL gameExplorer2Available
= FALSE
;
177 test_create(&gameExplorerAvailable
, &gameExplorer2Available
);
179 if(gameExplorerAvailable
)
180 test_add_remove_game();
182 if(gameExplorer2Available
)
183 test_install_uninstall_game();
186 START_TEST(gameexplorer
)
190 hr
= CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
191 ok(hr
== S_OK
, "Failed to initialize COM, hr %#lx.\n", hr
);
192 trace("Running multithreaded tests.\n");
196 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
197 ok(hr
== S_OK
, "Failed to initialize COM, hr %#lx.\n", hr
);
198 trace("Running apartment threaded tests.\n");