Signed-off-by: Daniel Lehman dlehman25@gmail.com --- dlls/msxml3/domdoc.c | 2 +- dlls/msxml3/tests/domdoc.c | 61 ++++++++++++++++++++++++++++++++- dlls/msxml3/tests/msxml3_test.h | 22 ++++++++++++ dlls/msxml3/tests/xmldoc.c | 2 +- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 dlls/msxml3/tests/msxml3_test.h
diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c index 76d3fdb601..c86a4931c5 100644 --- a/dlls/msxml3/domdoc.c +++ b/dlls/msxml3/domdoc.c @@ -2276,7 +2276,7 @@ static HRESULT WINAPI domdoc_load(
if (hr == S_OK) { - hr = domdoc_load_from_stream(This, stream); + hr = This->error = domdoc_load_from_stream(This, stream); if (hr == S_OK) *isSuccessful = VARIANT_TRUE; ISequentialStream_Release(stream); diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index a6acdba366..436f2a489f 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -37,12 +37,15 @@ #include "dispex.h" #include "objsafe.h" #include "mshtml.h" +#include "xmlparser.h" #include "initguid.h" #include "asptlb.h"
#include "wine/heap.h" #include "wine/test.h"
+#include "msxml3_test.h" + /* undef the #define in msxml2 so that we can access all versions */ #undef CLSID_DOMDocument
@@ -700,6 +703,36 @@ static void _expect_list_len(IXMLDOMNodeList *list, LONG len, int line) #define EXPECT_HR(hr,hr_exp) \ ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
+#define EXPECT_PARSE_ERROR(doc, hr_exp, hr_todo) _expect_parse_error(doc, hr_exp, hr_todo, __LINE__) +static void _expect_parse_error(IXMLDOMDocument *doc, HRESULT hr_exp, BOOL hr_todo, int line) +{ + IXMLDOMParseError *error; + HRESULT hr; + LONG code; + + error = NULL; + hr = IXMLDOMDocument_get_parseError(doc, &error); + ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr); + ok_(__FILE__,line)(!!error, "got NULL parseError\n"); + + code = 0xdeadbeef; + hr = IXMLDOMParseError_get_errorCode(error, &code); + if (FAILED(hr_exp)) + { + ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr); + ok_(__FILE__,line)(FAILED(code), "expected failure HRESULT\n"); + todo_wine_if(hr_todo) + ok_(__FILE__,line)(hr_exp == code, "expected 0x%08x, got 0x%08x\n", hr_exp, code); + } + else + { + ok_(__FILE__,line)(hr == S_FALSE, "got 0x%08x\n", hr); + ok_(__FILE__,line)(SUCCEEDED(code), "expected successful HRESULT\n"); + } + + IXMLDOMParseError_Release(error); +} + static const WCHAR szEmpty[] = { 0 }; static const WCHAR szIncomplete[] = { '<','?','x','m','l',' ', @@ -10138,7 +10171,7 @@ static void test_selection(void) free_bstrs(); }
-static void write_to_file(const char *name, const char *data) +void write_to_file(const char *name, const char *data) { DWORD written; HANDLE hfile; @@ -10215,6 +10248,7 @@ static void test_load(void) IXMLDOMNodeList *list; IXMLDOMDocument *doc; BSTR bstr1, bstr2; + IStream *stream; VARIANT_BOOL b; VARIANT src; HRESULT hr; @@ -10392,6 +10426,31 @@ static void test_load(void) ok(b == VARIANT_FALSE, "got %d\n", b);
VariantClear(&src); + + /* test istream with empty content */ + write_to_file(path, nocontent); + create_stream_on_file(&stream, path); + V_VT(&src) = VT_UNKNOWN; + V_UNKNOWN(&src) = (IUnknown*)stream; + b = VARIANT_TRUE; + hr = IXMLDOMDocument_load(doc, src, &b); + todo_wine ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(b == VARIANT_FALSE, "got %d\n", b); + EXPECT_PARSE_ERROR(doc, XML_E_INVALIDATROOTLEVEL, TRUE); + VariantClear(&src); + + /* test istream with valid xml */ + write_to_file(path, complete4A); + create_stream_on_file(&stream, path); + V_VT(&src) = VT_UNKNOWN; + V_UNKNOWN(&src) = (IUnknown*)stream; + b = VARIANT_FALSE; + hr = IXMLDOMDocument_load(doc, src, &b); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(b == VARIANT_TRUE, "got %d\n", b); + EXPECT_PARSE_ERROR(doc, S_OK, FALSE); + VariantClear(&src); + IXMLDOMDocument_Release(doc);
free_bstrs(); diff --git a/dlls/msxml3/tests/msxml3_test.h b/dlls/msxml3/tests/msxml3_test.h new file mode 100644 index 0000000000..a1a8a0a496 --- /dev/null +++ b/dlls/msxml3/tests/msxml3_test.h @@ -0,0 +1,22 @@ +/* + * Unit test suite for ntdll functions + * + * Copyright 2020 Daniel Lehman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +void write_to_file(const char *, const char *); +void create_stream_on_file(IStream **, LPCSTR); diff --git a/dlls/msxml3/tests/xmldoc.c b/dlls/msxml3/tests/xmldoc.c index 693af19571..680b32a4c0 100644 --- a/dlls/msxml3/tests/xmldoc.c +++ b/dlls/msxml3/tests/xmldoc.c @@ -53,7 +53,7 @@ static void create_xml_file(LPCSTR filename) CloseHandle(hf); }
-static void create_stream_on_file(IStream **stream, LPCSTR path) +void create_stream_on_file(IStream **stream, LPCSTR path) { HANDLE hfile; HGLOBAL hglobal;