From 0c8dc0090b0166ab17cd1b84fdd511cab9086d77 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Thu, 8 Nov 2012 00:12:48 +0100 Subject: [PATCH] mstask/tests: Add tests for SetTargetComputer. --- dlls/mstask/tests/Makefile.in | 2 +- dlls/mstask/tests/task_scheduler.c | 71 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/dlls/mstask/tests/Makefile.in b/dlls/mstask/tests/Makefile.in index ffb66a8448..1c0345d33d 100644 --- a/dlls/mstask/tests/Makefile.in +++ b/dlls/mstask/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = mstask.dll -IMPORTS = ole32 +IMPORTS = ole32 user32 C_SRCS = \ task.c \ diff --git a/dlls/mstask/tests/task_scheduler.c b/dlls/mstask/tests/task_scheduler.c index 98556beb21..576d2d6087 100644 --- a/dlls/mstask/tests/task_scheduler.c +++ b/dlls/mstask/tests/task_scheduler.c @@ -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(); }