Commit 9c2288fc authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3/mxnamespace: Support prefix override mode.

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