[MSHTML_WINETEST]
[reactos.git] / rostests / winetests / mshtml / dom.c
1 /*
2 * Copyright 2007-2008 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
36 static const char doc_blank[] = "<html></html>";
37 static const char doc_str1[] = "<html><body>test</body></html>";
38 static const char range_test_str[] =
39 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
40 static const char range_test2_str[] =
41 "<html><body>abc<hr />123<br /><hr />def</body></html>";
42 static const char elem_test_str[] =
43 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
44 "<body onload=\"Testing()\">text test<!-- a comment -->"
45 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
46 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
47 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
48 "<textarea id=\"X\">text text</textarea>"
49 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
50 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
51 "<test />"
52 "<img id=\"imgid\" name=\"WineImg\"/>"
53 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
54 "<form id=\"frm\"></form>"
55 "</body></html>";
56 static const char elem_test2_str[] =
57 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
58 "<body><div id=\"divid\"></div></body>"
59 "</html>";
60
61 static const char indent_test_str[] =
62 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
63 static const char cond_comment_str[] =
64 "<html><head><title>test</title></head><body>"
65 "<!--[if gte IE 4]> <br> <![endif]-->"
66 "</body></html>";
67 static const char frameset_str[] =
68 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
69 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
70 "<frame src=\"about:blank\" id=\"fr3\">"
71 "</frameset></html>";
72
73 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
74 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
75 static WCHAR wordW[] = {'w','o','r','d',0};
76
77 typedef enum {
78 ET_NONE,
79 ET_HTML,
80 ET_HEAD,
81 ET_TITLE,
82 ET_BODY,
83 ET_A,
84 ET_INPUT,
85 ET_SELECT,
86 ET_TEXTAREA,
87 ET_OPTION,
88 ET_STYLE,
89 ET_BLOCKQUOTE,
90 ET_P,
91 ET_BR,
92 ET_TABLE,
93 ET_TBODY,
94 ET_SCRIPT,
95 ET_TEST,
96 ET_TESTG,
97 ET_COMMENT,
98 ET_IMG,
99 ET_TR,
100 ET_TD,
101 ET_IFRAME,
102 ET_FORM,
103 ET_FRAME
104 } elem_type_t;
105
106 static const IID * const none_iids[] = {
107 &IID_IUnknown,
108 NULL
109 };
110
111 static const IID * const doc_node_iids[] = {
112 &IID_IHTMLDOMNode,
113 &IID_IHTMLDOMNode2,
114 &IID_IHTMLDocument,
115 &IID_IHTMLDocument2,
116 &IID_IHTMLDocument3,
117 &IID_IHTMLDocument4,
118 &IID_IHTMLDocument5,
119 &IID_IDispatchEx,
120 &IID_IConnectionPointContainer,
121 &IID_IInternetHostSecurityManager,
122 NULL
123 };
124
125 static const IID * const doc_obj_iids[] = {
126 &IID_IHTMLDocument,
127 &IID_IHTMLDocument2,
128 &IID_IHTMLDocument3,
129 &IID_IHTMLDocument4,
130 &IID_IHTMLDocument5,
131 &IID_IDispatchEx,
132 &IID_IConnectionPointContainer,
133 &IID_ICustomDoc,
134 NULL
135 };
136
137 static const IID * const elem_iids[] = {
138 &IID_IHTMLDOMNode,
139 &IID_IHTMLDOMNode2,
140 &IID_IHTMLElement,
141 &IID_IHTMLElement2,
142 &IID_IHTMLElement3,
143 &IID_IDispatchEx,
144 &IID_IConnectionPointContainer,
145 NULL
146 };
147
148 static const IID * const body_iids[] = {
149 &IID_IHTMLDOMNode,
150 &IID_IHTMLDOMNode2,
151 &IID_IHTMLElement,
152 &IID_IHTMLElement2,
153 &IID_IHTMLElement3,
154 &IID_IHTMLTextContainer,
155 &IID_IHTMLBodyElement,
156 &IID_IDispatchEx,
157 &IID_IConnectionPointContainer,
158 NULL
159 };
160
161 static const IID * const anchor_iids[] = {
162 &IID_IHTMLDOMNode,
163 &IID_IHTMLDOMNode2,
164 &IID_IHTMLElement,
165 &IID_IHTMLElement2,
166 &IID_IHTMLElement3,
167 &IID_IHTMLAnchorElement,
168 &IID_IDispatchEx,
169 &IID_IConnectionPointContainer,
170 NULL
171 };
172
173 static const IID * const input_iids[] = {
174 &IID_IHTMLDOMNode,
175 &IID_IHTMLDOMNode2,
176 &IID_IHTMLElement,
177 &IID_IHTMLElement2,
178 &IID_IHTMLElement3,
179 &IID_IHTMLInputElement,
180 &IID_IHTMLInputTextElement,
181 &IID_IDispatchEx,
182 &IID_IConnectionPointContainer,
183 NULL
184 };
185
186 static const IID * const select_iids[] = {
187 &IID_IHTMLDOMNode,
188 &IID_IHTMLDOMNode2,
189 &IID_IHTMLElement,
190 &IID_IHTMLElement2,
191 &IID_IHTMLElement3,
192 &IID_IHTMLSelectElement,
193 &IID_IDispatchEx,
194 &IID_IConnectionPointContainer,
195 NULL
196 };
197
198 static const IID * const textarea_iids[] = {
199 &IID_IHTMLDOMNode,
200 &IID_IHTMLDOMNode2,
201 &IID_IHTMLElement,
202 &IID_IHTMLElement2,
203 &IID_IHTMLElement3,
204 &IID_IHTMLTextAreaElement,
205 &IID_IDispatchEx,
206 &IID_IConnectionPointContainer,
207 NULL
208 };
209
210 static const IID * const option_iids[] = {
211 &IID_IHTMLDOMNode,
212 &IID_IHTMLDOMNode2,
213 &IID_IHTMLElement,
214 &IID_IHTMLElement2,
215 &IID_IHTMLElement3,
216 &IID_IHTMLOptionElement,
217 &IID_IDispatchEx,
218 &IID_IConnectionPointContainer,
219 NULL
220 };
221
222 static const IID * const table_iids[] = {
223 &IID_IHTMLDOMNode,
224 &IID_IHTMLDOMNode2,
225 &IID_IHTMLElement,
226 &IID_IHTMLElement2,
227 &IID_IHTMLElement3,
228 &IID_IHTMLTable,
229 &IID_IDispatchEx,
230 &IID_IConnectionPointContainer,
231 NULL
232 };
233
234 static const IID * const script_iids[] = {
235 &IID_IHTMLDOMNode,
236 &IID_IHTMLDOMNode2,
237 &IID_IHTMLElement,
238 &IID_IHTMLElement2,
239 &IID_IHTMLElement3,
240 &IID_IHTMLScriptElement,
241 &IID_IDispatchEx,
242 &IID_IConnectionPointContainer,
243 NULL
244 };
245
246 static const IID * const text_iids[] = {
247 &IID_IHTMLDOMNode,
248 &IID_IHTMLDOMNode2,
249 &IID_IHTMLDOMTextNode,
250 NULL
251 };
252
253 static const IID * const location_iids[] = {
254 &IID_IDispatch,
255 &IID_IHTMLLocation,
256 NULL
257 };
258
259 static const IID * const window_iids[] = {
260 &IID_IDispatch,
261 &IID_IHTMLWindow2,
262 &IID_IHTMLWindow3,
263 &IID_IDispatchEx,
264 NULL
265 };
266
267 static const IID * const comment_iids[] = {
268 &IID_IHTMLDOMNode,
269 &IID_IHTMLDOMNode2,
270 &IID_IHTMLElement,
271 &IID_IHTMLElement2,
272 &IID_IHTMLElement3,
273 &IID_IHTMLCommentElement,
274 &IID_IDispatchEx,
275 &IID_IConnectionPointContainer,
276 NULL
277 };
278
279 static const IID * const img_iids[] = {
280 &IID_IHTMLDOMNode,
281 &IID_IHTMLDOMNode2,
282 &IID_IHTMLElement,
283 &IID_IHTMLElement2,
284 &IID_IHTMLElement3,
285 &IID_IDispatchEx,
286 &IID_IHTMLImgElement,
287 &IID_IConnectionPointContainer,
288 NULL
289 };
290
291 static const IID * const tr_iids[] = {
292 &IID_IHTMLDOMNode,
293 &IID_IHTMLDOMNode2,
294 &IID_IHTMLElement,
295 &IID_IHTMLElement2,
296 &IID_IHTMLElement3,
297 &IID_IDispatchEx,
298 &IID_IHTMLTableRow,
299 &IID_IConnectionPointContainer,
300 NULL
301 };
302
303 static const IID * const td_iids[] = {
304 &IID_IHTMLDOMNode,
305 &IID_IHTMLDOMNode2,
306 &IID_IHTMLElement,
307 &IID_IHTMLElement2,
308 &IID_IHTMLElement3,
309 &IID_IDispatchEx,
310 &IID_IConnectionPointContainer,
311 NULL
312 };
313
314 static const IID * const frame_iids[] = {
315 &IID_IHTMLDOMNode,
316 &IID_IHTMLDOMNode2,
317 &IID_IHTMLElement,
318 &IID_IHTMLElement2,
319 &IID_IHTMLElement3,
320 &IID_IHTMLFrameBase,
321 &IID_IHTMLFrameBase2,
322 &IID_IDispatchEx,
323 &IID_IConnectionPointContainer,
324 NULL
325 };
326
327 static const IID * const iframe_iids[] = {
328 &IID_IHTMLDOMNode,
329 &IID_IHTMLDOMNode2,
330 &IID_IHTMLElement,
331 &IID_IHTMLElement2,
332 &IID_IHTMLElement3,
333 &IID_IHTMLFrameBase,
334 &IID_IHTMLFrameBase2,
335 &IID_IHTMLIFrameElement,
336 &IID_IDispatchEx,
337 &IID_IConnectionPointContainer,
338 NULL
339 };
340
341 static const IID * const form_iids[] = {
342 &IID_IHTMLDOMNode,
343 &IID_IHTMLDOMNode2,
344 &IID_IHTMLElement,
345 &IID_IHTMLElement2,
346 &IID_IHTMLElement3,
347 &IID_IHTMLFormElement,
348 &IID_IDispatchEx,
349 &IID_IConnectionPointContainer,
350 NULL
351 };
352
353 static const IID * const generic_iids[] = {
354 &IID_IHTMLDOMNode,
355 &IID_IHTMLDOMNode2,
356 &IID_IHTMLElement,
357 &IID_IHTMLElement2,
358 &IID_IHTMLElement3,
359 &IID_IHTMLGenericElement,
360 &IID_IDispatchEx,
361 &IID_IConnectionPointContainer,
362 NULL
363 };
364
365 static const IID * const style_iids[] = {
366 &IID_IUnknown,
367 &IID_IDispatch,
368 &IID_IDispatchEx,
369 &IID_IHTMLStyle,
370 &IID_IHTMLStyle2,
371 &IID_IHTMLStyle3,
372 &IID_IHTMLStyle4,
373 NULL
374 };
375
376 static const IID * const cstyle_iids[] = {
377 &IID_IUnknown,
378 &IID_IDispatch,
379 &IID_IDispatchEx,
380 &IID_IHTMLCurrentStyle,
381 NULL
382 };
383
384 static const IID * const img_factory_iids[] = {
385 &IID_IUnknown,
386 &IID_IDispatch,
387 &IID_IDispatchEx,
388 &IID_IHTMLImageElementFactory,
389 NULL
390 };
391
392 typedef struct {
393 const char *tag;
394 REFIID *iids;
395 const IID *dispiid;
396 } elem_type_info_t;
397
398 static const elem_type_info_t elem_type_infos[] = {
399 {"", none_iids, NULL},
400 {"HTML", elem_iids, NULL},
401 {"HEAD", elem_iids, NULL},
402 {"TITLE", elem_iids, NULL},
403 {"BODY", body_iids, &DIID_DispHTMLBody},
404 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
405 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
406 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
407 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
408 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
409 {"STYLE", elem_iids, NULL},
410 {"BLOCKQUOTE",elem_iids, NULL},
411 {"P", elem_iids, NULL},
412 {"BR", elem_iids, NULL},
413 {"TABLE", table_iids, &DIID_DispHTMLTable},
414 {"TBODY", elem_iids, NULL},
415 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
416 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
417 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
418 {"!", comment_iids, &DIID_DispHTMLCommentElement},
419 {"IMG", img_iids, &DIID_DispHTMLImg},
420 {"TR", tr_iids, &DIID_DispHTMLTableRow},
421 {"TD", td_iids, NULL},
422 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
423 {"FORM", form_iids, &DIID_DispHTMLFormElement},
424 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement}
425 };
426
427 static const char *dbgstr_guid(REFIID riid)
428 {
429 static char buf[50];
430
431 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
432 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
433 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
434 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
435
436 return buf;
437 }
438
439 static int strcmp_wa(LPCWSTR strw, const char *stra)
440 {
441 CHAR buf[512];
442 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
443 return lstrcmpA(stra, buf);
444 }
445
446 static BSTR a2bstr(const char *str)
447 {
448 BSTR ret;
449 int len;
450
451 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
452 ret = SysAllocStringLen(NULL, len);
453 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
454
455 return ret;
456 }
457
458 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
459 {
460 IUnknown *unk1, *unk2;
461
462 if(iface1 == iface2)
463 return TRUE;
464
465 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
466 IUnknown_Release(unk1);
467 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
468 IUnknown_Release(unk2);
469
470 return unk1 == unk2;
471 }
472
473 static IHTMLDocument2 *create_document(void)
474 {
475 IHTMLDocument2 *doc;
476 IHTMLDocument5 *doc5;
477 HRESULT hres;
478
479 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
480 &IID_IHTMLDocument2, (void**)&doc);
481 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
482 if(FAILED(hres))
483 return NULL;
484
485 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
486 if(FAILED(hres)) {
487 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
488 IHTMLDocument2_Release(doc);
489 return NULL;
490 }
491
492 IHTMLDocument5_Release(doc5);
493 return doc;
494 }
495
496 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
497 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
498 {
499 const IID * const *piid;
500 IUnknown *unk;
501 HRESULT hres;
502
503 for(piid = iids; *piid; piid++) {
504 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
505 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
506 if(SUCCEEDED(hres))
507 IUnknown_Release(unk);
508 }
509 }
510
511 #define test_get_dispid(u,id) _test_disp(__LINE__,u,id)
512 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
513 {
514 IDispatchEx *dispex;
515 ITypeInfo *typeinfo;
516 BOOL ret = FALSE;
517 UINT ticnt;
518 HRESULT hres;
519
520 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
521 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
522 if(FAILED(hres))
523 return FALSE;
524
525 ticnt = 0xdeadbeef;
526 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
527 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
528 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
529
530 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
531 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
532
533 if(SUCCEEDED(hres)) {
534 TYPEATTR *type_attr;
535
536 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
537 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
538 if(hres == S_OK) {
539 *iid = type_attr->guid;
540 ret = TRUE;
541 }
542
543 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
544 ITypeInfo_Release(typeinfo);
545 }
546
547 IDispatchEx_Release(dispex);
548 return ret;
549 }
550
551 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
552 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
553 {
554 DISPPARAMS dp = {NULL,NULL,0,0};
555 IDispatchEx *dispex;
556 EXCEPINFO ei;
557 VARIANT var;
558 HRESULT hres;
559
560 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
561 ok_(__FILE__,line)(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
562 if(FAILED(hres))
563 return;
564
565 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
566 IDispatchEx_Release(dispex);
567 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
568
569 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
570 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
571 VariantClear(&var);
572 }
573
574 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
575 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
576 {
577 IID iid;
578
579 if(_test_get_dispid(line, unk, &iid))
580 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
581
582 if(val)
583 _test_disp_value(line, unk, val);
584 }
585
586 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
587 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
588 {
589 IID iid;
590
591 if(_test_get_dispid(line, unk, &iid))
592 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
593 "unexpected guid %s\n", dbgstr_guid(&iid));
594
595 if(val)
596 _test_disp_value(line, unk, val);
597 }
598
599 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
600 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
601 {
602 IHTMLElement *elem;
603 HRESULT hres;
604
605 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
606 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
607 return elem;
608 }
609
610 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
611 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
612 {
613 IHTMLElement2 *elem;
614 HRESULT hres;
615
616 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
617 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
618 return elem;
619 }
620
621 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
622 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
623 {
624 IHTMLElement3 *elem;
625 HRESULT hres;
626
627 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
628 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
629 return elem;
630 }
631
632 #define get_node_iface(u) _get_node_iface(__LINE__,u)
633 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
634 {
635 IHTMLDOMNode *node;
636 HRESULT hres;
637
638 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
639 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
640 return node;
641 }
642
643 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
644 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
645 {
646 IHTMLDOMNode2 *node;
647 HRESULT hres;
648
649 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
650 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
651 return node;
652 }
653
654 #define get_img_iface(u) _get_img_iface(__LINE__,u)
655 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
656 {
657 IHTMLImgElement *img;
658 HRESULT hres;
659
660 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
661 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
662 return img;
663 }
664
665 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
666 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
667 {
668 IHTMLAnchorElement *anchor;
669 HRESULT hres;
670
671 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
672 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
673 return anchor;
674 }
675
676 #define get_text_iface(u) _get_text_iface(__LINE__,u)
677 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
678 {
679 IHTMLDOMTextNode *text;
680 HRESULT hres;
681
682 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
683 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
684 return text;
685 }
686
687 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
688 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
689 {
690 IHTMLCommentElement *comment;
691 HRESULT hres;
692
693 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
694 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
695 return comment;
696 }
697
698 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
699 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
700 {
701 IHTMLDOMNode *node = _get_node_iface(line, unk);
702 BSTR name;
703 HRESULT hres;
704
705 hres = IHTMLDOMNode_get_nodeName(node, &name);
706 IHTMLDOMNode_Release(node);
707 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
708 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
709
710 SysFreeString(name);
711 }
712
713 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
714 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
715 {
716 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
717 IDispatch *disp = (void*)0xdeadbeef;
718 IHTMLDocument2 *doc = NULL;
719 HRESULT hres;
720
721 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
722 IHTMLDOMNode2_Release(node);
723 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
724
725 if(disp) {
726 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
727 IDispatch_Release(disp);
728 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
729 }
730
731 return doc;
732 }
733
734 #define get_doc_window(d) _get_doc_window(__LINE__,d)
735 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
736 {
737 IHTMLWindow2 *window;
738 HRESULT hres;
739
740 window = NULL;
741 hres = IHTMLDocument2_get_parentWindow(doc, &window);
742 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
743 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
744
745 return window;
746 }
747
748 #define clone_node(n,d) _clone_node(__LINE__,n,d)
749 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
750 {
751 IHTMLDOMNode *node = _get_node_iface(line, unk);
752 IHTMLDOMNode *ret = NULL;
753 HRESULT hres;
754
755 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
756 IHTMLDOMNode_Release(node);
757 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
758 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
759
760 return ret;
761
762 }
763
764 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
765 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
766 {
767 IHTMLElement *elem = _get_elem_iface(line, unk);
768 BSTR tag;
769 HRESULT hres;
770
771 hres = IHTMLElement_get_tagName(elem, &tag);
772 IHTMLElement_Release(elem);
773 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
774 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
775
776 SysFreeString(tag);
777 }
778
779 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
780 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
781 {
782 _test_elem_tag(line, unk, elem_type_infos[type].tag);
783 _test_ifaces(line, unk, elem_type_infos[type].iids);
784
785 if(elem_type_infos[type].dispiid && type != ET_A)
786 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
787 }
788
789 #define get_node_type(n) _get_node_type(__LINE__,n)
790 static LONG _get_node_type(unsigned line, IUnknown *unk)
791 {
792 IHTMLDOMNode *node = _get_node_iface(line, unk);
793 LONG type = -1;
794 HRESULT hres;
795
796 hres = IHTMLDOMNode_get_nodeType(node, &type);
797 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
798
799 IHTMLDOMNode_Release(node);
800
801 return type;
802 }
803
804 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
805 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
806 {
807 IHTMLDOMNode *node = _get_node_iface(line, unk);
808 IHTMLDOMChildrenCollection *col = NULL;
809 IDispatch *disp;
810 HRESULT hres;
811
812 hres = IHTMLDOMNode_get_childNodes(node, &disp);
813 IHTMLDOMNode_Release(node);
814 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
815 if(FAILED(hres))
816 return NULL;
817
818 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
819 IDispatch_Release(disp);
820 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
821
822 return col;
823 }
824
825 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
826 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
827 {
828 IHTMLDOMNode *node = NULL;
829 IDispatch *disp;
830 HRESULT hres;
831
832 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
833 ok(hres == S_OK, "item failed: %08x\n", hres);
834
835 node = _get_node_iface(line, (IUnknown*)disp);
836 IDispatch_Release(disp);
837
838 return node;
839 }
840
841 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
842 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
843 {
844 VARIANT value;
845 BSTR tmp;
846 HRESULT hres;
847
848 VariantInit(&value);
849
850 tmp = a2bstr(name);
851 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
852 SysFreeString(tmp);
853 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
854
855 if(exval) {
856 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
857 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
858 }else {
859 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
860 }
861
862 VariantClear(&value);
863 }
864
865 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
866 static void _test_elem_offset(unsigned line, IUnknown *unk)
867 {
868 IHTMLElement *elem = _get_elem_iface(line, unk);
869 LONG l;
870 HRESULT hres;
871
872 hres = IHTMLElement_get_offsetTop(elem, &l);
873 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
874
875 hres = IHTMLElement_get_offsetHeight(elem, &l);
876 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
877
878 hres = IHTMLElement_get_offsetWidth(elem, &l);
879 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
880
881 IHTMLElement_Release(elem);
882 }
883
884 #define get_doc_node(d) _get_doc_node(__LINE__,d)
885 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
886 {
887 IHTMLWindow2 *window;
888 IHTMLDocument2 *ret;
889 HRESULT hres;
890
891 hres = IHTMLDocument2_get_parentWindow(doc, &window);
892 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
893
894 hres = IHTMLWindow2_get_document(window, &ret);
895 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
896 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
897
898 return ret;
899 }
900
901 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
902 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
903 {
904 BSTR name;
905 HRESULT hres;
906
907 hres = IHTMLWindow2_get_name(window, &name);
908 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
909 if(exname)
910 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
911 else
912 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
913 }
914
915 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
916 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
917 {
918 BSTR str;
919 HRESULT hres;
920
921 str = a2bstr(name);
922 hres = IHTMLWindow2_put_name(window, str);
923 SysFreeString(str);
924 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
925
926 _test_window_name(line, window, name);
927 }
928
929 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
930 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
931 {
932 LONG length = -1;
933 HRESULT hres;
934
935 hres = IHTMLWindow2_get_length(window, &length);
936 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
937 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
938 }
939
940 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
941 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
942 {
943 IHTMLFrameBase2 *base2;
944 IHTMLWindow2 *window;
945 HRESULT hres;
946
947 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
948 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
949
950 window = NULL;
951 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
952 IHTMLFrameBase2_Release(base2);
953 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
954 ok(window != NULL, "contentWindow = NULL\n");
955
956 return window;
957 }
958
959 static void test_get_set_attr(IHTMLDocument2 *doc)
960 {
961 IHTMLElement *elem;
962 IHTMLDocument3 *doc3;
963 HRESULT hres;
964 BSTR bstr;
965 VARIANT val;
966
967 /* grab an element to test with */
968 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
969 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
970
971 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
972 IHTMLDocument3_Release(doc3);
973 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
974
975 /* get a non-present attribute */
976 bstr = a2bstr("notAnAttribute");
977 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
978 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
979 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
980 VariantClear(&val);
981 SysFreeString(bstr);
982
983 /* get a present attribute */
984 bstr = a2bstr("scrollHeight");
985 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
986 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
987 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
988 VariantClear(&val);
989 SysFreeString(bstr);
990
991 /* create a new BSTR attribute */
992 bstr = a2bstr("newAttribute");
993
994 V_VT(&val) = VT_BSTR;
995 V_BSTR(&val) = a2bstr("the value");
996 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
997 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
998 VariantClear(&val);
999
1000 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1001 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1002 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1003 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)));
1004 VariantClear(&val);
1005
1006 /* overwrite the attribute with a BOOL */
1007 V_VT(&val) = VT_BOOL;
1008 V_BOOL(&val) = VARIANT_TRUE;
1009 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1010 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1011 VariantClear(&val);
1012
1013 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1014 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1015 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1016 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1017 VariantClear(&val);
1018
1019 SysFreeString(bstr);
1020
1021 /* case-insensitive */
1022 bstr = a2bstr("newattribute");
1023 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1024 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1025 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1026 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1027 VariantClear(&val);
1028 SysFreeString(bstr);
1029
1030 IHTMLElement_Release(elem);
1031 }
1032
1033 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1034 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1035 {
1036 IHTMLElement *elem;
1037 IHTMLDocument3 *doc3;
1038 HRESULT hres;
1039
1040 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1041 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1042 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1043 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1044 IHTMLDocument3_Release(doc3);
1045
1046 return elem;
1047 }
1048
1049 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1050 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1051 {
1052 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1053 BSTR str;
1054 HRESULT hres;
1055
1056 hres = IHTMLAnchorElement_get_href(anchor, &str);
1057 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1058 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1059 SysFreeString(str);
1060
1061 _test_disp_value(line, unk, exhref);
1062 }
1063
1064 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1065 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1066 {
1067 BSTR bstr;
1068 HRESULT hres;
1069
1070 hres = IHTMLOptionElement_get_text(option, &bstr);
1071 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1072 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1073 SysFreeString(bstr);
1074 }
1075
1076 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1077 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1078 {
1079 BSTR bstr;
1080 HRESULT hres;
1081
1082 bstr = a2bstr(text);
1083 hres = IHTMLOptionElement_put_text(option, bstr);
1084 SysFreeString(bstr);
1085 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1086
1087 _test_option_text(line, option, text);
1088 }
1089
1090 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1091 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1092 {
1093 BSTR bstr;
1094 HRESULT hres;
1095
1096 hres = IHTMLOptionElement_get_value(option, &bstr);
1097 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1098 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1099 SysFreeString(bstr);
1100 }
1101
1102 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1103 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1104 {
1105 BSTR bstr;
1106 HRESULT hres;
1107
1108 bstr = a2bstr(value);
1109 hres = IHTMLOptionElement_put_value(option, bstr);
1110 SysFreeString(bstr);
1111 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1112
1113 _test_option_value(line, option, value);
1114 }
1115
1116 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1117 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1118 {
1119 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1120 BSTR text;
1121 HRESULT hres;
1122
1123 text = a2bstr(extext);
1124 hres = IHTMLCommentElement_get_text(comment, &text);
1125 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1126 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1127
1128 IHTMLCommentElement_Release(comment);
1129 SysFreeString(text);
1130 }
1131
1132 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1133 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1134 const char *txt, const char *val)
1135 {
1136 IHTMLOptionElementFactory *factory;
1137 IHTMLOptionElement *option;
1138 IHTMLWindow2 *window;
1139 VARIANT text, value, empty;
1140 HRESULT hres;
1141
1142 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1143 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1144
1145 hres = IHTMLWindow2_get_Option(window, &factory);
1146 IHTMLWindow2_Release(window);
1147 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1148
1149 V_VT(&text) = VT_BSTR;
1150 V_BSTR(&text) = a2bstr(txt);
1151 V_VT(&value) = VT_BSTR;
1152 V_BSTR(&value) = a2bstr(val);
1153 V_VT(&empty) = VT_EMPTY;
1154
1155 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1156 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1157
1158 IHTMLOptionElementFactory_Release(factory);
1159 VariantClear(&text);
1160 VariantClear(&value);
1161
1162 _test_option_text(line, option, txt);
1163 _test_option_value(line, option, val);
1164
1165 return option;
1166 }
1167
1168 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1169 static void _test_img_width(unsigned line, IHTMLImgElement *img, const long exp)
1170 {
1171 LONG found = -1;
1172 HRESULT hres;
1173
1174 hres = IHTMLImgElement_get_width(img, &found);
1175 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1176 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1177 }
1178
1179 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1180 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const long width)
1181 {
1182 HRESULT hres;
1183
1184 hres = IHTMLImgElement_put_width(img, width);
1185 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1186
1187 _test_img_width(line, img, width);
1188 }
1189
1190 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1191 static void _test_img_height(unsigned line, IHTMLImgElement *img, const long exp)
1192 {
1193 LONG found = -1;
1194 HRESULT hres;
1195
1196 hres = IHTMLImgElement_get_height(img, &found);
1197 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1198 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1199 }
1200
1201 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1202 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const long height)
1203 {
1204 HRESULT hres;
1205
1206 hres = IHTMLImgElement_put_height(img, height);
1207 ok(hres == S_OK, "put_height failed: %08x\n", hres);
1208
1209 _test_img_height(line, img, height);
1210 }
1211
1212 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1213 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1214 LONG wdth, LONG hght)
1215 {
1216 IHTMLImageElementFactory *factory;
1217 IHTMLImgElement *img;
1218 IHTMLWindow2 *window;
1219 VARIANT width, height;
1220 char buf[16];
1221 HRESULT hres;
1222
1223 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1224 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1225
1226 hres = IHTMLWindow2_get_Image(window, &factory);
1227 IHTMLWindow2_Release(window);
1228 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1229
1230 test_ifaces((IUnknown*)factory, img_factory_iids);
1231 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1232
1233 if(wdth >= 0){
1234 snprintf(buf, 16, "%d", wdth);
1235 V_VT(&width) = VT_BSTR;
1236 V_BSTR(&width) = a2bstr(buf);
1237 }else{
1238 V_VT(&width) = VT_EMPTY;
1239 wdth = 0;
1240 }
1241
1242 if(hght >= 0){
1243 snprintf(buf, 16, "%d", hght);
1244 V_VT(&height) = VT_BSTR;
1245 V_BSTR(&height) = a2bstr(buf);
1246 }else{
1247 V_VT(&height) = VT_EMPTY;
1248 hght = 0;
1249 }
1250
1251 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1252 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1253
1254 IHTMLImageElementFactory_Release(factory);
1255 VariantClear(&width);
1256 VariantClear(&height);
1257
1258 if(SUCCEEDED(hres)) {
1259 _test_img_width(line, img, wdth);
1260 _test_img_height(line, img, hght);
1261 return img;
1262 }
1263
1264 return NULL;
1265 }
1266
1267 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1268 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1269 {
1270 LONG len = 0xdeadbeef;
1271 HRESULT hres;
1272
1273 hres = IHTMLSelectElement_get_length(select, &len);
1274 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1275 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1276 }
1277
1278 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1279 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1280 {
1281 LONG idx = 0xdeadbeef;
1282 HRESULT hres;
1283
1284 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1285 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1286 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1287 }
1288
1289 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1290 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1291 {
1292 HRESULT hres;
1293
1294 hres = IHTMLSelectElement_put_selectedIndex(select, index);
1295 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1296 _test_select_selidx(line, select, index);
1297 }
1298
1299 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1300 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1301 {
1302 BSTR val;
1303 HRESULT hres;
1304
1305 hres = IHTMLSelectElement_get_value(select, &val);
1306 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1307 if(exval)
1308 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1309 else
1310 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1311 }
1312
1313 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1314 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1315 {
1316 BSTR bstr;
1317 HRESULT hres;
1318
1319 bstr = a2bstr(val);
1320 hres = IHTMLSelectElement_put_value(select, bstr);
1321 SysFreeString(bstr);
1322 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1323 }
1324
1325 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1326 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1327 {
1328 BSTR type;
1329 HRESULT hres;
1330
1331 hres = IHTMLSelectElement_get_type(select, &type);
1332 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1333 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1334 }
1335
1336 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1337 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1338 {
1339 BSTR text;
1340 HRESULT hres;
1341
1342 hres = IHTMLTxtRange_get_text(range, &text);
1343 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1344
1345 if(extext) {
1346 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1347 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1348 }else {
1349 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1350 }
1351
1352 SysFreeString(text);
1353
1354 }
1355
1356 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1357 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1358 {
1359 HRESULT hres;
1360
1361 hres = IHTMLTxtRange_collapse(range, b);
1362 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1363 _test_range_text(line, range, NULL);
1364 }
1365
1366 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1367 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1368 VARIANT_BOOL exb, const char *extext)
1369 {
1370 VARIANT_BOOL b = 0xe0e0;
1371 HRESULT hres;
1372
1373 hres = IHTMLTxtRange_expand(range, unit, &b);
1374 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1375 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1376 _test_range_text(line, range, extext);
1377 }
1378
1379 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1380 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1381 {
1382 LONG c = 0xdeadbeef;
1383 HRESULT hres;
1384
1385 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1386 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1387 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1388 _test_range_text(line, range, NULL);
1389 }
1390
1391 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1392 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1393 LPWSTR unit, LONG cnt, LONG excnt)
1394 {
1395 LONG c = 0xdeadbeef;
1396 HRESULT hres;
1397
1398 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1399 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1400 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1401 }
1402
1403 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1404 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1405 {
1406 LONG c = 0xdeadbeef;
1407 HRESULT hres;
1408
1409 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1410 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1411 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1412 }
1413
1414 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1415 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1416 {
1417 HRESULT hres;
1418 BSTR bstr = a2bstr(text);
1419
1420 hres = IHTMLTxtRange_put_text(range, bstr);
1421 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1422 SysFreeString(bstr);
1423 _test_range_text(line, range, NULL);
1424 }
1425
1426 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1427 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1428 {
1429 VARIANT_BOOL b;
1430 HRESULT hres;
1431
1432 b = 0xe0e0;
1433 hres = IHTMLTxtRange_inRange(range1, range2, &b);
1434 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1435 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1436 }
1437
1438 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1439 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1440 {
1441 VARIANT_BOOL b;
1442 HRESULT hres;
1443
1444 b = 0xe0e0;
1445 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1446 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1447 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1448
1449 b = 0xe0e0;
1450 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1451 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1452 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1453
1454 if(exb) {
1455 test_range_inrange(range1, range2, VARIANT_TRUE);
1456 test_range_inrange(range2, range1, VARIANT_TRUE);
1457 }
1458 }
1459
1460 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1461 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1462 {
1463 IHTMLElement *elem;
1464 HRESULT hres;
1465
1466 hres = IHTMLTxtRange_parentElement(range, &elem);
1467 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1468
1469 _test_elem_type(line, (IUnknown*)elem, type);
1470
1471 IHTMLElement_Release(elem);
1472 }
1473
1474 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1475 static void _test_elem_collection(unsigned line, IUnknown *unk,
1476 const elem_type_t *elem_types, LONG exlen)
1477 {
1478 IHTMLElementCollection *col;
1479 LONG len;
1480 DWORD i;
1481 VARIANT name, index;
1482 IDispatch *disp, *disp2;
1483 HRESULT hres;
1484
1485 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1486 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1487
1488 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1489
1490 hres = IHTMLElementCollection_get_length(col, &len);
1491 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1492 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1493
1494 if(len > exlen)
1495 len = exlen;
1496
1497 V_VT(&index) = VT_EMPTY;
1498
1499 for(i=0; i<len; i++) {
1500 V_VT(&name) = VT_I4;
1501 V_I4(&name) = i;
1502 disp = (void*)0xdeadbeef;
1503 hres = IHTMLElementCollection_item(col, name, index, &disp);
1504 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1505 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1506 if(FAILED(hres) || !disp)
1507 continue;
1508
1509 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1510
1511 if(!i) {
1512 V_VT(&name) = VT_UINT;
1513 V_I4(&name) = 0;
1514 disp2 = (void*)0xdeadbeef;
1515 hres = IHTMLElementCollection_item(col, name, index, &disp2);
1516 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1517 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1518 if(disp2)
1519 IDispatch_Release(disp2);
1520 }
1521
1522 IDispatch_Release(disp);
1523 }
1524
1525 V_VT(&name) = VT_I4;
1526 V_I4(&name) = len;
1527 disp = (void*)0xdeadbeef;
1528 hres = IHTMLElementCollection_item(col, name, index, &disp);
1529 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1530 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1531
1532 V_VT(&name) = VT_I4;
1533 V_I4(&name) = -1;
1534 disp = (void*)0xdeadbeef;
1535 hres = IHTMLElementCollection_item(col, name, index, &disp);
1536 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1537 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1538
1539 IHTMLElementCollection_Release(col);
1540 }
1541
1542 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
1543 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
1544 {
1545 IHTMLElement *elem = _get_elem_iface(line, unk);
1546 IDispatch *disp;
1547 HRESULT hres;
1548
1549 hres = IHTMLElement_get_all(elem, &disp);
1550 IHTMLElement_Release(elem);
1551 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
1552
1553 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
1554 IDispatch_Release(disp);
1555 }
1556
1557 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1558 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1559 {
1560 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1561 IHTMLElementCollection *col = NULL;
1562 elem_type_t *types = NULL;
1563 BSTR tmp;
1564 int i;
1565 HRESULT hres;
1566
1567 tmp = a2bstr(elem_type_infos[type].tag);
1568 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1569 SysFreeString(tmp);
1570 IHTMLElement2_Release(elem);
1571 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1572 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1573
1574 if(exlen) {
1575 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1576 for(i=0; i<exlen; i++)
1577 types[i] = type;
1578 }
1579
1580 _test_elem_collection(line, (IUnknown*)col, types, exlen);
1581
1582 HeapFree(GetProcessHeap(), 0, types);
1583 }
1584
1585 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1586 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1587 {
1588 BSTR text = NULL;
1589 HRESULT hres;
1590
1591 hres = IHTMLElement_get_innerText(elem, &text);
1592 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1593 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1594 wine_dbgstr_w(text), extext);
1595 SysFreeString(text);
1596 }
1597
1598 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1599 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1600 {
1601 IHTMLDOMChildrenCollection *col;
1602 BSTR str;
1603 HRESULT hres;
1604
1605 str = a2bstr(text);
1606 hres = IHTMLElement_put_innerText(elem, str);
1607 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1608 SysFreeString(str);
1609
1610 _test_elem_innertext(line, elem, text);
1611
1612
1613 col = _get_child_nodes(line, (IUnknown*)elem);
1614 ok(col != NULL, "col == NULL\n");
1615 if(col) {
1616 LONG length = 0, type;
1617 IHTMLDOMNode *node;
1618
1619 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1620 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1621 ok(length == 1, "length = %d\n", length);
1622
1623 node = _get_child_item(line, col, 0);
1624 ok(node != NULL, "node == NULL\n");
1625 if(node) {
1626 type = _get_node_type(line, (IUnknown*)node);
1627 ok(type == 3, "type=%d\n", type);
1628 IHTMLDOMNode_Release(node);
1629 }
1630
1631 IHTMLDOMChildrenCollection_Release(col);
1632 }
1633
1634 }
1635
1636 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
1637 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1638 {
1639 IHTMLElement *elem = _get_elem_iface(line, unk);
1640 BSTR html;
1641 HRESULT hres;
1642
1643 hres = IHTMLElement_get_innerHTML(elem, &html);
1644 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
1645 if(inner_html)
1646 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
1647 else
1648 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
1649
1650 IHTMLElement_Release(elem);
1651 SysFreeString(html);
1652 }
1653
1654 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
1655 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1656 {
1657 IHTMLElement *elem = _get_elem_iface(line, unk);
1658 BSTR html;
1659 HRESULT hres;
1660
1661 html = a2bstr(inner_html);
1662 hres = IHTMLElement_put_innerHTML(elem, html);
1663 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
1664
1665 IHTMLElement_Release(elem);
1666 SysFreeString(html);
1667 }
1668
1669 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
1670 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
1671 {
1672 IHTMLElement *elem = _get_elem_iface(line, unk);
1673 BSTR html;
1674 HRESULT hres;
1675
1676 html = a2bstr(outer_html);
1677 hres = IHTMLElement_put_outerHTML(elem, html);
1678 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
1679
1680 IHTMLElement_Release(elem);
1681 SysFreeString(html);
1682 }
1683
1684 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
1685 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
1686 {
1687 IHTMLElement *elem = _get_elem_iface(line, unk);
1688 BSTR html;
1689 HRESULT hres;
1690
1691 hres = IHTMLElement_get_outerHTML(elem, &html);
1692 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
1693 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
1694
1695 IHTMLElement_Release(elem);
1696 SysFreeString(html);
1697 }
1698
1699 #define get_first_child(n) _get_first_child(__LINE__,n)
1700 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1701 {
1702 IHTMLDOMNode *node = _get_node_iface(line, unk);
1703 IHTMLDOMNode *child = NULL;
1704 HRESULT hres;
1705
1706 hres = IHTMLDOMNode_get_firstChild(node, &child);
1707 IHTMLDOMNode_Release(node);
1708 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1709
1710 return child;
1711 }
1712
1713 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1714 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1715 {
1716 IHTMLDOMNode *node = _get_node_iface(line, unk);
1717 VARIANT_BOOL b = 0xdead;
1718 HRESULT hres;
1719
1720 hres = IHTMLDOMNode_hasChildNodes(node, &b);
1721 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1722 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1723
1724 IHTMLDOMNode_Release(node);
1725 }
1726
1727 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1728 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1729 {
1730 IHTMLDOMNode *node = _get_node_iface(line, unk);
1731 IHTMLDOMNode *parent;
1732 HRESULT hres;
1733
1734 hres = IHTMLDOMNode_get_parentNode(node, &parent);
1735 IHTMLDOMNode_Release(node);
1736 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1737
1738 return parent;
1739 }
1740
1741 #define node_get_next(u) _node_get_next(__LINE__,u)
1742 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
1743 {
1744 IHTMLDOMNode *node = _get_node_iface(line, unk);
1745 IHTMLDOMNode *next;
1746 HRESULT hres;
1747
1748 hres = IHTMLDOMNode_get_nextSibling(node, &next);
1749 IHTMLDOMNode_Release(node);
1750 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
1751
1752 return next;
1753 }
1754
1755 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1756 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1757 {
1758 IHTMLElement *elem = _get_elem_iface(line, unk);
1759 IHTMLElement *parent;
1760 HRESULT hres;
1761
1762 hres = IHTMLElement_get_parentElement(elem, &parent);
1763 IHTMLElement_Release(elem);
1764 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1765
1766 return parent;
1767 }
1768
1769 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1770 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1771 {
1772 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1773 VARIANT_BOOL disabled = 100;
1774 HRESULT hres;
1775
1776 if (!elem3) return;
1777 hres = IHTMLElement3_get_disabled(elem3, &disabled);
1778 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1779 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1780 IHTMLElement3_Release(elem3);
1781 }
1782
1783 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1784 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1785 {
1786 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1787 HRESULT hres;
1788
1789 if (!elem3) return;
1790 hres = IHTMLElement3_put_disabled(elem3, b);
1791 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1792
1793 IHTMLElement3_Release(elem3);
1794 _test_elem3_get_disabled(line, unk, b);
1795 }
1796
1797 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1798 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1799 {
1800 VARIANT_BOOL disabled = 100;
1801 HRESULT hres;
1802
1803 hres = IHTMLSelectElement_get_disabled(select, &disabled);
1804 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1805 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1806
1807 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1808 }
1809
1810 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
1811 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
1812 {
1813 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
1814 LONG length;
1815 HRESULT hres;
1816
1817 hres = IHTMLDOMTextNode_get_length(text, &length);
1818 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1819 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
1820 IHTMLDOMTextNode_Release(text);
1821 }
1822
1823 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1824 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1825 {
1826 HRESULT hres;
1827
1828 hres = IHTMLSelectElement_put_disabled(select, b);
1829 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1830
1831 _test_select_get_disabled(line, select, b);
1832 }
1833
1834 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1835 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
1836 {
1837 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1838 IHTMLTextContainer *txtcont;
1839 LONG l = -1, l2 = -1;
1840 HRESULT hres;
1841
1842 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1843 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1844 IHTMLElement2_Release(elem);
1845
1846 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1847 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1848
1849 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1850 IHTMLTextContainer_Release(txtcont);
1851 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
1852 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
1853
1854 return l;
1855 }
1856
1857 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1858 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
1859 {
1860 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1861 IHTMLTextContainer *txtcont;
1862 LONG l = -1, l2 = -1;
1863 HRESULT hres;
1864
1865 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1866 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1867 IHTMLElement2_Release(elem);
1868
1869 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1870 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1871
1872 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1873 IHTMLTextContainer_Release(txtcont);
1874 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
1875 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
1876
1877 return l;
1878 }
1879
1880 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1881 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
1882 {
1883 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1884 IHTMLTextContainer *txtcont;
1885 LONG l = -1, l2 = -1;
1886 HRESULT hres;
1887
1888 hres = IHTMLElement2_get_scrollTop(elem, &l);
1889 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1890 IHTMLElement2_Release(elem);
1891
1892 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1893 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1894
1895 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1896 IHTMLTextContainer_Release(txtcont);
1897 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
1898 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
1899
1900 return l;
1901 }
1902
1903 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1904 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1905 {
1906 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1907 IHTMLTextContainer *txtcont;
1908 LONG l = -1, l2 = -1;
1909 HRESULT hres;
1910
1911 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1912 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1913
1914 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1915 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1916 IHTMLElement2_Release(elem);
1917
1918 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1919 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1920
1921 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1922 IHTMLTextContainer_Release(txtcont);
1923 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
1924 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
1925 }
1926
1927 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1928 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1929 {
1930 IHTMLImgElement *img = _get_img_iface(line, unk);
1931 BSTR src;
1932 HRESULT hres;
1933
1934 hres = IHTMLImgElement_get_src(img, &src);
1935 IHTMLImgElement_Release(img);
1936 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1937 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
1938 SysFreeString(src);
1939 }
1940
1941 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1942 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1943 {
1944 IHTMLImgElement *img = _get_img_iface(line, unk);
1945 BSTR tmp;
1946 HRESULT hres;
1947
1948 tmp = a2bstr(src);
1949 hres = IHTMLImgElement_put_src(img, tmp);
1950 IHTMLImgElement_Release(img);
1951 SysFreeString(tmp);
1952 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1953
1954 _test_img_src(line, unk, src);
1955 }
1956
1957 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1958 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1959 {
1960 IHTMLImgElement *img = _get_img_iface(line, unk);
1961 BSTR alt;
1962 HRESULT hres;
1963
1964 hres = IHTMLImgElement_get_alt(img, &alt);
1965 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1966 if(exalt)
1967 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
1968 else
1969 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1970 SysFreeString(alt);
1971 }
1972
1973 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1974 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1975 {
1976 IHTMLImgElement *img = _get_img_iface(line, unk);
1977 BSTR tmp;
1978 HRESULT hres;
1979
1980 tmp = a2bstr(alt);
1981 hres = IHTMLImgElement_put_alt(img, tmp);
1982 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1983 SysFreeString(tmp);
1984
1985 _test_img_alt(line, unk, alt);
1986 }
1987
1988 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
1989 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
1990 {
1991 IHTMLImgElement *img = _get_img_iface(line, unk);
1992 BSTR sName;
1993 HRESULT hres;
1994
1995 hres = IHTMLImgElement_get_name(img, &sName);
1996 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
1997 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
1998 SysFreeString(sName);
1999 }
2000
2001
2002 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
2003 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2004 {
2005 VARIANT_BOOL disabled = 100;
2006 HRESULT hres;
2007
2008 hres = IHTMLInputElement_get_disabled(input, &disabled);
2009 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2010 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2011
2012 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
2013 }
2014
2015 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
2016 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2017 {
2018 HRESULT hres;
2019
2020 hres = IHTMLInputElement_put_disabled(input, b);
2021 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2022
2023 _test_input_get_disabled(line, input, b);
2024 }
2025
2026 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
2027 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2028 {
2029 VARIANT_BOOL checked = 100;
2030 HRESULT hres;
2031
2032 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
2033 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2034 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2035 }
2036
2037 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
2038 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2039 {
2040 HRESULT hres;
2041
2042 hres = IHTMLInputElement_put_defaultChecked(input, b);
2043 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2044
2045 _test_input_get_defaultchecked(line, input, b);
2046 }
2047
2048 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
2049 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2050 {
2051 VARIANT_BOOL checked = 100;
2052 HRESULT hres;
2053
2054 hres = IHTMLInputElement_get_checked(input, &checked);
2055 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2056 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2057 }
2058
2059 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
2060 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2061 {
2062 HRESULT hres;
2063
2064 hres = IHTMLInputElement_put_checked(input, b);
2065 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2066
2067 _test_input_get_checked(line, input, b);
2068 }
2069
2070 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
2071 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
2072 {
2073 IHTMLInputElement *input;
2074 BSTR bstr;
2075 HRESULT hres;
2076
2077 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2078 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2079 if(FAILED(hres))
2080 return;
2081
2082 hres = IHTMLInputElement_get_value(input, &bstr);
2083 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2084 if(exval)
2085 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
2086 else
2087 ok_(__FILE__,line) (!exval, "exval != NULL\n");
2088 SysFreeString(bstr);
2089 IHTMLInputElement_Release(input);
2090 }
2091
2092 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
2093 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
2094 {
2095 IHTMLInputElement *input;
2096 BSTR bstr;
2097 HRESULT hres;
2098
2099 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2100 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2101 if(FAILED(hres))
2102 return;
2103
2104 bstr = a2bstr(val);
2105 hres = IHTMLInputElement_get_value(input, &bstr);
2106 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2107 SysFreeString(bstr);
2108 IHTMLInputElement_Release(input);
2109 }
2110
2111 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
2112 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
2113 {
2114 BSTR src;
2115 HRESULT hres;
2116
2117 hres = IHTMLInputElement_get_src(input, &src);
2118 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2119 if(exsrc)
2120 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2121 else
2122 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
2123 SysFreeString(src);
2124 }
2125
2126 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
2127 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
2128 {
2129 BSTR tmp;
2130 HRESULT hres;
2131
2132 tmp = a2bstr(src);
2133 hres = IHTMLInputElement_put_src(input, tmp);
2134 SysFreeString(tmp);
2135 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2136
2137 _test_input_src(line, input, src);
2138 }
2139
2140 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
2141 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
2142 {
2143 IHTMLElement *elem = _get_elem_iface(line, unk);
2144 BSTR class = (void*)0xdeadbeef;
2145 HRESULT hres;
2146
2147 hres = IHTMLElement_get_className(elem, &class);
2148 IHTMLElement_Release(elem);
2149 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
2150 if(exclass)
2151 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
2152 else
2153 ok_(__FILE__,line) (!class, "class != NULL\n");
2154 SysFreeString(class);
2155 }
2156
2157 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
2158 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
2159 {
2160 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2161 short index = -3;
2162 HRESULT hres;
2163
2164 hres = IHTMLElement2_get_tabIndex(elem2, &index);
2165 IHTMLElement2_Release(elem2);
2166 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2167 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
2168 }
2169
2170 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
2171 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
2172 {
2173 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2174 HRESULT hres;
2175
2176 hres = IHTMLElement2_put_tabIndex(elem2, index);
2177 IHTMLElement2_Release(elem2);
2178 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2179
2180 _test_elem_tabindex(line, unk, index);
2181 }
2182
2183 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
2184 static void _test_elem_filters(unsigned line, IUnknown *unk)
2185 {
2186 IHTMLElement *elem = _get_elem_iface(line, unk);
2187 HRESULT hres;
2188 IHTMLFiltersCollection *filters;
2189
2190 hres = IHTMLElement_get_filters(elem, &filters);
2191 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
2192 "get_filters failed: %08x\n", hres);
2193 if(hres == S_OK)
2194 {
2195 LONG len;
2196 IDispatchEx *dispex;
2197
2198 hres = IHTMLFiltersCollection_get_length(filters, &len);
2199 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2200 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
2201
2202 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
2203 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
2204 "Could not get IDispatchEx interface: %08x\n", hres);
2205 if(SUCCEEDED(hres)) {
2206 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
2207 IDispatchEx_Release(dispex);
2208 }
2209
2210 IHTMLFiltersCollection_Release(filters);
2211 }
2212
2213 IHTMLElement_Release(elem);
2214 }
2215
2216 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
2217 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
2218 {
2219 IHTMLElement *elem = _get_elem_iface(line, unk);
2220 BSTR tmp;
2221 HRESULT hres;
2222
2223 tmp = class ? a2bstr(class) : NULL;
2224 hres = IHTMLElement_put_className(elem, tmp);
2225 IHTMLElement_Release(elem);
2226 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
2227 SysFreeString(tmp);
2228
2229 _test_elem_class(line, unk, class);
2230 }
2231
2232 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
2233 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
2234 {
2235 IHTMLElement *elem = _get_elem_iface(line, unk);
2236 BSTR id = (void*)0xdeadbeef;
2237 HRESULT hres;
2238
2239 hres = IHTMLElement_get_id(elem, &id);
2240 IHTMLElement_Release(elem);
2241 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
2242
2243 if(exid)
2244 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
2245 else
2246 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
2247
2248 SysFreeString(id);
2249 }
2250
2251 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
2252 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
2253 {
2254 IHTMLElement *elem = _get_elem_iface(line, unk);
2255 BSTR tmp = a2bstr(new_id);
2256 HRESULT hres;
2257
2258 hres = IHTMLElement_put_id(elem, tmp);
2259 IHTMLElement_Release(elem);
2260 SysFreeString(tmp);
2261 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
2262
2263 _test_elem_id(line, unk, new_id);
2264 }
2265
2266 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
2267 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
2268 {
2269 IHTMLElement *elem = _get_elem_iface(line, unk);
2270 BSTR title;
2271 HRESULT hres;
2272
2273 hres = IHTMLElement_get_title(elem, &title);
2274 IHTMLElement_Release(elem);
2275 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2276 if(extitle)
2277 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2278 else
2279 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
2280
2281 SysFreeString(title);
2282 }
2283
2284 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
2285 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
2286 {
2287 IHTMLElement *elem = _get_elem_iface(line, unk);
2288 BSTR tmp;
2289 HRESULT hres;
2290
2291 tmp = a2bstr(title);
2292 hres = IHTMLElement_put_title(elem, tmp);
2293 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2294
2295 IHTMLElement_Release(elem);
2296 SysFreeString(tmp);
2297 }
2298
2299 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
2300 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
2301 {
2302 IHTMLDOMNode *node = _get_node_iface(line, unk);
2303 VARIANT var;
2304 HRESULT hres;
2305
2306 hres = IHTMLDOMNode_get_nodeValue(node, &var);
2307 IHTMLDOMNode_Release(node);
2308 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
2309
2310 if(exval) {
2311 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
2312 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
2313 }else {
2314 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
2315 }
2316
2317 VariantClear(&var);
2318 }
2319
2320 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
2321 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
2322 {
2323 IHTMLDOMNode *node = _get_node_iface(line, unk);
2324 VARIANT var;
2325 HRESULT hres;
2326
2327 V_VT(&var) = VT_BSTR;
2328 V_BSTR(&var) = a2bstr(val);
2329
2330 hres = IHTMLDOMNode_put_nodeValue(node, var);
2331 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
2332 IHTMLDOMNode_Release(node);
2333 VariantClear(&var);
2334 }
2335
2336 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
2337 static void _test_elem_client_size(unsigned line, IUnknown *unk)
2338 {
2339 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2340 LONG l;
2341 HRESULT hres;
2342
2343 hres = IHTMLElement2_get_clientWidth(elem, &l);
2344 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
2345 hres = IHTMLElement2_get_clientHeight(elem, &l);
2346 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
2347
2348 IHTMLElement2_Release(elem);
2349 }
2350
2351 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
2352 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
2353 {
2354 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2355 LONG l;
2356 HRESULT hres;
2357
2358 hres = IHTMLElement2_get_clientLeft(elem, &l);
2359 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
2360 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
2361
2362 hres = IHTMLElement2_get_clientTop(elem, &l);
2363 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
2364 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
2365
2366 IHTMLElement2_Release(elem);
2367 }
2368
2369 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
2370 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
2371 {
2372 IHTMLElement *elem = _get_elem_iface(line, unk);
2373 IHTMLDocument2 *doc;
2374 IDispatch *disp;
2375 HRESULT hres;
2376
2377 disp = NULL;
2378 hres = IHTMLElement_get_document(elem, &disp);
2379 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2380 ok(disp != NULL, "disp == NULL\n");
2381
2382 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
2383 IDispatch_Release(disp);
2384 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
2385
2386 return doc;
2387 }
2388
2389 #define get_window_doc(e) _get_window_doc(__LINE__,e)
2390 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
2391 {
2392 IHTMLDocument2 *doc;
2393 HRESULT hres;
2394
2395 doc = NULL;
2396 hres = IHTMLWindow2_get_document(window, &doc);
2397 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2398 ok(doc != NULL, "disp == NULL\n");
2399
2400 return doc;
2401 }
2402
2403 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
2404 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
2405 {
2406 IHTMLElement *elem = NULL;
2407 BSTR tmp;
2408 HRESULT hres;
2409
2410 tmp = a2bstr(tag);
2411 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
2412 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
2413 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
2414
2415 return elem;
2416 }
2417
2418 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
2419 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
2420 {
2421 IHTMLDocument3 *doc3;
2422 IHTMLDOMNode *node = NULL;
2423 BSTR tmp;
2424 HRESULT hres;
2425
2426 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2427 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
2428
2429 tmp = a2bstr(text);
2430 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
2431 IHTMLDocument3_Release(doc3);
2432 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
2433 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
2434
2435 return node;
2436 }
2437
2438 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
2439 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
2440 {
2441 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
2442 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
2443 IHTMLDOMNode *new_child = NULL;
2444 HRESULT hres;
2445
2446 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
2447 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
2448 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
2449 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
2450
2451 IHTMLDOMNode_Release(node);
2452 IHTMLDOMNode_Release(child);
2453
2454 return new_child;
2455 }
2456
2457 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
2458 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
2459 {
2460 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
2461 IHTMLDOMNode *new_child = NULL;
2462 HRESULT hres;
2463
2464 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
2465 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
2466 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
2467 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
2468
2469 IHTMLDOMNode_Release(node);
2470
2471 return new_child;
2472 }
2473
2474 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
2475 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
2476 {
2477 IHTMLDOMNode *node = _get_node_iface(line, unk);
2478 IHTMLDOMNode *new_node = NULL;
2479 HRESULT hres;
2480
2481 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
2482 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
2483 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
2484 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
2485
2486 IHTMLDOMNode_Release(node);
2487 IHTMLDOMNode_Release(new_node);
2488 }
2489
2490 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
2491 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
2492 {
2493 BSTR title = NULL;
2494 HRESULT hres;
2495
2496 hres = IHTMLDocument2_get_title(doc, &title);
2497 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2498 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2499 SysFreeString(title);
2500 }
2501
2502 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
2503 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
2504 {
2505 BSTR tmp;
2506 HRESULT hres;
2507
2508 tmp = a2bstr(title);
2509 hres = IHTMLDocument2_put_title(doc, tmp);
2510 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2511 SysFreeString(tmp);
2512 }
2513
2514 #define test_border_styles(p, n) _test_border_styles(__LINE__, p, n)
2515 static void _test_border_styles(unsigned line, IHTMLStyle *pStyle, BSTR Name)
2516 {
2517 HRESULT hres;
2518 DISPID dispid;
2519
2520 hres = IHTMLStyle_GetIDsOfNames(pStyle, &IID_NULL, &Name, 1,
2521 LOCALE_USER_DEFAULT, &dispid);
2522 ok_(__FILE__,line) (hres == S_OK, "GetIDsOfNames: %08x\n", hres);
2523 if(hres == S_OK)
2524 {
2525 DISPPARAMS params = {NULL,NULL,0,0};
2526 DISPID dispidNamed = DISPID_PROPERTYPUT;
2527 VARIANT ret;
2528 VARIANT vDefault;
2529 VARIANTARG arg;
2530
2531 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2532 DISPATCH_PROPERTYGET, &params, &vDefault, NULL, NULL);
2533 ok_(__FILE__,line) (hres == S_OK, "get_default. ret: %08x\n", hres);
2534
2535 params.cArgs = 1;
2536 params.cNamedArgs = 1;
2537 params.rgdispidNamedArgs = &dispidNamed;
2538 V_VT(&arg) = VT_BSTR;
2539 V_BSTR(&arg) = a2bstr("none");
2540 params.rgvarg = &arg;
2541 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2542 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2543 ok_(__FILE__,line) (hres == S_OK, "none. ret: %08x\n", hres);
2544 VariantClear(&arg);
2545
2546 V_VT(&arg) = VT_BSTR;
2547 V_BSTR(&arg) = a2bstr("dotted");
2548 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2549 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2550 ok_(__FILE__,line) (hres == S_OK, "dotted. ret: %08x\n", hres);
2551 VariantClear(&arg);
2552
2553 V_VT(&arg) = VT_BSTR;
2554 V_BSTR(&arg) = a2bstr("dashed");
2555 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2556 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2557 ok_(__FILE__,line) (hres == S_OK, "dashed. ret: %08x\n", hres);
2558 VariantClear(&arg);
2559
2560 V_VT(&arg) = VT_BSTR;
2561 V_BSTR(&arg) = a2bstr("solid");
2562 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2563 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2564 ok_(__FILE__,line) (hres == S_OK, "solid. ret: %08x\n", hres);
2565 VariantClear(&arg);
2566
2567 V_VT(&arg) = VT_BSTR;
2568 V_BSTR(&arg) = a2bstr("double");
2569 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2570 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2571 ok_(__FILE__,line) (hres == S_OK, "double. ret: %08x\n", hres);
2572 VariantClear(&arg);
2573
2574 V_VT(&arg) = VT_BSTR;
2575 V_BSTR(&arg) = a2bstr("groove");
2576 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2577 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2578 ok_(__FILE__,line) (hres == S_OK, "groove. ret: %08x\n", hres);
2579 VariantClear(&arg);
2580
2581 V_VT(&arg) = VT_BSTR;
2582 V_BSTR(&arg) = a2bstr("ridge");
2583 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2584 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2585 ok_(__FILE__,line) (hres == S_OK, "ridge. ret: %08x\n", hres);
2586 VariantClear(&arg);
2587
2588 V_VT(&arg) = VT_BSTR;
2589 V_BSTR(&arg) = a2bstr("inset");
2590 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2591 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2592 ok_(__FILE__,line) (hres == S_OK, "inset. ret: %08x\n", hres);
2593 VariantClear(&arg);
2594
2595 V_VT(&arg) = VT_BSTR;
2596 V_BSTR(&arg) = a2bstr("outset");
2597 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2598 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2599 ok_(__FILE__,line) (hres == S_OK, "outset. ret: %08x\n", hres);
2600 VariantClear(&arg);
2601
2602 V_VT(&arg) = VT_BSTR;
2603 V_BSTR(&arg) = a2bstr("invalid");
2604 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2605 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2606 ok_(__FILE__,line) (FAILED(hres), "invalid value passed.\n");
2607 VariantClear(&arg);
2608
2609 params.rgvarg = &vDefault;
2610 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2611 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2612 ok_(__FILE__,line) (hres == S_OK, "default. ret: %08x\n", hres);
2613 }
2614 }
2615
2616 #define test_style_csstext(s,t) _test_style_csstext(__LINE__,s,t)
2617 static void _test_style_csstext(unsigned line, IHTMLStyle *style, const char *extext)
2618 {
2619 BSTR text = (void*)0xdeadbeef;
2620 HRESULT hres;
2621
2622 hres = IHTMLStyle_get_cssText(style, &text);
2623 ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
2624 if(extext)
2625 ok_(__FILE__,line)(!strcmp_wa(text, extext), "cssText = %s\n", wine_dbgstr_w(text));
2626 else
2627 ok_(__FILE__,line)(!text, "cssText = %s\n", wine_dbgstr_w(text));
2628
2629 SysFreeString(text);
2630 }
2631
2632 #define test_style_set_csstext(s,t) _test_style_set_csstext(__LINE__,s,t)
2633 static void _test_style_set_csstext(unsigned line, IHTMLStyle *style, const char *text)
2634 {
2635 BSTR tmp;
2636 HRESULT hres;
2637
2638 tmp = a2bstr(text);
2639 hres = IHTMLStyle_put_cssText(style, tmp);
2640 ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
2641 SysFreeString(tmp);
2642 }
2643
2644 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
2645 const elem_type_t *elem_types, LONG len)
2646 {
2647 IDispatch *disp;
2648 VARIANT name, index;
2649 DWORD i;
2650 HRESULT hres;
2651
2652 V_VT(&index) = VT_EMPTY;
2653 V_VT(&name) = VT_BSTR;
2654 V_BSTR(&name) = a2bstr(n);
2655
2656 hres = IHTMLElementCollection_item(col, name, index, &disp);
2657 ok(hres == S_OK, "item failed: %08x\n", hres);
2658
2659 test_elem_collection((IUnknown*)disp, elem_types, len);
2660 IDispatch_Release(disp);
2661 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
2662 if(hres != S_OK)
2663 goto cleanup;
2664
2665 V_VT(&index) = VT_I4;
2666
2667 for(i=0; i<len; i++) {
2668 V_I4(&index) = i;
2669 disp = (void*)0xdeadbeef;
2670 hres = IHTMLElementCollection_item(col, name, index, &disp);
2671 ok(hres == S_OK, "item failed: %08x\n", hres);
2672 ok(disp != NULL, "disp == NULL\n");
2673 if(FAILED(hres) || !disp)
2674 continue;
2675
2676 test_elem_type((IUnknown*)disp, elem_types[i]);
2677
2678 IDispatch_Release(disp);
2679 }
2680
2681 V_I4(&index) = len;
2682 disp = (void*)0xdeadbeef;
2683 hres = IHTMLElementCollection_item(col, name, index, &disp);
2684 ok(hres == S_OK, "item failed: %08x\n", hres);
2685 ok(disp == NULL, "disp != NULL\n");
2686
2687 V_I4(&index) = -1;
2688 disp = (void*)0xdeadbeef;
2689 hres = IHTMLElementCollection_item(col, name, index, &disp);
2690 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2691 ok(disp == NULL, "disp != NULL\n");
2692
2693 cleanup:
2694 SysFreeString(V_BSTR(&name));
2695 }
2696
2697 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
2698 {
2699 IHTMLElementCollection *col;
2700 IHTMLElement *elem;
2701 IDispatch *disp = (void*)0xdeadbeef;
2702 VARIANT name, index;
2703 HRESULT hres;
2704
2705 hres = IHTMLDocument2_get_all(doc, &col);
2706 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2707 ok(col != NULL, "col == NULL\n");
2708 if(FAILED(hres) || !col)
2709 return NULL;
2710
2711 V_VT(&index) = VT_EMPTY;
2712 V_VT(&name) = VT_BSTR;
2713 V_BSTR(&name) = a2bstr(id);
2714
2715 hres = IHTMLElementCollection_item(col, name, index, &disp);
2716 IHTMLElementCollection_Release(col);
2717 SysFreeString(V_BSTR(&name));
2718 ok(hres == S_OK, "item failed: %08x\n", hres);
2719 if(!expect_success) {
2720 ok(disp == NULL, "disp != NULL\n");
2721 return NULL;
2722 }
2723
2724 ok(disp != NULL, "disp == NULL\n");
2725 if(!disp)
2726 return NULL;
2727
2728 elem = get_elem_iface((IUnknown*)disp);
2729 IDispatch_Release(disp);
2730
2731 return elem;
2732 }
2733
2734 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
2735 {
2736 IHTMLDocument3 *doc3;
2737 IHTMLElement *elem;
2738 BSTR tmp;
2739 HRESULT hres;
2740
2741 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2742 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
2743
2744 tmp = a2bstr(id);
2745 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
2746 SysFreeString(tmp);
2747 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
2748
2749 IHTMLDocument3_Release(doc3);
2750
2751 return elem;
2752 }
2753
2754 static void test_select_elem(IHTMLSelectElement *select)
2755 {
2756 test_select_type(select, "select-one");
2757 test_select_length(select, 2);
2758 test_select_selidx(select, 0);
2759 test_select_put_selidx(select, 1);
2760
2761 test_select_set_value(select, "val1");
2762 test_select_value(select, "val1");
2763
2764 test_select_get_disabled(select, VARIANT_FALSE);
2765 test_select_set_disabled(select, VARIANT_TRUE);
2766 test_select_set_disabled(select, VARIANT_FALSE);
2767 }
2768
2769 static void test_create_option_elem(IHTMLDocument2 *doc)
2770 {
2771 IHTMLOptionElement *option;
2772
2773 option = create_option_elem(doc, "test text", "test value");
2774
2775 test_option_put_text(option, "new text");
2776 test_option_put_value(option, "new value");
2777
2778 IHTMLOptionElement_Release(option);
2779 }
2780
2781 static void test_create_img_elem(IHTMLDocument2 *doc)
2782 {
2783 IHTMLImgElement *img;
2784
2785 img = create_img_elem(doc, 10, 15);
2786
2787 if(img){
2788 test_img_put_width(img, 5);
2789 test_img_put_height(img, 20);
2790
2791 IHTMLImgElement_Release(img);
2792 img = NULL;
2793 }
2794
2795 img = create_img_elem(doc, -1, -1);
2796
2797 if(img){
2798 test_img_put_width(img, 5);
2799 test_img_put_height(img, 20);
2800
2801 IHTMLImgElement_Release(img);
2802 }
2803 }
2804
2805 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
2806 {
2807 IHTMLBodyElement *body;
2808 IHTMLTxtRange *range;
2809 IHTMLElement *elem;
2810 HRESULT hres;
2811
2812 hres = IHTMLDocument2_get_body(doc, &elem);
2813 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2814
2815 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2816 IHTMLElement_Release(elem);
2817
2818 hres = IHTMLBodyElement_createTextRange(body, &range);
2819 IHTMLBodyElement_Release(body);
2820 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
2821
2822 return range;
2823 }
2824
2825 static void test_txtrange(IHTMLDocument2 *doc)
2826 {
2827 IHTMLTxtRange *body_range, *range, *range2;
2828 IHTMLSelectionObject *selection;
2829 IDispatch *disp_range;
2830 HRESULT hres;
2831
2832 body_range = test_create_body_range(doc);
2833
2834 test_range_text(body_range, "test abc 123\r\nit's text");
2835
2836 hres = IHTMLTxtRange_duplicate(body_range, &range);
2837 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2838
2839 hres = IHTMLTxtRange_duplicate(body_range, &range2);
2840 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2841 test_range_isequal(range, range2, VARIANT_TRUE);
2842
2843 test_range_text(range, "test abc 123\r\nit's text");
2844 test_range_text(body_range, "test abc 123\r\nit's text");
2845
2846 test_range_collapse(range, TRUE);
2847 test_range_isequal(range, range2, VARIANT_FALSE);
2848 test_range_inrange(range, range2, VARIANT_FALSE);
2849 test_range_inrange(range2, range, VARIANT_TRUE);
2850 IHTMLTxtRange_Release(range2);
2851
2852 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2853 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
2854 test_range_move(range, characterW, 2, 2);
2855 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2856
2857 test_range_collapse(range, FALSE);
2858 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
2859
2860 test_range_collapse(range, FALSE);
2861 test_range_expand(range, wordW, VARIANT_TRUE, "123");
2862 test_range_expand(range, wordW, VARIANT_FALSE, "123");
2863 test_range_move(range, characterW, 2, 2);
2864 test_range_expand(range, wordW, VARIANT_TRUE, "123");
2865 test_range_moveend(range, characterW, -5, -5);
2866 test_range_text(range, NULL);
2867 test_range_moveend(range, characterW, 3, 3);
2868 test_range_text(range, "c 1");
2869 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
2870 test_range_collapse(range, TRUE);
2871 test_range_move(range, characterW, 4, 4);
2872 test_range_moveend(range, characterW, 1, 1);
2873 test_range_text(range, " ");
2874 test_range_move(range, wordW, 1, 1);
2875 test_range_moveend(range, characterW, 2, 2);
2876 test_range_text(range, "ab");
2877
2878 IHTMLTxtRange_Release(range);
2879
2880 hres = IHTMLTxtRange_duplicate(body_range, &range);
2881 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2882
2883 test_range_text(range, "test abc 123\r\nit's text");
2884 test_range_move(range, characterW, 3, 3);
2885 test_range_moveend(range, characterW, 1, 1);
2886 test_range_text(range, "t");
2887 test_range_moveend(range, characterW, 3, 3);
2888 test_range_text(range, "t ab");
2889 test_range_moveend(range, characterW, -2, -2);
2890 test_range_text(range, "t ");
2891 test_range_move(range, characterW, 6, 6);
2892 test_range_moveend(range, characterW, 3, 3);
2893 test_range_text(range, "123");
2894 test_range_moveend(range, characterW, 2, 2);
2895 test_range_text(range, "123\r\ni");
2896
2897 IHTMLTxtRange_Release(range);
2898
2899 hres = IHTMLTxtRange_duplicate(body_range, &range);
2900 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2901
2902 test_range_move(range, wordW, 1, 1);
2903 test_range_moveend(range, characterW, 2, 2);
2904 test_range_text(range, "ab");
2905
2906 test_range_move(range, characterW, -2, -2);
2907 test_range_moveend(range, characterW, 2, 2);
2908 test_range_text(range, "t ");
2909
2910 test_range_move(range, wordW, 3, 3);
2911 test_range_move(range, wordW, -2, -2);
2912 test_range_moveend(range, characterW, 2, 2);
2913 test_range_text(range, "ab");
2914
2915 test_range_move(range, characterW, -6, -5);
2916 test_range_moveend(range, characterW, -1, 0);
2917 test_range_moveend(range, characterW, -6, 0);
2918 test_range_move(range, characterW, 2, 2);
2919 test_range_moveend(range, characterW, 2, 2);
2920 test_range_text(range, "st");
2921 test_range_moveend(range, characterW, -6, -4);
2922 test_range_moveend(range, characterW, 2, 2);
2923
2924 IHTMLTxtRange_Release(range);
2925
2926 hres = IHTMLTxtRange_duplicate(body_range, &range);
2927 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2928
2929 test_range_move(range, wordW, 2, 2);
2930 test_range_moveend(range, characterW, 2, 2);
2931 test_range_text(range, "12");
2932
2933 test_range_move(range, characterW, 15, 14);
2934 test_range_move(range, characterW, -2, -2);
2935 test_range_moveend(range, characterW, 3, 2);
2936 test_range_text(range, "t");
2937 test_range_moveend(range, characterW, -1, -1);
2938 test_range_text(range, "t");
2939 test_range_expand(range, wordW, VARIANT_TRUE, "text");
2940 test_range_move(range, characterW, -2, -2);
2941 test_range_moveend(range, characterW, 2, 2);
2942 test_range_text(range, "s ");
2943 test_range_move(range, characterW, 100, 7);
2944 test_range_move(range, wordW, 1, 0);
2945 test_range_move(range, characterW, -2, -2);
2946 test_range_moveend(range, characterW, 3, 2);
2947 test_range_text(range, "t");
2948
2949 IHTMLTxtRange_Release(range);
2950
2951 hres = IHTMLTxtRange_duplicate(body_range, &range);
2952 ok(hres == S_OK, "duplicate failed: %08x\n", hres);