sync msxml3 with wine 1.1.12 (2/2)

svn path=/trunk/; revision=38554
This commit is contained in:
Christoph von Wittich 2009-01-04 10:48:31 +00:00
parent 29dc01c8e2
commit 02a42aaf0d
8 changed files with 5620 additions and 0 deletions

View file

@ -73,6 +73,9 @@
<directory name="msvcrt">
<xi:include href="msvcrt/msvcrt.rbuild" />
</directory>
<directory name="msxml3">
<xi:include href="msxml3/msxml3.rbuild" />
</directory>
<directory name="netapi32">
<xi:include href="netapi32/netapi32.rbuild" />
</directory>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<group>
<module name="msxml3_winetest" type="win32cui" installbase="bin" installname="msxml3_winetest.exe" allowwarnings="true">
<compilerflag compiler="cc">-Wno-format</compilerflag>
<include base="msxml3_winetest">.</include>
<file>domdoc.c</file>
<file>saxreader.c</file>
<file>schema.c</file>
<file>testlist.c</file>
<file>xmldoc.c</file>
<file>xmlelem.c</file>
<library>wine</library>
<library>user32</library>
<library>ole32</library>
<library>oleaut32</library>
<library>kernel32</library>
<library>ntdll</library>
</module>
</group>

View file

