2008-08-19 23:58:53 +02:00
|
|
|
/*
|
|
|
|
* Test suite for Task interface
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Google (Roy Shea)
|
2018-04-20 10:37:08 +02:00
|
|
|
* Copyright (C) 2018 Dmitry Timoshkov
|
2008-08-19 23:58:53 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "corerror.h"
|
|
|
|
#include "mstask.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
static ITaskScheduler *scheduler;
|
|
|
|
static const WCHAR task_name[] = {'T','e','s','t','i','n','g',0};
|
2008-08-19 23:58:53 +02:00
|
|
|
static const WCHAR empty[] = {0};
|
|
|
|
|
2021-05-21 00:13:52 +02:00
|
|
|
extern HRESULT taskscheduler_delete(ITaskScheduler*, const WCHAR*);
|
|
|
|
|
|
|
|
|
2008-08-19 23:58:53 +02:00
|
|
|
static LPCWSTR path_resolve_name(LPCWSTR base_name)
|
|
|
|
{
|
|
|
|
static WCHAR buffer[MAX_PATH];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = SearchPathW(NULL, base_name, NULL, 0, NULL, NULL);
|
|
|
|
if (len == 0)
|
|
|
|
return base_name;
|
|
|
|
else if (len < MAX_PATH)
|
|
|
|
{
|
|
|
|
SearchPathW(NULL, base_name, NULL, MAX_PATH, buffer, NULL);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SetApplicationName_GetApplicationName(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-19 23:58:53 +02:00
|
|
|
HRESULT hres;
|
|
|
|
LPWSTR stored_name;
|
|
|
|
LPCWSTR full_name;
|
|
|
|
const WCHAR non_application_name[] = {'N','o','S','u','c','h',
|
|
|
|
'A','p','p','l','i','c','a','t','i','o','n', 0};
|
|
|
|
const WCHAR notepad_exe[] = {
|
|
|
|
'n','o','t','e','p','a','d','.','e','x','e', 0};
|
|
|
|
const WCHAR notepad[] = {'n','o','t','e','p','a','d', 0};
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-19 23:58:53 +02:00
|
|
|
|
|
|
|
/* Attempt getting before setting application name */
|
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-09-11 11:49:27 +02:00
|
|
|
ok(!lstrcmpiW(stored_name, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(stored_name));
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:17 +02:00
|
|
|
/* Set application name to a nonexistent application and then get
|
2008-08-19 23:58:53 +02:00
|
|
|
* the application name that is actually stored */
|
|
|
|
hres = ITask_SetApplicationName(test_task, non_application_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "Failed setting name %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(non_application_name), hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
full_name = path_resolve_name(non_application_name);
|
2008-09-11 11:49:27 +02:00
|
|
|
ok(!lstrcmpiW(stored_name, full_name), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(stored_name), wine_dbgstr_w(full_name));
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a valid application name with program type extension and then
|
|
|
|
* get the stored name */
|
|
|
|
hres = ITask_SetApplicationName(test_task, notepad_exe);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "Failed setting name %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(notepad_exe), hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
full_name = path_resolve_name(notepad_exe);
|
2008-09-11 11:49:27 +02:00
|
|
|
ok(!lstrcmpiW(stored_name, full_name), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(stored_name), wine_dbgstr_w(full_name));
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a valid application name without program type extension and
|
|
|
|
* then get the stored name */
|
|
|
|
hres = ITask_SetApplicationName(test_task, notepad);
|
2009-08-19 13:36:50 +02:00
|
|
|
ok(hres == S_OK, "Failed setting name %s: %08x\n", wine_dbgstr_w(notepad), hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-09-17 16:23:08 +02:00
|
|
|
full_name = path_resolve_name(notepad_exe); /* XP SP1 appends .exe */
|
|
|
|
if (lstrcmpiW(stored_name, full_name) != 0)
|
|
|
|
{
|
|
|
|
full_name = path_resolve_name(notepad);
|
|
|
|
ok(!lstrcmpiW(stored_name, full_name), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(stored_name), wine_dbgstr_w(full_name));
|
2008-09-17 16:23:08 +02:00
|
|
|
}
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:17 +02:00
|
|
|
/* After having a valid application name set, set application the name
|
|
|
|
* to a nonexistent application and then get the name that is
|
2008-08-19 23:58:53 +02:00
|
|
|
* actually stored */
|
|
|
|
hres = ITask_SetApplicationName(test_task, non_application_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "Failed setting name %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(non_application_name), hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
|
|
|
full_name = path_resolve_name(non_application_name);
|
2008-09-11 11:49:27 +02:00
|
|
|
ok(!lstrcmpiW(stored_name, full_name), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(stored_name), wine_dbgstr_w(full_name));
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear application name */
|
|
|
|
hres = ITask_SetApplicationName(test_task, empty);
|
2009-08-19 13:36:50 +02:00
|
|
|
ok(hres == S_OK, "Failed setting name %s: %08x\n", wine_dbgstr_w(empty), hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
hres = ITask_GetApplicationName(test_task, &stored_name);
|
2008-08-21 10:09:18 +02:00
|
|
|
ok(hres == S_OK, "GetApplicationName failed: %08x\n", hres);
|
2008-08-19 23:58:53 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-09-11 11:49:27 +02:00
|
|
|
ok(!lstrcmpiW(stored_name, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(stored_name));
|
2008-08-19 23:58:53 +02:00
|
|
|
CoTaskMemFree(stored_name);
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-19 23:58:53 +02:00
|
|
|
}
|
|
|
|
|
2008-08-20 00:01:07 +02:00
|
|
|
static void test_CreateTrigger(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-20 00:01:07 +02:00
|
|
|
HRESULT hres;
|
|
|
|
WORD trigger_index;
|
|
|
|
ITaskTrigger *test_trigger;
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-20 00:01:07 +02:00
|
|
|
|
|
|
|
hres = ITask_CreateTrigger(test_task, &trigger_index, &test_trigger);
|
2008-08-22 21:52:46 +02:00
|
|
|
ok(hres == S_OK, "Failed to create trigger: 0x%08x\n", hres);
|
2008-08-20 00:01:07 +02:00
|
|
|
|
|
|
|
ITaskTrigger_Release(test_trigger);
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-20 00:01:07 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 02:44:30 +02:00
|
|
|
static void test_SetParameters_GetParameters(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-21 02:44:30 +02:00
|
|
|
HRESULT hres;
|
|
|
|
LPWSTR parameters;
|
|
|
|
const WCHAR parameters_a[] = {'f','o','o','.','t','x','t', 0};
|
|
|
|
const WCHAR parameters_b[] = {'f','o','o','.','t','x','t',' ',
|
|
|
|
'b','a','r','.','t','x','t', 0};
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-21 02:44:30 +02:00
|
|
|
|
|
|
|
/* Get parameters before setting them */
|
|
|
|
hres = ITask_GetParameters(test_task, ¶meters);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(!lstrcmpW(parameters, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(parameters));
|
2008-08-21 02:44:30 +02:00
|
|
|
CoTaskMemFree(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set parameters to a simple string */
|
|
|
|
hres = ITask_SetParameters(test_task, parameters_a);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(parameters_a), hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
hres = ITask_GetParameters(test_task, ¶meters);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(!lstrcmpW(parameters, parameters_a), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(parameters), wine_dbgstr_w(parameters_a));
|
2008-08-21 02:44:30 +02:00
|
|
|
CoTaskMemFree(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update parameters to a different simple string */
|
|
|
|
hres = ITask_SetParameters(test_task, parameters_b);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(parameters_b), hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
hres = ITask_GetParameters(test_task, ¶meters);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(!lstrcmpW(parameters, parameters_b), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(parameters), wine_dbgstr_w(parameters_b));
|
2008-08-21 02:44:30 +02:00
|
|
|
CoTaskMemFree(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear parameters */
|
|
|
|
hres = ITask_SetParameters(test_task, empty);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "Failed setting parameters %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(empty), hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
hres = ITask_GetParameters(test_task, ¶meters);
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(hres == S_OK, "GetParameters failed: %08x\n", hres);
|
2008-08-21 02:44:30 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:07 +02:00
|
|
|
ok(!lstrcmpW(parameters, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(parameters));
|
2008-08-21 02:44:30 +02:00
|
|
|
CoTaskMemFree(parameters);
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-21 02:44:30 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 02:45:03 +02:00
|
|
|
static void test_SetComment_GetComment(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-21 02:45:03 +02:00
|
|
|
HRESULT hres;
|
|
|
|
LPWSTR comment;
|
|
|
|
const WCHAR comment_a[] = {'C','o','m','m','e','n','t','.', 0};
|
|
|
|
const WCHAR comment_b[] = {'L','o','n','g','e','r',' ',
|
|
|
|
'c','o','m','m','e','n','t','.', 0};
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-21 02:45:03 +02:00
|
|
|
|
|
|
|
/* Get comment before setting it*/
|
|
|
|
hres = ITask_GetComment(test_task, &comment);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "GetComment failed: %08x\n", hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(!lstrcmpW(comment, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(comment));
|
2008-08-21 02:45:03 +02:00
|
|
|
CoTaskMemFree(comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set comment to a simple string */
|
|
|
|
hres = ITask_SetComment(test_task, comment_a);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "Failed setting comment %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(comment_a), hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
hres = ITask_GetComment(test_task, &comment);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "GetComment failed: %08x\n", hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(!lstrcmpW(comment, comment_a), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(comment), wine_dbgstr_w(comment_a));
|
2008-08-21 02:45:03 +02:00
|
|
|
CoTaskMemFree(comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update comment to a different simple string */
|
|
|
|
hres = ITask_SetComment(test_task, comment_b);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "Failed setting comment %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(comment_b), hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
hres = ITask_GetComment(test_task, &comment);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "GetComment failed: %08x\n", hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(!lstrcmpW(comment, comment_b), "Got %s, expected %s\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(comment), wine_dbgstr_w(comment_b));
|
2008-08-21 02:45:03 +02:00
|
|
|
CoTaskMemFree(comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear comment */
|
|
|
|
hres = ITask_SetComment(test_task, empty);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "Failed setting comment %s: %08x\n",
|
2009-08-19 13:36:50 +02:00
|
|
|
wine_dbgstr_w(empty), hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
hres = ITask_GetComment(test_task, &comment);
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(hres == S_OK, "GetComment failed: %08x\n", hres);
|
2008-08-21 02:45:03 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:05:43 +02:00
|
|
|
ok(!lstrcmpW(comment, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(comment));
|
2008-08-21 02:45:03 +02:00
|
|
|
CoTaskMemFree(comment);
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-21 02:45:03 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 02:46:05 +02:00
|
|
|
static void test_SetMaxRunTime_GetMaxRunTime(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-21 02:46:05 +02:00
|
|
|
HRESULT hres;
|
|
|
|
DWORD max_run_time;
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-21 02:46:05 +02:00
|
|
|
|
|
|
|
/* Default time is 3 days:
|
|
|
|
* 3 days * 24 hours * 60 minutes * 60 seconds * 1000 ms = 259200000 */
|
|
|
|
max_run_time = 0;
|
|
|
|
hres = ITask_GetMaxRunTime(test_task, &max_run_time);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
|
|
|
|
ok(max_run_time == 259200000, "Expected 259200000: %d\n", max_run_time);
|
2008-08-21 02:46:05 +02:00
|
|
|
|
|
|
|
/* Basic set test */
|
|
|
|
max_run_time = 0;
|
|
|
|
hres = ITask_SetMaxRunTime(test_task, 1234);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
|
2008-08-21 02:46:05 +02:00
|
|
|
hres = ITask_GetMaxRunTime(test_task, &max_run_time);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
|
|
|
|
ok(max_run_time == 1234, "Expected 1234: %d\n", max_run_time);
|
2008-08-21 02:46:05 +02:00
|
|
|
|
|
|
|
/* Verify that time can be set to zero */
|
|
|
|
max_run_time = 1;
|
|
|
|
hres = ITask_SetMaxRunTime(test_task, 0);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
|
2008-08-21 02:46:05 +02:00
|
|
|
hres = ITask_GetMaxRunTime(test_task, &max_run_time);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
|
|
|
|
ok(max_run_time == 0, "Expected 0: %d\n", max_run_time);
|
2008-08-21 02:46:05 +02:00
|
|
|
|
|
|
|
/* Check resolution by setting time to one */
|
|
|
|
max_run_time = 0;
|
|
|
|
hres = ITask_SetMaxRunTime(test_task, 1);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
|
2008-08-21 02:46:05 +02:00
|
|
|
hres = ITask_GetMaxRunTime(test_task, &max_run_time);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
|
|
|
|
ok(max_run_time == 1, "Expected 1: %d\n", max_run_time);
|
2008-08-21 02:46:05 +02:00
|
|
|
|
|
|
|
/* Verify that time can be set to INFINITE */
|
|
|
|
max_run_time = 0;
|
|
|
|
hres = ITask_SetMaxRunTime(test_task, INFINITE);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to set max runtime: 0x%08x\n", hres);
|
2008-08-21 02:46:05 +02:00
|
|
|
hres = ITask_GetMaxRunTime(test_task, &max_run_time);
|
2008-08-21 22:06:19 +02:00
|
|
|
ok(hres == S_OK, "Failed to get max runtime: 0x%08x\n", hres);
|
|
|
|
ok(max_run_time == INFINITE, "Expected INFINITE: %d\n", max_run_time);
|
2008-08-21 02:46:05 +02:00
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-21 02:46:05 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 02:46:43 +02:00
|
|
|
static void test_SetAccountInformation_GetAccountInformation(void)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2008-08-21 02:46:43 +02:00
|
|
|
HRESULT hres;
|
|
|
|
LPWSTR account_name;
|
|
|
|
const WCHAR dummy_account_name[] = {'N', 'o', 'S', 'u', 'c', 'h',
|
|
|
|
'A', 'c', 'c', 'o', 'u', 'n', 't', 0};
|
2008-08-21 22:07:00 +02:00
|
|
|
const WCHAR dummy_account_name_b[] = {'N', 'o', 'S', 'u', 'c', 'h',
|
|
|
|
'A', 'c', 'c', 'o', 'u', 'n', 't', 'B', 0};
|
2008-08-21 02:46:43 +02:00
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hres = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hres == S_OK, "Failed to setup test_task\n");
|
2008-08-21 02:46:43 +02:00
|
|
|
|
|
|
|
/* Get account information before it is set */
|
|
|
|
hres = ITask_GetAccountInformation(test_task, &account_name);
|
|
|
|
/* WinXP returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): 0x80070002 but
|
2008-08-27 10:59:56 +02:00
|
|
|
* Win2K returns SCHED_E_CANNOT_OPEN_TASK: 0x8004130d
|
|
|
|
* Win9x doesn't support security services */
|
2009-12-22 14:01:22 +01:00
|
|
|
if (hres == SCHED_E_NO_SECURITY_SERVICES || hres == SCHED_E_SERVICE_NOT_RUNNING)
|
2008-08-27 10:59:56 +02:00
|
|
|
{
|
|
|
|
win_skip("Security services are not supported\n");
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-27 10:59:56 +02:00
|
|
|
}
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
2008-08-21 02:46:43 +02:00
|
|
|
hres == SCHED_E_CANNOT_OPEN_TASK,
|
|
|
|
"Unset account name generated: 0x%08x\n", hres);
|
|
|
|
|
|
|
|
/* Attempt to set to a dummy account without a password */
|
|
|
|
/* This test passes on WinXP but fails on Win2K */
|
|
|
|
hres = ITask_SetAccountInformation(test_task, dummy_account_name, NULL);
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(hres == S_OK,
|
2008-08-21 02:46:43 +02:00
|
|
|
"Failed setting dummy account with no password: %08x\n", hres);
|
|
|
|
hres = ITask_GetAccountInformation(test_task, &account_name);
|
2008-09-11 09:42:30 +02:00
|
|
|
ok(hres == S_OK ||
|
2008-09-17 16:23:08 +02:00
|
|
|
broken(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
2010-02-05 11:35:38 +01:00
|
|
|
hres == SCHED_E_CANNOT_OPEN_TASK ||
|
|
|
|
hres == 0x200), /* win2k */
|
2008-09-11 09:42:30 +02:00
|
|
|
"GetAccountInformation failed: %08x\n", hres);
|
2008-08-21 02:46:43 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(!lstrcmpW(account_name, dummy_account_name),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected %s\n", wine_dbgstr_w(account_name),
|
|
|
|
wine_dbgstr_w(dummy_account_name));
|
2008-08-21 02:46:43 +02:00
|
|
|
CoTaskMemFree(account_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to set to a dummy account with a (invalid) password */
|
|
|
|
/* This test passes on WinXP but fails on Win2K */
|
2008-08-21 22:07:00 +02:00
|
|
|
hres = ITask_SetAccountInformation(test_task, dummy_account_name_b,
|
|
|
|
dummy_account_name_b);
|
|
|
|
ok(hres == S_OK,
|
2008-08-21 02:46:43 +02:00
|
|
|
"Failed setting dummy account with password: %08x\n", hres);
|
|
|
|
hres = ITask_GetAccountInformation(test_task, &account_name);
|
2008-09-11 09:42:30 +02:00
|
|
|
ok(hres == S_OK ||
|
2008-09-17 16:23:08 +02:00
|
|
|
broken(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
2010-02-05 11:35:38 +01:00
|
|
|
hres == SCHED_E_CANNOT_OPEN_TASK ||
|
|
|
|
hres == 0x200), /* win2k */
|
2008-09-11 09:42:30 +02:00
|
|
|
"GetAccountInformation failed: %08x\n", hres);
|
2008-08-21 02:46:43 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(!lstrcmpW(account_name, dummy_account_name_b),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected %s\n", wine_dbgstr_w(account_name),
|
|
|
|
wine_dbgstr_w(dummy_account_name_b));
|
2008-08-21 02:46:43 +02:00
|
|
|
CoTaskMemFree(account_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to set to the local system account */
|
|
|
|
hres = ITask_SetAccountInformation(test_task, empty, NULL);
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(hres == S_OK, "Failed setting system account: %08x\n", hres);
|
2008-08-21 02:46:43 +02:00
|
|
|
hres = ITask_GetAccountInformation(test_task, &account_name);
|
2008-09-11 09:42:30 +02:00
|
|
|
ok(hres == S_OK ||
|
2008-09-17 16:23:08 +02:00
|
|
|
broken(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
|
2010-02-05 11:35:38 +01:00
|
|
|
hres == SCHED_E_CANNOT_OPEN_TASK ||
|
|
|
|
hres == 0x200), /* win2k */
|
2008-09-11 09:42:30 +02:00
|
|
|
"GetAccountInformation failed: %08x\n", hres);
|
2008-08-21 02:46:43 +02:00
|
|
|
if (hres == S_OK)
|
|
|
|
{
|
2008-08-21 22:07:00 +02:00
|
|
|
ok(!lstrcmpW(account_name, empty),
|
2009-08-19 13:36:50 +02:00
|
|
|
"Got %s, expected empty string\n", wine_dbgstr_w(account_name));
|
2008-08-21 02:46:43 +02:00
|
|
|
CoTaskMemFree(account_name);
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2008-08-21 02:46:43 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 10:37:08 +02:00
|
|
|
static void test_task_state(void)
|
2018-03-30 10:58:39 +02:00
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask *test_task;
|
2018-04-20 10:37:08 +02:00
|
|
|
HRESULT hr, status;
|
2018-04-20 10:37:21 +02:00
|
|
|
DWORD flags, val;
|
2018-04-20 10:37:18 +02:00
|
|
|
WORD val1, val2;
|
2018-04-20 10:37:27 +02:00
|
|
|
SYSTEMTIME st;
|
2018-03-30 10:58:39 +02:00
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
hr = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&test_task);
|
|
|
|
ok(hr == S_OK, "Failed to setup test_task\n");
|
2018-03-30 10:58:39 +02:00
|
|
|
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetFlags(test_task, NULL);
|
|
|
|
|
|
|
|
flags = 0xdeadbeef;
|
|
|
|
hr = ITask_GetFlags(test_task, &flags);
|
|
|
|
ok(hr == S_OK, "GetFlags error %#x\n", hr);
|
|
|
|
ok(flags == 0, "got %#x\n", flags);
|
|
|
|
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetTaskFlags(test_task, NULL);
|
|
|
|
|
|
|
|
flags = 0xdeadbeef;
|
|
|
|
hr = ITask_GetTaskFlags(test_task, &flags);
|
|
|
|
ok(hr == S_OK, "GetTaskFlags error %#x\n", hr);
|
|
|
|
ok(flags == 0, "got %#x\n", flags);
|
|
|
|
|
2018-04-20 10:37:08 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetStatus(test_task, NULL);
|
|
|
|
|
|
|
|
status = 0xdeadbeef;
|
|
|
|
hr = ITask_GetStatus(test_task, &status);
|
2018-04-25 05:34:28 +02:00
|
|
|
ok(hr == S_OK, "GetStatus error %#x\n", hr);
|
2018-04-20 10:37:08 +02:00
|
|
|
ok(status == SCHED_S_TASK_NOT_SCHEDULED, "got %#x\n", status);
|
|
|
|
|
2018-04-20 10:37:12 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetErrorRetryCount(test_task, NULL);
|
|
|
|
|
|
|
|
hr = ITask_GetErrorRetryCount(test_task, &val1);
|
|
|
|
ok(hr == E_NOTIMPL, "got %#x\n", hr);
|
|
|
|
|
2018-04-20 10:37:15 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetErrorRetryInterval(test_task, NULL);
|
|
|
|
|
|
|
|
hr = ITask_GetErrorRetryInterval(test_task, &val1);
|
|
|
|
ok(hr == E_NOTIMPL, "got %#x\n", hr);
|
|
|
|
|
2018-04-20 10:37:18 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetIdleWait(test_task, NULL, NULL);
|
|
|
|
|
|
|
|
val1 = 0xdead;
|
|
|
|
val2 = 0xbeef;
|
|
|
|
hr = ITask_GetIdleWait(test_task, &val1, &val2);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(val1 == 10, "got %u\n", val1);
|
|
|
|
ok(val2 == 60, "got %u\n", val2);
|
|
|
|
|
2018-04-20 10:37:21 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetPriority(test_task, NULL);
|
|
|
|
|
|
|
|
val = 0xdeadbeef;
|
|
|
|
hr = ITask_GetPriority(test_task, &val);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(val == NORMAL_PRIORITY_CLASS, "got %#x\n", val);
|
|
|
|
|
2018-04-20 10:37:24 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetExitCode(test_task, NULL);
|
|
|
|
|
|
|
|
val = 0xdeadbeef;
|
|
|
|
hr = ITask_GetExitCode(test_task, &val);
|
|
|
|
ok(hr == SCHED_S_TASK_HAS_NOT_RUN, "got %#x\n", hr);
|
|
|
|
ok(val == 0, "got %#x\n", val);
|
|
|
|
|
2018-04-20 10:37:27 +02:00
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetMostRecentRunTime(test_task, NULL);
|
|
|
|
|
|
|
|
memset(&st, 0xff, sizeof(st));
|
|
|
|
hr = ITask_GetMostRecentRunTime(test_task, &st);
|
|
|
|
ok(hr == SCHED_S_TASK_HAS_NOT_RUN, "got %#x\n", hr);
|
|
|
|
ok(st.wYear == 0, "got %u\n", st.wYear);
|
|
|
|
ok(st.wMonth == 0, "got %u\n", st.wMonth);
|
|
|
|
ok(st.wDay == 0, "got %u\n", st.wDay);
|
|
|
|
ok(st.wHour == 0, "got %u\n", st.wHour);
|
|
|
|
ok(st.wMinute == 0, "got %u\n", st.wMinute);
|
|
|
|
ok(st.wSecond == 0, "got %u\n", st.wSecond);
|
|
|
|
|
2018-05-14 09:49:10 +02:00
|
|
|
ITask_Release(test_task);
|
2018-03-30 10:58:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 06:36:47 +02:00
|
|
|
static void save_job(ITask *task)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IPersistFile *pfile;
|
|
|
|
|
|
|
|
hr = ITask_QueryInterface(task, &IID_IPersistFile, (void **)&pfile);
|
|
|
|
ok(hr == S_OK, "QueryInterface error %#x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistFile_Save(pfile, NULL, FALSE);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
IPersistFile_Release(pfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_Run(void)
|
|
|
|
{
|
|
|
|
static const WCHAR wine_test_runW[] = { 'w','i','n','e','_','t','e','s','t','_','r','u','n',0 };
|
|
|
|
static const WCHAR cmdW[] = { 'c','m','d','.','e','x','e',0 };
|
|
|
|
ITask *task;
|
|
|
|
ITaskTrigger *trigger;
|
|
|
|
WORD idx, i;
|
|
|
|
TASK_TRIGGER trigger_data;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
HRESULT hr, status;
|
|
|
|
|
|
|
|
/* cleanup after previous runs */
|
2021-05-21 00:13:52 +02:00
|
|
|
taskscheduler_delete(scheduler, wine_test_runW);
|
2018-05-11 06:36:47 +02:00
|
|
|
|
|
|
|
hr = ITaskScheduler_NewWorkItem(scheduler, wine_test_runW, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_Run(task);
|
|
|
|
ok(hr == SCHED_E_TASK_NOT_READY, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_Terminate(task);
|
|
|
|
ok(hr == SCHED_E_TASK_NOT_RUNNING, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(status == SCHED_S_TASK_NOT_SCHEDULED, "got %#x\n", status);
|
|
|
|
|
|
|
|
save_job(task);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(status == SCHED_S_TASK_NOT_SCHEDULED, "got %#x\n", status);
|
|
|
|
|
|
|
|
hr = ITask_CreateTrigger(task, &idx, &trigger);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
memset(&trigger_data, 0, sizeof(trigger_data));
|
|
|
|
trigger_data.cbTriggerSize = sizeof(trigger_data);
|
|
|
|
trigger_data.Reserved1 = 0;
|
|
|
|
GetLocalTime(&st);
|
|
|
|
trigger_data.wBeginYear = st.wYear;
|
|
|
|
trigger_data.wBeginMonth = st.wMonth;
|
|
|
|
trigger_data.wBeginDay = st.wDay;
|
|
|
|
trigger_data.wStartHour = st.wHour;
|
|
|
|
trigger_data.wStartMinute = st.wMinute;
|
|
|
|
trigger_data.TriggerType = TASK_TIME_TRIGGER_WEEKLY;
|
|
|
|
trigger_data.Type.Weekly.WeeksInterval = 1;
|
|
|
|
trigger_data.Type.Weekly.rgfDaysOfTheWeek = 0x7f; /* every day */
|
|
|
|
hr = ITaskTrigger_SetTrigger(trigger, &trigger_data);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ITaskTrigger_Release(trigger);
|
|
|
|
|
|
|
|
hr = ITask_SetApplicationName(task, cmdW);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_SetParameters(task, empty);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_SetWorkingDirectory(task, empty);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
/* Save the task so that the Scheduler service would notice the changes */
|
|
|
|
save_job(task);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(status == SCHED_S_TASK_HAS_NOT_RUN, "got %#x\n", status);
|
|
|
|
|
|
|
|
hr = ITask_Run(task);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
/* According to MSDN the task status doesn't update dynamically */
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(status == SCHED_S_TASK_HAS_NOT_RUN, "got %#x\n", status);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
|
|
|
|
/* Running the process associated with the task to start up may
|
|
|
|
* take quite a bit a of time, and waiting for it during the test
|
|
|
|
* may be not the best idea.
|
|
|
|
*
|
|
|
|
* This is how it's supposed to look like in the application
|
|
|
|
* (the loop should be infinite):
|
|
|
|
*/
|
2019-10-26 00:06:20 +02:00
|
|
|
for (i = 0; i < 5; i++)
|
2018-05-11 06:36:47 +02:00
|
|
|
{
|
|
|
|
hr = ITaskScheduler_Activate(scheduler, wine_test_runW, &IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "Activate error %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
|
|
|
|
if (status == SCHED_S_TASK_RUNNING) break;
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ITaskScheduler_Activate(scheduler, wine_test_runW, &IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "Activate error %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
if (status == SCHED_S_TASK_RUNNING)
|
|
|
|
{
|
|
|
|
hr = ITask_Terminate(task);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
|
|
|
|
/* Waiting for the process associated with the task to terminate
|
|
|
|
* may take quite a bit a of time, and waiting for it during the
|
|
|
|
* test is not practical.
|
|
|
|
*
|
|
|
|
* This is how it's supposed to look like in the application
|
|
|
|
* (the loop should be infinite):
|
|
|
|
*/
|
2019-10-26 00:06:20 +02:00
|
|
|
for (i = 0; i < 5; i++)
|
2018-05-11 06:36:47 +02:00
|
|
|
{
|
|
|
|
hr = ITaskScheduler_Activate(scheduler, wine_test_runW, &IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "Activate error %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_GetStatus(task, &status);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
|
|
|
|
if (status != SCHED_S_TASK_RUNNING) break;
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ITask_Release(task);
|
|
|
|
|
2021-05-21 00:13:52 +02:00
|
|
|
hr = taskscheduler_delete(scheduler, wine_test_runW);
|
2018-05-11 06:36:47 +02:00
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
}
|
|
|
|
|
2018-05-14 09:49:12 +02:00
|
|
|
static void test_SetFlags(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ITask *task;
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
hr = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_SetFlags(task, 0);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
flags = 0xdeadbeef;
|
|
|
|
hr = ITask_GetFlags(task, &flags);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(flags == 0, "got %#x\n", flags);
|
|
|
|
|
|
|
|
hr = ITask_SetFlags(task, 0xffffffff);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
flags = 0xdeadbeef;
|
|
|
|
hr = ITask_GetFlags(task, &flags);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(flags == 0x7fff, "got %#x\n", flags);
|
|
|
|
|
|
|
|
hr = ITask_SetFlags(task, 0x9234);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
flags = 0xdeadbeef;
|
|
|
|
hr = ITask_GetFlags(task, &flags);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(flags == 0x1234, "got %#x\n", flags);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
}
|
|
|
|
|
2018-06-13 06:05:21 +02:00
|
|
|
static void test_workitem_data(void)
|
|
|
|
{
|
|
|
|
static BYTE hello[] = "Hello World!";
|
|
|
|
HRESULT hr;
|
|
|
|
ITask *task;
|
|
|
|
WORD count;
|
|
|
|
BYTE *data;
|
|
|
|
|
|
|
|
hr = ITaskScheduler_NewWorkItem(scheduler, task_name, &CLSID_CTask,
|
|
|
|
&IID_ITask, (IUnknown **)&task);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetWorkItemData(task, &count, NULL);
|
|
|
|
if (0) /* crashes under Windows */
|
|
|
|
hr = ITask_GetWorkItemData(task, NULL, &data);
|
|
|
|
|
|
|
|
count = 0xdead;
|
|
|
|
data = (BYTE *)0xdeadbeef;
|
|
|
|
hr = ITask_GetWorkItemData(task, &count, &data);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(count == 0, "got %u\n", count);
|
|
|
|
ok(data == NULL, "got %p\n", data);
|
|
|
|
|
|
|
|
hr = ITask_SetWorkItemData(task, sizeof(hello), NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_SetWorkItemData(task, 0, hello);
|
|
|
|
ok(hr == E_INVALIDARG, "got %#x\n", hr);
|
|
|
|
|
|
|
|
hr = ITask_SetWorkItemData(task, sizeof(hello), hello);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
count = 0xdead;
|
|
|
|
data = NULL;
|
|
|
|
hr = ITask_GetWorkItemData(task, &count, &data);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(count == sizeof(hello), "got %u\n", count);
|
|
|
|
ok(data != NULL, "got NULL\n");
|
|
|
|
ok(!memcmp(data, hello, sizeof(hello)), "data mismatch\n");
|
2019-01-13 15:01:16 +01:00
|
|
|
CoTaskMemFree(data);
|
2018-06-13 06:05:21 +02:00
|
|
|
|
|
|
|
hr = ITask_SetWorkItemData(task, 0, NULL);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
|
|
|
|
count = 0xdead;
|
|
|
|
data = (BYTE *)0xdeadbeef;
|
|
|
|
hr = ITask_GetWorkItemData(task, &count, &data);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(count == 0, "got %u\n", count);
|
|
|
|
ok(data == NULL, "got %p\n", data);
|
|
|
|
|
|
|
|
ITask_Release(task);
|
|
|
|
}
|
|
|
|
|
2008-08-19 23:58:53 +02:00
|
|
|
START_TEST(task)
|
|
|
|
{
|
2018-05-14 09:49:10 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2008-08-19 23:58:53 +02:00
|
|
|
CoInitialize(NULL);
|
2018-05-14 09:49:10 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_ITaskScheduler, (void **)&scheduler);
|
|
|
|
ok(hr == S_OK, "failed to create task scheduler: %#x\n", hr);
|
|
|
|
|
2008-08-19 23:58:53 +02:00
|
|
|
test_SetApplicationName_GetApplicationName();
|
2008-08-20 00:01:07 +02:00
|
|
|
test_CreateTrigger();
|
2008-08-21 02:44:30 +02:00
|
|
|
test_SetParameters_GetParameters();
|
2008-08-21 02:45:03 +02:00
|
|
|
test_SetComment_GetComment();
|
2008-08-21 02:46:05 +02:00
|
|
|
test_SetMaxRunTime_GetMaxRunTime();
|
2008-08-21 02:46:43 +02:00
|
|
|
test_SetAccountInformation_GetAccountInformation();
|
2018-04-20 10:37:08 +02:00
|
|
|
test_task_state();
|
2018-05-11 06:36:47 +02:00
|
|
|
test_Run();
|
2018-05-14 09:49:12 +02:00
|
|
|
test_SetFlags();
|
2018-06-13 06:05:21 +02:00
|
|
|
test_workitem_data();
|
2018-05-14 09:49:10 +02:00
|
|
|
|
|
|
|
ITaskScheduler_Release(scheduler);
|
2008-08-19 23:58:53 +02:00
|
|
|
CoUninitialize();
|
|
|
|
}
|