mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / adsldp / tests / sysinfo.c
blobc7495dcb88b384d5a5902db7c1b18b2d0055815f
1 /*
2 * ADSystemInfo Tests
4 * Copyright 2018 Dmitry Timoshkov
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "initguid.h"
30 #include "iads.h"
31 #define SECURITY_WIN32
32 #include "security.h"
34 #include "wine/test.h"
36 static void test_ComputerName(void)
38 static const WCHAR cnW[] = { 'C','N','=' };
39 static const WCHAR ComputersW[] = { 'C','N','=','C','o','m','p','u','t','e','r','s' };
40 BOOL ret;
41 ULONG size, name_size;
42 WCHAR name[MAX_COMPUTERNAME_LENGTH + 1];
43 WCHAR buf[1024];
44 IADsADSystemInfo *sysinfo;
45 BSTR bstr;
46 HRESULT hr;
48 name_size = MAX_COMPUTERNAME_LENGTH + 1;
49 SetLastError(0xdeadbeef);
50 ret = GetComputerNameW(name, &name_size);
51 ok(ret, "GetComputerName error %u\n", GetLastError());
53 /* Distinguished name (rfc1779) is supposed to look like this:
54 * "CN=COMPNAME,CN=Computers,DC=domain,DC=com"
57 size = 1024;
58 SetLastError(0xdeadbeef);
59 ret = GetComputerObjectNameW(NameFullyQualifiedDN, buf, &size);
60 ok(ret || GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO, "GetComputerObjectName error %u\n", GetLastError());
61 if (ret)
63 const WCHAR *p;
64 ok(size == lstrlenW(buf) + 1, "got %u, expected %u\n", size, lstrlenW(buf) + 1);
65 ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
66 ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
67 p = wcschr(buf, ',');
68 ok(p != NULL, "delimiter was not found\n");
69 ok(p && !memcmp(p + 1, ComputersW, sizeof(ComputersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
72 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
73 ok(hr == S_OK, "got %#x\n", hr);
75 hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
76 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#x\n", hr);
77 if (hr == S_OK)
79 ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
80 SysFreeString(bstr);
83 IADsADSystemInfo_Release(sysinfo);
86 static void test_UserName(void)
88 static const WCHAR cnW[] = { 'C','N','=' };
89 static const WCHAR UsersW[] = { 'C','N','=','U','s','e','r','s' };
90 BOOL ret;
91 ULONG size, name_size;
92 WCHAR name[256];
93 WCHAR buf[1024];
94 IADsADSystemInfo *sysinfo;
95 BSTR bstr;
96 HRESULT hr;
98 name_size = 256;
99 SetLastError(0xdeadbeef);
100 ret = GetUserNameW(name, &name_size);
101 ok(ret, "GetUserName error %u\n", GetLastError());
103 /* Distinguished name (rfc1779) is supposed to look like this:
104 * "CN=username,CN=Users,DC=domain,DC=com"
107 size = 1024;
108 SetLastError(0xdeadbeef);
109 ret = GetUserNameExW(NameFullyQualifiedDN, buf, &size);
110 ok(ret || GetLastError() == ERROR_NONE_MAPPED, "GetUserNameEx error %u\n", GetLastError());
111 if (ret)
113 const WCHAR *p;
114 ok(size == lstrlenW(buf), "got %u, expected %u\n", size, lstrlenW(buf));
115 ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
116 ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
117 p = wcschr(buf, ',');
118 ok(p != NULL, "delimiter was not found\n");
119 ok(p && !memcmp(p + 1, UsersW, sizeof(UsersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
122 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
123 ok(hr == S_OK, "got %#x\n", hr);
125 hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
126 todo_wine
127 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
128 if (hr == S_OK)
130 ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
131 SysFreeString(bstr);
134 IADsADSystemInfo_Release(sysinfo);
137 static void test_sysinfo(void)
140 IADsADSystemInfo *sysinfo;
141 IDispatch *dispatch;
142 BSTR bstr;
143 VARIANT_BOOL value;
144 HRESULT hr;
146 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IUnknown, (void **)&sysinfo);
147 ok(hr == S_OK, "got %#x\n", hr);
148 IADsADSystemInfo_Release(sysinfo);
150 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
151 ok(hr == S_OK, "got %#x\n", hr);
153 hr = IADsADSystemInfo_QueryInterface(sysinfo, &IID_IDispatch, (void **)&dispatch);
154 ok(hr == S_OK, "got %#x\n", hr);
155 IDispatch_Release(dispatch);
157 hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
158 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#x\n", hr);
159 if (hr != S_OK)
161 skip("Computer is not part of a domain, skipping the tests\n");
162 goto done;
164 SysFreeString(bstr);
166 hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
167 todo_wine
168 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
169 if (hr != S_OK) goto done;
170 SysFreeString(bstr);
172 hr = IADsADSystemInfo_get_SiteName(sysinfo, &bstr);
173 ok(hr == S_OK, "got %#x\n", hr);
174 if (hr == S_OK) SysFreeString(bstr);
176 hr = IADsADSystemInfo_get_DomainShortName(sysinfo, &bstr);
177 ok(hr == S_OK, "got %#x\n", hr);
178 if (hr == S_OK) SysFreeString(bstr);
180 hr = IADsADSystemInfo_get_DomainDNSName(sysinfo, &bstr);
181 ok(hr == S_OK, "got %#x\n", hr);
182 if (hr == S_OK) SysFreeString(bstr);
184 hr = IADsADSystemInfo_get_ForestDNSName(sysinfo, &bstr);
185 ok(hr == S_OK, "got %#x\n", hr);
186 if (hr == S_OK) SysFreeString(bstr);
188 hr = IADsADSystemInfo_get_PDCRoleOwner(sysinfo, &bstr);
189 ok(hr == S_OK, "got %#x\n", hr);
190 if (hr == S_OK) SysFreeString(bstr);
192 hr = IADsADSystemInfo_get_IsNativeMode(sysinfo, &value);
193 ok(hr == S_OK, "got %#x\n", hr);
194 if (hr == S_OK) ok(value == VARIANT_TRUE, "IsNativeMode: %s\n", value == VARIANT_TRUE ? "yes" : "no");
196 hr = IADsADSystemInfo_GetAnyDCName(sysinfo, &bstr);
197 ok(hr == S_OK, "got %#x\n", hr);
198 if (hr == S_OK) SysFreeString(bstr);
199 done:
200 IADsADSystemInfo_Release(sysinfo);
203 START_TEST(sysinfo)
205 HRESULT hr;
207 hr = CoInitialize(NULL);
208 ok(hr == S_OK, "got %#x\n", hr);
210 test_ComputerName();
211 test_UserName();
212 test_sysinfo();
214 CoUninitialize();