ReactOS 0.4.16-dev-1946-g52006dd
xmldoc.c File Reference
#include <stdio.h>
#include "windows.h"
#include "ole2.h"
#include "msxml2.h"
#include "msxml2did.h"
#include "ocidl.h"
#include "wine/test.h"
Include dependency graph for xmldoc.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define XML_E_INVALIDATROOTLEVEL   0xc00ce556
 

Functions

static void create_xml_file (LPCSTR filename)
 
static void create_stream_on_file (IStream **stream, LPCSTR path)
 
static void test_xmldoc (void)
 
static void test_createElement (void)
 
static void test_persiststreaminit (void)
 
static BOOL test_try_xmldoc (void)
 
static void test_xmlelem_children (void)
 
static void test_xmlelem_collection (void)
 
static void test_xmlelem (void)
 
 START_TEST (xmldoc)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file xmldoc.c.

◆ XML_E_INVALIDATROOTLEVEL

#define XML_E_INVALIDATROOTLEVEL   0xc00ce556

Definition at line 33 of file xmldoc.c.

Function Documentation

◆ create_stream_on_file()

static void create_stream_on_file ( IStream **  stream,
LPCSTR  path 
)
static

Definition at line 53 of file xmldoc.c.

54{
55 HANDLE hfile;
56 HGLOBAL hglobal;
57 LPVOID ptr;
58 HRESULT hr;
60
63 ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n");
64 file_size = GetFileSize(hfile, NULL);
65
66 hglobal = GlobalAlloc(GHND, file_size);
67 ptr = GlobalLock(hglobal);
68
69 ReadFile(hfile, ptr, file_size, &read, NULL);
70 ok(file_size == read, "Expected to read the whole file, read %ld.\n", read);
71
73 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
74 ok(*stream != NULL, "Expected non-NULL stream\n");
75
76 CloseHandle(hfile);
77 GlobalUnlock(hglobal);
78}
#define read
Definition: acwin.h:96
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define S_OK
Definition: intsafe.h:52
static ERESOURCE GlobalLock
Definition: sys_arch.c:8
static PVOID ptr
Definition: dispmode.c:27
static unsigned int file_size
Definition: regtests2xml.c:47
HRESULT hr
Definition: shlfolder.c:183
Definition: parse.h:23
#define GHND
Definition: winbase.h:321

Referenced by test_persiststreaminit(), and test_xmldoc().

◆ create_xml_file()

static void create_xml_file ( LPCSTR  filename)
static

Definition at line 35 of file xmldoc.c.

36{
37 DWORD dwNumberOfBytesWritten;
40
41 static const char data[] =
42 "<?xml version=\"1.0\" ?>\n"
43 "<!DOCTYPE BankAccount>\n"
44 "<BankAccount>\n"
45 " <Number>1234</Number>\n"
46 " <Name>Captain Ahab</Name>\n"
47 "</BankAccount>";
48
49 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
50 CloseHandle(hf);
51}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90

Referenced by test_persiststreaminit(), test_xmldoc(), and test_xmlelem_collection().

◆ START_TEST()

START_TEST ( xmldoc  )

Definition at line 1082 of file xmldoc.c.

1083{
1084 HRESULT hr;
1085
1086 hr = CoInitialize(NULL);
1087 ok(hr == S_OK, "failed to init com\n");
1088
1089 if (!test_try_xmldoc())
1090 {
1092 return;
1093 }
1094
1095 test_xmldoc();
1098 test_xmlelem();
1101
1103}
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void test_xmlelem_collection(void)
Definition: xmldoc.c:634
static void test_xmlelem_children(void)
Definition: xmldoc.c:513
static void test_xmldoc(void)
Definition: xmldoc.c:80
static void test_createElement(void)
Definition: xmldoc.c:289
static BOOL test_try_xmldoc(void)
Definition: xmldoc.c:496
static void test_xmlelem(void)
Definition: xmldoc.c:879
static void test_persiststreaminit(void)
Definition: xmldoc.c:377

◆ test_createElement()

static void test_createElement ( void  )
static

Definition at line 289 of file xmldoc.c.

