text.c 37.6 KB
Newer Older
1 2 3 4
/*
 * DrawText tests
 *
 * Copyright (c) 2004 Zach Gorman
5
 * Copyright 2007,2016 Dmitry Timoshkov
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24 25 26 27 28
 */

#include <assert.h>

#include "wine/test.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winerror.h"
29
#include "winnls.h"
30

31
#define MODIFIED(rect) (rect.left == 10 && rect.right != 100 && rect.top == 10 && rect.bottom != 100)
32
#define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
33 34 35 36 37 38 39

static void test_DrawTextCalcRect(void)
{
    HWND hwnd;
    HDC hdc;
    HFONT hFont, hOldFont;
    LOGFONTA lf;
40
    static CHAR text[] = "Example text for testing DrawText in "
41
      "MM_HIENGLISH mode";
42
    static WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
43
        's','t','r','i','n','g','\0'};
44 45
    static CHAR emptystring[] = "";
    static WCHAR emptystringW[] = { 0 };
46 47
    static CHAR wordbreak_text[] = "line1 line2";
    static WCHAR wordbreak_textW[] = {'l','i','n','e','1',' ','l','i','n','e','2',0};
48
    static char tabstring[] = "one\ttwo";
49
    INT textlen, textheight, heightcheck;
50
    RECT rect = { 0, 0, 100, 0 }, rect2;
51
    BOOL ret;
52 53
    DRAWTEXTPARAMS dtp;
    BOOL conform_xp = TRUE;
54 55 56 57

    /* Initialization */
    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
                           0, 0, 200, 200, 0, 0, 0, NULL);
58
    ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
59
    hdc = GetDC(hwnd);
60
    ok(hdc != 0, "GetDC error %u\n", GetLastError());
61
    trace("hdc %p\n", hdc);
62
    textlen = lstrlenA(text);
63 64 65 66 67 68 69 70 71 72 73 74 75 76

    /* LOGFONT initialization */
    memset(&lf, 0, sizeof(lf));
    lf.lfCharSet = ANSI_CHARSET;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfWeight = FW_DONTCARE;
    lf.lfHeight = 0; /* mapping mode dependent */
    lf.lfQuality = DEFAULT_QUALITY;
    lstrcpyA(lf.lfFaceName, "Arial");

    /* DrawText in MM_HIENGLISH with DT_CALCRECT */
    SetMapMode(hdc, MM_HIENGLISH);
    lf.lfHeight = 100 * 9 / 72; /* 9 point */
    hFont = CreateFontIndirectA(&lf);
77
    ok(hFont != 0, "CreateFontIndirectA error %u\n",
78 79 80
       GetLastError());
    hOldFont = SelectObject(hdc, hFont);

81
    textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
82
       DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
83
       DT_NOPREFIX);
84
    ok( textheight, "DrawTextA error %u\n", GetLastError());
85

86
    trace("MM_HIENGLISH rect.bottom %d\n", rect.bottom);
87
    ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
88
       "DT_CALCRECT should return a negative rectangle bottom. "
89
       "(bot=%d)\n", rect.bottom);
90 91

    SelectObject(hdc, hOldFont);
92
    ret = DeleteObject(hFont);
93
    ok( ret, "DeleteObject error %u\n", GetLastError());
94 95 96 97 98 99 100


    /* DrawText in MM_TEXT with DT_CALCRECT */
    SetMapMode(hdc, MM_TEXT);
    lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
       LOGPIXELSY), 72); /* 9 point */
    hFont = CreateFontIndirectA(&lf);
101
    ok(hFont != 0, "CreateFontIndirectA error %u\n",
102 103 104
       GetLastError());
    hOldFont = SelectObject(hdc, hFont);

105
    textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
106
       DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
107
       DT_NOPREFIX);
108
    ok( textheight, "DrawTextA error %u\n", GetLastError());
109

110
    trace("MM_TEXT rect.bottom %d\n", rect.bottom);
111
    ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
112
       "should return a positive rectangle bottom. (bot=%d)\n",
113 114
       rect.bottom);

115
    /* empty or null text should in some cases calc an empty rectangle */
116

117
    SetRect( &rect, 10,10, 100, 100);
118
    heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT, NULL );
119 120
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
121
    ok(textheight==0,"Got textheight from DrawTextExA\n");
122 123 124

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT);
125 126
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
127 128 129 130
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

131 132
    SetRect( &rect, 10,10, 100, 100);
    SetLastError( 0);
133
    heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT, NULL );
