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

xmllite: Implement attribute iteration methods.

parent 13f12649
......@@ -113,6 +113,7 @@ typedef struct _xmlreader
DtdProcessing dtdmode;
UINT line, pos; /* reader position in XML stream */
struct list attrs; /* attributes list for current node */
struct attribute *attr; /* current attribute */
UINT attr_count;
} xmlreader;
......@@ -942,14 +943,32 @@ static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node
static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
{
FIXME("(%p): stub\n", iface);
return E_NOTIMPL;
xmlreader *This = impl_from_IXmlReader(iface);
TRACE("(%p)\n", This);
if (!This->attr_count) return S_FALSE;
This->attr = LIST_ENTRY(list_head(&This->attrs), struct attribute, entry);
return S_OK;
}
static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
{
FIXME("(%p): stub\n", iface);
return E_NOTIMPL;
xmlreader *This = impl_from_IXmlReader(iface);
const struct list *next;
TRACE("(%p)\n", This);
if (!This->attr_count) return S_FALSE;
if (!This->attr)
return IXmlReader_MoveToFirstAttribute(iface);
next = list_next(&This->attrs, &This->attr->entry);
if (next)
This->attr = LIST_ENTRY(next, struct attribute, entry);
return next ? S_OK : S_FALSE;
}
static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
......@@ -962,8 +981,13 @@ static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
{
FIXME("(%p): stub\n", iface);
return E_NOTIMPL;
xmlreader *This = impl_from_IXmlReader(iface);
TRACE("(%p)\n", This);
if (!This->attr_count) return S_FALSE;
This->attr = NULL;
return S_OK;
}
static HRESULT WINAPI xmlreader_GetQualifiedName(IXmlReader* iface, LPCWSTR *qualifiedName,
......@@ -1202,6 +1226,7 @@ HRESULT WINAPI CreateXmlReader(REFIID riid, void **obj, IMalloc *imalloc)
reader->nodetype = XmlNodeType_None;
list_init(&reader->attrs);
reader->attr_count = 0;
reader->attr = NULL;
*obj = &reader->IXmlReader_iface;
......
......@@ -591,6 +591,7 @@ static void test_read_xmldeclaration(void)
HRESULT hr;
XmlNodeType type;
UINT count = 0;
const WCHAR *val;
hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
......@@ -611,6 +612,16 @@ static void test_read_xmldeclaration(void)
ok(hr == S_OK, "got %08x\n", hr);
ok(count == 0, "got %d\n", count);
/* try to move without attributes */
hr = IXmlReader_MoveToElement(reader);
ok(hr == S_FALSE, "got %08x\n", hr);
hr = IXmlReader_MoveToNextAttribute(reader);
ok(hr == S_FALSE, "got %08x\n", hr);
hr = IXmlReader_MoveToFirstAttribute(reader);
ok(hr == S_FALSE, "got %08x\n", hr);
ok_pos(reader, 0, 0, -1, -1, FALSE);
type = -1;
......@@ -622,13 +633,27 @@ static void test_read_xmldeclaration(void)
ok_pos(reader, 1, 3, -1, 55, TRUE);
test_read_state(reader, XmlReadState_Interactive, -1, 0);
hr = IXmlReader_GetValue(reader, &val, NULL);
todo_wine
ok(hr == S_OK, "got %08x\n", hr);
if (hr == S_OK)
ok(*val == 0, "got %s\n", wine_dbgstr_w(val));
/* check attributes */
hr = IXmlReader_MoveToNextAttribute(reader);
todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(hr == S_OK, "got %08x\n", hr);
ok_pos(reader, 1, 7, -1, 55, TRUE);
/* try to move from last attribute */
hr = IXmlReader_MoveToNextAttribute(reader);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlReader_MoveToNextAttribute(reader);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlReader_MoveToNextAttribute(reader);
ok(hr == S_FALSE, "got %08x\n", hr);
hr = IXmlReader_MoveToFirstAttribute(reader);
todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(hr == S_OK, "got %08x\n", hr);
ok_pos(reader, 1, 7, -1, 55, TRUE);
hr = IXmlReader_GetAttributeCount(reader, NULL);
......@@ -644,6 +669,9 @@ todo_wine {
ok(count == 1, "Expected 1, got %d\n", count);
}
hr = IXmlReader_MoveToElement(reader);
ok(hr == S_OK, "got %08x\n", hr);
IStream_Release(stream);
IXmlReader_Release(reader);
}
......
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