[PATCH 4/4] Basic input object creation on IXmlReader::SetInput()

Nikolay Sivov bunglehead at gmail.com
Thu Jan 21 12:05:25 CST 2010


---
 dlls/xmllite/reader.c       |   39 +++++++++++++++++++++++++++++++++++++--
 dlls/xmllite/tests/reader.c |    8 ++++++--
 include/xmllite.idl         |    5 ++++-
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/dlls/xmllite/reader.c b/dlls/xmllite/reader.c
index 60df234..99a9e7a 100644
--- a/dlls/xmllite/reader.c
+++ b/dlls/xmllite/reader.c
@@ -38,6 +38,7 @@ typedef struct _xmlreader
 {
     const IXmlReaderVtbl *lpVtbl;
     LONG ref;
+    IXmlReaderInput *input;
 } xmlreader;
 
 typedef struct _xmlreaderinput
@@ -95,6 +96,7 @@ static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
     ref = InterlockedDecrement(&This->ref);
     if (ref == 0)
     {
+        if (This->input) IUnknown_Release(This->input);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -103,8 +105,40 @@ static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
 
 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
 {
-    FIXME("(%p %p): stub\n", iface, input);
-    return E_NOTIMPL;
+    xmlreader *This = impl_from_IXmlReader(iface);
+    HRESULT hr;
+
+    TRACE("(%p %p)\n", This, input);
+
+    if (This->input)
+    {
+        IUnknown_Release(This->input);
+        This->input = NULL;
+    }
+
+    /* just reset current input */
+    if (!input) return S_OK;
+
+    /* now try IXmlReaderInput, ISequentialStream, IStream */
+    hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input);
+    if (hr != S_OK)
+    {
+        IUnknown *stream_input = NULL;
+
+        hr = IUnknown_QueryInterface(input, &IID_ISequentialStream, (void**)&stream_input);
+        if (hr != S_OK)
+        {
+            hr = IUnknown_QueryInterface(input, &IID_IStream, (void**)&stream_input);
+            if (hr != S_OK) return hr;
+        }
+
+        /* create IXmlReaderInput basing on supplied interface */
+        IUnknown_Release(stream_input);
+        return CreateXmlReaderInputWithEncodingName(stream_input,
+                                         NULL, NULL, FALSE, NULL, &This->input);
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
@@ -357,6 +391,7 @@ HRESULT WINAPI CreateXmlReader(REFIID riid, void **pObject, IMalloc *pMalloc)
 
     reader->lpVtbl = &xmlreader_vtbl;
     reader->ref = 1;
+    reader->input = NULL;
 
     *pObject = &reader->lpVtbl;
 
diff --git a/dlls/xmllite/tests/reader.c b/dlls/xmllite/tests/reader.c
index 5585853..27dae53 100644
--- a/dlls/xmllite/tests/reader.c
+++ b/dlls/xmllite/tests/reader.c
@@ -195,14 +195,18 @@ static void test_reader_create(void)
     hr = IMalloc_DidAlloc(imalloc, reader);
     ok(hr != 1, "Expected 0 or -1, got %08x\n", hr);
 
+    /* Null input pointer, releases previous input */
+    hr = IXmlReader_SetInput(reader, NULL);
+    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
+
     /* test input interface selection sequence */
     hr = testinput_createinstance((void**)&input);
     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
 
     input_iids.count = 0;
     hr = IXmlReader_SetInput(reader, input);
-    todo_wine ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
-    ok_iids(&input_iids, setinput_full, sizeof(setinput_full)/sizeof(REFIID), TRUE);
+    ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
+    ok_iids(&input_iids, setinput_full, sizeof(setinput_full)/sizeof(REFIID), FALSE);
 
     IUnknown_Release(input);
 
diff --git a/include/xmllite.idl b/include/xmllite.idl
index 0fd65a4..e827612 100644
--- a/include/xmllite.idl
+++ b/include/xmllite.idl
@@ -81,5 +81,8 @@ interface IXmlReader : IUnknown
 /* IXmlReader construction */
 cpp_quote("STDAPI CreateXmlReader(REFIID riid, void **ppvObject, IMalloc *pMalloc);")
 
-typedef IUnknown IXmlReaderInput;
+cpp_quote("typedef IUnknown IXmlReaderInput;")
+cpp_quote("STDAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream, IMalloc *pMalloc,")
+cpp_quote("                                            LPCWSTR encoding, BOOL hint,")
+cpp_quote("                                            LPCWSTR base_uri, IXmlReaderInput **ppInput);")
 
-- 
1.5.6.5


--=-3tD158NvP9+tGo/ySlp+--




More information about the wine-patches mailing list