2 * Test suite for Task interface
4 * Copyright (C) 2008 Google (Roy Shea)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 static ITaskScheduler
*test_task_scheduler
;
28 static ITask
*test_task
;
29 static const WCHAR empty
[] = {0};
31 static BOOL
setup_task(void)
34 const WCHAR task_name
[] = {'T','e','s','t','i','n','g', 0};
36 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
37 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
40 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
, &CLSID_CTask
,
41 &IID_ITask
, (IUnknown
**)&test_task
);
44 ITaskScheduler_Release(test_task_scheduler
);
50 static void cleanup_task(void)
52 ITask_Release(test_task
);
53 ITaskScheduler_Release(test_task_scheduler
);
56 static LPCWSTR
path_resolve_name(LPCWSTR base_name
)
58 static WCHAR buffer
[MAX_PATH
];
61 len
= SearchPathW(NULL
, base_name
, NULL
, 0, NULL
, NULL
);
64 else if (len
< MAX_PATH
)
66 SearchPathW(NULL
, base_name
, NULL
, MAX_PATH
, buffer
, NULL
);
72 static void test_SetApplicationName_GetApplicationName(void)
78 const WCHAR non_application_name
[] = {'N','o','S','u','c','h',
79 'A','p','p','l','i','c','a','t','i','o','n', 0};
80 const WCHAR notepad_exe
[] = {
81 'n','o','t','e','p','a','d','.','e','x','e', 0};
82 const WCHAR notepad
[] = {'n','o','t','e','p','a','d', 0};
85 ok(setup
, "Failed to setup test_task\n");
88 skip("Failed to create task. Skipping tests.\n");
92 /* Attempt getting before setting application name */
93 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
94 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
97 ok(!lstrcmpiW(stored_name
, empty
),
98 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
99 CoTaskMemFree(stored_name
);
102 /* Set application name to a nonexistent application and then get
103 * the application name that is actually stored */
104 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
105 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
106 wine_dbgstr_w(non_application_name
), hres
);
107 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
108 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
111 full_name
= path_resolve_name(non_application_name
);
112 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
113 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
114 CoTaskMemFree(stored_name
);
117 /* Set a valid application name with program type extension and then
118 * get the stored name */
119 hres
= ITask_SetApplicationName(test_task
, notepad_exe
);
120 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
121 wine_dbgstr_w(notepad_exe
), hres
);
122 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
123 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
126 full_name
= path_resolve_name(notepad_exe
);
127 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
128 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
129 CoTaskMemFree(stored_name
);
132 /* Set a valid application name without program type extension and
133 * then get the stored name */
134 hres
= ITask_SetApplicationName(test_task
, notepad
);
135 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(notepad
), hres
);
136 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
137 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
140 full_name
= path_resolve_name(notepad_exe
); /* XP SP1 appends .exe */
141 if (lstrcmpiW(stored_name
, full_name
) != 0)
143 full_name
= path_resolve_name(notepad
);
144 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
145 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
147 CoTaskMemFree(stored_name
);
150 /* After having a valid application name set, set application the name
151 * to a nonexistent application and then get the name that is
153 hres
= ITask_SetApplicationName(test_task
, non_application_name
);
154 ok(hres
== S_OK
, "Failed setting name %s: %08x\n",
155 wine_dbgstr_w(non_application_name
), hres
);
156 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
157 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
160 full_name
= path_resolve_name(non_application_name
);
161 ok(!lstrcmpiW(stored_name
, full_name
), "Got %s, expected %s\n",
162 wine_dbgstr_w(stored_name
), wine_dbgstr_w(full_name
));
163 CoTaskMemFree(stored_name
);
166 /* Clear application name */
167 hres
= ITask_SetApplicationName(test_task
, empty
);
168 ok(hres
== S_OK
, "Failed setting name %s: %08x\n", wine_dbgstr_w(empty
), hres
);
169 hres
= ITask_GetApplicationName(test_task
, &stored_name
);
170 ok(hres
== S_OK
, "GetApplicationName failed: %08x\n", hres
);
173 ok(!lstrcmpiW(stored_name
, empty
),
174 "Got %s, expected empty string\n", wine_dbgstr_w(stored_name
));
175 CoTaskMemFree(stored_name
);
182 static void test_CreateTrigger(void)
187 ITaskTrigger
*test_trigger
;
189 setup
= setup_task();
190 ok(setup
, "Failed to setup test_task\n");
193 skip("Failed to create task. Skipping tests.\n");
197 hres
= ITask_CreateTrigger(test_task
, &trigger_index
, &test_trigger
);
198 ok(hres
== S_OK
, "Failed to create trigger: 0x%08x\n", hres
);
205 ITaskTrigger_Release(test_trigger
);
210 static void test_SetParameters_GetParameters(void)
215 const WCHAR parameters_a
[] = {'f','o','o','.','t','x','t', 0};
216 const WCHAR parameters_b
[] = {'f','o','o','.','t','x','t',' ',
217 'b','a','r','.','t','x','t', 0};
219 setup
= setup_task();
220 ok(setup
, "Failed to setup test_task\n");
223 skip("Failed to create task. Skipping tests.\n");
227 /* Get parameters before setting them */
228 hres
= ITask_GetParameters(test_task
, ¶meters
);
229 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
232 ok(!lstrcmpW(parameters
, empty
),
233 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
234 CoTaskMemFree(parameters
);
237 /* Set parameters to a simple string */
238 hres
= ITask_SetParameters(test_task
, parameters_a
);
239 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
240 wine_dbgstr_w(parameters_a
), hres
);
241 hres
= ITask_GetParameters(test_task
, ¶meters
);
242 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
245 ok(!lstrcmpW(parameters
, parameters_a
), "Got %s, expected %s\n",
246 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_a
));
247 CoTaskMemFree(parameters
);
250 /* Update parameters to a different simple string */
251 hres
= ITask_SetParameters(test_task
, parameters_b
);
252 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
253 wine_dbgstr_w(parameters_b
), hres
);
254 hres
= ITask_GetParameters(test_task
, ¶meters
);
255 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
258 ok(!lstrcmpW(parameters
, parameters_b
), "Got %s, expected %s\n",
259 wine_dbgstr_w(parameters
), wine_dbgstr_w(parameters_b
));
260 CoTaskMemFree(parameters
);
263 /* Clear parameters */
264 hres
= ITask_SetParameters(test_task
, empty
);
265 ok(hres
== S_OK
, "Failed setting parameters %s: %08x\n",
266 wine_dbgstr_w(empty
), hres
);
267 hres
= ITask_GetParameters(test_task
, ¶meters
);
268 ok(hres
== S_OK
, "GetParameters failed: %08x\n", hres
);
271 ok(!lstrcmpW(parameters
, empty
),
272 "Got %s, expected empty string\n", wine_dbgstr_w(parameters
));
273 CoTaskMemFree(parameters
);
280 static void test_SetComment_GetComment(void)
285 const WCHAR comment_a
[] = {'C','o','m','m','e','n','t','.', 0};
286 const WCHAR comment_b
[] = {'L','o','n','g','e','r',' ',
287 'c','o','m','m','e','n','t','.', 0};
289 setup
= setup_task();
290 ok(setup
, "Failed to setup test_task\n");
293 skip("Failed to create task. Skipping tests.\n");
297 /* Get comment before setting it*/
298 hres
= ITask_GetComment(test_task
, &comment
);
299 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
302 ok(!lstrcmpW(comment
, empty
),
303 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
304 CoTaskMemFree(comment
);
307 /* Set comment to a simple string */
308 hres
= ITask_SetComment(test_task
, comment_a
);
309 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
310 wine_dbgstr_w(comment_a
), hres
);
311 hres
= ITask_GetComment(test_task
, &comment
);
312 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
315 ok(!lstrcmpW(comment
, comment_a
), "Got %s, expected %s\n",
316 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_a
));
317 CoTaskMemFree(comment
);
320 /* Update comment to a different simple string */
321 hres
= ITask_SetComment(test_task
, comment_b
);
322 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
323 wine_dbgstr_w(comment_b
), hres
);
324 hres
= ITask_GetComment(test_task
, &comment
);
325 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
328 ok(!lstrcmpW(comment
, comment_b
), "Got %s, expected %s\n",
329 wine_dbgstr_w(comment
), wine_dbgstr_w(comment_b
));
330 CoTaskMemFree(comment
);
334 hres
= ITask_SetComment(test_task
, empty
);
335 ok(hres
== S_OK
, "Failed setting comment %s: %08x\n",
336 wine_dbgstr_w(empty
), hres
);
337 hres
= ITask_GetComment(test_task
, &comment
);
338 ok(hres
== S_OK
, "GetComment failed: %08x\n", hres
);
341 ok(!lstrcmpW(comment
, empty
),
342 "Got %s, expected empty string\n", wine_dbgstr_w(comment
));
343 CoTaskMemFree(comment
);
350 static void test_SetMaxRunTime_GetMaxRunTime(void)
356 setup
= setup_task();
357 ok(setup
, "Failed to setup test_task\n");
360 skip("Failed to create task. Skipping tests.\n");
364 /* Default time is 3 days:
365 * 3 days * 24 hours * 60 minutes * 60 seconds * 1000 ms = 259200000 */
367 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
368 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
369 ok(max_run_time
== 259200000, "Expected 259200000: %d\n", max_run_time
);
373 hres
= ITask_SetMaxRunTime(test_task
, 1234);
374 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
375 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
376 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
377 ok(max_run_time
== 1234, "Expected 1234: %d\n", max_run_time
);
379 /* Verify that time can be set to zero */
381 hres
= ITask_SetMaxRunTime(test_task
, 0);
382 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
383 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
384 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
385 ok(max_run_time
== 0, "Expected 0: %d\n", max_run_time
);
387 /* Check resolution by setting time to one */
389 hres
= ITask_SetMaxRunTime(test_task
, 1);
390 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
391 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
392 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
393 ok(max_run_time
== 1, "Expected 1: %d\n", max_run_time
);
395 /* Verify that time can be set to INFINITE */
397 hres
= ITask_SetMaxRunTime(test_task
, INFINITE
);
398 ok(hres
== S_OK
, "Failed to set max runtime: 0x%08x\n", hres
);
399 hres
= ITask_GetMaxRunTime(test_task
, &max_run_time
);
400 ok(hres
== S_OK
, "Failed to get max runtime: 0x%08x\n", hres
);
401 ok(max_run_time
== INFINITE
, "Expected INFINITE: %d\n", max_run_time
);
407 static void test_SetAccountInformation_GetAccountInformation(void)
412 const WCHAR dummy_account_name
[] = {'N', 'o', 'S', 'u', 'c', 'h',
413 'A', 'c', 'c', 'o', 'u', 'n', 't', 0};
414 const WCHAR dummy_account_name_b
[] = {'N', 'o', 'S', 'u', 'c', 'h',
415 'A', 'c', 'c', 'o', 'u', 'n', 't', 'B', 0};
417 setup
= setup_task();
418 ok(setup
, "Failed to setup test_task\n");
421 skip("Failed to create task. Skipping tests.\n");
425 /* Get account information before it is set */
426 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
427 /* WinXP returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): 0x80070002 but
428 * Win2K returns SCHED_E_CANNOT_OPEN_TASK: 0x8004130d
429 * Win9x doesn't support security services */
430 if (hres
== SCHED_E_NO_SECURITY_SERVICES
|| hres
== SCHED_E_SERVICE_NOT_RUNNING
)
432 win_skip("Security services are not supported\n");
436 ok(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
437 hres
== SCHED_E_CANNOT_OPEN_TASK
,
438 "Unset account name generated: 0x%08x\n", hres
);
440 /* Attempt to set to a dummy account without a password */
441 /* This test passes on WinXP but fails on Win2K */
442 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name
, NULL
);
444 "Failed setting dummy account with no password: %08x\n", hres
);
445 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
447 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
448 hres
== SCHED_E_CANNOT_OPEN_TASK
||
449 hres
== 0x200), /* win2k */
450 "GetAccountInformation failed: %08x\n", hres
);
453 ok(!lstrcmpW(account_name
, dummy_account_name
),
454 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
455 wine_dbgstr_w(dummy_account_name
));
456 CoTaskMemFree(account_name
);
459 /* Attempt to set to a dummy account with a (invalid) password */
460 /* This test passes on WinXP but fails on Win2K */
461 hres
= ITask_SetAccountInformation(test_task
, dummy_account_name_b
,
462 dummy_account_name_b
);
464 "Failed setting dummy account with password: %08x\n", hres
);
465 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
467 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
468 hres
== SCHED_E_CANNOT_OPEN_TASK
||
469 hres
== 0x200), /* win2k */
470 "GetAccountInformation failed: %08x\n", hres
);
473 ok(!lstrcmpW(account_name
, dummy_account_name_b
),
474 "Got %s, expected %s\n", wine_dbgstr_w(account_name
),
475 wine_dbgstr_w(dummy_account_name_b
));
476 CoTaskMemFree(account_name
);
479 /* Attempt to set to the local system account */
480 hres
= ITask_SetAccountInformation(test_task
, empty
, NULL
);
481 ok(hres
== S_OK
, "Failed setting system account: %08x\n", hres
);
482 hres
= ITask_GetAccountInformation(test_task
, &account_name
);
484 broken(hres
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
485 hres
== SCHED_E_CANNOT_OPEN_TASK
||
486 hres
== 0x200), /* win2k */
487 "GetAccountInformation failed: %08x\n", hres
);
490 ok(!lstrcmpW(account_name
, empty
),
491 "Got %s, expected empty string\n", wine_dbgstr_w(account_name
));
492 CoTaskMemFree(account_name
);
502 test_SetApplicationName_GetApplicationName();
503 test_CreateTrigger();
504 test_SetParameters_GetParameters();
505 test_SetComment_GetComment();
506 test_SetMaxRunTime_GetMaxRunTime();
507 test_SetAccountInformation_GetAccountInformation();