Commit a28ace9a authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3: Support more variant types in putProperty().

parent a41446b1
...@@ -2602,99 +2602,85 @@ static HRESULT internal_parseURL( ...@@ -2602,99 +2602,85 @@ static HRESULT internal_parseURL(
return detach_bsc(bsc); return detach_bsc(bsc);
} }
static HRESULT internal_putProperty( static HRESULT saxreader_put_handler_from_variant(saxreader *This, enum saxhandler_type type, const VARIANT *v, BOOL vb)
saxreader* This,
const WCHAR *prop,
VARIANT value,
BOOL vbInterface)
{ {
TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value)); const IID *riid;
if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW))) if (V_VT(v) == VT_EMPTY)
{ return saxreader_put_handler(This, type, NULL, vb);
if(This->isParsing) return E_FAIL;
switch (V_VT(&value)) switch (type)
{ {
case VT_EMPTY: case SAXDeclHandler:
saxreader_put_handler(This, SAXDeclHandler, NULL, vbInterface); riid = vb ? &IID_IVBSAXDeclHandler : &IID_ISAXDeclHandler;
break; break;
case VT_UNKNOWN: case SAXLexicalHandler:
{ riid = vb ? &IID_IVBSAXLexicalHandler : &IID_ISAXLexicalHandler;
IUnknown *handler = NULL;
if (V_UNKNOWN(&value))
{
HRESULT hr;
if (vbInterface)
hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXDeclHandler, (void**)&handler);
else
hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXDeclHandler, (void**)&handler);
if (FAILED(hr)) return hr;
}
saxreader_put_handler(This, SAXDeclHandler, handler, vbInterface);
if (handler) IUnknown_Release(handler);
break; break;
}
default: default:
return E_INVALIDARG; ERR("wrong handler type %d\n", type);
} return E_FAIL;
return S_OK;
} }
if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW))) switch (V_VT(v))
{
if(This->isParsing) return E_FAIL;
switch (V_VT(&value))
{ {
case VT_EMPTY: case VT_DISPATCH:
saxreader_put_handler(This, SAXLexicalHandler, NULL, vbInterface);
break;
case VT_UNKNOWN: case VT_UNKNOWN:
{ {
IUnknown *handler = NULL; IUnknown *handler = NULL;
if (V_UNKNOWN(&value)) if (V_UNKNOWN(v))
{ {
HRESULT hr; HRESULT hr = IUnknown_QueryInterface(V_UNKNOWN(v), riid, (void**)&handler);
if (vbInterface)
hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXLexicalHandler, (void**)&handler);
else
hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXLexicalHandler, (void**)&handler);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
} }
saxreader_put_handler(This, SAXLexicalHandler, handler, vbInterface); saxreader_put_handler(This, type, handler, vb);
if (handler) IUnknown_Release(handler); if (handler) IUnknown_Release(handler);
break; break;
} }
default: default:
ERR("value type %d not supported\n", V_VT(v));
return E_INVALIDARG; return E_INVALIDARG;
} }
return S_OK; return S_OK;
} }
static HRESULT internal_putProperty(
saxreader* This,
const WCHAR *prop,
VARIANT value,
BOOL vbInterface)
{
VARIANT *v;
TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
if (This->isParsing) return E_FAIL;
v = V_VT(&value) == (VT_VARIANT|VT_BYREF) ? V_VARIANTREF(&value) : &value;
if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
return saxreader_put_handler_from_variant(This, SAXDeclHandler, v, vbInterface);
if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
return saxreader_put_handler_from_variant(This, SAXLexicalHandler, v, vbInterface);
if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW))) if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
{ {
if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK; if (V_VT(v) == VT_I4 && V_I4(v) == 0) return S_OK;
FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value)); FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(v));
return E_NOTIMPL; return E_NOTIMPL;
} }
if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW))) if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
{ {
if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK; if (V_VT(v) == VT_I4 && V_I4(v) == 0) return S_OK;
FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value)); FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(v));
return E_NOTIMPL; return E_NOTIMPL;
} }
FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value)); FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(v));
if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW))) if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
return E_NOTIMPL; return E_NOTIMPL;
......
...@@ -2523,6 +2523,7 @@ static void test_saxreader_properties(void) ...@@ -2523,6 +2523,7 @@ static void test_saxreader_properties(void)
while (ptr->prop_name) while (ptr->prop_name)
{ {
VARIANT varref;
LONG ref; LONG ref;
init_saxlexicalhandler(&lexicalhandler, S_OK); init_saxlexicalhandler(&lexicalhandler, S_OK);
...@@ -2535,6 +2536,7 @@ static void test_saxreader_properties(void) ...@@ -2535,6 +2536,7 @@ static void test_saxreader_properties(void)
ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v)); ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v)); ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
/* VT_UNKNOWN */
V_VT(&v) = VT_UNKNOWN; V_VT(&v) = VT_UNKNOWN;
V_UNKNOWN(&v) = ptr->iface; V_UNKNOWN(&v) = ptr->iface;
ref = get_refcount(ptr->iface); ref = get_refcount(ptr->iface);
...@@ -2542,6 +2544,36 @@ static void test_saxreader_properties(void) ...@@ -2542,6 +2544,36 @@ static void test_saxreader_properties(void)
EXPECT_HR(hr, S_OK); EXPECT_HR(hr, S_OK);
ok(ref < get_refcount(ptr->iface), "expected inreased refcount\n"); ok(ref < get_refcount(ptr->iface), "expected inreased refcount\n");
/* VT_DISPATCH */
V_VT(&v) = VT_DISPATCH;
V_UNKNOWN(&v) = ptr->iface;
ref = get_refcount(ptr->iface);
hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
EXPECT_HR(hr, S_OK);
ok(ref == get_refcount(ptr->iface), "got wrong refcount %d, expected %d\n", get_refcount(ptr->iface), ref);
/* VT_VARIANT|VT_BYREF with VT_UNKNOWN in referenced variant */
V_VT(&varref) = VT_UNKNOWN;
V_UNKNOWN(&varref) = ptr->iface;
V_VT(&v) = VT_VARIANT|VT_BYREF;
V_VARIANTREF(&v) = &varref;
ref = get_refcount(ptr->iface);
hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
EXPECT_HR(hr, S_OK);
ok(ref == get_refcount(ptr->iface), "got wrong refcount %d, expected %d\n", get_refcount(ptr->iface), ref);
/* VT_VARIANT|VT_BYREF with VT_DISPATCH in referenced variant */
V_VT(&varref) = VT_DISPATCH;
V_UNKNOWN(&varref) = ptr->iface;
V_VT(&v) = VT_VARIANT|VT_BYREF;
V_VARIANTREF(&v) = &varref;
ref = get_refcount(ptr->iface);
hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
EXPECT_HR(hr, S_OK);
ok(ref == get_refcount(ptr->iface), "got wrong refcount %d, expected %d\n", get_refcount(ptr->iface), ref);
V_VT(&v) = VT_EMPTY; V_VT(&v) = VT_EMPTY;
V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef; V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment