Commit 2a56402c authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

mstask: Add support for event triggers to ITask::GetNextRunTime().

parent e14e6bde
...@@ -469,6 +469,7 @@ static void filetime_add_days(FILETIME *ft, ULONG days) ...@@ -469,6 +469,7 @@ static void filetime_add_days(FILETIME *ft, ULONG days)
static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt) static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt)
{ {
TaskImpl *This = impl_from_ITask(iface); TaskImpl *This = impl_from_ITask(iface);
HRESULT hr = SCHED_S_TASK_NO_VALID_TRIGGERS;
SYSTEMTIME st, current_st; SYSTEMTIME st, current_st;
FILETIME current_ft, begin_ft, end_ft, best_ft; FILETIME current_ft, begin_ft, end_ft, best_ft;
BOOL have_best_time = FALSE; BOOL have_best_time = FALSE;
...@@ -493,6 +494,12 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt) ...@@ -493,6 +494,12 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt)
switch (This->trigger[i].TriggerType) switch (This->trigger[i].TriggerType)
{ {
case TASK_EVENT_TRIGGER_ON_IDLE:
case TASK_EVENT_TRIGGER_AT_SYSTEMSTART:
case TASK_EVENT_TRIGGER_AT_LOGON:
hr = SCHED_S_EVENT_TRIGGER;
break;
case TASK_TIME_TRIGGER_ONCE: case TASK_TIME_TRIGGER_ONCE:
st = current_st; st = current_st;
st.wHour = This->trigger[i].wStartHour; st.wHour = This->trigger[i].wStartHour;
...@@ -547,7 +554,7 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt) ...@@ -547,7 +554,7 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt)
} }
memset(rt, 0, sizeof(*rt)); memset(rt, 0, sizeof(*rt));
return SCHED_S_TASK_NO_VALID_TRIGGERS; return hr;
} }
static HRESULT WINAPI MSTASK_ITask_SetIdleWait( static HRESULT WINAPI MSTASK_ITask_SetIdleWait(
......
...@@ -477,7 +477,7 @@ static void test_GetNextRunTime(void) ...@@ -477,7 +477,7 @@ static void test_GetNextRunTime(void)
ITask *task; ITask *task;
ITaskTrigger *trigger; ITaskTrigger *trigger;
TASK_TRIGGER data; TASK_TRIGGER data;
WORD idx; WORD idx, i;
SYSTEMTIME st, cmp; SYSTEMTIME st, cmp;
hr = ITaskScheduler_NewWorkItem(test_task_scheduler, task_name, &CLSID_CTask, hr = ITaskScheduler_NewWorkItem(test_task_scheduler, task_name, &CLSID_CTask,
...@@ -557,6 +557,60 @@ static void test_GetNextRunTime(void) ...@@ -557,6 +557,60 @@ static void test_GetNextRunTime(void)
/* FIXME: TASK_TIME_TRIGGER_MONTHLYDOW */ /* FIXME: TASK_TIME_TRIGGER_MONTHLYDOW */
ITaskTrigger_Release(trigger); ITaskTrigger_Release(trigger);
/* do not delete a valid trigger */
idx = 0xdead;
hr = ITask_CreateTrigger(task, &idx, &trigger);
ok(hr == S_OK, "got %#x\n", hr);
ok(idx == 1, "got %u\n", idx);
/* TASK_EVENT_TRIGGER_ON_IDLE = 5
* TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6
* TASK_EVENT_TRIGGER_AT_LOGON = 7
*/
for (i = 5; i <= 7; i++)
{
hr = ITaskTrigger_GetTrigger(trigger, &data);
ok(hr == S_OK, "got %#x\n", hr);
data.rgFlags &= ~TASK_TRIGGER_FLAG_DISABLED;
data.TriggerType = i;
hr = ITaskTrigger_SetTrigger(trigger, &data);
ok(hr == S_OK, "got %#x\n", hr);
memset(&st, 0xff, sizeof(st));
hr = ITask_GetNextRunTime(task, &st);
ok(hr == S_OK, "got %#x\n", hr);
ok(!memcmp(&st, &cmp, sizeof(st)), "got %u/%u/%u wday %u %u:%02u:%02u\n",
st.wDay, st.wMonth, st.wYear, st.wDayOfWeek,
st.wHour, st.wMinute, st.wSecond);
}
ITaskTrigger_Release(trigger);
hr = ITask_DeleteTrigger(task, 0);
ok(hr == S_OK, "got %#x\n", hr);
hr = ITask_GetTrigger(task, 0, &trigger);
ok(hr == S_OK, "got %#x\n", hr);
for (i = 5; i <= 7; i++)
{
hr = ITaskTrigger_GetTrigger(trigger, &data);
ok(hr == S_OK, "got %#x\n", hr);
data.rgFlags &= ~TASK_TRIGGER_FLAG_DISABLED;
data.TriggerType = i;
hr = ITaskTrigger_SetTrigger(trigger, &data);
ok(hr == S_OK, "got %#x\n", hr);
memset(&st, 0xff, sizeof(st));
hr = ITask_GetNextRunTime(task, &st);
ok(hr == SCHED_S_EVENT_TRIGGER, "got %#x\n", hr);
ok(!memcmp(&st, &st_empty, sizeof(st)), "got %u/%u/%u wday %u %u:%02u:%02u\n",
st.wDay, st.wMonth, st.wYear, st.wDayOfWeek,
st.wHour, st.wMinute, st.wSecond);
}
ITaskTrigger_Release(trigger);
ITask_Release(task); ITask_Release(task);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment