msxml3/mxnamespace: Implemented getURI().

This commit is contained in:
Nikolay Sivov 2011-08-21 21:48:15 +04:00 committed by Alexandre Julliard
parent 42f65e1358
commit a15fe5a755
2 changed files with 93 additions and 2 deletions

View File

@ -101,6 +101,8 @@ static HRESULT declare_prefix(struct nscontext *ctxt, const WCHAR *prefix, const
/* returned stored pointer, caller needs to copy it */
static HRESULT get_declared_prefix_idx(const struct nscontext *ctxt, LONG index, BSTR *prefix)
{
*prefix = NULL;
if (index >= ctxt->count || index < 0) return E_FAIL;
if (index > 0) index = ctxt->count - index;
@ -109,6 +111,21 @@ static HRESULT get_declared_prefix_idx(const struct nscontext *ctxt, LONG index,
return S_OK;
}
static HRESULT get_uri_from_prefix(const struct nscontext *ctxt, const WCHAR *prefix, BSTR *uri)
{
int i;
for (i = 0; i < ctxt->count; i++)
if (!strcmpW(ctxt->ns[i].prefix, prefix))
{
*uri = ctxt->ns[i].uri;
return S_OK;
}
*uri = NULL;
return S_FALSE;
}
static struct nscontext* alloc_ns_context(void)
{
struct nscontext *ctxt;
@ -257,8 +274,37 @@ static HRESULT WINAPI namespacemanager_getURI(IMXNamespaceManager *iface,
const WCHAR *prefix, IXMLDOMNode *node, WCHAR *uri, int *uri_len)
{
namespacemanager *This = impl_from_IMXNamespaceManager( iface );
FIXME("(%p)->(%s %p %p %p): stub\n", This, debugstr_w(prefix), node, uri, uri_len);
return E_NOTIMPL;
struct nscontext *ctxt;
HRESULT hr;
BSTR urib;
TRACE("(%p)->(%s %p %p %p)\n", This, debugstr_w(prefix), node, uri, uri_len);
if (!prefix) return E_INVALIDARG;
if (!uri_len) return E_POINTER;
if (node)
{
FIXME("namespaces from DOM node not supported\n");
return E_NOTIMPL;
}
ctxt = LIST_ENTRY(list_head(&This->ctxts), struct nscontext, entry);
hr = get_uri_from_prefix(ctxt, prefix, &urib);
if (hr == S_OK)
{
if (uri)
{
if (*uri_len < (INT)SysStringLen(urib)) return E_XML_BUFFERTOOSMALL;
strcpyW(uri, urib);
}
}
else
if (uri) *uri = 0;
*uri_len = SysStringLen(urib);
return hr;
}
static const struct IMXNamespaceManagerVtbl MXNamespaceManagerVtbl =

View File

@ -10117,6 +10117,7 @@ static void test_load(void)
static void test_nsnamespacemanager(void)
{
static const char xmluriA[] = "http://www.w3.org/XML/1998/namespace";
IMXNamespaceManager *nsmgr;
IVBMXNamespaceManager *mgr2;
IDispatch *disp;
@ -10184,6 +10185,50 @@ todo_wine {
ok(len == 3, "got %d\n", len);
ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
/* getURI */
hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, NULL);
EXPECT_HR(hr, E_INVALIDARG);
len = -1;
hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, &len);
EXPECT_HR(hr, E_INVALIDARG);
ok(len == -1, "got %d\n", len);
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, NULL);
EXPECT_HR(hr, E_POINTER);
len = -1;
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, &len);
EXPECT_HR(hr, S_OK);
/* length of "xml" uri is constant */
ok(len == strlen(xmluriA), "got %d\n", len);
len = 100;
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
EXPECT_HR(hr, S_OK);
ok(len == strlen(xmluriA), "got %d\n", len);
ok(!lstrcmpW(buffW, _bstr_(xmluriA)), "got prefix %s\n", wine_dbgstr_w(buffW));
len = strlen(xmluriA)-1;
buffW[0] = 0x1;
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
ok(len == strlen(xmluriA)-1, "got %d\n", len);
ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
/* prefix xml1 not defined */
len = -1;
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, NULL, &len);
EXPECT_HR(hr, S_FALSE);
ok(len == 0, "got %d\n", len);
len = 100;
buffW[0] = 0x1;
hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, buffW, &len);
EXPECT_HR(hr, S_FALSE);
ok(buffW[0] == 0, "got %x\n", buffW[0]);
ok(len == 0, "got %d\n", len);
IMXNamespaceManager_Release(nsmgr);
free_bstrs();