xmllite: Initial support for just created reader state.

oldstable
Nikolay Sivov 2010-01-23 23:03:14 +03:00 committed by Alexandre Julliard
parent 7b7011e595
commit 02da36631e
3 changed files with 135 additions and 4 deletions

View File

@ -43,6 +43,7 @@ typedef struct _xmlreader
IXmlReaderInput *input;
ISequentialStream *stream;/* stored as sequential stream, cause currently
optimizations possible with IStream aren't implemented */
XmlReadState state;
} xmlreader;
typedef struct _xmlreaderinput
@ -122,11 +123,21 @@ static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
if (This->input)
{
IUnknown_Release(This->input);
This->input = NULL;
This->input = NULL;
}
if (This->stream)
{
IUnknown_Release(This->stream);
This->stream = NULL;
}
/* just reset current input */
if (!input) return S_OK;
if (!input)
{
This->state = XmlReadState_Closed;
return S_OK;
}
/* now try IXmlReaderInput, ISequentialStream, IStream */
hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input);
@ -146,14 +157,31 @@ static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
IUnknown_Release(This->input);
This->input = NULL;
}
else
This->state = XmlReadState_Initial;
return hr;
}
static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
{
FIXME("(%p %u %p): stub\n", iface, property, value);
return E_NOTIMPL;
xmlreader *This = impl_from_IXmlReader(iface);
TRACE("(%p %u %p)\n", This, property, value);
if (!value) return E_INVALIDARG;
switch (property)
{
case XmlReaderProperty_ReadState:
*value = This->state;
break;
default:
FIXME("Unimplemented property (%u)\n", property);
return E_NOTIMPL;
}
return S_OK;
}
static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
@ -418,6 +446,7 @@ HRESULT WINAPI CreateXmlReader(REFIID riid, void **pObject, IMalloc *pMalloc)
reader->ref = 1;
reader->stream = NULL;
reader->input = NULL;
reader->state = XmlReadState_Closed;
*pObject = &reader->lpVtbl;

View File

@ -107,6 +107,53 @@ static void ok_iids_(const input_iids_t *iids, const IID **expected, const IID *
}
#define ok_iids(got, exp, brk, todo) ok_iids_(got, exp, brk, todo, __LINE__)
static const char *state_to_str(XmlReadState state)
{
static const char* state_names[] = {
"XmlReadState_Initial",
"XmlReadState_Interactive",
"XmlReadState_Error",
"XmlReadState_EndOfFile",
"XmlReadState_Closed"
};
static const char unknown[] = "unknown";
switch (state)
{
case XmlReadState_Initial:
case XmlReadState_Interactive:
case XmlReadState_Error:
case XmlReadState_EndOfFile:
case XmlReadState_Closed:
return state_names[state];
default:
return unknown;
}
}
static void test_read_state_(IXmlReader *reader, XmlReadState expected, int todo, int line)
{
XmlReadState state;
HRESULT hr;
state = -1; /* invalid value */
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, (LONG_PTR*)&state);
ok_(__FILE__, line)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
if (todo)
{
todo_wine
ok_(__FILE__, line)(state == expected, "Expected (%s), got (%s)\n",
state_to_str(expected), state_to_str(state));
}
else
ok_(__FILE__, line)(state == expected, "Expected (%s), got (%s)\n",
state_to_str(expected), state_to_str(state));
}
#define test_read_sate(reader, exp, todo) test_read_state_(reader, exp, todo, __LINE__)
typedef struct _testinput
{
const IUnknownVtbl *lpVtbl;
@ -211,10 +258,14 @@ static void test_reader_create(void)
hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_read_sate(reader, XmlReadState_Closed, FALSE);
/* Null input pointer, releases previous input */
hr = IXmlReader_SetInput(reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_read_sate(reader, XmlReadState_Closed, FALSE);
/* test input interface selection sequence */
hr = testinput_createinstance((void**)&input);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
@ -267,6 +318,9 @@ static void test_readerinput(void)
hr = IXmlReader_SetInput(reader, reader_input);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_read_sate(reader, XmlReadState_Initial, FALSE);
/* IXmlReader grabs a IXmlReaderInput reference */
ref = IUnknown_AddRef(reader_input);
ok(ref == 3, "Expected 3, got %d\n", ref);
@ -276,6 +330,12 @@ static void test_readerinput(void)
ok(ref == 4, "Expected 4, got %d\n", ref);
IStream_Release(stream);
/* reset input and check state */
hr = IXmlReader_SetInput(reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_read_sate(reader, XmlReadState_Closed, FALSE);
IXmlReader_Release(reader);
ref = IStream_AddRef(stream);
@ -330,6 +390,8 @@ static void test_readerinput(void)
ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
test_read_sate(reader, XmlReadState_Closed, FALSE);
ref = IUnknown_AddRef(input);
ok(ref == 3, "Expected 3, got %d\n", ref);
IUnknown_Release(input);
@ -361,6 +423,21 @@ static void test_readerinput(void)
IUnknown_Release(input);
}
static void test_reader_state(void)
{
IXmlReader *reader;
HRESULT hr;
hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* invalid arguments */
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, NULL);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
IXmlReader_Release(reader);
}
START_TEST(reader)
{
HRESULT r;
@ -376,6 +453,7 @@ START_TEST(reader)
test_reader_create();
test_readerinput();
test_reader_state();
CoUninitialize();
}

View File

@ -78,6 +78,30 @@ interface IXmlReader : IUnknown
BOOL IsEOF(void);
}
/* IXmlReader state */
cpp_quote("typedef enum XmlReadState")
cpp_quote("{")
cpp_quote(" XmlReadState_Initial = 0,")
cpp_quote(" XmlReadState_Interactive = 1,")
cpp_quote(" XmlReadState_Error = 2,")
cpp_quote(" XmlReadState_EndOfFile = 3,")
cpp_quote(" XmlReadState_Closed = 4")
cpp_quote("} XmlReadState;")
/* IXmlReader properties */
cpp_quote("typedef enum XmlReaderProperty")
cpp_quote("{")
cpp_quote(" XmlReaderProperty_MultiLanguage = 0,")
cpp_quote(" XmlReaderProperty_ConformanceLevel = XmlReaderProperty_MultiLanguage + 1,")
cpp_quote(" XmlReaderProperty_RandomAccess = XmlReaderProperty_ConformanceLevel + 1,")
cpp_quote(" XmlReaderProperty_XmlResolver = XmlReaderProperty_RandomAccess + 1,")
cpp_quote(" XmlReaderProperty_DtdProcessing = XmlReaderProperty_XmlResolver + 1,")
cpp_quote(" XmlReaderProperty_ReadState = XmlReaderProperty_DtdProcessing + 1,")
cpp_quote(" XmlReaderProperty_MaxElementDepth = XmlReaderProperty_ReadState + 1,")
cpp_quote(" XmlReaderProperty_MaxEntityExpansion = XmlReaderProperty_MaxElementDepth + 1,")
cpp_quote(" _XmlReaderProperty_Last = XmlReaderProperty_MaxEntityExpansion")
cpp_quote("} XmlReaderProperty;")
/* IXmlReader construction */
cpp_quote("STDAPI CreateXmlReader(REFIID riid, void **ppvObject, IMalloc *pMalloc);")