msxml3: Fix closing of open element.

This commit is contained in:
Nikolay Sivov 2012-06-23 12:29:14 +04:00 committed by Alexandre Julliard
parent 5e08765fbb
commit 7c9a1b52e3
2 changed files with 96 additions and 4 deletions

View File

@ -1071,7 +1071,8 @@ static HRESULT WINAPI SAXContentHandler_startElement(
TRACE("(%p)->(%s %s %s %p)\n", This, debugstr_wn(namespaceUri, nnamespaceUri), TRACE("(%p)->(%s %s %s %p)\n", This, debugstr_wn(namespaceUri, nnamespaceUri),
debugstr_wn(local_name, nlocal_name), debugstr_wn(QName, nQName), attr); debugstr_wn(local_name, nlocal_name), debugstr_wn(QName, nQName), attr);
if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6) if (((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6) ||
(nQName == -1 && This->class_version == MSXML6))
return E_INVALIDARG; return E_INVALIDARG;
close_element_starttag(This); close_element_starttag(This);
@ -1139,13 +1140,13 @@ static HRESULT WINAPI SAXContentHandler_endElement(
TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This, debugstr_wn(namespaceUri, nnamespaceUri), nnamespaceUri, TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This, debugstr_wn(namespaceUri, nnamespaceUri), nnamespaceUri,
debugstr_wn(local_name, nlocal_name), nlocal_name, debugstr_wn(QName, nQName), nQName); debugstr_wn(local_name, nlocal_name), nlocal_name, debugstr_wn(QName, nQName), nQName);
if ((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6) if (((!namespaceUri || !local_name || !QName) && This->class_version != MSXML6) ||
(nQName == -1 && This->class_version == MSXML6))
return E_INVALIDARG; return E_INVALIDARG;
if (This->element && QName && !strncmpW(This->element, QName, nQName)) if (This->element)
{ {
static const WCHAR closeW[] = {'/','>'}; static const WCHAR closeW[] = {'/','>'};
write_output_buffer(This->buffer, closeW, 2); write_output_buffer(This->buffer, closeW, 2);
} }
else else

View File

@ -3304,6 +3304,94 @@ static void test_mxwriter_startendelement_batch(const struct writer_startendelem
free_bstrs(); free_bstrs();
} }
/* point of these test is to start/end element with different names and name lengths */
struct writer_startendelement2_t {
const GUID *clsid;
const char *qnamestart;
int qnamestart_len;
const char *qnameend;
int qnameend_len;
const char *output;
HRESULT hr;
};
static const struct writer_startendelement2_t writer_startendelement2[] = {
{ &CLSID_MXXMLWriter, "a", -1, "b", -1, "<a/>", S_OK },
{ &CLSID_MXXMLWriter30, "a", -1, "b", -1, "<a/>", S_OK },
{ &CLSID_MXXMLWriter40, "a", -1, "b", -1, "<a/>", S_OK },
/* -1 length is not allowed for version 6 */
{ &CLSID_MXXMLWriter60, "a", -1, "b", -1, "<a/>", E_INVALIDARG },
{ &CLSID_MXXMLWriter, "a", 1, "b", 1, "<a/>", S_OK },
{ &CLSID_MXXMLWriter30, "a", 1, "b", 1, "<a/>", S_OK },
{ &CLSID_MXXMLWriter40, "a", 1, "b", 1, "<a/>", S_OK },
{ &CLSID_MXXMLWriter60, "a", 1, "b", 1, "<a/>", S_OK },
{ NULL }
};
static void test_mxwriter_startendelement_batch2(const struct writer_startendelement2_t *table)
{
int i = 0;
while (table->clsid)
{
ISAXContentHandler *content;
IMXWriter *writer;
HRESULT hr;
if (!is_clsid_supported(table->clsid, mxwriter_support_data))
{
table++;
i++;
continue;
}
hr = CoCreateInstance(table->clsid, 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 = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
EXPECT_HR(hr, S_OK);
hr = ISAXContentHandler_startDocument(content);
EXPECT_HR(hr, S_OK);
hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0,
_bstr_(table->qnamestart), table->qnamestart_len, NULL);
ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0,
_bstr_(table->qnameend), table->qnameend_len);
ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
/* test output */
if (hr == S_OK)
{
VARIANT dest;
V_VT(&dest) = VT_EMPTY;
hr = IMXWriter_get_output(writer, &dest);
EXPECT_HR(hr, S_OK);
ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
"test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
VariantClear(&dest);
}
ISAXContentHandler_Release(content);
IMXWriter_Release(writer);
table++;
i++;
free_bstrs();
}
}
static void test_mxwriter_startendelement(void) static void test_mxwriter_startendelement(void)
{ {
ISAXContentHandler *content; ISAXContentHandler *content;
@ -3312,6 +3400,7 @@ static void test_mxwriter_startendelement(void)
HRESULT hr; HRESULT hr;
test_mxwriter_startendelement_batch(writer_startendelement); test_mxwriter_startendelement_batch(writer_startendelement);
test_mxwriter_startendelement_batch2(writer_startendelement2);
hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER, hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
&IID_IMXWriter, (void**)&writer); &IID_IMXWriter, (void**)&writer);
@ -3410,6 +3499,7 @@ static void test_mxwriter_startendelement(void)
hr = IMXWriter_put_output(writer, dest); hr = IMXWriter_put_output(writer, dest);
EXPECT_HR(hr, S_OK); EXPECT_HR(hr, S_OK);
/* length -1 */
hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), -1, NULL); hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), -1, NULL);
EXPECT_HR(hr, S_OK); EXPECT_HR(hr, S_OK);
V_VT(&dest) = VT_EMPTY; V_VT(&dest) = VT_EMPTY;
@ -3417,6 +3507,7 @@ static void test_mxwriter_startendelement(void)
EXPECT_HR(hr, S_OK); EXPECT_HR(hr, S_OK);
ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest)); ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
ok(!lstrcmpW(_bstr_("<a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest))); ok(!lstrcmpW(_bstr_("<a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
VariantClear(&dest);
ISAXContentHandler_Release(content); ISAXContentHandler_Release(content);
IMXWriter_Release(writer); IMXWriter_Release(writer);