@ -0,0 +1,613 @@
/*
* XML test
*
* Copyright 2008 Piotr Caban
*
* 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
#define CONST_VTABLE
#include <stdio.h>
#include "windows.h"
#include "ole2.h"
#include "msxml2.h"
#include "ocidl.h"
#include "wine/test.h"
typedef enum _CH {
CH_ENDTEST,
CH_PUTDOCUMENTLOCATOR,
CH_STARTDOCUMENT,
CH_ENDDOCUMENT,
CH_STARTPREFIXMAPPING,
CH_ENDPREFIXMAPPING,
CH_STARTELEMENT,
CH_ENDELEMENT,
CH_CHARACTERS,
CH_IGNORABLEWHITESPACE,
CH_PROCESSINGINSTRUCTION,
CH_SKIPPEDENTITY
} CH;
static const WCHAR szSimpleXML[] = {
'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
'<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
'<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
};
static const WCHAR szCarriageRetTest[] = {
'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
'<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
'\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
'\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
'<','/','B','a','n','k','A','c','c','o','u','n','t','>','\0'
};
static const CHAR szTestXML[] =
"<?xml version=\"1.0\" ?>\n"
"<BankAccount>\n"
" <Number>1234</Number>\n"
" <Name>Captain Ahab</Name>\n"
"</BankAccount>\n";
typedef struct _contenthandlercheck {
CH id;
int line;
int column;
const char *arg1;
const char *arg2;
const char *arg3;
} content_handler_test;
static content_handler_test contentHandlerTest1[] = {
{ CH_PUTDOCUMENTLOCATOR, 0, 0 },
{ CH_STARTDOCUMENT, 0, 0 },
{ CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
{ CH_CHARACTERS, 2, 14, "\n " },
{ CH_STARTELEMENT, 3, 12, "", "Number", "Number" },
{ CH_CHARACTERS, 3, 12, "1234" },
{ CH_ENDELEMENT, 3, 18, "", "Number", "Number" },
{ CH_CHARACTERS, 3, 25, "\n " },
{ CH_STARTELEMENT, 4, 10, "", "Name", "Name" },
{ CH_CHARACTERS, 4, 10, "Captain Ahab" },
{ CH_ENDELEMENT, 4, 24, "", "Name", "Name" },
{ CH_CHARACTERS, 4, 29, "\n" },
{ CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
{ CH_ENDDOCUMENT, 0, 0 },
{ CH_ENDTEST }
};
static content_handler_test contentHandlerTest2[] = {
{ CH_PUTDOCUMENTLOCATOR, 0, 0 },
{ CH_STARTDOCUMENT, 0, 0 },
{ CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
{ CH_CHARACTERS, 2, 14, "\n" },
{ CH_CHARACTERS, 2, 16, "\t" },
{ CH_STARTELEMENT, 3, 10, "", "Number", "Number" },
{ CH_CHARACTERS, 3, 10, "1234" },
{ CH_ENDELEMENT, 3, 16, "", "Number", "Number" },
{ CH_CHARACTERS, 3, 23, "\n" },
{ CH_CHARACTERS, 3, 25, "\t" },
{ CH_STARTELEMENT, 4, 8, "", "Name", "Name" },
{ CH_CHARACTERS, 4, 8, "Captain Ahab" },
{ CH_ENDELEMENT, 4, 22, "", "Name", "Name" },
{ CH_CHARACTERS, 4, 27, "\n" },
{ CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
{ CH_ENDDOCUMENT, 0, 0 },
{ CH_ENDTEST }
};
static content_handler_test *expectCall;
static ISAXLocator *locator;
static const char *debugstr_wn(const WCHAR *szStr, int len)
{
static char buf[1024];
WideCharToMultiByte(CP_ACP, 0, szStr, len, buf, sizeof(buf), NULL, NULL);
return buf;
}
static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
{
WCHAR buf[1024];
int len;
if(!szTest) {
ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
return;
}
len = strlen(szTest);
ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
if(len != nStr)
return;
MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
debugstr_wn(szStr, nStr), szTest);
}
static BOOL test_expect_call(CH id)
{
ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
return expectCall->id == id;
}
static void test_locator(unsigned line, int loc_line, int loc_column)
{
int rcolumn, rline;
ISAXLocator_getLineNumber(locator, &rline);
ISAXLocator_getColumnNumber(locator, &rcolumn);
ok_(__FILE__,line) (rline == loc_line,
"unexpected line %d, expected %d\n", rline, loc_line);
ok_(__FILE__,line) (rcolumn == loc_column,
"unexpected column %d, expected %d\n", rcolumn, loc_column);
}
static HRESULT WINAPI contentHandler_QueryInterface(
ISAXContentHandler* iface,
REFIID riid,
void **ppvObject)
{
*ppvObject = NULL;
if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
{
*ppvObject = iface;
}
else
{
return E_NOINTERFACE;
}
return S_OK;
}
static ULONG WINAPI contentHandler_AddRef(
ISAXContentHandler* iface)
{
return 2;
}
static ULONG WINAPI contentHandler_Release(
ISAXContentHandler* iface)
{
return 1;
}
static HRESULT WINAPI contentHandler_putDocumentLocator(
ISAXContentHandler* iface,
ISAXLocator *pLocator)
{
if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
return E_FAIL;
locator = pLocator;
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_startDocument(
ISAXContentHandler* iface)
{
if(!test_expect_call(CH_STARTDOCUMENT))
return E_FAIL;
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_endDocument(
ISAXContentHandler* iface)
{
if(!test_expect_call(CH_ENDDOCUMENT))
return E_FAIL;
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_startPrefixMapping(
ISAXContentHandler* iface,
const WCHAR *pPrefix,
int nPrefix,
const WCHAR *pUri,
int nUri)
{
if(!test_expect_call(CH_ENDDOCUMENT))
return E_FAIL;
test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_endPrefixMapping(
ISAXContentHandler* iface,
const WCHAR *pPrefix,
int nPrefix)
{
if(!test_expect_call(CH_ENDPREFIXMAPPING))
return E_FAIL;
test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_startElement(
ISAXContentHandler* iface,
const WCHAR *pNamespaceUri,
int nNamespaceUri,
const WCHAR *pLocalName,
int nLocalName,
const WCHAR *pQName,
int nQName,
ISAXAttributes *pAttr)
{
if(!test_expect_call(CH_STARTELEMENT))
return E_FAIL;
test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_endElement(
ISAXContentHandler* iface,
const WCHAR *pNamespaceUri,
int nNamespaceUri,
const WCHAR *pLocalName,
int nLocalName,
const WCHAR *pQName,
int nQName)
{
if(!test_expect_call(CH_ENDELEMENT))
return E_FAIL;
test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_characters(
ISAXContentHandler* iface,
const WCHAR *pChars,
int nChars)
{
if(!test_expect_call(CH_CHARACTERS))
return E_FAIL;
test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_ignorableWhitespace(
ISAXContentHandler* iface,
const WCHAR *pChars,
int nChars)
{
if(!test_expect_call(CH_IGNORABLEWHITESPACE))
return E_FAIL;
test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_processingInstruction(
ISAXContentHandler* iface,
const WCHAR *pTarget,
int nTarget,
const WCHAR *pData,
int nData)
{
if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
return E_FAIL;
test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
test_saxstr(__LINE__, pData, nData, expectCall->arg2);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static HRESULT WINAPI contentHandler_skippedEntity(
ISAXContentHandler* iface,
const WCHAR *pName,
int nName)
{
if(!test_expect_call(CH_SKIPPEDENTITY))
return E_FAIL;
test_saxstr(__LINE__, pName, nName, expectCall->arg1);
test_locator(__LINE__, expectCall->line, expectCall->column);
expectCall++;
return S_OK;
}
static const ISAXContentHandlerVtbl contentHandlerVtbl =
{
contentHandler_QueryInterface,
contentHandler_AddRef,
contentHandler_Release,
contentHandler_putDocumentLocator,
contentHandler_startDocument,
contentHandler_endDocument,
contentHandler_startPrefixMapping,
contentHandler_endPrefixMapping,
contentHandler_startElement,
contentHandler_endElement,
contentHandler_characters,
contentHandler_ignorableWhitespace,
contentHandler_processingInstruction,
contentHandler_skippedEntity
};
static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
static HRESULT WINAPI isaxerrorHandler_QueryInterface(
ISAXErrorHandler* iface,
REFIID riid,
void **ppvObject)
{
*ppvObject = NULL;
if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
{
*ppvObject = iface;
}
else
{
return E_NOINTERFACE;
}
return S_OK;
}
static ULONG WINAPI isaxerrorHandler_AddRef(
ISAXErrorHandler* iface)
{
return 2;
}
static ULONG WINAPI isaxerrorHandler_Release(
ISAXErrorHandler* iface)
{
return 1;
}
static HRESULT WINAPI isaxerrorHandler_error(
ISAXErrorHandler* iface,
ISAXLocator *pLocator,
const WCHAR *pErrorMessage,
HRESULT hrErrorCode)
{
return S_OK;
}
static HRESULT WINAPI isaxerrorHandler_fatalError(
ISAXErrorHandler* iface,
ISAXLocator *pLocator,
const WCHAR *pErrorMessage,
HRESULT hrErrorCode)
{
return S_OK;
}
static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
ISAXErrorHandler* iface,
ISAXLocator *pLocator,
const WCHAR *pErrorMessage,
HRESULT hrErrorCode)
{
return S_OK;
}
static const ISAXErrorHandlerVtbl errorHandlerVtbl =
{
isaxerrorHandler_QueryInterface,
isaxerrorHandler_AddRef,
isaxerrorHandler_Release,
isaxerrorHandler_error,
isaxerrorHandler_fatalError,
isaxerrorHanddler_ignorableWarning
};
static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
static void test_saxreader(void)
{
HRESULT hr;
ISAXXMLReader *reader = NULL;
VARIANT var;
ISAXContentHandler *lpContentHandler;
ISAXErrorHandler *lpErrorHandler;
SAFEARRAY *pSA;
SAFEARRAYBOUND SADim[1];
char *pSAData = NULL;
IStream *iStream;
ULARGE_INTEGER liSize;
LARGE_INTEGER liPos;
ULONG bytesWritten;
HANDLE file;
static const CHAR testXmlA[] = "test.xml";
static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
IXMLDOMDocument *domDocument;
BSTR bstrData;
VARIANT_BOOL vBool;
hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
&IID_ISAXXMLReader, (LPVOID*)&reader);
if(FAILED(hr))
{
skip("Failed to create SAXXMLReader instance\n");
return;
}
hr = ISAXXMLReader_getContentHandler(reader, NULL);
ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
hr = ISAXXMLReader_getErrorHandler(reader, NULL);
ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
hr = ISAXXMLReader_putContentHandler(reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString(szSimpleXML);
expectCall = contentHandlerTest1;
hr = ISAXXMLReader_parse(reader, var);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
SADim[0].lLbound= 0;
SADim[0].cElements= sizeof(szTestXML)-1;
pSA = SafeArrayCreate(VT_UI1, 1, SADim);
SafeArrayAccessData(pSA, (void**)&pSAData);
memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
SafeArrayUnaccessData(pSA);
V_VT(&var) = VT_ARRAY|VT_UI1;
V_ARRAY(&var) = pSA;
expectCall = contentHandlerTest1;
hr = ISAXXMLReader_parse(reader, var);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
SafeArrayDestroy(pSA);
CreateStreamOnHGlobal(NULL, TRUE, &iStream);
liSize.QuadPart = strlen(szTestXML);
IStream_SetSize(iStream, liSize);
IStream_Write(iStream, (void const*)szTestXML, strlen(szTestXML), &bytesWritten);
liPos.QuadPart = 0;
IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
V_UNKNOWN(&var) = (IUnknown*)iStream;
expectCall = contentHandlerTest1;
hr = ISAXXMLReader_parse(reader, var);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
IStream_Release(iStream);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString(szCarriageRetTest);
expectCall = contentHandlerTest2;
hr = ISAXXMLReader_parse(reader, var);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
CloseHandle(file);
expectCall = contentHandlerTest1;
hr = ISAXXMLReader_parseURL(reader, testXmlW);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
DeleteFileA(testXmlA);
hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
&IID_IXMLDOMDocument, (LPVOID*)&domDocument);
if(FAILED(hr))
{
skip("Failed to create DOMDocument instance\n");
return;
}
bstrData = SysAllocString(szSimpleXML);
hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
V_VT(&var) = VT_UNKNOWN;
V_UNKNOWN(&var) = (IUnknown*)domDocument;
expectCall = contentHandlerTest2;
hr = ISAXXMLReader_parse(reader, var);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_expect_call(CH_ENDTEST);
IXMLDOMDocument_Release(domDocument);
ISAXXMLReader_Release(reader);
}
START_TEST(saxreader)
{
HRESULT hr;
hr = CoInitialize(NULL);
ok(hr == S_OK, "failed to init com\n");
test_saxreader();
CoUninitialize();
}

View file

@ -0,0 +1,212 @@
/*
* Schema test
*
* Copyright 2007 Huw Davies
*
* 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
*/
#include <stdio.h>
#define COBJMACROS
#include "initguid.h"
#include "windows.h"
#include "ole2.h"
#include "xmldom.h"
#include "msxml2.h"
#include "dispex.h"
#include "wine/test.h"
static const WCHAR schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
static const WCHAR schema_xml[] = {
'<','S','c','h','e','m','a',' ','x','m','l','n','s','=','\"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','x','m','l','-','d','a','t','a','\"','\n',
'x','m','l','n','s',':','d','t','=','\"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','d','a','t','a','t','y','p','e','s','\"','>','\n',
'<','/','S','c','h','e','m','a','>','\n',0
};
static void test_schema_refs(void)
{
IXMLDOMDocument2 *doc;
IXMLDOMSchemaCollection *schema;
HRESULT r;
LONG ref;
VARIANT v;
VARIANT_BOOL b;
BSTR str;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
if( r != S_OK )
return;
r = CoCreateInstance( &CLSID_XMLSchemaCache, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (LPVOID*)&schema );
if( r != S_OK )
{
IXMLDOMDocument2_Release(doc);
return;
}
str = SysAllocString(schema_xml);
r = IXMLDOMDocument2_loadXML(doc, str, &b);
ok(r == S_OK, "ret %08x\n", r);
ok(b == VARIANT_TRUE, "b %04x\n", b);
SysFreeString(str);
ref = IXMLDOMDocument2_AddRef(doc);
ok(ref == 2, "ref %d\n", ref);
VariantInit(&v);
V_VT(&v) = VT_DISPATCH;
V_DISPATCH(&v) = (IDispatch*)doc;
str = SysAllocString(schema_uri);
r = IXMLDOMSchemaCollection_add(schema, str, v);
ok(r == S_OK, "ret %08x\n", r);
/* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
ref = IXMLDOMDocument2_AddRef(doc);
ok(ref == 3, "ref %d\n", ref);
IXMLDOMDocument2_Release(doc);
SysFreeString(str);
VariantClear(&v);
V_VT(&v) = VT_INT;
r = IXMLDOMDocument2_get_schemas(doc, &v);
ok(r == S_FALSE, "ret %08x\n", r);
ok(V_VT(&v) == VT_NULL, "vt %x\n", V_VT(&v));
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 2, "ref %d\n", ref);
V_VT(&v) = VT_DISPATCH;
V_DISPATCH(&v) = (IDispatch*)schema;
/* check that putref_schemas takes a ref */
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == S_OK, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 4, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
VariantClear(&v);
/* refs now 2 */
V_VT(&v) = VT_INT;
/* check that get_schemas adds a ref */
r = IXMLDOMDocument2_get_schemas(doc, &v);
ok(r == S_OK, "ret %08x\n", r);
ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 4, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 3 */
/* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
r = IXMLDOMDocument2_get_schemas(doc, &v);
ok(r == S_OK, "ret %08x\n", r);
ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 5, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 4 */
/* release the two refs returned by get_schemas */
IXMLDOMSchemaCollection_Release(schema);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 2 */
/* check that taking another ref on the document doesn't change the schema's ref count */
IXMLDOMDocument2_AddRef(doc);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 3, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
IXMLDOMDocument2_Release(doc);
/* refs now 2 */
/* call putref_schema with some odd variants */
V_VT(&v) = VT_INT;
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == E_FAIL, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 3, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 2 */
/* calling with VT_EMPTY releases the schema */
V_VT(&v) = VT_EMPTY;
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == S_OK, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 2, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 1 */
/* try setting with VT_UNKNOWN */
IXMLDOMSchemaCollection_AddRef(schema);
V_VT(&v) = VT_UNKNOWN;
V_UNKNOWN(&v) = (IUnknown*)schema;
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == S_OK, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 4, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
VariantClear(&v);
/* refs now 2 */
/* calling with VT_NULL releases the schema */
V_VT(&v) = VT_NULL;
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == S_OK, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 2, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
/* refs now 1 */
/* set again */
IXMLDOMSchemaCollection_AddRef(schema);
V_VT(&v) = VT_UNKNOWN;
V_UNKNOWN(&v) = (IUnknown*)schema;
r = IXMLDOMDocument2_putref_schemas(doc, v);
ok(r == S_OK, "ret %08x\n", r);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 4, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
VariantClear(&v);
/* refs now 2 */
/* release the final ref on the doc which should release its ref on the schema */
IXMLDOMDocument2_Release(doc);
ref = IXMLDOMSchemaCollection_AddRef(schema);
ok(ref == 2, "ref %d\n", ref);
IXMLDOMSchemaCollection_Release(schema);
IXMLDOMSchemaCollection_Release(schema);
}
START_TEST(schema)
{
HRESULT r;
r = CoInitialize( NULL );
ok( r == S_OK, "failed to init com\n");
test_schema_refs();
CoUninitialize();
}

