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
26 #include "wine/test.h"
28 static ITaskScheduler
*test_task_scheduler
;
29 static ITask
*test_task
;
30 static ITaskTrigger
*test_trigger
;
31 static WORD trigger_index
;
33 static BOOL
setup_trigger(void)
36 const WCHAR task_name
[] = {'T','e','s','t','i','n','g', 0};
38 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
39 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
42 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
,
43 &CLSID_CTask
, &IID_ITask
, (IUnknown
**)&test_task
);
46 ITaskScheduler_Release(test_task_scheduler
);
49 hres
= ITask_CreateTrigger(test_task
, &trigger_index
, &test_trigger
);
52 ITask_Release(test_task
);
53 ITaskScheduler_Release(test_task_scheduler
);
59 static void cleanup_trigger(void)
61 ITaskTrigger_Release(test_trigger
);
62 ITask_Release(test_task
);
63 ITaskScheduler_Release(test_task_scheduler
);
66 static BOOL
compare_trigger_state(TASK_TRIGGER found_state
,
67 TASK_TRIGGER expected_state
)
69 ok(found_state
.cbTriggerSize
== expected_state
.cbTriggerSize
,
70 "cbTriggerSize: Found %d but expected %d\n",
71 found_state
.cbTriggerSize
, expected_state
.cbTriggerSize
);
73 ok(found_state
.Reserved1
== expected_state
.Reserved1
,
74 "Reserved1: Found %d but expected %d\n",
75 found_state
.Reserved1
, expected_state
.Reserved1
);
77 ok(found_state
.wBeginYear
== expected_state
.wBeginYear
,
78 "wBeginYear: Found %d but expected %d\n",
79 found_state
.wBeginYear
, expected_state
.wBeginYear
);
81 ok(found_state
.wBeginMonth
== expected_state
.wBeginMonth
,
82 "wBeginMonth: Found %d but expected %d\n",
83 found_state
.wBeginMonth
, expected_state
.wBeginMonth
);
85 ok(found_state
.wBeginDay
== expected_state
.wBeginDay
,
86 "wBeginDay: Found %d but expected %d\n",
87 found_state
.wBeginDay
, expected_state
.wBeginDay
);
89 ok(found_state
.wEndYear
== expected_state
.wEndYear
,
90 "wEndYear: Found %d but expected %d\n",
91 found_state
.wEndYear
, expected_state
.wEndYear
);
93 ok(found_state
.wEndMonth
== expected_state
.wEndMonth
,
94 "wEndMonth: Found %d but expected %d\n",
95 found_state
.wEndMonth
, expected_state
.wEndMonth
);
97 ok(found_state
.wEndDay
== expected_state
.wEndDay
,
98 "wEndDay: Found %d but expected %d\n",
99 found_state
.wEndDay
, expected_state
.wEndDay
);
101 ok(found_state
.wStartHour
== expected_state
.wStartHour
,
102 "wStartHour: Found %d but expected %d\n",
103 found_state
.wStartHour
, expected_state
.wStartHour
);
105 ok(found_state
.wStartMinute
== expected_state
.wStartMinute
,
106 "wStartMinute: Found %d but expected %d\n",
107 found_state
.wStartMinute
, expected_state
.wStartMinute
);
109 ok(found_state
.MinutesDuration
== expected_state
.MinutesDuration
,
110 "MinutesDuration: Found %d but expected %d\n",
111 found_state
.MinutesDuration
, expected_state
.MinutesDuration
);
113 ok(found_state
.MinutesInterval
== expected_state
.MinutesInterval
,
114 "MinutesInterval: Found %d but expected %d\n",
115 found_state
.MinutesInterval
, expected_state
.MinutesInterval
);
117 ok(found_state
.rgFlags
== expected_state
.rgFlags
,
118 "rgFlags: Found %d but expected %d\n",
119 found_state
.rgFlags
, expected_state
.rgFlags
);
121 ok(found_state
.TriggerType
== expected_state
.TriggerType
,
122 "TriggerType: Found %d but expected %d\n",
123 found_state
.TriggerType
, expected_state
.TriggerType
);
125 ok(found_state
.Type
.Daily
.DaysInterval
== expected_state
.Type
.Daily
.DaysInterval
,
126 "Type.Daily.DaysInterval: Found %d but expected %d\n",
127 found_state
.Type
.Daily
.DaysInterval
, expected_state
.Type
.Daily
.DaysInterval
);
129 ok(found_state
.Reserved2
== expected_state
.Reserved2
,
130 "Reserved2: Found %d but expected %d\n",
131 found_state
.Reserved2
, expected_state
.Reserved2
);
133 ok(found_state
.wRandomMinutesInterval
== expected_state
.wRandomMinutesInterval
,
134 "wRandomMinutesInterval: Found %d but expected %d\n",
135 found_state
.wRandomMinutesInterval
, expected_state
.wRandomMinutesInterval
);
140 static void test_SetTrigger_GetTrigger(void)
144 TASK_TRIGGER trigger_state
;
145 TASK_TRIGGER empty_trigger_state
= {
146 sizeof(trigger_state
), 0,
150 TASK_TRIGGER_FLAG_DISABLED
, TASK_TIME_TRIGGER_DAILY
, {{1}},
153 TASK_TRIGGER normal_trigger_state
= {
154 sizeof(trigger_state
), 0,
159 TASK_TRIGGER_FLAG_DISABLED
, TASK_TIME_TRIGGER_DAILY
, {{1}},
164 setup
= setup_trigger();
165 ok(setup
, "Failed to setup test_task\n");
168 skip("Failed to create task. Skipping tests.\n");
172 /* Setup a trigger with base values for this test run */
174 empty_trigger_state
.wStartHour
= time
.wHour
;
175 empty_trigger_state
.wStartMinute
= time
.wMinute
;
176 empty_trigger_state
.wBeginYear
= time
.wYear
;
177 empty_trigger_state
.wBeginMonth
= time
.wMonth
;
178 empty_trigger_state
.wBeginDay
= time
.wDay
;
180 /* Test trigger state after trigger creation but before setting * state */
181 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
182 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
183 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
184 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
185 compare_trigger_state(trigger_state
, empty_trigger_state
);
187 /* Test setting basic empty trigger */
188 hres
= ITaskTrigger_SetTrigger(test_trigger
, &empty_trigger_state
);
189 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
190 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
191 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
192 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
193 ok(hres
== S_OK
, "Failed to GetTrigger\n");
194 compare_trigger_state(trigger_state
, empty_trigger_state
);
196 /* Test setting basic non-empty trigger */
197 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
198 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
199 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
200 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
201 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
202 ok(hres
== S_OK
, "Failed to GetTrigger\n");
203 compare_trigger_state(trigger_state
, normal_trigger_state
);
205 /* The following tests modify the normal_trigger_state structure
206 * before each test, and return the normal_trigger_state structure
207 * back to its original valid state after each test. This keeps
208 * each test run independent. */
210 /* Test setting trigger with invalid cbTriggerSize */
211 normal_trigger_state
.cbTriggerSize
= sizeof(trigger_state
) - 1;
212 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
213 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
214 normal_trigger_state
.cbTriggerSize
= sizeof(trigger_state
) + 1;
215 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
216 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
217 normal_trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
219 /* Test setting trigger with invalid Reserved fields */
220 normal_trigger_state
.Reserved1
= 80;
221 normal_trigger_state
.Reserved2
= 80;
222 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
223 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
224 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
225 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
226 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
227 ok(trigger_state
.Reserved1
== 0 && trigger_state
.Reserved2
== 0,
228 "Reserved fields should be set to zero\n");
229 normal_trigger_state
.Reserved1
= 0;
230 normal_trigger_state
.Reserved2
= 0;
232 /* Test setting trigger with invalid month */
233 normal_trigger_state
.wBeginMonth
= 0;
234 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
235 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
236 normal_trigger_state
.wBeginMonth
= 13;
237 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
238 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
239 normal_trigger_state
.wBeginMonth
= 1;
241 /* Test setting trigger with invalid begin date */
242 normal_trigger_state
.wBeginDay
= 0;
243 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
244 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
245 normal_trigger_state
.wBeginDay
= 32;
246 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
247 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
248 normal_trigger_state
.wBeginMonth
= 2;
249 normal_trigger_state
.wBeginDay
= 30;
250 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
251 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
252 normal_trigger_state
.wBeginMonth
= 1;
253 normal_trigger_state
.wBeginDay
= 1;
255 /* Test setting trigger invalid end date */
256 normal_trigger_state
.wEndYear
= 0;
257 normal_trigger_state
.wEndMonth
= 200;
258 normal_trigger_state
.wEndDay
= 200;
259 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
260 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
261 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
262 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
263 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
264 ok(trigger_state
.wEndYear
== 0, "End year should be 0: %d\n",
265 trigger_state
.wEndYear
);
266 ok(trigger_state
.wEndMonth
== 200, "End month should be 200: %d\n",
267 trigger_state
.wEndMonth
);
268 ok(trigger_state
.wEndDay
== 200, "End day should be 200: %d\n",
269 trigger_state
.wEndDay
);
270 normal_trigger_state
.rgFlags
=
271 TASK_TRIGGER_FLAG_DISABLED
| TASK_TRIGGER_FLAG_HAS_END_DATE
;
272 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
273 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
274 normal_trigger_state
.rgFlags
= TASK_TRIGGER_FLAG_DISABLED
;
275 normal_trigger_state
.wEndYear
= 2980;
276 normal_trigger_state
.wEndMonth
= 1;
277 normal_trigger_state
.wEndDay
= 1;
279 /* Test setting trigger with invalid hour or minute*/
280 normal_trigger_state
.wStartHour
= 24;
281 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
282 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
283 normal_trigger_state
.wStartHour
= 3;
284 normal_trigger_state
.wStartHour
= 60;
285 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
286 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
287 normal_trigger_state
.wStartHour
= 3;
289 /* Test setting trigger with invalid duration / interval pairs */
290 normal_trigger_state
.MinutesDuration
= 5;
291 normal_trigger_state
.MinutesInterval
= 5;
292 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
293 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
294 normal_trigger_state
.MinutesDuration
= 5;
295 normal_trigger_state
.MinutesInterval
= 6;
296 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
297 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
298 normal_trigger_state
.MinutesDuration
= 0;
299 normal_trigger_state
.MinutesInterval
= 6;
300 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
301 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
302 normal_trigger_state
.MinutesDuration
= 5;
303 normal_trigger_state
.MinutesInterval
= 0;
304 ok(hres
== E_INVALIDARG
, "Expected E_INVALIDARG: 0x%08x\n", hres
);
305 normal_trigger_state
.MinutesDuration
= 0;
306 normal_trigger_state
.MinutesInterval
= 0;
308 /* Test setting trigger with end date before start date */
309 normal_trigger_state
.wEndYear
= 1979;
310 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
311 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
312 normal_trigger_state
.rgFlags
=
313 TASK_TRIGGER_FLAG_DISABLED
| TASK_TRIGGER_FLAG_HAS_END_DATE
;
314 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
315 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
316 normal_trigger_state
.rgFlags
= TASK_TRIGGER_FLAG_DISABLED
;
317 normal_trigger_state
.wEndYear
= 2980;
318 normal_trigger_state
.wEndMonth
= 1;
319 normal_trigger_state
.wEndDay
= 1;
322 /* Test setting trigger with invalid TriggerType and Type */
323 normal_trigger_state
.TriggerType
= TASK_TIME_TRIGGER_ONCE
;
324 normal_trigger_state
.Type
.Weekly
.WeeksInterval
= 2;
325 normal_trigger_state
.Type
.Weekly
.rgfDaysOfTheWeek
= (TASK_MONDAY
| TASK_TUESDAY
);
326 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
327 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
328 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
329 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
330 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
331 ok(trigger_state
.Type
.Weekly
.WeeksInterval
== 0xcfcf,
332 "Expected WeeksInterval set remain untouched: %d\n",
333 trigger_state
.Type
.Weekly
.WeeksInterval
);
334 ok(trigger_state
.Type
.Weekly
.rgfDaysOfTheWeek
== 0xcfcf,
335 "Expected WeeksInterval set remain untouched: %d\n",
336 trigger_state
.Type
.Weekly
.rgfDaysOfTheWeek
);
337 normal_trigger_state
.TriggerType
= TASK_TIME_TRIGGER_DAILY
;
338 normal_trigger_state
.Type
.Daily
.DaysInterval
= 1;
339 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
341 /* Test setting trigger with set wRandomMinutesInterval */
342 normal_trigger_state
.wRandomMinutesInterval
= 5;
343 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
344 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
345 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
346 trigger_state
.cbTriggerSize
= sizeof(trigger_state
);
347 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
348 ok(trigger_state
.wRandomMinutesInterval
== 0,
349 "wRandomMinutesInterval should be set to zero\n");
350 normal_trigger_state
.wRandomMinutesInterval
= 0;
352 /* Test GetTrigger using invalid cbTriggerSiz in pTrigger. In
353 * contrast to available documentation, this succeeds in practice. */
354 hres
= ITaskTrigger_SetTrigger(test_trigger
, &normal_trigger_state
);
355 ok(hres
== S_OK
, "Failed to set trigger: 0x%08x\n", hres
);
356 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
357 trigger_state
.cbTriggerSize
= sizeof(trigger_state
) - 1;
358 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
359 ok(hres
== S_OK
, "Failed to GetTrigger\n");
360 ok(compare_trigger_state(trigger_state
, normal_trigger_state
),
362 memset(&trigger_state
, 0xcf, sizeof(trigger_state
));
363 trigger_state
.cbTriggerSize
= 0;
364 hres
= ITaskTrigger_GetTrigger(test_trigger
, &trigger_state
);
365 ok(hres
== S_OK
, "Failed to GetTrigger\n");
366 ok(compare_trigger_state(trigger_state
, normal_trigger_state
),
375 START_TEST(task_trigger
)
378 test_SetTrigger_GetTrigger();