From d49613b7338ecd4b337049d7460745a136252636 Mon Sep 17 00:00:00 2001 From: Jefferson Carpenter Date: Sat, 23 Jan 2021 03:01:11 +0000 Subject: [PATCH 1/2] msxml3/tests: Test mxwriter DOMDocument output. Changes from previous version: Submitting conformance test in a separate patch. Signed-off-by: Jefferson Carpenter --- dlls/msxml3/tests/saxreader.c | 219 ++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c index ab814c5f764..70556f94615 100644 --- a/dlls/msxml3/tests/saxreader.c +++ b/dlls/msxml3/tests/saxreader.c @@ -4367,6 +4367,224 @@ static void test_mxwriter_stream(void) free_bstrs(); } +static void test_mxwriter_domdoc(void) +{ + IMXWriter *writer; + ISAXContentHandler *content; + IXMLDOMDocument3 *domdoc; + IDispatch *dispatch; + ISAXAttributes *sax_attributes; + IMXAttributes *mx_attributes; + HRESULT hr; + VARIANT dest; + + IXMLDOMElement *root = NULL; + IXMLDOMNodeList *node_list = NULL; + IXMLDOMNode *node = NULL; + IXMLDOMNamedNodeMap *attribute_map = NULL; + IXMLDOMNode *attribute_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); + EXPECT_HR(hr, S_OK); + + hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content); + EXPECT_HR(hr, S_OK); + + hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, + &IID_IXMLDOMDocument3, (void**)&domdoc); + EXPECT_HR(hr, S_OK); + + hr = IXMLDOMDocument3_QueryInterface(domdoc, &IID_IDispatch, (void**)&dispatch); + EXPECT_HR(hr, S_OK); + + V_VT(&dest) = VT_DISPATCH; + V_DISPATCH(&dest) = dispatch; + + hr = IMXWriter_put_output(writer, dest); + todo_wine EXPECT_HR(hr, S_OK); + + + /* Provide writer with events */ + hr = ISAXContentHandler_startDocument(content); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_processingInstruction( + content, + L"targ", 4, L"type=\"test sheet\" test=\"something\"", 34 + ); + EXPECT_HR(hr, S_OK); + + /* */ + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"BankAccount", 11, NULL); + EXPECT_HR(hr, S_OK); + + /* 12345 */ + hr = CoCreateInstance(&CLSID_SAXAttributes60, NULL, CLSCTX_INPROC_SERVER, + &IID_IMXAttributes, (void**)&mx_attributes); + EXPECT_HR(hr, S_OK); + + hr = IMXAttributes_addAttribute( + mx_attributes, _bstr_("uri"), _bstr_("local"), + _bstr_("bank"), _bstr_("type"), _bstr_("World Bank") + ); + EXPECT_HR(hr, S_OK); + + hr = IMXAttributes_addAttribute( + mx_attributes, _bstr_("uri"), _bstr_("local"), + _bstr_("branch"), _bstr_("type"), _bstr_("Japan") + ); + EXPECT_HR(hr, S_OK); + + hr = IMXAttributes_QueryInterface(mx_attributes, &IID_ISAXAttributes, (void**)&sax_attributes); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"Number", 6, sax_attributes); + EXPECT_HR(hr, S_OK); + + ISAXAttributes_Release(sax_attributes); + IMXAttributes_Release(mx_attributes); + + hr = ISAXContentHandler_characters(content, L"12345", 5); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"Number", 6); + EXPECT_HR(hr, S_OK); + + /* Captain Ahab */ + hr = ISAXContentHandler_startElement(content, L"", 0, L"", 0, L"Name", 4, NULL); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_characters(content, L"Captain Ahab", 12); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"Name", 4); + EXPECT_HR(hr, S_OK); + + /* */ + hr = ISAXContentHandler_endElement(content, L"", 0, L"", 0, L"BankAccount", 11); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_endDocument(content); + EXPECT_HR(hr, S_OK); + + + /* Assert that it created the correct document */ + hr = IXMLDOMDocument3_get_documentElement(domdoc, &root); + todo_wine EXPECT_HR(hr, S_OK); + ok(root != NULL, "root == NULL\n"); + if (!root) return; + + /* */ + hr = IXMLDOMElement_get_nodeName(root, &str); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine ok(!lstrcmpW(L"BankAccount", str), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + hr = IXMLDOMElement_get_childNodes(root, &node_list); + todo_wine EXPECT_HR(hr, S_OK); + + hr = IXMLDOMNodeList_get_length(node_list, &list_length); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine ok(2 == list_length, "list length %i, expected 1\n", list_length); + + /* 12345 */ + hr = IXMLDOMNode_get_text(node, &str); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine ok(!lstrcmpW(L"12345", str), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + IXMLDOMNode_Release(node); + + /* Captain Ahab */ + hr = IXMLDOMNodeList_get_item(node_list, 1, &node); + todo_wine EXPECT_HR(hr, S_OK); + + hr = IXMLDOMNode_get_nodeName(node, &str); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine ok(!lstrcmpW(L"Name", str), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + hr = IXMLDOMNode_get_text(node, &str); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine 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); + + /* finally test doc output */ + hr = IXMLDOMDocument3_get_xml(domdoc, &str); + todo_wine EXPECT_HR(hr, S_OK); + todo_wine ok( + !lstrcmpW( + L"\r\n" + "" + "12345" + "Captain Ahab" + "\r\n", + str), + "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + IDispatch_Release(dispatch); + IXMLDOMDocument3_Release(domdoc); + ISAXContentHandler_Release(content); + IMXWriter_Release(writer); + + free_bstrs(); +} + static const char *encoding_names[] = { "iso-8859-1", "iso-8859-2", @@ -5768,6 +5986,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(); -- 2.26.2