Re: mshtml.dll:Add implementation of HTMLDocument_(Get|Set)Title

2008-07-09 Thread Ivan Sinitsin
В сообщении от Friday 04 July 2008 19:23:32 вы написали:
> Ivan Sinitsin wrote:
> > Changelog:
> > mshtml.dll:Add implementation of HTMLDocument_(Get|Set)Title
>
> First of all it would be nice if you could add a test case for these.
>
Hi, 

I make test for HTMLDocument_(Get|Set)Title.
What do you think about it? Is it right?

On IE it - ok, but Gecko - failed.

>
> Jacek

--
Sinitsin Ivan
From 1456122d0ec239b1e34bc409c560f0da4ce39f2a Mon Sep 17 00:00:00 2001
From: Sinitsin Ivan <[EMAIL PROTECTED]>
Date: Wed, 9 Jul 2008 17:16:38 +0400
Subject: [PATCH] add test for HTMLDocument_(Get|Put)Title

---
 dlls/mshtml/tests/htmldoc.c |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c
index 4de5286..1eecb59 100644
--- a/dlls/mshtml/tests/htmldoc.c
+++ b/dlls/mshtml/tests/htmldoc.c
@@ -3664,6 +3664,32 @@ static void test_external(IUnknown *unk, BOOL 
initialized)
 IHTMLWindow2_Release(htmlwin);
 }
 
+static void test_Title(IUnknown *unk)
+{
+IHTMLDocument2 *htmldoc;
+BSTR ptitle, gtitle;
+const WCHAR title[] = {
+'H','T','M','L',' ','T','i','t','l','e',0};
+HRESULT hres;
+
+hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&htmldoc);
+ok(hres == S_OK, "QueryInterface(IID_IHTMLWindow2) failed: %08x\n", hres);
+
+ptitle = SysAllocString(title);
+
+hres = IHTMLDocument2_put_title(htmldoc, ptitle);
+ok(hres == S_OK, "put_Title failed: %08x\n", hres);
+
+hres = IHTMLDocument2_get_title(htmldoc, >itle);
+ok(hres == S_OK, "get_Title failed: %08x\n", hres);
+
+ok(!lstrcmpiW(ptitle, gtitle), "title not equal \n");
+
+SysFreeString(ptitle);
+SysFreeString(gtitle);
+IHTMLDocument2_Release(htmldoc);
+}
+
 static void test_StreamLoad(IUnknown *unk)
 {
 IPersistStreamInit *init;
@@ -3785,6 +3811,7 @@ static void test_HTMLDocument(BOOL do_load)
 test_OnAmbientPropertyChange(unk);
 test_Window(unk, TRUE);
 test_external(unk, TRUE);
+if (do_load) test_Title(unk);
 
 test_UIDeactivate();
 test_OleCommandTarget(unk);
-- 
1.5.4.5.GIT




Re: mshtml.dll:Add implementation of HTMLDocument_(Get|Set)Title

2008-07-04 Thread Jacek Caban
Ivan Sinitsin wrote:
> Changelog:
> mshtml.dll:Add implementation of HTMLDocument_(Get|Set)Title
>   

First of all it would be nice if you could add a test case for these.

>static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
> {
> HTMLDocument *This = HTMLDOC_THIS(iface);
>-FIXME("(%p)->(%s)\n", This, debugstr_w(v));
>-return E_NOTIMPL;
>+nsIDOMDocument *nsdoc;
>+nsIDOMHTMLDocument *nshtmldoc;
>+nsAString nsstr;
>+nsresult nsres;
>+
>+TRACE("(%p)->(%s)\n", This, debugstr_w(v));
>+
>+if(!This->nscontainer)
>+return E_POINTER;
>+
>+nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, 
>&nsdoc);
>+if(NS_FAILED(nsres)) {
>+ERR("GetDocument failed: %08x\n", nsres);
>+return nsres;
>+}
>+
>+if(NS_FAILED(nsres) || !nsdoc).
>+return E_FAIL;
>+
>+nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, 
>(void**)&nshtmldoc);
>+nsIDOMDocument_Release(nsdoc);
>+
>+nsAString_Init(&nsstr, NULL);
>+nsAString_SetData(&nsstr, v);


Use second argument of nsAString_Init instead of nsAString_SetData.

>+
>+nsres = nsIDOMHTMLDocument_SetTitle(nshtmldoc, &nsstr);
>+nsIDOMHTMLDocument_Release(nshtmldoc);
>+

You leak nsstr here.

>+return nsres;

Don't mix nsresult with HRESULT. You should return S_OK here.

> }
> 
> static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
> {
> HTMLDocument *This = HTMLDOC_THIS(iface);
>-FIXME("(%p)->(%p)\n", This, p);
>-return E_NOTIMPL;
>+nsIDOMDocument *nsdoc;
>+nsIDOMHTMLDocument *nshtmldoc;
>+nsAString nsstr;
>+const PRUnichar *ret;
>+nsresult nsres;
>+
>+TRACE("(%p)->(%p)\n", This, p);
>+
>+if (!p).
>+return E_POINTER;
>+
>+if(!This->nscontainer)
>+return E_POINTER;
>+
>+nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, 
>&nsdoc);
>+if(NS_FAILED(nsres)) {
>+ERR("GetDocument failed: %08x\n", nsres);
>+return nsres;
>+}
>+
>+if(NS_FAILED(nsres) || !nsdoc).
>+return E_FAIL;
>+
>+nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, 
>(void**)&nshtmldoc);
>+nsIDOMDocument_Release(nsdoc);
>+
>+nsAString_Init(&nsstr, NULL);
>+
>+nsres = nsIDOMHTMLDocument_GetTitle(nshtmldoc, &nsstr);
>+nsIDOMHTMLDocument_Release(nshtmldoc);
>+
>+if (NS_FAILED(nsres))
>+return nsres;

Don't mix nsresult with HRESULT. Also ERR would be nice in this case.

>+
>+nsAString_GetData(&nsstr, &ret);
>+*p = SysAllocString(ret);


DOM API usually returns NULL instead of empty string. That's worth testing.

>+
>+return nsres;
> }

Again, don't mix nsresult with HRESULT.



Jacek