mstask/tests: Add tests for SetTargetComputer.

This commit is contained in:
Detlef Riekenberg 2012-11-08 00:12:48 +01:00 committed by Alexandre Julliard
parent 5bff2fb66b
commit 0c8dc0090b
2 changed files with 72 additions and 1 deletions

View File

@ -1,5 +1,5 @@
TESTDLL = mstask.dll
IMPORTS = ole32
IMPORTS = ole32 user32
C_SRCS = \
task.c \

View File

@ -28,6 +28,8 @@
static ITaskScheduler *test_task_scheduler;
static const WCHAR does_not_existW[] = {'\\','\\','d','o','e','s','_','n','o','t','_','e','x','i','s','t',0};
static void test_NewWorkItem(void)
{
HRESULT hres;
@ -134,11 +136,80 @@ static void test_GetTargetComputer(void)
return;
}
static void test_SetTargetComputer(void)
{
WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 3]; /* extra space for two '\' and a zero */
DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for a zero */
WCHAR *oldname = NULL;
WCHAR *name = NULL;
HRESULT hres;
buffer[0] = '\\';
buffer[1] = '\\';
if (!GetComputerNameW(buffer + 2, &len))
return;
/* Create TaskScheduler */
hres = CoCreateInstance(&CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,
&IID_ITaskScheduler, (void **) &test_task_scheduler);
ok(hres == S_OK, "CTaskScheduler CoCreateInstance failed: %08x\n", hres);
if (hres != S_OK)
{
skip("Failed to create task scheduler. Skipping tests.\n");
return;
}
hres = ITaskScheduler_GetTargetComputer(test_task_scheduler, &oldname);
ok(hres == S_OK, "got 0x%x and %s (expected S_OK)\n", hres, wine_dbgstr_w(oldname));
/* NULL is an alias for the local computer */
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, NULL);
ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
hres = ITaskScheduler_GetTargetComputer(test_task_scheduler, &name);
ok((hres == S_OK && !lstrcmpiW(name, buffer)),
"got 0x%x with %s (expected S_OK and %s)\n",
hres, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
CoTaskMemFree(name);
/* The name must be valid */
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, does_not_existW);
ok(hres == HRESULT_FROM_WIN32(ERROR_BAD_NETPATH), "got 0x%x (expected 0x80070035)\n", hres);
/* the name of the target computer is unchanged */
hres = ITaskScheduler_GetTargetComputer(test_task_scheduler, &name);
ok((hres == S_OK && !lstrcmpiW(name, buffer)),
"got 0x%x with %s (expected S_OK and %s)\n",
hres, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
CoTaskMemFree(name);
/* the two backslash are optional */
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, oldname + 2);
ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
/* the case is ignored */
CharUpperW(buffer);
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, buffer);
ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
CharLowerW(buffer);
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, buffer);
ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
/* cleanup */
hres = ITaskScheduler_SetTargetComputer(test_task_scheduler, oldname);
ok(hres == S_OK, "got 0x%x (expected S_OK)\n", hres);
CoTaskMemFree(oldname);
ITaskScheduler_Release(test_task_scheduler);
return;
}
START_TEST(task_scheduler)
{
CoInitialize(NULL);
test_NewWorkItem();
test_Activate();
test_GetTargetComputer();
test_SetTargetComputer();
CoUninitialize();
}