msxml3/mxnamespace: Support prefix override mode.
This commit is contained in:
parent
a15fe5a755
commit
9c2288fcee
|
@ -71,6 +71,8 @@ typedef struct
|
|||
LONG ref;
|
||||
|
||||
struct list ctxts;
|
||||
|
||||
VARIANT_BOOL override;
|
||||
} namespacemanager;
|
||||
|
||||
static inline namespacemanager *impl_from_IMXNamespaceManager( IMXNamespaceManager *iface )
|
||||
|
@ -83,17 +85,46 @@ static inline namespacemanager *impl_from_IVBMXNamespaceManager( IVBMXNamespaceM
|
|||
return CONTAINING_RECORD(iface, namespacemanager, IVBMXNamespaceManager_iface);
|
||||
}
|
||||
|
||||
static HRESULT declare_prefix(struct nscontext *ctxt, const WCHAR *prefix, const WCHAR *uri)
|
||||
static HRESULT declare_prefix(namespacemanager *This, const WCHAR *prefix, const WCHAR *uri)
|
||||
{
|
||||
struct nscontext *ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
|
||||
static const WCHAR emptyW[] = {0};
|
||||
struct ns *ns;
|
||||
int i;
|
||||
|
||||
if (ctxt->count == ctxt->max_alloc)
|
||||
{
|
||||
ctxt->max_alloc *= 2;
|
||||
ctxt->ns = heap_realloc(ctxt->ns, ctxt->max_alloc*sizeof(*ctxt->ns));
|
||||
}
|
||||
|
||||
ctxt->ns[ctxt->count].prefix = SysAllocString(prefix);
|
||||
ctxt->ns[ctxt->count].uri = SysAllocString(uri);
|
||||
ctxt->count++;
|
||||
if (!prefix) prefix = emptyW;
|
||||
|
||||
ns = NULL;
|
||||
for (i = 0; i < ctxt->count; i++)
|
||||
if (!strcmpW(ctxt->ns[i].prefix, prefix))
|
||||
{
|
||||
ns = &ctxt->ns[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if (ns)
|
||||
{
|
||||
if (This->override == VARIANT_TRUE)
|
||||
{
|
||||
SysFreeString(ns->uri);
|
||||
ns->uri = SysAllocString(uri);
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
return E_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ctxt->ns[ctxt->count].prefix = SysAllocString(prefix);
|
||||
ctxt->ns[ctxt->count].uri = SysAllocString(uri);
|
||||
ctxt->count++;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -222,17 +253,13 @@ static HRESULT WINAPI namespacemanager_declarePrefix(IMXNamespaceManager *iface,
|
|||
static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
|
||||
|
||||
namespacemanager *This = impl_from_IMXNamespaceManager( iface );
|
||||
struct nscontext *ctxt;
|
||||
|
||||
TRACE("(%p)->(%s %s)\n", This, debugstr_w(prefix), debugstr_w(namespaceURI));
|
||||
|
||||
if (!prefix) return E_FAIL;
|
||||
|
||||
if (!strcmpW(prefix, xmlW) || !strcmpW(prefix, xmlnsW) || (prefix && !namespaceURI))
|
||||
if (prefix && (!strcmpW(prefix, xmlW) || !strcmpW(prefix, xmlnsW) || !namespaceURI))
|
||||
return E_INVALIDARG;
|
||||
|
||||
ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
|
||||
return declare_prefix(ctxt, prefix, namespaceURI);
|
||||
return declare_prefix(This, prefix, namespaceURI);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI namespacemanager_getDeclaredPrefix(IMXNamespaceManager *iface,
|
||||
|
@ -451,16 +478,24 @@ static HRESULT WINAPI vbnamespacemanager_put_allowOverride(IVBMXNamespaceManager
|
|||
VARIANT_BOOL override)
|
||||
{
|
||||
namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
|
||||
FIXME("(%p)->(%d): stub\n", This, override);
|
||||
return E_NOTIMPL;
|
||||
|
||||
TRACE("(%p)->(%d)\n", This, override);
|
||||
This->override = override;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI vbnamespacemanager_get_allowOverride(IVBMXNamespaceManager *iface,
|
||||
VARIANT_BOOL *override)
|
||||
{
|
||||
namespacemanager *This = impl_from_IVBMXNamespaceManager( iface );
|
||||
FIXME("(%p)->(%p): stub\n", This, override);
|
||||
return E_NOTIMPL;
|
||||
|
||||
TRACE("(%p)->(%p)\n", This, override);
|
||||
|
||||
if (!override) return E_POINTER;
|
||||
*override = This->override;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI vbnamespacemanager_reset(IVBMXNamespaceManager *iface)
|
||||
|
@ -572,6 +607,8 @@ HRESULT MXNamespaceManager_create(IUnknown *outer, void **obj)
|
|||
ctxt = alloc_ns_context();
|
||||
list_add_head(&ns->ctxts, &ctxt->entry);
|
||||
|
||||
ns->override = VARIANT_TRUE;
|
||||
|
||||
*obj = &ns->IMXNamespaceManager_iface;
|
||||
|
||||
TRACE("returning iface %p\n", *obj);
|
||||
|
|
|
@ -10142,14 +10142,13 @@ static void test_nsnamespacemanager(void)
|
|||
EXPECT_HR(hr, S_OK);
|
||||
IVBMXNamespaceManager_Release(mgr2);
|
||||
|
||||
todo_wine {
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
|
||||
/* prefix already added */
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
|
||||
EXPECT_HR(hr, S_FALSE);
|
||||
}
|
||||
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), NULL);
|
||||
EXPECT_HR(hr, E_INVALIDARG);
|
||||
|
||||
|
@ -10238,6 +10237,7 @@ static void test_nsnamespacemanager_override(void)
|
|||
{
|
||||
IMXNamespaceManager *nsmgr;
|
||||
WCHAR buffW[250];
|
||||
VARIANT_BOOL b;
|
||||
HRESULT hr;
|
||||
INT len;
|
||||
|
||||
|
@ -10260,11 +10260,25 @@ static void test_nsnamespacemanager_override(void)
|
|||
hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
|
||||
EXPECT_HR(hr, E_FAIL);
|
||||
|
||||
hr = IMXNamespaceManager_getAllowOverride(nsmgr, NULL);
|
||||
EXPECT_HR(hr, E_POINTER);
|
||||
|
||||
b = VARIANT_FALSE;
|
||||
hr = IMXNamespaceManager_getAllowOverride(nsmgr, &b);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
ok(b == VARIANT_TRUE, "got %d\n", b);
|
||||
|
||||
hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_FALSE);
|
||||
todo_wine EXPECT_HR(hr, S_OK);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
|
||||
todo_wine EXPECT_HR(hr, S_OK);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
|
||||
len = sizeof(buffW)/sizeof(WCHAR);
|
||||
buffW[0] = 0;
|
||||
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
ok(!lstrcmpW(buffW, _bstr_("ns0 uri")), "got uri %s\n", wine_dbgstr_w(buffW));
|
||||
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), _bstr_("ns0 uri"));
|
||||
EXPECT_HR(hr, S_OK);
|
||||
|
@ -10284,7 +10298,7 @@ static void test_nsnamespacemanager_override(void)
|
|||
len = sizeof(buffW)/sizeof(WCHAR);
|
||||
buffW[0] = 0;
|
||||
hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 2, buffW, &len);
|
||||
todo_wine EXPECT_HR(hr, S_OK);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
|
||||
|
||||
/* new prefix placed at index 1 always */
|
||||
|
@ -10306,6 +10320,24 @@ static void test_nsnamespacemanager_override(void)
|
|||
hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
|
||||
EXPECT_HR(hr, E_FAIL);
|
||||
|
||||
hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_TRUE);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
|
||||
hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri override"));
|
||||
EXPECT_HR(hr, S_FALSE);
|
||||
|
||||
len = sizeof(buffW)/sizeof(WCHAR);
|
||||
buffW[0] = 0;
|
||||
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
ok(!lstrcmpW(buffW, _bstr_("ns0 uri override")), "got uri %s\n", wine_dbgstr_w(buffW));
|
||||
|
||||
len = sizeof(buffW)/sizeof(WCHAR);
|
||||
buffW[0] = 0;
|
||||
hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 3, buffW, &len);
|
||||
EXPECT_HR(hr, S_OK);
|
||||
ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
|
||||
|
||||
IMXNamespaceManager_Release(nsmgr);
|
||||
|
||||
free_bstrs();
|
||||
|
|
Loading…
Reference in New Issue