134
    ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
135 136 137 138
    ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT);
139
    ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
140 141 142
    ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

143 144
    SetRect( &rect, 10,10, 100, 100);
    SetLastError( 0);
145
    heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
146
    ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
147 148 149
    if (!textheight) /* Windows NT 4 */
    {
        if (conform_xp)
150
            win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
151 152 153 154 155
        conform_xp = FALSE;
    }
    else
        ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");

156
    SetRect( &rect, 10,10, 100, 100);
157
    textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT);
158
    ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
159 160 161 162 163 164
    if (conform_xp)
        ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    SetRect( &rect, 10,10, 100, 100);
    heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
165 166
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
167 168 169 170 171
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT);
172 173
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
174 175 176 177 178 179 180 181
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    /* DT_SINGLELINE tests */

    SetRect( &rect, 10,10, 100, 100);
    heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
182 183
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
184 185 186 187 188
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
189 190
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
191 192 193 194 195 196 197
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    SetRect( &rect, 10,10, 100, 100);
    SetLastError( 0);
    heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
198 199
    ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
       wine_dbgstr_rect(&rect));
200 201 202 203
    ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
204 205
    ok(!EMPTY(rect) && MODIFIED (rect), "rectangle should be modified got %s\n",
       wine_dbgstr_rect(&rect));
206 207 208 209 210 211
    ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    SetRect( &rect, 10,10, 100, 100);
    SetLastError( 0);
    heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
212 213
    ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
       wine_dbgstr_rect(&rect));
214 215 216 217 218
    if (conform_xp)
        ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
219 220
    ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
       wine_dbgstr_rect(&rect));
221 222 223 224 225 226
    if (conform_xp)
        ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    SetRect( &rect, 10,10, 100, 100);
    heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
227 228
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
229 230 231 232 233
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");

    SetRect( &rect, 10,10, 100, 100);
    textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
234 235
    ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
        "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

    /* further tests with  0 count, NULL and empty strings */
    heightcheck = textheight = DrawTextA(hdc, text, 0, &rect, 0);
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, text, 0, &rect, 0, NULL );
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
    heightcheck = textheight = DrawTextA(hdc, emptystring, 0, &rect, 0);
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, NULL );
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
    heightcheck = textheight = DrawTextA(hdc, NULL, 0, &rect, 0);
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, NULL );
    if (conform_xp)
        ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
    heightcheck = textheight = DrawTextA(hdc, emptystring, -1, &rect, 0);
    ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, NULL );
    ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
    heightcheck = textheight = DrawTextA(hdc, NULL, -1, &rect, 0);
    if (conform_xp)
        ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, NULL );
    if (conform_xp)
        ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
    heightcheck = textheight = DrawTextA(hdc, NULL, 10, &rect, 0);
    ok(textheight==0,"Got textheight from DrawTextA\n");
    textheight = DrawTextExA(hdc, NULL, 10, &rect, 0, NULL );
    ok(textheight==0,"Got textheight from DrawTextA\n");
    ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");


    /* invalid dtp size test */
    dtp.cbSize = -1; /* Invalid */
    dtp.uiLengthDrawn = 1337;
    textheight = DrawTextExA(hdc, text, 0, &rect, 0, &dtp);
    ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
    dtp.uiLengthDrawn = 1337;
    textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, &dtp);
    ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
    dtp.uiLengthDrawn = 1337;
    textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, &dtp);
    ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
    dtp.uiLengthDrawn = 1337;
    textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, &dtp);
    ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
    dtp.uiLengthDrawn = 1337;
    textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, &dtp);
    ok(textheight==0,"Got textheight from DrawTextExA\n");
    ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
303

304 305 306 307
    /* Margin calculations */
    dtp.cbSize = sizeof(dtp);
    dtp.iLeftMargin = 0;
    dtp.iRightMargin = 0;
308
    SetRectEmpty(&rect);
309 310 311
    DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
    textlen = rect.right; /* Width without margin */
    dtp.iLeftMargin = 8;
312
    SetRectEmpty(&rect);
313 314 315 316
    DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
    ok(rect.right==dtp.iLeftMargin+textlen  ,"Incorrect left margin calculated  rc(%d,%d)\n", rect.left, rect.right);
    dtp.iLeftMargin = 0;
    dtp.iRightMargin = 8;
317
    SetRectEmpty(&rect);
318 319 320
    DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
    ok(rect.right==dtp.iRightMargin+textlen  ,"Incorrect right margin calculated rc(%d,%d)\n", rect.left, rect.right);

