2 * Web Services on Devices
5 * Copyright 2017 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
29 static LPWSTR largeText
;
30 static const int largeTextSize
= 10000 * sizeof(WCHAR
);
32 static void BuildAnyForSingleElement_tests(void)
34 WSDXML_ELEMENT
*element
;
37 static const WCHAR
*text
= L
"Hello";
40 /* Populate structures */
41 ns
.Uri
= L
"http://test.test/";
42 ns
.PreferredPrefix
= L
"t";
44 name
.LocalName
= (WCHAR
*) L
"El1";
47 /* Test invalid arguments */
48 hr
= WSDXMLBuildAnyForSingleElement(NULL
, NULL
, NULL
);
49 ok(hr
== E_INVALIDARG
, "BuildAnyForSingleElement failed with %08x\n", hr
);
51 hr
= WSDXMLBuildAnyForSingleElement(&name
, NULL
, NULL
);
52 ok(hr
== E_POINTER
, "BuildAnyForSingleElement failed with %08x\n", hr
);
54 /* Test calling the function with a text size that exceeds 8192 characters */
55 hr
= WSDXMLBuildAnyForSingleElement(&name
, largeText
, &element
);
56 ok(hr
== E_INVALIDARG
, "BuildAnyForSingleElement failed with %08x\n", hr
);
58 /* Test with valid parameters but no text */
60 hr
= WSDXMLBuildAnyForSingleElement(&name
, NULL
, &element
);
61 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
63 ok(element
->Name
!= &name
, "element->Name has not been duplicated\n");
64 ok(element
->Name
->Space
!= name
.Space
, "element->Name->Space has not been duplicated\n");
65 ok(element
->Name
->LocalName
!= name
.LocalName
, "element->LocalName has not been duplicated\n");
66 ok(lstrcmpW(element
->Name
->LocalName
, name
.LocalName
) == 0, "element->LocalName = %s, expected %s\n",
67 wine_dbgstr_w(element
->Name
->LocalName
), wine_dbgstr_w(name
.LocalName
));
68 ok(element
->FirstChild
== NULL
, "element->FirstChild == %p\n", element
->FirstChild
);
69 ok(element
->Node
.Next
== NULL
, "element->Node.Next == %p\n", element
->Node
.Next
);
70 ok(element
->Node
.Type
== ElementType
, "element->Node.Type == %d\n", element
->Node
.Type
);
72 WSDFreeLinkedMemory(element
);
74 /* Test with valid parameters and text */
76 hr
= WSDXMLBuildAnyForSingleElement(&name
, text
, &element
);
77 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
79 ok(element
->Name
!= &name
, "element->Name has not been duplicated\n");
80 ok(element
->Name
->Space
!= name
.Space
, "element->Name->Space has not been duplicated\n");
81 ok(element
->Name
->LocalName
!= name
.LocalName
, "element->LocalName has not been duplicated\n");
82 ok(lstrcmpW(element
->Name
->LocalName
, name
.LocalName
) == 0, "element->LocalName = %s, expected %s\n",
83 wine_dbgstr_w(element
->Name
->LocalName
), wine_dbgstr_w(name
.LocalName
));
84 ok(element
->FirstChild
!= NULL
, "element->FirstChild == %p\n", element
->FirstChild
);
85 ok(element
->Node
.Next
== NULL
, "element->Node.Next == %p\n", element
->Node
.Next
);
86 ok(element
->Node
.Type
== ElementType
, "element->Node.Type == %d\n", element
->Node
.Type
);
88 if (element
->FirstChild
!= NULL
)
90 ok(element
->FirstChild
->Parent
== element
, "element->FirstChild->Parent = %p, expected %p\n", element
->FirstChild
->Parent
, element
);
91 ok(element
->FirstChild
->Next
== NULL
, "element->FirstChild.Next == %p\n", element
->FirstChild
->Next
);
92 ok(element
->FirstChild
->Type
== TextType
, "element->FirstChild.Type == %d\n", element
->Node
.Type
);
93 ok(((WSDXML_TEXT
*)element
->FirstChild
)->Text
!= NULL
, "element->FirstChild.Text is null\n");
94 ok(lstrcmpW(((WSDXML_TEXT
*)element
->FirstChild
)->Text
, text
) == 0, "element->FirstChild->Text = %s, expected %s\n",
95 wine_dbgstr_w(((WSDXML_TEXT
*)element
->FirstChild
)->Text
), wine_dbgstr_w(text
));
98 WSDFreeLinkedMemory(element
);
101 static void AddChild_tests(void)
103 WSDXML_ELEMENT
*parent
, *child1
, *child2
;
104 WSDXML_NAME parentName
, child1Name
, child2Name
;
106 static const WCHAR
*child1NameText
= L
"Tim";
109 /* Test invalid values */
110 hr
= WSDXMLAddChild(NULL
, NULL
);
111 ok(hr
== E_INVALIDARG
, "WSDXMLAddChild failed with %08x\n", hr
);
113 /* Populate structures */
114 ns
.Uri
= L
"http://test.test/";
115 ns
.PreferredPrefix
= L
"t";
117 parentName
.LocalName
= (WCHAR
*) L
"Dad";
118 parentName
.Space
= &ns
;
120 child1Name
.LocalName
= (WCHAR
*) child1NameText
;
121 child1Name
.Space
= &ns
;
123 child2Name
.LocalName
= (WCHAR
*) L
"Bob";
124 child2Name
.Space
= &ns
;
126 /* Create some elements */
127 hr
= WSDXMLBuildAnyForSingleElement(&parentName
, NULL
, &parent
);
128 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
130 hr
= WSDXMLBuildAnyForSingleElement(&child1Name
, child1NameText
, &child1
);
131 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
133 hr
= WSDXMLBuildAnyForSingleElement(&child2Name
, NULL
, &child2
);
134 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
136 ok(parent
->Node
.Parent
== NULL
, "parent->Node.Parent == %p\n", parent
->Node
.Parent
);
137 ok(parent
->FirstChild
== NULL
, "parent->FirstChild == %p\n", parent
->FirstChild
);
138 ok(parent
->Node
.Next
== NULL
, "parent->Node.Next == %p\n", parent
->Node
.Next
);
139 ok(child1
->Node
.Parent
== NULL
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
140 ok(child1
->FirstChild
!= NULL
, "child1->FirstChild == NULL\n");
141 ok(child1
->FirstChild
->Type
== TextType
, "child1->FirstChild.Type == %d\n", child1
->FirstChild
->Type
);
142 ok(child1
->Node
.Next
== NULL
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
144 /* Add the child to the parent */
145 hr
= WSDXMLAddChild(parent
, child1
);
146 ok(hr
== S_OK
, "WSDXMLAddChild failed with %08x\n", hr
);
148 ok(parent
->Node
.Parent
== NULL
, "parent->Node.Parent == %p\n", parent
->Node
.Parent
);
149 ok(parent
->FirstChild
== (WSDXML_NODE
*)child1
, "parent->FirstChild == %p\n", parent
->FirstChild
);
150 ok(parent
->Node
.Next
== NULL
, "parent->Node.Next == %p\n", parent
->Node
.Next
);
151 ok(child1
->Node
.Parent
== parent
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
152 ok(child1
->FirstChild
!= NULL
, "child1->FirstChild == NULL\n");
153 ok(child1
->FirstChild
->Type
== TextType
, "child1->FirstChild.Type == %d\n", child1
->FirstChild
->Type
);
154 ok(child1
->Node
.Next
== NULL
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
156 /* Try to set child1 as the child of child2, which already has a parent */
157 hr
= WSDXMLAddChild(child2
, child1
);
158 ok(hr
== E_INVALIDARG
, "WSDXMLAddChild failed with %08x\n", hr
);
160 /* Try to set child2 as the child of child1, which has a text node as a child */
161 hr
= WSDXMLAddChild(child2
, child1
);
162 ok(hr
== E_INVALIDARG
, "WSDXMLAddChild failed with %08x\n", hr
);
164 /* Add child2 as a child of parent */
165 hr
= WSDXMLAddChild(parent
, child2
);
166 ok(hr
== S_OK
, "WSDXMLAddChild failed with %08x\n", hr
);
168 ok(parent
->Node
.Parent
== NULL
, "parent->Node.Parent == %p\n", parent
->Node
.Parent
);
169 ok(parent
->FirstChild
== (WSDXML_NODE
*)child1
, "parent->FirstChild == %p\n", parent
->FirstChild
);
170 ok(parent
->Node
.Next
== NULL
, "parent->Node.Next == %p\n", parent
->Node
.Next
);
171 ok(child1
->Node
.Parent
== parent
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
172 ok(child1
->FirstChild
!= NULL
, "child1->FirstChild == NULL\n");
173 ok(child1
->FirstChild
->Type
== TextType
, "child1->FirstChild.Type == %d\n", child1
->FirstChild
->Type
);
174 ok(child1
->Node
.Next
== (WSDXML_NODE
*)child2
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
175 ok(child2
->Node
.Parent
== parent
, "child2->Node.Parent == %p\n", child2
->Node
.Parent
);
176 ok(child2
->FirstChild
== NULL
, "child2->FirstChild == %p\n", child2
->FirstChild
);
177 ok(child2
->Node
.Next
== NULL
, "child2->Node.Next == %p\n", child2
->Node
.Next
);
179 WSDFreeLinkedMemory(parent
);
182 static void AddSibling_tests(void)
184 WSDXML_ELEMENT
*parent
, *child1
, *child2
, *child3
;
185 WSDXML_NAME parentName
, child1Name
, child2Name
;
187 static const WCHAR
*child1NameText
= L
"Tim";
190 /* Test invalid values */
191 hr
= WSDXMLAddSibling(NULL
, NULL
);
192 ok(hr
== E_INVALIDARG
, "WSDXMLAddSibling failed with %08x\n", hr
);
194 /* Populate structures */
195 ns
.Uri
= L
"http://test.test/";
196 ns
.PreferredPrefix
= L
"t";
198 parentName
.LocalName
= (WCHAR
*) L
"Dad";
199 parentName
.Space
= &ns
;
201 child1Name
.LocalName
= (WCHAR
*) child1NameText
;
202 child1Name
.Space
= &ns
;
204 child2Name
.LocalName
= (WCHAR
*) L
"Bob";
205 child2Name
.Space
= &ns
;
207 /* Create some elements */
208 hr
= WSDXMLBuildAnyForSingleElement(&parentName
, NULL
, &parent
);
209 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
211 hr
= WSDXMLBuildAnyForSingleElement(&child1Name
, child1NameText
, &child1
);
212 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
214 hr
= WSDXMLBuildAnyForSingleElement(&child2Name
, NULL
, &child2
);
215 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
217 hr
= WSDXMLBuildAnyForSingleElement(&child2Name
, NULL
, &child3
);
218 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
220 /* Add child1 to parent */
221 hr
= WSDXMLAddChild(parent
, child1
);
222 ok(hr
== S_OK
, "WSDXMLAddChild failed with %08x\n", hr
);
224 ok(parent
->Node
.Parent
== NULL
, "parent->Node.Parent == %p\n", parent
->Node
.Parent
);
225 ok(parent
->FirstChild
== (WSDXML_NODE
*)child1
, "parent->FirstChild == %p\n", parent
->FirstChild
);
226 ok(parent
->Node
.Next
== NULL
, "parent->Node.Next == %p\n", parent
->Node
.Next
);
227 ok(child1
->Node
.Parent
== parent
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
228 ok(child1
->FirstChild
!= NULL
, "child1->FirstChild == NULL\n");
229 ok(child1
->FirstChild
->Type
== TextType
, "child1->FirstChild.Type == %d\n", child1
->FirstChild
->Type
);
230 ok(child1
->Node
.Next
== NULL
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
231 ok(child2
->Node
.Parent
== NULL
, "child2->Node.Parent == %p\n", child2
->Node
.Parent
);
232 ok(child2
->FirstChild
== NULL
, "child2->FirstChild == %p\n", child2
->FirstChild
);
233 ok(child2
->Node
.Next
== NULL
, "child2->Node.Next == %p\n", child2
->Node
.Next
);
235 /* Try to add child2 as sibling of child1 */
236 hr
= WSDXMLAddSibling(child1
, child2
);
237 ok(hr
== S_OK
, "WSDXMLAddSibling failed with %08x\n", hr
);
239 ok(child1
->Node
.Parent
== parent
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
240 ok(child1
->Node
.Next
== (WSDXML_NODE
*)child2
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
241 ok(child2
->Node
.Parent
== parent
, "child2->Node.Parent == %p\n", child2
->Node
.Parent
);
242 ok(child2
->Node
.Next
== NULL
, "child2->Node.Next == %p\n", child2
->Node
.Next
);
243 ok(parent
->FirstChild
== (WSDXML_NODE
*)child1
, "parent->FirstChild == %p\n", parent
->FirstChild
);
245 /* Try to add child3 as sibling of child1 */
246 hr
= WSDXMLAddSibling(child1
, child3
);
247 ok(hr
== S_OK
, "WSDXMLAddSibling failed with %08x\n", hr
);
249 ok(child1
->Node
.Parent
== parent
, "child1->Node.Parent == %p\n", child1
->Node
.Parent
);
250 ok(child1
->Node
.Next
== (WSDXML_NODE
*)child2
, "child1->Node.Next == %p\n", child1
->Node
.Next
);
251 ok(child2
->Node
.Parent
== parent
, "child2->Node.Parent == %p\n", child2
->Node
.Parent
);
252 ok(child2
->Node
.Next
== (WSDXML_NODE
*)child3
, "child2->Node.Next == %p\n", child2
->Node
.Next
);
253 ok(child3
->Node
.Parent
== parent
, "child2->Node.Parent == %p\n", child2
->Node
.Parent
);
254 ok(child3
->Node
.Next
== NULL
, "child2->Node.Next == %p\n", child2
->Node
.Next
);
255 ok(parent
->FirstChild
== (WSDXML_NODE
*)child1
, "parent->FirstChild == %p\n", parent
->FirstChild
);
257 WSDFreeLinkedMemory(parent
);
260 static void GetValueFromAny_tests(void)
262 WSDXML_ELEMENT
*parent
, *child1
, *child2
, *child3
;
263 WSDXML_NAME parentName
, child1Name
, child2Name
, child3Name
;
264 WSDXML_NAMESPACE ns
, ns2
;
265 static const WCHAR
*child1NameText
= L
"Tim";
266 static const WCHAR
*child2NameText
= L
"Bob";
267 static const WCHAR
*child3NameText
= L
"Joe";
268 static const WCHAR
*child1Value
= L
"V1";
269 static const WCHAR
*child2Value
= L
"V2";
270 static const WCHAR
*uri
= L
"http://test.test/";
271 static const WCHAR
*uri2
= L
"http://test2.test/";
272 LPCWSTR returnedValue
= NULL
, oldReturnedValue
;
275 /* Populate structures */
277 ns
.PreferredPrefix
= L
"t";
280 ns2
.PreferredPrefix
= L
"u";
282 parentName
.LocalName
= (WCHAR
*) L
"Dad";
283 parentName
.Space
= &ns
;
285 child1Name
.LocalName
= (WCHAR
*) child1NameText
;
286 child1Name
.Space
= &ns2
;
288 child2Name
.LocalName
= (WCHAR
*) child2NameText
;
289 child2Name
.Space
= &ns
;
291 child3Name
.LocalName
= (WCHAR
*) child3NameText
;
292 child3Name
.Space
= &ns
;
294 /* Create some elements */
295 hr
= WSDXMLBuildAnyForSingleElement(&parentName
, NULL
, &parent
);
296 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
298 hr
= WSDXMLBuildAnyForSingleElement(&child1Name
, child1Value
, &child1
);
299 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
301 hr
= WSDXMLBuildAnyForSingleElement(&child2Name
, child2Value
, &child2
);
302 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
304 hr
= WSDXMLBuildAnyForSingleElement(&child3Name
, NULL
, &child3
);
305 ok(hr
== S_OK
, "BuildAnyForSingleElement failed with %08x\n", hr
);
307 /* Attach them to the parent element */
308 hr
= WSDXMLAddChild(parent
, child1
);
309 ok(hr
== S_OK
, "AddChild failed with %08x\n", hr
);
311 hr
= WSDXMLAddChild(parent
, child2
);
312 ok(hr
== S_OK
, "AddChild failed with %08x\n", hr
);
314 hr
= WSDXMLAddChild(parent
, child3
);
315 ok(hr
== S_OK
, "AddChild failed with %08x\n", hr
);
317 /* Test invalid arguments */
318 hr
= WSDXMLGetValueFromAny(NULL
, NULL
, NULL
, NULL
);
319 ok(hr
== E_INVALIDARG
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
321 hr
= WSDXMLGetValueFromAny(NULL
, NULL
, NULL
, &returnedValue
);
322 ok(hr
== E_INVALIDARG
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
324 hr
= WSDXMLGetValueFromAny(NULL
, NULL
, parent
, NULL
);
325 ok(hr
== E_POINTER
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
327 hr
= WSDXMLGetValueFromAny(uri
, NULL
, parent
, NULL
);
328 ok(hr
== E_POINTER
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
330 hr
= WSDXMLGetValueFromAny(uri
, child2NameText
, parent
, NULL
);
331 ok(hr
== E_POINTER
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
333 /* Test calling the function with a text size that exceeds 8192 characters */
334 hr
= WSDXMLGetValueFromAny(largeText
, child2NameText
, parent
, &returnedValue
);
335 ok(hr
== E_INVALIDARG
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
337 hr
= WSDXMLGetValueFromAny(uri
, largeText
, parent
, &returnedValue
);
338 ok(hr
== E_INVALIDARG
, "GetValueFromAny returned unexpected result: %08x\n", hr
);
340 /* Test with valid parameters */
341 hr
= WSDXMLGetValueFromAny(uri
, child2NameText
, child1
, &returnedValue
);
342 ok(hr
== S_OK
, "GetValueFromAny failed with %08x\n", hr
);
343 ok(returnedValue
!= NULL
, "returnedValue == NULL\n");
344 ok(lstrcmpW(returnedValue
, child2Value
) == 0, "returnedValue ('%s') != '%s'\n", wine_dbgstr_w(returnedValue
), wine_dbgstr_w(child2Value
));
346 hr
= WSDXMLGetValueFromAny(uri2
, child1NameText
, child1
, &returnedValue
);
347 ok(hr
== S_OK
, "GetValueFromAny failed with %08x\n", hr
);
348 ok(returnedValue
!= NULL
, "returnedValue == NULL\n");
349 ok(lstrcmpW(returnedValue
, child1Value
) == 0, "returnedValue ('%s') != '%s'\n", wine_dbgstr_w(returnedValue
), wine_dbgstr_w(child1Value
));
351 oldReturnedValue
= returnedValue
;
353 hr
= WSDXMLGetValueFromAny(uri2
, child2NameText
, child1
, &returnedValue
);
354 ok(hr
== E_FAIL
, "GetValueFromAny returned unexpected value: %08x\n", hr
);
355 ok(returnedValue
== oldReturnedValue
, "returnedValue == %p\n", returnedValue
);
357 oldReturnedValue
= returnedValue
;
359 hr
= WSDXMLGetValueFromAny(uri
, child3NameText
, child1
, &returnedValue
);
360 ok(hr
== E_FAIL
, "GetValueFromAny failed with %08x\n", hr
);
361 ok(returnedValue
== oldReturnedValue
, "returnedValue == %p\n", returnedValue
);
363 WSDFreeLinkedMemory(parent
);
366 static void XMLContext_AddNamespace_tests(void)
368 static const WCHAR
*ns1Uri
= L
"http://test.test";
369 static const WCHAR
*ns2Uri
= L
"http://wine.rocks";
370 static const WCHAR
*ns3Uri
= L
"http://test.again";
371 static const WCHAR
*prefix1
= L
"tst";
372 static const WCHAR
*prefix2
= L
"wine";
373 static const WCHAR
*unPrefix1
= L
"un1";
375 IWSDXMLContext
*context
;
376 WSDXML_NAMESPACE
*ns1
= NULL
, *ns2
= NULL
;
379 hr
= WSDXMLCreateContext(&context
);
380 ok(hr
== S_OK
, "WSDXMLCreateContext failed with %08x\n", hr
);
381 ok(context
!= NULL
, "context == NULL\n");
383 /* Test calling AddNamespace with invalid arguments */
384 hr
= IWSDXMLContext_AddNamespace(context
, NULL
, NULL
, NULL
);
385 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
387 hr
= IWSDXMLContext_AddNamespace(context
, ns1Uri
, NULL
, NULL
);
388 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
390 hr
= IWSDXMLContext_AddNamespace(context
, NULL
, prefix1
, NULL
);
391 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
393 /* Test calling AddNamespace without the ppNamespace parameter */
394 hr
= IWSDXMLContext_AddNamespace(context
, ns1Uri
, prefix1
, NULL
);
395 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
397 /* Now retrieve the created namespace */
398 hr
= IWSDXMLContext_AddNamespace(context
, ns1Uri
, prefix1
, &ns1
);
399 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
401 /* Check the returned structure */
402 ok(ns1
!= NULL
, "ns1 == NULL\n");
406 ok(lstrcmpW(ns1
->Uri
, ns1Uri
) == 0, "URI returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns1
->Uri
));
407 ok(lstrcmpW(ns1
->PreferredPrefix
, prefix1
) == 0, "PreferredPrefix returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns1
->PreferredPrefix
));
408 ok(ns1
->Names
== NULL
, "Names array is not empty\n");
409 ok(ns1
->NamesCount
== 0, "NamesCount is not 0 (value = %d)\n", ns1
->NamesCount
);
410 ok(ns1
->Uri
!= ns1Uri
, "URI has not been cloned\n");
411 ok(ns1
->PreferredPrefix
!= prefix1
, "URI has not been cloned\n");
414 /* Test calling AddNamespace with parameters that are too large */
415 hr
= IWSDXMLContext_AddNamespace(context
, largeText
, prefix2
, &ns2
);
416 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
418 hr
= IWSDXMLContext_AddNamespace(context
, ns2Uri
, largeText
, &ns2
);
419 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
421 hr
= IWSDXMLContext_AddNamespace(context
, largeText
, largeText
, &ns2
);
422 ok(hr
== E_INVALIDARG
, "AddNamespace failed with %08x\n", hr
);
424 /* Test calling AddNamespace with a conflicting prefix */
425 hr
= IWSDXMLContext_AddNamespace(context
, ns2Uri
, prefix1
, &ns2
);
426 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
428 /* Check the returned structure */
429 ok(ns2
!= NULL
, "ns2 == NULL\n");
433 ok(lstrcmpW(ns2
->Uri
, ns2Uri
) == 0, "URI returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->Uri
));
434 ok(lstrcmpW(ns2
->PreferredPrefix
, L
"un0") == 0, "PreferredPrefix returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->PreferredPrefix
));
435 ok(ns2
->Names
== NULL
, "Names array is not empty\n");
436 ok(ns2
->NamesCount
== 0, "NamesCount is not 0 (value = %d)\n", ns2
->NamesCount
);
437 ok(ns2
->Uri
!= ns2Uri
, "URI has not been cloned\n");
438 ok(ns2
->PreferredPrefix
!= prefix2
, "URI has not been cloned\n");
441 WSDFreeLinkedMemory(ns1
);
442 WSDFreeLinkedMemory(ns2
);
444 /* Try explicitly creating a prefix called 'un1' */
445 hr
= IWSDXMLContext_AddNamespace(context
, L
"http://one.more", unPrefix1
, &ns2
);
446 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
448 /* Check the returned structure */
449 ok(ns2
!= NULL
, "ns2 == NULL\n");
453 ok(lstrcmpW(ns2
->PreferredPrefix
, unPrefix1
) == 0, "PreferredPrefix returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->PreferredPrefix
));
456 WSDFreeLinkedMemory(ns2
);
458 /* Test with one more conflicting prefix */
459 hr
= IWSDXMLContext_AddNamespace(context
, ns3Uri
, prefix1
, &ns2
);
460 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
462 /* Check the returned structure */
463 ok(ns2
!= NULL
, "ns2 == NULL\n");
467 ok(lstrcmpW(ns2
->PreferredPrefix
, L
"un2") == 0, "PreferredPrefix returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->PreferredPrefix
));
470 WSDFreeLinkedMemory(ns2
);
472 /* Try renaming a prefix */
473 hr
= IWSDXMLContext_AddNamespace(context
, ns3Uri
, prefix2
, &ns2
);
474 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
476 /* Check the returned structure */
477 ok(ns2
!= NULL
, "ns2 == NULL\n");
481 ok(lstrcmpW(ns2
->Uri
, ns3Uri
) == 0, "Uri returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->Uri
));
482 ok(lstrcmpW(ns2
->PreferredPrefix
, prefix2
) == 0, "PreferredPrefix returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->PreferredPrefix
));
485 WSDFreeLinkedMemory(ns2
);
487 IWSDXMLContext_Release(context
);
490 static void XMLContext_AddNameToNamespace_tests(void)
492 static const WCHAR
*ns1Uri
= L
"http://test.test";
493 static const WCHAR
*ns2Uri
= L
"http://wine.rocks";
494 static const WCHAR
*prefix2
= L
"wine";
495 static const WCHAR
*name1Text
= L
"Bob";
496 static const WCHAR
*name2Text
= L
"Tim";
497 IWSDXMLContext
*context
;
498 WSDXML_NAMESPACE
*ns2
= NULL
;
499 WSDXML_NAME
*name1
= NULL
, *name2
= NULL
;
502 hr
= WSDXMLCreateContext(&context
);
503 ok(hr
== S_OK
, "WSDXMLCreateContext failed with %08x\n", hr
);
505 /* Test calling AddNameToNamespace with invalid arguments */
506 hr
= IWSDXMLContext_AddNameToNamespace(context
, NULL
, NULL
, NULL
);
507 ok(hr
== E_INVALIDARG
, "AddNameToNamespace failed with %08x\n", hr
);
509 hr
= IWSDXMLContext_AddNameToNamespace(context
, ns1Uri
, NULL
, NULL
);
510 ok(hr
== E_INVALIDARG
, "AddNameToNamespace failed with %08x\n", hr
);
512 hr
= IWSDXMLContext_AddNameToNamespace(context
, NULL
, name1Text
, NULL
);
513 ok(hr
== E_INVALIDARG
, "AddNameToNamespace failed with %08x\n", hr
);
515 /* Test calling AddNameToNamespace without the ppName parameter */
516 hr
= IWSDXMLContext_AddNameToNamespace(context
, ns1Uri
, name1Text
, NULL
);
517 ok(hr
== S_OK
, "AddNameToNamespace failed with %08x\n", hr
);
519 /* Now retrieve the created name */
520 hr
= IWSDXMLContext_AddNameToNamespace(context
, ns1Uri
, name1Text
, &name1
);
521 ok(hr
== S_OK
, "AddNameToNamespace failed with %08x\n", hr
);
523 /* Check the returned structure */
524 ok(name1
!= NULL
, "name1 == NULL\n");
528 ok(lstrcmpW(name1
->LocalName
, name1Text
) == 0, "LocalName returned by AddNameToNamespace is not as expected (%s)\n", wine_dbgstr_w(name1
->LocalName
));
529 ok(name1
->LocalName
!= name1Text
, "LocalName has not been cloned\n");
531 ok(name1
->Space
!= NULL
, "Space returned by AddNameToNamespace is null\n");
532 ok(lstrcmpW(name1
->Space
->Uri
, ns1Uri
) == 0, "URI returned by AddNameToNamespace is not as expected (%s)\n", wine_dbgstr_w(name1
->Space
->Uri
));
533 ok(lstrcmpW(name1
->Space
->PreferredPrefix
, L
"un0") == 0, "PreferredPrefix returned by AddName is not as expected (%s)\n", wine_dbgstr_w(name1
->Space
->PreferredPrefix
));
534 ok(name1
->Space
->Names
== NULL
, "Names array is not empty\n");
535 ok(name1
->Space
->NamesCount
== 0, "NamesCount is not 0 (value = %d)\n", name1
->Space
->NamesCount
);
536 ok(name1
->Space
->Uri
!= ns1Uri
, "URI has not been cloned\n");
539 /* Test calling AddNamespace with parameters that are too large */
540 hr
= IWSDXMLContext_AddNameToNamespace(context
, largeText
, name1Text
, &name2
);
541 ok(hr
== E_INVALIDARG
, "AddNameToNamespace failed with %08x\n", hr
);
543 hr
= IWSDXMLContext_AddNameToNamespace(context
, ns1Uri
, largeText
, &name2
);
544 ok(hr
== E_INVALIDARG
, "AddNameToNamespace failed with %08x\n", hr
);
546 /* Try creating a namespace explicitly */
547 hr
= IWSDXMLContext_AddNamespace(context
, ns2Uri
, prefix2
, &ns2
);
548 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
550 /* Now add a name to it */
551 hr
= IWSDXMLContext_AddNameToNamespace(context
, ns2Uri
, name2Text
, &name2
);
552 ok(hr
== S_OK
, "AddNameToNamespace failed with %08x\n", hr
);
554 /* Check the returned structure */
555 ok(name2
!= NULL
, "name2 == NULL\n");
559 ok(lstrcmpW(name2
->LocalName
, name2Text
) == 0, "LocalName returned by AddNameToNamespace is not as expected (%s)\n", wine_dbgstr_w(name2
->LocalName
));
560 ok(name2
->LocalName
!= name2Text
, "LocalName has not been cloned\n");
562 ok(name2
->Space
!= NULL
, "Space returned by AddNameToNamespace is null\n");
563 ok(name2
->Space
!= ns2
, "Space returned by AddNameToNamespace is equal to the namespace returned by AddNamespace\n");
564 ok(lstrcmpW(name2
->Space
->Uri
, ns2Uri
) == 0, "URI returned by AddNameToNamespace is not as expected (%s)\n", wine_dbgstr_w(name2
->Space
->Uri
));
565 ok(lstrcmpW(name2
->Space
->PreferredPrefix
, prefix2
) == 0, "PreferredPrefix returned by AddNameToNamespace is not as expected (%s)\n", wine_dbgstr_w(name2
->Space
->PreferredPrefix
));
566 ok(name2
->Space
->Names
== NULL
, "Names array is not empty\n");
567 ok(name2
->Space
->NamesCount
== 0, "NamesCount is not 0 (value = %d)\n", name2
->Space
->NamesCount
);
568 ok(name2
->Space
->Uri
!= ns2Uri
, "URI has not been cloned\n");
571 WSDFreeLinkedMemory(name1
);
572 WSDFreeLinkedMemory(name2
);
573 WSDFreeLinkedMemory(ns2
);
575 /* Now re-retrieve ns2 */
576 hr
= IWSDXMLContext_AddNamespace(context
, ns2Uri
, prefix2
, &ns2
);
577 ok(hr
== S_OK
, "AddNamespace failed with %08x\n", hr
);
579 /* Check the returned structure */
580 ok(ns2
!= NULL
, "ns2 == NULL\n");
584 ok(lstrcmpW(ns2
->Uri
, ns2Uri
) == 0, "URI returned by AddNamespace is not as expected (%s)\n", wine_dbgstr_w(ns2
->Uri
));
586 /* Apparently wsdapi always leaves the namespace names array as empty */
587 ok(ns2
->Names
== NULL
, "Names array is not empty\n");
588 ok(ns2
->NamesCount
== 0, "NamesCount is not 0 (value = %d)\n", ns2
->NamesCount
);
589 WSDFreeLinkedMemory(ns2
);
592 IWSDXMLContext_Release(context
);
597 /* Allocate a large text buffer for use in tests */
598 largeText
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, largeTextSize
+ sizeof(WCHAR
));
599 memset(largeText
, 'a', largeTextSize
);
601 BuildAnyForSingleElement_tests();
604 GetValueFromAny_tests();
606 XMLContext_AddNamespace_tests();
607 XMLContext_AddNameToNamespace_tests();
609 HeapFree(GetProcessHeap(), 0, largeText
);