290{
291 HRESULT hr;
292 IXMLDocument *doc = NULL;
293 IXMLElement *element = NULL, *root = NULL;
294 VARIANT vType, vName;
295 LONG type;
296
297 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
298 &IID_IXMLDocument, (LPVOID*)&doc);
299 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
300
301 /* invalid vType type */
302 V_VT(&vType) = VT_NULL;
303 V_VT(&vName) = VT_NULL;
304 element = (IXMLElement *)0xdeadbeef;
305 hr = IXMLDocument_createElement(doc, vType, vName, &element);
306 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
307 ok(element == NULL, "Expected NULL element\n");
308
309 /* invalid vType value */
310 V_VT(&vType) = VT_I4;
311 V_I4(&vType) = -1;
312 V_VT(&vName) = VT_NULL;
313 hr = IXMLDocument_createElement(doc, vType, vName, &element);
314 /* Up to and including SP7, createElement returns an element. */
315 if(hr == S_OK)
316 {
317 ok(element != NULL, "Expected element\n");
318 if (element != NULL)
319 {
320 hr = IXMLElement_get_type(element, &type);
321 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
322 /* SP7 returns an XMLELEMTYPE_ELEMENT */
323 ok(type == XMLELEMTYPE_OTHER || type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
324
325 IXMLElement_Release(element);
326 }
327 }
328 else
329 {
330 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
331 ok(element == NULL, "Expected NULL element\n");
332 }
333
334 /* invalid vName type */
335 V_VT(&vType) = VT_I4;
336 V_I4(&vType) = XMLELEMTYPE_ELEMENT;
337 V_VT(&vName) = VT_I4;
338 hr = IXMLDocument_createElement(doc, vType, vName, &element);
339 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
340 ok(element != NULL, "Expected non-NULL element\n");
341
342 hr = IXMLElement_get_type(element, &type);
343 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
344 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
345
346 IXMLElement_Release(element);
347
348 /* NULL element */
349 V_VT(&vType) = VT_I4;
350 V_I4(&vType) = XMLELEMTYPE_ELEMENT;
351 V_VT(&vName) = VT_I4;
352 hr = IXMLDocument_createElement(doc, vType, vName, NULL);
353 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
354
355 root = (IXMLElement *)0xdeadbeef;
356 hr = IXMLDocument_get_root(doc, &root);
357 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
358 ok(root == NULL, "Expected NULL root\n");
359
360 V_VT(&vType) = VT_I4;
361 V_I4(&vType) = XMLELEMTYPE_ELEMENT;
362 V_VT(&vName) = VT_NULL;
363 hr = IXMLDocument_createElement(doc, vType, vName, &element);
364 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
365 ok(element != NULL, "Expected non-NULL element\n");
366
367 /* createElement does not set the new element as root */
368 root = (IXMLElement *)0xdeadbeef;
369 hr = IXMLDocument_get_root(doc, &root);
370 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
371 ok(root == NULL, "Expected NULL root\n");
372
373 IXMLElement_Release(element);
374 IXMLDocument_Release(doc);
375}
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
@ VT_NULL
Definition: compat.h:2296
@ VT_I4
Definition: compat.h:2298
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
const struct _GUID CLSID_XMLDocument
#define V_VT(A)
Definition: oleauto.h:211
#define V_I4(A)
Definition: oleauto.h:247
long LONG
Definition: pedump.c:60

Referenced by START_TEST().

◆ test_persiststreaminit()

static void test_persiststreaminit ( void  )
static

Definition at line 377 of file xmldoc.c.

378{
379 IXMLDocument *doc = NULL;
380 IXMLElement *element = NULL;
383 STATSTG stat;
384 HRESULT hr;
387 CLSID id;
388 BSTR str;
389
390 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
391 &IID_IXMLDocument, (LPVOID*)&doc);
392 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
393
394 hr = IXMLDocument_QueryInterface(doc, &IID_IPersistStreamInit, (LPVOID *)&psi);
395 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
396 ok(psi != NULL, "Expected non-NULL psi\n");
397
398 /* null arguments */
399 hr = IPersistStreamInit_GetSizeMax(psi, NULL);
400 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
401
402 hr = IPersistStreamInit_Load(psi, NULL);
403 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
404
405 hr = IPersistStreamInit_Save(psi, NULL, FALSE);
406 todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
407
408 hr = IPersistStreamInit_GetClassID(psi, NULL);
409 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
410
411 hr = IPersistStreamInit_IsDirty(psi);
412 todo_wine ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
413
414 create_xml_file("bank.xml");
415 GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
417
418 /* GetSizeMax not implemented */
419 size.QuadPart = 0;
420 hr = IPersistStreamInit_GetSizeMax(psi, &size);
421 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
422 ok(size.QuadPart == 0, "Expected 0\n");
423
424 hr = IPersistStreamInit_Load(psi, stream);
425 IStream_Release(stream);
426 ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Unexpected hr %#lx.\n", hr);
428 goto cleanup;
429
430 hr = IPersistStreamInit_IsDirty(psi);
431 todo_wine ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
432
433 /* try to save document */
434 stream = NULL;
436 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
437 hr = IPersistStreamInit_Save(psi, stream, FALSE);
438 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
439
440 stat.cbSize.QuadPart = 0;
441 hr = IStream_Stat(stream, &stat, 0);
442 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
443 todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
444 IStream_Release(stream);
445
446 str = SysAllocString(L"test");
447 hr = IXMLDocument_get_root(doc, &element);
448 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
449 hr = IXMLElement_put_text(element, str);
450 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
451 IXMLElement_Release(element);
453
454 hr = IPersistStreamInit_IsDirty(psi);
455 todo_wine ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
456
458 hr = IPersistStreamInit_Load(psi, stream);
459 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
460 IStream_Release(stream);
461
462 hr = IPersistStreamInit_IsDirty(psi);
463 todo_wine ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
464
465 /* reset internal stream */
466 hr = IPersistStreamInit_InitNew(psi);
467 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
468
469 hr = IPersistStreamInit_IsDirty(psi);
470 todo_wine ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
471
472 stream = NULL;
474 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
475
476 hr = IPersistStreamInit_Save(psi, stream, FALSE);
477 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
478
479 stat.cbSize.QuadPart = 0;
480 hr = IStream_Stat(stream, &stat, 0);
481 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
482 todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
483 IStream_Release(stream);
484
485 memset(&id, 0, sizeof(id));
486 hr = IPersistStreamInit_GetClassID(psi, &id);
487 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
488 ok(IsEqualCLSID(&id, &CLSID_XMLDocument), "Expected CLSID_XMLDocument\n");
489
490cleanup:
491 IPersistStreamInit_Release(psi);
492 IXMLDocument_Release(doc);
493 DeleteFileA("bank.xml");
494}
#define stat
Definition: acwin.h:99
#define FALSE
Definition: types.h:117
OLECHAR * BSTR
Definition: compat.h:2293
#define MAX_PATH
Definition: compat.h:34
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
DWORD WINAPI GetFullPathNameA(IN LPCSTR lpFileName, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart)
Definition: path.c:993
#define L(x)
Definition: resources.c:13
GLsizeiptr size
Definition: glext.h:5919
GLuint id
Definition: glext.h:5910
#define todo_wine
Definition: minitest.h:80
static void create_stream_on_file(IStream **stream, LPCSTR path)
Definition: xmldoc.c:53
static void create_xml_file(LPCSTR filename)
Definition: xmldoc.c:35
#define XML_E_INVALIDATROOTLEVEL
Definition: xmldoc.c:33
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
const GUID IID_IPersistStreamInit
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96
const WCHAR * str
#define memset(x, y, z)
Definition: compat.h:39
Definition: stat.h:55
#define S_FALSE
Definition: winerror.h:3451
#define E_POINTER
Definition: winerror.h:3480
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ test_try_xmldoc()