321 322 323
    /* Wide char versions */
    SetRect( &rect, 10,10, 100, 100);
    SetLastError( 0);
324
    heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT, NULL );
325
    if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
326 327
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
328 329
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");

330
        SetRect( &rect, 10,10, 100, 100);
331
        textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT);
332 333
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
334 335 336 337 338
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        SetRect( &rect, 10,10, 100, 100);
        heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT, NULL );
339
        ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
340 341 342 343
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");

        SetRect( &rect, 10,10, 100, 100);
        textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT);
344
        ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
345 346 347 348 349
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        SetRect( &rect, 10,10, 100, 100);
        heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
350 351
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
352 353 354
        if (textheight) /* windows 2000 */
        {
            if (conform_xp)
355
                win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
356 357 358 359 360 361 362
            conform_xp = FALSE;
        }
        else
            ok(textheight==0,"Got textheight from DrawTextExW\n");

        SetRect( &rect, 10,10, 100, 100);
        textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT);
363 364
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
365 366 367 368 369 370
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        if (conform_xp) {
            /* Crashes on NT4 */
371
            SetRect( &rect, 10,10, 100, 100);
372
            heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
373 374
            ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
                "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
375 376 377 378
            ok(textheight==0,"Got textheight from DrawTextExW\n");

            SetRect( &rect, 10,10, 100, 100);
            textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT);
379 380
            ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
                "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
381 382 383 384 385 386 387 388
            ok(textheight==0,"Got textheight from DrawTextW\n");
            ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        }


        /* DT_SINGLELINE tests */

        heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
389 390
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
391 392 393 394
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");

        SetRect( &rect, 10,10, 100, 100);
        textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
395 396
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
397 398 399 400 401
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        SetRect( &rect, 10,10, 100, 100);
        heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
402 403
        ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
           wine_dbgstr_rect(&rect));
404 405 406 407
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");

        SetRect( &rect, 10,10, 100, 100);
        textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
408 409
        ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
           wine_dbgstr_rect(&rect));
410 411 412 413
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        if (conform_xp) {
414
            /* Crashes on NT4 */
415 416
            SetRect( &rect, 10,10, 100, 100);
            heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
417 418
            ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
                "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
419 420 421 422
            ok(textheight==0,"Got textheight from DrawTextExW\n");

            SetRect( &rect, 10,10, 100, 100);
            textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
423 424
            ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
                "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
425 426
            ok(textheight==0,"Got textheight from DrawTextW\n");
            ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
427
        }
428 429 430

        SetRect( &rect, 10,10, 100, 100);
        heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
431 432
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
433 434 435
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextExW\n");

436
        SetRect( &rect, 10,10, 100, 100);
437
        textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
438 439
        ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
            "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");

        /* further tests with NULL and empty strings */
        heightcheck = textheight = DrawTextW(hdc, textW, 0, &rect, 0);
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        textheight = DrawTextExW(hdc, textW, 0, &rect, 0, NULL );
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        heightcheck = textheight = DrawTextW(hdc, emptystringW, 0, &rect, 0);
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, NULL );
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        heightcheck = textheight = DrawTextW(hdc, NULL, 0, &rect, 0);
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextW\n");
        textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, NULL );
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextExW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        heightcheck = textheight = DrawTextW(hdc, emptystringW, -1, &rect, 0);
        ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
        textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, NULL );
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
        ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        if (conform_xp) {
            /* Crashes on NT4 */
            heightcheck = textheight = DrawTextW(hdc, NULL, -1, &rect, 0);
            ok(textheight==0,"Got textheight from DrawTextW\n");
            textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, NULL );
            ok(textheight==0,"Got textheight from DrawTextExW\n");
            ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
            heightcheck = textheight = DrawTextW(hdc, NULL, 10, &rect, 0);
            ok(textheight==0,"Got textheight from DrawTextW\n");
            textheight = DrawTextExW(hdc, NULL, 10, &rect, 0, NULL );
            ok(textheight==0,"Got textheight from DrawTextW\n");
            ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
        }

        dtp.cbSize = -1; /* Invalid */
        dtp.uiLengthDrawn = 1337;
        textheight = DrawTextExW(hdc, textW, 0, &rect, 0, &dtp);
        ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
        ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
        dtp.uiLengthDrawn = 1337;
        textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, &dtp);
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextExW\n");
        ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
        dtp.uiLengthDrawn = 1337;
        textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, &dtp);
        if (conform_xp)
            ok(textheight==0,"Got textheight from DrawTextExW\n");
        ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
        dtp.uiLengthDrawn = 1337;
        textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, &dtp);
        ok(textheight==0,"Got textheight from DrawTextExW\n");
        ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
        if (conform_xp) {
            /* Crashes on NT4 */
            dtp.uiLengthDrawn = 1337;
            textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, &dtp);
            ok(textheight==0,"Got textheight from DrawTextExW\n");
            ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
        }
