adsldp: Add initial tests for ADSystemInfo.
[wine.git] / dlls / adsldp / tests / sysinfo.c
blob73435a612959bd15262aafb6c409cc12e240e88d
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 WCHAR *strchrW(const WCHAR *str, WCHAR ch)
38 do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
39 return NULL;
42 static void test_ComputerName(void)
44 static const WCHAR cnW[] = { 'C','N','=' };
45 static const WCHAR ComputersW[] = { 'C','N','=','C','o','m','p','u','t','e','r','s' };
46 BOOL ret;
47 ULONG size, name_size;
48 WCHAR name[MAX_COMPUTERNAME_LENGTH + 1];
49 WCHAR buf[1024];
50 IADsADSystemInfo *sysinfo;
51 BSTR bstr;
52 HRESULT hr;
54 name_size = MAX_COMPUTERNAME_LENGTH + 1;
55 SetLastError(0xdeadbeef);
56 ret = GetComputerNameW(name, &name_size);
57 ok(ret, "GetComputerName error %u\n", GetLastError());
59 /* Distinguished name (rfc1779) is supposed to look like this:
60 * "CN=COMPNAME,CN=Computers,DC=domain,DC=com"
63 size = 1024;
64 SetLastError(0xdeadbeef);
65 ret = GetComputerObjectNameW(NameFullyQualifiedDN, buf, &size);
66 ok(ret || GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO, "GetComputerObjectName error %u\n", GetLastError());
67 if (ret)
69 const WCHAR *p;
70 ok(size == lstrlenW(buf) + 1, "got %u, expected %u\n", size, lstrlenW(buf) + 1);
71 ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
72 ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
73 p = strchrW(buf, ',');
74 ok(p != NULL, "delimiter was not found\n");
75 ok(p && !memcmp(p + 1, ComputersW, sizeof(ComputersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
78 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
79 ok(hr == S_OK, "got %#x\n", hr);
81 hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
82 todo_wine
83 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#x\n", hr);
84 if (hr == S_OK)
86 ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
87 SysFreeString(bstr);
90 IADsADSystemInfo_Release(sysinfo);
93 static void test_UserName(void)
95 static const WCHAR cnW[] = { 'C','N','=' };
96 static const WCHAR UsersW[] = { 'C','N','=','U','s','e','r','s' };
97 BOOL ret;
98 ULONG size, name_size;
99 WCHAR name[256];
100 WCHAR buf[1024];
101 IADsADSystemInfo *sysinfo;
102 BSTR bstr;
103 HRESULT hr;
105 name_size = 256;
106 SetLastError(0xdeadbeef);
107 ret = GetUserNameW(name, &name_size);
108 ok(ret, "GetUserName error %u\n", GetLastError());
110 /* Distinguished name (rfc1779) is supposed to look like this:
111 * "CN=username,CN=Users,DC=domain,DC=com"
114 size = 1024;
115 SetLastError(0xdeadbeef);
116 ret = GetUserNameExW(NameFullyQualifiedDN, buf, &size);
117 ok(ret || GetLastError() == ERROR_NONE_MAPPED, "GetUserNameEx error %u\n", GetLastError());
118 if (ret)
120 const WCHAR *p;
121 ok(size == lstrlenW(buf), "got %u, expected %u\n", size, lstrlenW(buf));
122 ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
123 ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
124 p = strchrW(buf, ',');
125 ok(p != NULL, "delimiter was not found\n");
126 ok(p && !memcmp(p + 1, UsersW, sizeof(UsersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
129 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
130 ok(hr == S_OK, "got %#x\n", hr);
132 hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
133 todo_wine
134 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
135 if (hr == S_OK)
137 ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
138 SysFreeString(bstr);
141 IADsADSystemInfo_Release(sysinfo);
144 static void test_sysinfo(void)
147 IADsADSystemInfo *sysinfo;
148 IDispatch *dispatch;
149 BSTR bstr;
150 VARIANT_BOOL value;
151 HRESULT hr;
153 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IUnknown, (void **)&sysinfo);
154 ok(hr == S_OK, "got %#x\n", hr);
155 IADsADSystemInfo_Release(sysinfo);
157 hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
158 ok(hr == S_OK, "got %#x\n", hr);
160 hr = IADsADSystemInfo_QueryInterface(sysinfo, &IID_IDispatch, (void **)&dispatch);
161 ok(hr == S_OK, "got %#x\n", hr);
162 IDispatch_Release(dispatch);
164 hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
165 todo_wine
166 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
167 if (hr != S_OK)
169 skip("Computer is not part of a domain, skipping the tests\n");
170 IADsADSystemInfo_Release(sysinfo);
171 return;
173 SysFreeString(bstr);
175 hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
176 ok(hr == S_OK, "got %#x\n", hr);
177 if (hr == S_OK) SysFreeString(bstr);
179 hr = IADsADSystemInfo_get_SiteName(sysinfo, &bstr);
180 ok(hr == S_OK, "got %#x\n", hr);
181 if (hr == S_OK) SysFreeString(bstr);
183 hr = IADsADSystemInfo_get_DomainShortName(sysinfo, &bstr);
184 ok(hr == S_OK, "got %#x\n", hr);
185 if (hr == S_OK) SysFreeString(bstr);
187 hr = IADsADSystemInfo_get_DomainDNSName(sysinfo, &bstr);
188 ok(hr == S_OK, "got %#x\n", hr);
189 if (hr == S_OK) SysFreeString(bstr);
191 hr = IADsADSystemInfo_get_ForestDNSName(sysinfo, &bstr);
192 ok(hr == S_OK, "got %#x\n", hr);
193 if (hr == S_OK) SysFreeString(bstr);
195 hr = IADsADSystemInfo_get_PDCRoleOwner(sysinfo, &bstr);
196 ok(hr == S_OK, "got %#x\n", hr);
197 if (hr == S_OK) SysFreeString(bstr);
199 hr = IADsADSystemInfo_get_IsNativeMode(sysinfo, &value);
200 ok(hr == S_OK, "got %#x\n", hr);
201 if (hr == S_OK) ok(value == VARIANT_TRUE, "IsNativeMode: %s\n", value == VARIANT_TRUE ? "yes" : "no");
203 hr = IADsADSystemInfo_GetAnyDCName(sysinfo, &bstr);
204 ok(hr == S_OK, "got %#x\n", hr);
205 if (hr == S_OK) SysFreeString(bstr);
207 IADsADSystemInfo_Release(sysinfo);
210 START_TEST(sysinfo)
212 HRESULT hr;
214 hr = CoInitialize(NULL);
215 ok(hr == S_OK, "got %#x\n", hr);
217 test_ComputerName();
218 test_UserName();
219 test_sysinfo();