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
31 #define SECURITY_WIN32
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' };
41 ULONG size
, name_size
;
42 WCHAR name
[MAX_COMPUTERNAME_LENGTH
+ 1];
44 IADsADSystemInfo
*sysinfo
;
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"
58 SetLastError(0xdeadbeef);
59 ret
= GetComputerObjectNameW(NameFullyQualifiedDN
, buf
, &size
);
60 ok(ret
|| GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO
, "GetComputerObjectName error %u\n", GetLastError());
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
);
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
);
79 ok(!lstrcmpW(bstr
, buf
), "got %s, expected %s\n", wine_dbgstr_w(bstr
), wine_dbgstr_w(buf
));
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' };
91 ULONG size
, name_size
;
94 IADsADSystemInfo
*sysinfo
;
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"
108 SetLastError(0xdeadbeef);
109 ret
= GetUserNameExW(NameFullyQualifiedDN
, buf
, &size
);
110 ok(ret
|| GetLastError() == ERROR_NONE_MAPPED
, "GetUserNameEx error %u\n", GetLastError());
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
);
127 ok(hr
== S_OK
|| hr
== HRESULT_FROM_WIN32(ERROR_NONE_MAPPED
), "got %#x\n", hr
);
130 ok(!lstrcmpW(bstr
, buf
), "got %s, expected %s\n", wine_dbgstr_w(bstr
), wine_dbgstr_w(buf
));
134 IADsADSystemInfo_Release(sysinfo
);
137 static void test_sysinfo(void)
140 IADsADSystemInfo
*sysinfo
;
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
);
161 skip("Computer is not part of a domain, skipping the tests\n");
166 hr
= IADsADSystemInfo_get_UserName(sysinfo
, &bstr
);
168 ok(hr
== S_OK
|| hr
== HRESULT_FROM_WIN32(ERROR_NONE_MAPPED
), "got %#x\n", hr
);
169 if (hr
!= S_OK
) goto done
;
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
);
200 IADsADSystemInfo_Release(sysinfo
);
207 hr
= CoInitialize(NULL
);
208 ok(hr
== S_OK
, "got %#x\n", hr
);