507
    }
508

509
    /* More test cases from bug 12226 */
510
    SetRectEmpty(&rect);
511
    textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
512
    ok(textheight, "DrawTextA error %u\n", GetLastError());
513 514 515
    ok(0 == rect.left, "expected 0, got %d\n", rect.left);
    ok(0 == rect.right, "expected 0, got %d\n", rect.right);
    ok(0 == rect.top, "expected 0, got %d\n", rect.top);
516
    ok(rect.bottom, "rect.bottom should not be 0\n");
517

518
    SetRectEmpty(&rect);
519
    textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
520 521 522 523 524 525
    if (!textheight && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip( "DrawTextW not implemented\n" );
    }
    else
    {
526
        ok(textheight, "DrawTextW error %u\n", GetLastError());
527 528 529
        ok(0 == rect.left, "expected 0, got %d\n", rect.left);
        ok(0 == rect.right, "expected 0, got %d\n", rect.right);
        ok(0 == rect.top, "expected 0, got %d\n", rect.top);
530
        ok(rect.bottom, "rect.bottom should not be 0\n");
531
    }
532

533 534 535 536 537 538
    SetRect(&rect, 0, 0, 1, 1);
    heightcheck = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT);
    SetRect(&rect, 0, 0, 1, 1);
    textheight = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT | DT_WORDBREAK);
    ok(textheight == heightcheck * 2, "Got unexpected textheight %d, expected %d.\n",
       textheight, heightcheck * 2);
539 540 541 542
    SetRect(&rect, 0, 0, 1, 1);
    textheight = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);
    ok(textheight >= heightcheck * 6, "Got unexpected textheight %d, expected at least %d.\n",
       textheight, heightcheck * 6);
543 544 545 546 547 548 549

    SetRect(&rect, 0, 0, 1, 1);
    heightcheck = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT);
    SetRect(&rect, 0, 0, 1, 1);
    textheight = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT | DT_WORDBREAK);
    ok(textheight == heightcheck * 2, "Got unexpected textheight %d, expected %d.\n",
       textheight, heightcheck * 2);
550 551 552 553
    SetRect(&rect, 0, 0, 1, 1);
    textheight = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);
    ok(textheight >= heightcheck * 6, "Got unexpected textheight %d, expected at least %d.\n",
       textheight, heightcheck * 6);
