static void test_writeendelement(void) { static const WCHAR aW[] = {'a',0}; static const WCHAR bW[] = {'b',0}; IXmlWriter *writer; IStream *stream; HRESULT hr; hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); stream = writer_set_output(writer); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "got 0x%08x\n", hr); CHECK_OUTPUT(stream, "<a><b /></a>"); IXmlWriter_Release(writer); IStream_Release(stream); }
static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface) { xmlwriter *This = impl_from_IXmlWriter(iface); HRESULT hr = S_OK; TRACE("%p\n", This); switch (This->state) { case XmlWriterState_Initial: hr = E_UNEXPECTED; break; case XmlWriterState_Ready: case XmlWriterState_DocClosed: hr = WR_E_INVALIDACTION; break; default: ; } if (FAILED(hr)) { This->state = XmlWriterState_DocClosed; return hr; } /* empty element stack */ while (IXmlWriter_WriteEndElement(iface) == S_OK) ; This->state = XmlWriterState_DocClosed; return S_OK; }
static void test_writeendelement(void) { static const WCHAR aW[] = {'a',0}; static const WCHAR bW[] = {'b',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_SetOutput(writer, (IUnknown*)stream); 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_WriteStartElement(writer, NULL, bW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = GetHGlobalFromStream(stream, &hglobal); ok(hr == S_OK, "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><b /></a>", 12), "got %s\n", ptr); GlobalUnlock(hglobal); IXmlWriter_Release(writer); IStream_Release(stream); }
static void test_writer_state(void) { static const WCHAR aW[] = {'a',0}; IXmlWriter *writer; IStream *stream; HRESULT hr; hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* initial state */ check_writer_state(writer, E_UNEXPECTED); /* set output and call 'wrong' method, WriteEndElement */ stream = writer_set_output(writer); hr = IXmlWriter_WriteEndElement(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteAttributeString */ stream = writer_set_output(writer); hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, aW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteEndDocument */ stream = writer_set_output(writer); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteFullEndElement */ stream = writer_set_output(writer); hr = IXmlWriter_WriteFullEndElement(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteCData */ stream = writer_set_output(writer); hr = IXmlWriter_WriteCData(writer, aW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteName */ stream = writer_set_output(writer); hr = IXmlWriter_WriteName(writer, aW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteNmToken */ stream = writer_set_output(writer); hr = IXmlWriter_WriteNmToken(writer, aW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); /* WriteString */ stream = writer_set_output(writer); hr = IXmlWriter_WriteString(writer, aW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream); IXmlWriter_Release(writer); }
/* used to test all Write* methods for consistent error state */ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) { static const WCHAR aW[] = {'a',0}; HRESULT hr; /* FIXME: add WriteAttributes */ hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteCData(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteCharEntity(writer, aW[0]); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteChars(writer, aW, 1); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteComment(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); /* FIXME: add WriteDocType */ hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteEntityRef(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteFullEndElement(writer); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteName(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteNmToken(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); /* FIXME: add WriteNode */ /* FIXME: add WriteNodeShallow */ hr = IXmlWriter_WriteProcessingInstruction(writer, aW, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteQualifiedName(writer, aW, NULL); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteRaw(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteRawChars(writer, aW, 1); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); hr = IXmlWriter_WriteString(writer, aW); ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr); /* FIXME: add WriteSurrogateCharEntity */ /* FIXME: add WriteWhitespace */ }