[WTSAPI32_WINETEST] Sync with Wine 3.0. CORE-14225
[reactos.git] / modules / rostests / winetests / wtsapi32 / wtsapi.c
1 /*
2 * Copyright 2014 Stefan Leichter
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <windef.h>
22 #include <winbase.h>
23 #include <wine/winternl.h>
24 #include <wtsapi32.h>
25
26 #include "wine/test.h"
27
28 static void test_WTSEnumerateProcessesW(void)
29 {
30 BOOL found = FALSE, ret;
31 DWORD count, i;
32 PWTS_PROCESS_INFOW info;
33 WCHAR *pname, nameW[MAX_PATH];
34
35 GetModuleFileNameW(NULL, nameW, MAX_PATH);
36 for (pname = nameW + lstrlenW(nameW); pname > nameW; pname--)
37 {
38 if(*pname == '/' || *pname == '\\')
39 {
40 pname++;
41 break;
42 }
43 }
44
45 info = NULL;
46 SetLastError(0xdeadbeef);
47 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 1, 1, &info, &count);
48 ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
49 ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
50 if (info) WTSFreeMemory(info);
51
52 info = NULL;
53 SetLastError(0xdeadbeef);
54 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 0, &info, &count);
55 ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
56 ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
57 if (info) WTSFreeMemory(info);
58
59 info = NULL;
60 SetLastError(0xdeadbeef);
61 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 2, &info, &count);
62 ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
63 ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
64 if (info) WTSFreeMemory(info);
65
66 SetLastError(0xdeadbeef);
67 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, NULL, &count);
68 ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
69 ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
70
71 info = NULL;
72 SetLastError(0xdeadbeef);
73 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, NULL);
74 ok(!ret, "expected WTSEnumerateProcessesW to fail\n");
75 ok(GetLastError()== ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got: %d\n", GetLastError());
76 if (info) WTSFreeMemory(info);
77
78 count = 0;
79 info = NULL;
80 SetLastError(0xdeadbeef);
81 ret = WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, &count);
82 ok(ret || broken(!ret), /* fails on Win2K with error ERROR_APP_WRONG_OS */
83 "expected WTSEnumerateProcessesW to succeed; failed with %d\n", GetLastError());
84 for(i = 0; ret && i < count; i++)
85 {
86 found = found || !lstrcmpW(pname, info[i].pProcessName);
87 }
88 todo_wine
89 ok(found || broken(!ret), "process name %s not found\n", wine_dbgstr_w(pname));
90 if (info) WTSFreeMemory(info);
91 }
92
93 START_TEST (wtsapi)
94 {
95 test_WTSEnumerateProcessesW();
96 }