riched20/tests: Added ITextServices::TxGetNaturalSize test (resent)

Austin Lund austin.lund at gmail.com
Thu Jan 15 17:23:42 CST 2009


-------------- next part --------------
From 19c4d3b8858ca58389551acfc7d6a854dc597527 Mon Sep 17 00:00:00 2001
From: Austin Lund <austin.lund at gmail.com>
Date: Fri, 16 Jan 2009 09:18:05 +1000
Subject: [PATCH] riched20/tests: Added ITextServices::TxGetNaturalSize test.

---
 dlls/riched20/tests/txtsrv.c |   66 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index 0714535..70d140e 100644
--- a/dlls/riched20/tests/txtsrv.c
+++ b/dlls/riched20/tests/txtsrv.c
@@ -32,6 +32,7 @@
 #include <textserv.h>
 #include <wine/test.h>
 #include <oleauto.h>
+#include <limits.h>
 
 static HMODULE hmoduleRichEdit;
 
@@ -434,12 +435,16 @@ static void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface, HIMC himc
     TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This, himc);
 }
 
+/* This function must set the variable pointed to by *lSelBarWidth.
+   Otherwise an uninitalized value will be used to calculate
+   positions and sizes even if E_NOTIMPL is returned. */
 static HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
                                                            LONG *lSelBarWidth)
 {
     ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
     TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
                 This, lSelBarWidth);
+    *lSelBarWidth = 0;
     return E_NOTIMPL;
 }
 
@@ -666,6 +671,66 @@ static void test_TxSetText(void)
     CoTaskMemFree(dummyTextHost);
 }
 
+void test_TxGetNaturalSize() {
+    HRESULT result;
+
+    /* This value is used when calling TxGetNaturalSize.  MSDN says
+       that this is not supported however a null pointer cannot be
+       used as it will cause a segmentation violation.  The values in
+       the structure being pointed to are required to be LONG_MAX
+       otherwise calculations can give wrong values. */
+    const SIZEL psizelExtent = {LONG_MAX,LONG_MAX};
+
+    static const WCHAR oneA[] = {'A',0};
+
+    /* Results of measurements */
+    LONG xdim, ydim;
+
+    /* The device context to do the tests in */
+    HDC hdcDraw;
+
+    /* Variables with the text metric information */
+    INT charwidth_caps_text[26];
+    TEXTMETRIC tmInfo_text;
+
+    if (!init_texthost())
+        return;
+
+    hdcDraw = GetDC(NULL);
+    SaveDC(hdcDraw);
+
+    /* Populate the metric strucs */
+    SetMapMode(hdcDraw,MM_TEXT);
+    GetTextMetrics(hdcDraw, &tmInfo_text);
+    GetCharWidth32(hdcDraw,(UINT)'A',(UINT)'Z',charwidth_caps_text);
+
+    /* Make measurements in MM_TEXT */
+    SetMapMode(hdcDraw,MM_TEXT);
+    xdim = 0; ydim = 0;
+
+    result = ITextServices_TxSetText(txtserv, (LPCWSTR)oneA);
+    todo_wine ok(result == S_OK, "ITextServices_TxSetText failed\n");
+
+    result = ITextServices_TxGetNaturalSize(txtserv, (DWORD) DVASPECT_CONTENT, 
+                                            hdcDraw, NULL, NULL, 
+                                            TXTNS_FITTOCONTENT, &psizelExtent, 
+                                            &xdim, &ydim);
+    todo_wine ok(result == S_OK, "TxGetNaturalSize failed\n");
+    todo_wine ok(ydim == tmInfo_text.tmHeight,
+                 "Height calculated incorrectly (expected %d, got %d)\n",
+                 tmInfo_text.tmHeight, ydim);
+    /* The native DLL adds one pixel extra when calculating widths. */
+    todo_wine ok(xdim >= charwidth_caps_text[0] && xdim <= charwidth_caps_text[0] + 1,
+                 "Width calculated incorrectly (expected %d {+1}, got %d)\n",
+                 charwidth_caps_text[0], xdim);
+
+    RestoreDC(hdcDraw,1);
+    ReleaseDC(NULL,hdcDraw);
+
+    IUnknown_Release(txtserv);
+    CoTaskMemFree(dummyTextHost);
+}
+
 START_TEST( txtsrv )
 {
     setup_thiscall_wrappers();
@@ -682,6 +747,7 @@ START_TEST( txtsrv )
 
         test_TxGetText();
         test_TxSetText();
+        test_TxGetNaturalSize();
     }
     if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);
 }
-- 
1.5.6.3


More information about the wine-patches mailing list