[PATCH] adsldp: Add initial tests for ADSystemInfo.
Dmitry Timoshkov
dmitry at baikal.ru
Mon Feb 19 05:02:42 CST 2018
Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
configure.ac | 1 +
dlls/adsldp/tests/Makefile.in | 5 +
dlls/adsldp/tests/sysinfo.c | 228 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 234 insertions(+)
create mode 100644 dlls/adsldp/tests/Makefile.in
create mode 100644 dlls/adsldp/tests/sysinfo.c
diff --git a/configure.ac b/configure.ac
index d06476e6c9..18918b7924 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2794,6 +2794,7 @@ WINE_CONFIG_DLL(activeds,,[implib])
WINE_CONFIG_DLL(actxprxy,,[clean])
WINE_CONFIG_LIB(adsiid)
WINE_CONFIG_DLL(adsldp,,[clean])
+WINE_CONFIG_TEST(dlls/adsldp/tests)
WINE_CONFIG_DLL(adsldpc)
WINE_CONFIG_DLL(advapi32,,[clean,implib])
WINE_CONFIG_TEST(dlls/advapi32/tests)
diff --git a/dlls/adsldp/tests/Makefile.in b/dlls/adsldp/tests/Makefile.in
new file mode 100644
index 0000000000..777d2aa9de
--- /dev/null
+++ b/dlls/adsldp/tests/Makefile.in
@@ -0,0 +1,5 @@
+TESTDLL = adsldp.dll
+IMPORTS = ole32 oleaut32 secur32 advapi32 uuid
+
+C_SRCS = \
+ sysinfo.c
diff --git a/dlls/adsldp/tests/sysinfo.c b/dlls/adsldp/tests/sysinfo.c
new file mode 100644
index 0000000000..649fb7fa3b
--- /dev/null
+++ b/dlls/adsldp/tests/sysinfo.c
@@ -0,0 +1,228 @@
+/*
+ * ADSystemInfo Tests
+ *
+ * Copyright 2018 Dmitry Timoshkov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "winbase.h"
+#include "objbase.h"
+#include "initguid.h"
+#include "iads.h"
+#define SECURITY_WIN32
+#include "security.h"
+
+#include "wine/test.h"
+
+static WCHAR *strchrW(const WCHAR *str, WCHAR ch)
+{
+ do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
+ return NULL;
+}
+
+static void test_ComputerName(void)
+{
+ static const WCHAR cnW[] = { 'C','N','=' };
+ static const WCHAR ComputersW[] = { 'C','N','=','C','o','m','p','u','t','e','r','s' };
+ BOOL ret;
+ ULONG size, name_size;
+ WCHAR name[MAX_COMPUTERNAME_LENGTH + 1];
+ WCHAR buf[1024];
+ IADsADSystemInfo *sysinfo;
+ BSTR bstr;
+ HRESULT hr;
+
+ name_size = MAX_COMPUTERNAME_LENGTH + 1;
+ SetLastError(0xdeadbeef);
+ ret = GetComputerNameW(name, &name_size);
+ ok(ret, "GetComputerName error %u\n", GetLastError());
+
+ /* Distinguished name (rfc1779) is supposed to look like this:
+ * "CN=COMPNAME,CN=Computers,DC=domain,DC=com"
+ */
+
+ size = 1024;
+ SetLastError(0xdeadbeef);
+ ret = GetComputerObjectNameW(NameFullyQualifiedDN, buf, &size);
+ ok(ret || GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO, "GetComputerObjectName error %u\n", GetLastError());
+ if (ret)
+ {
+ const WCHAR *p;
+ ok(size == lstrlenW(buf) + 1, "got %u, expected %u\n", size, lstrlenW(buf) + 1);
+ ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
+ ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
+ p = strchrW(buf, ',');
+ ok(p != NULL, "delimiter was not found\n");
+ ok(p && !memcmp(p + 1, ComputersW, sizeof(ComputersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
+ }
+
+ hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
+ ok(hr == S_OK, "got %#x\n", hr);
+
+ hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
+todo_wine
+ ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_CANT_ACCESS_DOMAIN_INFO), "got %#x\n", hr);
+ if (hr == S_OK)
+ {
+ ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
+ SysFreeString(bstr);
+ }
+
+ IADsADSystemInfo_Release(sysinfo);
+}
+
+static void test_UserName(void)
+{
+ static const WCHAR cnW[] = { 'C','N','=' };
+ static const WCHAR UsersW[] = { 'C','N','=','U','s','e','r','s' };
+ BOOL ret;
+ ULONG size, name_size;
+ WCHAR name[256];
+ WCHAR buf[1024];
+ IADsADSystemInfo *sysinfo;
+ BSTR bstr;
+ HRESULT hr;
+
+ name_size = 256;
+ SetLastError(0xdeadbeef);
+ ret = GetUserNameW(name, &name_size);
+ ok(ret, "GetUserName error %u\n", GetLastError());
+
+ /* Distinguished name (rfc1779) is supposed to look like this:
+ * "CN=username,CN=Users,DC=domain,DC=com"
+ */
+
+ size = 1024;
+ SetLastError(0xdeadbeef);
+ ret = GetUserNameExW(NameFullyQualifiedDN, buf, &size);
+ ok(ret || GetLastError() == ERROR_NONE_MAPPED, "GetUserNameEx error %u\n", GetLastError());
+ if (ret)
+ {
+ const WCHAR *p;
+ ok(size == lstrlenW(buf), "got %u, expected %u\n", size, lstrlenW(buf));
+ ok(!memcmp(buf, cnW, sizeof(cnW)), "got %s\n", wine_dbgstr_w(buf));
+ ok(!memcmp(buf + 3, name, name_size), "got %s (name_size = %u)\n", wine_dbgstr_w(buf), name_size);
+ p = strchrW(buf, ',');
+ ok(p != NULL, "delimiter was not found\n");
+ ok(p && !memcmp(p + 1, UsersW, sizeof(UsersW)), "got %s\n", p ? wine_dbgstr_w(p + 1) : wine_dbgstr_w(buf));
+ }
+
+ hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
+ ok(hr == S_OK, "got %#x\n", hr);
+
+ hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
+todo_wine
+ ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
+ if (hr == S_OK)
+ {
+ ok(!lstrcmpW(bstr, buf), "got %s, expected %s\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
+ SysFreeString(bstr);
+ }
+
+ IADsADSystemInfo_Release(sysinfo);
+}
+
+static void test_sysinfo(void)
+{
+
+ IADsADSystemInfo *sysinfo;
+ IDispatch *dispatch;
+ BSTR bstr;
+ VARIANT_BOOL value;
+ HRESULT hr;
+
+ hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IUnknown, (void **)&sysinfo);
+ ok(hr == S_OK, "got %#x\n", hr);
+ IADsADSystemInfo_Release(sysinfo);
+
+ hr = CoCreateInstance(&CLSID_ADSystemInfo, 0, CLSCTX_ALL, &IID_IADsADSystemInfo, (void **)&sysinfo);
+ ok(hr == S_OK, "got %#x\n", hr);
+
+ hr = IADsADSystemInfo_QueryInterface(sysinfo, &IID_IDispatch, (void **)&dispatch);
+ ok(hr == S_OK, "got %#x\n", hr);
+ IDispatch_Release(dispatch);
+
+ hr = IADsADSystemInfo_get_UserName(sysinfo, &bstr);
+todo_wine
+ ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NONE_MAPPED), "got %#x\n", hr);
+ if (hr != S_OK)
+ {
+ skip("Computer is not part of a domain, skipping the tests\n");
+ IADsADSystemInfo_Release(sysinfo);
+ return;
+ }
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_ComputerName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_SiteName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_DomainShortName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_DomainDNSName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_ForestDNSName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_PDCRoleOwner(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ hr = IADsADSystemInfo_get_IsNativeMode(sysinfo, &value);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ ok(value == VARIANT_TRUE, "IsNativeMode: %s\n", value == VARIANT_TRUE ? "yes" : "no");
+
+ hr = IADsADSystemInfo_GetAnyDCName(sysinfo, &bstr);
+ ok(hr == S_OK, "got %#x\n", hr);
+if (hr == S_OK)
+ SysFreeString(bstr);
+
+ IADsADSystemInfo_Release(sysinfo);
+}
+
+START_TEST(sysinfo)
+{
+ HRESULT hr;
+
+ hr = CoInitialize(NULL);
+ ok(hr == S_OK, "got %#x\n", hr);
+
+ test_ComputerName();
+ test_UserName();
+ test_sysinfo();
+}
--
2.16.1
More information about the wine-devel
mailing list