[PATCH v2 3/8] d3dx9/tests: Add some more ID3DXFont tests.

Matteo Bruni matteo.mystral at gmail.com
Wed Jan 22 10:07:13 CST 2020


On Mon, Jan 6, 2020 at 3:35 PM Sven Baars <sbaars at codeweavers.com> wrote:
>
> Signed-off-by: Sven Baars <sbaars at codeweavers.com>
> ---
> v2: Fix some test failures and remove tests that fail on my machine,
> but not on the testbot.
>
>  dlls/d3dx9_36/tests/core.c | 119 ++++++++++++++++++++++++++++++-------
>  1 file changed, 99 insertions(+), 20 deletions(-)
>
> diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c
> index 8c1d41e952..b2a44ded70 100644
> --- a/dlls/d3dx9_36/tests/core.c
> +++ b/dlls/d3dx9_36/tests/core.c
> @@ -306,6 +306,14 @@ static void test_ID3DXSprite(IDirect3DDevice9 *device)
>  static void test_ID3DXFont(IDirect3DDevice9 *device)
>  {
>      static const WCHAR testW[] = {'t','e','s','t',0};
> +    static const WCHAR emptyW[] = {0};
> +    static const char longText[] = "Example text to test clipping and other related things";
> +    static const WCHAR longTextW[] = {'E', 'x', 'a', 'm', 'p', 'l', 'e', ' ',
> +                                      't', 'e', 'x', 't', ' ', 't', 'o', ' ',
> +                                      't', 'e', 's', 't', ' ', 'c', 'l', 'i', 'p', 'p', 'i', 'n', 'g', ' ',
> +                                      'a', 'n', 'd', ' ', 'o', 't', 'h', 'e', 'r', ' ',
> +                                      'r', 'e', 'l', 'a', 't', 'e', 'd', ' ', 't', 'h', 'i', 'n', 'g', 's', 0};

You can now use the L"xxx" syntax for WCHAR strings. emptyW in
particular could just be dropped and be replaced by a L"" inline.

> +
>      static const struct
>      {
>          int font_height;
> @@ -314,11 +322,14 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>      }
>      tests[] =
>      {
> -        {  6, 128, 4 },
> -        {  8, 128, 4 },
> -        { 10, 256, 5 },
> -        { 12, 256, 5 },
> -        { 72, 256, 8 },
> +        {   2,  32,  2 },
> +        {   6, 128,  4 },
> +        {  10, 256,  5 },
> +        {  12, 256,  5 },
> +        {  72, 256,  8 },
> +        { 250, 256,  9 },
> +        { 258, 512, 10 },
> +        { 512, 512, 10 },
>      };
>      const unsigned int size = ARRAY_SIZE(testW);
>      D3DXFONT_DESCA desc;
> @@ -477,6 +488,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
>          hr = ID3DXFont_PreloadTextA(font, "test", -1);
>          ok(hr == D3D_OK, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3D_OK);
> +        hr = ID3DXFont_PreloadTextA(font, "", 0);
> +        ok(hr == D3D_OK, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3D_OK);
> +        hr = ID3DXFont_PreloadTextA(font, "", -1);
> +        ok(hr == D3D_OK, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3D_OK);
>
>          hr = ID3DXFont_PreloadTextW(font, NULL, -1);
>          ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
> @@ -486,6 +501,10 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
>          hr = ID3DXFont_PreloadTextW(font, testW, -1);
>          ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK);
> +        hr = ID3DXFont_PreloadTextW(font, emptyW, 0);
> +        ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK);
> +        hr = ID3DXFont_PreloadTextW(font, emptyW, -1);
> +        ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK);
>          }
>
>          check_release((IUnknown*)font, 0);
> @@ -498,6 +517,7 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          char c;
>          HDC hdc;
>          DWORD ret;
> +        WORD glyph;
>          HRESULT hr;
>          RECT blackbox;
>          POINT cellinc;
> @@ -524,26 +544,42 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK);
>
>          for(c = 'b'; c <= 'z'; c++) {
> -            WORD glyph;
> -
>              ret = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0);
>              ok(ret != GDI_ERROR, "GetGlyphIndicesA failed\n");
>
>              hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc);
>              todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
>              if(SUCCEEDED(hr)) {
> -                DWORD levels;
> +                DWORD ret, levels;
> +                TEXTMETRICW tm;
>                  D3DSURFACE_DESC desc;
> +                GLYPHMETRICS metrics;
> +                MAT2 mat = { {0,1}, {0,0}, {0,0}, {0,1} };
>
>                  levels = IDirect3DTexture9_GetLevelCount(texture);
> -                ok(levels == 5, "Got levels %u, expected %u\n", levels, 5);
> +                todo_wine ok(levels == 5, "Character %c, got levels %u, expected %u\n", c, levels, 5);

Why does this require a todo_wine now? My guess is that it actually
doesn't, since GetGlyphData() is currently a stub; it would be nicer
to add todo_wine in the same patch that implements GetGlyphData().

>                  hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
>                  ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc failed\n");
> -                ok(desc.Format == D3DFMT_A8R8G8B8, "Got format %#x, expected %#x\n", desc.Format, D3DFMT_A8R8G8B8);
> -                ok(desc.Usage == 0, "Got usage %#x, expected %#x\n", desc.Usage, 0);
> -                ok(desc.Width == 256, "Got width %u, expected %u\n", desc.Width, 256);
> -                ok(desc.Height == 256, "Got height %u, expected %u\n", desc.Height, 256);
> -                ok(desc.Pool == D3DPOOL_MANAGED, "Got pool %u, expected %u\n", desc.Pool, D3DPOOL_MANAGED);
> +                ok(desc.Format == D3DFMT_A8R8G8B8, "Character %c, got format %#x, expected %#x\n", c, desc.Format, D3DFMT_A8R8G8B8);
> +                ok(desc.Usage == 0, "Character %c, got usage %#x, expected %#x\n", c, desc.Usage, 0);
> +                ok(desc.Width == 256, "Character %c, got width %u, expected %u\n", c, desc.Width, 256);
> +                ok(desc.Height == 256, "Character %c, got height %u, expected %u\n", c, desc.Height, 256);
> +                ok(desc.Pool == D3DPOOL_MANAGED, "Character %c, got pool %u, expected %u\n", c, desc.Pool, D3DPOOL_MANAGED);
> +
> +                /* Check blackbox and cellinc, but skip v, w and y, because these
> +                   are apparently smaller */
> +                ret = GetGlyphOutlineW(hdc, glyph, GGO_GLYPH_INDEX | GGO_GRAY8_BITMAP | GGO_METRICS, &metrics, 0, NULL, &mat);
> +                if (ret != GDI_ERROR && c != 'v' && c != 'w' && c != 'y') {

Smaller how exactly? Anyway, I don't like this kind of special casing;
I'd rather allow some tolerance in the checks below.

> +                    ID3DXFont_GetTextMetricsW(font, &tm);
> +                    todo_wine ok(blackbox.right - blackbox.left == metrics.gmBlackBoxX + 2, "Character %c, got %d, expected %d\n",
> +                                 c, blackbox.right - blackbox.left, metrics.gmBlackBoxX + 2);
> +                    todo_wine ok(blackbox.bottom - blackbox.top == metrics.gmBlackBoxY + 2, "Character %c, got %d, expected %d\n",
> +                                 c, blackbox.bottom - blackbox.top, metrics.gmBlackBoxY + 2);
> +                    ok(cellinc.x == metrics.gmptGlyphOrigin.x - 1, "Character %c, got %d, expected %d\n",
> +                       c, cellinc.x, metrics.gmptGlyphOrigin.x - 1);
> +                    ok(cellinc.y == tm.tmAscent - metrics.gmptGlyphOrigin.y - 1, "Character %c, got %d, expected %d\n",
> +                       c, cellinc.y, tm.tmAscent - metrics.gmptGlyphOrigin.y - 1);
> +                } else if (ret == GDI_ERROR) skip("Failed to obtain glyph metrics\n");
>
>                  check_release((IUnknown*)texture, 1);
>              }
> @@ -552,6 +588,19 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          hr = ID3DXFont_PreloadCharacters(font, 'a', 'z');
>          ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK);
>
> +        /* Test multiple textures */
> +        hr = ID3DXFont_PreloadGlyphs(font, 0, 1000);
> +        todo_wine ok(hr == D3D_OK, "ID3DXFont_PreloadGlyphs returned %#x, expected %#x\n", hr, D3D_OK);
> +
> +        /* Test glyphs that are not rendered */
> +        for (glyph = 1; glyph < 4; glyph++)
> +        {
> +            texture = (IDirect3DTexture9*)0xdeadbeef;
> +            hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc);
> +            todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
> +            todo_wine ok(!texture, "Got unexpected texture\n");
> +        }

