2 * Test suite for Task interface
4 * Copyright (C) 2008 Google (Roy Shea)
5 * Copyright (C) 2018 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 static ITaskScheduler
*scheduler
;
29 static const WCHAR task_name
[] = {'T','e','s','t','i','n','g',0};
30 static const WCHAR empty
[] = {0};
32 static LPCWSTR
path_resolve_name(LPCWSTR base_name
)
34 static WCHAR buffer
[MAX_PATH
];
37 len
= SearchPathW(NULL
, base_name
, NULL
, 0, NULL
, NULL
);
40 else if (len
< MAX_PATH
)
42 SearchPathW(NULL
, base_name
, NULL
, MAX_PATH
, buffer
, NULL
);
48 static void test_SetApplicationName_GetApplicationName(void)
54 const WCHAR non_application_name
[] = {'N','o','S','u','c','h',
55 'A','p','p','l','i','c','a','t','i','o','n', 0};
56 const WCHAR notepad_exe
[] = {
57 'n','o','t','e','p','a','d','.','e','x','e', 0};
58 const WCHAR notepad
[] = {'n','o','t','e','p','a','d', 0};
60 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
61 &IID_ITask
, (IUnknown
**)&test_task
);
62 ok(hres
== S_OK
, "Failed to setup test_task\n");
64 /* Attempt getting before setting application name */
65 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
66 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
69 ok(!lstrcmpiW(stored_name
, empty
),
70 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
71 CoTaskMemFree(stored_name
);
74 /* Set application name to a nonexistent application and then get
75 * the application name that is actually stored */
76 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
77 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
78 wine_dbgstr_w(non_application_name
), hres
);
79 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
80 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
83 full_name
= path_resolve_name(non_application_name
);
84 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
85 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
86 CoTaskMemFree(stored_name
);
89 /* Set a valid application name with program type extension and then
90 * get the stored name */
91 hres
= ITask_SetApplicationName(test_task
, notepad_exe
);
92 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
93 wine_dbgstr_w(notepad_exe
), hres
);
94 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
95 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
98 full_name
= path_resolve_name(notepad_exe
);
99 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
100 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
101 CoTaskMemFree(stored_name
);
104 /* Set a valid application name without program type extension and
105 * then get the stored name */
106 hres
= ITask_SetApplicationName(test_task
, notepad
);
107 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(notepad
), hres
);
108 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
109 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
112 full_name
= path_resolve_name(notepad_exe
); /* XP SP1 appends .exe */
113 if (lstrcmpiW(stored_name
, full_name
) != 0)
115 full_name
= path_resolve_name(notepad
);
116 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
117 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
119 CoTaskMemFree(stored_name
);
122 /* After having a valid application name set, set application the name
123 * to a nonexistent application and then get the name that is
125 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
126 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
127 wine_dbgstr_w(non_application_name
), hres
);
128 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
129 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
132 full_name
= path_resolve_name(non_application_name
);
133 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
134 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
135 CoTaskMemFree(stored_name
);
138 /* Clear application name */
139 hres
= ITask_SetApplicationName(test_task
, empty
);
140 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(empty
), hres
);
141 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
142 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
145 ok(!lstrcmpiW(stored_name
, empty
),
146 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
147 CoTaskMemFree(stored_name
);
150 ITask_Release(test_task
);
153 static void test_CreateTrigger(void)
158 ITaskTrigger
*test_trigger
;
160 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
161 &IID_ITask
, (IUnknown
**)&test_task
);
162 ok(hres
== S_OK
, "Failed to setup test_task\n");
164 hres
= ITask_CreateTrigger(test_task
, &trigger_index
, &test_trigger
);
165 ok(hres
== S_OK
, "Failed to create trigger: 0x%08x\n", hres
);
167 ITaskTrigger_Release(test_trigger
);
168 ITask_Release(test_task
);
171 static void test_SetParameters_GetParameters(void)
176 const WCHAR parameters_a
[] = {'f','o','o','.','t','x','t', 0};
177 const WCHAR parameters_b
[] = {'f','o','o','.','t','x','t',' ',
178 'b','a','r','.','t','x','t', 0};
180 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
181 &IID_ITask
, (IUnknown
**)&test_task
);
182 ok(hres
== S_OK
, "Failed to setup test_task\n");
184 /* Get parameters before setting them */
185 hres
= ITask_GetParameters(test_task
, ¶meters
);
186 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
189 ok(!lstrcmpW(parameters
, empty
),
190 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
191 CoTaskMemFree(parameters
);
194 /* Set parameters to a simple string */
195 hres
= ITask_SetParameters(test_task
, parameters_a
);
196 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
197 wine_dbgstr_w(parameters_a
), hres
);
198 hres
= ITask_GetParameters(test_task
, ¶meters
);
199 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
202 ok(!lstrcmpW(parameters
, parameters_a
), "Got %s, expected %s\n",
203 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_a
));
204 CoTaskMemFree(parameters
);
207 /* Update parameters to a different simple string */
208 hres
= ITask_SetParameters(test_task
, parameters_b
);
209 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
210 wine_dbgstr_w(parameters_b
), hres
);
211 hres
= ITask_GetParameters(test_task
, ¶meters
);
212 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
215 ok(!lstrcmpW(parameters
, parameters_b
), "Got %s, expected %s\n",
216 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_b
));
217 CoTaskMemFree(parameters
);
220 /* Clear parameters */
221 hres
= ITask_SetParameters(test_task
, empty
);
222 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
223 wine_dbgstr_w(empty
), hres
);
224 hres
= ITask_GetParameters(test_task
, ¶meters
);
225 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
228 ok(!lstrcmpW(parameters
, empty
),
229 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
230 CoTaskMemFree(parameters
);
233 ITask_Release(test_task
);
236 static void test_SetComment_GetComment(void)
241 const WCHAR comment_a
[] = {'C','o','m','m','e','n','t','.', 0};
242 const WCHAR comment_b
[] = {'L','o','n','g','e','r',' ',
243 'c','o','m','m','e','n','t','.', 0};
245 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
246 &IID_ITask
, (IUnknown
**)&test_task
);
247 ok(hres
== S_OK
, "Failed to setup test_task\n");
249 /* Get comment before setting it*/
250 hres
= ITask_GetComment(test_task
, &comment
);
251 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
254 ok(!lstrcmpW(comment
, empty
),
255 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
256 CoTaskMemFree(comment
);
259 /* Set comment to a simple string */
260 hres
= ITask_SetComment(test_task
, comment_a
);
261 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
262 wine_dbgstr_w(comment_a
), hres
);
263 hres
= ITask_GetComment(test_task
, &comment
);
264 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
267 ok(!lstrcmpW(comment
, comment_a
), "Got %s, expected %s\n",
268 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_a
));
269 CoTaskMemFree(comment
);
272 /* Update comment to a different simple string */
273 hres
= ITask_SetComment(test_task
, comment_b
);
274 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
275 wine_dbgstr_w(comment_b
), hres
);
276 hres
= ITask_GetComment(test_task
, &comment
);
277 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
280 ok(!lstrcmpW(comment
, comment_b
), "Got %s, expected %s\n",
281 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_b
));
282 CoTaskMemFree(comment
);
286 hres
= ITask_SetComment(test_task
, empty
);
287 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
288 wine_dbgstr_w(empty
), hres
);
289 hres
= ITask_GetComment(test_task
, &comment
);
290 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
293 ok(!lstrcmpW(comment
, empty
),
294 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
295 CoTaskMemFree(comment
);
298 ITask_Release(test_task
);
301 static void test_SetMaxRunTime_GetMaxRunTime(void)
307 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
308 &IID_ITask
, (IUnknown
**)&test_task
);
309 ok(hres
== S_OK
, "Failed to setup test_task\n");
311 /* Default time is 3 days:
312 * 3 days * 24 hours * 60 minutes * 60 seconds * 1000 ms = 259200000 */
314 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
315 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
316 ok(max_run_time
== 259200000, "Expected 259200000: %d\n", max_run_time
);
320 hres
= ITask_SetMaxRunTime(test_task
, 1234);
321 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
322 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
323 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
324 ok(max_run_time
== 1234, "Expected 1234: %d\n", max_run_time
);
326 /* Verify that time can be set to zero */
328 hres
= ITask_SetMaxRunTime(test_task
, 0);
329 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
330 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
331 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
332 ok(max_run_time
== 0, "Expected 0: %d\n", max_run_time
);
334 /* Check resolution by setting time to one */
336 hres
= ITask_SetMaxRunTime(test_task
, 1);
337 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
338 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
339 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
340 ok(max_run_time
== 1, "Expected 1: %d\n", max_run_time
);
342 /* Verify that time can be set to INFINITE */
344 hres
= ITask_SetMaxRunTime(test_task
, INFINITE
);
345 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
346 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
347 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
348 ok(max_run_time
== INFINITE
, "Expected INFINITE: %d\n", max_run_time
);
350 ITask_Release(test_task
);
353 static void test_SetAccountInformation_GetAccountInformation(void)
358 const WCHAR dummy_account_name
[] = {'N', 'o', 'S', 'u', 'c', 'h',
359 'A', 'c', 'c', 'o', 'u', 'n', 't', 0};
360 const WCHAR dummy_account_name_b
[] = {'N', 'o', 'S', 'u', 'c', 'h',
361 'A', 'c', 'c', 'o', 'u', 'n', 't', 'B', 0};
363 hres
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
364 &IID_ITask
, (IUnknown
**)&test_task
);
365 ok(hres
== S_OK
, "Failed to setup test_task\n");
367 /* Get account information before it is set */
368 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
369 /* WinXP returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): 0x80070002 but
370 * Win2K returns SCHED_E_CANNOT_OPEN_TASK: 0x8004130d
371 * Win9x doesn't support security services */
372 if (hres
== SCHED_E_NO_SECURITY_SERVICES
|| hres
== SCHED_E_SERVICE_NOT_RUNNING
)
374 win_skip("Security services are not supported\n");
375 ITask_Release(test_task
);
377 ok(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
378 hres
== SCHED_E_CANNOT_OPEN_TASK
,
379 "Unset account name generated: 0x%08x\n", hres
);
381 /* Attempt to set to a dummy account without a password */
382 /* This test passes on WinXP but fails on Win2K */
383 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name
, NULL
);
385 "Failed setting dummy account with no password: %08x\n", hres
);
386 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
388 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
389 hres
== SCHED_E_CANNOT_OPEN_TASK
||
390 hres
== 0x200), /* win2k */
391 "GetAccountInformation failed: %08x\n", hres
);
394 ok(!lstrcmpW(account_name
, dummy_account_name
),
395 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
396 wine_dbgstr_w(dummy_account_name
));
397 CoTaskMemFree(account_name
);
400 /* Attempt to set to a dummy account with a (invalid) password */
401 /* This test passes on WinXP but fails on Win2K */
402 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name_b
,
403 dummy_account_name_b
);
405 "Failed setting dummy account with password: %08x\n", hres
);
406 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
408 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
409 hres
== SCHED_E_CANNOT_OPEN_TASK
||
410 hres
== 0x200), /* win2k */
411 "GetAccountInformation failed: %08x\n", hres
);
414 ok(!lstrcmpW(account_name
, dummy_account_name_b
),
415 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
416 wine_dbgstr_w(dummy_account_name_b
));
417 CoTaskMemFree(account_name
);
420 /* Attempt to set to the local system account */
421 hres
= ITask_SetAccountInformation(test_task
, empty
, NULL
);
422 ok(hres
== S_OK
, "Failed setting system account: %08x\n", hres
);
423 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
425 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
426 hres
== SCHED_E_CANNOT_OPEN_TASK
||
427 hres
== 0x200), /* win2k */
428 "GetAccountInformation failed: %08x\n", hres
);
431 ok(!lstrcmpW(account_name
, empty
),
432 "Got %s, expected empty string\n", wine_dbgstr_w(account_name
));
433 CoTaskMemFree(account_name
);
436 ITask_Release(test_task
);
439 static void test_task_state(void)
447 hr
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
448 &IID_ITask
, (IUnknown
**)&test_task
);
449 ok(hr
== S_OK
, "Failed to setup test_task\n");
451 if (0) /* crashes under Windows */
452 hr
= ITask_GetFlags(test_task
, NULL
);
455 hr
= ITask_GetFlags(test_task
, &flags
);
456 ok(hr
== S_OK
, "GetFlags error %#x\n", hr
);
457 ok(flags
== 0, "got %#x\n", flags
);
459 if (0) /* crashes under Windows */
460 hr
= ITask_GetTaskFlags(test_task
, NULL
);
463 hr
= ITask_GetTaskFlags(test_task
, &flags
);
464 ok(hr
== S_OK
, "GetTaskFlags error %#x\n", hr
);
465 ok(flags
== 0, "got %#x\n", flags
);
467 if (0) /* crashes under Windows */
468 hr
= ITask_GetStatus(test_task
, NULL
);
471 hr
= ITask_GetStatus(test_task
, &status
);
472 ok(hr
== S_OK
, "GetStatus error %#x\n", hr
);
473 ok(status
== SCHED_S_TASK_NOT_SCHEDULED
, "got %#x\n", status
);
475 if (0) /* crashes under Windows */
476 hr
= ITask_GetErrorRetryCount(test_task
, NULL
);
478 hr
= ITask_GetErrorRetryCount(test_task
, &val1
);
479 ok(hr
== E_NOTIMPL
, "got %#x\n", hr
);
481 if (0) /* crashes under Windows */
482 hr
= ITask_GetErrorRetryInterval(test_task
, NULL
);
484 hr
= ITask_GetErrorRetryInterval(test_task
, &val1
);
485 ok(hr
== E_NOTIMPL
, "got %#x\n", hr
);
487 if (0) /* crashes under Windows */
488 hr
= ITask_GetIdleWait(test_task
, NULL
, NULL
);
492 hr
= ITask_GetIdleWait(test_task
, &val1
, &val2
);
493 ok(hr
== S_OK
, "got %#x\n", hr
);
494 ok(val1
== 10, "got %u\n", val1
);
495 ok(val2
== 60, "got %u\n", val2
);
497 if (0) /* crashes under Windows */
498 hr
= ITask_GetPriority(test_task
, NULL
);
501 hr
= ITask_GetPriority(test_task
, &val
);
502 ok(hr
== S_OK
, "got %#x\n", hr
);
503 ok(val
== NORMAL_PRIORITY_CLASS
, "got %#x\n", val
);
505 if (0) /* crashes under Windows */
506 hr
= ITask_GetExitCode(test_task
, NULL
);
509 hr
= ITask_GetExitCode(test_task
, &val
);
510 ok(hr
== SCHED_S_TASK_HAS_NOT_RUN
, "got %#x\n", hr
);
511 ok(val
== 0, "got %#x\n", val
);
513 if (0) /* crashes under Windows */
514 hr
= ITask_GetMostRecentRunTime(test_task
, NULL
);
516 memset(&st
, 0xff, sizeof(st
));
517 hr
= ITask_GetMostRecentRunTime(test_task
, &st
);
518 ok(hr
== SCHED_S_TASK_HAS_NOT_RUN
, "got %#x\n", hr
);
519 ok(st
.wYear
== 0, "got %u\n", st
.wYear
);
520 ok(st
.wMonth
== 0, "got %u\n", st
.wMonth
);
521 ok(st
.wDay
== 0, "got %u\n", st
.wDay
);
522 ok(st
.wHour
== 0, "got %u\n", st
.wHour
);
523 ok(st
.wMinute
== 0, "got %u\n", st
.wMinute
);
524 ok(st
.wSecond
== 0, "got %u\n", st
.wSecond
);
526 ITask_Release(test_task
);
529 static void save_job(ITask
*task
)
534 hr
= ITask_QueryInterface(task
, &IID_IPersistFile
, (void **)&pfile
);
535 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
537 hr
= IPersistFile_Save(pfile
, NULL
, FALSE
);
538 ok(hr
== S_OK
, "got %#x\n", hr
);
540 IPersistFile_Release(pfile
);
543 static void test_Run(void)
545 static const WCHAR wine_test_runW
[] = { 'w','i','n','e','_','t','e','s','t','_','r','u','n',0 };
546 static const WCHAR cmdW
[] = { 'c','m','d','.','e','x','e',0 };
548 ITaskTrigger
*trigger
;
550 TASK_TRIGGER trigger_data
;
554 /* cleanup after previous runs */
555 ITaskScheduler_Delete(scheduler
, wine_test_runW
);
557 hr
= ITaskScheduler_NewWorkItem(scheduler
, wine_test_runW
, &CLSID_CTask
,
558 &IID_ITask
, (IUnknown
**)&task
);
559 ok(hr
== S_OK
, "got %#x\n", hr
);
561 hr
= ITask_Run(task
);
562 ok(hr
== SCHED_E_TASK_NOT_READY
, "got %#x\n", hr
);
564 hr
= ITask_Terminate(task
);
565 ok(hr
== SCHED_E_TASK_NOT_RUNNING
, "got %#x\n", hr
);
567 hr
= ITask_GetStatus(task
, &status
);
568 ok(hr
== S_OK
, "got %#x\n", hr
);
569 ok(status
== SCHED_S_TASK_NOT_SCHEDULED
, "got %#x\n", status
);
573 hr
= ITask_GetStatus(task
, &status
);
574 ok(hr
== S_OK
, "got %#x\n", hr
);
575 ok(status
== SCHED_S_TASK_NOT_SCHEDULED
, "got %#x\n", status
);
577 hr
= ITask_CreateTrigger(task
, &idx
, &trigger
);
578 ok(hr
== S_OK
, "got %#x\n", hr
);
580 memset(&trigger_data
, 0, sizeof(trigger_data
));
581 trigger_data
.cbTriggerSize
= sizeof(trigger_data
);
582 trigger_data
.Reserved1
= 0;
584 trigger_data
.wBeginYear
= st
.wYear
;
585 trigger_data
.wBeginMonth
= st
.wMonth
;
586 trigger_data
.wBeginDay
= st
.wDay
;
587 trigger_data
.wStartHour
= st
.wHour
;
588 trigger_data
.wStartMinute
= st
.wMinute
;
589 trigger_data
.TriggerType
= TASK_TIME_TRIGGER_WEEKLY
;
590 trigger_data
.Type
.Weekly
.WeeksInterval
= 1;
591 trigger_data
.Type
.Weekly
.rgfDaysOfTheWeek
= 0x7f; /* every day */
592 hr
= ITaskTrigger_SetTrigger(trigger
, &trigger_data
);
593 ok(hr
== S_OK
, "got %#x\n", hr
);
594 ITaskTrigger_Release(trigger
);
596 hr
= ITask_SetApplicationName(task
, cmdW
);
597 ok(hr
== S_OK
, "got %#x\n", hr
);
599 hr
= ITask_SetParameters(task
, empty
);
600 ok(hr
== S_OK
, "got %#x\n", hr
);
602 hr
= ITask_SetWorkingDirectory(task
, empty
);
603 ok(hr
== S_OK
, "got %#x\n", hr
);
605 /* Save the task so that the Scheduler service would notice the changes */
608 hr
= ITask_GetStatus(task
, &status
);
609 ok(hr
== S_OK
, "got %#x\n", hr
);
610 ok(status
== SCHED_S_TASK_HAS_NOT_RUN
, "got %#x\n", status
);
612 hr
= ITask_Run(task
);
613 ok(hr
== S_OK
, "got %#x\n", hr
);
615 /* According to MSDN the task status doesn't update dynamically */
616 hr
= ITask_GetStatus(task
, &status
);
617 ok(hr
== S_OK
, "got %#x\n", hr
);
618 ok(status
== SCHED_S_TASK_HAS_NOT_RUN
, "got %#x\n", status
);
622 /* Running the process associated with the task to start up may
623 * take quite a bit a of time, and waiting for it during the test
624 * may be not the best idea.
626 * This is how it's supposed to look like in the application
627 * (the loop should be infinite):
629 for (i
= 0; i
< 5; i
++)
631 hr
= ITaskScheduler_Activate(scheduler
, wine_test_runW
, &IID_ITask
, (IUnknown
**)&task
);
632 ok(hr
== S_OK
, "Activate error %#x\n", hr
);
634 hr
= ITask_GetStatus(task
, &status
);
635 ok(hr
== S_OK
, "got %#x\n", hr
);
639 if (status
== SCHED_S_TASK_RUNNING
) break;
644 hr
= ITaskScheduler_Activate(scheduler
, wine_test_runW
, &IID_ITask
, (IUnknown
**)&task
);
645 ok(hr
== S_OK
, "Activate error %#x\n", hr
);
647 hr
= ITask_GetStatus(task
, &status
);
648 ok(hr
== S_OK
, "got %#x\n", hr
);
650 if (status
== SCHED_S_TASK_RUNNING
)
652 hr
= ITask_Terminate(task
);
653 ok(hr
== S_OK
, "got %#x\n", hr
);
657 /* Waiting for the process associated with the task to terminate
658 * may take quite a bit a of time, and waiting for it during the
659 * test is not practical.
661 * This is how it's supposed to look like in the application
662 * (the loop should be infinite):
664 for (i
= 0; i
< 5; i
++)
666 hr
= ITaskScheduler_Activate(scheduler
, wine_test_runW
, &IID_ITask
, (IUnknown
**)&task
);
667 ok(hr
== S_OK
, "Activate error %#x\n", hr
);
669 hr
= ITask_GetStatus(task
, &status
);
670 ok(hr
== S_OK
, "got %#x\n", hr
);
674 if (status
!= SCHED_S_TASK_RUNNING
) break;
682 hr
= ITaskScheduler_Delete(scheduler
, wine_test_runW
);
683 ok(hr
== S_OK
, "got %#x\n", hr
);
686 static void test_SetFlags(void)
692 hr
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
693 &IID_ITask
, (IUnknown
**)&task
);
694 ok(hr
== S_OK
, "got %#x\n", hr
);
696 hr
= ITask_SetFlags(task
, 0);
697 ok(hr
== S_OK
, "got %#x\n", hr
);
700 hr
= ITask_GetFlags(task
, &flags
);
701 ok(hr
== S_OK
, "got %#x\n", hr
);
702 ok(flags
== 0, "got %#x\n", flags
);
704 hr
= ITask_SetFlags(task
, 0xffffffff);
705 ok(hr
== S_OK
, "got %#x\n", hr
);
708 hr
= ITask_GetFlags(task
, &flags
);
709 ok(hr
== S_OK
, "got %#x\n", hr
);
710 ok(flags
== 0x7fff, "got %#x\n", flags
);
712 hr
= ITask_SetFlags(task
, 0x9234);
713 ok(hr
== S_OK
, "got %#x\n", hr
);
716 hr
= ITask_GetFlags(task
, &flags
);
717 ok(hr
== S_OK
, "got %#x\n", hr
);
718 ok(flags
== 0x1234, "got %#x\n", flags
);
723 static void test_workitem_data(void)
725 static BYTE hello
[] = "Hello World!";
731 hr
= ITaskScheduler_NewWorkItem(scheduler
, task_name
, &CLSID_CTask
,
732 &IID_ITask
, (IUnknown
**)&task
);
733 ok(hr
== S_OK
, "got %#x\n", hr
);
735 if (0) /* crashes under Windows */
736 hr
= ITask_GetWorkItemData(task
, &count
, NULL
);
737 if (0) /* crashes under Windows */
738 hr
= ITask_GetWorkItemData(task
, NULL
, &data
);
741 data
= (BYTE
*)0xdeadbeef;
742 hr
= ITask_GetWorkItemData(task
, &count
, &data
);
743 ok(hr
== S_OK
, "got %#x\n", hr
);
744 ok(count
== 0, "got %u\n", count
);
745 ok(data
== NULL
, "got %p\n", data
);
747 hr
= ITask_SetWorkItemData(task
, sizeof(hello
), NULL
);
748 ok(hr
== E_INVALIDARG
, "got %#x\n", hr
);
750 hr
= ITask_SetWorkItemData(task
, 0, hello
);
751 ok(hr
== E_INVALIDARG
, "got %#x\n", hr
);
753 hr
= ITask_SetWorkItemData(task
, sizeof(hello
), hello
);
754 ok(hr
== S_OK
, "got %#x\n", hr
);
758 hr
= ITask_GetWorkItemData(task
, &count
, &data
);
759 ok(hr
== S_OK
, "got %#x\n", hr
);
760 ok(count
== sizeof(hello
), "got %u\n", count
);
761 ok(data
!= NULL
, "got NULL\n");
762 ok(!memcmp(data
, hello
, sizeof(hello
)), "data mismatch\n");
765 hr
= ITask_SetWorkItemData(task
, 0, NULL
);
766 ok(hr
== S_OK
, "got %#x\n", hr
);
769 data
= (BYTE
*)0xdeadbeef;
770 hr
= ITask_GetWorkItemData(task
, &count
, &data
);
771 ok(hr
== S_OK
, "got %#x\n", hr
);
772 ok(count
== 0, "got %u\n", count
);
773 ok(data
== NULL
, "got %p\n", data
);
783 hr
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
784 &IID_ITaskScheduler
, (void **)&scheduler
);
785 ok(hr
== S_OK
, "failed to create task scheduler: %#x\n", hr
);
787 test_SetApplicationName_GetApplicationName();
788 test_CreateTrigger();
789 test_SetParameters_GetParameters();
790 test_SetComment_GetComment();
791 test_SetMaxRunTime_GetMaxRunTime();
792 test_SetAccountInformation_GetAccountInformation();
796 test_workitem_data();
798 ITaskScheduler_Release(scheduler
);