From fb297f3423e913e7c25e433a0257a12970666d57 Mon Sep 17 00:00:00 2001
From: Jactry Zeng <wine@jactry.com>
Date: Mon, 11 Aug 2014 13:51:55 +0800
Subject: riched20: Stub for ITextFont interface and implement
 ITextRange::GetFont and ITextSelection::GetFont.

---
 dlls/riched20/richole.c       | 20 ++++++++++
 dlls/riched20/tests/richole.c | 93 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index d39bce7..64809cc 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -2544,6 +2544,10 @@ static HRESULT WINAPI TextFont_SetDuplicate(ITextFont *iface, ITextFont *pFont)
 {
     ITextFontImpl *This = impl_from_ITextFont(iface);
     FIXME("(%p)->(%p): stub\n", This, pFont);
+
+    if (This->range && !get_range_reole(This->range))
+        return CO_E_RELEASED;
+
     return E_NOTIMPL;
 }
 
@@ -2551,6 +2555,10 @@ static HRESULT WINAPI TextFont_CanChange(ITextFont *iface, LONG *ret)
 {
     ITextFontImpl *This = impl_from_ITextFont(iface);
     FIXME("(%p)->(%p): stub\n", This, ret);
+
+    if (This->range && !get_range_reole(This->range))
+        return CO_E_RELEASED;
+
     return E_NOTIMPL;
 }
 
@@ -2558,6 +2566,10 @@ static HRESULT WINAPI TextFont_IsEqual(ITextFont *iface, ITextFont *font, LONG *
 {
     ITextFontImpl *This = impl_from_ITextFont(iface);
     FIXME("(%p)->(%p %p): stub\n", This, font, ret);
+
+    if (This->range && !get_range_reole(This->range))
+        return CO_E_RELEASED;
+
     return E_NOTIMPL;
 }
 
@@ -2731,6 +2743,10 @@ static HRESULT WINAPI TextFont_GetStyle(ITextFont *iface, LONG *value)
 {
     ITextFontImpl *This = impl_from_ITextFont(iface);
     FIXME("(%p)->(%p): stub\n", This, value);
+
+    if (This->range && !get_range_reole(This->range))
+        return CO_E_RELEASED;
+
     return E_NOTIMPL;
 }
 
@@ -2738,6 +2754,10 @@ static HRESULT WINAPI TextFont_SetStyle(ITextFont *iface, LONG value)
 {
     ITextFontImpl *This = impl_from_ITextFont(iface);
     FIXME("(%p)->(%d): stub\n", This, value);
+
+    if (This->range && !get_range_reole(This->range))
+        return CO_E_RELEASED;
+
     return E_NOTIMPL;
 }
 
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 3be6320..5f8e1cc 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -3382,6 +3382,97 @@ static void test_ITextSelection_SetEnd(void)
   release_interfaces(&w, &reOle, &txtDoc, &txtSel);
 }
 