static BOOL test_try_xmldoc ( void  )
static

Definition at line 496 of file xmldoc.c.

497{
498 IXMLDocument *doc = NULL;
499 HRESULT hr;
500
501 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
502 &IID_IXMLDocument, (LPVOID*)&doc);
503 if (FAILED(hr))
504 {
505 win_skip("Failed to create XMLDocument instance\n");
506 return FALSE;
507 }
508
509 IXMLDocument_Release(doc);
510 return TRUE;
511}
#define FAILED(hr)
Definition: intsafe.h:51
#define win_skip
Definition: minitest.h:67

Referenced by START_TEST().

◆ test_xmldoc()

static void test_xmldoc ( void  )
static

Definition at line 80 of file xmldoc.c.

81{
82 IXMLElement *element = NULL, *child = NULL, *value = NULL;
83 IXMLElementCollection *collection = NULL, *inner = NULL;
85 IXMLDocument *doc = NULL;
87 VARIANT vIndex, vName;
88 LONG type, num_child;
90 IDispatch *disp;
91 ITypeInfo *ti;
92 HRESULT hr;
93 BSTR name;
94
95 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
96 &IID_IXMLDocument, (void**)&doc);
97 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
98
99 /* IDispatch */
100 hr = IXMLDocument_QueryInterface(doc, &IID_IDispatch, (void**)&disp);
101 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
102
103 /* just to make sure we're on right type data */
104 hr = IDispatch_GetTypeInfo(disp, 0, 0, &ti);
105 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
106 name = NULL;
107 hr = ITypeInfo_GetDocumentation(ti, DISPID_XMLDOCUMENT_ROOT, &name, NULL, NULL, NULL);
108 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
109 ok(!lstrcmpW(name, L"root"), "got name %s\n", wine_dbgstr_w(name));
111
112 ITypeInfo_Release(ti);
113 IDispatch_Release(disp);
114
115 hr = IXMLDocument_QueryInterface(doc, &IID_IXMLDOMDocument, (void**)&disp);
116 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
117
118 create_xml_file("bank.xml");
119 GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
121
122 hr = IXMLDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&psi);
123 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
124 ok(psi != NULL, "Expected non-NULL psi\n");
125
126 hr = IXMLDocument_get_root(doc, &element);
127 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
128 ok(element == NULL, "Expected NULL element\n");
129
130 hr = IPersistStreamInit_Load(psi, stream);
131 ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Unexpected hr %#lx.\n", hr);
133 goto cleanup;
134
135 ok(stream != NULL, "Expected non-NULL stream\n");
136
137 /* version field */
138 hr = IXMLDocument_get_version(doc, NULL);
139 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
140
141 name = NULL;
142 hr = IXMLDocument_get_version(doc, &name);
143 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
144 ok(!lstrcmpW(name, L"1.0"), "Expected 1.0, got %s\n", wine_dbgstr_w(name));
146
147 /* doctype */
148 hr = IXMLDocument_get_doctype(doc, NULL);
149 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
150
151 hr = IXMLDocument_get_doctype(doc, &name);
152 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
153 ok(!lstrcmpW(name, L"BANKACCOUNT"), "Expected BANKACCOUNT, got %s\n", wine_dbgstr_w(name));
155
156 hr = IXMLDocument_get_root(doc, &element);
157 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
158 ok(element != NULL, "Expected non-NULL element\n");
159
160 /* ::root() returns new instance each time */
161 hr = IXMLDocument_get_root(doc, &child);
162 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
163 ok(child != NULL, "Expected non-NULL element\n");
164 ok(child != element, "Expected new element instance\n");
165 IXMLElement_Release(child);
166
167 hr = IXMLElement_get_type(element, &type);
168 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
169 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
170
171 hr = IXMLElement_get_tagName(element, &name);
172 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
173 ok(!lstrcmpW(name, L"BANKACCOUNT"), "Expected BANKACCOUNT\n");
175
176 hr = IXMLElement_get_children(element, &collection);
177 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
178 ok(collection != NULL, "Expected non-NULL collection\n");
179
180 hr = IXMLElementCollection_get_length(collection, &num_child);
181 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
182 ok(num_child == 2, "Unexpected length %ld.\n", num_child);
183
184 V_VT(&vIndex) = VT_I4;
185 V_I4(&vIndex) = 0;
186 V_VT(&vName) = VT_ERROR;
188 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
189 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
190 ok(child != NULL, "Expected non-NULL child\n");
191
192 hr = IXMLElement_get_type(child, &type);
193 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
194 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
195
196 hr = IXMLElement_get_tagName(child, &name);
197 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
198 ok(!lstrcmpW(name, L"NUMBER"), "Expected NUMBER\n");
200
201 hr = IXMLElement_get_children(child, &inner);
202 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
203 ok(inner != NULL, "Expected non-NULL inner\n");
204
205 hr = IXMLElementCollection_get_length(inner, &num_child);
206 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
207 ok(num_child == 1, "Unexpected length %ld.\n", num_child);
208
209 hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
210 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
211 ok(value != NULL, "Expected non-NULL value\n");
212
213 hr = IXMLElement_get_type(value, &type);
214 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
215 ok(type == XMLELEMTYPE_TEXT, "Unexpected type %ld.\n", type);
216
217 hr = IXMLElement_get_text(value, &name);
218 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
219 ok(!lstrcmpW(name, L"1234"), "Expected '1234'\n");
221
222 IXMLElementCollection_Release(inner);
223
224 inner = (IXMLElementCollection *)0xdeadbeef;
225 hr = IXMLElement_get_children(value, &inner);
226 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
227 ok(inner == NULL, "Expected NULL inner, got %p\n", inner);
228
229 IXMLElement_Release(value);
230 IXMLElement_Release(child);
231 value = NULL;
232 child = NULL;
233
234 V_I4(&vIndex) = 1;
235 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
236 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
237 ok(child != NULL, "Expected non-NULL child\n");
238
239 hr = IXMLElement_get_type(child, &type);
240 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
241 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
242
243 hr = IXMLElement_get_tagName(child, &name);
244 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
245 ok(!lstrcmpW(name, L"NAME"), "Expected NAME\n");
247
248 hr = IXMLElement_get_children(child, &inner);
249 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
250 ok(inner != NULL, "Expected non-NULL inner\n");
251
252 hr = IXMLElementCollection_get_length(inner, &num_child);
253 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
254 ok(num_child == 1, "Unexpected length %ld.\n", num_child);
255
256 V_I4(&vIndex) = 0;
257 hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
258 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
259 ok(value != NULL, "Expected non-NULL value\n");
260
261 hr = IXMLElement_get_type(value, &type);
262 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
263 ok(type == XMLELEMTYPE_TEXT, "Unexpected type %ld.\n", type);
264
265 hr = IXMLElement_get_text(value, &name);
266 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
267 ok(!lstrcmpW(name, L"Captain Ahab"), "Expected 'Captain Ahab'\n");
269
270 IXMLElementCollection_Release(inner);
271
272 inner = (IXMLElementCollection *)0xdeadbeef;
273 hr = IXMLElement_get_children(value, &inner);
274 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
275 ok(inner == NULL, "Expected NULL inner, got %p\n", inner);
276
277 IXMLElement_Release(value);
278 IXMLElement_Release(child);
279 IXMLElementCollection_Release(collection);
280 IXMLElement_Release(element);
281cleanup:
282 IStream_Release(stream);
283 IPersistStreamInit_Release(psi);
284 IXMLDocument_Release(doc);
285
286 DeleteFileA("bank.xml");
287}
@ VT_ERROR
Definition: compat.h:2305
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
#define wine_dbgstr_w
Definition: kernel32.h:34
static ICollection collection
Definition: typelib.c:184
static HWND child
Definition: cursoricon.c:298
#define DISPID_XMLDOCUMENT_ROOT
Definition: msxml2did.h:33
#define V_ERROR(A)
Definition: oleauto.h:241
const GUID IID_IDispatch
Definition: name.c:39
Definition: pdh_main.c:96
#define DISP_E_PARAMNOTFOUND
Definition: winerror.h:3616
#define E_NOINTERFACE
Definition: winerror.h:3479

