c9531188fc9b7063ba64952efcc66d0956616942
[reactos.git] / rostests / winetests / mshtml / dom.c
1 /*
2 * Copyright 2007-2011 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 //#include <stdarg.h>
24 #include <stdio.h>
25
26 //#include "windef.h"
27 //#include "winbase.h"
28 //#include "ole2.h"
29 #include <mshtml.h>
30 #include <mshtmcid.h>
31 #include <mshtmhst.h>
32 //#include "docobj.h"
33 //#include "dispex.h"
34 #include "mshtml_test.h"
35 #include <objsafe.h>
36 #include <htiface.h>
37 #include <tlogstg.h>
38
39 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
40 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
41
42 static const char doc_blank[] = "<html></html>";
43 static const char doc_str1[] = "<html><body>test</body></html>";
44 static const char range_test_str[] =
45 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
46 static const char range_test2_str[] =
47 "<html><body>abc<hr />123<br /><hr />def</body></html>";
48 static const char elem_test_str[] =
49 "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
50 "<meta id=\"metaid\" name=\"meta name\" http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
51 "<link id=\"linkid\"></head>"
52 "<body onload=\"Testing()\">text test<!-- a comment -->"
53 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
54 "<label for=\"in\" id=\"labelid\">Label:</label>"
55 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
56 "<button id=\"btnid\"></button>"
57 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
58 "<textarea id=\"X\">text text</textarea>"
59 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
60 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
61 "<test /><object id=\"objid\" name=\"objname\" vspace=100></object><embed />"
62 "<img id=\"imgid\" name=\"WineImg\"/>"
63 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
64 "<form id=\"frm\"></form>"
65 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
66 "</body></html>";
67 static const char elem_test2_str[] =
68 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
69 "<link id=\"linkid\" rel=\"stylesheet\" href=\"about:blank\" type=\"text/css\"></head>"
70 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
71 "</html>";
72
73 static const char indent_test_str[] =
74 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
75 static const char cond_comment_str[] =
76 "<html><head><title>test</title></head><body>"
77 "<!--[if gte IE 4]> <br> <![endif]-->"
78 "</body></html>";
79 static const char frameset_str[] =
80 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
81 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
82 "<frame src=\"about:blank\" id=\"fr3\">"
83 "</frameset></html>";
84 static const char emptydiv_str[] =
85 "<html><head><title>emptydiv test</title></head>"
86 "<body><div id=\"divid\"></div></body></html>";
87 static const char noscript_str[] =
88 "<html><head><title>noscript test</title><noscript><style>.body { margin-right: 0px; }</style></noscript></head>"
89 "<body><noscript><div>test</div></noscript></body></html>";
90 static const char doctype_str[] =
91 "<!DOCTYPE html>"
92 "<html><head><title>emptydiv test</title></head>"
93 "<body><div id=\"divid\"></div></body></html>";
94
95 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
96 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
97 static WCHAR wordW[] = {'w','o','r','d',0};
98
99 typedef enum {
100 ET_NONE,
101 ET_HTML,
102 ET_HEAD,
103 ET_TITLE,
104 ET_BODY,
105 ET_A,
106 ET_INPUT,
107 ET_SELECT,
108 ET_TEXTAREA,
109 ET_OPTION,
110 ET_STYLE,
111 ET_BLOCKQUOTE,
112 ET_P,
113 ET_BR,
114 ET_TABLE,
115 ET_TBODY,
116 ET_SCRIPT,
117 ET_TEST,
118 ET_TESTG,
119 ET_COMMENT,
120 ET_IMG,
121 ET_TR,
122 ET_TD,
123 ET_IFRAME,
124 ET_FORM,
125 ET_FRAME,
126 ET_OBJECT,
127 ET_EMBED,
128 ET_DIV,
129 ET_META,
130 ET_NOSCRIPT,
131 ET_LINK,
132 ET_LABEL,
133 ET_BUTTON
134 } elem_type_t;
135
136 static const IID * const none_iids[] = {
137 &IID_IUnknown,
138 NULL
139 };
140
141 static const IID * const doc_node_iids[] = {
142 &IID_IHTMLDOMNode,
143 &IID_IHTMLDOMNode2,
144 &IID_IHTMLDocument,
145 &IID_IHTMLDocument2,
146 &IID_IHTMLDocument3,
147 &IID_IHTMLDocument4,
148 &IID_IHTMLDocument5,
149 &IID_IDispatchEx,
150 &IID_IConnectionPointContainer,
151 &IID_IInternetHostSecurityManager,
152 &IID_IOleContainer,
153 &IID_IObjectSafety,
154 &IID_IProvideClassInfo,
155 NULL
156 };
157
158 static const IID * const doc_obj_iids[] = {
159 &IID_IHTMLDocument,
160 &IID_IHTMLDocument2,
161 &IID_IHTMLDocument3,
162 &IID_IHTMLDocument4,
163 &IID_IHTMLDocument5,
164 &IID_IDispatchEx,
165 &IID_IConnectionPointContainer,
166 &IID_ICustomDoc,
167 &IID_IOleContainer,
168 &IID_IObjectSafety,
169 &IID_IProvideClassInfo,
170 &IID_ITargetContainer,
171 NULL
172 };
173
174 #define ELEM_IFACES \
175 &IID_IHTMLDOMNode, \
176 &IID_IHTMLDOMNode2, \
177 &IID_IHTMLElement, \
178 &IID_IHTMLElement2, \
179 &IID_IHTMLElement3, \
180 &IID_IHTMLElement4, \
181 &IID_IDispatchEx
182
183 static const IID * const elem_iids[] = {
184 ELEM_IFACES,
185 &IID_IConnectionPointContainer,
186 NULL
187 };
188
189 static const IID * const body_iids[] = {
190 ELEM_IFACES,
191 &IID_IHTMLTextContainer,
192 &IID_IHTMLBodyElement,
193 &IID_IConnectionPointContainer,
194 NULL
195 };
196
197 static const IID * const anchor_iids[] = {
198 ELEM_IFACES,
199 &IID_IHTMLAnchorElement,
200 &IID_IConnectionPointContainer,
201 NULL
202 };
203
204 static const IID * const input_iids[] = {
205 ELEM_IFACES,
206 &IID_IHTMLInputElement,
207 &IID_IHTMLInputTextElement,
208 &IID_IConnectionPointContainer,
209 NULL
210 };
211
212 static const IID *const button_iids[] = {
213 ELEM_IFACES,
214 &IID_IHTMLButtonElement,
215 &IID_IConnectionPointContainer,
216 NULL
217 };
218
219 static const IID * const label_iids[] = {
220 ELEM_IFACES,
221 &IID_IHTMLLabelElement,
222 &IID_IConnectionPointContainer,
223 NULL
224 };
225
226 static const IID * const select_iids[] = {
227 ELEM_IFACES,
228 &IID_IHTMLSelectElement,
229 &IID_IConnectionPointContainer,
230 NULL
231 };
232
233 static const IID * const textarea_iids[] = {
234 ELEM_IFACES,
235 &IID_IHTMLTextAreaElement,
236 &IID_IConnectionPointContainer,
237 NULL
238 };
239
240 static const IID * const option_iids[] = {
241 ELEM_IFACES,
242 &IID_IHTMLOptionElement,
243 &IID_IConnectionPointContainer,
244 NULL
245 };
246
247 static const IID * const table_iids[] = {
248 ELEM_IFACES,
249 &IID_IHTMLTable,
250 &IID_IHTMLTable2,
251 &IID_IHTMLTable3,
252 &IID_IConnectionPointContainer,
253 NULL
254 };
255
256 static const IID * const script_iids[] = {
257 ELEM_IFACES,
258 &IID_IHTMLScriptElement,
259 &IID_IConnectionPointContainer,
260 NULL
261 };
262
263 static const IID * const text_iids[] = {
264 &IID_IHTMLDOMNode,
265 &IID_IHTMLDOMNode2,
266 &IID_IHTMLDOMTextNode,
267 NULL
268 };
269
270 static const IID * const attr_iids[] = {
271 &IID_IHTMLDOMAttribute,
272 &IID_IDispatchEx,
273 NULL
274 };
275
276 static const IID * const location_iids[] = {
277 &IID_IDispatch,
278 &IID_IHTMLLocation,
279 NULL
280 };
281
282 static const IID * const window_iids[] = {
283 &IID_IDispatch,
284 &IID_IHTMLWindow2,
285 &IID_IHTMLWindow3,
286 &IID_IDispatchEx,
287 &IID_IServiceProvider,
288 NULL
289 };
290
291 static const IID * const comment_iids[] = {
292 ELEM_IFACES,
293 &IID_IHTMLCommentElement,
294 &IID_IConnectionPointContainer,
295 NULL
296 };
297
298 static const IID * const img_iids[] = {
299 ELEM_IFACES,
300 &IID_IHTMLImgElement,
301 &IID_IConnectionPointContainer,
302 NULL
303 };
304
305 static const IID * const tr_iids[] = {
306 ELEM_IFACES,
307 &IID_IHTMLTableRow,
308 &IID_IConnectionPointContainer,
309 NULL
310 };
311
312 static const IID * const td_iids[] = {
313 ELEM_IFACES,
314 &IID_IHTMLTableCell,
315 &IID_IConnectionPointContainer,
316 NULL
317 };
318
319 static const IID * const frame_iids[] = {
320 ELEM_IFACES,
321 &IID_IHTMLFrameBase,
322 &IID_IHTMLFrameBase2,
323 &IID_IConnectionPointContainer,
324 NULL
325 };
326
327 static const IID * const head_iids[] = {
328 ELEM_IFACES,
329 &IID_IHTMLHeadElement,
330 &IID_IConnectionPointContainer,
331 NULL
332 };
333
334 static const IID * const title_iids[] = {
335 ELEM_IFACES,
336 &IID_IHTMLTitleElement,
337 &IID_IConnectionPointContainer,
338 NULL
339 };
340
341 static const IID * const meta_iids[] = {
342 ELEM_IFACES,
343 &IID_IHTMLMetaElement,
344 &IID_IConnectionPointContainer,
345 NULL
346 };
347
348 static const IID * const link_iids[] = {
349 ELEM_IFACES,
350 &IID_IHTMLLinkElement,
351 &IID_IConnectionPointContainer,
352 NULL
353 };
354
355 static const IID * const object_iids[] = {
356 ELEM_IFACES,
357 &IID_IHTMLObjectElement,
358 &IID_IHTMLObjectElement2,
359 /* FIXME: No IConnectionPointContainer */
360 NULL
361 };
362
363 static const IID * const embed_iids[] = {
364 ELEM_IFACES,
365 &IID_IHTMLEmbedElement,
366 /* FIXME: No IConnectionPointContainer */
367 NULL
368 };
369
370 static const IID * const iframe_iids[] = {
371 ELEM_IFACES,
372 &IID_IHTMLFrameBase,
373 &IID_IHTMLFrameBase2,
374 &IID_IHTMLIFrameElement,
375 &IID_IHTMLIFrameElement2,
376 &IID_IConnectionPointContainer,
377 NULL
378 };
379
380 static const IID * const form_iids[] = {
381 ELEM_IFACES,
382 &IID_IHTMLFormElement,
383 &IID_IConnectionPointContainer,
384 NULL
385 };
386
387 static const IID * const styleelem_iids[] = {
388 ELEM_IFACES,
389 &IID_IHTMLStyleElement,
390 &IID_IConnectionPointContainer,
391 NULL
392 };
393
394 static const IID * const generic_iids[] = {
395 ELEM_IFACES,
396 &IID_IHTMLGenericElement,
397 &IID_IConnectionPointContainer,
398 NULL
399 };
400
401 static const IID * const style_iids[] = {
402 &IID_IUnknown,
403 &IID_IDispatch,
404 &IID_IDispatchEx,
405 &IID_IHTMLStyle,
406 &IID_IHTMLStyle2,
407 &IID_IHTMLStyle3,
408 &IID_IHTMLStyle4,
409 NULL
410 };
411
412 static const IID * const cstyle_iids[] = {
413 &IID_IUnknown,
414 &IID_IDispatch,
415 &IID_IDispatchEx,
416 &IID_IHTMLCurrentStyle,
417 &IID_IHTMLCurrentStyle2,
418 &IID_IHTMLCurrentStyle3,
419 NULL
420 };
421
422 static const IID * const img_factory_iids[] = {
423 &IID_IUnknown,
424 &IID_IDispatch,
425 &IID_IDispatchEx,
426 &IID_IHTMLImageElementFactory,
427 NULL
428 };
429
430 typedef struct {
431 const char *tag;
432 REFIID *iids;
433 const IID *dispiid;
434 } elem_type_info_t;
435
436 static const elem_type_info_t elem_type_infos[] = {
437 {"", none_iids, NULL},
438 {"HTML", elem_iids, NULL},
439 {"HEAD", head_iids, &DIID_DispHTMLHeadElement},
440 {"TITLE", title_iids, &DIID_DispHTMLTitleElement},
441 {"BODY", body_iids, &DIID_DispHTMLBody},
442 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
443 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
444 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
445 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
446 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
447 {"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement},
448 {"BLOCKQUOTE",elem_iids, NULL},
449 {"P", elem_iids, NULL},
450 {"BR", elem_iids, NULL},
451 {"TABLE", table_iids, &DIID_DispHTMLTable},
452 {"TBODY", elem_iids, NULL},
453 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
454 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
455 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
456 {"!", comment_iids, &DIID_DispHTMLCommentElement},
457 {"IMG", img_iids, &DIID_DispHTMLImg},
458 {"TR", tr_iids, &DIID_DispHTMLTableRow},
459 {"TD", td_iids, &DIID_DispHTMLTableCell},
460 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
461 {"FORM", form_iids, &DIID_DispHTMLFormElement},
462 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement},
463 {"OBJECT", object_iids, &DIID_DispHTMLObjectElement},
464 {"EMBED", embed_iids, &DIID_DispHTMLEmbed},
465 {"DIV", elem_iids, NULL},
466 {"META", meta_iids, &DIID_DispHTMLMetaElement},
467 {"NOSCRIPT", elem_iids, NULL /*&DIID_DispHTMLNoShowElement*/},
468 {"LINK", link_iids, &DIID_DispHTMLLinkElement},
469 {"LABEL", label_iids, &DIID_DispHTMLLabelElement},
470 {"BUTTON", button_iids, &DIID_DispHTMLButtonElement}
471 };
472
473 static int strcmp_wa(LPCWSTR strw, const char *stra)
474 {
475 CHAR buf[512];
476 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
477 return lstrcmpA(stra, buf);
478 }
479
480 static BSTR a2bstr(const char *str)
481 {
482 BSTR ret;
483 int len;
484
485 if(!str)
486 return NULL;
487
488 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
489 ret = SysAllocStringLen(NULL, len);
490 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
491
492 return ret;
493 }
494
495 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
496 {
497 IUnknown *unk1, *unk2;
498
499 if(iface1 == iface2)
500 return TRUE;
501
502 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
503 IUnknown_Release(unk1);
504 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
505 IUnknown_Release(unk2);
506
507 return unk1 == unk2;
508 }
509
510 static IHTMLDocument2 *create_document(void)
511 {
512 IHTMLDocument2 *doc;
513 IHTMLDocument5 *doc5;
514 HRESULT hres;
515
516 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
517 &IID_IHTMLDocument2, (void**)&doc);
518 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
519 if(FAILED(hres))
520 return NULL;
521
522 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
523 if(FAILED(hres)) {
524 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
525 IHTMLDocument2_Release(doc);
526 return NULL;
527 }
528
529 IHTMLDocument5_Release(doc5);
530 return doc;
531 }
532
533 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
534 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
535 {
536 IDispatchEx *dispex;
537 HRESULT hres;
538
539 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
540 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
541 return dispex;
542 }
543
544 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
545 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
546 {
547 const IID * const *piid;
548 IUnknown *unk;
549 HRESULT hres;
550
551 for(piid = iids; *piid; piid++) {
552 hres = IUnknown_QueryInterface(iface, *piid, (void**)&unk);
553 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", wine_dbgstr_guid(*piid), hres);
554 if(SUCCEEDED(hres))
555 IUnknown_Release(unk);
556 }
557 }
558
559 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
560 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
561 {
562 IUnknown *unk;
563 HRESULT hres;
564
565 unk = (void*)0xdeadbeef;
566 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
567 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
568 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
569 }
570
571 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
572 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
573 {
574 IDispatchEx *dispex = _get_dispex_iface(line, unk);
575 ITypeInfo *typeinfo;
576 BOOL ret = FALSE;
577 UINT ticnt;
578 HRESULT hres;
579
580 ticnt = 0xdeadbeef;
581 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
582 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
583 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
584
585 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
586 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
587
588 if(SUCCEEDED(hres)) {
589 TYPEATTR *type_attr;
590
591 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
592 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
593 if(hres == S_OK) {
594 *iid = type_attr->guid;
595 ret = TRUE;
596 }
597
598 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
599 ITypeInfo_Release(typeinfo);
600 }
601
602 IDispatchEx_Release(dispex);
603 return ret;
604 }
605
606 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
607 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
608 {
609 IDispatchEx *dispex = _get_dispex_iface(line, unk);
610 DISPPARAMS dp = {NULL,NULL,0,0};
611 EXCEPINFO ei;
612 VARIANT var;
613 HRESULT hres;
614
615 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
616 IDispatchEx_Release(dispex);
617 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
618
619 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
620 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
621 VariantClear(&var);
622 }
623
624 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
625 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
626 {
627 IID iid;
628
629 if(_test_get_dispid(line, unk, &iid))
630 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", wine_dbgstr_guid(&iid));
631
632 if(val)
633 _test_disp_value(line, unk, val);
634 }
635
636 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
637 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
638 {
639 IID iid;
640
641 if(_test_get_dispid(line, unk, &iid))
642 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
643 "unexpected guid %s\n", wine_dbgstr_guid(&iid));
644
645 if(val)
646 _test_disp_value(line, unk, val);
647 }
648
649 #define test_class_info(u) _test_class_info(__LINE__,u)
650 static void _test_class_info(unsigned line, IUnknown *unk)
651 {
652 IProvideClassInfo *classinfo;
653 ITypeInfo *typeinfo;
654 TYPEATTR *type_attr;
655 HRESULT hres;
656
657 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
658 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
659 if(FAILED(hres))
660 return;
661
662 hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
663 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
664 if(FAILED(hres))
665 {
666 IProvideClassInfo_Release(classinfo);
667 return;
668 }
669
670 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
671 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
672 if(SUCCEEDED(hres))
673 {
674 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
675 "unexpected guid %s\n", wine_dbgstr_guid(&type_attr->guid));
676 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
677 "unexpected typekind %d\n", type_attr->typekind);
678 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
679 }
680
681 ITypeInfo_Release(typeinfo);
682 IProvideClassInfo_Release(classinfo);
683 }
684
685 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
686 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
687 {
688 IDispatchEx *dispex = _get_dispex_iface(line, unk);
689 DISPPARAMS dp = {val, NULL, 1, 0};
690 EXCEPINFO ei;
691 DISPID id;
692 BSTR str;
693 HRESULT hres;
694
695 str = a2bstr(name);
696 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
697 SysFreeString(str);
698 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
699
700 memset(&ei, 0, sizeof(ei));
701 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
702 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
703
704 }
705
706 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
707 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
708 {
709 IHTMLElement *elem;
710 HRESULT hres;
711
712 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
713 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
714 return elem;
715 }
716
717 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
718 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
719 {
720 IHTMLElement2 *elem;
721 HRESULT hres;
722
723 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
724 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
725 return elem;
726 }
727
728 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
729 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
730 {
731 IHTMLElement3 *elem;
732 HRESULT hres;
733
734 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
735 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
736 return elem;
737 }
738
739 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
740 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
741 {
742 IHTMLElement4 *elem;
743 HRESULT hres;
744
745 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
746 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
747 return elem;
748 }
749
750 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
751 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IHTMLDocument2 *doc)
752 {
753 IHTMLDocument3 *doc3;
754 HRESULT hres;
755
756 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
757 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
758
759 return doc3;
760 }
761
762 #define get_node_iface(u) _get_node_iface(__LINE__,u)
763 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
764 {
765 IHTMLDOMNode *node;
766 HRESULT hres;
767
768 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
769 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
770 return node;
771 }
772
773 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
774 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
775 {
776 IHTMLDOMNode2 *node;
777 HRESULT hres;
778
779 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
780 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
781 return node;
782 }
783
784 #define get_htmldoc5_iface(u) _get_htmldoc5_iface(__LINE__,u)
785 static IHTMLDocument5 *_get_htmldoc5_iface(unsigned line, IUnknown *unk)
786 {
787 IHTMLDocument5 *doc;
788 HRESULT hres;
789
790 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument5, (void**)&doc);
791 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument5: %08x\n", hres);
792 return doc;
793 }
794
795 #define get_img_iface(u) _get_img_iface(__LINE__,u)
796 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
797 {
798 IHTMLImgElement *img;
799 HRESULT hres;
800
801 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
802 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
803 return img;
804 }
805
806 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
807 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
808 {
809 IHTMLAnchorElement *anchor;
810 HRESULT hres;
811
812 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
813 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
814 return anchor;
815 }
816
817 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
818 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
819 {
820 IHTMLTextAreaElement *textarea;
821 HRESULT hres;
822
823 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
824 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
825 return textarea;
826 }
827
828 #define get_select_iface(u) _get_select_iface(__LINE__,u)
829 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
830 {
831 IHTMLSelectElement *select;
832 HRESULT hres;
833
834 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
835 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
836 return select;
837 }
838
839 #define get_form_iface(u) _get_form_iface(__LINE__,u)
840 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
841 {
842 IHTMLFormElement *form;
843 HRESULT hres;
844
845 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
846 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
847 return form;
848 }
849
850 #define get_text_iface(u) _get_text_iface(__LINE__,u)
851 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
852 {
853 IHTMLDOMTextNode *text;
854 HRESULT hres;
855
856 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
857 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
858 return text;
859 }
860
861 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
862 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
863 {
864 IHTMLCommentElement *comment;
865 HRESULT hres;
866
867 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
868 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
869 return comment;
870 }
871
872 #define get_object_iface(u) _get_object_iface(__LINE__,u)
873 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
874 {
875 IHTMLObjectElement *obj;
876 HRESULT hres;
877
878 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
879 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
880 return obj;
881 }
882
883 #define get_style_iface(u) _get_style_iface(__LINE__,u)
884 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
885 {
886 IHTMLStyleElement *obj;
887 HRESULT hres;
888
889 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
890 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
891 return obj;
892 }
893
894 #define get_metaelem_iface(u) _get_metaelem_iface(__LINE__,u)
895 static IHTMLMetaElement *_get_metaelem_iface(unsigned line, IUnknown *unk)
896 {
897 IHTMLMetaElement *ret;
898 HRESULT hres;
899
900 hres = IUnknown_QueryInterface(unk, &IID_IHTMLMetaElement, (void**)&ret);
901 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLMetaElement: %08x\n", hres);
902 return ret;
903 }
904
905 #define get_link_iface(u) _get_link_iface(__LINE__,u)
906 static IHTMLLinkElement *_get_link_iface(unsigned line, IUnknown *unk)
907 {
908 IHTMLLinkElement *ret;
909 HRESULT hres;
910
911 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLinkElement, (void**)&ret);
912 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLinkElement: %08x\n", hres);
913 return ret;
914 }
915
916 #define get_iframe2_iface(u) _get_iframe2_iface(__LINE__,u)
917 static IHTMLIFrameElement2 *_get_iframe2_iface(unsigned line, IUnknown *unk)
918 {
919 IHTMLIFrameElement2 *ret;
920 HRESULT hres;
921
922 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement2, (void**)&ret);
923 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLIFrameElement: %08x\n", hres);
924 return ret;
925 }
926
927 #define get_button_iface(u) _get_button_iface(__LINE__,u)
928 static IHTMLButtonElement *_get_button_iface(unsigned line, IUnknown *unk)
929 {
930 IHTMLButtonElement *ret;
931 HRESULT hres;
932
933 hres = IUnknown_QueryInterface(unk, &IID_IHTMLButtonElement, (void**)&ret);
934 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLButtonElement: %08x\n", hres);
935 return ret;
936 }
937
938 #define get_label_iface(u) _get_label_iface(__LINE__,u)
939 static IHTMLLabelElement *_get_label_iface(unsigned line, IUnknown *unk)
940 {
941 IHTMLLabelElement *ret;
942 HRESULT hres;
943
944 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLabelElement, (void**)&ret);
945 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLabelElement: %08x\n", hres);
946 return ret;
947 }
948
949 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
950 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
951 {
952 IHTMLDOMNode *node = _get_node_iface(line, unk);
953 BSTR name;
954 HRESULT hres;
955
956 hres = IHTMLDOMNode_get_nodeName(node, &name);
957 IHTMLDOMNode_Release(node);
958 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
959 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
960
961 SysFreeString(name);
962 }
963
964 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
965 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
966 {
967 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
968 IDispatch *disp = (void*)0xdeadbeef;
969 IHTMLDocument2 *doc = NULL;
970 HRESULT hres;
971
972 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
973 IHTMLDOMNode2_Release(node);
974 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
975
976 if(disp) {
977 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
978 IDispatch_Release(disp);
979 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
980 }
981
982 return doc;
983 }
984
985 #define get_doc_window(d) _get_doc_window(__LINE__,d)
986 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
987 {
988 IHTMLWindow2 *window;
989 HRESULT hres;
990
991 window = NULL;
992 hres = IHTMLDocument2_get_parentWindow(doc, &window);
993 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
994 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
995
996 return window;
997 }
998
999 #define clone_node(n,d) _clone_node(__LINE__,n,d)
1000 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
1001 {
1002 IHTMLDOMNode *node = _get_node_iface(line, unk);
1003 IHTMLDOMNode *ret = NULL;
1004 HRESULT hres;
1005
1006 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
1007 IHTMLDOMNode_Release(node);
1008 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
1009 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
1010
1011 return ret;
1012
1013 }
1014
1015 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
1016 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
1017 {
1018 IHTMLElement *elem = _get_elem_iface(line, unk);
1019 BSTR tag;
1020 HRESULT hres;
1021
1022 hres = IHTMLElement_get_tagName(elem, &tag);
1023 IHTMLElement_Release(elem);
1024 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
1025 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
1026
1027 SysFreeString(tag);
1028 }
1029
1030 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
1031 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
1032 {
1033 _test_elem_tag(line, unk, elem_type_infos[type].tag);
1034 _test_ifaces(line, unk, elem_type_infos[type].iids);
1035
1036 if(elem_type_infos[type].dispiid && type != ET_A)
1037 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
1038 }
1039
1040 #define get_node_type(n) _get_node_type(__LINE__,n)
1041 static LONG _get_node_type(unsigned line, IUnknown *unk)
1042 {
1043 IHTMLDOMNode *node = _get_node_iface(line, unk);
1044 LONG type = -1;
1045 HRESULT hres;
1046
1047 hres = IHTMLDOMNode_get_nodeType(node, &type);
1048 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1049
1050 IHTMLDOMNode_Release(node);
1051
1052 return type;
1053 }
1054
1055 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1056 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1057 {
1058 IHTMLDOMNode *node = _get_node_iface(line, unk);
1059 IHTMLDOMChildrenCollection *col = NULL;
1060 IDispatch *disp;
1061 HRESULT hres;
1062
1063 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1064 IHTMLDOMNode_Release(node);
1065 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1066 if(FAILED(hres))
1067 return NULL;
1068
1069 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1070 IDispatch_Release(disp);
1071 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1072
1073 return col;
1074 }
1075
1076 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1077 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
1078 {
1079 IHTMLDOMNode *node = NULL;
1080 IDispatch *disp;
1081 HRESULT hres;
1082
1083 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1084 ok(hres == S_OK, "item failed: %08x\n", hres);
1085
1086 node = _get_node_iface(line, (IUnknown*)disp);
1087 IDispatch_Release(disp);
1088
1089 return node;
1090 }
1091
1092 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
1093 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
1094 {
1095 VARIANT value;
1096 BSTR tmp;
1097 HRESULT hres;
1098
1099 VariantInit(&value);
1100
1101 tmp = a2bstr(name);
1102 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
1103 SysFreeString(tmp);
1104 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
1105
1106 if(exval) {
1107 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
1108 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
1109 }else {
1110 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
1111 }
1112
1113 VariantClear(&value);
1114 }
1115
1116 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
1117 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
1118 {
1119 IHTMLElement *elem = _get_elem_iface(line, unk);
1120 IHTMLElement *off_parent;
1121 LONG l;
1122 HRESULT hres;
1123
1124 hres = IHTMLElement_get_offsetTop(elem, &l);
1125 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1126
1127 hres = IHTMLElement_get_offsetHeight(elem, &l);
1128 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1129
1130 hres = IHTMLElement_get_offsetWidth(elem, &l);
1131 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1132
1133 hres = IHTMLElement_get_offsetLeft(elem, &l);
1134 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1135
1136 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1137 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1138
1139 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1140 IHTMLElement_Release(off_parent);
1141
1142 IHTMLElement_Release(elem);
1143 }
1144
1145 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1146 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1147 {
1148 IHTMLWindow2 *window;
1149 IHTMLDocument2 *ret;
1150 HRESULT hres;
1151
1152 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1153 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1154
1155 hres = IHTMLWindow2_get_document(window, &ret);
1156 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1157 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1158
1159 return ret;
1160 }
1161
1162 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1163 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1164 {
1165 BSTR name;
1166 HRESULT hres;
1167
1168 hres = IHTMLWindow2_get_name(window, &name);
1169 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1170 if(exname)
1171 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1172 else
1173 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1174 SysFreeString(name);
1175 }
1176
1177 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1178 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1179 {
1180 BSTR str;
1181 HRESULT hres;
1182
1183 str = a2bstr(name);
1184 hres = IHTMLWindow2_put_name(window, str);
1185 SysFreeString(str);
1186 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1187
1188 _test_window_name(line, window, name);
1189 }
1190
1191 #define test_window_status(d) _test_window_status(__LINE__,d)
1192 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1193 {
1194 BSTR status;
1195 HRESULT hres;
1196
1197 status = (void*)0xdeadbeef;
1198 hres = IHTMLWindow2_get_status(window, &status);
1199 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1200 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1201 SysFreeString(status);
1202 }
1203
1204 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1205 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1206 {
1207 BSTR str;
1208 HRESULT hres;
1209
1210 str = a2bstr(status);
1211 hres = IHTMLWindow2_put_status(window, str);
1212 SysFreeString(str);
1213 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1214 }
1215
1216 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1217 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1218 {
1219 LONG length = -1;
1220 HRESULT hres;
1221
1222 hres = IHTMLWindow2_get_length(window, &length);
1223 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1224 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1225 }
1226
1227 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1228 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1229 {
1230 IHTMLFrameBase2 *base2;
1231 IHTMLWindow2 *window;
1232 HRESULT hres;
1233
1234 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1235 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1236
1237 window = NULL;
1238 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1239 IHTMLFrameBase2_Release(base2);
1240 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1241 ok(window != NULL, "contentWindow = NULL\n");
1242
1243 return window;
1244 }
1245
1246 static void test_get_set_attr(IHTMLDocument2 *doc)
1247 {
1248 IHTMLElement *elem;
1249 IHTMLDocument3 *doc3;
1250 HRESULT hres;
1251 BSTR bstr;
1252 VARIANT val;
1253
1254 /* grab an element to test with */
1255 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1256 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1257
1258 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1259 IHTMLDocument3_Release(doc3);
1260 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1261
1262 /* get a non-present attribute */
1263 bstr = a2bstr("notAnAttribute");
1264 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1265 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1266 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1267 VariantClear(&val);
1268 SysFreeString(bstr);
1269
1270 /* get a present attribute */
1271 bstr = a2bstr("scrollHeight");
1272 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1273 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1274 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1275 VariantClear(&val);
1276 SysFreeString(bstr);
1277
1278 /* create a new BSTR attribute */
1279 bstr = a2bstr("newAttribute");
1280
1281 V_VT(&val) = VT_BSTR;
1282 V_BSTR(&val) = a2bstr("the value");
1283 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1284 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1285 VariantClear(&val);
1286
1287 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1288 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1289 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1290 ok(strcmp_wa(V_BSTR(&val), "the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
1291 VariantClear(&val);
1292
1293 /* overwrite the attribute with a BOOL */
1294 V_VT(&val) = VT_BOOL;
1295 V_BOOL(&val) = VARIANT_TRUE;
1296 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1297 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1298 VariantClear(&val);
1299
1300 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1301 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1302 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1303 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1304 VariantClear(&val);
1305
1306 SysFreeString(bstr);
1307
1308 /* case-insensitive */
1309 bstr = a2bstr("newattribute");
1310 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1311 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1312 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1313 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1314 VariantClear(&val);
1315 SysFreeString(bstr);
1316
1317 IHTMLElement_Release(elem);
1318 }
1319
1320 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1321 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1322 {
1323 IHTMLElement *elem;
1324 IHTMLDocument3 *doc3;
1325 HRESULT hres;
1326
1327 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1328 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1329 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1330 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1331 IHTMLDocument3_Release(doc3);
1332
1333 return elem;
1334 }
1335
1336 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1337 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1338 {
1339 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1340 BSTR str;
1341 HRESULT hres;
1342
1343 hres = IHTMLAnchorElement_get_href(anchor, &str);
1344 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1345 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1346 SysFreeString(str);
1347
1348 _test_disp_value(line, unk, exhref);
1349 }
1350
1351 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1352 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1353 {
1354 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1355 BSTR str;
1356 HRESULT hres;
1357
1358 str = a2bstr(exhref);
1359 hres = IHTMLAnchorElement_put_href(anchor, str);
1360 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1361 SysFreeString(str);
1362
1363 _test_disp_value(line, unk, exhref);
1364 }
1365
1366 #define test_anchor_rel(a,h) _test_anchor_rel(__LINE__,a,h)
1367 static void _test_anchor_rel(unsigned line, IUnknown *unk, const char *exrel)
1368 {
1369 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1370 BSTR str;
1371 HRESULT hres;
1372
1373 hres = IHTMLAnchorElement_get_rel(anchor, &str);
1374 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1375 if(exrel)
1376 ok_(__FILE__,line)(!strcmp_wa(str, exrel), "rel = %s, expected %s\n", wine_dbgstr_w(str), exrel);
1377 else
1378 ok_(__FILE__,line)(!str, "rel = %s, expected NULL\n", wine_dbgstr_w(str));
1379 SysFreeString(str);
1380 }
1381
1382 #define test_anchor_put_rel(a,h) _test_anchor_put_rel(__LINE__,a,h)
1383 static void _test_anchor_put_rel(unsigned line, IUnknown *unk, const char *exrel)
1384 {
1385 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1386 BSTR str;
1387 HRESULT hres;
1388
1389 str = a2bstr(exrel);
1390 hres = IHTMLAnchorElement_put_rel(anchor, str);
1391 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1392 SysFreeString(str);
1393 }
1394
1395 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1396 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1397 {
1398 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1399 BSTR str;
1400 HRESULT hres;
1401
1402 hres = IHTMLAnchorElement_get_target(anchor, &str);
1403 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1404 if(target)
1405 ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1406 else
1407 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1408 SysFreeString(str);
1409 }
1410
1411 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1412 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1413 {
1414 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1415 BSTR str;
1416 HRESULT hres;
1417
1418 str = target ? a2bstr(target) : NULL;
1419 hres = IHTMLAnchorElement_put_target(anchor, str);
1420 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1421 SysFreeString(str);
1422 }
1423
1424 #define test_anchor_name(a,h) _test_anchor_name(__LINE__,a,h)
1425 static void _test_anchor_name(unsigned line, IUnknown *unk, const char *name)
1426 {
1427 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1428 BSTR str;
1429 HRESULT hres;
1430
1431 hres = IHTMLAnchorElement_get_name(anchor, &str);
1432 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1433 if(name)
1434 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
1435 else
1436 ok_(__FILE__,line)(str == NULL, "name = %s, expected NULL\n", wine_dbgstr_w(str));
1437 SysFreeString(str);
1438 }
1439
1440 #define test_anchor_put_name(a,h) _test_anchor_put_name(__LINE__,a,h)
1441 static void _test_anchor_put_name(unsigned line, IUnknown *unk, const char *name)
1442 {
1443 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1444 BSTR str;
1445 HRESULT hres;
1446
1447 str = name ? a2bstr(name) : NULL;
1448 hres = IHTMLAnchorElement_put_name(anchor, str);
1449 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1450 SysFreeString(str);
1451
1452 _test_anchor_name(line, unk, name);
1453 }
1454
1455 #define test_anchor_hostname(a,h) _test_anchor_hostname(__LINE__,a,h)
1456 static void _test_anchor_hostname(unsigned line, IUnknown *unk, const char *hostname)
1457 {
1458 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1459 BSTR str;
1460 HRESULT hres;
1461
1462 hres = IHTMLAnchorElement_get_hostname(anchor, &str);
1463 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1464 if(hostname)
1465 ok_(__FILE__,line)(!strcmp_wa(str, hostname), "hostname = %s, expected %s\n", wine_dbgstr_w(str), hostname);
1466 else
1467 ok_(__FILE__,line)(str == NULL, "hostname = %s, expected NULL\n", wine_dbgstr_w(str));
1468 SysFreeString(str);
1469 }
1470
1471 #define test_anchor_hash(a,h) _test_anchor_hash(__LINE__,a,h)
1472 static void _test_anchor_hash(unsigned line, IHTMLElement *elem, const char *exhash)
1473 {
1474 IHTMLAnchorElement *anchor = _get_anchor_iface(line, (IUnknown*)elem);
1475 BSTR str;
1476 HRESULT hres;
1477
1478 hres = IHTMLAnchorElement_get_hash(anchor, &str);
1479 ok_(__FILE__,line)(hres == S_OK, "get_hash failed: %08x\n", hres);
1480 if(exhash)
1481 ok_(__FILE__,line)(!strcmp_wa(str, exhash), "hash = %s, expected %s\n", wine_dbgstr_w(str), exhash);
1482 else
1483 ok_(__FILE__,line)(!str, "hash = %s, expected NULL\n", wine_dbgstr_w(str));
1484 SysFreeString(str);
1485 }
1486
1487 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1488 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1489 {
1490 BSTR bstr;
1491 HRESULT hres;
1492
1493 hres = IHTMLOptionElement_get_text(option, &bstr);
1494 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1495 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1496 SysFreeString(bstr);
1497 }
1498
1499 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1500 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1501 {
1502 BSTR bstr;
1503 HRESULT hres;
1504
1505 bstr = a2bstr(text);
1506 hres = IHTMLOptionElement_put_text(option, bstr);
1507 SysFreeString(bstr);
1508 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1509
1510 _test_option_text(line, option, text);
1511 }
1512
1513 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1514 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1515 {
1516 BSTR bstr;
1517 HRESULT hres;
1518
1519 hres = IHTMLOptionElement_get_value(option, &bstr);
1520 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1521 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1522 SysFreeString(bstr);
1523 }
1524
1525 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1526 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1527 {
1528 BSTR bstr;
1529 HRESULT hres;
1530
1531 bstr = a2bstr(value);
1532 hres = IHTMLOptionElement_put_value(option, bstr);
1533 SysFreeString(bstr);
1534 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1535
1536 _test_option_value(line, option, value);
1537 }
1538
1539 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1540 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1541 {
1542 VARIANT_BOOL b = 0x100;
1543 HRESULT hres;
1544
1545 hres = IHTMLOptionElement_get_selected(option, &b);
1546 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1547 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1548 }
1549
1550 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1551 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1552 {
1553 HRESULT hres;
1554
1555 hres = IHTMLOptionElement_put_selected(option, b);
1556 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1557 _test_option_selected(line, option, b);
1558 }
1559
1560 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1561 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1562 {
1563 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1564 BSTR value = (void*)0xdeadbeef;
1565 HRESULT hres;
1566
1567 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1568 IHTMLTextAreaElement_Release(textarea);
1569 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1570 if(exval)
1571 ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1572 else
1573 ok_(__FILE__,line)(!value, "value = %p\n", value);
1574 SysFreeString(value);
1575 }
1576
1577 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1578 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1579 {
1580 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1581 BSTR tmp = a2bstr(value);
1582 HRESULT hres;
1583
1584 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1585 IHTMLTextAreaElement_Release(textarea);
1586 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1587 SysFreeString(tmp);
1588
1589 _test_textarea_value(line, unk, value);
1590 }
1591
1592 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1593 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1594 {
1595 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1596 VARIANT_BOOL b = 0x100;
1597 HRESULT hres;
1598
1599 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1600 IHTMLTextAreaElement_Release(textarea);
1601 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1602 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1603 }
1604
1605 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1606 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1607 {
1608 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1609 HRESULT hres;
1610
1611 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1612 IHTMLTextAreaElement_Release(textarea);
1613 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1614
1615 _test_textarea_readonly(line, unk, b);
1616 }
1617
1618 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1619 static void _test_textarea_type(unsigned line, IUnknown *unk)
1620 {
1621 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1622 BSTR type = (void*)0xdeadbeef;
1623 HRESULT hres;
1624
1625 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1626 IHTMLTextAreaElement_Release(textarea);
1627 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1628 ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1629 SysFreeString(type);
1630 }
1631
1632 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1633 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1634 {
1635 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1636 BSTR text;
1637 HRESULT hres;
1638
1639 text = a2bstr(extext);
1640 hres = IHTMLCommentElement_get_text(comment, &text);
1641 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1642 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1643
1644 IHTMLCommentElement_Release(comment);
1645 SysFreeString(text);
1646 }
1647
1648 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1649 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1650 {
1651 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1652 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1653 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1654 IHTMLDOMAttribute *attr;
1655 BSTR name = a2bstr("test");
1656 VARIANT val;
1657 HRESULT hres;
1658
1659 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1660 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1661 ok(attr == NULL, "attr != NULL\n");
1662
1663 V_VT(&val) = VT_I4;
1664 V_I4(&val) = 1234;
1665 hres = IHTMLElement_setAttribute(elem, name, val, 0);
1666 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1667
1668 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1669 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1670 ok(attr != NULL, "attr == NULL\n");
1671
1672 IHTMLDOMAttribute_Release(attr);
1673 IHTMLCommentElement_Release(comment);
1674 IHTMLElement_Release(elem);
1675 IHTMLElement4_Release(elem4);
1676 SysFreeString(name);
1677 }
1678
1679 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1680 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1681 {
1682 IHTMLObjectElement *object = _get_object_iface(line, unk);
1683 LONG l;
1684 HRESULT hres;
1685
1686 l = 0xdeadbeef;
1687 hres = IHTMLObjectElement_get_vspace(object, &l);
1688 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1689 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1690 IHTMLObjectElement_Release(object);
1691 }
1692
1693 #define test_object_name(a,b) _test_object_name(__LINE__,a,b)
1694 static void _test_object_name(unsigned line, IHTMLElement *elem, const char *exname)
1695 {
1696 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1697 BSTR str;
1698 HRESULT hres;
1699
1700 str = (void*)0xdeadbeef;
1701 hres = IHTMLObjectElement_get_name(object, &str);
1702 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1703 if(exname)
1704 ok_(__FILE__,line)(!strcmp_wa(str, exname), "name=%s, expected %s\n", wine_dbgstr_w(str), exname);
1705 else
1706 ok_(__FILE__,line)(!str, "name=%s, expected NULL\n", wine_dbgstr_w(str));
1707 SysFreeString(str);
1708 IHTMLObjectElement_Release(object);
1709 }
1710
1711 #define set_object_name(a,b) _set_object_name(__LINE__,a,b)
1712 static void _set_object_name(unsigned line, IHTMLElement *elem, const char *name)
1713 {
1714 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1715 BSTR str;
1716 HRESULT hres;
1717
1718 str = a2bstr(name);
1719 hres = IHTMLObjectElement_put_name(object, str);
1720 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1721 SysFreeString(str);
1722 IHTMLObjectElement_Release(object);
1723
1724 _test_object_name(line, elem, name);
1725 }
1726
1727 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1728 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1729 const char *txt, const char *val)
1730 {
1731 IHTMLOptionElementFactory *factory;
1732 IHTMLOptionElement *option;
1733 IHTMLWindow2 *window;
1734 VARIANT text, value, empty;
1735 HRESULT hres;
1736
1737 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1738 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1739
1740 hres = IHTMLWindow2_get_Option(window, &factory);
1741 IHTMLWindow2_Release(window);
1742 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1743
1744 V_VT(&text) = VT_BSTR;
1745 V_BSTR(&text) = a2bstr(txt);
1746 V_VT(&value) = VT_BSTR;
1747 V_BSTR(&value) = a2bstr(val);
1748 V_VT(&empty) = VT_EMPTY;
1749
1750 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1751 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1752
1753 IHTMLOptionElementFactory_Release(factory);
1754 VariantClear(&text);
1755 VariantClear(&value);
1756
1757 _test_option_text(line, option, txt);
1758 _test_option_value(line, option, val);
1759 _test_option_selected(line, option, VARIANT_FALSE);
1760
1761 return option;
1762 }
1763
1764 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1765 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1766 {
1767 LONG found = -1;
1768 HRESULT hres;
1769
1770 hres = IHTMLImgElement_get_width(img, &found);
1771 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1772 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1773 }
1774
1775 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1776 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
1777 {
1778 HRESULT hres;
1779
1780 hres = IHTMLImgElement_put_width(img, width);
1781 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1782
1783 _test_img_width(line, img, width);
1784 }
1785
1786 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1787 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
1788 {
1789 LONG found = -1;
1790 HRESULT hres;
1791
1792 hres = IHTMLImgElement_get_height(img, &found);
1793 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1794 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1795 }
1796
1797 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1798 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
1799 {
1800 HRESULT hres;
1801
1802 hres = IHTMLImgElement_put_height(img, height);
1803 ok(hres == S_OK, "put_height failed: %08x\n", hres);
1804
1805 _test_img_height(line, img, height);
1806 }
1807
1808 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1809 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1810 LONG wdth, LONG hght)
1811 {
1812 IHTMLImageElementFactory *factory;
1813 IHTMLImgElement *img;
1814 IHTMLWindow2 *window;
1815 VARIANT width, height;
1816 char buf[16];
1817 HRESULT hres;
1818
1819 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1820 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1821
1822 hres = IHTMLWindow2_get_Image(window, &factory);
1823 IHTMLWindow2_Release(window);
1824 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1825
1826 test_ifaces((IUnknown*)factory, img_factory_iids);
1827 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1828
1829 if(wdth >= 0){
1830 snprintf(buf, 16, "%d", wdth);
1831 V_VT(&width) = VT_BSTR;
1832 V_BSTR(&width) = a2bstr(buf);
1833 }else{
1834 V_VT(&width) = VT_EMPTY;
1835 wdth = 0;
1836 }
1837
1838 if(hght >= 0){
1839 snprintf(buf, 16, "%d", hght);
1840 V_VT(&height) = VT_BSTR;
1841 V_BSTR(&height) = a2bstr(buf);
1842 }else{
1843 V_VT(&height) = VT_EMPTY;
1844 hght = 0;
1845 }
1846
1847 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1848 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1849
1850 IHTMLImageElementFactory_Release(factory);
1851 VariantClear(&width);
1852 VariantClear(&height);
1853
1854 if(SUCCEEDED(hres)) {
1855 _test_img_width(line, img, wdth);
1856 _test_img_height(line, img, hght);
1857 return img;
1858 }
1859
1860 return NULL;
1861 }
1862
1863 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1864 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1865 {
1866 LONG len = 0xdeadbeef;
1867 HRESULT hres;
1868
1869 hres = IHTMLSelectElement_get_length(select, &len);
1870 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1871 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1872 }
1873
1874 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
1875 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
1876 {
1877 IHTMLSelectElement *select = _get_select_iface(line, unk);
1878 HRESULT hres;
1879
1880 hres = IHTMLSelectElement_put_length(select, length);
1881 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
1882 _test_select_length(line, select, length);
1883 IHTMLSelectElement_Release(select);
1884 }
1885
1886 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1887 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1888 {
1889 LONG idx = 0xdeadbeef;
1890 HRESULT hres;
1891
1892 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1893 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1894 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1895 }
1896
1897 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1898 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1899 {
1900 HRESULT hres;
1901
1902 hres = IHTMLSelectElement_put_selectedIndex(select, index);
1903 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1904 _test_select_selidx(line, select, index);
1905 }
1906
1907 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1908 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1909 {
1910 BSTR val;
1911 HRESULT hres;
1912
1913 hres = IHTMLSelectElement_get_value(select, &val);
1914 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1915 if(exval)
1916 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1917 else
1918 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1919 SysFreeString(val);
1920 }
1921
1922 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1923 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1924 {
1925 BSTR bstr;
1926 HRESULT hres;
1927
1928 bstr = a2bstr(val);
1929 hres = IHTMLSelectElement_put_value(select, bstr);
1930 SysFreeString(bstr);
1931 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1932 }
1933
1934 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1935 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1936 {
1937 BSTR type;
1938 HRESULT hres;
1939
1940 hres = IHTMLSelectElement_get_type(select, &type);
1941 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1942 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1943 SysFreeString(type);
1944 }
1945
1946 #define test_select_multiple(s,t) _test_select_multiple(__LINE__,s,t)
1947 static void _test_select_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exmultiple)
1948 {
1949 VARIANT_BOOL b = 100;
1950 HRESULT hres;
1951
1952 hres = IHTMLSelectElement_get_multiple(select, &b);
1953 ok_(__FILE__,line) (hres == S_OK, "get_multiple failed: %08x\n", hres);
1954 ok_(__FILE__,line) (b == exmultiple, "multiple=%x, expected %x\n", b, exmultiple);
1955 }
1956
1957 #define test_select_set_multiple(s,v) _test_select_set_multiple(__LINE__,s,v)
1958 static void _test_select_set_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL val)
1959 {
1960 HRESULT hres;
1961
1962 hres = IHTMLSelectElement_put_multiple(select, val);
1963 ok_(__FILE__,line) (hres == S_OK, "put_multiple failed: %08x\n", hres);
1964
1965 _test_select_multiple(line, select, val);
1966 }
1967
1968 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1969 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1970 {
1971 BSTR text;
1972 HRESULT hres;
1973
1974 hres = IHTMLTxtRange_get_text(range, &text);
1975 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1976
1977 if(extext) {
1978 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1979 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1980 }else {
1981 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1982 }
1983
1984 SysFreeString(text);
1985
1986 }
1987
1988 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1989 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1990 {
1991 HRESULT hres;
1992
1993 hres = IHTMLTxtRange_collapse(range, b);
1994 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1995 _test_range_text(line, range, NULL);
1996 }
1997
1998 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1999 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
2000 VARIANT_BOOL exb, const char *extext)
2001 {
2002 VARIANT_BOOL b = 0xe0e0;
2003 HRESULT hres;
2004
2005 hres = IHTMLTxtRange_expand(range, unit, &b);
2006 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
2007 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
2008 _test_range_text(line, range, extext);
2009 }
2010
2011 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
2012 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2013 {
2014 LONG c = 0xdeadbeef;
2015 HRESULT hres;
2016
2017 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
2018 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2019 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2020 _test_range_text(line, range, NULL);
2021 }
2022
2023 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
2024 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
2025 LPWSTR unit, LONG cnt, LONG excnt)
2026 {
2027 LONG c = 0xdeadbeef;
2028 HRESULT hres;
2029
2030 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
2031 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2032 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2033 }
2034
2035 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
2036 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2037 {
2038 LONG c = 0xdeadbeef;
2039 HRESULT hres;
2040
2041 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
2042 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2043 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2044 }
2045
2046 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
2047 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
2048 {
2049 HRESULT hres;
2050 BSTR bstr = a2bstr(text);
2051
2052 hres = IHTMLTxtRange_put_text(range, bstr);
2053 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
2054 SysFreeString(bstr);
2055 _test_range_text(line, range, NULL);
2056 }
2057
2058 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
2059 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2060 {
2061 VARIANT_BOOL b;
2062 HRESULT hres;
2063
2064 b = 0xe0e0;
2065 hres = IHTMLTxtRange_inRange(range1, range2, &b);
2066 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2067 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2068 }
2069
2070 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
2071 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2072 {
2073 VARIANT_BOOL b;
2074 HRESULT hres;
2075
2076 b = 0xe0e0;
2077 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
2078 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2079 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2080
2081 b = 0xe0e0;
2082 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
2083 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
2084 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
2085
2086 if(exb) {
2087 test_range_inrange(range1, range2, VARIANT_TRUE);
2088 test_range_inrange(range2, range1, VARIANT_TRUE);
2089 }
2090 }
2091
2092 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
2093 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
2094 {
2095 IHTMLElement *elem;
2096 HRESULT hres;
2097
2098 hres = IHTMLTxtRange_parentElement(range, &elem);
2099 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
2100
2101 _test_elem_type(line, (IUnknown*)elem, type);
2102
2103 IHTMLElement_Release(elem);
2104 }
2105
2106 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
2107 static void _test_elem_collection(unsigned line, IUnknown *unk,
2108 const elem_type_t *elem_types, LONG exlen)
2109 {
2110 IHTMLElementCollection *col;
2111 LONG len;
2112 DWORD i;
2113 VARIANT name, index;
2114 IDispatch *disp, *disp2;
2115 HRESULT hres;
2116
2117 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
2118 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2119
2120 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
2121
2122 hres = IHTMLElementCollection_get_length(col, &len);
2123 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2124 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
2125
2126 if(len > exlen)
2127 len = exlen;
2128
2129 V_VT(&index) = VT_EMPTY;
2130
2131 for(i=0; i<len; i++) {
2132 V_VT(&name) = VT_I4;
2133 V_I4(&name) = i;
2134 disp = (void*)0xdeadbeef;
2135 hres = IHTMLElementCollection_item(col, name, index, &disp);
2136 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2137 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
2138 if(FAILED(hres) || !disp)
2139 continue;
2140
2141 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
2142
2143 if(!i) {
2144 V_VT(&name) = VT_UINT;
2145 V_I4(&name) = 0;
2146 disp2 = (void*)0xdeadbeef;
2147 hres = IHTMLElementCollection_item(col, name, index, &disp2);
2148 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2149 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
2150 if(disp2)
2151 IDispatch_Release(disp2);
2152 }
2153
2154 IDispatch_Release(disp);
2155 }
2156
2157 V_VT(&name) = VT_I4;
2158 V_I4(&name) = len;
2159 disp = (void*)0xdeadbeef;
2160 hres = IHTMLElementCollection_item(col, name, index, &disp);
2161 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2162 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2163
2164 V_VT(&name) = VT_I4;
2165 V_I4(&name) = -1;
2166 disp = (void*)0xdeadbeef;
2167 hres = IHTMLElementCollection_item(col, name, index, &disp);
2168 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2169 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2170
2171 IHTMLElementCollection_Release(col);
2172 }
2173
2174 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
2175 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
2176 {
2177 IHTMLElement *elem = _get_elem_iface(line, unk);
2178 IDispatch *disp;
2179 HRESULT hres;
2180
2181 hres = IHTMLElement_get_all(elem, &disp);
2182 IHTMLElement_Release(elem);
2183 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2184
2185 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
2186 IDispatch_Release(disp);
2187 }
2188
2189 #define test_doc_all(a,b,c) _test_doc_all(__LINE__,a,b,c)
2190 static void _test_doc_all(unsigned line, IHTMLDocument2 *doc, const elem_type_t *elem_types, LONG exlen)
2191 {
2192 IHTMLElementCollection *col;
2193 HRESULT hres;
2194
2195 hres = IHTMLDocument2_get_all(doc, &col);
2196 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2197
2198 _test_elem_collection(line, (IUnknown*)col, elem_types, exlen);
2199 IHTMLElementCollection_Release(col);
2200 }
2201
2202 #define test_elem_getelembytag(a,b,c,d) _test_elem_getelembytag(__LINE__,a,b,c,d)
2203 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen, IHTMLElement **ret)
2204 {
2205 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2206 IHTMLElementCollection *col = NULL;
2207 elem_type_t *types = NULL;
2208 BSTR tmp;
2209 int i;
2210 HRESULT hres;
2211
2212 tmp = a2bstr(elem_type_infos[type].tag);
2213 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
2214 SysFreeString(tmp);
2215 IHTMLElement2_Release(elem);
2216 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
2217 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
2218
2219 if(exlen) {
2220 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
2221 for(i=0; i<exlen; i++)
2222 types[i] = type;
2223 }
2224
2225 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2226
2227 HeapFree(GetProcessHeap(), 0, types);
2228
2229 if(ret) {
2230 IDispatch *disp;
2231 VARIANT v;
2232
2233 V_VT(&v) = VT_I4;
2234 V_I4(&v) = 0;
2235 disp = NULL;
2236 hres = IHTMLElementCollection_item(col, v, v, &disp);
2237 ok(hres == S_OK, "item failed: %08x\n", hres);
2238 ok(disp != NULL, "disp == NULL\n");
2239 *ret = _get_elem_iface(line, (IUnknown*)disp);
2240 IDispatch_Release(disp);
2241 }
2242
2243 IHTMLElementCollection_Release(col);
2244 }
2245
2246 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
2247 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
2248 {
2249 BSTR text = NULL;
2250 HRESULT hres;
2251
2252 hres = IHTMLElement_get_innerText(elem, &text);
2253 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
2254 if(extext)
2255 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
2256 wine_dbgstr_w(text), extext);
2257 else
2258 ok_(__FILE__,line) (!text, "get_innerText returned %s expected NULL\n", wine_dbgstr_w(text));
2259 SysFreeString(text);
2260 }
2261
2262 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
2263 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
2264 {
2265 IHTMLDOMChildrenCollection *col;
2266 BSTR str;
2267 HRESULT hres;
2268
2269 str = a2bstr(text);
2270 hres = IHTMLElement_put_innerText(elem, str);
2271 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
2272 SysFreeString(str);
2273
2274 _test_elem_innertext(line, elem, text);
2275
2276
2277 col = _get_child_nodes(line, (IUnknown*)elem);
2278 ok(col != NULL, "col == NULL\n");
2279 if(col) {
2280 LONG length = 0, type;
2281 IHTMLDOMNode *node;
2282
2283 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
2284 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2285 ok(length == 1, "length = %d\n", length);
2286
2287 node = _get_child_item(line, col, 0);
2288 ok(node != NULL, "node == NULL\n");
2289 if(node) {
2290 type = _get_node_type(line, (IUnknown*)node);
2291 ok(type == 3, "type=%d\n", type);
2292 IHTMLDOMNode_Release(node);
2293 }
2294
2295 IHTMLDOMChildrenCollection_Release(col);
2296 }
2297
2298 }
2299
2300 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2301 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2302 {
2303 IHTMLElement *elem = _get_elem_iface(line, unk);
2304 BSTR html;
2305 HRESULT hres;
2306
2307 hres = IHTMLElement_get_innerHTML(elem, &html);
2308 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2309 if(inner_html)
2310 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2311 else
2312 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2313
2314 IHTMLElement_Release(elem);
2315 SysFreeString(html);
2316 }
2317
2318 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2319 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2320 {
2321 IHTMLElement *elem = _get_elem_iface(line, unk);
2322 BSTR html;
2323 HRESULT hres;
2324
2325 html = a2bstr(inner_html);
2326 hres = IHTMLElement_put_innerHTML(elem, html);
2327 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2328
2329 IHTMLElement_Release(elem);
2330 SysFreeString(html);
2331 }
2332
2333 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2334 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2335 {
2336 IHTMLElement *elem = _get_elem_iface(line, unk);
2337 BSTR html;
2338 HRESULT hres;
2339
2340 html = a2bstr(outer_html);
2341 hres = IHTMLElement_put_outerHTML(elem, html);
2342 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2343
2344 IHTMLElement_Release(elem);
2345 SysFreeString(html);
2346 }
2347
2348 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2349 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2350 {
2351 IHTMLElement *elem = _get_elem_iface(line, unk);
2352 BSTR html;
2353 HRESULT hres;
2354
2355 hres = IHTMLElement_get_outerHTML(elem, &html);
2356 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2357 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2358
2359 IHTMLElement_Release(elem);
2360 SysFreeString(html);
2361 }
2362
2363 #define test_elem_contains(a,b,c) _test_elem_contains(__LINE__,a,b,c)
2364 static void _test_elem_contains(unsigned line, IHTMLElement *elem, IHTMLElement *elem2, VARIANT_BOOL exval)
2365 {
2366 VARIANT_BOOL b;
2367 HRESULT hres;
2368
2369 b = 100;
2370 hres = IHTMLElement_contains(elem, elem2, &b);
2371 ok_(__FILE__,line)(hres == S_OK, "contains failed: %08x\n", hres);
2372 ok_(__FILE__,line)(b == exval, "contains returned %x, expected %x\n", b, exval);
2373 }
2374
2375 #define get_first_child(n) _get_first_child(__LINE__,n)
2376 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2377 {
2378 IHTMLDOMNode *node = _get_node_iface(line, unk);
2379 IHTMLDOMNode *child = NULL;
2380 HRESULT hres;
2381
2382 hres = IHTMLDOMNode_get_firstChild(node, &child);
2383 IHTMLDOMNode_Release(node);
2384 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2385
2386 return child;
2387 }
2388
2389 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2390 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2391 {
2392 IHTMLDOMNode *node = _get_node_iface(line, unk);
2393 VARIANT_BOOL b = 0xdead;
2394 HRESULT hres;
2395
2396 hres = IHTMLDOMNode_hasChildNodes(node, &b);
2397 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2398 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2399
2400 IHTMLDOMNode_Release(node);
2401 }
2402
2403 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2404 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2405 {
2406 IHTMLDOMNode *node = _get_node_iface(line, unk);
2407 IHTMLDOMNode *parent;
2408 HRESULT hres;
2409
2410 hres = IHTMLDOMNode_get_parentNode(node, &parent);
2411 IHTMLDOMNode_Release(node);
2412 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2413
2414 return parent;
2415 }
2416
2417 #define node_get_next(u) _node_get_next(__LINE__,u)
2418 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2419 {
2420 IHTMLDOMNode *node = _get_node_iface(line, unk);
2421 IHTMLDOMNode *next;
2422 HRESULT hres;
2423
2424 hres = IHTMLDOMNode_get_nextSibling(node, &next);
2425 IHTMLDOMNode_Release(node);
2426 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2427
2428 return next;
2429 }
2430
2431 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2432 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2433 {
2434 IHTMLDOMNode *node = _get_node_iface(line, unk);
2435 IHTMLDOMNode *prev;
2436 HRESULT hres;
2437
2438 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2439 IHTMLDOMNode_Release(node);
2440 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2441
2442 return prev;
2443 }
2444
2445 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2446 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2447 {
2448 IHTMLElement *elem = _get_elem_iface(line, unk);
2449 IHTMLElement *parent;
2450 HRESULT hres;
2451
2452 hres = IHTMLElement_get_parentElement(elem, &parent);
2453 IHTMLElement_Release(elem);
2454 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2455
2456 return parent;
2457 }
2458
2459 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2460 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2461 {
2462 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2463 VARIANT_BOOL disabled = 100;
2464 HRESULT hres;
2465
2466 if (!elem3) return;
2467 hres = IHTMLElement3_get_disabled(elem3, &disabled);
2468 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2469 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2470 IHTMLElement3_Release(elem3);
2471 }
2472
2473 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2474 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2475 {
2476 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2477 HRESULT hres;
2478
2479 if (!elem3) return;
2480 hres = IHTMLElement3_put_disabled(elem3, b);
2481 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2482
2483 IHTMLElement3_Release(elem3);
2484 _test_elem3_get_disabled(line, unk, b);
2485 }
2486
2487 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2488 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2489 {
2490 VARIANT_BOOL disabled = 100;
2491 HRESULT hres;
2492
2493 hres = IHTMLSelectElement_get_disabled(select, &disabled);
2494 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2495 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2496
2497 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2498 }
2499
2500 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2501 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2502 {
2503 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2504 LONG length;
2505 HRESULT hres;
2506
2507 hres = IHTMLDOMTextNode_get_length(text, &length);
2508 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2509 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2510 IHTMLDOMTextNode_Release(text);
2511 }
2512
2513 #define test_text_data(a,b) _test_text_data(__LINE__,a,b)
2514 static void _test_text_data(unsigned line, IUnknown *unk, const char *exdata)
2515 {
2516 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2517 BSTR str;
2518 HRESULT hres;
2519
2520 hres = IHTMLDOMTextNode_get_data(text, &str);
2521 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2522 ok_(__FILE__,line)(!strcmp_wa(str, exdata), "data = %s, expected %s\n", wine_dbgstr_w(str), exdata);
2523 IHTMLDOMTextNode_Release(text);
2524 SysFreeString(str);
2525 }
2526
2527 #define set_text_data(a,b) _set_text_data(__LINE__,a,b)
2528 static void _set_text_data(unsigned line, IUnknown *unk, const char *data)
2529 {
2530 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2531 BSTR str = a2bstr(data);
2532 HRESULT hres;
2533
2534 hres = IHTMLDOMTextNode_put_data(text, str);
2535 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2536 IHTMLDOMTextNode_Release(text);
2537 SysFreeString(str);
2538 }
2539
2540 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2541 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2542 {
2543 HRESULT hres;
2544
2545 hres = IHTMLSelectElement_put_disabled(select, b);
2546 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2547
2548 _test_select_get_disabled(line, select, b);
2549 }
2550
2551 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2552 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2553 {
2554 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2555 IHTMLTextContainer *txtcont;
2556 LONG l = -1, l2 = -1;
2557 HRESULT hres;
2558
2559 hres = IHTMLElement2_get_scrollHeight(elem, &l);
2560 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2561 IHTMLElement2_Release(elem);
2562
2563 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2564 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2565
2566 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2567 IHTMLTextContainer_Release(txtcont);
2568 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2569 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
2570
2571 return l;
2572 }
2573
2574 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
2575 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
2576 {
2577 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2578 IHTMLTextContainer *txtcont;
2579 LONG l = -1, l2 = -1;
2580 HRESULT hres;
2581
2582 hres = IHTMLElement2_get_scrollWidth(elem, &l);
2583 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
2584 IHTMLElement2_Release(elem);
2585
2586 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2587 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2588
2589 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
2590 IHTMLTextContainer_Release(txtcont);
2591 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
2592 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
2593
2594 return l;
2595 }
2596
2597 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
2598 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
2599 {
2600 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2601 IHTMLTextContainer *txtcont;
2602 LONG l = -1, l2 = -1;
2603 HRESULT hres;
2604
2605 hres = IHTMLElement2_get_scrollTop(elem, &l);
2606 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2607 IHTMLElement2_Release(elem);
2608
2609 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2610 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2611
2612 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
2613 IHTMLTextContainer_Release(txtcont);
2614 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
2615 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
2616
2617 return l;
2618 }
2619
2620 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
2621 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
2622 {
2623 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2624 IHTMLTextContainer *txtcont;
2625 LONG l = -1, l2 = -1;
2626 HRESULT hres;
2627
2628 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
2629 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
2630
2631 hres = IHTMLElement2_get_scrollLeft(elem, &l);
2632 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2633 IHTMLElement2_Release(elem);
2634
2635 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2636 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2637
2638 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
2639 IHTMLTextContainer_Release(txtcont);
2640 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
2641 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
2642 }
2643
2644 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
2645 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
2646 {
2647 IHTMLImgElement *img = _get_img_iface(line, unk);
2648 BSTR src;
2649 HRESULT hres;
2650
2651 hres = IHTMLImgElement_get_src(img, &src);
2652 IHTMLImgElement_Release(img);
2653 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2654 ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
2655 "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2656 SysFreeString(src);
2657 }
2658
2659 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
2660 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
2661 {
2662 IHTMLImgElement *img = _get_img_iface(line, unk);
2663 BSTR tmp;
2664 HRESULT hres;
2665
2666 tmp = a2bstr(src);
2667 hres = IHTMLImgElement_put_src(img, tmp);
2668 IHTMLImgElement_Release(img);
2669 SysFreeString(tmp);
2670 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2671 }
2672
2673 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
2674 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
2675 {
2676 IHTMLImgElement *img = _get_img_iface(line, unk);
2677 BSTR alt;
2678 HRESULT hres;
2679
2680 hres = IHTMLImgElement_get_alt(img, &alt);
2681 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2682 if(exalt)
2683 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
2684 else
2685 ok_(__FILE__,line) (!alt, "alt != NULL\n");
2686 SysFreeString(alt);
2687 }
2688
2689 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
2690 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
2691 {
2692 IHTMLImgElement *img = _get_img_iface(line, unk);
2693 BSTR tmp;
2694 HRESULT hres;
2695
2696 tmp = a2bstr(alt);
2697 hres = IHTMLImgElement_put_alt(img, tmp);
2698 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2699 SysFreeString(tmp);
2700
2701 _test_img_alt(line, unk, alt);
2702 }
2703
2704 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
2705 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
2706 {
2707 IHTMLImgElement *img = _get_img_iface(line, unk);
2708 BSTR sName;
2709 HRESULT hres;
2710
2711 hres = IHTMLImgElement_get_name(img, &sName);
2712 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
2713 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
2714 IHTMLImgElement_Release(img);
2715 SysFreeString(sName);
2716 }
2717
2718 #define test_img_complete(a,b) _test_img_complete(__LINE__,a,b)
2719 static void _test_img_complete(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
2720 {
2721 IHTMLImgElement *img = _get_img_iface(line, (IUnknown*)elem);
2722 VARIANT_BOOL b = 100;
2723 HRESULT hres;
2724
2725 hres = IHTMLImgElement_get_complete(img, &b);
2726 ok_(__FILE__,line) (hres == S_OK, "get_complete failed: %08x\n", hres);
2727 ok_(__FILE__,line) (b == exb, "complete = %x, expected %x\n", b, exb);
2728 IHTMLImgElement_Release(img);
2729 }
2730
2731 static void test_dynamic_properties(IHTMLElement *elem)
2732 {
2733 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
2734 IDispatchEx *dispex;
2735 BSTR name, attr1 = SysAllocString(attr1W);
2736 VARIANT_BOOL succ;
2737 VARIANT val;
2738 int checked_no = 0;
2739 DISPID id = DISPID_STARTENUM;
2740 HRESULT hres;
2741
2742 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2743 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2744
2745 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
2746 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
2747 ok(succ, "removeAttribute set succ to FALSE\n");
2748
2749 while(1) {
2750 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2751 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
2752 if(hres != S_OK)
2753 break;
2754
2755 hres = IDispatchEx_GetMemberName(dispex, id, &name);
2756 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2757
2758 if(!strcmp_wa(name, "attr1"))
2759 ok(0, "attr1 should be removed\n");
2760 else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
2761 checked_no++;
2762 SysFreeString(name);
2763 }
2764 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
2765 IDispatchEx_Release(dispex);
2766
2767 V_VT(&val) = VT_BSTR;
2768 V_BSTR(&val) = attr1;
2769 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
2770 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2771 SysFreeString(attr1);
2772 }
2773
2774 #define test_attr_node_name(a,b) _test_attr_node_name(__LINE__,a,b)
2775 static void _test_attr_node_name(unsigned line, IHTMLDOMAttribute *attr, const char *exname)
2776 {
2777 BSTR str;
2778 HRESULT hres;
2779
2780 hres = IHTMLDOMAttribute_get_nodeName(attr, &str);
2781 ok_(__FILE__,line)(hres == S_OK, "get_nodeName failed: %08x\n", hres);
2782 ok_(__FILE__,line)(!strcmp_wa(str, exname), "node name is %s, expected %s\n", wine_dbgstr_w(str), exname);
2783 SysFreeString(str);
2784 }
2785
2786 static void test_attr_collection_disp(IDispatch *disp)
2787 {
2788 IDispatchEx *dispex;
2789 IHTMLDOMAttribute *attr;
2790 DISPPARAMS dp = {NULL, NULL, 0, 0};
2791 VARIANT var;
2792 EXCEPINFO ei;
2793 DISPID id;
2794 BSTR bstr;
2795 HRESULT hres;
2796
2797 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2798 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2799
2800 bstr = a2bstr("0");
2801 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2802 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2803 SysFreeString(bstr);
2804
2805 VariantInit(&var);
2806 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2807 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2808 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2809 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2810 VariantClear(&var);
2811
2812 bstr = a2bstr("attr1");
2813 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2814 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2815 SysFreeString(bstr);
2816
2817 VariantInit(&var);
2818 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2819 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2820 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2821 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2822 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
2823 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2824
2825 test_attr_node_name(attr, "attr1");
2826
2827 IHTMLDOMAttribute_Release(attr);
2828 VariantClear(&var);
2829
2830 IDispatchEx_Release(dispex);
2831 }
2832
2833 static void test_attr_collection(IHTMLElement *elem)
2834 {
2835 static const WCHAR testW[] = {'t','e','s','t',0};
2836
2837 IHTMLDOMNode *node;
2838 IDispatch *disp, *attr;
2839 IHTMLDOMAttribute *dom_attr;
2840 IHTMLAttributeCollection *attr_col;
2841 BSTR name = SysAllocString(testW);
2842 VARIANT id, val;
2843 LONG i, len, checked;
2844 HRESULT hres;
2845
2846 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
2847 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2848
2849 hres = IHTMLDOMNode_get_attributes(node, &disp);
2850 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2851
2852 hres = IHTMLDOMNode_get_attributes(node, &attr);
2853 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2854 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
2855 IDispatch_Release(attr);
2856 IHTMLDOMNode_Release(node);
2857
2858 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
2859 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2860
2861 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
2862 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2863
2864 V_VT(&val) = VT_I4;
2865 V_I4(&val) = 1;
2866 hres = IHTMLElement_setAttribute(elem, name, val, 0);
2867 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2868 SysFreeString(name);
2869
2870 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
2871 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2872 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
2873
2874 checked = 0;
2875 for(i=0; i<len; i++) {
2876 V_VT(&id) = VT_I4;
2877 V_I4(&id) = i;
2878 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2879 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
2880
2881 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
2882 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
2883 IDispatch_Release(attr);
2884
2885 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
2886 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
2887
2888 if(!strcmp_wa(name, "id")) {
2889 checked++;
2890 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2891 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2892 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
2893 ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2894 } else if(!strcmp_wa(name, "attr1")) {
2895 checked++;
2896 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2897 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2898 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
2899 ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2900 } else if(!strcmp_wa(name, "attr2")) {
2901 checked++;
2902 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2903 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2904 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
2905 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
2906 } else if(!strcmp_wa(name, "attr3")) {
2907 checked++;
2908 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2909 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2910 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
2911 ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2912 } else if(!strcmp_wa(name, "test")) {
2913 checked++;
2914 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2915 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2916 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
2917 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
2918 }
2919
2920 IHTMLDOMAttribute_Release(dom_attr);
2921 SysFreeString(name);
2922 VariantClear(&val);
2923 }
2924 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
2925
2926 V_I4(&id) = len;
2927 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2928 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2929
2930 V_VT(&id) = VT_BSTR;
2931 V_BSTR(&id) = a2bstr("nonexisting");
2932 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2933 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2934 VariantClear(&id);
2935
2936 test_attr_collection_disp(disp);
2937
2938 IDispatch_Release(disp);
2939 IHTMLAttributeCollection_Release(attr_col);
2940 }
2941
2942 #define test_attr_specified(a,b) _test_attr_specified(__LINE__,a,b)
2943 static void _test_attr_specified(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
2944 {
2945 VARIANT_BOOL specified;
2946 HRESULT hres;
2947
2948 hres = IHTMLDOMAttribute_get_specified(attr, &specified);
2949 ok_(__FILE__,line)(hres == S_OK, "get_specified failed: %08x\n", hres);
2950 ok_(__FILE__,line)(specified == expected, "specified = %x, expected %x\n", specified, expected);
2951 }
2952
2953 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
2954 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
2955 {
2956 BSTR type;
2957 HRESULT hres;
2958
2959 hres = IHTMLInputElement_get_type(input, &type);
2960 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2961 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
2962 SysFreeString(type);
2963 }
2964
2965 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
2966 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
2967 {
2968 BSTR name = (BSTR)0xdeadbeef;
2969 HRESULT hres;
2970
2971 hres = IHTMLInputElement_get_name(input, &name);
2972 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
2973 if(exname)
2974 ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
2975 else
2976 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
2977 SysFreeString(name);
2978 }
2979
2980 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
2981 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
2982 {
2983 BSTR tmp = a2bstr(name);
2984 HRESULT hres;
2985
2986 hres = IHTMLInputElement_put_name(input, tmp);
2987 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
2988 SysFreeString(tmp);
2989
2990 _test_input_name(line, input, name);
2991 }
2992
2993 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
2994 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2995 {
2996 VARIANT_BOOL disabled = 100;
2997 HRESULT hres;
2998
2999 hres = IHTMLInputElement_get_disabled(input, &disabled);
3000 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3001 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3002
3003 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
3004 }
3005
3006 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
3007 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3008 {
3009 HRESULT hres;
3010
3011 hres = IHTMLInputElement_put_disabled(input, b);
3012 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3013
3014 _test_input_get_disabled(line, input, b);
3015 }
3016
3017 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
3018 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3019 {
3020 VARIANT_BOOL checked = 100;
3021 HRESULT hres;
3022
3023 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
3024 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3025 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3026 }
3027
3028 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
3029 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3030 {
3031 HRESULT hres;
3032
3033 hres = IHTMLInputElement_put_defaultChecked(input, b);
3034 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3035
3036 _test_input_get_defaultchecked(line, input, b);
3037 }
3038
3039 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
3040 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3041 {
3042 VARIANT_BOOL checked = 100;
3043 HRESULT hres;
3044
3045 hres = IHTMLInputElement_get_checked(input, &checked);
3046 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
3047 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3048 }
3049
3050 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
3051 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3052 {
3053 HRESULT hres;
3054
3055 hres = IHTMLInputElement_put_checked(input, b);
3056 ok_(__FILE__,line) (hres == S_OK, "put_checked failed: %08x\n", hres);
3057
3058 _test_input_get_checked(line, input, b);
3059 }
3060
3061 #define test_input_maxlength(i,b) _test_input_maxlength(__LINE__,i,b)
3062 static void _test_input_maxlength(unsigned line, IHTMLInputElement *input, LONG exl)
3063 {
3064 LONG maxlength = 0xdeadbeef;
3065 HRESULT hres;
3066
3067 hres = IHTMLInputElement_get_maxLength(input, &maxlength);
3068 ok_(__FILE__,line) (hres == S_OK, "get_maxLength failed: %08x\n", hres);
3069 ok_(__FILE__,line) (maxlength == exl, "maxLength=%x, expected %d\n", maxlength, exl);
3070 }
3071
3072 #define test_input_set_maxlength(i,b) _test_input_set_maxlength(__LINE__,i,b)
3073 static void _test_input_set_maxlength(unsigned line, IHTMLInputElement *input, LONG l)
3074 {
3075 HRESULT hres;
3076
3077 hres = IHTMLInputElement_put_maxLength(input, l);
3078 ok_(__FILE__,line) (hres == S_OK, "put_maxLength failed: %08x\n", hres);
3079
3080 _test_input_maxlength(line, input, l);
3081 }
3082
3083 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
3084 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
3085 {
3086 IHTMLInputElement *input;
3087 BSTR bstr;
3088 HRESULT hres;
3089
3090 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3091 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3092 if(FAILED(hres))
3093 return;
3094
3095 hres = IHTMLInputElement_get_value(input, &bstr);
3096 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3097 if(exval)
3098 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
3099 else
3100 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
3101 SysFreeString(bstr);
3102 IHTMLInputElement_Release(input);
3103 }
3104
3105 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
3106 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
3107 {
3108 IHTMLInputElement *input;
3109 BSTR bstr;
3110 HRESULT hres;
3111
3112 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3113 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3114 if(FAILED(hres))
3115 return;
3116
3117 bstr = a2bstr(val);
3118 hres = IHTMLInputElement_put_value(input, bstr);
3119 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3120 SysFreeString(bstr);
3121 IHTMLInputElement_Release(input);
3122
3123 _test_input_value(line, unk, val);
3124 }
3125
3126 #define test_input_defaultValue(o,t) _test_input_defaultValue(__LINE__,o,t)
3127 static void _test_input_defaultValue(unsigned line, IUnknown *unk, const char *exval)
3128 {
3129 IHTMLInputElement *input;
3130 BSTR str;
3131 HRESULT hres;
3132
3133 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3134 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3135 if(FAILED(hres))
3136 return;
3137
3138 hres = IHTMLInputElement_get_defaultValue(input, &str);
3139 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3140 if(exval)
3141 ok_(__FILE__,line) (!strcmp_wa(str, exval), "defaultValue=%s\n", wine_dbgstr_w(str));
3142 else
3143 ok_(__FILE__,line) (!str, "exval != NULL\n");
3144 SysFreeString(str);
3145 IHTMLInputElement_Release(input);
3146 }
3147
3148 #define test_input_put_defaultValue(o,v) _test_input_put_defaultValue(__LINE__,o,v)
3149 static void _test_input_put_defaultValue(unsigned line, IUnknown *unk, const char *val)
3150 {
3151 IHTMLInputElement *input;
3152 BSTR str;
3153 HRESULT hres;
3154
3155 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3156 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3157 if(FAILED(hres))
3158 return;
3159
3160 str = a2bstr(val);
3161 hres = IHTMLInputElement_put_defaultValue(input, str);
3162 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3163 SysFreeString(str);
3164 IHTMLInputElement_Release(input);
3165
3166 _test_input_defaultValue(line, unk, val);
3167 }
3168
3169 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
3170 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
3171 {
3172 BSTR src;
3173 HRESULT hres;
3174
3175 hres = IHTMLInputElement_get_src(input, &src);
3176 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
3177 if(exsrc)
3178 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
3179 else
3180 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
3181 SysFreeString(src);
3182 }
3183
3184 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
3185 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
3186 {
3187 BSTR tmp;
3188 HRESULT hres;
3189
3190 tmp = a2bstr(src);
3191 hres = IHTMLInputElement_put_src(input, tmp);
3192 SysFreeString(tmp);
3193 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
3194
3195 _test_input_src(line, input, src);
3196 }
3197
3198 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
3199 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
3200 {
3201 IHTMLElement *elem = _get_elem_iface(line, unk);
3202 BSTR class = (void*)0xdeadbeef;
3203 HRESULT hres;
3204
3205 hres = IHTMLElement_get_className(elem, &class);
3206 IHTMLElement_Release(elem);
3207 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
3208 if(exclass)
3209 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
3210 else
3211 ok_(__FILE__,line) (!class, "class != NULL\n");
3212 SysFreeString(class);
3213 }
3214
3215 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
3216 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
3217 {
3218 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3219 short index = -3;
3220 HRESULT hres;
3221
3222 hres = IHTMLElement2_get_tabIndex(elem2, &index);
3223 IHTMLElement2_Release(elem2);
3224 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3225 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
3226 }
3227
3228 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
3229 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
3230 {
3231 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3232 HRESULT hres;
3233
3234 hres = IHTMLElement2_put_tabIndex(elem2, index);
3235 IHTMLElement2_Release(elem2);
3236 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3237
3238 _test_elem_tabindex(line, unk, index);
3239 }
3240
3241 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
3242 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
3243 {
3244 IHTMLStyleElement *style = _get_style_iface(line, unk);
3245 BSTR media;
3246 HRESULT hres;
3247
3248 hres = IHTMLStyleElement_get_media(style, &media);
3249 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
3250 if(exmedia)
3251 ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
3252 else
3253 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
3254
3255 IHTMLStyleElement_Release(style);
3256 SysFreeString(media);
3257 }
3258
3259 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
3260 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
3261 {
3262 IHTMLStyleElement *style = _get_style_iface(line, unk);
3263 BSTR str;
3264 HRESULT hres;
3265
3266 str = a2bstr(media);
3267 hres = IHTMLStyleElement_put_media(style, str);
3268 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
3269 IHTMLStyleElement_Release(style);
3270 SysFreeString(str);
3271
3272 _test_style_media(line, unk, media);
3273 }
3274
3275 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
3276 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
3277 {
3278 IHTMLStyleElement *style = _get_style_iface(line, unk);
3279 BSTR type;
3280 HRESULT hres;
3281
3282 hres = IHTMLStyleElement_get_type(style, &type);
3283 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
3284 if(extype)
3285 ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
3286 else
3287 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
3288
3289 IHTMLStyleElement_Release(style);
3290 SysFreeString(type);
3291 }
3292
3293 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
3294 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
3295 {
3296 IHTMLStyleElement *style = _get_style_iface(line, unk);
3297 BSTR str;
3298 HRESULT hres;
3299
3300 str = a2bstr(type);
3301 hres = IHTMLStyleElement_put_type(style, str);
3302 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
3303 IHTMLStyleElement_Release(style);
3304 SysFreeString(str);
3305
3306 _test_style_type(line, unk, type);
3307 }
3308
3309 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
3310 static void _test_elem_filters(unsigned line, IUnknown *unk)
3311 {
3312 IHTMLElement *elem = _get_elem_iface(line, unk);
3313 HRESULT hres;
3314 IHTMLFiltersCollection *filters;
3315
3316 hres = IHTMLElement_get_filters(elem, &filters);
3317 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
3318 "get_filters failed: %08x\n", hres);
3319 if(hres == S_OK)
3320 {
3321 LONG len;
3322 IDispatchEx *dispex;
3323
3324 hres = IHTMLFiltersCollection_get_length(filters, &len);
3325 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
3326 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
3327
3328 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
3329 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
3330 "Could not get IDispatchEx interface: %08x\n", hres);
3331 if(SUCCEEDED(hres)) {
3332 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
3333 IDispatchEx_Release(dispex);
3334 }
3335
3336 IHTMLFiltersCollection_Release(filters);
3337 }
3338
3339 IHTMLElement_Release(elem);
3340 }
3341
3342 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
3343 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
3344 {
3345 IHTMLElement *elem = _get_elem_iface(line, unk);
3346 BSTR tmp;
3347 HRESULT hres;
3348
3349 tmp = class ? a2bstr(class) : NULL;
3350 hres = IHTMLElement_put_className(elem, tmp);
3351 IHTMLElement_Release(elem);
3352 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
3353 SysFreeString(tmp);
3354
3355 _test_elem_class(line, unk, class);
3356 }
3357
3358 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
3359 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
3360 {
3361