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
*test_task_scheduler
;
29 static ITask
*test_task
;
30 static const WCHAR empty
[] = {0};
32 static BOOL
setup_task(void)
35 const WCHAR task_name
[] = {'T','e','s','t','i','n','g', 0};
37 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
38 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
41 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
, &CLSID_CTask
,
42 &IID_ITask
, (IUnknown
**)&test_task
);
45 ITaskScheduler_Release(test_task_scheduler
);
51 static void cleanup_task(void)
53 ITask_Release(test_task
);
54 ITaskScheduler_Release(test_task_scheduler
);
57 static LPCWSTR
path_resolve_name(LPCWSTR base_name
)
59 static WCHAR buffer
[MAX_PATH
];
62 len
= SearchPathW(NULL
, base_name
, NULL
, 0, NULL
, NULL
);
65 else if (len
< MAX_PATH
)
67 SearchPathW(NULL
, base_name
, NULL
, MAX_PATH
, buffer
, NULL
);
73 static void test_SetApplicationName_GetApplicationName(void)
79 const WCHAR non_application_name
[] = {'N','o','S','u','c','h',
80 'A','p','p','l','i','c','a','t','i','o','n', 0};
81 const WCHAR notepad_exe
[] = {
82 'n','o','t','e','p','a','d','.','e','x','e', 0};
83 const WCHAR notepad
[] = {'n','o','t','e','p','a','d', 0};
86 ok(setup
, "Failed to setup test_task\n");
89 skip("Failed to create task. Skipping tests.\n");
93 /* Attempt getting before setting application name */
94 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
95 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
98 ok(!lstrcmpiW(stored_name
, empty
),
99 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
100 CoTaskMemFree(stored_name
);
103 /* Set application name to a nonexistent application and then get
104 * the application name that is actually stored */
105 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
106 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
107 wine_dbgstr_w(non_application_name
), 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(non_application_name
);
113 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
114 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
115 CoTaskMemFree(stored_name
);
118 /* Set a valid application name with program type extension and then
119 * get the stored name */
120 hres
= ITask_SetApplicationName(test_task
, notepad_exe
);
121 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
122 wine_dbgstr_w(notepad_exe
), hres
);
123 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
124 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
127 full_name
= path_resolve_name(notepad_exe
);
128 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
129 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
130 CoTaskMemFree(stored_name
);
133 /* Set a valid application name without program type extension and
134 * then get the stored name */
135 hres
= ITask_SetApplicationName(test_task
, notepad
);
136 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(notepad
), hres
);
137 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
138 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
141 full_name
= path_resolve_name(notepad_exe
); /* XP SP1 appends .exe */
142 if (lstrcmpiW(stored_name
, full_name
) != 0)
144 full_name
= path_resolve_name(notepad
);
145 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
146 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
148 CoTaskMemFree(stored_name
);
151 /* After having a valid application name set, set application the name
152 * to a nonexistent application and then get the name that is
154 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
155 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
156 wine_dbgstr_w(non_application_name
), hres
);
157 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
158 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
161 full_name
= path_resolve_name(non_application_name
);
162 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
163 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
164 CoTaskMemFree(stored_name
);
167 /* Clear application name */
168 hres
= ITask_SetApplicationName(test_task
, empty
);
169 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(empty
), hres
);
170 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
171 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
174 ok(!lstrcmpiW(stored_name
, empty
),
175 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
176 CoTaskMemFree(stored_name
);
183 static void test_CreateTrigger(void)
188 ITaskTrigger
*test_trigger
;
190 setup
= setup_task();
191 ok(setup
, "Failed to setup test_task\n");
194 skip("Failed to create task. Skipping tests.\n");
198 hres
= ITask_CreateTrigger(test_task
, &trigger_index
, &test_trigger
);
199 ok(hres
== S_OK
, "Failed to create trigger: 0x%08x\n", hres
);
206 ITaskTrigger_Release(test_trigger
);
211 static void test_SetParameters_GetParameters(void)
216 const WCHAR parameters_a
[] = {'f','o','o','.','t','x','t', 0};
217 const WCHAR parameters_b
[] = {'f','o','o','.','t','x','t',' ',
218 'b','a','r','.','t','x','t', 0};
220 setup
= setup_task();
221 ok(setup
, "Failed to setup test_task\n");
224 skip("Failed to create task. Skipping tests.\n");
228 /* Get parameters before setting them */
229 hres
= ITask_GetParameters(test_task
, ¶meters
);
230 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
233 ok(!lstrcmpW(parameters
, empty
),
234 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
235 CoTaskMemFree(parameters
);
238 /* Set parameters to a simple string */
239 hres
= ITask_SetParameters(test_task
, parameters_a
);
240 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
241 wine_dbgstr_w(parameters_a
), hres
);
242 hres
= ITask_GetParameters(test_task
, ¶meters
);
243 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
246 ok(!lstrcmpW(parameters
, parameters_a
), "Got %s, expected %s\n",
247 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_a
));
248 CoTaskMemFree(parameters
);
251 /* Update parameters to a different simple string */
252 hres
= ITask_SetParameters(test_task
, parameters_b
);
253 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
254 wine_dbgstr_w(parameters_b
), hres
);
255 hres
= ITask_GetParameters(test_task
, ¶meters
);
256 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
259 ok(!lstrcmpW(parameters
, parameters_b
), "Got %s, expected %s\n",
260 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_b
));
261 CoTaskMemFree(parameters
);
264 /* Clear parameters */
265 hres
= ITask_SetParameters(test_task
, empty
);
266 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
267 wine_dbgstr_w(empty
), hres
);
268 hres
= ITask_GetParameters(test_task
, ¶meters
);
269 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
272 ok(!lstrcmpW(parameters
, empty
),
273 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
274 CoTaskMemFree(parameters
);
281 static void test_SetComment_GetComment(void)
286 const WCHAR comment_a
[] = {'C','o','m','m','e','n','t','.', 0};
287 const WCHAR comment_b
[] = {'L','o','n','g','e','r',' ',
288 'c','o','m','m','e','n','t','.', 0};
290 setup
= setup_task();
291 ok(setup
, "Failed to setup test_task\n");
294 skip("Failed to create task. Skipping tests.\n");
298 /* Get comment before setting it*/
299 hres
= ITask_GetComment(test_task
, &comment
);
300 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
303 ok(!lstrcmpW(comment
, empty
),
304 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
305 CoTaskMemFree(comment
);
308 /* Set comment to a simple string */
309 hres
= ITask_SetComment(test_task
, comment_a
);
310 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
311 wine_dbgstr_w(comment_a
), hres
);
312 hres
= ITask_GetComment(test_task
, &comment
);
313 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
316 ok(!lstrcmpW(comment
, comment_a
), "Got %s, expected %s\n",
317 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_a
));
318 CoTaskMemFree(comment
);
321 /* Update comment to a different simple string */
322 hres
= ITask_SetComment(test_task
, comment_b
);
323 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
324 wine_dbgstr_w(comment_b
), hres
);
325 hres
= ITask_GetComment(test_task
, &comment
);
326 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
329 ok(!lstrcmpW(comment
, comment_b
), "Got %s, expected %s\n",
330 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_b
));
331 CoTaskMemFree(comment
);
335 hres
= ITask_SetComment(test_task
, empty
);
336 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
337 wine_dbgstr_w(empty
), hres
);
338 hres
= ITask_GetComment(test_task
, &comment
);
339 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
342 ok(!lstrcmpW(comment
, empty
),
343 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
344 CoTaskMemFree(comment
);
351 static void test_SetMaxRunTime_GetMaxRunTime(void)
357 setup
= setup_task();
358 ok(setup
, "Failed to setup test_task\n");
361 skip("Failed to create task. Skipping tests.\n");
365 /* Default time is 3 days:
366 * 3 days * 24 hours * 60 minutes * 60 seconds * 1000 ms = 259200000 */
368 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
369 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
370 ok(max_run_time
== 259200000, "Expected 259200000: %d\n", max_run_time
);
374 hres
= ITask_SetMaxRunTime(test_task
, 1234);
375 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
376 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
377 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
378 ok(max_run_time
== 1234, "Expected 1234: %d\n", max_run_time
);
380 /* Verify that time can be set to zero */
382 hres
= ITask_SetMaxRunTime(test_task
, 0);
383 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
384 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
385 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
386 ok(max_run_time
== 0, "Expected 0: %d\n", max_run_time
);
388 /* Check resolution by setting time to one */
390 hres
= ITask_SetMaxRunTime(test_task
, 1);
391 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
392 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
393 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
394 ok(max_run_time
== 1, "Expected 1: %d\n", max_run_time
);
396 /* Verify that time can be set to INFINITE */
398 hres
= ITask_SetMaxRunTime(test_task
, INFINITE
);
399 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
400 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
401 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
402 ok(max_run_time
== INFINITE
, "Expected INFINITE: %d\n", max_run_time
);
408 static void test_SetAccountInformation_GetAccountInformation(void)
413 const WCHAR dummy_account_name
[] = {'N', 'o', 'S', 'u', 'c', 'h',
414 'A', 'c', 'c', 'o', 'u', 'n', 't', 0};
415 const WCHAR dummy_account_name_b
[] = {'N', 'o', 'S', 'u', 'c', 'h',
416 'A', 'c', 'c', 'o', 'u', 'n', 't', 'B', 0};
418 setup
= setup_task();
419 ok(setup
, "Failed to setup test_task\n");
422 skip("Failed to create task. Skipping tests.\n");
426 /* Get account information before it is set */
427 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
428 /* WinXP returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): 0x80070002 but
429 * Win2K returns SCHED_E_CANNOT_OPEN_TASK: 0x8004130d
430 * Win9x doesn't support security services */
431 if (hres
== SCHED_E_NO_SECURITY_SERVICES
|| hres
== SCHED_E_SERVICE_NOT_RUNNING
)
433 win_skip("Security services are not supported\n");
437 ok(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
438 hres
== SCHED_E_CANNOT_OPEN_TASK
,
439 "Unset account name generated: 0x%08x\n", hres
);
441 /* Attempt to set to a dummy account without a password */
442 /* This test passes on WinXP but fails on Win2K */
443 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name
, NULL
);
445 "Failed setting dummy account with no password: %08x\n", hres
);
446 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
448 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
449 hres
== SCHED_E_CANNOT_OPEN_TASK
||
450 hres
== 0x200), /* win2k */
451 "GetAccountInformation failed: %08x\n", hres
);
454 ok(!lstrcmpW(account_name
, dummy_account_name
),
455 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
456 wine_dbgstr_w(dummy_account_name
));
457 CoTaskMemFree(account_name
);
460 /* Attempt to set to a dummy account with a (invalid) password */
461 /* This test passes on WinXP but fails on Win2K */
462 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name_b
,
463 dummy_account_name_b
);
465 "Failed setting dummy account with password: %08x\n", hres
);
466 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
468 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
469 hres
== SCHED_E_CANNOT_OPEN_TASK
||
470 hres
== 0x200), /* win2k */
471 "GetAccountInformation failed: %08x\n", hres
);
474 ok(!lstrcmpW(account_name
, dummy_account_name_b
),
475 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
476 wine_dbgstr_w(dummy_account_name_b
));
477 CoTaskMemFree(account_name
);
480 /* Attempt to set to the local system account */
481 hres
= ITask_SetAccountInformation(test_task
, empty
, NULL
);
482 ok(hres
== S_OK
, "Failed setting system account: %08x\n", hres
);
483 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
485 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
486 hres
== SCHED_E_CANNOT_OPEN_TASK
||
487 hres
== 0x200), /* win2k */
488 "GetAccountInformation failed: %08x\n", hres
);
491 ok(!lstrcmpW(account_name
, empty
),
492 "Got %s, expected empty string\n", wine_dbgstr_w(account_name
));
493 CoTaskMemFree(account_name
);
500 static void test_task_state(void)
507 setup
= setup_task();
508 ok(setup
, "Failed to setup test_task\n");
511 skip("Failed to create task. Skipping tests.\n");
515 if (0) /* crashes under Windows */
516 hr
= ITask_GetFlags(test_task
, NULL
);
519 hr
= ITask_GetFlags(test_task
, &flags
);
520 ok(hr
== S_OK
, "GetFlags error %#x\n", hr
);
521 ok(flags
== 0, "got %#x\n", flags
);
523 if (0) /* crashes under Windows */
524 hr
= ITask_GetTaskFlags(test_task
, NULL
);
527 hr
= ITask_GetTaskFlags(test_task
, &flags
);
528 ok(hr
== S_OK
, "GetTaskFlags error %#x\n", hr
);
529 ok(flags
== 0, "got %#x\n", flags
);
531 if (0) /* crashes under Windows */
532 hr
= ITask_GetStatus(test_task
, NULL
);
535 hr
= ITask_GetStatus(test_task
, &status
);
536 ok(status
== SCHED_S_TASK_NOT_SCHEDULED
, "got %#x\n", status
);
538 if (0) /* crashes under Windows */
539 hr
= ITask_GetErrorRetryCount(test_task
, NULL
);
541 hr
= ITask_GetErrorRetryCount(test_task
, &val1
);
542 ok(hr
== E_NOTIMPL
, "got %#x\n", hr
);
544 if (0) /* crashes under Windows */
545 hr
= ITask_GetErrorRetryInterval(test_task
, NULL
);
547 hr
= ITask_GetErrorRetryInterval(test_task
, &val1
);
548 ok(hr
== E_NOTIMPL
, "got %#x\n", hr
);
556 test_SetApplicationName_GetApplicationName();
557 test_CreateTrigger();
558 test_SetParameters_GetParameters();
559 test_SetComment_GetComment();
560 test_SetMaxRunTime_GetMaxRunTime();
561 test_SetAccountInformation_GetAccountInformation();