Referenced by START_TEST().

◆ test_xmlelem()

static void test_xmlelem ( void  )
static

Definition at line 879 of file xmldoc.c.

880{
881 HRESULT hr;
882 IXMLDocument *doc = NULL;
883 IXMLElement *element = NULL, *parent;
884 IXMLElement *child, *child2;
885 IXMLElementCollection *children;
886 VARIANT vType, vName;
887 VARIANT vIndex, vValue;
888 BSTR str, val, name;
889 LONG type, num_child;
890 IDispatch *disp;
891 ITypeInfo *ti;
892
893 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
894 &IID_IXMLDocument, (LPVOID*)&doc);
895 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
896
897 V_VT(&vType) = VT_I4;
898 V_I4(&vType) = XMLELEMTYPE_ELEMENT;
899 V_VT(&vName) = VT_NULL;
900 hr = IXMLDocument_createElement(doc, vType, vName, &element);
901 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
902 ok(element != NULL, "Expected non-NULL element\n");
903
904 /* test for IDispatch */
905 disp = NULL;
906 hr = IXMLElement_QueryInterface(element, &IID_IDispatch, (void**)&disp);
907 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
908
909 hr = IDispatch_GetTypeInfo(disp, 0, 0, &ti);
910 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
911
912 name = NULL;
913 hr = ITypeInfo_GetDocumentation(ti, DISPID_XMLELEMENT_TAGNAME, &name, NULL, NULL, NULL);
914 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
916
917 ITypeInfo_Release(ti);
918 IDispatch_Release(disp);
919
920 hr = IXMLElement_get_tagName(element, &str);
921 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
922 ok(!str, "Expected empty tag name, got %s\n", wine_dbgstr_w(str));
924
925 parent = (IXMLElement *)0xdeadbeef;
926 hr = IXMLElement_get_parent(element, &parent);
927 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
928 ok(parent == NULL, "Expected NULL parent\n");
929
930 str = SysAllocString(L"noexist");
931 hr = IXMLElement_getAttribute(element, str, &vValue);
932 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
933 ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
934 ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
935 VariantClear(&vValue);
937
938 str = SysAllocString(L"CRazYcASE");
939 val = SysAllocString(L"val");
940 V_VT(&vValue) = VT_BSTR;
941 V_BSTR(&vValue) = val;
942 hr = IXMLElement_setAttribute(element, str, vValue);
943 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
946
947 str = SysAllocString(L"CRAZYCASE");
948 hr = IXMLElement_getAttribute(element, str, &vValue);
949 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
950 ok(V_VT(&vValue) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&vValue));
951 ok(!lstrcmpW(V_BSTR(&vValue), L"val"), "Expected 'val'\n");
952 VariantClear(&vValue);
954
955 str = SysAllocString(L"prop");
956 val = SysAllocString(L"val");
957 V_VT(&vValue) = VT_BSTR;
958 V_BSTR(&vValue) = val;
959 hr = IXMLElement_setAttribute(element, str, vValue);
960 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
962
963 hr = IXMLElement_getAttribute(element, str, &vValue);
964 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
965 ok(V_VT(&vValue) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&vValue));
966 ok(!lstrcmpW(V_BSTR(&vValue), L"val"), "Expected 'val'\n");
967 VariantClear(&vValue);
968
969 hr = IXMLElement_removeAttribute(element, str);
970 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
971
972 /* remove now nonexistent attribute */
973 hr = IXMLElement_removeAttribute(element, str);
974 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
975
976 hr = IXMLElement_getAttribute(element, str, &vValue);
977 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
978 ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
979 ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
981 VariantClear(&vValue);
982
983 children = (IXMLElementCollection *)0xdeadbeef;
984 hr = IXMLElement_get_children(element, &children);
985 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
986 ok(children == NULL, "Expected NULL collection\n");
987
988 hr = IXMLElement_get_type(element, &type);
989 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
990 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
991
992 hr = IXMLElement_get_text(element, &str);
993 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
994 ok(str && !*str, "Expected empty text\n");
996
997 /* put_text with an ELEMENT */
998 str = SysAllocString(L"val");
999 hr = IXMLElement_put_text(element, str);
1000 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1002
1003 V_VT(&vType) = VT_I4;
1004 V_I4(&vType) = XMLELEMTYPE_TEXT;
1005 V_VT(&vName) = VT_NULL;
1006 hr = IXMLDocument_createElement(doc, vType, vName, &child);
1007 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1008 ok(child != NULL, "Expected non-NULL child\n");
1009
1010 hr = IXMLElement_addChild(element, child, 0, -1);
1011 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1012
1013 str = SysAllocString(L"val");
1014 hr = IXMLElement_put_text(child, str);
1015 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1017
1018 parent = (IXMLElement *)0xdeadbeef;
1019 hr = IXMLElement_get_parent(child, &parent);
1020 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1021 ok(parent != element, "Expected parent != element\n");
1022
1023 hr = IXMLElement_get_type(parent, &type);
1024 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1025 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
1026
1027 children = (IXMLElementCollection *)0xdeadbeef;
1028 hr = IXMLElement_get_children(element, &children);
1029 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1030 ok(children != NULL, "Expected non-NULL collection\n");
1031
1032 hr = IXMLElementCollection_get_length(children, &num_child);
1033 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1034 ok(num_child == 1, "Unexpected length %ld.\n", num_child);
1035
1036 V_VT(&vIndex) = VT_I4;
1037 V_I4(&vIndex) = 0;
1038 V_VT(&vName) = VT_ERROR;
1039 V_ERROR(&vName) = DISP_E_PARAMNOTFOUND;
1040 hr = IXMLElementCollection_item(children, vIndex, vName, (IDispatch **)&child2);
1041 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1042 ok(child2 != NULL, "Expected non-NULL child\n");
1043
1044 hr = IXMLElement_get_type(child2, &type);
1045 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1046 ok(type == XMLELEMTYPE_TEXT, "Unexpected type %ld.\n", type);
1047
1048 hr = IXMLElement_get_text(element, &str);
1049 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1050 ok(!lstrcmpW(str, L"val"), "Expected 'val'\n");
1052
1053 hr = IXMLElement_get_text(child2, &str);
1054 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1055 ok(!lstrcmpW(str, L"val"), "Expected 'val'\n");
1057
1058 /* try put_text on ELEMENT again, now that it has a text child */
1059 str = SysAllocString(L"next");
1060 hr = IXMLElement_put_text(element, str);
1061 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1063
1064 str = SysAllocString(L"next");
1065 hr = IXMLElement_put_text(child2, str);
1066 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1068
1069 hr = IXMLElement_get_text(element, &str);
1070 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1071 ok(!lstrcmpW(str, L"next"), "Expected 'val'\n");
1073
1074 IXMLElement_Release(child2);
1075 IXMLElementCollection_Release(children);
1076 IXMLElement_Release(parent);
1077 IXMLElement_Release(child);
1078 IXMLElement_Release(element);
1079 IXMLDocument_Release(doc);
1080}
@ VT_BSTR
Definition: compat.h:2303
@ VT_EMPTY
Definition: compat.h:2295
r parent
Definition: btrfs.c:3010
GLuint GLfloat * val
Definition: glext.h:7180
#define DISPID_XMLELEMENT_TAGNAME
Definition: msxml2did.h:49
MSXML::enum XMLELEMTYPE_TEXT
#define V_BSTR(A)
Definition: oleauto.h:226
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648

