msxml3/tests: Some encoding switching tests.

This commit is contained in:
Nikolay Sivov 2010-10-29 01:00:44 +04:00 committed by Alexandre Julliard
parent 0140a8aacc
commit 843bd25012
3 changed files with 97 additions and 15 deletions

View File

@ -1241,16 +1241,19 @@ static void libxmlSetDocumentLocator(
xmlSAXLocatorPtr loc)
{
saxlocator *This = ctx;
HRESULT hr;
HRESULT hr = S_OK;
if(This->vbInterface)
hr = IVBSAXContentHandler_putref_documentLocator(
This->saxreader->vbcontentHandler,
(IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
else
hr = ISAXContentHandler_putDocumentLocator(
This->saxreader->contentHandler,
(ISAXLocator*)&This->lpSAXLocatorVtbl);
if(has_content_handler(This))
{
if(This->vbInterface)
hr = IVBSAXContentHandler_putref_documentLocator(
This->saxreader->vbcontentHandler,
(IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
else
hr = ISAXContentHandler_putDocumentLocator(
This->saxreader->contentHandler,
(ISAXLocator*)&This->lpSAXLocatorVtbl);
}
if(FAILED(hr))
format_error_message_from_id(This, hr);

View File

@ -29,6 +29,8 @@
#include "wine/test.h"
#include "initguid.h"
typedef enum _CH {
CH_ENDTEST,
CH_PUTDOCUMENTLOCATOR,
@ -44,6 +46,8 @@ typedef enum _CH {
CH_SKIPPEDENTITY
} CH;
DEFINE_GUID(CLSID_SAXXMLReader60, 0x88d96a0c, 0xf192, 0x11d4, 0xa6,0x5f, 0x00,0x40,0x96,0x32,0x51,0xe5);
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',
@ -478,12 +482,7 @@ static void test_saxreader(void)
hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
&IID_ISAXXMLReader, (LPVOID*)&reader);
if(FAILED(hr))
{
skip("Failed to create SAXXMLReader instance\n");
return;
}
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = ISAXXMLReader_getContentHandler(reader, NULL);
ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
@ -598,14 +597,86 @@ static void test_saxreader(void)
SysFreeString(bstrData);
}
/* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
static const CHAR UTF8BOMTest[] =
"\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
"<a></a>\n";
struct enc_test_entry_t {
const GUID *guid;
const char *clsid;
const char *data;
HRESULT hr;
int todo;
};
static const struct enc_test_entry_t encoding_test_data[] = {
{ &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
{ &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
{ &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
{ &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
{ 0 }
};
static void test_encoding(void)
{
const struct enc_test_entry_t *entry = encoding_test_data;
static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
static const CHAR testXmlA[] = "test.xml";
ISAXXMLReader *reader;
DWORD written;
HANDLE file;
HRESULT hr;
while (entry->guid)
{
hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
if (hr != S_OK)
{
win_skip("can't create %s instance\n", entry->clsid);
entry++;
continue;
}
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, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
CloseHandle(file);
hr = ISAXXMLReader_parseURL(reader, testXmlW);
if (entry->todo)
todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
else
ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
DeleteFileA(testXmlA);
ISAXXMLReader_Release(reader);
entry++;
}
}
START_TEST(saxreader)
{
ISAXXMLReader *reader;
HRESULT hr;
hr = CoInitialize(NULL);
ok(hr == S_OK, "failed to init com\n");
hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
&IID_ISAXXMLReader, (void**)&reader);
if(FAILED(hr))
{
skip("Failed to create SAXXMLReader instance\n");
CoUninitialize();
return;
}
ISAXXMLReader_Release(reader);
test_saxreader();
test_encoding();
CoUninitialize();
}

View File

@ -370,6 +370,14 @@ static struct regsvr_coclass const coclass_list[] = {
"Msxml2.MXXMLWriter",
"6.0"
},
{ &CLSID_SAXXMLReader60,
"SAX XML Reader 6.0",
NULL,
"msxml6.dll",
"Both",
"Msxml2.SAXXMLReader.6.0",
"6.0"
},
{ &CLSID_SAXAttributes60,
"SAX Attribute 6.0",
NULL,