2007-05-24 20:13:43 +02:00
|
|
|
/*
|
|
|
|
* IXMLElement tests
|
|
|
|
*
|
|
|
|
* Copyright 2007 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "xmldom.h"
|
|
|
|
#include "msxml2.h"
|
|
|
|
#include "ocidl.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2008-06-09 14:12:25 +02:00
|
|
|
#define ERROR_URL_NOT_FOUND 0x800c0006
|
|
|
|
|
2007-05-24 20:13:43 +02:00
|
|
|
static void test_xmlelem(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
IXMLElement *element = NULL, *parent;
|
|
|
|
IXMLElement *child, *child2;
|
|
|
|
IXMLElementCollection *children;
|
|
|
|
VARIANT vType, vName;
|
|
|
|
VARIANT vIndex, vValue;
|
|
|
|
BSTR str, val;
|
2009-03-09 23:28:42 +01:00
|
|
|
LONG type, num_child;
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
static const WCHAR propName[] = {'p','r','o','p',0};
|
|
|
|
static const WCHAR propVal[] = {'v','a','l',0};
|
|
|
|
static const WCHAR nextVal[] = {'n','e','x','t',0};
|
|
|
|
static const WCHAR noexist[] = {'n','o','e','x','i','s','t',0};
|
|
|
|
static const WCHAR crazyCase1[] = {'C','R','a','z','Y','c','A','S','E',0};
|
|
|
|
static const WCHAR crazyCase2[] = {'C','R','A','Z','Y','C','A','S','E',0};
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
2010-01-14 22:10:22 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_ELEMENT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &element);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(element, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(lstrlenW(str) == 0, "Expected empty tag name\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
parent = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_parent(element, &parent);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == 1, "Expected 1, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(parent == NULL, "Expected NULL parent\n");
|
|
|
|
|
|
|
|
str = SysAllocString(noexist);
|
|
|
|
hr = IXMLElement_getAttribute(element, str, &vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
|
2008-06-23 08:00:45 +02:00
|
|
|
ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
|
2007-05-24 20:13:43 +02:00
|
|
|
VariantClear(&vValue);
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
str = SysAllocString(crazyCase1);
|
|
|
|
val = SysAllocString(propVal);
|
|
|
|
V_VT(&vValue) = VT_BSTR;
|
|
|
|
V_BSTR(&vValue) = val;
|
|
|
|
hr = IXMLElement_setAttribute(element, str, vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
SysFreeString(val);
|
|
|
|
|
|
|
|
str = SysAllocString(crazyCase2);
|
|
|
|
hr = IXMLElement_getAttribute(element, str, &vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&vValue) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&vValue));
|
|
|
|
ok(!lstrcmpW(V_BSTR(&vValue), propVal), "Expected 'val'\n");
|
|
|
|
VariantClear(&vValue);
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
str = SysAllocString(propName);
|
|
|
|
val = SysAllocString(propVal);
|
|
|
|
V_VT(&vValue) = VT_BSTR;
|
|
|
|
V_BSTR(&vValue) = val;
|
|
|
|
hr = IXMLElement_setAttribute(element, str, vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(val);
|
|
|
|
|
|
|
|
hr = IXMLElement_getAttribute(element, str, &vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&vValue) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&vValue));
|
|
|
|
ok(!lstrcmpW(V_BSTR(&vValue), propVal), "Expected 'val'\n");
|
|
|
|
VariantClear(&vValue);
|
|
|
|
|
|
|
|
hr = IXMLElement_removeAttribute(element, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
2007-05-28 01:10:17 +02:00
|
|
|
/* remove now nonexistent attribute */
|
2007-05-24 20:13:43 +02:00
|
|
|
hr = IXMLElement_removeAttribute(element, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_getAttribute(element, str, &vValue);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == 1, "Expected 1, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
|
2008-06-23 08:00:45 +02:00
|
|
|
ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
VariantClear(&vValue);
|
|
|
|
|
|
|
|
children = (IXMLElementCollection *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_children(element, &children);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == 1, "Expected 1, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(children == NULL, "Expected NULL collection\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(element, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_text(element, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(lstrlenW(str) == 0, "Expected empty text\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
/* put_text with an ELEMENT */
|
|
|
|
str = SysAllocString(propVal);
|
|
|
|
hr = IXMLElement_put_text(element, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_TEXT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &child);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_addChild(element, child, 0, -1);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
str = SysAllocString(propVal);
|
|
|
|
hr = IXMLElement_put_text(child, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
parent = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_parent(child, &parent);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(parent != element, "Expected parent != element\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(parent, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
children = (IXMLElementCollection *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_children(element, &children);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(children != NULL, "Expected non-NULL collection\n");
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(children, &num_child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(num_child == 1, "Expected 1, got %d\n", num_child);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
V_VT(&vIndex) = VT_I4;
|
|
|
|
V_I4(&vIndex) = 0;
|
|
|
|
V_VT(&vName) = VT_ERROR;
|
|
|
|
V_ERROR(&vName) = DISP_E_PARAMNOTFOUND;
|
|
|
|
hr = IXMLElementCollection_item(children, vIndex, vName, (IDispatch **)&child2);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child2 != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child2, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_text(element, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, propVal), "Expected 'val'\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_text(child2, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, propVal), "Expected 'val'\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
/* try put_text on ELEMENT again, now that it has a text child */
|
|
|
|
str = SysAllocString(nextVal);
|
|
|
|
hr = IXMLElement_put_text(element, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
str = SysAllocString(nextVal);
|
|
|
|
hr = IXMLElement_put_text(child2, str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_text(element, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, nextVal), "Expected 'val'\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
IXMLElement_Release(child2);
|
|
|
|
IXMLElementCollection_Release(children);
|
|
|
|
IXMLElement_Release(parent);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
IXMLElement_Release(element);
|
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_xml_file(LPCSTR filename)
|
|
|
|
{
|
|
|
|
DWORD dwNumberOfBytesWritten;
|
|
|
|
HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
2008-12-05 04:40:28 +01:00
|
|
|
static const char data[] =
|
|
|
|
"<?xml version=\"1.0\" ?>\n"
|
|
|
|
"<BankAccount>\n"
|
|
|
|
" <Number>1234</Number>\n"
|
|
|
|
" <Name>Captain Ahab</Name>\n"
|
|
|
|
"</BankAccount>\n";
|
2007-05-24 20:13:43 +02:00
|
|
|
|
2008-12-05 04:40:28 +01:00
|
|
|
WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
|
2007-05-24 20:13:43 +02:00
|
|
|
CloseHandle(hf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_xmlelem_collection(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IUnknown *unk = NULL;
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
IXMLElement *element = NULL, *child;
|
|
|
|
IXMLElementCollection *collection = NULL;
|
|
|
|
IEnumVARIANT *enumVar = NULL;
|
2008-09-03 09:48:49 +02:00
|
|
|
CHAR pathA[MAX_PATH];
|
2007-05-24 20:13:43 +02:00
|
|
|
WCHAR path[MAX_PATH];
|
2009-03-09 23:28:42 +01:00
|
|
|
LONG length, type;
|
2007-05-24 20:13:43 +02:00
|
|
|
ULONG num_vars;
|
|
|
|
VARIANT var, vIndex, vName;
|
|
|
|
BSTR url, str;
|
2008-09-03 09:48:49 +02:00
|
|
|
static const CHAR szBankXML[] = "bank.xml";
|
2007-05-24 20:13:43 +02:00
|
|
|
static const WCHAR szNumber[] = {'N','U','M','B','E','R',0};
|
|
|
|
static const WCHAR szName[] = {'N','A','M','E',0};
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
2010-01-14 22:10:22 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
2008-09-03 09:48:49 +02:00
|
|
|
create_xml_file(szBankXML);
|
|
|
|
GetFullPathNameA(szBankXML, MAX_PATH, pathA, NULL);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
url = SysAllocString(path);
|
|
|
|
hr = IXMLDocument_put_URL(doc, url);
|
2008-09-03 09:48:49 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
SysFreeString(url);
|
|
|
|
|
2008-06-18 13:40:06 +02:00
|
|
|
if(hr != S_OK)
|
2008-06-09 14:12:25 +02:00
|
|
|
goto cleanup;
|
|
|
|
|
2007-05-24 20:13:43 +02:00
|
|
|
hr = IXMLDocument_get_root(doc, &element);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_children(element, &collection);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(collection != NULL, "Expected non-NULL collection\n");
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(collection, NULL);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(length == 2, "Expected 2, got %d\n", length);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
/* IXMLElementCollection:put_length does nothing */
|
|
|
|
hr = IXMLElementCollection_put_length(collection, -1);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_put_length(collection, 0);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_put_length(collection, 1);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_put_length(collection, 2);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_put_length(collection, 3);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_put_length(collection, 50);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
|
|
|
|
/* make sure the length hasn't changed */
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(length == 2, "Expected 2, got %d\n", length);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
/* IXMLElementCollection implements IEnumVARIANT */
|
|
|
|
hr = IXMLElementCollection_QueryInterface(collection, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(enumVar != NULL, "Expected non-NULL enumVar\n");
|
|
|
|
IEnumVARIANT_Release(enumVar);
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get__newEnum(collection, &unk);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(unk != NULL, "Expected non-NULL unk\n");
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(enumVar != NULL, "Expected non-NULL enumVar\n");
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
/* <Number>1234</Number> */
|
|
|
|
hr = IEnumVARIANT_Next(enumVar, 1, &var, &num_vars);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var));
|
2008-07-01 23:05:27 +02:00
|
|
|
ok(num_vars == 1, "Expected 1, got %d\n", num_vars);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(V_DISPATCH(&var), &IID_IXMLElement, (LPVOID *)&child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
VariantClear(&var);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, szNumber), "Expected NUMBER\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
|
|
|
/* <Name>Captain Ahab</Name> */
|
|
|
|
hr = IEnumVARIANT_Next(enumVar, 1, &var, &num_vars);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var));
|
2008-07-01 23:05:27 +02:00
|
|
|
ok(num_vars == 1, "Expected 1, got %d\n", num_vars);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
2010-06-21 00:46:23 +02:00
|
|
|
/* try advance further, no children left */
|
|
|
|
hr = IEnumVARIANT_Next(enumVar, 1, &var, &num_vars);
|
|
|
|
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
|
|
|
ok(V_VT(&var) == 0, "Expected 0, got %d\n", V_VT(&var));
|
|
|
|
ok(num_vars == 0, "Expected 0, got %d\n", num_vars);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Next(enumVar, 1, &var, NULL);
|
|
|
|
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
|
|
|
ok(V_VT(&var) == 0, "Expected 0, got %d\n", V_VT(&var));
|
|
|
|
|
2007-05-24 20:13:43 +02:00
|
|
|
hr = IUnknown_QueryInterface(V_DISPATCH(&var), &IID_IXMLElement, (LPVOID *)&child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
VariantClear(&var);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, szName), "Expected NAME\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
|
|
|
/* <Number>1234</Number> */
|
|
|
|
V_VT(&vIndex) = VT_I4;
|
|
|
|
V_I4(&vIndex) = 0;
|
|
|
|
V_VT(&vName) = VT_ERROR;
|
|
|
|
V_ERROR(&vName) = DISP_E_PARAMNOTFOUND;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, szNumber), "Expected NUMBER\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
|
|
|
/* <Name>Captain Ahab</Name> */
|
|
|
|
V_VT(&vIndex) = VT_I4;
|
|
|
|
V_I4(&vIndex) = 1;
|
|
|
|
V_VT(&vName) = VT_ERROR;
|
|
|
|
V_ERROR(&vName) = DISP_E_PARAMNOTFOUND;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 23:28:42 +01:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 20:13:43 +02:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &str);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(!lstrcmpW(str, szName), "Expected NAME\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
|
|
|
V_I4(&vIndex) = 100;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
ok(child == NULL, "Expected NULL child\n");
|
|
|
|
|
|
|
|
V_I4(&vIndex) = -1;
|
|
|
|
child = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
|
2008-07-01 23:05:10 +02:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2007-05-24 20:13:43 +02:00
|
|
|
ok(child == NULL, "Expected NULL child\n");
|
|
|
|
|
2007-12-10 03:05:16 +01:00
|
|
|
IEnumVARIANT_Release(enumVar);
|
2007-05-24 20:13:43 +02:00
|
|
|
IXMLElement_Release(element);
|
|
|
|
IXMLElementCollection_Release(collection);
|
2008-06-09 14:12:25 +02:00
|
|
|
cleanup:
|
2007-05-24 20:13:43 +02:00
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
DeleteFileA("bank.xml");
|
|
|
|
}
|
|
|
|
|
2010-01-14 22:10:22 +01:00
|
|
|
static void test_xmlelem_children(void)
|
|
|
|
{
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
IXMLElement *element = NULL, *child = NULL, *child2 = NULL;
|
|
|
|
IXMLElementCollection *collection = NULL;
|
|
|
|
VARIANT vType, vName, vIndex;
|
|
|
|
LONG length;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_ELEMENT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &element);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_TEXT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &child);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_TEXT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &child2);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child2 != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_addChild(element, child, 0, -1);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_children(element, &collection);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(collection != NULL, "Expected non-NULL collection\n");
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(length == 1, "Expected 1, got %08x\n", length);
|
|
|
|
|
|
|
|
/* remove/add child and check what happens with collection */
|
|
|
|
hr = IXMLElement_removeChild(element, child);
|
2010-01-14 22:13:50 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2010-01-14 22:10:22 +01:00
|
|
|
|
|
|
|
length = -1;
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2010-01-14 22:16:03 +01:00
|
|
|
ok(length == 0, "Expected 0, got %08x\n", length);
|
2010-01-14 22:10:22 +01:00
|
|
|
IXMLElementCollection_Release(collection);
|
|
|
|
|
|
|
|
hr = IXMLElement_AddRef(child);
|
|
|
|
ok(hr == 2, "Expected 2, got %08x\n", hr);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
hr = IXMLElement_addChild(element, child, 0, -1);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
hr = IXMLElement_AddRef(child);
|
|
|
|
ok(hr == 2, "Expected 2, got %08x\n", hr);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
hr = IXMLElement_addChild(element, child2, 0, -1);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElement_get_children(element, &collection);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(collection != NULL, "Expected non-NULL collection\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_AddRef(child);
|
|
|
|
ok(hr == 2, "Expected 2, got %08x\n", hr);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(length == 2, "Expected 2, got %08x\n", length);
|
|
|
|
|
|
|
|
IXMLElement_Release(child2);
|
|
|
|
|
|
|
|
length = 0;
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &length);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(length == 2, "Expected 2, got %08x\n", length);
|
|
|
|
|
|
|
|
V_VT(&vIndex) = VT_I4;
|
|
|
|
V_I4(&vIndex) = 1;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child2);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child2 != NULL, "Expected not NULL child\n");
|
2010-01-14 22:13:50 +01:00
|
|
|
IXMLElementCollection_Release(collection);
|
2010-01-14 22:18:32 +01:00
|
|
|
IXMLElement_Release(child2);
|
2010-01-14 22:13:50 +01:00
|
|
|
|
|
|
|
/* add element->child->child2 structure, then remove child2 from node */
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_TEXT;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &child2);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child2 != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_addChild(child, child2, 0, -1);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElement_removeChild(element, child2);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElement_removeChild(child, child2);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLElement_removeChild(child, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2010-01-14 22:10:22 +01:00
|
|
|
|
|
|
|
IXMLElement_Release(element);
|
|
|
|
IXMLElement_Release(child);
|
2010-01-14 22:13:50 +01:00
|
|
|
IXMLElement_Release(child2);
|
2010-01-14 22:10:22 +01:00
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL test_try_xmldoc(void)
|
|
|
|
{
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
skip("Failed to create XMLDocument instance\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-05-24 20:13:43 +02:00
|
|
|
START_TEST(xmlelem)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
ok(hr == S_OK, "failed to init com\n");
|
|
|
|
|
2010-01-14 22:10:22 +01:00
|
|
|
if (!test_try_xmldoc())
|
|
|
|
{
|
|
|
|
CoUninitialize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-24 20:13:43 +02:00
|
|
|
test_xmlelem();
|
|
|
|
test_xmlelem_collection();
|
2010-01-14 22:10:22 +01:00
|
|
|
test_xmlelem_children();
|
2008-09-01 16:17:06 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
2007-05-24 20:13:43 +02:00
|
|
|
}
|