Referenced by START_TEST().

◆ test_xmlelem_children()

static void test_xmlelem_children ( void  )
static

Definition at line 513 of file xmldoc.c.

514{
515 IXMLDocument *doc = NULL;
516 IXMLElement *element = NULL, *child = NULL, *child2 = NULL;
517 IXMLElementCollection *collection = NULL;
518 VARIANT vType, vName, vIndex;
519 LONG length, refcount;
520 HRESULT hr;
521
522 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
523 &IID_IXMLDocument, (LPVOID*)&doc);
524 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
525
526 V_VT(&vType) = VT_I4;
527 V_I4(&vType) = XMLELEMTYPE_ELEMENT;
528 V_VT(&vName) = VT_NULL;
529 hr = IXMLDocument_createElement(doc, vType, vName, &element);
530 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
531 ok(element != NULL, "Expected non-NULL element\n");
532
533 V_VT(&vType) = VT_I4;
534 V_I4(&vType) = XMLELEMTYPE_TEXT;
535 V_VT(&vName) = VT_NULL;
536 hr = IXMLDocument_createElement(doc, vType, vName, &child);
537 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
538 ok(child != NULL, "Expected non-NULL child\n");
539
540 V_VT(&vType) = VT_I4;
541 V_I4(&vType) = XMLELEMTYPE_TEXT;
542 V_VT(&vName) = VT_NULL;
543 hr = IXMLDocument_createElement(doc, vType, vName, &child2);
544 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
545 ok(child2 != NULL, "Expected non-NULL child\n");
546
547 hr = IXMLElement_addChild(element, child, 0, -1);
548 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
549
550 hr = IXMLElement_get_children(element, &collection);
551 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
552 ok(collection != NULL, "Expected non-NULL collection\n");
553
554 length = 0;
555 hr = IXMLElementCollection_get_length(collection, &length);
556 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
557 ok(length == 1, "Unexpected length %ld.\n", length);
558
559 /* remove/add child and check what happens with collection */
560 hr = IXMLElement_removeChild(element, child);
561 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
562
563 length = -1;
564 hr = IXMLElementCollection_get_length(collection, &length);
565 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
566 ok(!length, "Unexpected length %ld.\n", length);
567 IXMLElementCollection_Release(collection);
568
569 refcount = IXMLElement_AddRef(child);
570 ok(refcount == 2, "Unexpected refcount %ld.\n", refcount);
571 IXMLElement_Release(child);
572 hr = IXMLElement_addChild(element, child, 0, -1);
573 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
574 refcount = IXMLElement_AddRef(child);
575 ok(refcount == 2, "Unexpected refcount %ld.\n", refcount);
576 IXMLElement_Release(child);
577 hr = IXMLElement_addChild(element, child2, 0, -1);
578 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
579
580 hr = IXMLElement_get_children(element, &collection);
581 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
582 ok(collection != NULL, "Expected non-NULL collection\n");
583
584 refcount = IXMLElement_AddRef(child);
585 ok(refcount == 2, "Unexpected refcount %ld.\n", refcount);
586 IXMLElement_Release(child);
587
588 length = 0;
589 hr = IXMLElementCollection_get_length(collection, &length);
590 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
591 ok(length == 2, "Unexpected length %ld.\n", length);
592
593 IXMLElement_Release(child2);
594
595 length = 0;
596 hr = IXMLElementCollection_get_length(collection, &length);
597 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
598 ok(length == 2, "Unexpected length %ld.\n", length);
599
600 V_VT(&vIndex) = VT_I4;
601 V_I4(&vIndex) = 1;
602 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child2);
603 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
604 ok(child2 != NULL, "Expected not NULL child\n");
605 IXMLElementCollection_Release(collection);
606 IXMLElement_Release(child2);
607
608 /* add element->child->child2 structure, then remove child2 from node */
609 V_VT(&vType) = VT_I4;
610 V_I4(&vType) = XMLELEMTYPE_TEXT;
611 V_VT(&vName) = VT_NULL;
612 hr = IXMLDocument_createElement(doc, vType, vName, &child2);
613 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
614 ok(child2 != NULL, "Expected non-NULL child\n");
615
616 hr = IXMLElement_addChild(child, child2, 0, -1);
617 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
618
619 hr = IXMLElement_removeChild(element, child2);
620 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
621
622 hr = IXMLElement_removeChild(child, child2);
623 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
624
625 hr = IXMLElement_removeChild(child, NULL);
626 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
627
628 IXMLElement_Release(element);
629 IXMLElement_Release(child);
630 IXMLElement_Release(child2);
631 IXMLDocument_Release(doc);
632}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040

