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 /* allocate some tmp string space */
32 /* FIXME: this is not 100% thread-safe */
33 static char *get_tmp_space(int size)
35 static char *list[16];
40 idx = ++pos % (sizeof(list)/sizeof(list[0]));
41 if ((ret = realloc(list[idx], size)))
46 static const char *dbgstr_w(LPCWSTR str)
52 len = lstrlenW(str) + 1;
53 buf = get_tmp_space(len);
54 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, len, NULL, NULL);
58 static BOOL setup_task(void)
61 const WCHAR task_name[] = {'T','e','s','t','i','n','g', 0};
63 hres = CoCreateInstance(&CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,
64 &IID_ITaskScheduler, (void **) &test_task_scheduler);
67 hres = ITaskScheduler_NewWorkItem(test_task_scheduler, task_name, &CLSID_CTask,
68 &IID_ITask, (IUnknown**)&test_task);
71 ITaskScheduler_Release(test_task_scheduler);
77 static void cleanup_task(void)
79 ITask_Release(test_task);
80 ITaskScheduler_Release(test_task_scheduler);
83 static LPCWSTR path_resolve_name(LPCWSTR base_name)
85 static WCHAR buffer[MAX_PATH];
88 len = SearchPathW(NULL, base_name, NULL, 0, NULL, NULL);
91 else if (len < MAX_PATH)
93 SearchPathW(NULL, base_name, NULL, MAX_PATH, buffer, NULL);
99 static void test_SetApplicationName_GetApplicationName(void)
105 const WCHAR non_application_name[] = {'N','o','S','u','c','h',
106 'A','p','p','l','i','c','a','t','i','o','n', 0};
107 const WCHAR notepad_exe[] = {
108 'n','o','t','e','p','a','d','.','e','x','e', 0};
109 const WCHAR notepad[] = {'n','o','t','e','p','a','d', 0};
111 setup = setup_task();
112 ok(setup, "Failed to setup test_task\n");
115 skip("Failed to create task. Skipping tests.\n");
119 /* Attempt getting before setting application name */
120 hres = ITask_GetApplicationName(test_task, &stored_name);
121 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
124 todo_wine ok(!lstrcmpW(stored_name, empty),
125 "Got %s, expected empty string\n", dbgstr_w(stored_name));
126 CoTaskMemFree(stored_name);
129 /* Set application name to a non-existent application and then get
130 * the application name that is actually stored */
131 hres = ITask_SetApplicationName(test_task, non_application_name);
132 todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n",
133 dbgstr_w(non_application_name), hres);
134 hres = ITask_GetApplicationName(test_task, &stored_name);
135 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
138 full_name = path_resolve_name(non_application_name);
139 todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n",
140 dbgstr_w(stored_name), dbgstr_w(full_name));
141 CoTaskMemFree(stored_name);
144 /* Set a valid application name with program type extension and then
145 * get the stored name */
146 hres = ITask_SetApplicationName(test_task, notepad_exe);
147 todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n",
148 dbgstr_w(notepad_exe), hres);
149 hres = ITask_GetApplicationName(test_task, &stored_name);
150 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
153 full_name = path_resolve_name(notepad_exe);
154 todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n",
155 dbgstr_w(stored_name), dbgstr_w(full_name));
156 CoTaskMemFree(stored_name);
159 /* Set a valid application name without program type extension and
160 * then get the stored name */
161 hres = ITask_SetApplicationName(test_task, notepad);
162 todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(notepad), hres);
163 hres = ITask_GetApplicationName(test_task, &stored_name);
164 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
167 full_name = path_resolve_name(notepad);
168 todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n",
169 dbgstr_w(stored_name), dbgstr_w(full_name));
170 CoTaskMemFree(stored_name);
173 /* After having a valid application name set, set application name
174 * to a non-existant application and then get the name that is
176 hres = ITask_SetApplicationName(test_task, non_application_name);
177 todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n",
178 dbgstr_w(non_application_name), hres);
179 hres = ITask_GetApplicationName(test_task, &stored_name);
180 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
183 full_name = path_resolve_name(non_application_name);
184 todo_wine ok(!lstrcmpW(stored_name, full_name), "Got %s, expected %s\n",
185 dbgstr_w(stored_name), dbgstr_w(full_name));
186 CoTaskMemFree(stored_name);
189 /* Clear application name */
190 hres = ITask_SetApplicationName(test_task, empty);
191 todo_wine ok(hres == S_OK, "Failed setting name %s: %08x\n", dbgstr_w(empty), hres);
192 hres = ITask_GetApplicationName(test_task, &stored_name);
193 todo_wine ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
196 todo_wine ok(!lstrcmpW(stored_name, empty),
197 "Got %s, expected empty string\n", dbgstr_w(stored_name));
198 CoTaskMemFree(stored_name);
205 static void test_CreateTrigger(void)
210 ITaskTrigger *test_trigger;
212 setup = setup_task();
213 ok(setup, "Failed to setup test_task\n");
216 skip("Failed to create task. Skipping tests.\n");
220 hres = ITask_CreateTrigger(test_task, &trigger_index, &test_trigger);
221 todo_wine ok(hres == S_OK, "Failed to create trigger: 0x%08x\n", hres);
228 ITaskTrigger_Release(test_trigger);
233 static void test_SetParameters_GetParameters(void)
238 const WCHAR parameters_a[] = {'f','o','o','.','t','x','t', 0};
239 const WCHAR parameters_b[] = {'f','o','o','.','t','x','t',' ',
240 'b','a','r','.','t','x','t', 0};
242 setup = setup_task();
243 ok(setup, "Failed to setup test_task\n");
246 skip("Failed to create task. Skipping tests.\n");
250 /* Get parameters before setting them */
251 hres = ITask_GetParameters(test_task, ¶meters);
252 todo_wine ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
255 todo_wine ok(!lstrcmpW(parameters, empty),
256 "Got %s, expected empty string\n", dbgstr_w(parameters));
257 CoTaskMemFree(parameters);
260 /* Set parameters to a simple string */
261 hres = ITask_SetParameters(test_task, parameters_a);
262 todo_wine ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
263 dbgstr_w(parameters_a), hres);
264 hres = ITask_GetParameters(test_task, ¶meters);
265 todo_wine ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
268 todo_wine ok(!lstrcmpW(parameters, parameters_a), "Got %s, expected %s\n",
269 dbgstr_w(parameters), dbgstr_w(parameters_a));
270 CoTaskMemFree(parameters);
273 /* Update parameters to a different simple string */
274 hres = ITask_SetParameters(test_task, parameters_b);
275 todo_wine ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
276 dbgstr_w(parameters_b), hres);
277 hres = ITask_GetParameters(test_task, ¶meters);
278 todo_wine ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
281 todo_wine ok(!lstrcmpW(parameters, parameters_b), "Got %s, expected %s\n",
282 dbgstr_w(parameters), dbgstr_w(parameters_b));
283 CoTaskMemFree(parameters);
286 /* Clear parameters */
287 hres = ITask_SetParameters(test_task, empty);
288 todo_wine ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
289 dbgstr_w(empty), hres);
290 hres = ITask_GetParameters(test_task, ¶meters);
291 todo_wine ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
294 todo_wine ok(!lstrcmpW(parameters, empty),
295 "Got %s, expected empty string\n", dbgstr_w(parameters));
296 CoTaskMemFree(parameters);
303 static void test_SetComment_GetComment(void)
308 const WCHAR comment_a[] = {'C','o','m','m','e','n','t','.', 0};
309 const WCHAR comment_b[] = {'L','o','n','g','e','r',' ',
310 'c','o','m','m','e','n','t','.', 0};
312 setup = setup_task();
313 ok(setup, "Failed to setup test_task\n");
316 skip("Failed to create task. Skipping tests.\n");
320 /* Get comment before setting it*/
321 hres = ITask_GetComment(test_task, &comment);
322 todo_wine ok(hres == S_OK, "GetComment failed: %08x\n", hres);
325 todo_wine ok(!lstrcmpW(comment, empty),
326 "Got %s, expected empty string\n", dbgstr_w(comment));
327 CoTaskMemFree(comment);
330 /* Set comment to a simple string */
331 hres = ITask_SetComment(test_task, comment_a);
332 todo_wine ok(hres == S_OK, "Failed setting comment %s: %08x\n",
333 dbgstr_w(comment_a), hres);
334 hres = ITask_GetComment(test_task, &comment);
335 todo_wine ok(hres == S_OK, "GetComment failed: %08x\n", hres);
338 todo_wine ok(!lstrcmpW(comment, comment_a), "Got %s, expected %s\n",
339 dbgstr_w(comment), dbgstr_w(comment_a));
340 CoTaskMemFree(comment);
343 /* Update comment to a different simple string */
344 hres = ITask_SetComment(test_task, comment_b);
345 todo_wine ok(hres == S_OK, "Failed setting comment %s: %08x\n",
346 dbgstr_w(comment_b), hres);
347 hres = ITask_GetComment(test_task, &comment);
348 todo_wine ok(hres == S_OK, "GetComment failed: %08x\n", hres);
351 todo_wine ok(!lstrcmpW(comment, comment_b), "Got %s, expected %s\n",
352 dbgstr_w(comment), dbgstr_w(comment_b));
353 CoTaskMemFree(comment);
357 hres = ITask_SetComment(test_task, empty);
358 todo_wine ok(hres == S_OK, "Failed setting comment %s: %08x\n",
359 dbgstr_w(empty), hres);
360 hres = ITask_GetComment(test_task, &comment);
361 todo_wine ok(hres == S_OK, "GetComment failed: %08x\n", hres);
364 todo_wine ok(!lstrcmpW(comment, empty),
365 "Got %s, expected empty string\n", dbgstr_w(comment));
366 CoTaskMemFree(comment);
373 static void test_SetMaxRunTime_GetMaxRunTime(void)
379 setup = setup_task();
380 ok(setup, "Failed to setup test_task\n");
383 skip("Failed to create task. Skipping tests.\n");
387 /* Default time is 3 days:
388 * 3 days * 24 hours * 60 minutes * 60 seconds * 1000 ms = 259200000 */
390 hres = ITask_GetMaxRunTime(test_task, &max_run_time);
391 todo_wine ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
392 todo_wine ok(max_run_time == 259200000, "Expected 259200000: %d\n", max_run_time);
396 hres = ITask_SetMaxRunTime(test_task, 1234);
397 todo_wine ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
398 hres = ITask_GetMaxRunTime(test_task, &max_run_time);
399 todo_wine ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
400 todo_wine ok(max_run_time == 1234, "Expected 1234: %d\n", max_run_time);
402 /* Verify that time can be set to zero */
404 hres = ITask_SetMaxRunTime(test_task, 0);
405 todo_wine ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
406 hres = ITask_GetMaxRunTime(test_task, &max_run_time);
407 todo_wine ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
408 todo_wine ok(max_run_time == 0, "Expected 0: %d\n", max_run_time);
410 /* Check resolution by setting time to one */
412 hres = ITask_SetMaxRunTime(test_task, 1);
413 todo_wine ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
414 hres = ITask_GetMaxRunTime(test_task, &max_run_time);
415 todo_wine ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
416 todo_wine ok(max_run_time == 1, "Expected 1: %d\n", max_run_time);
418 /* Verify that time can be set to INFINITE */
420 hres = ITask_SetMaxRunTime(test_task, INFINITE);
421 todo_wine ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
422 hres = ITask_GetMaxRunTime(test_task, &max_run_time);
423 todo_wine ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
424 todo_wine ok(max_run_time == INFINITE, "Expected INFINITE: %d\n", max_run_time);
430 static void test_SetAccountInformation_GetAccountInformation(void)
435 const WCHAR dummy_account_name[] = {'N', 'o', 'S', 'u', 'c', 'h',
436 'A', 'c', 'c', 'o', 'u', 'n', 't', 0};
438 setup = setup_task();
439 ok(setup, "Failed to setup test_task\n");
442 skip("Failed to create task. Skipping tests.\n");
446 /* Get account information before it is set */
447 hres = ITask_GetAccountInformation(test_task, &account_name);
448 /* WinXP returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): 0x80070002 but
449 * Win2K returns SCHED_E_CANNOT_OPEN_TASK: 0x8004130d */
450 todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
451 hres == SCHED_E_CANNOT_OPEN_TASK,
452 "Unset account name generated: 0x%08x\n", hres);
454 /* Attempt to set to a dummy account without a password */
455 /* This test passes on WinXP but fails on Win2K */
456 hres = ITask_SetAccountInformation(test_task, dummy_account_name, NULL);
457 todo_wine ok(hres == S_OK,
458 "Failed setting dummy account with no password: %08x\n", hres);
459 hres = ITask_GetAccountInformation(test_task, &account_name);
460 todo_wine ok(hres == S_OK, "GetAccountInformation failed: %08x\n", hres);
463 todo_wine ok(!lstrcmpW(account_name, dummy_account_name),
464 "Got %s, expected %s\n", dbgstr_w(account_name),
465 dbgstr_w(dummy_account_name));
466 CoTaskMemFree(account_name);
469 /* Attempt to set to a dummy account with a (invalid) password */
470 /* This test passes on WinXP but fails on Win2K */
471 hres = ITask_SetAccountInformation(test_task, dummy_account_name,
473 todo_wine ok(hres == S_OK,
474 "Failed setting dummy account with password: %08x\n", hres);
475 hres = ITask_GetAccountInformation(test_task, &account_name);
476 todo_wine ok(hres == S_OK, "GetAccountInformation failed: %08x\n", hres);
479 todo_wine ok(!lstrcmpW(account_name, dummy_account_name),
480 "Got %s, expected %s\n", dbgstr_w(account_name),
481 dbgstr_w(dummy_account_name));
482 CoTaskMemFree(account_name);
485 /* Attempt to set to the local system account */
486 hres = ITask_SetAccountInformation(test_task, empty, NULL);
487 todo_wine ok(hres == S_OK, "Failed setting system account: %08x\n", hres);
488 hres = ITask_GetAccountInformation(test_task, &account_name);
489 todo_wine ok(hres == S_OK, "GetAccountInformation failed: %08x\n", hres);
492 todo_wine ok(!lstrcmpW(account_name, empty),
493 "Got %s, expected empty string\n", dbgstr_w(account_name));
494 CoTaskMemFree(account_name);
504 test_SetApplicationName_GetApplicationName();
505 test_CreateTrigger();
506 test_SetParameters_GetParameters();
507 test_SetComment_GetComment();
508 test_SetMaxRunTime_GetMaxRunTime();
509 test_SetAccountInformation_GetAccountInformation();