View file

@ -0,0 +1,23 @@
/* Automatically generated file; DO NOT EDIT!! */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define STANDALONE
#include "wine/test.h"
extern void func_domdoc(void);
extern void func_saxreader(void);
extern void func_schema(void);
extern void func_xmldoc(void);
extern void func_xmlelem(void);
const struct test winetest_testlist[] =
{
{ "domdoc", func_domdoc },
{ "saxreader", func_saxreader },
{ "schema", func_schema },
{ "xmldoc", func_xmldoc },
{ "xmlelem", func_xmlelem },
{ 0, 0 }
};

View file

@ -0,0 +1,348 @@
/*
* 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"
/* Deprecated Error Code */
#define XML_E_INVALIDATROOTLEVEL 0xc00ce556
static void create_xml_file(LPCSTR filename)
{
DWORD dwNumberOfBytesWritten;
HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
static const char data[] =
"<?xml version=\"1.0\" ?>\n"
"<BankAccount>\n"
" <Number>1234</Number>\n"
" <Name>Captain Ahab</Name>\n"
"</BankAccount>";
WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
CloseHandle(hf);
}
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;
HGLOBAL hglobal;
HANDLE hfile;
LPVOID ptr;
DWORD file_size, read;
CHAR path[MAX_PATH];
long type, num_child;
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};
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
&IID_IXMLDocument, (LPVOID*)&doc);
if (FAILED(hr))
{
skip("Failed to create XMLDocument instance\n");
return;
}
create_xml_file("bank.xml");
GetFullPathNameA("bank.xml", MAX_PATH, path, NULL);
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);
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");
hr = IXMLDocument_get_root(doc, &element);
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
ok(element == NULL, "Expected NULL element\n");
hr = IPersistStreamInit_Load(psi, stream);
ok(hr == S_OK || hr == XML_E_INVALIDATROOTLEVEL, "Expected S_OK, got %08x\n", hr);
if(hr == XML_E_INVALIDATROOTLEVEL)
goto cleanup;
ok(stream != NULL, "Expected non-NULL stream\n");
hr = IXMLDocument_get_root(doc, &element);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(element != NULL, "Expected non-NULL element\n");
hr = IXMLElement_get_type(element, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(element, &name);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(name, szBankAccount), "Expected BANKACCOUNT\n");
SysFreeString(name);
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 = IXMLElementCollection_get_length(collection, &num_child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(num_child == 2, "Expected 2, got %ld\n", num_child);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &name);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(name, szNumber), "Expected NUMBER\n");
SysFreeString(name);
hr = IXMLElement_get_children(child, &inner);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(inner != NULL, "Expected non-NULL inner\n");
hr = IXMLElementCollection_get_length(inner, &num_child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(num_child == 1, "Expected 1, got %ld\n", num_child);
hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(value != NULL, "Expected non-NULL value\n");
hr = IXMLElement_get_type(value, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %ld\n", type);
hr = IXMLElement_get_text(value, &name);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(name, szNumVal), "Expected '1234'\n");
SysFreeString(name);
IXMLElementCollection_Release(inner);
inner = (IXMLElementCollection *)0xdeadbeef;
hr = IXMLElement_get_children(value, &inner);
ok(hr == 1, "Expected 1, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &name);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(name, szName), "Expected NAME\n");
SysFreeString(name);
hr = IXMLElement_get_children(child, &inner);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(inner != NULL, "Expected non-NULL inner\n");
hr = IXMLElementCollection_get_length(inner, &num_child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(num_child == 1, "Expected 1, got %ld\n", num_child);
V_I4(&vIndex) = 0;
hr = IXMLElementCollection_item(inner, vIndex, vName, (IDispatch **)&value);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(value != NULL, "Expected non-NULL value\n");
hr = IXMLElement_get_type(value, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %ld\n", type);
hr = IXMLElement_get_text(value, &name);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(name, szNameVal), "Expected 'Captain Ahab'\n");
SysFreeString(name);
IXMLElementCollection_Release(inner);
inner = (IXMLElementCollection *)0xdeadbeef;
hr = IXMLElement_get_children(value, &inner);
ok(hr == 1, "Expected 1, got %08x\n", hr);
ok(inner == NULL, "Expected NULL inner, got %p\n", inner);
IXMLElement_Release(value);
IXMLElement_Release(child);
IXMLElementCollection_Release(collection);
IXMLElement_Release(element);
cleanup:
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;
long type;
hr = CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER,
&IID_IXMLDocument, (LPVOID*)&doc);
if (FAILED(hr))
{
skip("Failed to create XMLDocument instance\n");
return;
}
/* invalid vType type */
V_VT(&vType) = VT_NULL;
V_VT(&vName) = VT_NULL;
element = (IXMLElement *)0xdeadbeef;
hr = IXMLDocument_createElement(doc, vType, vName, &element);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
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);
/* Up to and including SP7, createElement returns an element. */
if(hr == S_OK)
{
ok(element != NULL, "Expected element\n");
if (element != NULL)
{
hr = IXMLElement_get_type(element, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* SP7 returns an XMLELEMTYPE_ELEMENT */
ok(type == XMLELEMTYPE_OTHER || type == XMLELEMTYPE_ELEMENT,
"Expected XMLELEMTYPE_OTHER || XMLELEMTYPE_ELEMENT, got %ld\n", type);
IXMLElement_Release(element);
}
}
else
{
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
ok(element == NULL, "Expected NULL element\n");
}
/* 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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(element != NULL, "Expected non-NULL element\n");
hr = IXMLElement_get_type(element, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
ok(root == NULL, "Expected NULL root\n");
IXMLElement_Release(element);
IXMLDocument_Release(doc);
}
START_TEST(xmldoc)
{
HRESULT hr;
hr = CoInitialize(NULL);
ok(hr == S_OK, "failed to init com\n");
test_xmldoc();
test_createElement();
CoUninitialize();
}

View file

@ -0,0 +1,452 @@
/*
* 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"
#define ERROR_URL_NOT_FOUND 0x800c0006
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;
long type, num_child;
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);
if (FAILED(hr))
{
skip("Failed to create XMLDocument instance\n");
return;
}
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");
hr = IXMLElement_get_tagName(element, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(lstrlenW(str) == 0, "Expected empty tag name\n");
SysFreeString(str);
parent = (IXMLElement *)0xdeadbeef;
hr = IXMLElement_get_parent(element, &parent);
ok(hr == 1, "Expected 1, got %08x\n", hr);
ok(parent == NULL, "Expected NULL parent\n");
str = SysAllocString(noexist);
hr = IXMLElement_getAttribute(element, str, &vValue);
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
SysFreeString(str);
SysFreeString(val);
str = SysAllocString(crazyCase2);
hr = IXMLElement_getAttribute(element, str, &vValue);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
SysFreeString(val);
hr = IXMLElement_getAttribute(element, str, &vValue);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* remove now nonexistent attribute */
hr = IXMLElement_removeAttribute(element, str);
ok(hr == S_FALSE, "Expected S_FALSE, got %08x\n", hr);
hr = IXMLElement_getAttribute(element, str, &vValue);
ok(hr == 1, "Expected 1, got %08x\n", hr);
ok(V_VT(&vValue) == VT_EMPTY, "Expected VT_EMPTY, got %d\n", V_VT(&vValue));
ok(V_BSTR(&vValue) == NULL, "Expected null value\n");
SysFreeString(str);
VariantClear(&vValue);
children = (IXMLElementCollection *)0xdeadbeef;
hr = IXMLElement_get_children(element, &children);
ok(hr == 1, "Expected 1, got %08x\n", hr);
ok(children == NULL, "Expected NULL collection\n");
hr = IXMLElement_get_type(element, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_text(element, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(lstrlenW(str) == 0, "Expected empty text\n");
SysFreeString(str);
/* put_text with an ELEMENT */
str = SysAllocString(propVal);
hr = IXMLElement_put_text(element, str);
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
str = SysAllocString(propVal);
hr = IXMLElement_put_text(child, str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
SysFreeString(str);
parent = (IXMLElement *)0xdeadbeef;
hr = IXMLElement_get_parent(child, &parent);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(parent != element, "Expected parent != element\n");
hr = IXMLElement_get_type(parent, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
children = (IXMLElementCollection *)0xdeadbeef;
hr = IXMLElement_get_children(element, &children);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(children != NULL, "Expected non-NULL collection\n");
hr = IXMLElementCollection_get_length(children, &num_child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(num_child == 1, "Expected 1, got %ld\n", num_child);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child2 != NULL, "Expected non-NULL child\n");
hr = IXMLElement_get_type(child2, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_TEXT, "Expected XMLELEMTYPE_TEXT, got %ld\n", type);
hr = IXMLElement_get_text(element, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(str, propVal), "Expected 'val'\n");
SysFreeString(str);
hr = IXMLElement_get_text(child2, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == E_NOTIMPL, "Expected E_NOTIMPL, got %08x\n", hr);
SysFreeString(str);
str = SysAllocString(nextVal);
hr = IXMLElement_put_text(child2, str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
SysFreeString(str);
hr = IXMLElement_get_text(element, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
static const char data[] =
"<?xml version=\"1.0\" ?>\n"
"<BankAccount>\n"
" <Number>1234</Number>\n"
" <Name>Captain Ahab</Name>\n"
"</BankAccount>\n";
WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
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;
CHAR pathA[MAX_PATH];
WCHAR path[MAX_PATH];
long length, type;
ULONG num_vars;
VARIANT var, vIndex, vName;
BSTR url, str;
static const CHAR szBankXML[] = "bank.xml";
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);
if (FAILED(hr))
{
skip("Failed to create XMLDocument instance\n");
return;
}
create_xml_file(szBankXML);
GetFullPathNameA(szBankXML, MAX_PATH, pathA, NULL);
MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
url = SysAllocString(path);
hr = IXMLDocument_put_URL(doc, url);
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr);
SysFreeString(url);
if(hr != S_OK)
goto cleanup;
hr = IXMLDocument_get_root(doc, &element);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(element != NULL, "Expected non-NULL element\n");
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 = IXMLElementCollection_get_length(collection, NULL);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
hr = IXMLElementCollection_get_length(collection, &length);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(length == 2, "Expected 2, got %ld\n", length);
/* 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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(length == 2, "Expected 2, got %ld\n", length);
/* IXMLElementCollection implements IEnumVARIANT */
hr = IXMLElementCollection_QueryInterface(collection, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(enumVar != NULL, "Expected non-NULL enumVar\n");
IEnumVARIANT_Release(enumVar);
hr = IXMLElementCollection_get__newEnum(collection, &unk);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(unk != NULL, "Expected non-NULL unk\n");
hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (LPVOID *)&enumVar);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(enumVar != NULL, "Expected non-NULL enumVar\n");
IUnknown_Release(unk);
/* <Number>1234</Number> */
hr = IEnumVARIANT_Next(enumVar, 1, &var, &num_vars);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var));
ok(num_vars == 1, "Expected 1, got %d\n", num_vars);
hr = IUnknown_QueryInterface(V_DISPATCH(&var), &IID_IXMLElement, (LPVOID *)&child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
VariantClear(&var);
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(!lstrcmpW(str, szNumber), "Expected NUMBER\n");
SysFreeString(str);
IXMLElement_Release(child);
/* <Name>Captain Ahab</Name> */
hr = IEnumVARIANT_Next(enumVar, 1, &var, &num_vars);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(V_VT(&var) == VT_DISPATCH, "Expected VT_DISPATCH, got %d\n", V_VT(&var));
ok(num_vars == 1, "Expected 1, got %d\n", num_vars);
hr = IUnknown_QueryInterface(V_DISPATCH(&var), &IID_IXMLElement, (LPVOID *)&child);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
VariantClear(&var);
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(child != NULL, "Expected non-NULL child\n");
hr = IXMLElement_get_type(child, &type);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(type == XMLELEMTYPE_ELEMENT, "Expected XMLELEMTYPE_ELEMENT, got %ld\n", type);
hr = IXMLElement_get_tagName(child, &str);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
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);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
ok(child == NULL, "Expected NULL child\n");
IEnumVARIANT_Release(enumVar);
IXMLElement_Release(element);
IXMLElementCollection_Release(collection);
cleanup:
IXMLDocument_Release(doc);
DeleteFileA("bank.xml");
}
START_TEST(xmlelem)
{
HRESULT hr;
hr = CoInitialize(NULL);
ok(hr == S_OK, "failed to init com\n");
test_xmlelem();
test_xmlelem_collection();
CoUninitialize();
}