2007-05-24 18:23:10 +00:00
|
|
|
/*
|
|
|
|
* IXMLDocument 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 "msxml2.h"
|
|
|
|
#include "ocidl.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2008-06-09 12:12:25 +00:00
|
|
|
/* Deprecated Error Code */
|
|
|
|
#define XML_E_INVALIDATROOTLEVEL 0xc00ce556
|
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
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 03:40:28 +00:00
|
|
|
static const char data[] =
|
|
|
|
"<?xml version=\"1.0\" ?>\n"
|
2010-01-10 19:22:06 +00:00
|
|
|
"<!DOCTYPE BankAccount>\n"
|
2008-12-05 03:40:28 +00:00
|
|
|
"<BankAccount>\n"
|
|
|
|
" <Number>1234</Number>\n"
|
|
|
|
" <Name>Captain Ahab</Name>\n"
|
|
|
|
"</BankAccount>";
|
2007-05-24 18:23:10 +00:00
|
|
|
|
2008-12-05 03:40:28 +00:00
|
|
|
WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
|
2007-05-24 18:23:10 +00:00
|
|
|
CloseHandle(hf);
|
|
|
|
}
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
static void create_stream_on_file(IStream **stream, LPCSTR path)
|
|
|
|
{
|
|
|
|
HANDLE hfile;
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
LPVOID ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD file_size, read;
|
|
|
|
|
|
|
|
hfile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n");
|
|
|
|
file_size = GetFileSize(hfile, NULL);
|
|
|
|
|
|
|
|
hglobal = GlobalAlloc(GHND, file_size);
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
|
|
|
|
ReadFile(hfile, ptr, file_size, &read, NULL);
|
|
|
|
ok(file_size == read, "Expected to read the whole file, read %d\n", read);
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(hglobal, TRUE, stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(*stream != NULL, "Expected non-NULL stream\n");
|
|
|
|
|
|
|
|
CloseHandle(hfile);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
}
|
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
static void test_xmldoc(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
IXMLElement *element = NULL, *child = NULL, *value = NULL;
|
|
|
|
IXMLElementCollection *collection = NULL, *inner = NULL;
|
|
|
|
IPersistStreamInit *psi = NULL;
|
|
|
|
IStream *stream = NULL;
|
|
|
|
CHAR path[MAX_PATH];
|
2009-03-09 22:28:42 +00:00
|
|
|
LONG type, num_child;
|
2007-05-24 18:23:10 +00:00
|
|
|
VARIANT vIndex, vName;
|
|
|
|
BSTR name = NULL;
|
|
|
|
|
|
|
|
static const WCHAR szBankAccount[] = {'B','A','N','K','A','C','C','O','U','N','T',0};
|
|
|
|
static const WCHAR szNumber[] = {'N','U','M','B','E','R',0};
|
|
|
|
static const WCHAR szNumVal[] = {'1','2','3','4',0};
|
|
|
|
static const WCHAR szName[] = {'N','A','M','E',0};
|
|
|
|
static const WCHAR szNameVal[] = {'C','a','p','t','a','i','n',' ','A','h','a','b',0};
|
2010-01-10 18:08:21 +00:00
|
|
|
static const WCHAR szVersion[] = {'1','.','0',0};
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
2010-01-12 00:48:00 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
create_xml_file("bank.xml");
|
|
|
|
GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
|
2010-01-12 00:48:00 +00:00
|
|
|
create_stream_on_file(&stream, path);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLDocument_QueryInterface(doc, &IID_IPersistStreamInit, (LPVOID *)&psi);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(psi != NULL, "Expected non-NULL psi\n");
|
|
|
|
|
|
|
|
hr = IXMLDocument_get_root(doc, &element);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(element == NULL, "Expected NULL element\n");
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_Load(psi, stream);
|
2008-06-09 12:12:25 +00:00
|
|
|
ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Expected S_OK, got %08x\n", hr);
|
|
|
|
if(hr == XML_E_INVALIDATROOTLEVEL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(stream != NULL, "Expected non-NULL stream\n");
|
|
|
|
|
2010-01-10 18:08:21 +00:00
|
|
|
/* version field */
|
|
|
|
hr = IXMLDocument_get_version(doc, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLDocument_get_version(doc, &name);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(!lstrcmpW(name, szVersion), "Expected 1.0, got %s\n", wine_dbgstr_w(name));
|
|
|
|
SysFreeString(name);
|
2010-01-10 19:22:06 +00:00
|
|
|
|
|
|
|
/* doctype */
|
|
|
|
hr = IXMLDocument_get_doctype(doc, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLDocument_get_doctype(doc, &name);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(!lstrcmpW(name, szBankAccount), "Expected BANKACCOUNT, got %s\n", wine_dbgstr_w(name));
|
|
|
|
SysFreeString(name);
|
2010-01-10 18:08:21 +00:00
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
hr = IXMLDocument_get_root(doc, &element);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
2010-01-14 21:10:22 +00:00
|
|
|
/* ::root() returns new instance each time */
|
|
|
|
hr = IXMLDocument_get_root(doc, &child);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(child != NULL, "Expected non-NULL element\n");
|
|
|
|
ok(child != element, "Expected new element instance\n");
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
hr = IXMLElement_get_type(element, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(element, &name);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(!lstrcmpW(name, szBankAccount), "Expected BANKACCOUNT\n");
|
2007-11-14 10:45:29 +00:00
|
|
|
SysFreeString(name);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_children(element, &collection);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(collection != NULL, "Expected non-NULL collection\n");
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(collection, &num_child);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(num_child == 2, "Expected 2, got %d\n", num_child);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
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 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &name);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(!lstrcmpW(name, szNumber), "Expected NUMBER\n");
|
2007-11-14 10:45:29 +00:00
|
|
|
SysFreeString(name);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_children(child, &inner);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(inner != NULL, "Expected non-NULL inner\n");
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(inner, &num_child);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(num_child == 1, "Expected 1, got %d\n", num_child);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(value != NULL, "Expected non-NULL value\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(value, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_text(value, &name);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(!lstrcmpW(name, szNumVal), "Expected '1234'\n");
|
2007-11-14 10:45:29 +00:00
|
|
|
SysFreeString(name);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
IXMLElementCollection_Release(inner);
|
|
|
|
|
|
|
|
inner = (IXMLElementCollection *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_children(value, &inner);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == 1, "Expected 1, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(inner == NULL, "Expected NULL inner, got %p\n", inner);
|
|
|
|
|
|
|
|
IXMLElement_Release(value);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
value = NULL;
|
|
|
|
child = NULL;
|
|
|
|
|
|
|
|
V_I4(&vIndex) = 1;
|
|
|
|
hr = IXMLElementCollection_item(collection, vIndex, vName, (IDispatch **)&child);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(child != NULL, "Expected non-NULL child\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(child, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_tagName(child, &name);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(!lstrcmpW(name, szName), "Expected NAME\n");
|
2007-11-14 10:45:29 +00:00
|
|
|
SysFreeString(name);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_children(child, &inner);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(inner != NULL, "Expected non-NULL inner\n");
|
|
|
|
|
|
|
|
hr = IXMLElementCollection_get_length(inner, &num_child);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(num_child == 1, "Expected 1, got %d\n", num_child);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
V_I4(&vIndex) = 0;
|
|
|
|
hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(value != NULL, "Expected non-NULL value\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(value, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = IXMLElement_get_text(value, &name);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(!lstrcmpW(name, szNameVal), "Expected 'Captain Ahab'\n");
|
2007-11-14 10:45:29 +00:00
|
|
|
SysFreeString(name);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
IXMLElementCollection_Release(inner);
|
|
|
|
|
|
|
|
inner = (IXMLElementCollection *)0xdeadbeef;
|
|
|
|
hr = IXMLElement_get_children(value, &inner);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == 1, "Expected 1, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(inner == NULL, "Expected NULL inner, got %p\n", inner);
|
|
|
|
|
|
|
|
IXMLElement_Release(value);
|
|
|
|
IXMLElement_Release(child);
|
|
|
|
IXMLElementCollection_Release(collection);
|
|
|
|
IXMLElement_Release(element);
|
2008-06-09 12:12:25 +00:00
|
|
|
cleanup:
|
2007-05-24 18:23:10 +00:00
|
|
|
IStream_Release(stream);
|
|
|
|
IPersistStreamInit_Release(psi);
|
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
|
|
|
|
DeleteFileA("bank.xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_createElement(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IXMLDocument *doc = NULL;
|
|
|
|
IXMLElement *element = NULL, *root = NULL;
|
|
|
|
VARIANT vType, vName;
|
2009-03-09 22:28:42 +00:00
|
|
|
LONG type;
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
2010-01-12 00:48:00 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
/* invalid vType type */
|
|
|
|
V_VT(&vType) = VT_NULL;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
element = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &element);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(element == NULL, "Expected NULL element\n");
|
|
|
|
|
|
|
|
/* invalid vType value */
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = -1;
|
|
|
|
V_VT(&vName) = VT_NULL;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &element);
|
2008-03-01 20:10:38 +00:00
|
|
|
/* Up to and including SP7, createElement returns an element. */
|
2008-02-12 19:56:09 +00:00
|
|
|
if(hr == S_OK)
|
2007-07-11 22:11:59 +00:00
|
|
|
{
|
2008-02-12 19:56:09 +00:00
|
|
|
ok(element != NULL, "Expected element\n");
|
|
|
|
if (element != NULL)
|
|
|
|
{
|
|
|
|
hr = IXMLElement_get_type(element, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2008-02-12 19:56:09 +00:00
|
|
|
/* SP7 returns an XMLELEMTYPE_ELEMENT */
|
|
|
|
ok(type == XMLELEMTYPE_OTHER || type == XMLELEMTYPE_ELEMENT,
|
2009-03-09 22:28:42 +00:00
|
|
|
"Expected XMLELEMTYPE_OTHER || XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2008-02-12 19:56:09 +00:00
|
|
|
|
|
|
|
IXMLElement_Release(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
2008-02-12 19:56:09 +00:00
|
|
|
ok(element == NULL, "Expected NULL element\n");
|
2007-07-11 22:11:59 +00:00
|
|
|
}
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
/* invalid vName type */
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_ELEMENT;
|
|
|
|
V_VT(&vName) = VT_I4;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, &element);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
|
|
|
hr = IXMLElement_get_type(element, &type);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2009-03-09 22:28:42 +00:00
|
|
|
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %d\n", type);
|
2007-05-24 18:23:10 +00:00
|
|
|
|
|
|
|
IXMLElement_Release(element);
|
|
|
|
|
|
|
|
/* NULL element */
|
|
|
|
V_VT(&vType) = VT_I4;
|
|
|
|
V_I4(&vType) = XMLELEMTYPE_ELEMENT;
|
|
|
|
V_VT(&vName) = VT_I4;
|
|
|
|
hr = IXMLDocument_createElement(doc, vType, vName, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
root = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLDocument_get_root(doc, &root);
|
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
|
|
|
ok(root == NULL, "Expected NULL root\n");
|
|
|
|
|
|
|
|
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 21:05:10 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(element != NULL, "Expected non-NULL element\n");
|
|
|
|
|
|
|
|
/* createElement does not set the new element as root */
|
|
|
|
root = (IXMLElement *)0xdeadbeef;
|
|
|
|
hr = IXMLDocument_get_root(doc, &root);
|
2008-07-01 21:05:10 +00:00
|
|
|
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
|
2007-05-24 18:23:10 +00:00
|
|
|
ok(root == NULL, "Expected NULL root\n");
|
|
|
|
|
|
|
|
IXMLElement_Release(element);
|
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
}
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
static void test_persiststreaminit(void)
|
|
|
|
{
|
|
|
|
IXMLDocument *doc = NULL;
|
2010-01-12 21:30:46 +00:00
|
|
|
IXMLElement *element = NULL;
|
2010-01-12 00:48:00 +00:00
|
|
|
IPersistStreamInit *psi = NULL;
|
|
|
|
IStream *stream = NULL;
|
|
|
|
STATSTG stat;
|
|
|
|
HRESULT hr;
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
CHAR path[MAX_PATH];
|
2010-01-12 01:13:15 +00:00
|
|
|
CLSID id;
|
2010-01-12 21:30:46 +00:00
|
|
|
BSTR str;
|
|
|
|
static const WCHAR testW[] = {'t','e','s','t',0};
|
2010-01-12 00:48:00 +00:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IXMLDocument, (LPVOID*)&doc);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXMLDocument_QueryInterface(doc, &IID_IPersistStreamInit, (LPVOID *)&psi);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(psi != NULL, "Expected non-NULL psi\n");
|
|
|
|
|
|
|
|
/* null arguments */
|
|
|
|
hr = IPersistStreamInit_GetSizeMax(psi, NULL);
|
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_Load(psi, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_Save(psi, NULL, FALSE);
|
|
|
|
todo_wine ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
2010-01-12 01:13:15 +00:00
|
|
|
hr = IPersistStreamInit_GetClassID(psi, NULL);
|
2010-01-12 21:30:46 +00:00
|
|
|
ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_IsDirty(psi);
|
|
|
|
todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
2010-01-12 01:13:15 +00:00
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
create_xml_file("bank.xml");
|
|
|
|
GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
|
|
|
|
create_stream_on_file(&stream, path);
|
|
|
|
|
|
|
|
/* GetSizeMax not implemented */
|
|
|
|
size.QuadPart = 0;
|
|
|
|
hr = IPersistStreamInit_GetSizeMax(psi, &size);
|
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
|
|
|
ok(size.QuadPart == 0, "Expected 0\n");
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_Load(psi, stream);
|
|
|
|
IStream_Release(stream);
|
|
|
|
ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Expected S_OK, got %08x\n", hr);
|
|
|
|
if(hr == XML_E_INVALIDATROOTLEVEL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-01-12 21:30:46 +00:00
|
|
|
hr = IPersistStreamInit_IsDirty(psi);
|
|
|
|
todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
/* try to save document */
|
|
|
|
stream = NULL;
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
hr = IPersistStreamInit_Save(psi, stream, FALSE);
|
|
|
|
todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
stat.cbSize.QuadPart = 0;
|
|
|
|
hr = IStream_Stat(stream, &stat, 0);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2010-01-12 21:30:46 +00:00
|
|
|
str = SysAllocString(testW);
|
|
|
|
hr = IXMLDocument_get_root(doc, &element);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
hr = IXMLElement_put_text(element, str);
|
2011-02-09 21:43:41 +00:00
|
|
|
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
|
2010-01-20 23:24:29 +00:00
|
|
|
IXMLElement_Release(element);
|
2010-01-12 21:30:46 +00:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_IsDirty(psi);
|
|
|
|
todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
|
|
|
|
2010-01-12 21:33:03 +00:00
|
|
|
create_stream_on_file(&stream, path);
|
|
|
|
hr = IPersistStreamInit_Load(psi, stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_IsDirty(psi);
|
|
|
|
todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
/* reset internal stream */
|
|
|
|
hr = IPersistStreamInit_InitNew(psi);
|
2010-01-12 21:30:46 +00:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_IsDirty(psi);
|
|
|
|
todo_wine ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
|
2010-01-12 00:48:00 +00:00
|
|
|
|
|
|
|
stream = NULL;
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IPersistStreamInit_Save(psi, stream, FALSE);
|
|
|
|
todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
stat.cbSize.QuadPart = 0;
|
|
|
|
hr = IStream_Stat(stream, &stat, 0);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
todo_wine ok(stat.cbSize.QuadPart > 0, "Expected >0\n");
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2010-01-12 01:13:15 +00:00
|
|
|
memset(&id, 0, sizeof(id));
|
|
|
|
hr = IPersistStreamInit_GetClassID(psi, &id);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(IsEqualCLSID(&id, &CLSID_XMLDocument), "Expected CLSID_XMLDocument\n");
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
cleanup:
|
|
|
|
IPersistStreamInit_Release(psi);
|
|
|
|
IXMLDocument_Release(doc);
|
|
|
|
DeleteFileA("bank.xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
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 18:23:10 +00:00
|
|
|
START_TEST(xmldoc)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
ok(hr == S_OK, "failed to init com\n");
|
|
|
|
|
2010-01-12 00:48:00 +00:00
|
|
|
if (!test_try_xmldoc())
|
|
|
|
{
|
|
|
|
CoUninitialize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-24 18:23:10 +00:00
|
|
|
test_xmldoc();
|
|
|
|
test_createElement();
|
2010-01-12 00:48:00 +00:00
|
|
|
test_persiststreaminit();
|
2008-09-01 14:17:00 +00:00
|
|
|
|
|
|
|
CoUninitialize();
|
2007-05-24 18:23:10 +00:00
|
|
|
}
|