Nice test.

> +
>          check_release((IUnknown*)font, 0);
>      } else skip("Failed to create a ID3DXFont object\n");
>
> @@ -611,20 +660,20 @@ static void test_ID3DXFont(IDirect3DDevice9 *device)
>          todo_wine
>          {
>          height = ID3DXFont_DrawTextW(font, sprite, testW, -1, &rect, DT_TOP, 0xffffffff);
> -        ok(height == tests[i].font_height, "Got unexpected height %u.\n", height);
> +        ok(height == tests[i].font_height, "Got height %u, expected %u.\n", height, tests[i].font_height);
>          height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_TOP, 0xffffffff);
> -        ok(height == tests[i].font_height, "Got unexpected height %u.\n", height);
> +        ok(height == tests[i].font_height, "Got height %u, expected %u.\n", height, tests[i].font_height);
>          height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_RIGHT, 0xffffffff);
> -        ok(height == tests[i].font_height, "Got unexpected height %u.\n", height);
> +        ok(height == tests[i].font_height, "Got height %u, expected %u.\n", height, tests[i].font_height);
>          height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_LEFT | DT_NOCLIP,
>                  0xffffffff);
> -        ok(height == tests[i].font_height, "Got unexpected height %u.\n", height);
> +        ok(height == tests[i].font_height, "Got height %u, expected %u.\n", height, tests[i].font_height);

Usually in these cases we prefer printing the test index instead of
the expected value, the point being that once you have to look at the
code anyway to figure out which test fails it's trivial to recover the
expected value.



More information about the wine-devel mailing list