2 * Copyright 2020 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 DEFINE_GUID(CLSID_Pathname
,0x080d0d78,0xf421,0x11d0,0xa3,0x6e,0x00,0xc0,0x4f,0xb9,0x50,0xdc);
36 static void test_ADsBuildVarArrayStr(void)
38 const WCHAR
*props
[] = { L
"prop1", L
"prop2" };
40 VARIANT var
, item
, *data
;
43 hr
= ADsBuildVarArrayStr(NULL
, 0, NULL
);
44 ok(hr
== E_ADS_BAD_PARAMETER
|| hr
== E_FAIL
/* XP */, "got %#x\n", hr
);
46 hr
= ADsBuildVarArrayStr(NULL
, 0, &var
);
47 ok(hr
== S_OK
, "got %#x\n", hr
);
48 ok(V_VT(&var
) == (VT_ARRAY
| VT_VARIANT
), "got %d\n", V_VT(&var
));
50 hr
= SafeArrayGetLBound(V_ARRAY(&var
), 1, &start
);
51 ok(hr
== S_OK
, "got %#x\n", hr
);
52 ok(start
== 0, "got %d\n", start
);
54 hr
= SafeArrayGetUBound(V_ARRAY(&var
), 1, &end
);
55 ok(hr
== S_OK
, "got %#x\n", hr
);
56 ok(end
== -1, "got %d\n", end
);
59 hr
= ADsBuildVarArrayStr((LPWSTR
*)props
, ARRAY_SIZE(props
), &var
);
60 ok(hr
== S_OK
, "got %#x\n", hr
);
61 ok(V_VT(&var
) == (VT_ARRAY
| VT_VARIANT
), "got %d\n", V_VT(&var
));
63 hr
= SafeArrayGetLBound(V_ARRAY(&var
), 1, &start
);
64 ok(hr
== S_OK
, "got %#x\n", hr
);
65 ok(start
== 0, "got %d\n", start
);
67 hr
= SafeArrayGetUBound(V_ARRAY(&var
), 1, &end
);
68 ok(hr
== S_OK
, "got %#x\n", hr
);
69 ok(end
== 1, "got %d\n", end
);
71 hr
= SafeArrayGetElement(V_ARRAY(&var
), &idx
, &item
);
72 ok(hr
== S_OK
, "got %#x\n", hr
);
73 ok(V_VT(&item
) == VT_BSTR
, "got %d\n", V_VT(&item
));
74 ok(!lstrcmpW(V_BSTR(&item
), L
"prop1"), "got %s\n", wine_dbgstr_w(V_BSTR(&item
)));
76 hr
= SafeArrayAccessData(V_ARRAY(&var
), (void *)&data
);
77 ok(hr
== S_OK
, "got %#x\n", hr
);
78 ok(V_VT(&data
[0]) == VT_BSTR
, "got %d\n", V_VT(&data
[0]));
79 ok(!lstrcmpW(V_BSTR(&data
[0]), L
"prop1"), "got %s\n", wine_dbgstr_w(V_BSTR(&data
[0])));
80 ok(V_VT(&data
[0]) == VT_BSTR
, "got %d\n", V_VT(&data
[0]));
81 ok(!lstrcmpW(V_BSTR(&data
[1]), L
"prop2"), "got %s\n", wine_dbgstr_w(V_BSTR(&data
[1])));
82 hr
= SafeArrayUnaccessData(V_ARRAY(&var
));
83 ok(hr
== S_OK
, "got %#x\n", hr
);
87 static void test_Pathname(void)
89 static const WCHAR
* const elem
[3] = { L
"a=b",L
"c=d",L
"e=f" };
95 hr
= CoCreateInstance(&CLSID_Pathname
, 0, CLSCTX_INPROC_SERVER
, &IID_IADsPathname
, (void **)&path
);
96 ok(hr
== S_OK
, "got %#x\n", hr
);
99 hr
= IADsPathname_GetNumElements(path
, &count
);
100 ok(hr
== S_OK
, "got %#x\n", hr
);
101 ok(count
== 0, "got %d\n", count
);
104 hr
= IADsPathname_Retrieve(path
, ADS_FORMAT_X500
, &bstr
);
105 ok(hr
== S_OK
, "got %#x\n", hr
);
106 ok(bstr
&& !wcscmp(bstr
, L
"LDAP://"), "got %s\n", wine_dbgstr_w(bstr
));
109 bstr
= SysAllocString(L
"LDAP://sample");
110 hr
= IADsPathname_Set(path
, bstr
, ADS_SETTYPE_FULL
);
111 ok(hr
== S_OK
, "got %#x\n", hr
);
115 hr
= IADsPathname_GetNumElements(path
, &count
);
116 ok(hr
== S_OK
, "got %#x\n", hr
);
117 ok(count
== 0, "got %d\n", count
);
119 hr
= IADsPathname_GetElement(path
, 0, &bstr
);
120 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_INDEX
), "got %#x\n", hr
);
123 bstr
= SysAllocString(L
"LDAP://sample:123/a=b,c=d,e=f");
124 hr
= IADsPathname_Set(path
, bstr
, ADS_SETTYPE_FULL
);
125 ok(hr
== S_OK
, "got %#x\n", hr
);
129 hr
= IADsPathname_GetNumElements(path
, &count
);
130 ok(hr
== S_OK
, "got %#x\n", hr
);
131 ok(count
== 3, "got %d\n", count
);
133 for (i
= 0; i
< count
; i
++)
135 hr
= IADsPathname_GetElement(path
, i
, &bstr
);
136 ok(hr
== S_OK
, "got %#x\n", hr
);
137 ok(!wcscmp(bstr
, elem
[i
]), "%u: %s\n", i
, wine_dbgstr_w(bstr
));
141 hr
= IADsPathname_Retrieve(path
, ADS_FORMAT_X500
, &bstr
);
142 ok(hr
== S_OK
, "got %#x\n", hr
);
143 ok(!wcscmp(bstr
, L
"LDAP://sample:123/a=b,c=d,e=f"), "got %s\n", wine_dbgstr_w(bstr
));
146 hr
= IADsPathname_Retrieve(path
, ADS_FORMAT_PROVIDER
, &bstr
);
147 ok(hr
== S_OK
, "got %#x\n", hr
);
148 ok(!wcscmp(bstr
, L
"LDAP"), "got %s\n", wine_dbgstr_w(bstr
));
151 hr
= IADsPathname_Retrieve(path
, ADS_FORMAT_SERVER
, &bstr
);
152 ok(hr
== S_OK
, "got %#x\n", hr
);
153 ok(!wcscmp(bstr
, L
"sample:123"), "got %s\n", wine_dbgstr_w(bstr
));
156 hr
= IADsPathname_Retrieve(path
, ADS_FORMAT_LEAF
, &bstr
);
157 ok(hr
== S_OK
, "got %#x\n", hr
);
158 ok(!wcscmp(bstr
, L
"a=b"), "got %s\n", wine_dbgstr_w(bstr
));
161 IADsPathname_Release(path
);
169 test_ADsBuildVarArrayStr();