From 25bde51d0cd9f805af03ae3a2234f284eb4464e9 Mon Sep 17 00:00:00 2001 From: Austin Lund Date: Thu, 3 Jul 2008 14:43:51 +1000 Subject: [PATCH] richedit: Added tests for simple strings for TxGetNaturalSize in txtsrv.c Strings of 'A' and 'I' chars are measured using GetCharWidth32. There appears to be a one pixel error in the native dll measurements. The test corrects for this difference. Also a string containing all capital letters is measured as well. --- dlls/riched20/tests/txtsrv.c | 258 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 258 insertions(+), 0 deletions(-) diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 8233bc5..d499b9c 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -102,6 +103,27 @@ __ASM_GLOBAL_FUNC(fnTextSrv_TxSetText, STDCALL_TO_THISCALL); #define fnTextSrv_TxSetText(f, iface, pszText) f(iface, pszText) #endif +#ifdef THISCALL_NEEDED +HRESULT WINAPI fnTextSrv_TxGetNaturalSize(LPVOID function, + ITextServices *iface, + DWORD dwAspect, + HDC hdcDraw, + HDC hicTargetDev, + DVTARGETDEVICE* ptd, + DWORD dwMode, + const SIZEL* psizelExtent, + LONG* pwidth, + LONG* pheight); +__ASM_GLOBAL_FUNC(fnTextSrv_TxGetNaturalSize, STDCALL_TO_THISCALL); +#else +#define fnTextSrv_TxGetNaturalSize(function, iface, dwAspect, \ + hdcDraw, hicTargetDev, ptd, \ + dwMode,psizelExtent, pwidth, \ + pheight) \ + function(iface, dwAspect, hdcDraw, hicTargetDev, ptd, dwMode, \ + psizelExtent, pwidth, pheight) +#endif + /************************************************************************/ /* ITextHost implementation for conformance testing. */ @@ -638,6 +660,240 @@ void TEST_TxSetGetText(LPCTSTR newtext) { } } +/* This sets up variables which are unused in a default state that + * works. */ +HRESULT TEST_TxGetNaturalSize_RAW(HDC hdcDraw, DWORD dwMode, + LONG *pwidth, LONG *pheight) { + HRESULT result; + DWORD dwAspect = (DWORD) ((DVASPECT) DVASPECT_CONTENT); + HDC hicTargetDev = NULL; /* Default device */ + DVTARGETDEVICE *ptd = NULL; + /* MSDN says that this is not supported, this is absolutely required. */ + const SIZEL psizelExtent = {LONG_MAX,LONG_MAX}; + + todo_wine { + trace("Calling TxGetNaturalSize (pwdith %d, pheight %d)\n", + *pwidth, *pheight); + result = fnTextSrv_TxGetNaturalSize(txtserv->lpVtbl->TxGetNaturalSize, + txtserv, + dwAspect, hdcDraw, hicTargetDev, + ptd, dwMode, &psizelExtent, + pwidth, pheight); + trace("Called TxGetNaturalSize (pwidth %d, pheight %d)\n", + *pwidth ,*pheight); + ok(result == S_OK, "TxGetNaturalSize failed\n"); + return result; + } + return E_FAIL; +} + +void TEST_TxGetNaturalSize_STRING(HDC hdcDraw, LPCTSTR lpctIn, + INT *lpintXdim, INT *lpintYdim) { + HRESULT result; + TEST_TxSetText(lpctIn); + result = TEST_TxGetNaturalSize_RAW(hdcDraw, TXTNS_FITTOCONTENT, + lpintXdim, lpintYdim); + if (result == S_OK) + trace("Calculated: %d %d\n", *lpintXdim, *lpintYdim); +} + +/* This test measures simple strings and checks the results. */ +void TEST_TxGetNaturalSize_MEASURE() { + + /* The test strings */ + static const WCHAR oneA[] = {'A',0}; + static const WCHAR twoA[] = {'A','A',0}; + static const WCHAR threeA[] = {'A','A','A',0}; + + static const WCHAR oneI[] = {'I',0}; + static const WCHAR twoI[] = {'I','I',0}; + static const WCHAR threeI[] = {'I','I','I',0}; + + static const WCHAR caps[] = {'A','B','C','D','E','F','G','H','I', + 'J','K','L','M','N','O','P','Q','R', + 'S','T','U','V','W','X','Y','Z',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_caps_himetric[26]; + INT charwidth_lower_text[26]; + INT charwidth_lower_himetric[26]; + TEXTMETRIC tmInfo_text; + TEXTMETRIC tmInfo_himetric; + INT total_caps_text, total_caps_himetric; + + /* An iterator variable */ + INT i; + + /* Obtain a device context form the root window. */ + hdcDraw = GetDC(NULL); + +#define capsize_himetric(char) charwidth_caps_himetric[(int)char - (int)'A'] +#define capsize_text(char) charwidth_caps_text[(int)char - (int)'A'] +#define size_himetric(char) charwidth_lower_himetric[(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 in both MM_TEXT and MM_HIMETRIC. + */ + SetMapMode(hdcDraw,MM_TEXT); + GetTextMetrics(hdcDraw, &tmInfo_text); + trace("Got height: %d (MM_TEXT)\n", tmInfo_text.tmHeight); + GetCharWidth32(hdcDraw,(UINT)'A',(UINT)'Z',charwidth_caps_text); + GetCharWidth32(hdcDraw,(UINT)'a',(UINT)'z',charwidth_lower_text); + total_caps_text = 0; + for (i = 0; i < 26; i++) + total_caps_text += charwidth_caps_text[i]; + + SetMapMode(hdcDraw,MM_HIMETRIC); + GetTextMetrics(hdcDraw, &tmInfo_himetric); + trace("Got height: %d (MM_HIMETRIC)\n", tmInfo_himetric.tmHeight); + GetCharWidth32(hdcDraw,(UINT)'A',(UINT)'Z',charwidth_caps_himetric); + GetCharWidth32(hdcDraw,(UINT)'A',(UINT)'Z',charwidth_lower_himetric); + total_caps_himetric = 0; + for (i = 0; i < 26; i++) + total_caps_himetric += charwidth_caps_himetric[i]; + + SetMapMode(hdcDraw,MM_TEXT); + + trace("Got width of A: %d himetric, %d px)\n",capsize_himetric('A'), + capsize_text('A')); + trace("Got width of I: %d himetric, %d px\n",capsize_himetric('I'), + capsize_text('I')); + trace("Sum of length of capitals: %d himetric, %d px\n", + total_caps_himetric, total_caps_text); + + /* Measurements in MM_TEXT */ + todo_wine { + /* Measure a series of As */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)oneA, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= capsize_text('A') && xdim <= capsize_text('A') + 1, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)twoA, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 2*capsize_text('A') && xdim <= 2*capsize_text('A') + 1, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)threeA, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 3*capsize_text('A') && xdim <= 3*capsize_text('A') + 1, + "Width calculated incorrectly\n"); + + /* Measure a series of Is */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)oneI, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= capsize_text('I') && xdim <= capsize_text('I') + 1, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)twoI, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 2*capsize_text('I') && xdim <= 2*capsize_text('I') + 1, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)threeI, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 3*capsize_text('I') && xdim <= 3*capsize_text('I') + 1, + "Width calculated incorrectly\n"); + + /* Measure all capital letters */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)caps, &xdim, &ydim); + ok(ydim == tmInfo_text.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= total_caps_text && xdim <= total_caps_text + 1, + "Width calculated incorrectly\n"); + } + + SaveDC(hdcDraw); + + /* Perform the measurements in MM_HIMETRIC */ + SetMapMode(hdcDraw,MM_HIMETRIC); + todo_wine{ + /* Measure a series of As */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)oneA, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= capsize_himetric('A') && + xdim <= capsize_himetric('A') + 27, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)twoA, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 2*capsize_himetric('A') && + xdim <= 2*capsize_himetric('A') + 27, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)threeA, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 3*capsize_himetric('A') && + xdim <= 3*capsize_himetric('A') + 27, + "Width calculated incorrectly\n"); + + /* Measure a series of Is */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)oneI, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= capsize_himetric('I') && + xdim <= capsize_himetric('I') + 27, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)twoI, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 2*capsize_himetric('I') && + xdim <= 2*capsize_himetric('I') + 27, + "Width calculated incorrectly\n"); + + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)threeI, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= 3*capsize_himetric('I') && + xdim <= 3*capsize_himetric('I') + 27, + "Width calculated incorrectly\n"); + + /* Measure all capital letters */ + xdim = 0; ydim = 0; + TEST_TxGetNaturalSize_STRING(hdcDraw, (LPCTSTR)caps, &xdim, &ydim); + ok(ydim == -tmInfo_himetric.tmHeight, + "Height calculated incorrectly\n"); + ok(xdim >= total_caps_himetric && + xdim <= total_caps_himetric + 27, + "Width calculated incorrectly\n"); + } + + RestoreDC(hdcDraw,1); + ReleaseDC(NULL,hdcDraw); +} + + START_TEST( txtsrv ) { static const WCHAR newtextw[] = @@ -648,4 +904,6 @@ START_TEST( txtsrv ) return; TEST_TxSetGetText((LPCTSTR)newtextw); + + TEST_TxGetNaturalSize_MEASURE(); } -- 1.5.4.3