Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/adsldp/tests/sysinfo.c
4394 views
1
/*
2
* ADSystemInfo Tests
3
*
4
* Copyright 2018 Dmitry Timoshkov
5
*
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.
10
*
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.
15
*
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
19
*/
20
21
#include <stdarg.h>
22
#include <stdio.h>
23
24
#define COBJMACROS
25
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"
33
34
#include "wine/test.h"
35
36
static void test_ComputerName(void)
37
{
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;
47
48
name_size = MAX_COMPUTERNAME_LENGTH + 1;
49
SetLastError(0xdeadbeef);
50
ret = GetComputerNameW(name, &name_size);
51
ok(ret, "GetComputerName error %lu\n", GetLastError());
52
53
/* Distinguished name (rfc1779) is supposed to look like this:
54
* "CN=COMPNAME,CN=Computers,DC=domain,DC=com"
55
*/
56
57
size = 1024;
58
SetLastError(0xdeadbeef);
59
ret = GetComputerObjectNameW(NameFullyQualifiedDN, buf, &size);
60
ok(ret || GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO, "GetComputerObjectName error %lu\n", GetLastError());
61
if (ret)
62
{
63
const WCHAR *p;
64
ok(size == lstrlenW(buf) + 1, "got %lu, 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 = %lu)\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));
70
}
71
72
hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
73
ok(hr == S_OK, "got %#lx\n", hr);
74
75
hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
76
ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#lx\n", hr);
77
if (hr == S_OK)
78
{
79
ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
80
SysFreeString(bstr);
81
}
82
83
IADsADSystemInfo_Release(sysinfo);
84
}
85
86
static void test_UserName(void)
87
{
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;
97
98
name_size = 256;
99
SetLastError(0xdeadbeef);
100
ret = GetUserNameW(name, &name_size);
101
ok(ret, "GetUserName error %lu\n", GetLastError());
102
103
/* Distinguished name (rfc1779) is supposed to look like this:
104
* "CN=username,CN=Users,DC=domain,DC=com"
105
*/
106
107
size = 1024;
108
SetLastError(0xdeadbeef);
109
ret = GetUserNameExW(NameFullyQualifiedDN, buf, &size);
110
ok(ret || GetLastError() == ERROR_NONE_MAPPED, "GetUserNameEx error %lu\n", GetLastError());
111
if (ret)
112
{
113
const WCHAR *p;
114
ok(size == lstrlenW(buf), "got %lu, 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 = %lu)\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));
120
}
121
122
hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
123
ok(hr == S_OK, "got %#lx\n", hr);
124
125
hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
126
todo_wine
127
ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#lx\n", hr);
128
if (hr == S_OK)
129
{
130
ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
131
SysFreeString(bstr);
132
}
133
134
IADsADSystemInfo_Release(sysinfo);
135
}
136
137
static void test_sysinfo(void)
138
{
139
140
IADsADSystemInfo *sysinfo;
141
IDispatch *dispatch;
142
BSTR bstr;
143
VARIANT_BOOL value;
144
HRESULT hr;
145
146
hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IUnknown, (void **)&sysinfo);
147
ok(hr == S_OK, "got %#lx\n", hr);
148
IADsADSystemInfo_Release(sysinfo);
149
150
hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
151
ok(hr == S_OK, "got %#lx\n", hr);
152
153
hr = IADsADSystemInfo_QueryInterface(sysinfo, &IID_IDispatch, (void **)&dispatch);
154
ok(hr == S_OK, "got %#lx\n", hr);
155
IDispatch_Release(dispatch);
156
157
hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
158
ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#lx\n", hr);
159
if (hr != S_OK)
160
{
161
skip("Computer is not part of a domain, skipping the tests\n");
162
goto done;
163
}
164
SysFreeString(bstr);
165
166
hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
167
todo_wine
168
ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#lx\n", hr);
169
if (hr != S_OK) goto done;
170
SysFreeString(bstr);
171
172
hr = IADsADSystemInfo_get_SiteName(sysinfo, &bstr);
173
ok(hr == S_OK, "got %#lx\n", hr);
174
if (hr == S_OK) SysFreeString(bstr);
175
176
hr = IADsADSystemInfo_get_DomainShortName(sysinfo, &bstr);
177
ok(hr == S_OK, "got %#lx\n", hr);
178
if (hr == S_OK) SysFreeString(bstr);
179
180
hr = IADsADSystemInfo_get_DomainDNSName(sysinfo, &bstr);
181
ok(hr == S_OK, "got %#lx\n", hr);
182
if (hr == S_OK) SysFreeString(bstr);
183
184
hr = IADsADSystemInfo_get_ForestDNSName(sysinfo, &bstr);
185
ok(hr == S_OK, "got %#lx\n", hr);
186
if (hr == S_OK) SysFreeString(bstr);
187
188
hr = IADsADSystemInfo_get_PDCRoleOwner(sysinfo, &bstr);
189
ok(hr == S_OK, "got %#lx\n", hr);
190
if (hr == S_OK) SysFreeString(bstr);
191
192
hr = IADsADSystemInfo_get_IsNativeMode(sysinfo, &value);
193
ok(hr == S_OK, "got %#lx\n", hr);
194
if (hr == S_OK) ok(value == VARIANT_TRUE, "IsNativeMode: %s\n", value == VARIANT_TRUE ? "yes" : "no");
195
196
hr = IADsADSystemInfo_GetAnyDCName(sysinfo, &bstr);
197
ok(hr == S_OK, "got %#lx\n", hr);
198
if (hr == S_OK) SysFreeString(bstr);
199
done:
200
IADsADSystemInfo_Release(sysinfo);
201
}
202
203
START_TEST(sysinfo)
204
{
205
HRESULT hr;
206
207
hr = CoInitialize(NULL);
208
ok(hr == S_OK, "got %#lx\n", hr);
209
210
test_ComputerName();
211
test_UserName();
212
test_sysinfo();
213
214
CoUninitialize();
215
}
216
217