From: Jefferson Carpenter jeffersoncarpenter2@gmail.com
Signed-off-by: Jefferson Carpenter jeffersoncarpenter2@gmail.com Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
Jefferson, note that this test appears to rely on DOMDocument60 behavior, it fails for me on Windows otherwise. It would be nice if it didn't.
v6: using regular interface version; skipping earlier on Wine; formatting changes.
dlls/msxml3/tests/saxreader.c | 194 ++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+)
diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c index ab814c5f764..35d0e71545b 100644 --- a/dlls/msxml3/tests/saxreader.c +++ b/dlls/msxml3/tests/saxreader.c @@ -4367,6 +4367,199 @@ static void test_mxwriter_stream(void) free_bstrs(); }
+static void test_mxwriter_domdoc(void) +{ + ISAXContentHandler *content; + IXMLDOMDocument *domdoc; + IMXWriter *writer; + HRESULT hr; + VARIANT dest; + IXMLDOMElement *root = NULL; + IXMLDOMNodeList *node_list = NULL; + IXMLDOMNode *node = NULL; + LONG list_length = 0; + BSTR str; + + /* Create writer and attach DOMDocument output */ + hr = CoCreateInstance(&CLSID_MXXMLWriter60, NULL, CLSCTX_INPROC_SERVER, &IID_IMXWriter, (void**)&writer); + ok(hr == S_OK, "Failed to create a writer, hr %#x.\n", hr); + + hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void **)&domdoc); + ok(hr == S_OK, "Failed to create a document, hr %#x.\n", hr); + + V_VT(&dest) = VT_DISPATCH; + V_DISPATCH(&dest) = (IDispatch *)domdoc; + + hr = IMXWriter_put_output(writer, dest); +todo_wine + ok(hr == S_OK, "Failed to set writer output, hr %#x.\n", hr); + if (FAILED(hr)) + { + IXMLDOMDocument_Release(domdoc); + IMXWriter_Release(writer); + return; + } + + /* Add root element to document. */ + hr = IXMLDOMDocument_createElement(domdoc, _bstr_("TestElement"), &root); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + hr = IXMLDOMDocument_appendChild(domdoc, (IXMLDOMNode *)root, NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IXMLDOMElement_Release(root); + + hr = IXMLDOMDocument_get_documentElement(domdoc, &root); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(root != NULL, "Unexpected document root.\n"); + IXMLDOMElement_Release(root); + + /* startDocument clears root element and disables methods. */ + hr = ISAXContentHandler_startDocument(content); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMDocument_get_documentElement(domdoc, &root); +todo_wine + ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMDocument_createElement(domdoc, _bstr_("TestElement"), &root); +todo_wine + ok(hr == E_FAIL, "Unexpected hr %#x.\n", hr); + + /* startElement allows document root node to be accessed. */ + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"BankAccount", 11, NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMDocument_get_documentElement(domdoc, &root); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(root != NULL, "Unexpected document root.\n"); + + hr = IXMLDOMElement_get_nodeName(root, &str); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); +todo_wine + ok(!lstrcmpW(L"BankAccount", str), "Unexpected name %s.\n", wine_dbgstr_w(str)); + SysFreeString(str); + + /* startElement immediately updates previous node. */ + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"Number", 6, NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMElement_get_childNodes(root, &node_list); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNodeList_get_length(node_list, &list_length); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); +todo_wine + ok(list_length == 1, "list length %i, expected 1\n", list_length); + + hr = IXMLDOMNodeList_get_item(node_list, 0, &node); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNode_get_nodeName(node, &str); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW(L"Number", str), "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + /* characters not immediately visible. */ + hr = ISAXContentHandler_characters(content, L"12345", 5); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNode_get_text(node, &str); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW(L"", str), "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + /* characters visible after endElement. */ + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"Number", 6); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNode_get_text(node, &str); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW(L"12345", str), "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + IXMLDOMNode_Release(node); + + /* second startElement updates the existing node list. */ + + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"Name", 4, NULL); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = ISAXContentHandler_characters(content, L"Captain Ahab", 12); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"Name", 4); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"BankAccount", 11); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNodeList_get_length(node_list, &list_length); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(2 == list_length, "list length %i, expected 2\n", list_length); +} + hr = IXMLDOMNodeList_get_item(node_list, 1, &node); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMNode_get_nodeName(node, &str); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW(L"Name", str), "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + hr = IXMLDOMNode_get_text(node, &str); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW(L"Captain Ahab", str), "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + IXMLDOMNode_Release(node); + IXMLDOMNodeList_Release(node_list); + IXMLDOMElement_Release(root); + + /* endDocument makes document modifiable again. */ + + hr = ISAXContentHandler_endDocument(content); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IXMLDOMDocument_createElement(domdoc, _bstr_("TestElement"), &root); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IXMLDOMElement_Release(root); + + /* finally check doc output */ + hr = IXMLDOMDocument_get_xml(domdoc, &str); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!lstrcmpW( + L"<BankAccount>" + "<Number>12345</Number>" + "<Name>Captain Ahab</Name>" + "</BankAccount>\r\n", + str), + "got %s\n", wine_dbgstr_w(str)); +} + SysFreeString(str); + + IXMLDOMDocument_Release(domdoc); + ISAXContentHandler_Release(content); + IMXWriter_Release(writer); + + free_bstrs(); +} + static const char *encoding_names[] = { "iso-8859-1", "iso-8859-2", @@ -5768,6 +5961,7 @@ START_TEST(saxreader) test_mxwriter_properties(); test_mxwriter_flush(); test_mxwriter_stream(); + test_mxwriter_domdoc(); test_mxwriter_encoding(); test_mxwriter_dispex(); test_mxwriter_indent();