2008-07-08 20:53:43 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2008-07-10 15:22:14 +02:00
|
|
|
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'
|
|
|
|
};
|
|
|
|
|
2008-07-08 20:53:43 +02:00
|
|
|
typedef struct _contenthandler
|
|
|
|
{
|
|
|
|
const struct ISAXContentHandlerVtbl *lpContentHandlerVtbl;
|
|
|
|
} contenthandler;
|
|
|
|
|
|
|
|
static inline contenthandler *impl_from_ISAXContentHandler(ISAXContentHandler *iface)
|
|
|
|
{
|
|
|
|
return (contenthandler *)((char*)iface - FIELD_OFFSET(contenthandler, lpContentHandlerVtbl));
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return 2;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI contentHandler_Release(
|
|
|
|
ISAXContentHandler* iface)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return 1;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_putDocumentLocator(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
ISAXLocator *pLocator)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_startDocument(
|
|
|
|
ISAXContentHandler* iface)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_endDocument(
|
|
|
|
ISAXContentHandler* iface)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_startPrefixMapping(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pPrefix,
|
|
|
|
int nPrefix,
|
|
|
|
const WCHAR *pUri,
|
|
|
|
int nUri)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_endPrefixMapping(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pPrefix,
|
|
|
|
int nPrefix)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_startElement(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pNamespaceUri,
|
|
|
|
int nNamespaceUri,
|
|
|
|
const WCHAR *pLocalName,
|
|
|
|
int nLocalName,
|
|
|
|
const WCHAR *pQName,
|
|
|
|
int nQName,
|
|
|
|
ISAXAttributes *pAttr)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_endElement(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pNamespaceUri,
|
|
|
|
int nNamespaceUri,
|
|
|
|
const WCHAR *pLocalName,
|
|
|
|
int nLocalName,
|
|
|
|
const WCHAR *pQName,
|
|
|
|
int nQName)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_characters(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pChars,
|
|
|
|
int nChars)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_ignorableWhitespace(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pChars,
|
|
|
|
int nChars)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_processingInstruction(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pTarget,
|
|
|
|
int nTarget,
|
|
|
|
const WCHAR *pData,
|
|
|
|
int nData)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI contentHandler_skippedEntity(
|
|
|
|
ISAXContentHandler* iface,
|
|
|
|
const WCHAR *pName,
|
|
|
|
int nName)
|
|
|
|
{
|
2008-07-10 15:22:14 +02:00
|
|
|
return S_OK;
|
2008-07-08 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 void test_saxreader(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ISAXXMLReader *reader = NULL;
|
2008-07-10 15:22:14 +02:00
|
|
|
VARIANT var;
|
|
|
|
ISAXContentHandler *lpContentHandler;
|
2008-07-08 20:53:43 +02:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_ISAXXMLReader, (LPVOID*)&reader);
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
skip("Failed to create SAXXMLReader instance\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-10 15:22:14 +02:00
|
|
|
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_putContentHandler(reader, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2008-07-08 20:53:43 +02:00
|
|
|
hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2008-07-10 15:22:14 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
hr = ISAXXMLReader_parse(reader, var);
|
|
|
|
todo_wine {
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
}
|
|
|
|
|
2008-07-08 20:53:43 +02:00
|
|
|
ISAXXMLReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(saxreader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
ok(hr == S_OK, "failed to init com\n");
|
|
|
|
|
|
|
|
test_saxreader();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|