dwrite/tests: Create separate isolated factory for each test.

This commit is contained in:
Nikolay Sivov 2014-10-22 15:42:30 +04:00 committed by Alexandre Julliard
parent aad1997dff
commit 272964666a
1 changed files with 81 additions and 10 deletions

View File

@ -47,11 +47,17 @@ static inline BOOL heap_free(void *mem)
return HeapFree(GetProcessHeap(), 0, mem);
}
static IDWriteFactory *factory;
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
static const WCHAR blahW[] = {'B','l','a','h','!',0};
static IDWriteFactory *create_factory(void)
{
IDWriteFactory *factory;
HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
ok(hr == S_OK, "got 0x%08x\n", hr);
return factory;
}
/* Here is a functional custom font set of interfaces */
struct test_fontdatastream
{
@ -225,6 +231,7 @@ static void test_CreateFontFromLOGFONT(void)
{960, DWRITE_FONT_WEIGHT_BOLD},
};
OUTLINETEXTMETRICW otm;
IDWriteFactory *factory;
HRESULT hr;
BOOL ret;
HDC hdc;
@ -233,6 +240,8 @@ static void test_CreateFontFromLOGFONT(void)
int i;
UINT r;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -357,12 +366,14 @@ todo_wine {
ok(font == NULL, "got %p\n", font);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_CreateBitmapRenderTarget(void)
{
IDWriteBitmapRenderTarget *target, *target2;
IDWriteGdiInterop *interop;
IDWriteFactory *factory;
HBITMAP hbm, hbm2;
DWRITE_MATRIX m;
DIBSECTION ds;
@ -371,6 +382,8 @@ static void test_CreateBitmapRenderTarget(void)
HDC hdc;
int ret;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -499,6 +512,7 @@ if (0) /* crashes on native */
IDWriteBitmapRenderTarget_Release(target);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_GetFontFamily(void)
@ -508,9 +522,12 @@ static void test_GetFontFamily(void)
IDWriteFontFamily *family, *family2;
IDWriteGdiInterop *interop;
IDWriteFont *font, *font2;
IDWriteFactory *factory;
LOGFONTW logfont;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -578,6 +595,7 @@ if (collection)
IDWriteFont_Release(font);
IDWriteFont_Release(font2);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_GetFamilyNames(void)
@ -585,12 +603,15 @@ static void test_GetFamilyNames(void)
IDWriteFontFamily *family;
IDWriteLocalizedStrings *names, *names2;
IDWriteGdiInterop *interop;
IDWriteFactory *factory;
IDWriteFont *font;
LOGFONTW logfont;
WCHAR buffer[100];
HRESULT hr;
UINT32 len;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -670,6 +691,7 @@ if (0)
IDWriteFontFamily_Release(family);
IDWriteFont_Release(font);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_CreateFontFace(void)
@ -679,9 +701,12 @@ static void test_CreateFontFace(void)
IDWriteGdiInterop *interop;
IDWriteFont *font, *font2;
IDWriteFontFamily *family;
IDWriteFactory *factory;
LOGFONTW logfont;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -767,12 +792,14 @@ todo_wine
IDWriteFont_Release(font);
IDWriteFontFamily_Release(family);
IDWriteFontCollection_Release(collection);
IDWriteFactory_Release(factory);
}
static void test_GetMetrics(void)
{
IDWriteGdiInterop *interop;
DWRITE_FONT_METRICS metrics;
IDWriteFactory *factory;
OUTLINETEXTMETRICW otm;
IDWriteFont *font;
LOGFONTW logfont;
@ -781,6 +808,8 @@ static void test_GetMetrics(void)
HFONT hfont;
int ret;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
EXPECT_HR(hr, S_OK);
@ -824,17 +853,20 @@ todo_wine
IDWriteFont_Release(font);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_system_fontcollection(void)
{
IDWriteFontCollection *collection, *coll2;
IDWriteFactory *factory, *factory2;
IDWriteFontFamily *family;
IDWriteFactory *factory2;
HRESULT hr;
UINT32 i;
BOOL ret;
factory = create_factory();
hr = IDWriteFactory_GetSystemFontCollection(factory, &collection, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -880,16 +912,20 @@ static void test_system_fontcollection(void)
ok(i == (UINT32)-1, "got %u\n", i);
IDWriteFontCollection_Release(collection);
IDWriteFactory_Release(factory);
}
static void test_ConvertFontFaceToLOGFONT(void)
{
IDWriteGdiInterop *interop;
IDWriteFontFace *fontface;
IDWriteFactory *factory;
IDWriteFont *font;
LOGFONTW logfont;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -933,6 +969,7 @@ if (0) /* crashes on native */
IDWriteGdiInterop_Release(interop);
IDWriteFontFace_Release(fontface);
IDWriteFactory_Release(factory);
}
static HRESULT WINAPI fontcollectionloader_QueryInterface(IDWriteFontCollectionLoader *iface, REFIID riid, void **obj)
@ -967,8 +1004,11 @@ static void test_CustomFontCollection(void)
{
IDWriteFontCollectionLoader collection = { &dwritefontcollectionloadervtbl };
IDWriteFontCollectionLoader collection2 = { &dwritefontcollectionloadervtbl };
IDWriteFactory *factory;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_RegisterFontCollectionLoader(factory, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
@ -988,6 +1028,8 @@ static void test_CustomFontCollection(void)
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontCollectionLoader(factory, &collection2);
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteFactory_Release(factory);
}
static HRESULT WINAPI fontfileloader_QueryInterface(IDWriteFontFileLoader *iface, REFIID riid, void **obj)
@ -1036,11 +1078,14 @@ static void test_CreateCustomFontFileReference(void)
DWRITE_FONT_FACE_TYPE face_type;
UINT32 count;
IDWriteFontFace *face, *face2;
IDWriteFactory *factory;
HRESULT hr;
HRSRC fontrsrc;
UINT32 codePoints[1] = {0xa8};
UINT16 indices[1];
factory = create_factory();
hr = IDWriteFactory_RegisterFontFileLoader(factory, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IDWriteFactory_RegisterFontFileLoader(factory, &floader);
@ -1140,6 +1185,8 @@ todo_wine
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDWriteFactory_UnregisterFontFileLoader(factory, &rloader);
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteFactory_Release(factory);
}
static void test_CreateFontFileReference(void)
@ -1156,10 +1203,10 @@ static void test_CreateFontFileReference(void)
DWRITE_FONT_FACE_TYPE face = 1;
UINT32 count = 1;
IDWriteFontFace *fface = NULL;
IDWriteFactory *factory;
file = CreateFileW(font_name, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
if (file == INVALID_HANDLE_VALUE) return;
res = FindResourceA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(1), (LPCSTR)RT_RCDATA);
ok( res != 0, "couldn't find resource\n" );
@ -1168,6 +1215,8 @@ static void test_CreateFontFileReference(void)
ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
CloseHandle( file );
factory = create_factory();
hr = IDWriteFactory_CreateFontFileReference(factory, font_name, NULL, &ffile);
ok(hr == S_OK, "got 0x%08x\n",hr);
@ -1183,6 +1232,7 @@ static void test_CreateFontFileReference(void)
IDWriteFontFace_Release(fface);
IDWriteFontFile_Release(ffile);
IDWriteFactory_Release(factory);
DeleteFileW(font_name);
}
@ -1238,10 +1288,13 @@ static void test_GetUnicodeRanges(void)
IDWriteFontFile *ffile = NULL;
IDWriteFontFace1 *fontface1;
IDWriteFontFace *fontface;
IDWriteFactory *factory;
UINT32 count;
HRESULT hr;
HRSRC font;
factory = create_factory();
hr = IDWriteFactory_RegisterFontFileLoader(factory, &rloader);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1259,6 +1312,7 @@ static void test_GetUnicodeRanges(void)
IDWriteFontFace_Release(fontface);
if (hr != S_OK) {
win_skip("GetUnicodeRanges() is not supported.\n");
IDWriteFactory_Release(factory);
return;
}
@ -1292,6 +1346,7 @@ static void test_GetUnicodeRanges(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteFontFace1_Release(fontface1);
IDWriteFactory_Release(factory);
}
static void test_GetFontFromFontFace(void)
@ -1300,8 +1355,11 @@ static void test_GetFontFromFontFace(void)
IDWriteFontCollection *collection;
IDWriteFont *font, *font2, *font3;
IDWriteFontFamily *family;
IDWriteFactory *factory;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetSystemFontCollection(factory, &collection, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1351,6 +1409,7 @@ if (font3)
IDWriteFontFace_Release(fontface);
IDWriteFontFamily_Release(family);
IDWriteFontCollection_Release(collection);
IDWriteFactory_Release(factory);
}
static void test_GetFirstMatchingFont(void)
@ -1358,8 +1417,11 @@ static void test_GetFirstMatchingFont(void)
IDWriteFontCollection *collection;
IDWriteFont *font, *font2;
IDWriteFontFamily *family;
IDWriteFactory *factory;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetSystemFontCollection(factory, &collection, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1379,6 +1441,7 @@ static void test_GetFirstMatchingFont(void)
IDWriteFont_Release(font2);
IDWriteFontFamily_Release(family);
IDWriteFontCollection_Release(collection);
IDWriteFactory_Release(factory);
}
static void test_GetInformationalStrings(void)
@ -1386,10 +1449,13 @@ static void test_GetInformationalStrings(void)
IDWriteLocalizedStrings *strings, *strings2;
IDWriteFontCollection *collection;
IDWriteFontFamily *family;
IDWriteFactory *factory;
IDWriteFont *font;
BOOL exists;
HRESULT hr;
factory = create_factory();
hr = IDWriteFactory_GetSystemFontCollection(factory, &collection, FALSE);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1435,16 +1501,19 @@ if (strings2)
IDWriteFont_Release(font);
IDWriteFontFamily_Release(family);
IDWriteFontCollection_Release(collection);
IDWriteFactory_Release(factory);
}
static void test_GetGdiInterop(void)
{
IDWriteGdiInterop *interop, *interop2;
IDWriteFactory *factory2;
IDWriteFactory *factory, *factory2;
IDWriteFont *font;
LOGFONTW logfont;
HRESULT hr;
factory = create_factory();
interop = NULL;
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1479,17 +1548,21 @@ static void test_GetGdiInterop(void)
IDWriteGdiInterop_Release(interop2);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
static void test_CreateFontFaceFromHdc(void)
{
IDWriteGdiInterop *interop;
IDWriteFontFace *fontface;
IDWriteFactory *factory;
HFONT hfont, oldhfont;
LOGFONTW logfont;
HRESULT hr;
HDC hdc;
factory = create_factory();
interop = NULL;
hr = IDWriteFactory_GetGdiInterop(factory, &interop);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1516,16 +1589,14 @@ static void test_CreateFontFaceFromHdc(void)
DeleteDC(hdc);
IDWriteGdiInterop_Release(interop);
IDWriteFactory_Release(factory);
}
START_TEST(font)
{
HRESULT hr;
IDWriteFactory *factory;
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
ok(hr == S_OK, "got 0x%08x\n", hr);
if (hr != S_OK)
{
if (!(factory = create_factory())) {
win_skip("failed to create factory\n");
return;
}