Referenced by START_TEST().

◆ test_xmlelem_collection()

static void test_xmlelem_collection ( void  )
static

Definition at line 634 of file xmldoc.c.

635{
636 HRESULT hr;
637 IUnknown *unk = NULL;
638 IXMLDocument *doc = NULL;
639 IXMLElement *element = NULL, *child;
640 IXMLElementCollection *collection = NULL;
641 IEnumVARIANT *enumVar = NULL;
645 ULONG num_vars;
646 VARIANT var[4], dummy, vIndex, vName;
647 BSTR url, str;
648
649 hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
650 &IID_IXMLDocument, (LPVOID*)&doc);
651 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
652
653 create_xml_file("bank.xml");
654 GetFullPathNameA("bank.xml", MAX_PATH, pathA, NULL);
656
658 hr = IXMLDocument_put_URL(doc, url);
659 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
661
662 if(hr != S_OK)
663 goto cleanup;
664
665 hr = IXMLDocument_get_root(doc, &element);
666 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
667 ok(element != NULL, "Expected non-NULL element\n");
668
669 hr = IXMLElement_get_children(element, &collection);
670 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
671 ok(collection != NULL, "Expected non-NULL collection\n");
672
673 hr = IXMLElementCollection_get_length(collection, NULL);
674 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
675
676 hr = IXMLElementCollection_get_length(collection, &length);
677 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
678 ok(length == 2, "Unexpected count %ld.\n", length);
679
680 /* IXMLElementCollection:put_length does nothing */
681 hr = IXMLElementCollection_put_length(collection, -1);
682 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
683
684 hr = IXMLElementCollection_put_length(collection, 0);
685 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
686
687 hr = IXMLElementCollection_put_length(collection, 1);
688 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
689
690 hr = IXMLElementCollection_put_length(collection, 2);
691 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
692
693 hr = IXMLElementCollection_put_length(collection, 3);
694 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
695
696 hr = IXMLElementCollection_put_length(collection, 50);
697 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
698
699 /* make sure the length hasn't changed */
700 hr = IXMLElementCollection_get_length(collection, &length);
701 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
702 ok(length == 2, "Unexpected count %ld.\n", length);
703
704 /* IXMLElementCollection implements IEnumVARIANT */
705 hr = IXMLElementCollection_QueryInterface(collection, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
706 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
707 ok(enumVar != NULL, "Expected non-NULL enumVar\n");
708 IEnumVARIANT_Release(enumVar);
709
710 hr = IXMLElementCollection_get__newEnum(collection, &unk);
711 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
712 ok(unk != NULL, "Expected non-NULL unk\n");
713
714 enumVar = (void *)0xdeadbeef;
715 hr = IUnknown_QueryInterface(unk, &IID_IXMLElementCollection, (LPVOID *)&enumVar);
716 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
717 ok(enumVar == NULL || broken(enumVar == (void *)0xdeadbeef) /* XP */, "Expected NULL, got %p\n", enumVar);
718
719 hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
720 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
721 ok(enumVar != NULL, "Expected non-NULL enumVar\n");
722 IUnknown_Release(unk);
723
724 /* <Number>1234</Number> */
725 hr = IEnumVARIANT_Next(enumVar, 1, &var[0], &num_vars);
726 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
727 ok(V_VT(&var[0]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[0]));
728 ok(num_vars == 1, "Unexpected count %ld.\n", num_vars);
729
730 hr = IDispatch_QueryInterface(V_DISPATCH(&var[0]), &IID_IXMLElement, (LPVOID *)&child);
731 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
732 ok(child != NULL, "Expected non-NULL child\n");
733
734 VariantClear(&var[0]);
735
736 hr = IXMLElement_get_type(child, &type);
737 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
738 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
739
740 hr = IXMLElement_get_tagName(child, &str);
741 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
742 ok(!lstrcmpW(str, L"NUMBER"), "Expected NUMBER\n");
744 IXMLElement_Release(child);
745
746 /* <Name>Captain Ahab</Name> */
747 hr = IEnumVARIANT_Next(enumVar, 1, &var[0], &num_vars);
748 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
749 ok(V_VT(&var[0]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[0]));
750 ok(num_vars == 1, "Unexpected count %ld.\n", num_vars);
751
752 VariantClear(&var[0]);
753
754 /* try advance further, no children left */
755 V_VT(&dummy) = VT_I4;
756 hr = IEnumVARIANT_Next(enumVar, 1, &dummy, &num_vars);
757 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
758 ok(V_VT(&dummy) == VT_EMPTY, "Expected 0, got %d\n", V_VT(&dummy));
759 ok(!num_vars, "Unexpected count %ld.\n", num_vars);
760
761 V_VT(&dummy) = VT_I4;
762 hr = IEnumVARIANT_Next(enumVar, 1, &dummy, NULL);
763 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
764 ok(V_VT(&dummy) == VT_EMPTY, "Expected 0, got %d\n", V_VT(&dummy));
765
766 hr = IEnumVARIANT_Reset(enumVar);
767 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
768
769 /* retrieve multiple elements */
770 hr = IEnumVARIANT_Next(enumVar, 2, var, &num_vars);
771 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
772 ok(V_VT(&var[0]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[0]));
773 ok(V_VT(&var[1]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[1]));
774 ok(num_vars == 2, "Unexpected count %ld.\n", num_vars);
775
776 V_VT(&dummy) = VT_I4;
777 hr = IEnumVARIANT_Next(enumVar, 1, &dummy, &num_vars);
778 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
779 ok(V_VT(&dummy) == VT_EMPTY, "Expected 0, got %d\n", V_VT(&dummy));
780 ok(!num_vars, "Unexpected count %ld.\n", num_vars);
781
782 hr = IEnumVARIANT_Reset(enumVar);
783 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
784
785 VariantClear(&var[1]);
786 VariantClear(&var[0]);
787
788 memset( var, 0xcc, sizeof(var));
789
790 /* request more elements than available */
791 hr = IEnumVARIANT_Next(enumVar, 4, var, &num_vars);
792 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
793 ok(V_VT(&var[0]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[0]));
794 ok(V_VT(&var[1]) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var[1]));
795 ok(V_VT(&var[2]) == VT_EMPTY, "Expected 0, got %d\n", V_VT(&var[2]));
796 ok(V_VT(&var[3]) == 0xcccc, "Expected invalid, got %x\n", V_VT(&var[3]));
797 ok(num_vars == 2, "Unexpected count %ld.\n", num_vars);
798
799#ifdef __REACTOS__
800 if (V_VT(&var[1]) == VT_DISPATCH) {
801#endif
802 hr = IDispatch_QueryInterface(V_DISPATCH(&var[1]), &IID_IXMLElement, (LPVOID *)&child);
803 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
804 ok(child != NULL, "Expected non-NULL child\n");
805
806 VariantClear(&var[1]);
807 VariantClear(&var[0]);
808
809 hr = IXMLElement_get_type(child, &type);
810 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
811 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
812
813 hr = IXMLElement_get_tagName(child, &str);
814 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
815 ok(!lstrcmpW(str, L"NAME"), "Expected NAME\n");
817 IXMLElement_Release(child);
818#ifdef __REACTOS__
819 }
820#endif
821
822 /* <Number>1234</Number> */
823 V_VT(&vIndex) = VT_I4;
824 V_I4(&vIndex) = 0;
825 V_VT(&vName) = VT_ERROR;
827 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
828 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
829 ok(child != NULL, "Expected non-NULL child\n");
830
831 hr = IXMLElement_get_type(child, &type);
832 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
833 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
834
835 hr = IXMLElement_get_tagName(child, &str);
836 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
837 ok(!lstrcmpW(str, L"NUMBER"), "Expected NUMBER\n");
839 IXMLElement_Release(child);
840
841 /* <Name>Captain Ahab</Name> */
842 V_VT(&vIndex) = VT_I4;
843 V_I4(&vIndex) = 1;
844 V_VT(&vName) = VT_ERROR;
846 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
847 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
848 ok(child != NULL, "Expected non-NULL child\n");
849
850 hr = IXMLElement_get_type(child, &type);
851 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
852 ok(type == XMLELEMTYPE_ELEMENT, "Unexpected type %ld.\n", type);
853
854 hr = IXMLElement_get_tagName(child, &str);
855 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
856 ok(!lstrcmpW(str, L"NAME"), "Expected NAME\n");
858 IXMLElement_Release(child);
859
860 V_I4(&vIndex) = 100;
861 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
862 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
863 ok(child == NULL, "Expected NULL child\n");
864
865 V_I4(&vIndex) = -1;
866 child = (IXMLElement *)0xdeadbeef;
867 hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
868 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
869 ok(child == NULL, "Expected NULL child\n");
870
871 IEnumVARIANT_Release(enumVar);
872 IXMLElement_Release(element);
873 IXMLElementCollection_Release(collection);
874cleanup:
875 IXMLDocument_Release(doc);
876 DeleteFileA("bank.xml");
877}
#define broken(x)
Definition: atltest.h:178
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
@ VT_DISPATCH
Definition: compat.h:2304
GLuint pathA
Definition: glext.h:11719
static const WCHAR url[]
Definition: encode.c:1384
const char * var
Definition: shader.c:5666
#define V_DISPATCH(A)
Definition: oleauto.h:239
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().