554

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
    /* DT_TABSTOP | DT_EXPANDTABS tests */
    SetRect( &rect, 0,0, 10, 10);
    textheight = DrawTextA(hdc, tabstring, -1, &rect, DT_TABSTOP | DT_EXPANDTABS );
    ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);

    SetRect( &rect, 0,0, 10, 10);
    memset(&dtp, 0, sizeof(dtp));
    dtp.cbSize = sizeof(dtp);
    textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT, &dtp);
    ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
    ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);

    SetRect( &rect2, 0,0, 10, 10);
    memset(&dtp, 0, sizeof(dtp));
    dtp.cbSize = sizeof(dtp);
    textheight = DrawTextExA(hdc, tabstring, -1, &rect2, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
    ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
    ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
    ok(rect.left == rect2.left && rect.right != rect2.right && rect.top == rect2.top && rect.bottom == rect2.bottom,
574
       "incorrect rect %s rect2 %s\n", wine_dbgstr_rect(&rect), wine_dbgstr_rect(&rect2));
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

    SetRect( &rect, 0,0, 10, 10);
    memset(&dtp, 0, sizeof(dtp));
    dtp.cbSize = sizeof(dtp);
    dtp.iTabLength = 8;
    textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
    ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
    ok(dtp.iTabLength == 8, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
    ok(rect.left == rect2.left, "unexpected value %d, got %d\n", rect.left, rect2.left);
    /* XP, 2003 appear to not give the same values. */
    ok(rect.right == rect2.right || broken(rect.right > rect2.right), "unexpected value %d, got %d\n",rect.right, rect2.right);
    ok(rect.top == rect2.top, "unexpected value %d, got %d\n", rect.top, rect2.top);
    ok(rect.bottom == rect2.bottom , "unexpected value %d, got %d\n", rect.bottom, rect2.bottom);


590
    SelectObject(hdc, hOldFont);
591
    ret = DeleteObject(hFont);
592
    ok( ret, "DeleteObject error %u\n", GetLastError());
593 594

    /* Clean up */
595
    ret = ReleaseDC(hwnd, hdc);
596
    ok( ret, "ReleaseDC error %u\n", GetLastError());
597
    ret = DestroyWindow(hwnd);
598
    ok( ret, "DestroyWindow error %u\n", GetLastError());
599 600
}

601
/* replace tabs by \t */
602
static void strfmt( const char *str, char *strout)
603 604 605 606 607 608 609 610
{
    unsigned int i,j ;
    for(i=0,j=0;i<=strlen(str);i++,j++)
        if((strout[j]=str[i])=='\t') {
            strout[j++]='\\';
            strout[j]='t';
        }
}
611

612 613

#define TABTEST( tabval, tabcount, string, _exp) \
614
{ int i; char strdisp[64];\
615 616 617 618
    for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
    extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
    strfmt( string, strdisp); \
 /*   trace( "Extent is %08lx\n", extent); */\
619 620
    ok( extent == _exp, "Test case \"%s\". Text extent is 0x%x, expected 0x%x tab %d tabcount %d\n", \
        strdisp, extent, _exp, tabval, tabcount); \
621 622 623
} \


624
static void test_TabbedText(void)
625 626 627 628 629 630 631 632 633 634 635
{
    HWND hwnd;
    HDC hdc;
    BOOL ret;
    TEXTMETRICA tm;
    DWORD extent;
    INT tabs[8], cx, cy, tab, tabcount,t,align;

    /* Initialization */
    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
                           0, 0, 200, 200, 0, 0, 0, NULL);
636
    ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
637
    hdc = GetDC(hwnd);
638
    ok(hdc != 0, "GetDC error %u\n", GetLastError());
639 640

    ret = GetTextMetricsA( hdc, &tm);
641
    ok( ret, "GetTextMetrics error %u\n", GetLastError());
642

643 644 645
    extent = GetTabbedTextExtentA( hdc, "x", 0, 1, tabs);
    ok( extent == 0, "GetTabbedTextExtentA returned non-zero on nCount == 0\n");

646 647 648 649 650 651 652 653 654 655 656
    extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
    cx = LOWORD( extent);
    cy = HIWORD( extent);
    trace( "cx is %d cy is %d\n", cx, cy);

    align=1;
    for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to 
                               catch the one off errors */
        tab =  (cx *4 + t);
        /* test the special case tabcount =1 and the general array (80 of tabs */
        for( tabcount = 1; tabcount <= 8; tabcount +=7) { 
657 658 659 660 661 662 663 664 665 666
            TABTEST( align * tab, tabcount, "\t", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "xxx\t", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "\tx", MAKELONG(tab+cx, cy))
            TABTEST( align * tab, tabcount, "\t\t", MAKELONG(tab*2, cy))
            TABTEST( align * tab, tabcount, "\tx\t", MAKELONG(tab*2, cy))
            TABTEST( align * tab, tabcount, "x\tx", MAKELONG(tab+cx, cy))
            TABTEST( align * tab, tabcount, "xx\tx", MAKELONG(tab+cx, cy))
            TABTEST( align * tab, tabcount, "xxx\tx", MAKELONG(tab+cx, cy))
            TABTEST( align * tab, tabcount, "xxxx\tx", MAKELONG(t>0 ? tab + cx : 2*tab+cx, cy))
            TABTEST( align * tab, tabcount, "xxxxx\tx", MAKELONG(2*tab+cx, cy))
667 668 669 670 671 672 673 674
        }
    }
    align=-1;
    for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to 
                               catch the one off errors */
        tab =  (cx *4 + t);
        /* test the special case tabcount =1 and the general array (8) of tabs */
        for( tabcount = 1; tabcount <= 8; tabcount +=7) { 
675 676 677 678 679 680 681 682 683 684
            TABTEST( align * tab, tabcount, "\t", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "xxx\t", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "\tx", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "\t\t", MAKELONG(tab*2, cy))
            TABTEST( align * tab, tabcount, "\tx\t", MAKELONG(tab*2, cy))
            TABTEST( align * tab, tabcount, "x\tx", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "xx\tx", MAKELONG(tab, cy))
            TABTEST( align * tab, tabcount, "xxx\tx", MAKELONG(4 * cx >= tab ? 2*tab :tab, cy))
            TABTEST( align * tab, tabcount, "xxxx\tx", MAKELONG(2*tab, cy))
            TABTEST( align * tab, tabcount, "xxxxx\tx", MAKELONG(2*tab, cy))
685 686 687
        }
    }

