From: Sven Baars Subject: [PATCH v2 3/8] d3dx9/tests: Add some more ID3DXFont tests. Message-Id: <20200106143408.12864-3-sbaars@codeweavers.com> Date: Mon, 6 Jan 2020 15:34:03 +0100 In-Reply-To: <20200106143408.12864-1-sbaars@codeweavers.com> References: <20200106143408.12864-1-sbaars@codeweavers.com> Signed-off-by: Sven Baars --- 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}; + 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); 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') { + 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"); + } + 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); } SetRectEmpty(&rect); height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_LEFT | DT_CALCRECT, 0xffffffff); - todo_wine ok(height == tests[i].font_height, "Got unexpected height %u.\n", height); + todo_wine ok(height == tests[i].font_height, "Got height %u, expected %u.\n", height, tests[i].font_height); ok(!rect.left, "Got unexpected rect left %d.\n", rect.left); ok(!rect.top, "Got unexpected rect top %d.\n", rect.top); todo_wine ok(rect.right, "Got unexpected rect right %d.\n", rect.right); @@ -662,6 +711,12 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) height = ID3DXFont_DrawTextA(font, NULL, "test", 2, &rect, 0, 0xFF00FF); ok(height == 12, "DrawTextA returned %d, expected 12.\n", height); + height = ID3DXFont_DrawTextA(font, NULL, "", 0, &rect, 0, 0xFF00FF); + ok(height == 0, "DrawTextA returned %d, expected 0.\n", height); + + height = ID3DXFont_DrawTextA(font, NULL, "", -1, &rect, 0, 0xFF00FF); + ok(height == 0, "DrawTextA returned %d, expected 0.\n", height); + height = ID3DXFont_DrawTextA(font, NULL, "test", -1, NULL, 0, 0xFF00FF); ok(height == 12, "DrawTextA returned %d, expected 12.\n", height); @@ -671,7 +726,17 @@ static void test_ID3DXFont(IDirect3DDevice9 *device) height = ID3DXFont_DrawTextA(font, NULL, NULL, -1, NULL, 0, 0xFF00FF); ok(height == 0, "DrawTextA returned %d, expected 0.\n", height); -if (0) { /* Causes a lockup on windows 7. */ + SetRect(&rect, 10, 10, 50, 50); + + height = ID3DXFont_DrawTextA(font, NULL, longText, -1, &rect, DT_WORDBREAK, 0xFF00FF); + ok(height == 60, "DrawTextA returned %d, expected 60.\n", height); + + height = ID3DXFont_DrawTextA(font, NULL, longText, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xFF00FF); + ok(height == 96, "DrawTextA returned %d, expected 96.\n", height); + + SetRect(&rect, 10, 10, 200, 200); + +if (0) { /* Causes a lockup on Windows 7+ */ height = ID3DXFont_DrawTextW(font, NULL, testW, -2, &rect, 0, 0xFF00FF); ok(height == 12, "DrawTextW returned %d, expected 12.\n", height); } @@ -688,6 +753,12 @@ if (0) { /* Causes a lockup on windows 7. */ height = ID3DXFont_DrawTextW(font, NULL, testW, 2, &rect, 0, 0xFF00FF); ok(height == 12, "DrawTextW returned %d, expected 12.\n", height); + height = ID3DXFont_DrawTextW(font, NULL, emptyW, 0, &rect, 0, 0xFF00FF); + ok(height == 0, "DrawTextW returned %d, expected 0.\n", height); + + height = ID3DXFont_DrawTextW(font, NULL, emptyW, -1, &rect, 0, 0xFF00FF); + ok(height == 0, "DrawTextW returned %d, expected 0.\n", height); + height = ID3DXFont_DrawTextW(font, NULL, testW, -1, NULL, 0, 0xFF00FF); ok(height == 12, "DrawTextW returned %d, expected 12.\n", height); @@ -696,6 +767,14 @@ if (0) { /* Causes a lockup on windows 7. */ height = ID3DXFont_DrawTextW(font, NULL, NULL, -1, NULL, 0, 0xFF00FF); ok(height == 0, "DrawTextW returned %d, expected 0.\n", height); + + SetRect(&rect, 10, 10, 50, 50); + + height = ID3DXFont_DrawTextW(font, NULL, longTextW, -1, &rect, DT_WORDBREAK, 0xFF00FF); + ok(height == 60, "DrawTextW returned %d, expected 60.\n", height); + + height = ID3DXFont_DrawTextW(font, NULL, longTextW, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xFF00FF); + ok(height == 96, "DrawTextW returned %d, expected 96.\n", height); } ID3DXFont_Release(font); -- 2.24.0