+static void test_ITextRange_GetFont(void)
+{
+  HWND w;
+  IRichEditOle *reOle = NULL;
+  ITextDocument *txtDoc = NULL;
+  ITextRange *txtRge = NULL;
+  ITextFont *txtFont = NULL, *txtFont1 = NULL;
+  HRESULT hres;
+  int first, lim;
+  int refcount;
+  static const CHAR test_text1[] = "TestSomeText";
+  LONG value;
+
+  create_interfaces(&w, &reOle, &txtDoc, NULL);
+  SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+
+  first = 4, lim = 4;
+  ITextDocument_Range(txtDoc, first, lim, &txtRge);
+  refcount = get_refcount((IUnknown *)txtRge);
+  ok(refcount == 1, "got wrong ref count: %d\n", refcount);
+
+  hres = ITextRange_GetFont(txtRge, &txtFont);
+  ok(hres == S_OK, "ITextRange_GetFont\n");
+  refcount = get_refcount((IUnknown *)txtFont);
+  ok(refcount == 1, "got wrong ref count: %d\n", refcount);
+  refcount = get_refcount((IUnknown *)txtRge);
+  ok(refcount == 2, "got wrong ref count: %d\n", refcount);
+
+  hres = ITextRange_GetFont(txtRge, &txtFont1);
+  ok(hres == S_OK, "ITextRange_GetFont\n");
+  ok(txtFont1 != txtFont, "A new pointer should be return\n");
+  refcount = get_refcount((IUnknown *)txtFont1);
+  ok(refcount == 1, "got wrong ref count: %d\n", refcount);
+  ITextFont_Release(txtFont1);
+  refcount = get_refcount((IUnknown *)txtRge);
+  ok(refcount == 2, "got wrong ref count: %d\n", refcount);
+
+  ITextRange_Release(txtRge);
+  release_interfaces(&w, &reOle, &txtDoc, NULL);
+
+  hres = ITextFont_GetOutline(txtFont, &value);
+  ok(hres == CO_E_RELEASED, "ITextFont after ITextDocument destroyed\n");
+
+  ITextFont_Release(txtFont);
+}
+
+static void test_ITextSelection_GetFont(void)
+{
+  HWND w;
+  IRichEditOle *reOle = NULL;
+  ITextDocument *txtDoc = NULL;
+  ITextSelection *txtSel = NULL;
+  ITextFont *txtFont = NULL, *txtFont1 = NULL;
+  HRESULT hres;
+  int first, lim;
+  int refcount;
+  static const CHAR test_text1[] = "TestSomeText";
+  LONG value;
+
+  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
+  SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+
+  first = 4, lim = 4;
+  SendMessageA(w, EM_SETSEL, first, lim);
+  refcount = get_refcount((IUnknown *)txtSel);
+  ok(refcount == 2, "got wrong ref count: %d\n", refcount);
+
+  hres = ITextSelection_GetFont(txtSel, &txtFont);
+  ok(hres == S_OK, "ITextSelection_GetFont\n");
+  refcount = get_refcount((IUnknown *)txtFont);
+  ok(refcount == 1, "got wrong ref count: %d\n", refcount);
+  refcount = get_refcount((IUnknown *)txtSel);
+  ok(refcount == 3, "got wrong ref count: %d\n", refcount);
+
+  hres = ITextSelection_GetFont(txtSel, &txtFont1);
+  ok(hres == S_OK, "ITextSelection_GetFont\n");
+  ok(txtFont1 != txtFont, "A new pointer should be return\n");
+  refcount = get_refcount((IUnknown *)txtFont1);
+  ok(refcount == 1, "got wrong ref count: %d\n", refcount);
+  ITextFont_Release(txtFont1);
+  refcount = get_refcount((IUnknown *)txtSel);
+  ok(refcount == 3, "got wrong ref count: %d\n", refcount);
+
+  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
+
+  hres = ITextFont_GetOutline(txtFont, &value);
+  ok(hres == CO_E_RELEASED, "ITextFont after ITextDocument destroyed\n");
+
+  ITextFont_Release(txtFont);
+}
+
 START_TEST(richole)
 {
   /* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -3397,6 +3488,7 @@ START_TEST(richole)
   test_ITextSelection_SetStart();
   test_ITextSelection_SetEnd();
   test_ITextSelection_Collapse();
+  test_ITextSelection_GetFont();
   test_ITextDocument_Range();
   test_ITextRange_GetChar();
   test_ITextRange_GetStart_GetEnd();
@@ -3404,6 +3496,7 @@ START_TEST(richole)
   test_ITextRange_SetStart();
   test_ITextRange_SetEnd();
   test_ITextRange_Collapse();
+  test_ITextRange_GetFont();
   test_GetClientSite();
   test_IOleWindow_GetWindow();
   test_IOleInPlaceSite_GetWindow();
-- 
2.4.2

