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
30 #include <wine/test.h>
32 static void test_Connect(void)
34 static WCHAR empty
[] = { 0 };
35 static const WCHAR deadbeefW
[] = { '0','.','0','.','0','.','0',0 };
36 WCHAR comp_name
[MAX_COMPUTERNAME_LENGTH
+ 1];
40 VARIANT v_null
, v_comp
;
43 ITaskService
*service
;
45 hr
= CoCreateInstance(&CLSID_TaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ITaskService
, (void **)&service
);
48 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr
);
52 hr
= ITaskService_get_Connected(service
, NULL
);
53 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
56 hr
= ITaskService_get_Connected(service
, &vbool
);
57 ok(hr
== S_OK
, "get_Connected error %#x\n", hr
);
58 ok(vbool
== VARIANT_FALSE
, "expected VARIANT_FALSE, got %d\n", vbool
);
60 hr
= ITaskService_get_TargetServer(service
, NULL
);
61 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
63 hr
= ITaskService_get_TargetServer(service
, &bstr
);
64 ok(hr
== HRESULT_FROM_WIN32(ERROR_ONLY_IF_CONNECTED
), "expected ERROR_ONLY_IF_CONNECTED, got %#x\n", hr
);
66 /* Win7 doesn't support UNC \\ prefix, but according to a user
67 * comment on MSDN Win8 supports both ways.
69 len
= sizeof(comp_name
)/sizeof(comp_name
[0]);
70 GetComputerNameW(comp_name
, &len
);
72 V_VT(&v_null
) = VT_NULL
;
74 V_VT(&v_comp
) = VT_BSTR
;
75 V_BSTR(&v_comp
) = SysAllocString(comp_name
);
77 hr
= ITaskService_Connect(service
, v_comp
, v_null
, v_null
, v_null
);
78 ok(hr
== S_OK
|| hr
== E_ACCESSDENIED
/* not an administrator */, "Connect error %#x\n", hr
);
79 was_connected
= hr
== S_OK
;
80 SysFreeString(V_BSTR(&v_comp
));
82 V_BSTR(&v_comp
) = SysAllocString(deadbeefW
);
83 hr
= ITaskService_Connect(service
, v_comp
, v_null
, v_null
, v_null
);
84 ok(hr
== HRESULT_FROM_WIN32(RPC_S_INVALID_NET_ADDR
) || hr
== HRESULT_FROM_WIN32(ERROR_BAD_NETPATH
) /* VM */,
85 "expected RPC_S_INVALID_NET_ADDR, got %#x\n", hr
);
86 SysFreeString(V_BSTR(&v_comp
));
89 hr
= ITaskService_get_Connected(service
, &vbool
);
90 ok(hr
== S_OK
, "get_Connected error %#x\n", hr
);
91 ok(vbool
== VARIANT_FALSE
|| (was_connected
&& vbool
== VARIANT_TRUE
),
92 "Connect shouldn't trash an existing connection, got %d (was connected %d)\n", vbool
, was_connected
);
94 V_BSTR(&v_comp
) = SysAllocString(empty
);
95 hr
= ITaskService_Connect(service
, v_comp
, v_null
, v_null
, v_null
);
96 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
97 SysFreeString(V_BSTR(&v_comp
));
99 V_BSTR(&v_comp
) = NULL
;
100 hr
= ITaskService_Connect(service
, v_comp
, v_null
, v_null
, v_null
);
101 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
103 hr
= ITaskService_Connect(service
, v_null
, v_null
, v_null
, v_null
);
104 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
107 hr
= ITaskService_get_Connected(service
, &vbool
);
108 ok(hr
== S_OK
, "get_Connected error %#x\n", hr
);
109 ok(vbool
== VARIANT_TRUE
, "expected VARIANT_TRUE, got %d\n", vbool
);
111 hr
= ITaskService_get_TargetServer(service
, &bstr
);
112 ok(hr
== S_OK
, "get_TargetServer error %#x\n", hr
);
113 ok(!lstrcmpW(comp_name
, bstr
), "compname %s != server name %s\n", wine_dbgstr_w(comp_name
), wine_dbgstr_w(bstr
));
116 ITaskService_Release(service
);
119 static void test_GetFolder(void)
121 static WCHAR dot
[] = { '.',0 };
122 static WCHAR empty
[] = { 0 };
123 static WCHAR slash
[] = { '/',0 };
124 static WCHAR bslash
[] = { '\\',0 };
125 static WCHAR Wine
[] = { '\\','W','i','n','e',0 };
126 static WCHAR Wine_Folder1
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1',0 };
127 static WCHAR Wine_Folder1_
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1','\\',0 };
128 static WCHAR Wine_Folder1_Folder2
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1','\\','F','o','l','d','e','r','2',0 };
129 static WCHAR Folder1_Folder2
[] = { '\\','F','o','l','d','e','r','1','\\','F','o','l','d','e','r','2',0 };
130 static const WCHAR Folder1
[] = { 'F','o','l','d','e','r','1',0 };
131 static const WCHAR Folder2
[] = { 'F','o','l','d','e','r','2',0 };
135 ITaskService
*service
;
136 ITaskFolder
*folder
, *subfolder
, *subfolder2
;
138 hr
= CoCreateInstance(&CLSID_TaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ITaskService
, (void **)&service
);
141 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr
);
145 hr
= ITaskService_GetFolder(service
, NULL
, &folder
);
146 ok(hr
== HRESULT_FROM_WIN32(ERROR_ONLY_IF_CONNECTED
), "expected ERROR_ONLY_IF_CONNECTED, got %#x\n", hr
);
148 V_VT(&v_null
) = VT_NULL
;
150 hr
= ITaskService_Connect(service
, v_null
, v_null
, v_null
, v_null
);
151 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
153 hr
= ITaskService_GetFolder(service
, slash
, &folder
);
155 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), "expected ERROR_INVALID_NAME, got %#x\n", hr
);
157 hr
= ITaskService_GetFolder(service
, dot
, &folder
);
159 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* win7 */,
160 "expected ERROR_INVALID_NAME, got %#x\n", hr
);
162 hr
= ITaskService_GetFolder(service
, bslash
, &folder
);
163 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
164 ITaskFolder_Release(folder
);
166 hr
= ITaskService_GetFolder(service
, NULL
, NULL
);
167 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
169 hr
= ITaskService_GetFolder(service
, empty
, &folder
);
170 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
171 ITaskFolder_Release(folder
);
173 hr
= ITaskService_GetFolder(service
, NULL
, &folder
);
174 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
176 hr
= ITaskFolder_get_Name(folder
, NULL
);
177 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
179 hr
= ITaskFolder_get_Name(folder
, &bstr
);
180 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
181 ok(!lstrcmpW(bstr
, bslash
), "expected '\\', got %s\n", wine_dbgstr_w(bstr
));
184 hr
= ITaskFolder_get_Path(folder
, NULL
);
185 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
187 hr
= ITaskFolder_get_Path(folder
, &bstr
);
188 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
189 ok(!lstrcmpW(bstr
, bslash
), "expected '\\', got %s\n", wine_dbgstr_w(bstr
));
192 hr
= ITaskFolder_CreateFolder(folder
, NULL
, v_null
, &subfolder
);
193 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
195 /* Just in case something was left from previous runs */
196 ITaskFolder_DeleteFolder(folder
, Wine_Folder1_Folder2
, 0);
197 ITaskFolder_DeleteFolder(folder
, Wine_Folder1
, 0);
198 ITaskFolder_DeleteFolder(folder
, Wine
, 0);
200 hr
= ITaskFolder_CreateFolder(folder
, slash
, v_null
, &subfolder
);
202 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), "expected ERROR_INVALID_NAME, got %#x\n", hr
);
204 hr
= ITaskService_GetFolder(service
, Wine_Folder1_Folder2
, &subfolder
);
205 ok(hr
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* win7 */,
206 "expected ERROR_PATH_NOT_FOUND, got %#x\n", hr
);
208 hr
= ITaskFolder_CreateFolder(folder
, bslash
, v_null
, &subfolder
);
210 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
212 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1_Folder2
, v_null
, &subfolder
);
213 ok(hr
== S_OK
, "CreateFolder error %#x\n", hr
);
214 ITaskFolder_Release(subfolder
);
216 hr
= ITaskFolder_CreateFolder(folder
, Wine
, v_null
, NULL
);
217 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
219 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1_
, v_null
, &subfolder
);
220 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), "expected ERROR_INVALID_NAME, got %#x\n", hr
);
222 hr
= ITaskFolder_CreateFolder(folder
, Wine
, v_null
, &subfolder
);
223 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
224 hr
= ITaskFolder_CreateFolder(folder
, Wine
+1, v_null
, &subfolder
);
225 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
226 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1
, v_null
, &subfolder
);
227 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
228 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1
+1, v_null
, &subfolder
);
229 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
230 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1_Folder2
, v_null
, &subfolder
);
231 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
232 hr
= ITaskFolder_CreateFolder(folder
, Wine_Folder1_Folder2
+1, v_null
, &subfolder
);
233 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
235 hr
= ITaskService_GetFolder(service
, Wine_Folder1_Folder2
, NULL
);
236 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
238 hr
= ITaskService_GetFolder(service
, Wine_Folder1_Folder2
, &subfolder
);
239 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
241 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
242 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
243 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
245 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
246 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
247 ok(!lstrcmpW(bstr
, Wine_Folder1_Folder2
), "expected \\Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
249 ITaskFolder_Release(subfolder
);
251 hr
= ITaskService_GetFolder(service
, Wine_Folder1_Folder2
+1, &subfolder
);
252 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
253 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
254 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
255 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
257 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
258 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
259 ok(!lstrcmpW(bstr
, Wine_Folder1_Folder2
+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
261 ITaskFolder_Release(subfolder
);
263 hr
= ITaskService_GetFolder(service
, Wine_Folder1
, &subfolder
);
264 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
265 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
266 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
267 ok(!lstrcmpW(bstr
, Folder1
), "expected Folder1, got %s\n", wine_dbgstr_w(bstr
));
269 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
270 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
271 ok(!lstrcmpW(bstr
, Wine_Folder1
), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr
));
273 ITaskFolder_Release(subfolder
);
275 hr
= ITaskService_GetFolder(service
, Wine
, &subfolder
);
276 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
277 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
278 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
279 ok(!lstrcmpW(bstr
, Wine
+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr
));
281 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
282 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
283 ok(!lstrcmpW(bstr
, Wine
), "expected \\Wine, got %s\n", wine_dbgstr_w(bstr
));
285 ITaskFolder_Release(subfolder
);
287 hr
= ITaskService_GetFolder(service
, Wine
+1, &subfolder
);
288 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
289 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
290 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
291 ok(!lstrcmpW(bstr
, Wine
+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr
));
293 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
294 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
295 ok(!lstrcmpW(bstr
, Wine
+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr
));
298 hr
= ITaskFolder_GetFolder(subfolder
, bslash
, &subfolder2
);
299 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), "expected ERROR_INVALID_NAME, got %#x\n", hr
);
301 hr
= ITaskFolder_GetFolder(subfolder
, NULL
, &subfolder2
);
302 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
304 hr
= ITaskFolder_GetFolder(subfolder
, empty
, &subfolder2
);
305 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
306 hr
= ITaskFolder_get_Name(subfolder2
, &bstr
);
307 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
308 ok(!lstrcmpW(bstr
, Wine
+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr
));
310 hr
= ITaskFolder_get_Path(subfolder2
, &bstr
);
311 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
312 ok(!lstrcmpW(bstr
, Wine
+1), "expected Wine, got %s\n", wine_dbgstr_w(bstr
));
314 ITaskFolder_Release(subfolder2
);
316 hr
= ITaskFolder_GetFolder(subfolder
, Folder1_Folder2
, &subfolder2
);
317 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
318 hr
= ITaskFolder_get_Name(subfolder2
, &bstr
);
319 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
320 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
322 hr
= ITaskFolder_get_Path(subfolder2
, &bstr
);
323 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
324 ok(!lstrcmpW(bstr
, Wine_Folder1_Folder2
+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
326 ITaskFolder_Release(subfolder2
);
328 hr
= ITaskFolder_GetFolder(subfolder
, Folder1_Folder2
+1, &subfolder2
);
329 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
331 hr
= ITaskFolder_get_Name(subfolder2
, &bstr
);
332 ok (hr
== S_OK
, "get_Name error %#x\n", hr
);
333 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
335 hr
= ITaskFolder_get_Path(subfolder2
, &bstr
);
336 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
337 ok(!lstrcmpW(bstr
, Wine_Folder1_Folder2
+1), "expected Wine\\Folder1\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
339 ITaskFolder_Release(subfolder2
);
341 ITaskFolder_Release(subfolder
);
343 hr
= ITaskFolder_DeleteFolder(folder
, Wine
, 0);
344 ok(hr
== HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY
), "expected ERROR_DIR_NOT_EMPTY, got %#x\n", hr
);
346 hr
= ITaskFolder_DeleteFolder(folder
, Wine_Folder1_Folder2
, 0);
347 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
348 hr
= ITaskFolder_DeleteFolder(folder
, Wine_Folder1
+1, 0);
349 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
350 hr
= ITaskFolder_DeleteFolder(folder
, Wine
+1, 0);
351 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
353 hr
= ITaskFolder_DeleteFolder(folder
, Wine
, 0);
354 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) || hr
== S_OK
/* win7 */, "expected ERROR_FILE_NOT_FOUND, got %#x\n", hr
);
356 hr
= ITaskFolder_DeleteFolder(folder
, NULL
, 0);
357 ok(hr
== E_ACCESSDENIED
|| hr
== E_INVALIDARG
/* Vista */, "expected E_ACCESSDENIED, got %#x\n", hr
);
359 hr
= ITaskFolder_DeleteFolder(folder
, empty
, 0);
360 ok(hr
== E_ACCESSDENIED
|| hr
== E_INVALIDARG
/* Vista */, "expected E_ACCESSDENIED, got %#x\n", hr
);
362 hr
= ITaskFolder_DeleteFolder(folder
, slash
, 0);
364 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), "expected ERROR_INVALID_NAME, got %#x\n", hr
);
366 ITaskFolder_Release(folder
);
367 ITaskService_Release(service
);
370 static void set_var(int vt
, VARIANT
*var
, LONG val
)
378 V_UI1(var
) = (BYTE
)val
;
383 V_UI2(var
) = (USHORT
)val
;
407 static void test_FolderCollection(void)
409 static WCHAR Wine
[] = { '\\','W','i','n','e',0 };
410 static WCHAR Wine_Folder1
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','1',0 };
411 static WCHAR Wine_Folder2
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','2',0 };
412 static WCHAR Wine_Folder3
[] = { '\\','W','i','n','e','\\','F','o','l','d','e','r','3',0 };
413 static const WCHAR Folder1
[] = { 'F','o','l','d','e','r','1',0 };
414 static const WCHAR Folder2
[] = { 'F','o','l','d','e','r','2',0 };
417 VARIANT v_null
, var
[3];
418 ITaskService
*service
;
419 ITaskFolder
*root
, *folder
, *subfolder
;
420 ITaskFolderCollection
*folders
;
422 IEnumVARIANT
*enumvar
;
426 static const int vt
[] = { VT_I1
, VT_I2
, VT_I4
, VT_I8
, VT_UI1
, VT_UI2
, VT_UI4
, VT_UI8
, VT_INT
, VT_UINT
};
428 hr
= CoCreateInstance(&CLSID_TaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ITaskService
, (void **)&service
);
431 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr
);
435 V_VT(&v_null
) = VT_NULL
;
437 hr
= ITaskService_Connect(service
, v_null
, v_null
, v_null
, v_null
);
438 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
440 hr
= ITaskService_GetFolder(service
, NULL
, &root
);
441 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
443 /* Just in case something was left from previous runs */
444 ITaskFolder_DeleteFolder(root
, Wine_Folder1
, 0);
445 ITaskFolder_DeleteFolder(root
, Wine_Folder2
, 0);
446 ITaskFolder_DeleteFolder(root
, Wine_Folder3
, 0);
447 ITaskFolder_DeleteFolder(root
, Wine
, 0);
449 hr
= ITaskFolder_CreateFolder(root
, Wine_Folder1
, v_null
, &subfolder
);
450 ok(hr
== S_OK
, "CreateFolder error %#x\n", hr
);
451 ITaskFolder_Release(subfolder
);
453 hr
= ITaskFolder_CreateFolder(root
, Wine_Folder2
, v_null
, &subfolder
);
454 ok(hr
== S_OK
, "CreateFolder error %#x\n", hr
);
455 ITaskFolder_Release(subfolder
);
457 hr
= ITaskFolder_GetFolder(root
, Wine
, &folder
);
458 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
460 hr
= ITaskFolder_GetFolders(folder
, 0, NULL
);
461 ok (hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
463 hr
= ITaskFolder_GetFolders(folder
, 0, &folders
);
464 ok(hr
== S_OK
, "GetFolders error %#x\n", hr
);
466 ITaskFolder_Release(folder
);
468 hr
= ITaskFolderCollection_get_Count(folders
, NULL
);
469 ok (hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
472 hr
= ITaskFolderCollection_get_Count(folders
, (LONG
*)&count
);
473 ok(hr
== S_OK
, "get_Count error %#x\n", hr
);
474 ok(count
== 2, "expected 2, got %d\n", count
);
476 hr
= ITaskFolder_CreateFolder(root
, Wine_Folder3
, v_null
, &subfolder
);
477 ok(hr
== S_OK
, "CreateFolder error %#x\n", hr
);
478 ITaskFolder_Release(subfolder
);
481 hr
= ITaskFolderCollection_get_Count(folders
, (LONG
*)&count
);
482 ok(hr
== S_OK
, "get_Count error %#x\n", hr
);
483 ok(count
== 2, "expected 2, got %d\n", count
);
485 set_var(VT_INT
, &idx
, 0);
486 hr
= ITaskFolderCollection_get_Item(folders
, idx
, NULL
);
487 ok (hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
489 for (i
= 0; i
< sizeof(vt
)/sizeof(vt
[0]); i
++)
491 set_var(vt
[i
], &idx
, 1);
492 hr
= ITaskFolderCollection_get_Item(folders
, idx
, &subfolder
);
493 ok(hr
== S_OK
, "get_Item(vt = %d) error %#x\n", vt
[i
], hr
);
494 ITaskFolder_Release(subfolder
);
497 for (i
= 0; i
<= count
; i
++)
501 hr
= ITaskFolderCollection_get_Item(folders
, idx
, &subfolder
);
504 ok (hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
507 ok(hr
== S_OK
, "get_Item error %#x\n", hr
);
509 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
510 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
511 is_first
= !lstrcmpW(bstr
, Wine_Folder1
);
513 ok(!lstrcmpW(bstr
, Wine_Folder1
), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr
));
515 ok(!lstrcmpW(bstr
, Wine_Folder2
), "expected \\Wine\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
518 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
519 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
521 ok(!lstrcmpW(bstr
, Folder1
), "expected Folder1, got %s\n", wine_dbgstr_w(bstr
));
523 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
525 ITaskFolder_Release(subfolder
);
527 V_VT(&idx
) = VT_BSTR
;
529 hr
= ITaskFolderCollection_get_Item(folders
, idx
, &subfolder
);
530 ok(hr
== S_OK
, "get_Item error %#x\n", hr
);
533 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
534 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
536 ok(!lstrcmpW(bstr
, Wine_Folder1
), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr
));
538 ok(!lstrcmpW(bstr
, Wine_Folder2
), "expected \\Wine\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
541 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
542 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
544 ok(!lstrcmpW(bstr
, Folder1
), "expected Folder1, got %s\n", wine_dbgstr_w(bstr
));
546 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
548 ITaskFolder_Release(subfolder
);
553 hr
= ITaskFolderCollection_get_Item(folders
, idx
, &subfolder
);
554 ok (hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
556 hr
= ITaskFolderCollection_QueryInterface(folders
, &IID_IEnumVARIANT
, (void **)&enumvar
);
557 ok(hr
== E_NOINTERFACE
, "expected E_NOINTERFACE, got %#x\n", hr
);
558 hr
= ITaskFolderCollection_QueryInterface(folders
, &IID_IEnumUnknown
, (void **)&enumvar
);
559 ok(hr
== E_NOINTERFACE
, "expected E_NOINTERFACE, got %#x\n", hr
);
561 hr
= ITaskFolderCollection_get__NewEnum(folders
, NULL
);
562 ok (hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
564 hr
= ITaskFolderCollection_get__NewEnum(folders
, &unknown
);
565 ok(hr
== S_OK
, "get__NewEnum error %#x\n", hr
);
566 hr
= IUnknown_QueryInterface(unknown
, &IID_IEnumUnknown
, (void **)&enumvar
);
567 ok(hr
== E_NOINTERFACE
, "expected E_NOINTERFACE, got %#x\n", hr
);
568 hr
= IUnknown_QueryInterface(unknown
, &IID_IEnumVARIANT
, (void **)&enumvar
);
569 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
570 IEnumVARIANT_Release(enumvar
);
572 hr
= IUnknown_QueryInterface(unknown
, &IID_IUnknown
, (void **)&enumvar
);
573 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
575 hr
= IEnumVARIANT_Skip(enumvar
, 0);
576 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
577 hr
= IEnumVARIANT_Skip(enumvar
, 2);
578 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
579 hr
= IEnumVARIANT_Skip(enumvar
, 1);
580 ok(hr
== S_FALSE
, "expected S_FALSE, got %#x\n", hr
);
582 hr
= IEnumVARIANT_Reset(enumvar
);
583 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
586 hr
= IEnumVARIANT_Next(enumvar
, 1, NULL
, &count
);
587 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
589 memset(var
, 0, sizeof(var
));
591 hr
= IEnumVARIANT_Next(enumvar
, 1, var
, &count
);
592 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
593 ok(count
== 1, "expected 1, got %d\n", count
);
594 hr
= ITaskFolder_get_Path((ITaskFolder
*)V_DISPATCH(&var
[0]), &bstr
);
595 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
596 is_first
= !lstrcmpW(bstr
, Wine_Folder1
);
598 ok(!lstrcmpW(bstr
, Wine_Folder1
), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr
));
600 ok(!lstrcmpW(bstr
, Wine_Folder2
), "expected \\Wine\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
602 hr
= ITaskFolder_get_Name((ITaskFolder
*)V_DISPATCH(&var
[0]), &bstr
);
603 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
605 ok(!lstrcmpW(bstr
, Folder1
), "expected Folder1, got %s\n", wine_dbgstr_w(bstr
));
607 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
608 IDispatch_Release(V_DISPATCH(&var
[0]));
610 memset(var
, 0, sizeof(var
));
612 hr
= IEnumVARIANT_Next(enumvar
, 1, var
, &count
);
613 ok(hr
== S_FALSE
, "expected S_FALSE, got %#x\n", hr
);
614 ok(count
== 0, "expected 0, got %d\n", count
);
617 hr
= IEnumVARIANT_Next(enumvar
, 1, NULL
, &count
);
618 ok(hr
== S_FALSE
, "expected S_FALSE, got %#x\n", hr
);
619 ok(count
== 0, "expected 0, got %d\n", count
);
621 hr
= IEnumVARIANT_Reset(enumvar
);
622 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
624 memset(var
, 0, sizeof(var
));
626 hr
= IEnumVARIANT_Next(enumvar
, 3, var
, &count
);
627 ok(hr
== S_FALSE
, "expected S_FALSE, got %#x\n", hr
);
628 ok(count
== 2, "expected 2, got %d\n", count
);
629 ok(V_VT(&var
[0]) == VT_DISPATCH
, "expected VT_DISPATCH, got %d\n", V_VT(&var
[0]));
630 ok(V_VT(&var
[1]) == VT_DISPATCH
, "expected VT_DISPATCH, got %d\n", V_VT(&var
[1]));
631 IEnumVARIANT_Release(enumvar
);
633 for (i
= 0; i
< count
; i
++)
635 hr
= IDispatch_QueryInterface(V_DISPATCH(&var
[i
]), &IID_ITaskFolder
, (void **)&subfolder
);
636 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
638 hr
= ITaskFolder_get_Path(subfolder
, &bstr
);
639 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
640 is_first
= !lstrcmpW(bstr
, Wine_Folder1
);
642 ok(!lstrcmpW(bstr
, Wine_Folder1
), "expected \\Wine\\Folder1, got %s\n", wine_dbgstr_w(bstr
));
644 ok(!lstrcmpW(bstr
, Wine_Folder2
), "expected \\Wine\\Folder2, got %s\n", wine_dbgstr_w(bstr
));
647 hr
= ITaskFolder_get_Name(subfolder
, &bstr
);
648 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
650 ok(!lstrcmpW(bstr
, Folder1
), "expected Folder1, got %s\n", wine_dbgstr_w(bstr
));
652 ok(!lstrcmpW(bstr
, Folder2
), "expected Folder2, got %s\n", wine_dbgstr_w(bstr
));
654 ITaskFolder_Release(subfolder
);
657 IDispatch_Release(V_DISPATCH(&var
[0]));
658 IDispatch_Release(V_DISPATCH(&var
[1]));
660 ITaskFolderCollection_Release(folders
);
662 hr
= ITaskFolder_DeleteFolder(root
, Wine_Folder1
, 0);
663 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
664 hr
= ITaskFolder_DeleteFolder(root
, Wine_Folder2
, 0);
665 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
666 hr
= ITaskFolder_DeleteFolder(root
, Wine_Folder3
, 0);
667 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
668 hr
= ITaskFolder_DeleteFolder(root
, Wine
, 0);
669 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
671 ITaskFolder_Release(root
);
672 ITaskService_Release(service
);
675 static void test_GetTask(void)
677 static WCHAR Wine
[] = { '\\','W','i','n','e',0 };
678 static WCHAR Wine_Task1
[] = { '\\','W','i','n','e','\\','T','a','s','k','1',0 };
679 static WCHAR Wine_Task2
[] = { '\\','W','i','n','e','\\','T','a','s','k','2',0 };
680 static WCHAR Task1
[] = { 'T','a','s','k','1',0 };
681 static WCHAR Task2
[] = { 'T','a','s','k','2',0 };
682 static const char xml1
[] =
683 "<?xml version=\"1.0\"?>\n"
684 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
685 " <RegistrationInfo>\n"
686 " <Description>\"Task1\"</Description>\n"
687 " </RegistrationInfo>\n"
689 " <Enabled>false</Enabled>\n"
690 " <Hidden>false</Hidden>\n"
694 " <Command>\"task1.exe\"</Command>\n"
698 static const char xml2
[] =
699 "<?xml version=\"1.0\"?>\n"
700 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
701 " <RegistrationInfo>\n"
702 " <Description>\"Task2\"</Description>\n"
703 " </RegistrationInfo>\n"
705 " <Enabled>true</Enabled>\n"
706 " <Hidden>true</Hidden>\n"
710 " <Command>\"task2.exe\"</Command>\n"
717 } create_new_task
[] =
720 { TASK_CREATE
, S_OK
},
721 { TASK_UPDATE
, 0x80070002 /* HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) */ },
722 { TASK_CREATE
| TASK_UPDATE
, S_OK
}
727 } open_existing_task
[] =
729 { 0, 0x800700b7 /* HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) */ },
730 { TASK_CREATE
, 0x800700b7 /* HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) */ },
731 { TASK_UPDATE
, S_OK
},
732 { TASK_CREATE
| TASK_UPDATE
, S_OK
}
734 WCHAR xmlW
[sizeof(xml1
)];
740 ITaskService
*service
;
741 ITaskFolder
*root
, *folder
;
742 IRegisteredTask
*task1
, *task2
;
746 hr
= CoCreateInstance(&CLSID_TaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ITaskService
, (void **)&service
);
749 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr
);
753 V_VT(&v_null
) = VT_NULL
;
755 hr
= ITaskService_Connect(service
, v_null
, v_null
, v_null
, v_null
);
756 ok(hr
== S_OK
, "Connect error %#x\n", hr
);
758 hr
= ITaskService_GetFolder(service
, NULL
, &root
);
759 ok(hr
== S_OK
, "GetFolder error %#x\n", hr
);
761 /* Just in case something was left from previous runs */
762 ITaskFolder_DeleteTask(root
, Wine_Task1
, 0);
763 ITaskFolder_DeleteTask(root
, Wine_Task2
, 0);
764 ITaskFolder_DeleteFolder(root
, Wine
, 0);
766 hr
= ITaskFolder_GetTask(root
, Wine_Task1
, &task1
);
767 ok(hr
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* win7 */,
768 "expected ERROR_PATH_NOT_FOUND, got %#x\n", hr
);
770 hr
= ITaskFolder_CreateFolder(root
, Wine
, v_null
, &folder
);
771 ok(hr
== S_OK
, "CreateFolder error %#x\n", hr
);
773 hr
= ITaskFolder_GetTask(root
, Wine
, &task1
);
774 ok(hr
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* win7 */,
775 "expected ERROR_PATH_NOT_FOUND, got %#x\n", hr
);
777 MultiByteToWideChar(CP_ACP
, 0, xml1
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
779 for (i
= 0; i
< sizeof(create_new_task
)/sizeof(create_new_task
[0]); i
++)
781 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, create_new_task
[i
].flags
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task1
);
782 ok(hr
== create_new_task
[i
].hr
, "%d: expected %#x, got %#x\n", i
, create_new_task
[i
].hr
, hr
);
785 hr
= ITaskFolder_DeleteTask(root
, Wine_Task1
, 0);
786 ok(hr
== S_OK
, "DeleteTask error %#x\n", hr
);
787 IRegisteredTask_Release(task1
);
791 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, NULL
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, NULL
);
792 ok(hr
== HRESULT_FROM_WIN32(RPC_X_NULL_REF_POINTER
), "expected RPC_X_NULL_REF_POINTER, got %#x\n", hr
);
794 hr
= ITaskFolder_RegisterTask(root
, Wine
, xmlW
, TASK_VALIDATE_ONLY
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, NULL
);
795 ok(hr
== S_OK
, "RegisterTask error %#x\n", hr
);
797 hr
= ITaskFolder_RegisterTask(root
, Wine
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, NULL
);
799 ok(hr
== HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED
) || broken(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
)) /* Vista */, "expected ERROR_ACCESS_DENIED, got %#x\n", hr
);
801 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, NULL
);
802 ok(hr
== S_OK
, "RegisterTask error %#x\n", hr
);
804 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task1
);
805 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
807 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, 0, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, NULL
);
808 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
810 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, TASK_CREATE_OR_UPDATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task1
);
811 ok(hr
== S_OK
, "RegisterTask error %#x\n", hr
);
813 for (i
= 0; i
< sizeof(open_existing_task
)/sizeof(open_existing_task
[0]); i
++)
815 hr
= ITaskFolder_RegisterTask(root
, Wine_Task1
, xmlW
, open_existing_task
[i
].flags
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task2
);
816 ok(hr
== open_existing_task
[i
].hr
, "%d: expected %#x, got %#x\n", i
, open_existing_task
[i
].hr
, hr
);
818 IRegisteredTask_Release(task2
);
821 hr
= IRegisteredTask_get_Name(task1
, NULL
);
822 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
824 hr
= IRegisteredTask_get_Name(task1
, &bstr
);
825 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
826 ok(!lstrcmpW(bstr
, Task1
), "expected Task1, got %s\n", wine_dbgstr_w(bstr
));
828 hr
= IRegisteredTask_get_Path(task1
, &bstr
);
829 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
830 ok(!lstrcmpW(bstr
, Wine_Task1
), "expected \\Wine\\Task1, got %s\n", wine_dbgstr_w(bstr
));
832 hr
= IRegisteredTask_get_State(task1
, &state
);
833 ok(hr
== S_OK
, "get_State error %#x\n", hr
);
834 ok(state
== TASK_STATE_DISABLED
, "expected TASK_STATE_DISABLED, got %d\n", state
);
835 hr
= IRegisteredTask_get_Enabled(task1
, &vbool
);
836 ok(hr
== S_OK
, "get_Enabled error %#x\n", hr
);
837 ok(vbool
== VARIANT_FALSE
, "expected VARIANT_FALSE, got %d\n", vbool
);
839 IRegisteredTask_Release(task1
);
841 hr
= ITaskFolder_RegisterTask(folder
, Task1
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task2
);
842 ok(hr
== HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS
), "expected ERROR_ALREADY_EXISTS, got %#x\n", hr
);
844 MultiByteToWideChar(CP_ACP
, 0, xml2
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
846 hr
= ITaskFolder_RegisterTask(folder
, Task2
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task2
);
847 ok(hr
== S_OK
, "RegisterTask error %#x\n", hr
);
849 hr
= IRegisteredTask_get_Name(task2
, &bstr
);
850 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
851 ok(!lstrcmpW(bstr
, Task2
), "expected Task2, got %s\n", wine_dbgstr_w(bstr
));
853 hr
= IRegisteredTask_get_Path(task2
, &bstr
);
854 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
855 ok(!lstrcmpW(bstr
, Wine_Task2
), "expected \\Wine\\Task2, got %s\n", wine_dbgstr_w(bstr
));
857 hr
= IRegisteredTask_get_State(task2
, &state
);
858 ok(hr
== S_OK
, "get_State error %#x\n", hr
);
860 ok(state
== TASK_STATE_READY
, "expected TASK_STATE_READY, got %d\n", state
);
861 hr
= IRegisteredTask_get_Enabled(task2
, &vbool
);
862 ok(hr
== S_OK
, "get_Enabled error %#x\n", hr
);
864 ok(vbool
== VARIANT_TRUE
, "expected VARIANT_TRUE, got %d\n", vbool
);
866 IRegisteredTask_Release(task2
);
868 hr
= ITaskFolder_GetTask(root
, NULL
, &task1
);
869 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
871 hr
= ITaskFolder_GetTask(root
, Wine_Task1
, NULL
);
872 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
874 hr
= ITaskFolder_GetTask(root
, Wine_Task1
, &task1
);
875 ok(hr
== S_OK
, "GetTask error %#x\n", hr
);
877 hr
= IRegisteredTask_get_Name(task1
, &bstr
);
878 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
879 ok(!lstrcmpW(bstr
, Task1
), "expected Task1, got %s\n", wine_dbgstr_w(bstr
));
881 hr
= IRegisteredTask_get_Path(task1
, &bstr
);
882 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
883 ok(!lstrcmpW(bstr
, Wine_Task1
), "expected \\Wine\\Task1, got %s\n", wine_dbgstr_w(bstr
));
885 hr
= IRegisteredTask_get_State(task1
, &state
);
886 ok(hr
== S_OK
, "get_State error %#x\n", hr
);
887 ok(state
== TASK_STATE_DISABLED
, "expected TASK_STATE_DISABLED, got %d\n", state
);
888 hr
= IRegisteredTask_get_Enabled(task1
, &vbool
);
889 ok(hr
== S_OK
, "get_Enabled error %#x\n", hr
);
890 ok(vbool
== VARIANT_FALSE
, "expected VARIANT_FALSE, got %d\n", vbool
);
892 hr
= IRegisteredTask_put_Enabled(task1
, VARIANT_TRUE
);
893 ok(hr
== S_OK
, "put_Enabled error %#x\n", hr
);
894 hr
= IRegisteredTask_get_State(task1
, &state
);
895 ok(hr
== S_OK
, "get_State error %#x\n", hr
);
897 ok(state
== TASK_STATE_READY
, "expected TASK_STATE_READY, got %d\n", state
);
898 hr
= IRegisteredTask_get_Enabled(task1
, &vbool
);
899 ok(hr
== S_OK
, "get_Enabled error %#x\n", hr
);
901 ok(vbool
== VARIANT_TRUE
, "expected VARIANT_TRUE, got %d\n", vbool
);
903 IRegisteredTask_Release(task1
);
905 hr
= ITaskFolder_GetTask(folder
, Task2
, &task2
);
906 ok(hr
== S_OK
, "GetTask error %#x\n", hr
);
908 hr
= IRegisteredTask_get_Name(task2
, &bstr
);
909 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
910 ok(!lstrcmpW(bstr
, Task2
), "expected Task2, got %s\n", wine_dbgstr_w(bstr
));
912 hr
= IRegisteredTask_get_Path(task2
, &bstr
);
913 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
914 ok(!lstrcmpW(bstr
, Wine_Task2
), "expected \\Wine\\Task2, got %s\n", wine_dbgstr_w(bstr
));
916 hr
= IRegisteredTask_get_State(task2
, &state
);
917 ok(hr
== S_OK
, "get_State error %#x\n", hr
);
919 ok(state
== TASK_STATE_READY
, "expected TASK_STATE_READY, got %d\n", state
);
920 hr
= IRegisteredTask_get_Enabled(task2
, &vbool
);
921 ok(hr
== S_OK
, "get_Enabled error %#x\n", hr
);
923 ok(vbool
== VARIANT_TRUE
, "expected VARIANT_TRUE, got %d\n", vbool
);
925 hr
= IRegisteredTask_get_State(task2
, NULL
);
926 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
927 hr
= IRegisteredTask_get_Enabled(task2
, NULL
);
928 ok(hr
== E_POINTER
, "expected E_POINTER, got %#x\n", hr
);
930 IRegisteredTask_Release(task2
);
932 hr
= ITaskFolder_DeleteTask(folder
, NULL
, 0);
934 ok(hr
== HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY
), "expected ERROR_DIR_NOT_EMPTY, got %#x\n", hr
);
936 hr
= ITaskFolder_DeleteTask(root
, Wine_Task1
, 0);
937 ok(hr
== S_OK
, "DeleteTask error %#x\n", hr
);
938 hr
= ITaskFolder_DeleteTask(folder
, Task2
, 0);
939 ok(hr
== S_OK
, "DeleteTask error %#x\n", hr
);
941 hr
= ITaskFolder_DeleteTask(folder
, Task2
, 0);
942 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) || hr
== S_OK
/* win7 */, "expected ERROR_FILE_NOT_FOUND, got %#x\n", hr
);
944 hr
= ITaskFolder_RegisterTask(root
, NULL
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task1
);
945 ok(hr
== S_OK
, "RegisterTask error %#x\n", hr
);
947 hr
= IRegisteredTask_get_Name(task1
, &bstr
);
948 ok(hr
== S_OK
, "get_Name error %#x\n", hr
);
949 hr
= IIDFromString(bstr
, &iid
);
950 ok(hr
== S_OK
, "IIDFromString error %#x\n", hr
);
952 IRegisteredTask_Release(task1
);
954 hr
= ITaskFolder_DeleteTask(root
, bstr
, 0);
955 ok(hr
== S_OK
, "DeleteTask error %#x\n", hr
);
958 hr
= ITaskFolder_RegisterTask(folder
, NULL
, xmlW
, TASK_CREATE
, v_null
, v_null
, TASK_LOGON_NONE
, v_null
, &task1
);
959 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
961 ITaskFolder_Release(folder
);
963 hr
= ITaskFolder_DeleteFolder(root
, Wine
, 0);
964 ok(hr
== S_OK
, "DeleteFolder error %#x\n", hr
);
966 ITaskFolder_Release(root
);
967 ITaskService_Release(service
);
972 WCHAR restart_interval
[20];
973 WCHAR execution_time_limit
[20];
974 WCHAR delete_expired_task_after
[20];
977 TASK_INSTANCES_POLICY policy
;
978 TASK_COMPATIBILITY compatibility
;
979 VARIANT_BOOL allow_on_demand_start
;
980 VARIANT_BOOL stop_if_going_on_batteries
;
981 VARIANT_BOOL disallow_start_if_on_batteries
;
982 VARIANT_BOOL allow_hard_terminate
;
983 VARIANT_BOOL start_when_available
;
984 VARIANT_BOOL run_only_if_network_available
;
985 VARIANT_BOOL enabled
;
987 VARIANT_BOOL run_only_if_idle
;
988 VARIANT_BOOL wake_to_run
;
991 /* test the version 1 compatibility settings */
992 static void test_settings_v1(ITaskDefinition
*taskdef
, struct settings
*test
, struct settings
*def
)
999 TASK_INSTANCES_POLICY policy
;
1000 TASK_COMPATIBILITY compat
;
1002 hr
= ITaskDefinition_get_Settings(taskdef
, &set
);
1003 ok(hr
== S_OK
, "get_Settings error %#x\n", hr
);
1005 hr
= ITaskSettings_get_AllowDemandStart(set
, &vbool
);
1006 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1007 ok(vbool
== def
->allow_on_demand_start
, "expected %d, got %d\n", def
->allow_on_demand_start
, vbool
);
1009 hr
= ITaskSettings_get_RestartInterval(set
, &bstr
);
1010 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1011 if (!def
->restart_interval
[0])
1012 ok(bstr
== NULL
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1015 ok(!lstrcmpW(bstr
, def
->restart_interval
), "expected %s, got %s\n", wine_dbgstr_w(def
->restart_interval
), wine_dbgstr_w(bstr
));
1016 SysFreeString(bstr
);
1019 hr
= ITaskSettings_get_RestartCount(set
, &vint
);
1020 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1021 ok(vint
== def
->restart_count
, "expected %d, got %d\n", def
->restart_count
, vint
);
1023 hr
= ITaskSettings_get_MultipleInstances(set
, &policy
);
1024 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1025 ok(policy
== def
->policy
, "expected %d, got %d\n", def
->policy
, policy
);
1027 hr
= ITaskSettings_get_StopIfGoingOnBatteries(set
, &vbool
);
1028 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1029 ok(vbool
== test
->stop_if_going_on_batteries
, "expected %d, got %d\n", test
->stop_if_going_on_batteries
, vbool
);
1031 hr
= ITaskSettings_get_DisallowStartIfOnBatteries(set
, &vbool
);
1032 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1033 ok(vbool
== test
->disallow_start_if_on_batteries
, "expected %d, got %d\n", test
->disallow_start_if_on_batteries
, vbool
);
1035 hr
= ITaskSettings_get_AllowHardTerminate(set
, &vbool
);
1036 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1037 ok(vbool
== def
->allow_hard_terminate
, "expected %d, got %d\n", def
->allow_hard_terminate
, vbool
);
1039 hr
= ITaskSettings_get_StartWhenAvailable(set
, &vbool
);
1040 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1041 ok(vbool
== def
->start_when_available
, "expected %d, got %d\n", def
->start_when_available
, vbool
);
1043 hr
= ITaskSettings_get_RunOnlyIfNetworkAvailable(set
, &vbool
);
1044 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1045 ok(vbool
== def
->run_only_if_network_available
, "expected %d, got %d\n", def
->run_only_if_network_available
, vbool
);
1047 hr
= ITaskSettings_get_ExecutionTimeLimit(set
, &bstr
);
1048 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1049 if (!test
->execution_time_limit
[0])
1050 ok(bstr
== NULL
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1052 ok(!lstrcmpW(bstr
, test
->execution_time_limit
), "expected %s, got %s\n", wine_dbgstr_w(test
->execution_time_limit
), wine_dbgstr_w(bstr
));
1054 hr
= ITaskSettings_get_Enabled(set
, &vbool
);
1055 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1056 ok(vbool
== test
->enabled
, "expected %d, got %d\n", test
->enabled
, vbool
);
1058 hr
= ITaskSettings_get_DeleteExpiredTaskAfter(set
, &bstr
);
1059 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1060 if (!test
->delete_expired_task_after
[0])
1061 ok(bstr
== NULL
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1064 ok(!lstrcmpW(bstr
, test
->delete_expired_task_after
), "expected %s, got %s\n", wine_dbgstr_w(test
->delete_expired_task_after
), wine_dbgstr_w(bstr
));
1065 SysFreeString(bstr
);
1068 hr
= ITaskSettings_get_Priority(set
, &vint
);
1069 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1070 ok(vint
== test
->priority
, "expected %d, got %d\n", test
->priority
, vint
);
1072 hr
= ITaskSettings_get_Compatibility(set
, &compat
);
1073 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1074 ok(compat
== test
->compatibility
, "expected %d, got %d\n", test
->compatibility
, compat
);
1076 hr
= ITaskSettings_get_Hidden(set
, &vbool
);
1077 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1078 ok(vbool
== test
->hidden
, "expected %d, got %d\n", test
->hidden
, vbool
);
1080 hr
= ITaskSettings_get_RunOnlyIfIdle(set
, &vbool
);
1081 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1082 ok(vbool
== test
->run_only_if_idle
, "expected %d, got %d\n", test
->run_only_if_idle
, vbool
);
1084 hr
= ITaskSettings_get_WakeToRun(set
, &vbool
);
1085 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1086 ok(vbool
== test
->wake_to_run
, "expected %d, got %d\n", test
->wake_to_run
, vbool
);
1088 /* FIXME: test IIdleSettings and INetworkSettings */
1090 ITaskSettings_Release(set
);
1093 static void change_settings(ITaskDefinition
*taskdef
, struct settings
*test
)
1097 ITriggerCollection
*triggers
;
1098 IPrincipal
*principal
;
1099 IActionCollection
*actions
;
1101 hr
= ITaskDefinition_get_Settings(taskdef
, &set
);
1102 ok(hr
== S_OK
, "get_Settings error %#x\n", hr
);
1104 if (!test
->restart_interval
[0])
1105 hr
= ITaskSettings_put_RestartInterval(set
, NULL
);
1107 hr
= ITaskSettings_put_RestartInterval(set
, test
->restart_interval
);
1108 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1110 hr
= ITaskSettings_put_RestartCount(set
, test
->restart_count
);
1111 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1113 hr
= ITaskSettings_put_MultipleInstances(set
, test
->policy
);
1114 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1116 hr
= ITaskSettings_put_StopIfGoingOnBatteries(set
, test
->stop_if_going_on_batteries
);
1117 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1119 hr
= ITaskSettings_put_DisallowStartIfOnBatteries(set
, test
->disallow_start_if_on_batteries
);
1120 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1122 hr
= ITaskSettings_put_AllowHardTerminate(set
, test
->allow_hard_terminate
);
1123 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1125 hr
= ITaskSettings_put_StartWhenAvailable(set
, test
->start_when_available
);
1126 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1128 hr
= ITaskSettings_put_RunOnlyIfNetworkAvailable(set
, test
->run_only_if_network_available
);
1129 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1131 if (!test
->execution_time_limit
[0])
1132 hr
= ITaskSettings_put_ExecutionTimeLimit(set
, NULL
);
1134 hr
= ITaskSettings_put_ExecutionTimeLimit(set
, test
->execution_time_limit
);
1135 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1137 hr
= ITaskSettings_put_Enabled(set
, test
->enabled
);
1138 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1140 if (!test
->delete_expired_task_after
[0])
1141 hr
= ITaskSettings_put_DeleteExpiredTaskAfter(set
, NULL
);
1143 hr
= ITaskSettings_put_DeleteExpiredTaskAfter(set
, test
->delete_expired_task_after
);
1144 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1146 hr
= ITaskSettings_put_Priority(set
, test
->priority
);
1147 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1149 hr
= ITaskSettings_put_Compatibility(set
, test
->compatibility
);
1150 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1152 hr
= ITaskSettings_put_Hidden(set
, test
->hidden
);
1153 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1155 hr
= ITaskSettings_put_RunOnlyIfIdle(set
, test
->run_only_if_idle
);
1156 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1158 hr
= ITaskSettings_put_WakeToRun(set
, test
->wake_to_run
);
1159 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1161 hr
= ITaskSettings_put_AllowDemandStart(set
, test
->allow_on_demand_start
);
1162 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1165 hr
= ITaskDefinition_get_Triggers(taskdef
, &triggers
);
1166 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1167 ok(triggers
!= NULL
, "triggers not set\n");
1169 hr
= ITaskDefinition_put_Triggers(taskdef
, triggers
);
1170 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1171 if (triggers
) ITriggerCollection_Release(triggers
);
1174 hr
= ITaskDefinition_get_Principal(taskdef
, &principal
);
1175 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1176 ok(principal
!= NULL
, "principal not set\n");
1178 hr
= ITaskDefinition_put_Principal(taskdef
, principal
);
1179 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1180 if (principal
) IPrincipal_Release(principal
);
1183 hr
= ITaskDefinition_get_Actions(taskdef
, &actions
);
1184 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1185 ok(actions
!= NULL
, "actions not set\n");
1187 hr
= ITaskDefinition_put_Actions(taskdef
, actions
);
1188 ok(hr
== S_OK
, "expected S_OK, got %#x\n", hr
);
1189 if (actions
) IActionCollection_Release(actions
);
1191 /* FIXME: set IIdleSettings and INetworkSettings */
1193 ITaskSettings_Release(set
);
1196 static void test_daily_trigger(ITrigger
*trigger
)
1198 static const WCHAR startW
[] =
1199 {'2','0','0','4','-','0','1','-','0','1','T','0','0',':','0','0',':','0','0',0};
1200 static const WCHAR start2W
[] =
1201 {'2','0','0','4','-','0','1','-','0','1','T','0','0',':','0','0',':','0','0','Z',0};
1202 static const WCHAR start3W
[] =
1203 {'2','0','0','4','-','0','1','-','0','1','T','0','0',':','0','0',':','0','0','+','0','1',':','0','0',0};
1204 static const WCHAR start4W
[] =
1205 {'2','0','0','4','.','0','1','.','0','1','T','0','0','.','0','0','.','0','0',0};
1206 static const WCHAR start5W
[] =
1207 {'9','9','9','9','-','9','9','-','9','9','T','9','9',':','9','9',':','9','9',0};
1208 static const WCHAR start6W
[] =
1209 {'i','n','v','a','l','i','d',0};
1224 IDailyTrigger
*daily_trigger
;
1225 BSTR start_boundary
;
1226 VARIANT_BOOL enabled
;
1231 hr
= ITrigger_QueryInterface(trigger
, &IID_IDailyTrigger
, (void**)&daily_trigger
);
1232 ok(hr
== S_OK
, "Could not get IDailyTrigger iface: %08x\n", hr
);
1235 hr
= IDailyTrigger_get_DaysInterval(daily_trigger
, &interval
);
1236 ok(hr
== S_OK
, "get_DaysInterval failed: %08x\n", hr
);
1237 ok(interval
== 1, "interval = %d\n", interval
);
1239 hr
= IDailyTrigger_put_DaysInterval(daily_trigger
, -2);
1240 ok(hr
== E_INVALIDARG
, "put_DaysInterval failed: %08x\n", hr
);
1241 hr
= IDailyTrigger_put_DaysInterval(daily_trigger
, 0);
1242 ok(hr
== E_INVALIDARG
, "put_DaysInterval failed: %08x\n", hr
);
1245 hr
= IDailyTrigger_get_DaysInterval(daily_trigger
, &interval
);
1246 ok(hr
== S_OK
, "get_DaysInterval failed: %08x\n", hr
);
1247 ok(interval
== 1, "interval = %d\n", interval
);
1249 hr
= IDailyTrigger_put_DaysInterval(daily_trigger
, 2);
1250 ok(hr
== S_OK
, "put_DaysInterval failed: %08x\n", hr
);
1253 hr
= IDailyTrigger_get_DaysInterval(daily_trigger
, &interval
);
1254 ok(hr
== S_OK
, "get_DaysInterval failed: %08x\n", hr
);
1255 ok(interval
== 2, "interval = %d\n", interval
);
1257 hr
= IDailyTrigger_get_StartBoundary(daily_trigger
, NULL
);
1258 ok(hr
== E_POINTER
, "get_StartBoundary failed: %08x\n", hr
);
1260 start_boundary
= (BSTR
)0xdeadbeef;
1261 hr
= IDailyTrigger_get_StartBoundary(daily_trigger
, &start_boundary
);
1262 ok(hr
== S_OK
, "get_StartBoundary failed: %08x\n", hr
);
1263 ok(start_boundary
== NULL
, "start_boundary not set\n");
1265 for (i
= 0; i
< sizeof(start_test
)/sizeof(start_test
[0]); i
++)
1267 start_boundary
= SysAllocString(start_test
[i
].str
);
1268 hr
= IDailyTrigger_put_StartBoundary(daily_trigger
, start_boundary
);
1269 ok(hr
== start_test
[i
].hr
, "%u: got %08x expected %08x\n", i
, hr
, start_test
[i
].hr
);
1270 SysFreeString(start_boundary
);
1273 start_boundary
= NULL
;
1274 hr
= IDailyTrigger_get_StartBoundary(daily_trigger
, &start_boundary
);
1275 ok(hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1276 ok(start_boundary
!= NULL
, "start_boundary not set\n");
1277 ok(!lstrcmpW(start_boundary
, start_test
[i
].str
), "%u: got %s\n", i
, wine_dbgstr_w(start_boundary
));
1278 SysFreeString(start_boundary
);
1282 hr
= IDailyTrigger_put_StartBoundary(daily_trigger
, NULL
);
1283 ok(hr
== S_OK
, "put_StartBoundary failed: %08x\n", hr
);
1285 hr
= IDailyTrigger_get_Enabled(daily_trigger
, NULL
);
1286 ok(hr
== E_POINTER
, "get_Enabled failed: %08x\n", hr
);
1288 enabled
= VARIANT_FALSE
;
1289 hr
= IDailyTrigger_get_Enabled(daily_trigger
, &enabled
);
1290 ok(hr
== S_OK
, "get_Enabled failed: %08x\n", hr
);
1291 ok(enabled
== VARIANT_TRUE
, "got %d\n", enabled
);
1293 hr
= IDailyTrigger_put_Enabled(daily_trigger
, VARIANT_FALSE
);
1294 ok(hr
== S_OK
, "put_Enabled failed: %08x\n", hr
);
1296 enabled
= VARIANT_TRUE
;
1297 hr
= IDailyTrigger_get_Enabled(daily_trigger
, &enabled
);
1298 ok(hr
== S_OK
, "get_Enabled failed: %08x\n", hr
);
1299 ok(enabled
== VARIANT_FALSE
, "got %d\n", enabled
);
1301 IDailyTrigger_Release(daily_trigger
);
1304 static void create_action(ITaskDefinition
*taskdef
)
1306 static WCHAR task1_exe
[] = { 't','a','s','k','1','.','e','x','e',0 };
1307 static WCHAR workdir
[] = { 'w','o','r','k','d','i','r',0 };
1308 static WCHAR args
[] = { 'a','r','g','u','m','e','n','s',0 };
1309 static WCHAR comment
[] = { 'c','o','m','m','e','n','t',0 };
1311 IActionCollection
*actions
;
1313 IExecAction
*exec_action
;
1314 TASK_ACTION_TYPE type
;
1317 hr
= ITaskDefinition_get_Actions(taskdef
, NULL
);
1318 ok(hr
== E_POINTER
, "got %#x\n", hr
);
1320 hr
= ITaskDefinition_get_Actions(taskdef
, &actions
);
1321 ok(hr
== S_OK
, "get_Actions error %#x\n", hr
);
1323 hr
= IActionCollection_Create(actions
, TASK_ACTION_EXEC
, &action
);
1324 ok(hr
== S_OK
, "Create action error %#x\n", hr
);
1326 hr
= IAction_QueryInterface(action
, &IID_IExecAction
, (void **)&exec_action
);
1327 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1330 hr
= IExecAction_get_Type(exec_action
, &type
);
1331 ok(hr
== S_OK
, "get_Type error %#x\n", hr
);
1332 ok(type
== TASK_ACTION_EXEC
, "got %u\n", type
);
1334 hr
= IExecAction_get_Path(exec_action
, NULL
);
1335 ok(hr
== E_POINTER
, "got %#x\n", hr
);
1337 path
= (BSTR
)0xdeadbeef;
1338 hr
= IExecAction_get_Path(exec_action
, &path
);
1339 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
1340 ok(path
== NULL
, "path not set\n");
1342 hr
= IExecAction_put_Path(exec_action
, NULL
);
1343 ok(hr
== S_OK
, "put_Path error %#x\n", hr
);
1345 hr
= IExecAction_put_Path(exec_action
, task1_exe
);
1346 ok(hr
== S_OK
, "put_Path error %#x\n", hr
);
1349 hr
= IExecAction_get_Path(exec_action
, &path
);
1350 ok(hr
== S_OK
, "get_Path error %#x\n", hr
);
1351 ok(path
!= NULL
, "path not set\n");
1352 ok(!lstrcmpW(path
, task1_exe
), "got %s\n", wine_dbgstr_w(path
));
1353 SysFreeString(path
);
1355 hr
= IExecAction_get_WorkingDirectory(exec_action
, NULL
);
1356 ok(hr
== E_POINTER
, "got %#x\n", hr
);
1358 path
= (BSTR
)0xdeadbeef;
1359 hr
= IExecAction_get_WorkingDirectory(exec_action
, &path
);
1360 ok(hr
== S_OK
, "get_WorkingDirectory error %#x\n", hr
);
1361 ok(path
== NULL
, "workdir not set\n");
1363 hr
= IExecAction_put_WorkingDirectory(exec_action
, NULL
);
1364 ok(hr
== S_OK
, "put_WorkingDirectory error %#x\n", hr
);
1366 hr
= IExecAction_put_WorkingDirectory(exec_action
, workdir
);
1367 ok(hr
== S_OK
, "put_WorkingDirectory error %#x\n", hr
);
1370 hr
= IExecAction_get_WorkingDirectory(exec_action
, &path
);
1371 ok(hr
== S_OK
, "get_WorkingDirectory error %#x\n", hr
);
1372 ok(path
!= NULL
, "workdir not set\n");
1373 ok(!lstrcmpW(path
, workdir
), "got %s\n", wine_dbgstr_w(path
));
1374 SysFreeString(path
);
1376 hr
= IExecAction_get_Arguments(exec_action
, NULL
);
1377 ok(hr
== E_POINTER
, "got %#x\n", hr
);
1379 path
= (BSTR
)0xdeadbeef;
1380 hr
= IExecAction_get_Arguments(exec_action
, &path
);
1381 ok(hr
== S_OK
, "get_Arguments error %#x\n", hr
);
1382 ok(path
== NULL
, "args not set\n");
1384 hr
= IExecAction_put_Arguments(exec_action
, NULL
);
1385 ok(hr
== S_OK
, "put_Arguments error %#x\n", hr
);
1387 hr
= IExecAction_put_Arguments(exec_action
, args
);
1388 ok(hr
== S_OK
, "put_Arguments error %#x\n", hr
);
1391 hr
= IExecAction_get_Arguments(exec_action
, &path
);
1392 ok(hr
== S_OK
, "get_Arguments error %#x\n", hr
);
1393 ok(path
!= NULL
, "args not set\n");
1394 ok(!lstrcmpW(path
, args
), "got %s\n", wine_dbgstr_w(path
));
1395 SysFreeString(path
);
1398 str
= (BSTR
)0xdeadbeef;
1399 hr
= IExecAction_get_Id(exec_action
, &str
);
1400 ok(hr
== S_OK
, "get_Id error %#x\n", hr
);
1401 ok(str
== NULL
, "id should be NULL\n");
1403 hr
= IExecAction_put_Id(exec_action
, NULL
);
1404 ok(hr
== S_OK
, "put_Id error %#x\n", hr
);
1406 hr
= IExecAction_put_Id(exec_action
, comment
);
1407 ok(hr
== S_OK
, "put_Id error %#x\n", hr
);
1410 hr
= IExecAction_get_Id(exec_action
, &str
);
1411 ok(hr
== S_OK
, "get_Id error %#x\n", hr
);
1412 ok(str
!= NULL
, "should not be NULL\n");
1413 ok(!lstrcmpW(str
, comment
), "got %s\n", wine_dbgstr_w(str
));
1416 IExecAction_Release(exec_action
);
1417 IAction_Release(action
);
1418 IActionCollection_Release(actions
);
1421 static void test_TaskDefinition(void)
1423 static const char xml1
[] =
1424 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
1425 " <RegistrationInfo>\n"
1426 " <Description>\"Task1\"</Description>\n"
1427 " <Author>author</Author>\n"
1428 " <Version>1.0</Version>\n"
1429 " <Date>2018-04-02T11:22:33</Date>\n"
1430 " <Documentation>doc</Documentation>\n"
1432 " <Source>source</Source>\n"
1433 " </RegistrationInfo>\n"
1435 " <Enabled>false</Enabled>\n"
1436 " <Hidden>false</Hidden>\n"
1440 " <Command>\"task1.exe\"</Command>\n"
1444 static const char xml2
[] =
1446 " <RegistrationInfo>\n"
1447 " <Description>\"Task1\"</Description>\n"
1448 " </RegistrationInfo>\n"
1450 " <Enabled>false</Enabled>\n"
1451 " <Hidden>false</Hidden>\n"
1455 " <Command>\"task1.exe\"</Command>\n"
1459 static const char xml3
[] =
1461 " <RegistrationInfo>\n"
1462 " <Description>\"Task1\"</Description>\n"
1463 " </RegistrationInfo>\n"
1465 " <Enabled>false</Enabled>\n"
1466 " <Hidden>false</Hidden>\n"
1470 " <Command>\"task1.exe\"</Command>\n"
1474 static const char xml4
[] =
1475 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
1476 " <RegistrationInfo/>\n"
1480 " <Command>\"task1.exe\"</Command>\n"
1484 static const char xml5
[] =
1485 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
1486 " <RegistrationInfo/>\n"
1490 static const char xml6
[] =
1491 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
1492 " <RegistrationInfo/>\n"
1495 " <Command>\"task1.exe\"</Command>\n"
1500 static const char xml7
[] =
1501 "<Task xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n"
1502 " <RegistrationInfo/>\n"
1504 " <Enabled>FALSE</Enabled>\n"
1508 " <Command>\"task1.exe\"</Command>\n"
1512 static const WCHAR authorW
[] = { 'a','u','t','h','o','r',0 };
1513 static const WCHAR versionW
[] = { '1','.','0',0 };
1514 static const WCHAR dateW
[] = { '2','0','1','8','-','0','4','-','0','2','T','1','1',':','2','2',':','3','3',0 };
1515 static const WCHAR docW
[] = { 'd','o','c',0 };
1516 static const WCHAR uriW
[] = { 'u','r','i',0 };
1517 static const WCHAR sourceW
[] = { 's','o','u','r','c','e',0 };
1518 static WCHAR Task1
[] = { '"','T','a','s','k','1','"',0 };
1519 static struct settings def_settings
= { { 0 }, { 'P','T','7','2','H',0 }, { 0 },
1520 0, 7, TASK_INSTANCES_IGNORE_NEW
, TASK_COMPATIBILITY_V2
, VARIANT_TRUE
, VARIANT_TRUE
,
1521 VARIANT_TRUE
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_TRUE
, VARIANT_FALSE
,
1522 VARIANT_FALSE
, VARIANT_FALSE
};
1523 static struct settings new_settings
= { { 'P','1','Y',0 }, { 'P','T','1','0','M',0 }, { 0 },
1524 100, 1, TASK_INSTANCES_STOP_EXISTING
, TASK_COMPATIBILITY_V1
, VARIANT_FALSE
, VARIANT_FALSE
,
1525 VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_TRUE
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_TRUE
,
1526 VARIANT_TRUE
, VARIANT_TRUE
};
1527 ITriggerCollection
*trigger_col
, *trigger_col2
;
1529 ITaskService
*service
;
1530 ITaskDefinition
*taskdef
;
1531 IRegistrationInfo
*reginfo
;
1535 WCHAR xmlW
[sizeof(xml1
)];
1537 hr
= CoCreateInstance(&CLSID_TaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ITaskService
, (void **)&service
);
1540 win_skip("CoCreateInstance(CLSID_TaskScheduler) error %#x\n", hr
);
1544 hr
= ITaskService_NewTask(service
, 0, &taskdef
);
1545 ok(hr
== S_OK
, "NewTask error %#x\n", hr
);
1547 test_settings_v1(taskdef
, &def_settings
, &def_settings
);
1548 change_settings(taskdef
, &new_settings
);
1550 /* Action is mandatory for v1 compatibility */
1551 create_action(taskdef
);
1553 hr
= ITaskDefinition_get_XmlText(taskdef
, &xml
);
1554 ok(hr
== S_OK
, "get_XmlText error %#x\n", hr
);
1556 ITaskDefinition_Release(taskdef
);
1558 hr
= ITaskService_NewTask(service
, 0, &taskdef
);
1559 ok(hr
== S_OK
, "NewTask error %#x\n", hr
);
1561 hr
= ITaskDefinition_put_XmlText(taskdef
, xml
);
1562 ok(hr
== S_OK
, "put_XmlText error %#x\n", hr
);
1565 /* FIXME: uncomment once changing settings is implemented
1566 test_settings_v1(taskdef, &new_settings, &def_settings);
1569 hr
= ITaskDefinition_put_XmlText(taskdef
, NULL
);
1570 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
1572 MultiByteToWideChar(CP_ACP
, 0, xml1
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1573 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1574 ok(hr
== S_OK
, "put_XmlText error %#x\n", hr
);
1576 MultiByteToWideChar(CP_ACP
, 0, xml2
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1577 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1578 ok(hr
== SCHED_E_NAMESPACE
, "expected SCHED_E_NAMESPACE, got %#x\n", hr
);
1580 MultiByteToWideChar(CP_ACP
, 0, xml3
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1581 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1583 ok(hr
== SCHED_E_UNEXPECTEDNODE
, "expected SCHED_E_UNEXPECTEDNODE, got %#x\n", hr
);
1585 MultiByteToWideChar(CP_ACP
, 0, xml4
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1586 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1587 ok(hr
== S_OK
, "put_XmlText error %#x\n", hr
);
1589 MultiByteToWideChar(CP_ACP
, 0, xml5
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1590 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1592 ok(hr
== SCHED_E_MISSINGNODE
, "expected SCHED_E_MISSINGNODE, got %#x\n", hr
);
1594 MultiByteToWideChar(CP_ACP
, 0, xml6
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1595 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1596 ok(hr
== SCHED_E_MALFORMEDXML
, "expected SCHED_E_MALFORMEDXML, got %#x\n", hr
);
1598 MultiByteToWideChar(CP_ACP
, 0, xml7
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1599 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1600 ok(hr
== SCHED_E_INVALIDVALUE
, "expected SCHED_E_INVALIDVALUE, got %#x\n", hr
);
1603 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1604 ok(hr
== SCHED_E_MALFORMEDXML
, "expected SCHED_E_MALFORMEDXML, got %#x\n", hr
);
1606 /* test registration info */
1607 MultiByteToWideChar(CP_ACP
, 0, xml1
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1608 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1609 ok(hr
== S_OK
, "put_XmlText error %#x\n", hr
);
1610 hr
= ITaskDefinition_get_RegistrationInfo(taskdef
, ®info
);
1611 ok(hr
== S_OK
, "get_RegistrationInfo error %#x\n", hr
);
1613 hr
= IRegistrationInfo_get_Description(reginfo
, &bstr
);
1614 ok(hr
== S_OK
, "get_Description error %#x\n", hr
);
1615 ok(!lstrcmpW(bstr
, Task1
), "expected Task1, got %s\n", wine_dbgstr_w(bstr
));
1616 SysFreeString(bstr
);
1617 hr
= IRegistrationInfo_put_Description(reginfo
, NULL
);
1618 ok(hr
== S_OK
, "put_Description error %#x\n", hr
);
1619 bstr
= (BSTR
)0xdeadbeef;
1620 hr
= IRegistrationInfo_get_Description(reginfo
, &bstr
);
1621 ok(hr
== S_OK
, "get_Description error %#x\n", hr
);
1622 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1624 hr
= IRegistrationInfo_get_Author(reginfo
, &bstr
);
1625 ok(hr
== S_OK
, "get_Author error %#x\n", hr
);
1626 ok(!lstrcmpW(bstr
, authorW
), "expected %s, got %s\n", wine_dbgstr_w(authorW
), wine_dbgstr_w(bstr
));
1627 SysFreeString(bstr
);
1628 hr
= IRegistrationInfo_put_Author(reginfo
, NULL
);
1629 ok(hr
== S_OK
, "put_Author error %#x\n", hr
);
1630 bstr
= (BSTR
)0xdeadbeef;
1631 hr
= IRegistrationInfo_get_Author(reginfo
, &bstr
);
1632 ok(hr
== S_OK
, "get_Author error %#x\n", hr
);
1633 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1635 hr
= IRegistrationInfo_get_Version(reginfo
, &bstr
);
1636 ok(hr
== S_OK
, "get_Version error %#x\n", hr
);
1637 ok(!lstrcmpW(bstr
, versionW
), "expected %s, got %s\n", wine_dbgstr_w(versionW
), wine_dbgstr_w(bstr
));
1638 SysFreeString(bstr
);
1639 hr
= IRegistrationInfo_put_Version(reginfo
, NULL
);
1640 ok(hr
== S_OK
, "put_Version error %#x\n", hr
);
1641 bstr
= (BSTR
)0xdeadbeef;
1642 hr
= IRegistrationInfo_get_Version(reginfo
, &bstr
);
1643 ok(hr
== S_OK
, "get_Version error %#x\n", hr
);
1644 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1646 hr
= IRegistrationInfo_get_Date(reginfo
, &bstr
);
1647 ok(hr
== S_OK
, "get_Date error %#x\n", hr
);
1648 ok(!lstrcmpW(bstr
, dateW
), "expected %s, got %s\n", wine_dbgstr_w(dateW
), wine_dbgstr_w(bstr
));
1649 SysFreeString(bstr
);
1650 hr
= IRegistrationInfo_put_Date(reginfo
, NULL
);
1651 ok(hr
== S_OK
, "put_Date error %#x\n", hr
);
1652 bstr
= (BSTR
)0xdeadbeef;
1653 hr
= IRegistrationInfo_get_Date(reginfo
, &bstr
);
1654 ok(hr
== S_OK
, "get_Date error %#x\n", hr
);
1655 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1657 hr
= IRegistrationInfo_get_Documentation(reginfo
, &bstr
);
1658 ok(hr
== S_OK
, "get_Documentation error %#x\n", hr
);
1659 ok(!lstrcmpW(bstr
, docW
), "expected %s, got %s\n", wine_dbgstr_w(docW
), wine_dbgstr_w(bstr
));
1660 SysFreeString(bstr
);
1661 hr
= IRegistrationInfo_put_Documentation(reginfo
, NULL
);
1662 ok(hr
== S_OK
, "put_Documentation error %#x\n", hr
);
1663 bstr
= (BSTR
)0xdeadbeef;
1664 hr
= IRegistrationInfo_get_Documentation(reginfo
, &bstr
);
1665 ok(hr
== S_OK
, "get_Documentation error %#x\n", hr
);
1666 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1668 hr
= IRegistrationInfo_get_URI(reginfo
, &bstr
);
1669 ok(hr
== S_OK
, "get_URI error %#x\n", hr
);
1670 ok(!lstrcmpW(bstr
, uriW
), "expected %s, got %s\n", wine_dbgstr_w(uriW
), wine_dbgstr_w(bstr
));
1671 SysFreeString(bstr
);
1672 hr
= IRegistrationInfo_put_URI(reginfo
, NULL
);
1673 ok(hr
== S_OK
, "put_URI error %#x\n", hr
);
1674 bstr
= (BSTR
)0xdeadbeef;
1675 hr
= IRegistrationInfo_get_URI(reginfo
, &bstr
);
1676 ok(hr
== S_OK
, "get_URI error %#x\n", hr
);
1677 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1679 hr
= IRegistrationInfo_get_Source(reginfo
, &bstr
);
1680 ok(hr
== S_OK
, "get_Source error %#x\n", hr
);
1681 ok(!lstrcmpW(bstr
, sourceW
), "expected %s, got %s\n", wine_dbgstr_w(sourceW
), wine_dbgstr_w(bstr
));
1682 SysFreeString(bstr
);
1683 hr
= IRegistrationInfo_put_Source(reginfo
, NULL
);
1684 ok(hr
== S_OK
, "put_Source error %#x\n", hr
);
1685 bstr
= (BSTR
)0xdeadbeef;
1686 hr
= IRegistrationInfo_get_Source(reginfo
, &bstr
);
1687 ok(hr
== S_OK
, "get_Source error %#x\n", hr
);
1688 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1690 V_VT(&var
) = VT_BSTR
;
1691 V_BSTR(&var
) = NULL
;
1692 hr
= IRegistrationInfo_get_SecurityDescriptor(reginfo
, &var
);
1694 ok(hr
== S_OK
, "get_SecurityDescriptor error %#x\n", hr
);
1696 ok(V_VT(&var
) == VT_EMPTY
, "expected VT_EMPTY, got %u\n", V_VT(&var
));
1698 IRegistrationInfo_Release(reginfo
);
1700 MultiByteToWideChar(CP_ACP
, 0, xml4
, -1, xmlW
, sizeof(xmlW
)/sizeof(xmlW
[0]));
1701 hr
= ITaskDefinition_put_XmlText(taskdef
, xmlW
);
1702 ok(hr
== S_OK
, "put_XmlText error %#x\n", hr
);
1703 hr
= ITaskDefinition_get_RegistrationInfo(taskdef
, ®info
);
1704 ok(hr
== S_OK
, "get_RegistrationInfo error %#x\n", hr
);
1706 hr
= IRegistrationInfo_get_Description(reginfo
, &bstr
);
1707 ok(hr
== S_OK
, "get_Description error %#x\n", hr
);
1708 ok(!bstr
, "expected NULL, got %s\n", wine_dbgstr_w(bstr
));
1710 hr
= ITaskDefinition_get_Triggers(taskdef
, &trigger_col
);
1711 ok(hr
== S_OK
, "get_Triggers failed: %08x\n", hr
);
1712 ok(trigger_col
!= NULL
, "Triggers = NULL\n");
1714 hr
= ITriggerCollection_Create(trigger_col
, TASK_TRIGGER_DAILY
, &trigger
);
1715 ok(hr
== S_OK
, "Create failed: %08x\n", hr
);
1716 ok(trigger
!= NULL
, "trigger = NULL\n");
1717 test_daily_trigger(trigger
);
1718 ITrigger_Release(trigger
);
1719 ITriggerCollection_Release(trigger_col
);
1721 hr
= ITaskDefinition_get_Triggers(taskdef
, &trigger_col2
);
1722 ok(hr
== S_OK
, "get_Triggers failed: %08x\n", hr
);
1723 ok(trigger_col
== trigger_col2
, "Mismatched triggers\n");
1724 ITriggerCollection_Release(trigger_col2
);
1726 IRegistrationInfo_Release(reginfo
);
1727 ITaskDefinition_Release(taskdef
);
1728 ITaskService_Release(service
);
1731 START_TEST(scheduler
)
1733 OleInitialize(NULL
);
1737 test_FolderCollection();
1739 test_TaskDefinition();