From 710b643b2ffe56f1ab754d030cbc651220919bfa Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 10 Mar 2011 04:19:29 +0300 Subject: [PATCH] msxml3: Some get_attributes() tests. --- dlls/msxml3/pi.c | 26 +++++- dlls/msxml3/tests/domdoc.c | 161 ++++++++++++++++++++++--------------- 2 files changed, 117 insertions(+), 70 deletions(-) diff --git a/dlls/msxml3/pi.c b/dlls/msxml3/pi.c index b9a2c7e0af8..176678152f9 100644 --- a/dlls/msxml3/pi.c +++ b/dlls/msxml3/pi.c @@ -315,14 +315,32 @@ static HRESULT WINAPI dom_pi_get_nextSibling( static HRESULT WINAPI dom_pi_get_attributes( IXMLDOMProcessingInstruction *iface, - IXMLDOMNamedNodeMap** attributeMap) + IXMLDOMNamedNodeMap** map) { dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface ); + static const WCHAR xmlW[] = {'x','m','l',0}; + HRESULT hr; + BSTR name; - TRACE("(%p)->(%p)\n", This, attributeMap); + TRACE("(%p)->(%p)\n", This, map); - *attributeMap = create_nodemap((IXMLDOMNode*)&This->IXMLDOMProcessingInstruction_iface); - return S_OK; + if (!map) return E_INVALIDARG; + + *map = NULL; + + hr = node_get_nodeName(&This->node, &name); + if (hr != S_OK) return hr; + + if (!strcmpW(name, xmlW)) + { + FIXME("not implemented for declaration\n"); + SysFreeString(name); + return E_NOTIMPL; + } + + SysFreeString(name); + + return S_FALSE; } static HRESULT WINAPI dom_pi_insertBefore( diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index b606dc1e0fe..42fd22ae06b 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -1089,8 +1089,6 @@ if (0) SysFreeString( str ); if(nodetext) { - IXMLDOMNamedNodeMap *pAttribs; - r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element); ok(r == E_NOINTERFACE, "ret %08x\n", r ); @@ -1103,15 +1101,6 @@ if (0) ok(r == S_FALSE, "ret %08x\n", r ); ok(nodeChild == NULL, "nodeChild not NULL\n"); - /* test get_attributes */ - r = IXMLDOMText_get_attributes( nodetext, NULL ); - ok( r == E_INVALIDARG, "get_attributes returned wrong code\n"); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - r = IXMLDOMText_get_attributes( nodetext, &pAttribs); - ok(r == S_FALSE, "ret %08x\n", r ); - ok( pAttribs == NULL, "pAttribs not NULL\n"); - /* test length property */ r = IXMLDOMText_get_length(nodetext, NULL); ok(r == E_INVALIDARG, "ret %08x\n", r ); @@ -4258,15 +4247,6 @@ static void test_xmlTypes(void) ok(hr == S_FALSE, "ret %08x\n", hr ); ok(pNextChild == NULL, "pNextChild not NULL\n"); - /* test get_attributes */ - hr = IXMLDOMDocument_get_attributes( doc, NULL ); - ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n"); - - pAttribs = (void*)0xdeadbeef; - hr = IXMLDOMDocument_get_attributes( doc, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok( pAttribs == NULL, "pAttribs not NULL\n"); - /* test get_dataType */ V_VT(&v) = VT_EMPTY; hr = IXMLDOMDocument_get_dataType(doc, &v); @@ -4352,15 +4332,6 @@ static void test_xmlTypes(void) ok(hr == S_OK, "ret %08x\n", hr ); if(hr == S_OK) { - /* test get_attributes */ - hr = IXMLDOMComment_get_attributes( pComment, NULL ); - ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n"); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - hr = IXMLDOMComment_get_attributes( pComment, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok( pAttribs == NULL, "pAttribs not NULL\n"); - hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL); ok(hr == S_OK, "ret %08x\n", hr ); @@ -4710,15 +4681,6 @@ static void test_xmlTypes(void) ok(hr == S_FALSE, "ret %08x\n", hr ); ok(pNextChild == NULL, "pNextChild not NULL\n"); - /* test get_attributes */ - hr = IXMLDOMAttribute_get_attributes( pAttribute, NULL ); - ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n"); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - hr = IXMLDOMAttribute_get_attributes( pAttribute, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok( pAttribs == NULL, "pAttribs not NULL\n"); - hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild); ok(hr == E_FAIL, "ret %08x\n", hr ); ok(pNewChild == NULL, "pNewChild not NULL\n"); @@ -4812,15 +4774,6 @@ static void test_xmlTypes(void) hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL); ok(hr == S_OK, "ret %08x\n", hr ); - /* get Attribute Tests */ - hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL); - ok(hr == E_INVALIDARG, "ret %08x\n", hr ); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok(pAttribs == NULL, "pAttribs != NULL\n"); - hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str); ok(hr == S_OK, "ret %08x\n", hr ); ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n"); @@ -5139,15 +5092,6 @@ static void test_xmlTypes(void) hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL); ok(hr == S_OK, "ret %08x\n", hr ); - /* get Attribute Tests */ - hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL); - ok(hr == E_INVALIDARG, "ret %08x\n", hr ); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok(pAttribs == NULL, "pAttribs != NULL\n"); - hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str); ok(hr == S_OK, "ret %08x\n", hr ); ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n"); @@ -5192,15 +5136,6 @@ static void test_xmlTypes(void) hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL); ok(hr == S_OK, "ret %08x\n", hr ); - /* get Attribute Tests */ - hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL); - ok(hr == E_INVALIDARG, "ret %08x\n", hr ); - - pAttribs = (IXMLDOMNamedNodeMap*)0x1; - hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs); - ok(hr == S_FALSE, "ret %08x\n", hr ); - ok(pAttribs == NULL, "pAttribs != NULL\n"); - /* test get_xml*/ hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str); ok(hr == S_OK, "ret %08x\n", hr ); @@ -8364,8 +8299,8 @@ static const get_node_typestring_t get_node_typestring[] = { static void test_get_nodeTypeString(void) { - IXMLDOMDocument *doc; const get_node_typestring_t *entry = get_node_typestring; + IXMLDOMDocument *doc; HRESULT hr; BSTR str; @@ -8402,6 +8337,99 @@ static void test_get_nodeTypeString(void) free_bstrs(); } +typedef struct _get_attributes_t { + DOMNodeType type; + HRESULT hr; +} get_attributes_t; + +static const get_attributes_t get_attributes[] = { + { NODE_ATTRIBUTE, S_FALSE }, + { NODE_TEXT, S_FALSE }, + { NODE_CDATA_SECTION , S_FALSE }, + { NODE_ENTITY_REFERENCE, S_FALSE }, + { NODE_PROCESSING_INSTRUCTION, S_FALSE }, + { NODE_COMMENT, S_FALSE }, + { NODE_DOCUMENT_FRAGMENT, S_FALSE }, + { 0 } +}; + +static void test_get_attributes(void) +{ + const get_attributes_t *entry = get_attributes; + IXMLDOMNamedNodeMap *map; + IXMLDOMDocument *doc; + IXMLDOMNode *node; + VARIANT_BOOL b; + HRESULT hr; + BSTR str; + + doc = create_document(&IID_IXMLDOMDocument); + + str = SysAllocString( szComplete3 ); + hr = IXMLDOMDocument_loadXML(doc, str, &b); + SysFreeString(str); + + hr = IXMLDOMDocument_get_attributes(doc, NULL); + ok(hr == E_INVALIDARG, "got %08x\n", hr); + + map = (void*)0xdeadbeef; + hr = IXMLDOMDocument_get_attributes(doc, &map); + ok(hr == S_FALSE, "got %08x\n", hr); + ok(map == NULL, "got %p\n", map); + + /* first child is */ + hr = IXMLDOMDocument_get_firstChild(doc, &node); + ok(hr == S_OK, "got %08x\n", hr); + + hr = IXMLDOMNode_get_attributes(node, &map); + todo_wine ok(hr == S_OK, "got %08x\n", hr); + + if (hr == S_OK) + { + IXMLDOMNode_Release(node); + + node = NULL; + hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node); + ok(hr == S_OK, "got %08x\n", hr); + ok(node != NULL, "got %p\n", node); + + hr = IXMLDOMNode_get_nodeName(node, &str); + ok(hr == S_OK, "got %08x\n", hr); + ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + IXMLDOMNamedNodeMap_Release(map); + } + + IXMLDOMNode_Release(node); + + while (entry->type) + { + VARIANT var; + + node = NULL; + + V_VT(&var) = VT_I4; + V_I4(&var) = entry->type; + hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node); + ok(hr == S_OK, "failed to create node, type %d\n", entry->type); + + hr = IXMLDOMNode_get_attributes(node, NULL); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + + map = (void*)0xdeadbeef; + hr = IXMLDOMNode_get_attributes(node, &map); + ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n", + hr, entry->hr, entry->type); + ok(map == NULL, "got %p\n", map); + + entry++; + } + + IXMLDOMDocument_Release(doc); + free_bstrs(); +} + START_TEST(domdoc) { IXMLDOMDocument *doc; @@ -8472,6 +8500,7 @@ START_TEST(domdoc) test_get_tagName(); test_get_dataType(); test_get_nodeTypeString(); + test_get_attributes(); test_xsltemplate(); CoUninitialize();