Piotr Caban : mshtml: Added IHTMLFormElement_{get/ put}_encoding implementation.

Alexandre Julliard julliard at winehq.org
Thu Oct 28 12:19:51 CDT 2010


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu Oct 28 00:42:20 2010 +0200

mshtml: Added IHTMLFormElement_{get/put}_encoding implementation.

---

 dlls/mshtml/htmlform.c  |   45 +++++++++++++++++++++++++++++++++++++++++----
 dlls/mshtml/tests/dom.c |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/dlls/mshtml/htmlform.c b/dlls/mshtml/htmlform.c
index 37cf2ec..27aef79 100644
--- a/dlls/mshtml/htmlform.c
+++ b/dlls/mshtml/htmlform.c
@@ -188,16 +188,53 @@ static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
 
 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
 {
+    static const WCHAR urlencodedW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
+        'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
+    static const WCHAR dataW[] = {'m','u','l','t','i','p','a','r','t','/',
+        'f','o','r','m','-','d','a','t','a',0};
+    static const WCHAR plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
+
     HTMLFormElement *This = HTMLFORM_THIS(iface);
-    FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
-    return E_NOTIMPL;
+    nsAString encoding_str;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
+
+    if(lstrcmpiW(v, urlencodedW) && lstrcmpiW(v, dataW) && lstrcmpiW(v, plainW)) {
+        WARN("incorrect enctype\n");
+        return E_INVALIDARG;
+    }
+
+    nsAString_InitDepend(&encoding_str, v);
+    nsres = nsIDOMHTMLFormElement_SetEnctype(This->nsform, &encoding_str);
+    nsAString_Finish(&encoding_str);
+    if(NS_FAILED(nsres))
+        return E_FAIL;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
 {
     HTMLFormElement *This = HTMLFORM_THIS(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsAString encoding_str;
+    nsresult nsres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    nsAString_Init(&encoding_str, NULL);
+    nsres = nsIDOMHTMLFormElement_GetEnctype(This->nsform, &encoding_str);
+    if(NS_SUCCEEDED(nsres)) {
+        const PRUnichar *encoding;
+        nsAString_GetData(&encoding_str, &encoding);
+
+        *p = SysAllocString(encoding);
+        if(!*p)
+            return E_OUTOFMEMORY;
+    }else
+        return E_FAIL;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index c634cf6..ed95b6c 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -2662,6 +2662,40 @@ static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
     _test_form_name(line, unk, name);
 }
 
+#define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
+static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
+{
+    IHTMLFormElement *form = _get_form_iface(line, unk);
+    BSTR encoding = (void*)0xdeadbeef;
+    HRESULT hres;
+
+    hres = IHTMLFormElement_get_encoding(form, &encoding);
+    ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
+    if(ex)
+        ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
+    else
+        ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
+
+    SysFreeString(encoding);
+    IHTMLFormElement_Release(form);
+}
+
+#define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
+static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
+{
+    IHTMLFormElement *form = _get_form_iface(line, unk);
+    BSTR tmp = a2bstr(encoding);
+    HRESULT hres;
+
+    hres = IHTMLFormElement_put_encoding(form, tmp);
+    ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
+    SysFreeString(tmp);
+    IHTMLFormElement_Release(form);
+
+    if(exp_hres == S_OK)
+        _test_form_encoding(line, unk, encoding);
+}
+
 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
 {
@@ -6361,6 +6395,13 @@ static void test_elems2(IHTMLDocument2 *doc)
         test_form_put_method((IUnknown*)elem, S_OK, "post");
         test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
         test_form_method((IUnknown*)elem, "post");
+        test_form_name((IUnknown*)elem, NULL);
+        test_form_put_name((IUnknown*)elem, "Name");
+        test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
+        test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
+        test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
+        test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
+        test_form_encoding((IUnknown*)elem, "multipart/form-data");
         IHTMLElement_Release(elem);
     }
 




More information about the wine-cvs mailing list