ReactOS 0.4.16-dev-297-gc569aee
task_scheduler.c File Reference
#include "corerror.h"
#include "initguid.h"
#include "mstask.h"
#include "wine/test.h"
Include dependency graph for task_scheduler.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

static void test_NewWorkItem (void)
 
static void test_Activate (void)
 
static void test_GetTargetComputer (void)
 
static void test_SetTargetComputer (void)
 
static void test_Enum (void)
 
 START_TEST (task_scheduler)
 

Variables

static ITaskSchedulertest_task_scheduler
 
static const WCHAR does_not_existW [] = {'\\','\\','d','o','e','s','_','n','o','t','_','e','x','i','s','t',0}
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file task_scheduler.c.

Function Documentation

◆ START_TEST()

START_TEST ( task_scheduler  )

Definition at line 234 of file task_scheduler.c.

235{
241 test_Enum();
243}
#define NULL
Definition: types.h:112
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void test_Activate(void)
static void test_SetTargetComputer(void)
static void test_Enum(void)
static void test_GetTargetComputer(void)
static void test_NewWorkItem(void)

◆ test_Activate()

static void test_Activate ( void  )
static

Definition at line 81 of file task_scheduler.c.

82{
84 ITask *task = NULL;
85 const WCHAR not_task_name[] =
86 {'N', 'o', 'S', 'u', 'c', 'h', 'T', 'a', 's', 'k', 0};
87
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);
92 if (hres != S_OK)
93 {
94 skip("Failed to create task scheduler. Skipping tests.\n");
95 return;
96 }
97
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);
102
103 ITaskScheduler_Release(test_task_scheduler);
104 return;
105}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define COR_E_FILENOTFOUND
Definition: corerror.h:42
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:52
HRESULT hres
Definition: protocol.c:465
static ITaskScheduler * test_task_scheduler
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_Enum()

static void test_Enum ( void  )
static

Definition at line 212 of file task_scheduler.c.

213{
214 ITaskScheduler *scheduler;
215 IEnumWorkItems *tasks;
216 HRESULT hr;
217
218 hr = CoCreateInstance(&CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,
219 &IID_ITaskScheduler, (void **)&scheduler);
220 ok(hr == S_OK, "got 0x%08x\n", hr);
221
222if (0) { /* crashes on win2k */
223 hr = ITaskScheduler_Enum(scheduler, NULL);
224 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
225}
226
227 hr = ITaskScheduler_Enum(scheduler, &tasks);
228 ok(hr == S_OK, "got 0x%08x\n", hr);
229 IEnumWorkItems_Release(tasks);
230
231 ITaskScheduler_Release(scheduler);
232}
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT hr
Definition: shlfolder.c:183

Referenced by START_TEST().

◆ test_GetTargetComputer()

static void test_GetTargetComputer ( void  )
static

Definition at line 107 of file task_scheduler.c.

108{
110 WCHAR *oldname;
111
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);
116 if (hres != S_OK)
117 {
118 skip("Failed to create task scheduler.\n");
119 return;
120 }
121
122 if (0)
123 {
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);
127 }
128
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));
132
133 CoTaskMemFree(oldname);
134
135 ITaskScheduler_Release(test_task_scheduler);
136 return;
137}
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define wine_dbgstr_w
Definition: kernel32.h:34

Referenced by START_TEST().

◆ test_NewWorkItem()

static void test_NewWorkItem ( void  )
static

Definition at line 33 of file task_scheduler.c.

34{
36 ITask *task;
37 const WCHAR task_name[] = {'T', 'e', 's', 't', 'i', 'n', 'g', 0};
38 GUID GUID_BAD;
39
40 /* Initialize a GUID that will not be a recognized CLSID or a IID */
41 CoCreateGuid(&GUID_BAD);
42
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);
47 if (hres != S_OK)
48 {
49 skip("Failed to create task scheduler. Skipping tests.\n");
50 return;
51 }
52
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);
57 if (hres == S_OK)
58 ITask_Release(task);
59
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);
64 "Expected CLASS_E_CLASSNOTAVAILABLE: %08x\n", hres);
65
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);
70
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);
75 "Expected CLASS_E_CLASSNOTAVAILABLE: %08x\n", hres);
76
77 ITaskScheduler_Release(test_task_scheduler);
78 return;
79}
HRESULT WINAPI CoCreateGuid(GUID *pguid)
Definition: compobj.c:2206
#define E_NOINTERFACE
Definition: winerror.h:2364
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663

Referenced by START_TEST().

◆ test_SetTargetComputer()

static void test_SetTargetComputer ( void  )
static

Definition at line 139 of file task_scheduler.c.

140{
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;
144 WCHAR *name = NULL;
146
147
148 buffer[0] = '\\';
149 buffer[1] = '\\';
150 if (!GetComputerNameW(buffer + 2, &len))
151 return;
152
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);
157 if (hres != S_OK)
158 {
159 skip("Failed to create task scheduler. Skipping tests.\n");
160 return;
161 }
162
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));
165
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",
174
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",
184
185 /* the two backslashes are optional */
186 hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, oldname + 2);
187 if (hres == E_ACCESSDENIED)
188 {
189 skip("SetTargetComputer failed with E_ACCESSDENIED (needs admin rights)\n");
190 goto done;
191 }
192 ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
193
194 /* the case is ignored */
196 hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, buffer);
197 ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
199 hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, buffer);
200 ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
201
202 /* cleanup */
203 hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, oldname);
204 ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
205
206done:
207 CoTaskMemFree(oldname);
208 ITaskScheduler_Release(test_task_scheduler);
209 return;
210}
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4262
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR does_not_existW[]
Definition: name.c:39
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
#define ERROR_BAD_NETPATH
Definition: winerror.h:145
#define E_ACCESSDENIED
Definition: winerror.h:2849
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
LPWSTR WINAPI CharLowerW(_Inout_ LPWSTR)
LPWSTR WINAPI CharUpperW(_Inout_ LPWSTR)

Referenced by START_TEST().

Variable Documentation

◆ does_not_existW

const WCHAR does_not_existW[] = {'\\','\\','d','o','e','s','_','n','o','t','_','e','x','i','s','t',0}
static

Definition at line 31 of file task_scheduler.c.

Referenced by test_SetTargetComputer().

◆ test_task_scheduler

ITaskScheduler* test_task_scheduler
static