Nikolay Sivov : msxml3: Basic support for encoding property.

Alexandre Julliard julliard at winehq.org
Mon May 2 14:16:15 CDT 2011


Module: wine
Branch: master
Commit: e93125f31b5f6a57ec01e94b46727bf30f6a46e6
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e93125f31b5f6a57ec01e94b46727bf30f6a46e6

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun May  1 12:54:09 2011 +0400

msxml3: Basic support for encoding property.

---

 dlls/msxml3/mxwriter.c        |   32 ++++++++++++++++++++++++++++----
 dlls/msxml3/tests/saxreader.c |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/dlls/msxml3/mxwriter.c b/dlls/msxml3/mxwriter.c
index 14fccb8..fe7fba7 100644
--- a/dlls/msxml3/mxwriter.c
+++ b/dlls/msxml3/mxwriter.c
@@ -46,6 +46,7 @@ typedef struct _mxwriter
     LONG ref;
 
     VARIANT_BOOL standalone;
+    BSTR encoding;
 
     IStream *dest;
 } mxwriter;
@@ -107,6 +108,7 @@ static ULONG WINAPI mxwriter_Release(IMXWriter *iface)
     if(!ref)
     {
         if (This->dest) IStream_Release(This->dest);
+        SysFreeString(This->encoding);
         heap_free(This);
     }
 
@@ -232,16 +234,35 @@ static HRESULT WINAPI mxwriter_get_output(IMXWriter *iface, VARIANT *dest)
 
 static HRESULT WINAPI mxwriter_put_encoding(IMXWriter *iface, BSTR encoding)
 {
+    static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
+    static const WCHAR utf8W[]  = {'U','T','F','-','8',0};
     mxwriter *This = impl_from_IMXWriter( iface );
-    FIXME("(%p)->(%s)\n", This, debugstr_w(encoding));
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(encoding));
+
+    /* FIXME: filter all supported encodings */
+    if (!strcmpW(encoding, utf16W) || !strcmpW(encoding, utf8W))
+    {
+        SysFreeString(This->encoding);
+        This->encoding = SysAllocString(encoding);
+        return S_OK;
+    }
+    else
+    {
+        FIXME("unsupported encoding %s\n", debugstr_w(encoding));
+        return E_INVALIDARG;
+    }
 }
 
 static HRESULT WINAPI mxwriter_get_encoding(IMXWriter *iface, BSTR *encoding)
 {
     mxwriter *This = impl_from_IMXWriter( iface );
-    FIXME("(%p)->(%p)\n", This, encoding);
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%p)\n", This, encoding);
+
+    if (!encoding) return E_POINTER;
+
+    return return_bstr(This->encoding, encoding);
 }
 
 static HRESULT WINAPI mxwriter_put_byteOrderMark(IMXWriter *iface, VARIANT_BOOL writeBOM)
@@ -532,6 +553,7 @@ static const struct ISAXContentHandlerVtbl mxwriter_saxcontent_vtbl =
 
 HRESULT MXWriter_create(IUnknown *pUnkOuter, void **ppObj)
 {
+    static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
     mxwriter *This;
 
     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
@@ -547,6 +569,8 @@ HRESULT MXWriter_create(IUnknown *pUnkOuter, void **ppObj)
     This->ref = 1;
 
     This->standalone = VARIANT_FALSE;
+    This->encoding = SysAllocString(utf16W);
+
     This->dest = NULL;
 
     *ppObj = &This->IMXWriter_iface;
diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c
index 1f7aac7..34fa902 100644
--- a/dlls/msxml3/tests/saxreader.c
+++ b/dlls/msxml3/tests/saxreader.c
@@ -691,9 +691,13 @@ static void test_mxwriter_contenthandler(void)
 
 static void test_mxwriter_properties(void)
 {
+    static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
+    static const WCHAR emptyW[] = {0};
+    static const WCHAR testW[] = {'t','e','s','t',0};
     IMXWriter *writer;
     VARIANT_BOOL b;
     HRESULT hr;
+    BSTR str, str2;
 
     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
             &IID_IMXWriter, (void**)&writer);
@@ -716,6 +720,40 @@ static void test_mxwriter_properties(void)
     ok(hr == S_OK, "got %08x\n", hr);
     ok(b == VARIANT_TRUE, "got %d\n", b);
 
+    hr = IMXWriter_get_encoding(writer, NULL);
+    ok(hr == E_POINTER, "got %08x\n", hr);
+
+    /* UTF-16 is a default setting apparently */
+    str = (void*)0xdeadbeef;
+    hr = IMXWriter_get_encoding(writer, &str);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
+
+    str2 = (void*)0xdeadbeef;
+    hr = IMXWriter_get_encoding(writer, &str2);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(str != str2, "expected newly allocated, got same %p\n", str);
+
+    SysFreeString(str2);
+    SysFreeString(str);
+
+    /* put empty string */
+    str = SysAllocString(emptyW);
+    hr = IMXWriter_put_encoding(writer, str);
+    ok(hr == E_INVALIDARG, "got %08x\n", hr);
+    SysFreeString(str);
+
+    str = (void*)0xdeadbeef;
+    hr = IMXWriter_get_encoding(writer, &str);
+    ok(hr == S_OK, "got %08x\n", hr);
+    ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
+
+    /* invalid encoding name */
+    str = SysAllocString(testW);
+    hr = IMXWriter_put_encoding(writer, str);
+    ok(hr == E_INVALIDARG, "got %08x\n", hr);
+    SysFreeString(str);
+
     IMXWriter_Release(writer);
 }
 




More information about the wine-cvs mailing list