xmllite/writer: Initial implementation of WriteStartElement().
This commit is contained in:
parent
05a80d0f18
commit
2177403b8e
|
@ -410,6 +410,7 @@ static void test_bom(void)
|
||||||
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
|
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
|
||||||
static const WCHAR utf16W[] = {'u','t','f','-','1','6',0};
|
static const WCHAR utf16W[] = {'u','t','f','-','1','6',0};
|
||||||
static const WCHAR xmlW[] = {'x','m','l',0};
|
static const WCHAR xmlW[] = {'x','m','l',0};
|
||||||
|
static const WCHAR aW[] = {'a',0};
|
||||||
IXmlWriterOutput *output;
|
IXmlWriterOutput *output;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
IXmlWriter *writer;
|
IXmlWriter *writer;
|
||||||
|
@ -473,8 +474,98 @@ static void test_bom(void)
|
||||||
GlobalUnlock(hglobal);
|
GlobalUnlock(hglobal);
|
||||||
|
|
||||||
IUnknown_Release(output);
|
IUnknown_Release(output);
|
||||||
IXmlWriter_Release(writer);
|
|
||||||
IStream_Release(stream);
|
IStream_Release(stream);
|
||||||
|
|
||||||
|
/* start with element */
|
||||||
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = pCreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
|
||||||
|
ok(hr == S_OK, "got %08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_SetOutput(writer, output);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_Flush(writer);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
ptr = GlobalLock(hglobal);
|
||||||
|
ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
|
||||||
|
GlobalUnlock(hglobal);
|
||||||
|
|
||||||
|
IUnknown_Release(output);
|
||||||
|
IStream_Release(stream);
|
||||||
|
|
||||||
|
IXmlWriter_Release(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_writestartelement(void)
|
||||||
|
{
|
||||||
|
static const WCHAR aW[] = {'a',0};
|
||||||
|
char *ptr;
|
||||||
|
IXmlWriter *writer;
|
||||||
|
IStream *stream;
|
||||||
|
HGLOBAL hglobal;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
||||||
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
||||||
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, aW, NULL, NULL);
|
||||||
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, NULL);
|
||||||
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, aW);
|
||||||
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
||||||
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_Flush(writer);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
ptr = GlobalLock(hglobal);
|
||||||
|
ok(!strncmp(ptr, "<a", 2), "got %s\n", ptr);
|
||||||
|
GlobalUnlock(hglobal);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
||||||
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
/* write another element without closing previous one */
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
||||||
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, NULL);
|
||||||
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXmlWriter_WriteProcessingInstruction(writer, aW, aW);
|
||||||
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
IStream_Release(stream);
|
||||||
|
IXmlWriter_Release(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(writer)
|
START_TEST(writer)
|
||||||
|
@ -485,6 +576,7 @@ START_TEST(writer)
|
||||||
test_writer_create();
|
test_writer_create();
|
||||||
test_writeroutput();
|
test_writeroutput();
|
||||||
test_writestartdocument();
|
test_writestartdocument();
|
||||||
|
test_writestartelement();
|
||||||
test_flush();
|
test_flush();
|
||||||
test_omitxmldeclaration();
|
test_omitxmldeclaration();
|
||||||
test_bom();
|
test_bom();
|
||||||
|
|
|
@ -51,7 +51,8 @@ typedef enum
|
||||||
XmlWriterState_Initial, /* output is not set yet */
|
XmlWriterState_Initial, /* output is not set yet */
|
||||||
XmlWriterState_Ready, /* SetOutput() was called, ready to start */
|
XmlWriterState_Ready, /* SetOutput() was called, ready to start */
|
||||||
XmlWriterState_PIDocStarted, /* document was started with manually added 'xml' PI */
|
XmlWriterState_PIDocStarted, /* document was started with manually added 'xml' PI */
|
||||||
XmlWriterState_DocStarted /* document was started with WriteStartDocument() */
|
XmlWriterState_DocStarted, /* document was started with WriteStartDocument() */
|
||||||
|
XmlWriterState_ElemStarted /* writing element */
|
||||||
} XmlWriterState;
|
} XmlWriterState;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -593,11 +594,19 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP
|
||||||
|
|
||||||
TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(text));
|
TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_w(name), wine_dbgstr_w(text));
|
||||||
|
|
||||||
if (This->state == XmlWriterState_Initial)
|
switch (This->state)
|
||||||
|
{
|
||||||
|
case XmlWriterState_Initial:
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
|
case XmlWriterState_DocStarted:
|
||||||
if (This->state == XmlWriterState_DocStarted && !strcmpW(name, xmlW))
|
if (!strcmpW(name, xmlW))
|
||||||
|
return WR_E_INVALIDACTION;
|
||||||
|
break;
|
||||||
|
case XmlWriterState_ElemStarted:
|
||||||
return WR_E_INVALIDACTION;
|
return WR_E_INVALIDACTION;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
write_encoding_bom(This);
|
write_encoding_bom(This);
|
||||||
write_output_buffer(This->output, openpiW, sizeof(openpiW)/sizeof(WCHAR));
|
write_output_buffer(This->output, openpiW, sizeof(openpiW)/sizeof(WCHAR));
|
||||||
|
@ -656,6 +665,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
|
||||||
This->state = XmlWriterState_DocStarted;
|
This->state = XmlWriterState_DocStarted;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
case XmlWriterState_DocStarted:
|
case XmlWriterState_DocStarted:
|
||||||
|
case XmlWriterState_ElemStarted:
|
||||||
return WR_E_INVALIDACTION;
|
return WR_E_INVALIDACTION;
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
|
@ -690,15 +700,36 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pwszPrefix,
|
static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR prefix, LPCWSTR local_name, LPCWSTR uri)
|
||||||
LPCWSTR pwszLocalName, LPCWSTR pwszNamespaceUri)
|
|
||||||
{
|
{
|
||||||
xmlwriter *This = impl_from_IXmlWriter(iface);
|
xmlwriter *This = impl_from_IXmlWriter(iface);
|
||||||
|
static const WCHAR ltW[] = {'<'};
|
||||||
|
|
||||||
FIXME("%p %s %s %s\n", This, wine_dbgstr_w(pwszPrefix), wine_dbgstr_w(pwszLocalName),
|
TRACE("(%p)->(%s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri));
|
||||||
wine_dbgstr_w(pwszNamespaceUri));
|
|
||||||
|
|
||||||
return E_NOTIMPL;
|
if (This->state == XmlWriterState_Initial)
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
|
||||||
|
if (!local_name)
|
||||||
|
return E_INVALIDARG;
|
||||||
|
|
||||||
|
if (This->state == XmlWriterState_ElemStarted)
|
||||||
|
return WR_E_INVALIDACTION;
|
||||||
|
|
||||||
|
write_encoding_bom(This);
|
||||||
|
This->state = XmlWriterState_ElemStarted;
|
||||||
|
|
||||||
|
write_output_buffer(This->output, ltW, 1);
|
||||||
|
|
||||||
|
if (prefix) {
|
||||||
|
static const WCHAR colW[] = {':'};
|
||||||
|
write_output_buffer(This->output, prefix, -1);
|
||||||
|
write_output_buffer(This->output, colW, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
write_output_buffer(This->output, local_name, -1);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, LPCWSTR pwszText)
|
static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, LPCWSTR pwszText)
|
||||||
|
|
Loading…
Reference in New Issue