riched20/tests: Added ITextServices::TxGetNaturalSize test
Austin Lund
austin.lund at gmail.com
Tue Jan 13 22:45:04 CST 2009
-------------- next part --------------
From c7b176dd3475519a3b2e41b0cd39b7cba44021b6 Mon Sep 17 00:00:00 2001
From: Austin Lund <austin.lund at gmail.com>
Date: Wed, 14 Jan 2009 14:17:30 +1000
Subject: [PATCH] riched20/tests: Added ITextServices::TxGetNaturalSize test.
---
dlls/riched20/tests/txtsrv.c | 77 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index 0714535..13c0cf0 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,77 @@ 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};
+
+ /* The test string */
+ static const WCHAR oneA[] = {'A',0};
+
+ /* Variables to hold the 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];
+ INT charwidth_lower_text[26];
+ TEXTMETRIC tmInfo_text;
+
+ if (!init_texthost())
+ return;
+
+ /* Obtain a device context form the root window. */
+ hdcDraw = GetDC(NULL);
+ SaveDC(hdcDraw);
+
+#define capsize_text(char) charwidth_caps_text[(int)char - (int)'A']
+#define size_text(char) charwidth_lower_text[(int)char - (int)'a']
+
+ /* Populate the metric strucs with the letters from the English
+ alphabet using MM_TEXT metric. */
+ SetMapMode(hdcDraw,MM_TEXT);
+ GetTextMetrics(hdcDraw, &tmInfo_text);
+
+ GetCharWidth32(hdcDraw,(UINT)'A',(UINT)'Z',charwidth_caps_text);
+ GetCharWidth32(hdcDraw,(UINT)'a',(UINT)'z',charwidth_lower_text);
+
+ /* Make measurements in MM_TEXT */
+ SetMapMode(hdcDraw,MM_TEXT);
+ xdim = 0; ydim = 0;
+
+ /* Measure a single 'A' character */
+ 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 has rounding errors when calculating widths with
+ the MM_TEXT metric. See:
+ http://www.kegel.com/wine/itextservices-demo.cc.txt */
+ todo_wine ok(xdim >= capsize_text('A') && xdim <= capsize_text('A') + 1,
+ "Width calculated incorrectly (expected %d {+1}, got %d)\n",
+ capsize_text('A'), xdim);
+
+ RestoreDC(hdcDraw,1);
+ ReleaseDC(NULL,hdcDraw);
+
+ IUnknown_Release(txtserv);
+ CoTaskMemFree(dummyTextHost);
+}
+
START_TEST( txtsrv )
{
setup_thiscall_wrappers();
@@ -682,6 +758,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