4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 * Copyright 2010-2011 Adam Martinson for CodeWeavers
7 * Copyright 2010-2013 Nikolay Sivov for CodeWeavers
8 * Copyright 2023 Daniel Lehman
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include "wine/test.h"
39 static BSTR alloced_bstrs
[256];
40 static int alloced_bstrs_count
;
42 static BSTR
alloc_str_from_narrow(const char *str
)
44 int len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
45 BSTR ret
= SysAllocStringLen(NULL
, len
- 1); /* NUL character added automatically */
46 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
50 static BSTR
_bstr_(const char *str
)
52 assert(alloced_bstrs_count
< ARRAY_SIZE(alloced_bstrs
));
53 alloced_bstrs
[alloced_bstrs_count
] = alloc_str_from_narrow(str
);
54 return alloced_bstrs
[alloced_bstrs_count
++];
57 static void free_bstrs(void)
60 for (i
= 0; i
< alloced_bstrs_count
; i
++)
61 SysFreeString(alloced_bstrs
[i
]);
62 alloced_bstrs_count
= 0;
65 /* see dlls/msxml[36]/tests/domdoc.c */
66 static void test_namespaces_as_attributes(void)
73 const char *prefixes
[3];
74 const char *basenames
[3];
78 static const struct test tests
[] =
81 "<a ns:b=\"b attr\" d=\"d attr\" xmlns:ns=\"nshref\" />", 3,
82 { "ns:b", "d", "xmlns:ns" }, /* nodeName */
83 { "ns", NULL
, "xmlns" }, /* prefix */
84 { "b", "d", "ns" }, /* baseName */
85 { "nshref", NULL
, "" }, /* namespaceURI */
86 { "b attr", "d attr", "nshref" }, /* text */
90 "<a d=\"d attr\" />", 1,
91 { "d" }, /* nodeName */
92 { NULL
}, /* prefix */
93 { "d" }, /* baseName */
94 { NULL
}, /* namespaceURI */
95 { "d attr" }, /* text */
99 "<a xmlns:ns=\"nshref\" />", 1,
100 { "xmlns:ns" }, /* nodeName */
101 { "xmlns" }, /* prefix */
102 { "ns" }, /* baseName */
103 { "" }, /* namespaceURI */
104 { "nshref" }, /* text */
106 /* no properties or namespaces */
113 const struct test
*test
;
114 IXMLDOMNamedNodeMap
*map
;
115 IXMLDOMNode
*node
, *item
;
116 IXMLDOMDocument2
*doc
;
125 hr
= CoCreateInstance(&CLSID_DOMDocument40
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (void **)&doc
);
126 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
128 hr
= IXMLDOMDocument2_loadXML(doc
, _bstr_(test
->xml
), &b
);
129 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
132 hr
= IXMLDOMDocument2_selectSingleNode(doc
, _bstr_("a"), &node
);
133 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
135 hr
= IXMLDOMNode_get_attributes(node
, &map
);
136 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
139 hr
= IXMLDOMNamedNodeMap_get_length(map
, &len
);
140 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
141 ok(len
== test
->explen
, "got %ld\n", len
);
144 hr
= IXMLDOMNamedNodeMap_get_item(map
, test
->explen
+1, &item
);
145 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
146 ok(!item
, "Item should be NULL\n");
148 for (i
= 0; i
< len
; i
++)
151 hr
= IXMLDOMNamedNodeMap_get_item(map
, i
, &item
);
152 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
155 hr
= IXMLDOMNode_get_nodeName(item
, &str
);
156 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
157 ok(!lstrcmpW(str
, _bstr_(test
->names
[i
])), "got %s\n", wine_dbgstr_w(str
));
161 hr
= IXMLDOMNode_get_prefix(item
, &str
);
162 if (test
->prefixes
[i
])
164 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
165 ok(!lstrcmpW(str
, _bstr_(test
->prefixes
[i
])), "got %s\n", wine_dbgstr_w(str
));
169 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
172 hr
= IXMLDOMNode_get_baseName(item
, &str
);
173 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
174 ok(!lstrcmpW(str
, _bstr_(test
->basenames
[i
])), "got %s\n", wine_dbgstr_w(str
));
178 hr
= IXMLDOMNode_get_namespaceURI(item
, &str
);
181 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
182 if (test
->prefixes
[i
] && !strcmp(test
->prefixes
[i
], "xmlns"))
183 ok(!lstrcmpW(str
, L
""), "got %s\n", wine_dbgstr_w(str
));
185 ok(!lstrcmpW(str
, _bstr_(test
->uris
[i
])), "got %s\n", wine_dbgstr_w(str
));
189 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
192 hr
= IXMLDOMNode_get_text(item
, &str
);
193 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
194 ok(!lstrcmpW(str
, _bstr_(test
->texts
[i
])), "got %s\n", wine_dbgstr_w(str
));
197 IXMLDOMNode_Release(item
);
200 IXMLDOMNamedNodeMap_Release(map
);
201 IXMLDOMNode_Release(node
);
202 IXMLDOMDocument2_Release(doc
);
212 IXMLDOMDocument2
*doc
;
214 hr
= CoInitialize(NULL
);
215 ok(hr
== S_OK
, "failed to init com\n");
217 hr
= CoCreateInstance(&CLSID_DOMDocument40
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (void **)&doc
);
220 win_skip("class &CLSID_DOMDocument40 not supported\n");
223 IXMLDOMDocument2_Release(doc
);
225 test_namespaces_as_attributes();