2020-03-23 14:14:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2020 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>
|
|
|
|
|
2020-04-10 09:34:14 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2020-03-23 14:14:39 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
2020-04-10 09:34:14 +02:00
|
|
|
#include "initguid.h"
|
2020-03-23 14:14:39 +01:00
|
|
|
#include "iads.h"
|
|
|
|
#include "adshlp.h"
|
|
|
|
#include "adserr.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2020-04-10 09:34:14 +02:00
|
|
|
DEFINE_GUID(CLSID_Pathname,0x080d0d78,0xf421,0x11d0,0xa3,0x6e,0x00,0xc0,0x4f,0xb9,0x50,0xdc);
|
|
|
|
|
2020-03-23 14:14:39 +01:00
|
|
|
static void test_ADsBuildVarArrayStr(void)
|
|
|
|
{
|
|
|
|
const WCHAR *props[] = { L"prop1", L"prop2" };
|
|
|
|
HRESULT hr;
|
|
|
|
VARIANT var, item, *data;
|
|
|
|
LONG start, end, idx;
|
|
|
|
|
|
|
|
hr = ADsBuildVarArrayStr(NULL, 0, NULL);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == E_ADS_BAD_PARAMETER || hr == E_FAIL /* XP */, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
|
|
|
|
hr = ADsBuildVarArrayStr(NULL, 0, &var);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
ok(V_VT(&var) == (VT_ARRAY | VT_VARIANT), "got %d\n", V_VT(&var));
|
|
|
|
start = 0xdeadbeef;
|
|
|
|
hr = SafeArrayGetLBound(V_ARRAY(&var), 1, &start);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(start == 0, "got %ld\n", start);
|
2020-03-23 14:14:39 +01:00
|
|
|
end = 0xdeadbeef;
|
|
|
|
hr = SafeArrayGetUBound(V_ARRAY(&var), 1, &end);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(end == -1, "got %ld\n", end);
|
2020-03-23 14:14:39 +01:00
|
|
|
VariantClear(&var);
|
|
|
|
|
|
|
|
hr = ADsBuildVarArrayStr((LPWSTR *)props, ARRAY_SIZE(props), &var);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
ok(V_VT(&var) == (VT_ARRAY | VT_VARIANT), "got %d\n", V_VT(&var));
|
|
|
|
start = 0xdeadbeef;
|
|
|
|
hr = SafeArrayGetLBound(V_ARRAY(&var), 1, &start);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(start == 0, "got %ld\n", start);
|
2020-03-23 14:14:39 +01:00
|
|
|
end = 0xdeadbeef;
|
|
|
|
hr = SafeArrayGetUBound(V_ARRAY(&var), 1, &end);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(end == 1, "got %ld\n", end);
|
2020-03-23 14:14:39 +01:00
|
|
|
idx = 0;
|
|
|
|
hr = SafeArrayGetElement(V_ARRAY(&var), &idx, &item);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
ok(V_VT(&item) == VT_BSTR, "got %d\n", V_VT(&item));
|
|
|
|
ok(!lstrcmpW(V_BSTR(&item), L"prop1"), "got %s\n", wine_dbgstr_w(V_BSTR(&item)));
|
|
|
|
VariantClear(&item);
|
|
|
|
hr = SafeArrayAccessData(V_ARRAY(&var), (void *)&data);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
ok(V_VT(&data[0]) == VT_BSTR, "got %d\n", V_VT(&data[0]));
|
|
|
|
ok(!lstrcmpW(V_BSTR(&data[0]), L"prop1"), "got %s\n", wine_dbgstr_w(V_BSTR(&data[0])));
|
|
|
|
ok(V_VT(&data[0]) == VT_BSTR, "got %d\n", V_VT(&data[0]));
|
|
|
|
ok(!lstrcmpW(V_BSTR(&data[1]), L"prop2"), "got %s\n", wine_dbgstr_w(V_BSTR(&data[1])));
|
|
|
|
hr = SafeArrayUnaccessData(V_ARRAY(&var));
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-03-23 14:14:39 +01:00
|
|
|
VariantClear(&var);
|
|
|
|
}
|
|
|
|
|
2020-04-10 09:34:14 +02:00
|
|
|
static void test_Pathname(void)
|
|
|
|
{
|
|
|
|
static const WCHAR * const elem[3] = { L"a=b",L"c=d",L"e=f" };
|
|
|
|
HRESULT hr;
|
|
|
|
IADsPathname *path;
|
|
|
|
BSTR bstr;
|
|
|
|
LONG count, i;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_Pathname, 0, CLSCTX_INPROC_SERVER, &IID_IADsPathname, (void **)&path);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
hr = IADsPathname_GetNumElements(path, &count);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(count == 0, "got %ld\n", count);
|
2020-04-10 09:34:14 +02:00
|
|
|
|
|
|
|
bstr = NULL;
|
|
|
|
hr = IADsPathname_Retrieve(path, ADS_FORMAT_X500, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
ok(bstr && !wcscmp(bstr, L"LDAP://"), "got %s\n", wine_dbgstr_w(bstr));
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
bstr = SysAllocString(L"LDAP://sample");
|
|
|
|
hr = IADsPathname_Set(path, bstr, ADS_SETTYPE_FULL);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
hr = IADsPathname_GetNumElements(path, &count);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(count == 0, "got %ld\n", count);
|
2020-04-10 09:34:14 +02:00
|
|
|
|
|
|
|
hr = IADsPathname_GetElement(path, 0, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_INDEX), "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
bstr = SysAllocString(L"LDAP://sample:123/a=b,c=d,e=f");
|
|
|
|
hr = IADsPathname_Set(path, bstr, ADS_SETTYPE_FULL);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
hr = IADsPathname_GetNumElements(path, &count);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(count == 3, "got %ld\n", count);
|
2020-04-10 09:34:38 +02:00
|
|
|
|
2020-04-10 09:34:14 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
hr = IADsPathname_GetElement(path, i, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
|
|
|
ok(!wcscmp(bstr, elem[i]), "%lu: %s\n", i, wine_dbgstr_w(bstr));
|
2020-04-10 09:34:14 +02:00
|
|
|
SysFreeString(bstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IADsPathname_Retrieve(path, ADS_FORMAT_X500, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
ok(!wcscmp(bstr, L"LDAP://sample:123/a=b,c=d,e=f"), "got %s\n", wine_dbgstr_w(bstr));
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
hr = IADsPathname_Retrieve(path, ADS_FORMAT_PROVIDER, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
ok(!wcscmp(bstr, L"LDAP"), "got %s\n", wine_dbgstr_w(bstr));
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
hr = IADsPathname_Retrieve(path, ADS_FORMAT_SERVER, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
ok(!wcscmp(bstr, L"sample:123"), "got %s\n", wine_dbgstr_w(bstr));
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
hr = IADsPathname_Retrieve(path, ADS_FORMAT_LEAF, &bstr);
|
2022-02-23 09:10:39 +01:00
|
|
|
ok(hr == S_OK, "got %#lx\n", hr);
|
2020-04-10 09:34:14 +02:00
|
|
|
ok(!wcscmp(bstr, L"a=b"), "got %s\n", wine_dbgstr_w(bstr));
|
|
|
|
SysFreeString(bstr);
|
|
|
|
|
|
|
|
IADsPathname_Release(path);
|
|
|
|
}
|
|
|
|
|
2020-03-23 14:14:39 +01:00
|
|
|
START_TEST(activeds)
|
|
|
|
{
|
2020-04-10 09:34:14 +02:00
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
test_Pathname();
|
2020-03-23 14:14:39 +01:00
|
|
|
test_ADsBuildVarArrayStr();
|
2020-04-10 09:34:14 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
2020-03-23 14:14:39 +01:00
|
|
|
}
|