688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
    ReleaseDC( hwnd, hdc );
    DestroyWindow( hwnd );
}

static void test_DrawState(void)
{
    static const char text[] = "Sample text string";
    HWND hwnd;
    HDC hdc;
    BOOL ret;

    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
                           0, 0, 200, 200, 0, 0, 0, NULL);
    assert(hwnd);

    hdc = GetDC(hwnd);
    assert(hdc);

    SetLastError(0xdeadbeef);
707
    ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, strlen(text),
708 709 710 711
                    0, 0, 10, 10, DST_TEXT);
    ok(ret, "DrawState error %u\n", GetLastError());

    SetLastError(0xdeadbeef);
712
    ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, 0,
713 714 715 716
                    0, 0, 10, 10, DST_TEXT);
    ok(ret, "DrawState error %u\n", GetLastError());

    SetLastError(0xdeadbeef);
717
    ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, strlen(text),
718
                    0, 0, 10, 10, DST_TEXT);
719
    ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
720 721 722
    ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());

    SetLastError(0xdeadbeef);
723
    ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, 0,
724
                    0, 0, 10, 10, DST_TEXT);
725
    ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
726
    ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
727

728 729
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);
730 731
}

732 733
static void test_CharToOem_OemToChar(void)
{
734 735
    static const WCHAR helloWorldW[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
    static const WCHAR emptyW[] = {0};
736 737 738 739 740 741 742 743 744 745 746 747 748 749
    static const char helloWorld[] = "Hello World";
    static const struct
    {
        BOOL src, dst, ret;
    }
    tests[] =
    {
        { FALSE, FALSE, FALSE },
        { TRUE,  FALSE, FALSE },
        { FALSE, TRUE,  FALSE },
        { TRUE,  TRUE,  TRUE  },
    };
    BOOL ret;
    int i;
750 751
    char oem;
    WCHAR uni, expect;
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778

    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
    {
        const char *expected = tests[i].ret ? helloWorld : "";
        const char *src = tests[i].src ? helloWorld : NULL;
        char buf[64], *dst = tests[i].dst ? buf : NULL;

        memset(buf, 0, sizeof(buf));
        ret = CharToOemA(src, dst);
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);

        memset(buf, 0, sizeof(buf));
        ret = CharToOemBuffA(src, dst, sizeof(helloWorld));
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);

        memset(buf, 0, sizeof(buf));
        ret = OemToCharA(src, dst);
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);

        memset(buf, 0, sizeof(buf));
        ret = OemToCharBuffA(src, dst, sizeof(helloWorld));
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
    }
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812

    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
    {
        const char *expected = tests[i].ret ? helloWorld : "";
        const WCHAR *src = tests[i].src ? helloWorldW : NULL;
        char buf[64], *dst = tests[i].dst ? buf : NULL;

        memset(buf, 0, sizeof(buf));
        ret = CharToOemW(src, dst);
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);

        memset(buf, 0, sizeof(buf));
        ret = CharToOemBuffW(src, dst, sizeof(helloWorldW)/sizeof(WCHAR));
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
    }

    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
    {
        const WCHAR *expected = tests[i].ret ? helloWorldW : emptyW;
        const char *src = tests[i].src ? helloWorld : NULL;
        WCHAR buf[64], *dst = tests[i].dst ? buf : NULL;

        memset(buf, 0, sizeof(buf));
        ret = OemToCharW(src, dst);
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));

        memset(buf, 0, sizeof(buf));
        ret = OemToCharBuffW(src, dst, sizeof(helloWorld));
        ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
        ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
    }
813 814 815 816 817 818 819 820 821

    for (i = 0; i < 0x100; i++)
    {
        oem = i;
        ret = OemToCharBuffW( &oem, &uni, 1 );
        ok( ret, "%02x: returns FALSE\n", i );
        MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED | MB_USEGLYPHCHARS, &oem, 1, &expect, 1 );
        ok( uni == expect, "%02x: got %04x expected %04x\n", i, uni, expect );
    }
822 823
}

824 825
START_TEST(text)
{
826
    test_TabbedText();
827
    test_DrawTextCalcRect();
828
    test_DrawState();
829
    test_CharToOem_OemToChar();
830
}