Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/mstask/task.c | 9 ++++++- dlls/mstask/tests/task_trigger.c | 56 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/dlls/mstask/task.c b/dlls/mstask/task.c index a201e44a1f..57ad0f7005 100644 --- a/dlls/mstask/task.c +++ b/dlls/mstask/task.c @@ -469,6 +469,7 @@ static void filetime_add_days(FILETIME *ft, ULONG days) static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt) { TaskImpl *This = impl_from_ITask(iface); + HRESULT hr = SCHED_S_TASK_NO_VALID_TRIGGERS; SYSTEMTIME st, current_st; FILETIME current_ft, begin_ft, end_ft, best_ft; BOOL have_best_time = FALSE; @@ -493,6 +494,12 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt)
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: st = current_st; st.wHour = This->trigger[i].wStartHour; @@ -547,7 +554,7 @@ static HRESULT WINAPI MSTASK_ITask_GetNextRunTime(ITask *iface, SYSTEMTIME *rt) }
memset(rt, 0, sizeof(*rt)); - return SCHED_S_TASK_NO_VALID_TRIGGERS; + return hr; }
static HRESULT WINAPI MSTASK_ITask_SetIdleWait( diff --git a/dlls/mstask/tests/task_trigger.c b/dlls/mstask/tests/task_trigger.c index a89fa62d1c..328cae25fd 100644 --- a/dlls/mstask/tests/task_trigger.c +++ b/dlls/mstask/tests/task_trigger.c @@ -477,7 +477,7 @@ static void test_GetNextRunTime(void) ITask *task; ITaskTrigger *trigger; TASK_TRIGGER data; - WORD idx; + WORD idx, i; SYSTEMTIME st, cmp;
hr = ITaskScheduler_NewWorkItem(test_task_scheduler, task_name, &CLSID_CTask, @@ -556,6 +556,60 @@ static void test_GetNextRunTime(void) /* FIXME: TASK_TIME_TRIGGER_MONTHLYDATE */ /* FIXME: TASK_TIME_TRIGGER_MONTHLYDOW */
+ 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); }