taskschd: Add some invalid parameters checks to ITaskFolder::DeleteFolder.
[wine/multimedia.git] / dlls / taskschd / tests / scheduler.c
blob2d9beeaa544d8cef32ffe3bd81b43906dc8d12d2
1 /*
2 * Copyright 2014 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "initguid.h"
26 #include "objbase.h"
27 #include "taskschd.h"
29 #include <wine/test.h>
31 static void test_Connect(void)
33 static WCHAR empty[] = { 0 };
34 static const WCHAR deadbeefW[] = { '0','.','0','.','0','.','0',0 };
35 WCHAR comp_name[MAX_COMPUTERNAME_LENGTH + 1];
36 DWORD len;
37 HRESULT hr;
38 BSTR bstr;
39 VARIANT v_null, v_comp;
40 VARIANT_BOOL vbool;
41 BOOL was_connected;
42 ITaskService *service;
44 hr = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskService, (void **)&service);
45 if (hr != S_OK)
47 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr);
48 return;
51 hr = ITaskService_get_Connected(service, NULL);
52 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
54 vbool = 0xdead;
55 hr = ITaskService_get_Connected(service, &vbool);
56 ok(hr == S_OK, "get_Connected error %#x\n", hr);
57 ok(vbool == VARIANT_FALSE, "expected VARIANT_FALSE, got %d\n", vbool);
59 hr = ITaskService_get_TargetServer(service, NULL);
60 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
62 hr = ITaskService_get_TargetServer(service, &bstr);
63 ok(hr == HRESULT_FROM_WIN32(ERROR_ONLY_IF_CONNECTED), "expected ERROR_ONLY_IF_CONNECTED, got %#x\n", hr);
65 /* Win7 doesn't support UNC \\ prefix, but according to a user
66 * comment on MSDN Win8 supports both ways.
68 len = sizeof(comp_name)/sizeof(comp_name[0]);
69 GetComputerNameW(comp_name, &len);
71 V_VT(&v_null) = VT_NULL;
73 V_VT(&v_comp) = VT_BSTR;
74 V_BSTR(&v_comp) = SysAllocString(comp_name);
76 hr = ITaskService_Connect(service, v_comp, v_null, v_null, v_null);
77 ok(hr == S_OK || hr == E_ACCESSDENIED /* not an administrator */, "Connect error %#x\n", hr);
78 was_connected = hr == S_OK;
79 SysFreeString(V_BSTR(&v_comp));
81 V_BSTR(&v_comp) = SysAllocString(deadbeefW);
82 hr = ITaskService_Connect(service, v_comp, v_null, v_null, v_null);
83 todo_wine
84 ok(hr == HRESULT_FROM_WIN32(RPC_S_INVALID_NET_ADDR), "expected RPC_S_INVALID_NET_ADDR, got %#x\n", hr);
85 SysFreeString(V_BSTR(&v_comp));
87 vbool = 0xdead;
88 hr = ITaskService_get_Connected(service, &vbool);
89 ok(hr == S_OK, "get_Connected error %#x\n", hr);
90 ok(vbool == VARIANT_FALSE || (was_connected && vbool == VARIANT_TRUE),
91 "Connect shouldn't trash an existing connection, got %d (was connected %d)\n", vbool, was_connected);
93 V_BSTR(&v_comp) = SysAllocString(empty);
94 hr = ITaskService_Connect(service, v_comp, v_null, v_null, v_null);
95 ok(hr == S_OK, "Connect error %#x\n", hr);
96 SysFreeString(V_BSTR(&v_comp));
98 V_BSTR(&v_comp) = NULL;
99 hr = ITaskService_Connect(service, v_comp, v_null, v_null, v_null);
100 ok(hr == S_OK, "Connect error %#x\n", hr);
102 hr = ITaskService_Connect(service, v_null, v_null, v_null, v_null);
103 ok(hr == S_OK, "Connect error %#x\n", hr);
105 vbool = 0xdead;
106 hr = ITaskService_get_Connected(service, &vbool);
107 ok(hr == S_OK, "get_Connected error %#x\n", hr);
108 ok(vbool == VARIANT_TRUE, "expected VARIANT_TRUE, got %d\n", vbool);
110 hr = ITaskService_get_TargetServer(service, &bstr);
111 ok(hr == S_OK, "get_TargetServer error %#x\n", hr);
112 ok(!lstrcmpW(comp_name, bstr), "compname %s != server name %s\n", wine_dbgstr_w(comp_name), wine_dbgstr_w(bstr));
113 SysFreeString(bstr);
115 ITaskService_Release(service);
118 static void test_GetFolder(void)
120 static WCHAR dot[] = { '.',0 };
121 static WCHAR empty[] = { 0 };
122 static WCHAR slash[] = { '/',0 };
123 static WCHAR bslash[] = { '\\',0 };
124 static WCHAR Wine[] = { '\\','W','i','n','e',0 };
125 static WCHAR Wine_Folder1[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1',0 };
126 static WCHAR Wine_Folder1_[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1','\\',0 };
127 static WCHAR Wine_Folder1_Folder2[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1','\\','F','o','l','d','e','r','2',0 };
128 static WCHAR Folder1_Folder2[] = { '\\','F','o','l','d','e','r','1','\\','F','o','l','d','e','r','2',0 };
129 static const WCHAR Folder1[] = { 'F','o','l','d','e','r','1',0 };
130 static const WCHAR Folder2[] = { 'F','o','l','d','e','r','2',0 };
131 HRESULT hr;
132 BSTR bstr;
133 VARIANT v_null;
134 ITaskService *service;
135 ITaskFolder *folder, *subfolder, *subfolder2;
137 hr = CoCreateInstance(&CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskService, (void **)&service);
138 if (hr != S_OK)
140 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr);
141 return;
144 V_VT(&v_null) = VT_NULL;
146 hr = ITaskService_Connect(service, v_null, v_null, v_null, v_null);
147 ok(hr == S_OK, "Connect error %#x\n", hr);
149 hr = ITaskService_GetFolder(service, slash, &folder);
150 todo_wine
151 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
153 hr = ITaskService_GetFolder(service, dot, &folder);
154 todo_wine
155 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
157 hr = ITaskService_GetFolder(service, bslash, &folder);
158 ok(hr == S_OK, "GetFolder error %#x\n", hr);
159 ITaskFolder_Release(folder);
161 hr = ITaskService_GetFolder(service, NULL, NULL);
162 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
164 hr = ITaskService_GetFolder(service, empty, &folder);
165 ok(hr == S_OK, "GetFolder error %#x\n", hr);
166 ITaskFolder_Release(folder);
168 hr = ITaskService_GetFolder(service, NULL, &folder);
169 ok(hr == S_OK, "GetFolder error %#x\n", hr);
171 hr = ITaskFolder_get_Name(folder, NULL);
172 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
174 hr = ITaskFolder_get_Name(folder, &bstr);
175 ok (hr == S_OK, "get_Name error %#x\n", hr);
176 ok(!lstrcmpW(bstr, bslash), "expected '\\', got %s\n", wine_dbgstr_w(bstr));
177 SysFreeString(bstr);
179 hr = ITaskFolder_get_Path(folder, NULL);
180 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
182 hr = ITaskFolder_get_Path(folder, &bstr);
183 ok(hr == S_OK, "get_Path error %#x\n", hr);
184 ok(!lstrcmpW(bstr, bslash), "expected '\\', got %s\n", wine_dbgstr_w(bstr));
185 SysFreeString(bstr);
187 hr = ITaskFolder_CreateFolder(folder, NULL, v_null, &subfolder);
188 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
190 /* Just in case something was left from previous runs */
191 ITaskFolder_DeleteFolder(folder, Wine_Folder1_Folder2, 0);
192 ITaskFolder_DeleteFolder(folder, Wine_Folder1, 0);
193 ITaskFolder_DeleteFolder(folder, Wine, 0);
195 hr = ITaskFolder_CreateFolder(folder, slash, v_null, &subfolder);
196 todo_wine
197 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
199 hr = ITaskService_GetFolder(service, Wine_Folder1_Folder2, &subfolder);
200 ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "expected ERROR_PATH_NOT_FOUND, got %#x\n", hr);
202 hr = ITaskFolder_CreateFolder(folder, bslash, v_null, &subfolder);
203 todo_wine
204 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
206 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1_Folder2, v_null, &subfolder);
207 ok(hr == S_OK, "CreateFolder error %#x\n", hr);
208 ITaskFolder_Release(subfolder);
210 hr = ITaskFolder_CreateFolder(folder, Wine, v_null, NULL);
211 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
213 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1_, v_null, &subfolder);
214 todo_wine
215 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
217 hr = ITaskFolder_CreateFolder(folder, Wine, v_null, &subfolder);
218 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
219 hr = ITaskFolder_CreateFolder(folder, Wine+1, v_null, &subfolder);
220 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
221 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1, v_null, &subfolder);
222 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
223 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1+1, v_null, &subfolder);
224 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
225 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1_Folder2, v_null, &subfolder);
226 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
227 hr = ITaskFolder_CreateFolder(folder, Wine_Folder1_Folder2+1, v_null, &subfolder);
228 ok(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr);
230 hr = ITaskService_GetFolder(service, Wine_Folder1_Folder2, NULL);
231 ok(hr == E_POINTER, "expected E_POINTER, got %#x\n", hr);
233 hr = ITaskService_GetFolder(service, Wine_Folder1_Folder2, &subfolder);
234 ok(hr == S_OK, "GetFolder error %#x\n", hr);
236 hr = ITaskFolder_get_Name(subfolder, &bstr);
237 ok (hr == S_OK, "get_Name error %#x\n", hr);
238 ok(!lstrcmpW(bstr, Folder2), "expected Folder2, got %s\n", wine_dbgstr_w(bstr));
239 SysFreeString(bstr);
240 hr = ITaskFolder_get_Path(subfolder, &bstr);
241 ok(hr == S_OK, "get_Path error %#x\n", hr);
242 ok(!lstrcmpW(bstr, Wine_Folder1_Folder2), "expected \\Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr));
243 SysFreeString(bstr);
244 ITaskFolder_Release(subfolder);
246 hr = ITaskService_GetFolder(service, Wine_Folder1_Folder2+1, &subfolder);
247 ok(hr == S_OK, "GetFolder error %#x\n", hr);
248 hr = ITaskFolder_get_Name(subfolder, &bstr);
249 ok (hr == S_OK, "get_Name error %#x\n", hr);
250 ok(!lstrcmpW(bstr, Folder2), "expected Folder2, got %s\n", wine_dbgstr_w(bstr));
251 SysFreeString(bstr);
252 hr = ITaskFolder_get_Path(subfolder, &bstr);
253 ok(hr == S_OK, "get_Path error %#x\n", hr);
254 ok(!lstrcmpW(bstr, Wine_Folder1_Folder2+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr));
255 SysFreeString(bstr);
256 ITaskFolder_Release(subfolder);
258 hr = ITaskService_GetFolder(service, Wine_Folder1, &subfolder);
259 ok(hr == S_OK, "GetFolder error %#x\n", hr);
260 hr = ITaskFolder_get_Name(subfolder, &bstr);
261 ok (hr == S_OK, "get_Name error %#x\n", hr);
262 ok(!lstrcmpW(bstr, Folder1), "expected Folder1, got %s\n", wine_dbgstr_w(bstr));
263 SysFreeString(bstr);
264 hr = ITaskFolder_get_Path(subfolder, &bstr);
265 ok(hr == S_OK, "get_Path error %#x\n", hr);
266 ok(!lstrcmpW(bstr, Wine_Folder1), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr));
267 SysFreeString(bstr);
268 ITaskFolder_Release(subfolder);
270 hr = ITaskService_GetFolder(service, Wine, &subfolder);
271 ok(hr == S_OK, "GetFolder error %#x\n", hr);
272 hr = ITaskFolder_get_Name(subfolder, &bstr);
273 ok (hr == S_OK, "get_Name error %#x\n", hr);
274 ok(!lstrcmpW(bstr, Wine+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr));
275 SysFreeString(bstr);
276 hr = ITaskFolder_get_Path(subfolder, &bstr);
277 ok(hr == S_OK, "get_Path error %#x\n", hr);
278 ok(!lstrcmpW(bstr, Wine), "expected \\Wine, got %s\n", wine_dbgstr_w(bstr));
279 SysFreeString(bstr);
280 ITaskFolder_Release(subfolder);
282 hr = ITaskService_GetFolder(service, Wine+1, &subfolder);
283 ok(hr == S_OK, "GetFolder error %#x\n", hr);
284 hr = ITaskFolder_get_Name(subfolder, &bstr);
285 ok (hr == S_OK, "get_Name error %#x\n", hr);
286 ok(!lstrcmpW(bstr, Wine+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr));
287 SysFreeString(bstr);
288 hr = ITaskFolder_get_Path(subfolder, &bstr);
289 ok(hr == S_OK, "get_Path error %#x\n", hr);
290 ok(!lstrcmpW(bstr, Wine+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr));
291 SysFreeString(bstr);
293 hr = ITaskFolder_GetFolder(subfolder, bslash, &subfolder2);
294 todo_wine
295 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
297 hr = ITaskFolder_GetFolder(subfolder, NULL, &subfolder2);
298 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
300 hr = ITaskFolder_GetFolder(subfolder, empty, &subfolder2);
301 ok(hr == S_OK, "GetFolder error %#x\n", hr);
302 hr = ITaskFolder_get_Name(subfolder2, &bstr);
303 ok (hr == S_OK, "get_Name error %#x\n", hr);
304 ok(!lstrcmpW(bstr, Wine+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr));
305 SysFreeString(bstr);
306 hr = ITaskFolder_get_Path(subfolder2, &bstr);
307 ok(hr == S_OK, "get_Path error %#x\n", hr);
308 ok(!lstrcmpW(bstr, Wine+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr));
309 SysFreeString(bstr);
310 ITaskFolder_Release(subfolder2);
312 hr = ITaskFolder_GetFolder(subfolder, Folder1_Folder2, &subfolder2);
313 ok(hr == S_OK, "GetFolder error %#x\n", hr);
314 hr = ITaskFolder_get_Name(subfolder2, &bstr);
315 ok (hr == S_OK, "get_Name error %#x\n", hr);
316 ok(!lstrcmpW(bstr, Folder2), "expected Folder2, got %s\n", wine_dbgstr_w(bstr));
317 SysFreeString(bstr);
318 hr = ITaskFolder_get_Path(subfolder2, &bstr);
319 ok(hr == S_OK, "get_Path error %#x\n", hr);
320 ok(!lstrcmpW(bstr, Wine_Folder1_Folder2+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr));
321 SysFreeString(bstr);
322 ITaskFolder_Release(subfolder2);
324 hr = ITaskFolder_GetFolder(subfolder, Folder1_Folder2+1, &subfolder2);
325 ok(hr == S_OK, "GetFolder error %#x\n", hr);
327 hr = ITaskFolder_get_Name(subfolder2, &bstr);
328 ok (hr == S_OK, "get_Name error %#x\n", hr);
329 ok(!lstrcmpW(bstr, Folder2), "expected Folder2, got %s\n", wine_dbgstr_w(bstr));
330 SysFreeString(bstr);
331 hr = ITaskFolder_get_Path(subfolder2, &bstr);
332 ok(hr == S_OK, "get_Path error %#x\n", hr);
333 ok(!lstrcmpW(bstr, Wine_Folder1_Folder2+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr));
334 SysFreeString(bstr);
335 ITaskFolder_Release(subfolder2);
337 ITaskFolder_Release(subfolder);
339 hr = ITaskFolder_DeleteFolder(folder, Wine_Folder1_Folder2, 0);
340 ok(hr == S_OK, "DeleteFolder error %#x\n", hr);
341 ITaskFolder_DeleteFolder(folder, Wine_Folder1+1, 0);
342 ok(hr == S_OK, "DeleteFolder error %#x\n", hr);
343 hr = ITaskFolder_DeleteFolder(folder, Wine+1, 0);
344 ok(hr == S_OK, "DeleteFolder error %#x\n", hr);
346 hr = ITaskFolder_DeleteFolder(folder, Wine, 0);
347 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "expected ERROR_FILE_NOT_FOUND, got %#x\n", hr);
349 hr = ITaskFolder_DeleteFolder(folder, NULL, 0);
350 ok(hr == E_ACCESSDENIED || hr == E_INVALIDARG /* Vista */, "expected E_ACCESSDENIED, got %#x\n", hr);
352 hr = ITaskFolder_DeleteFolder(folder, empty, 0);
353 ok(hr == E_ACCESSDENIED || hr == E_INVALIDARG /* Vista */, "expected E_ACCESSDENIED, got %#x\n", hr);
355 hr = ITaskFolder_DeleteFolder(folder, slash, 0);
356 todo_wine
357 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), "expected ERROR_INVALID_NAME, got %#x\n", hr);
359 ITaskFolder_Release(folder);
360 ITaskService_Release(service);
363 START_TEST(scheduler)
365 OleInitialize(NULL);
367 test_Connect();
368 test_GetFolder();
370 OleUninitialize();