From 41287679e1b89dc810eb3b2a3c44279a40223645 Mon Sep 17 00:00:00 2001 From: Jefferson Carpenter Date: Mon, 31 May 2021 20:07:58 +0000 Subject: [PATCH 3/4] msxml3/tests: Test for disabled document methods with writer domdoc dest. Signed-off-by: Jefferson Carpenter --- dlls/msxml3/tests/saxreader.c | 338 ++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c index 53e2af016f4..2a82a81da02 100644 --- a/dlls/msxml3/tests/saxreader.c +++ b/dlls/msxml3/tests/saxreader.c @@ -4970,6 +4970,331 @@ static void check_domelement_methods_disabled(IXMLDOMElement *locked_element) ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_element, hr); } +typedef struct { + IDispatch IDispatch_iface; + LONG ref; +} dispevent; + +static inline dispevent *impl_from_IDispatch( IDispatch *iface ) +{ + return CONTAINING_RECORD(iface, dispevent, IDispatch_iface); +} + +static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject) +{ + *ppvObject = NULL; + + if ( IsEqualGUID( riid, &IID_IDispatch) || + IsEqualGUID( riid, &IID_IUnknown) ) + { + *ppvObject = iface; + } + else + return E_NOINTERFACE; + + IDispatch_AddRef( iface ); + + return S_OK; +} + +static ULONG WINAPI dispevent_AddRef(IDispatch *iface) +{ + dispevent *This = impl_from_IDispatch( iface ); + return InterlockedIncrement( &This->ref ); +} + +static ULONG WINAPI dispevent_Release(IDispatch *iface) +{ + dispevent *This = impl_from_IDispatch( iface ); + ULONG ref = InterlockedDecrement( &This->ref ); + + if (ref == 0) + heap_free(This); + + return ref; +} + +static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo) +{ + return S_OK; +} + +static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo, + LCID lcid, ITypeInfo **ppTInfo) +{ + return S_OK; +} + +static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid, + LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) +{ + return S_OK; +} + +static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid, + LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result, + EXCEPINFO *excepInfo, UINT *argErr) +{ + return S_OK; +} + +static const IDispatchVtbl dispeventVtbl = +{ + dispevent_QueryInterface, + dispevent_AddRef, + dispevent_Release, + dispevent_GetTypeInfoCount, + dispevent_GetTypeInfo, + dispevent_GetIDsOfNames, + dispevent_Invoke +}; + +static IDispatch* create_dispevent(void) +{ + dispevent *event = heap_alloc(sizeof(*event)); + + event->IDispatch_iface.lpVtbl = &dispeventVtbl; + event->ref = 1; + + return (IDispatch*)&event->IDispatch_iface; +} + +static void check_domdoc_methods_disabled(IXMLDOMDocument *locked_doc) +{ + HRESULT hr; + VARIANT variant; + VARIANT_BOOL variant_bool; + BSTR bstr; + LONG long_integer; + IDispatch *dispatch; + IXMLDOMDocumentType *document_type; + IXMLDOMImplementation *implementation; + IXMLDOMElement *element; + IXMLDOMDocumentFragment *document_fragment; + IXMLDOMText *text; + IXMLDOMComment *comment; + IXMLDOMCDATASection *cdata_section; + IXMLDOMProcessingInstruction *processing_instruction; + IXMLDOMAttribute *attribute; + IXMLDOMEntityReference *entity_reference; + IXMLDOMNodeList *node_list; + IXMLDOMNode *node; + IXMLDOMParseError *parse_error; + + document_type = (void*)0xdeadbeef; + hr = IXMLDOMDocument_get_doctype(locked_doc, &document_type); + ok(hr == S_FALSE, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(document_type == NULL, "%p: Got %p.\n", locked_doc, document_type); + + hr = IXMLDOMDocument_get_implementation(locked_doc, &implementation); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMImplementation_Release(implementation); + + element = (void*)0xdeadbeef; + hr = IXMLDOMDocument_get_documentElement(locked_doc, &element); + todo_wine ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(element != (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, element); + /* element used by next test */ + + if (element) { + hr = IXMLDOMDocument_putref_documentElement(locked_doc, element); + ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMElement_Release(element); + } + + element = (void*)0xdeadbeef; + hr = IXMLDOMDocument_createElement(locked_doc, _bstr_("SomeTagName"), &element); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(element == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, element); + if (element && element != (void*)0xdeadbeef) IXMLDOMElement_Release(element); + + hr = IXMLDOMDocument_createDocumentFragment(locked_doc, &document_fragment); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMDocumentFragment_Release(document_fragment); + + hr = IXMLDOMDocument_createTextNode(locked_doc, _bstr_("some text"), &text); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMText_Release(text); + + hr = IXMLDOMDocument_createComment(locked_doc, _bstr_("some comment"), &comment); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMComment_Release(comment); + + hr = IXMLDOMDocument_createCDATASection(locked_doc, _bstr_("some CDATA"), &cdata_section); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMCDATASection_Release(cdata_section); + + processing_instruction = (void*)0xdeadbeef; + hr = IXMLDOMDocument_createProcessingInstruction( locked_doc, _bstr_("xml"), + _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &processing_instruction); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(processing_instruction == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, processing_instruction); + if (processing_instruction && processing_instruction != (void*)0xdeadbeef) + IXMLDOMProcessingInstruction_Release(processing_instruction); + + attribute = (void*)0xdeadbeef; + hr = IXMLDOMDocument_createAttribute(locked_doc, _bstr_("attribute"), &attribute); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(attribute == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, attribute); + if (attribute && attribute != (void*)0xdeadbeef) IXMLDOMAttribute_Release(attribute); + + entity_reference = (void*)0xdeadbeef; + hr = IXMLDOMDocument_createEntityReference(locked_doc, _bstr_("entityref"), &entity_reference); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(entity_reference == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, entity_reference); + if (entity_reference && entity_reference != (void*)0xdeadbeef) IXMLDOMEntityReference_Release(entity_reference); + + node_list = (void*)0xdeadbeef; + hr = IXMLDOMDocument_getElementsByTagName(locked_doc, _bstr_("BankAccount"), &node_list); + todo_wine ok(hr == E_PENDING, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(node_list == NULL, "%p: Got %p.\n", locked_doc, node_list); + if (node_list && node_list != (void*)0xdeadbeef) IXMLDOMNodeList_Release(node_list); + + V_VT(&variant) = VT_I1; + V_I1(&variant) = NODE_TEXT; + node = (void*)0xdeadbeef; + hr = IXMLDOMDocument_createNode(locked_doc, variant, NULL, NULL, &node); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(node == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, node); + if (node && node != (void*)0xdeadbeef) IXMLDOMNode_Release(node); + + node = (void*)0xdeadbeef; + hr = IXMLDOMDocument_nodeFromID(locked_doc, _bstr_("id"), &node); + todo_wine ok(hr == E_PENDING, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(node == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, node); + if (node && node != (void*)0xdeadbeef) IXMLDOMNode_Release(node); + + long_integer = 0; + hr = IXMLDOMDocument_get_readyState(locked_doc, &long_integer); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(long_integer == 3, "%p: Got %d, expected %d.", locked_doc, long_integer, 3); + + hr = IXMLDOMDocument_get_parseError(locked_doc, &parse_error); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMParseError_Release(parse_error); + + bstr = (void*)0xdeadbeef; + hr = IXMLDOMDocument_get_url(locked_doc, &bstr); + ok(hr == S_FALSE, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(bstr == NULL, "%p: Got %p.\n", locked_doc, bstr); + + hr = IXMLDOMDocument_get_async(locked_doc, &variant_bool); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(variant_bool == VARIANT_TRUE, "Got %d, expected %d.\n", variant_bool, VARIANT_TRUE); + + hr = IXMLDOMDocument_put_async(locked_doc, variant_bool); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + V_VT(&variant) = VT_BSTR; + V_BSTR(&variant) = _bstr_("saxreader_test.xml"); + hr = IXMLDOMDocument_save(locked_doc, variant); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + DeleteFileA("saxreader_test.xml"); + + hr = IXMLDOMDocument_get_validateOnParse(locked_doc, &variant_bool); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(variant_bool == VARIANT_TRUE, "%p: Got %d, expected %d.\n", locked_doc, variant_bool, VARIANT_TRUE); + + hr = IXMLDOMDocument_put_validateOnParse(locked_doc, variant_bool); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + variant_bool = VARIANT_TRUE; + hr = IXMLDOMDocument_get_resolveExternals(locked_doc, &variant_bool); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(variant_bool == VARIANT_FALSE, "%p: Got %d, expected %d.\n", locked_doc, variant_bool, VARIANT_FALSE); + + hr = IXMLDOMDocument_put_resolveExternals(locked_doc, variant_bool); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + variant_bool = VARIANT_TRUE; + hr = IXMLDOMDocument_get_preserveWhiteSpace(locked_doc, &variant_bool); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(variant_bool == VARIANT_FALSE, "%p: Got %d, expected %d.\n", locked_doc, variant_bool, VARIANT_FALSE); + + hr = IXMLDOMDocument_put_preserveWhiteSpace(locked_doc, variant_bool); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + dispatch = create_dispevent(); + V_VT(&variant) = VT_DISPATCH; + V_DISPATCH(&variant) = dispatch; + hr = IXMLDOMDocument_put_onreadystatechange(locked_doc, variant); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + EXPECT_REF(dispatch, 2); + + hr = IXMLDOMDocument_put_ondataavailable(locked_doc, variant); + todo_wine ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine EXPECT_REF(dispatch, 3); + + hr = IXMLDOMDocument_put_ontransformnode(locked_doc, variant); + todo_wine ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine EXPECT_REF(dispatch, 4); + + IDispatch_Release(dispatch); + + /* The abort, load, and loadXML functions break the connection + with the mxwriter and are tested elsewhere. */ +} + +static void check_domdoc2_methods_disabled(IXMLDOMDocument2 *locked_doc) +{ + HRESULT hr; + VARIANT variant; + IXMLDOMSchemaCollection *schema_collection; + IXMLDOMParseError *parse_error; + + hr = IXMLDOMDocument2_get_namespaces(locked_doc, &schema_collection); + ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + IXMLDOMSchemaCollection_Release(schema_collection); + + V_VT(&variant) = VT_EMPTY; + hr = IXMLDOMDocument2_get_schemas(locked_doc, &variant); + ok(hr == S_FALSE, "%p: Unexpected hr %#x.\n", locked_doc, hr); + ok(V_VT(&variant) == VT_NULL, "%p: Got %d.\n", locked_doc, V_VT(&variant)); + + V_VT(&variant) = VT_DISPATCH; + V_DISPATCH(&variant) = NULL; + hr = IXMLDOMDocument2_putref_schemas(locked_doc, variant); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + parse_error = (void*)0xdeadbeef; + hr = IXMLDOMDocument2_validate(locked_doc, &parse_error); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(parse_error == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, parse_error); + if (parse_error && parse_error != (void*)0xdeadbeef) IXMLDOMParseError_Release(parse_error); + + V_VT(&variant) = VT_BOOL; + V_BOOL(&variant) = VARIANT_FALSE; + hr = IXMLDOMDocument2_setProperty(locked_doc, _bstr_("ForcedResync"), variant); + ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + + V_VT(&variant) = VT_EMPTY; + hr = IXMLDOMDocument2_getProperty(locked_doc, _bstr_("ForcedResync"), &variant); + todo_wine ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(V_VT(&variant) == VT_BOOL, "%p: Got %d, expected %d.\n", locked_doc, V_VT(&variant), VT_BOOL); + todo_wine ok(V_BOOL(&variant) == VARIANT_TRUE, "%p: Got %d, expected %d.\n", locked_doc, V_BOOL(&variant), VARIANT_TRUE); +} + +static void check_domdoc3_methods_disabled(IXMLDOMDocument3 *locked_doc, IXMLDOMNode *locked_node) +{ + HRESULT hr; + VARIANT_BOOL variant_bool; + IXMLDOMParseError *parse_error; + IXMLDOMNode *node; + + parse_error = (void*)0xdeadbeef; + hr = IXMLDOMDocument3_validateNode(locked_doc, locked_node, &parse_error); + todo_wine ok(hr == E_FAIL, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(parse_error == (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, parse_error); + if (parse_error && parse_error != (void*)0xdeadbeef) IXMLDOMParseError_Release(parse_error); + + node = (void*)0xdeadbeef; + variant_bool = VARIANT_TRUE; + hr = IXMLDOMDocument3_importNode(locked_doc, locked_node, variant_bool, &node); + todo_wine ok(hr == S_OK, "%p: Unexpected hr %#x.\n", locked_doc, hr); + todo_wine ok(node != (void*)0xdeadbeef, "%p: Got %p.\n", locked_doc, node); + if (node && node != (void*)0xdeadbeef) IXMLDOMNode_Release(node); +} + static void test_mxwriter_domdoc_startDocument_disables_domdoc_methods(void) { HRESULT hr; @@ -4991,6 +5316,7 @@ static void test_mxwriter_domdoc_startDocument_disables_domdoc_methods(void) IXMLDOMCDATASection *cdata_section = NULL; /* for disabled element methods */ IXMLDOMElement *element = NULL; + /* for disabled domdoc methods */ IXMLDOMDocument2 *domdoc2; IXMLDOMDocument3 *domdoc3; @@ -5130,6 +5456,18 @@ static void test_mxwriter_domdoc_startDocument_disables_domdoc_methods(void) } + /* Call IXMLDOMDocument/2/3 methods on domdoc. */ + check_domdoc_methods_disabled(domdoc); + + check_domdoc_methods_disabled((IXMLDOMDocument*)domdoc2); + check_domdoc2_methods_disabled(domdoc2); + + check_domdoc_methods_disabled((IXMLDOMDocument*)domdoc3); + check_domdoc2_methods_disabled((IXMLDOMDocument2*)domdoc3); + check_domdoc3_methods_disabled(domdoc3, element_node); + check_domdoc3_methods_disabled(domdoc3, text_node); + + if (import_text_node) IXMLDOMNode_Release(import_text_node); if (import_element_node) IXMLDOMNode_Release(import_element_node); if (text_node) IXMLDOMNode_Release(text_node); -- 2.26.2