2 * Test suite for TaskScheduler 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
27 #include "wine/test.h"
29 static ITaskScheduler
*test_task_scheduler
;
31 static const WCHAR does_not_existW
[] = {'\\','\\','d','o','e','s','_','n','o','t','_','e','x','i','s','t',0};
33 static void test_NewWorkItem(void)
37 const WCHAR task_name
[] = {'T', 'e', 's', 't', 'i', 'n', 'g', 0};
40 /* Initialize a GUID that will not be a recognized CLSID or a IID */
41 CoCreateGuid(&GUID_BAD
);
43 /* Create TaskScheduler */
44 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
45 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
46 ok(hres
== S_OK
, "CTaskScheduler CoCreateInstance failed: %08x\n", hres
);
49 skip("Failed to create task scheduler. Skipping tests.\n");
53 /* Test basic task creation */
54 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
,
55 &CLSID_CTask
, &IID_ITask
, (IUnknown
**)&task
);
56 ok(hres
== S_OK
, "NewNetworkItem failed: %08x\n", hres
);
60 /* Task creation attempt using invalid work item class ID */
61 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
,
62 &GUID_BAD
, &IID_ITask
, (IUnknown
**)&task
);
63 ok(hres
== CLASS_E_CLASSNOTAVAILABLE
,
64 "Expected CLASS_E_CLASSNOTAVAILABLE: %08x\n", hres
);
66 /* Task creation attempt using invalid interface ID */
67 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
,
68 &CLSID_CTask
, &GUID_BAD
, (IUnknown
**)&task
);
69 ok(hres
== E_NOINTERFACE
, "Expected E_NOINTERFACE: %08x\n", hres
);
71 /* Task creation attempt using invalid work item class and interface ID */
72 hres
= ITaskScheduler_NewWorkItem(test_task_scheduler
, task_name
,
73 &GUID_BAD
, &GUID_BAD
, (IUnknown
**)&task
);
74 ok(hres
== CLASS_E_CLASSNOTAVAILABLE
,
75 "Expected CLASS_E_CLASSNOTAVAILABLE: %08x\n", hres
);
77 ITaskScheduler_Release(test_task_scheduler
);
81 static void test_Activate(void)
85 const WCHAR not_task_name
[] =
86 {'N', 'o', 'S', 'u', 'c', 'h', 'T', 'a', 's', 'k', 0};
88 /* Create TaskScheduler */
89 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
90 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
91 ok(hres
== S_OK
, "CTaskScheduler CoCreateInstance failed: %08x\n", hres
);
94 skip("Failed to create task scheduler. Skipping tests.\n");
98 /* Attempt to activate a nonexistent task */
99 hres
= ITaskScheduler_Activate(test_task_scheduler
, not_task_name
,
100 &IID_ITask
, (IUnknown
**)&task
);
101 ok(hres
== COR_E_FILENOTFOUND
, "Expected COR_E_FILENOTFOUND: %08x\n", hres
);
103 ITaskScheduler_Release(test_task_scheduler
);
107 static void test_GetTargetComputer(void)
112 /* Create TaskScheduler */
113 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
114 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
115 ok(hres
== S_OK
, "CTaskScheduler CoCreateInstance failed: %08x\n", hres
);
118 skip("Failed to create task scheduler.\n");
124 /* This crashes on w2k */
125 hres
= ITaskScheduler_GetTargetComputer(test_task_scheduler
, NULL
);
126 ok(hres
== E_INVALIDARG
, "got 0x%x (expected E_INVALIDARG)\n", hres
);
129 hres
= ITaskScheduler_GetTargetComputer(test_task_scheduler
, &oldname
);
130 ok((hres
== S_OK
) && oldname
&& oldname
[0] == '\\' && oldname
[1] == '\\' && oldname
[2],
131 "got 0x%x and %s (expected S_OK and an unc name)\n", hres
, wine_dbgstr_w(oldname
));
133 CoTaskMemFree(oldname
);
135 ITaskScheduler_Release(test_task_scheduler
);
139 static void test_SetTargetComputer(void)
141 WCHAR buffer
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* extra space for two '\' and a zero */
142 DWORD len
= MAX_COMPUTERNAME_LENGTH
+ 1; /* extra space for a zero */
143 WCHAR
*oldname
= NULL
;
150 if (!GetComputerNameW(buffer
+ 2, &len
))
153 /* Create TaskScheduler */
154 hres
= CoCreateInstance(&CLSID_CTaskScheduler
, NULL
, CLSCTX_INPROC_SERVER
,
155 &IID_ITaskScheduler
, (void **) &test_task_scheduler
);
156 ok(hres
== S_OK
, "CTaskScheduler CoCreateInstance failed: %08x\n", hres
);
159 skip("Failed to create task scheduler. Skipping tests.\n");
163 hres
= ITaskScheduler_GetTargetComputer(test_task_scheduler
, &oldname
);
164 ok(hres
== S_OK
, "got 0x%x and %s (expected S_OK)\n", hres
, wine_dbgstr_w(oldname
));
166 /* NULL is an alias for the local computer */
167 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, NULL
);
168 ok(hres
== S_OK
, "got 0x%x (expected S_OK)\n", hres
);
169 hres
= ITaskScheduler_GetTargetComputer(test_task_scheduler
, &name
);
170 ok((hres
== S_OK
&& !lstrcmpiW(name
, buffer
)),
171 "got 0x%x with %s (expected S_OK and %s)\n",
172 hres
, wine_dbgstr_w(name
), wine_dbgstr_w(buffer
));
175 /* The name must be valid */
176 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, does_not_existW
);
177 ok(hres
== HRESULT_FROM_WIN32(ERROR_BAD_NETPATH
), "got 0x%x (expected 0x80070035)\n", hres
);
178 /* the name of the target computer is unchanged */
179 hres
= ITaskScheduler_GetTargetComputer(test_task_scheduler
, &name
);
180 ok((hres
== S_OK
&& !lstrcmpiW(name
, buffer
)),
181 "got 0x%x with %s (expected S_OK and %s)\n",
182 hres
, wine_dbgstr_w(name
), wine_dbgstr_w(buffer
));
185 /* the two backslash are optional */
186 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, oldname
+ 2);
187 ok(hres
== S_OK
, "got 0x%x (expected S_OK)\n", hres
);
189 /* the case is ignored */
191 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, buffer
);
192 ok(hres
== S_OK
, "got 0x%x (expected S_OK)\n", hres
);
194 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, buffer
);
195 ok(hres
== S_OK
, "got 0x%x (expected S_OK)\n", hres
);
198 hres
= ITaskScheduler_SetTargetComputer(test_task_scheduler
, oldname
);
199 ok(hres
== S_OK
, "got 0x%x (expected S_OK)\n", hres
);
201 CoTaskMemFree(oldname
);
202 ITaskScheduler_Release(test_task_scheduler
);
207 START_TEST(task_scheduler
)
212 test_GetTargetComputer();
213 test_SetTargetComputer();