127 lines
4.4 KiB
C
127 lines
4.4 KiB
C
/*
|
|
* Text layout/format tests
|
|
*
|
|
* Copyright 2012 Nikolay Sivov for CodeWeavers
|
|
*
|
|
* 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
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "windows.h"
|
|
#include "dwrite.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
static IDWriteFactory *factory;
|
|
|
|
static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
|
|
|
|
#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
|
|
static void _expect_ref(IUnknown* obj, ULONG ref, int line)
|
|
{
|
|
ULONG rc = IUnknown_AddRef(obj);
|
|
IUnknown_Release(obj);
|
|
ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
|
|
}
|
|
|
|
static void test_CreateTextLayout(void)
|
|
{
|
|
static const WCHAR strW[] = {'s','t','r','i','n','g',0};
|
|
IDWriteTextLayout *layout;
|
|
HRESULT hr;
|
|
|
|
hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 0.0, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1.0, 0.0, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 1.0, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
}
|
|
|
|
static void test_CreateGdiCompatibleTextLayout(void)
|
|
{
|
|
static const WCHAR strW[] = {'s','t','r','i','n','g',0};
|
|
static const WCHAR enusW[] = {'e','n','-','u','s',0};
|
|
IDWriteTextLayout *layout;
|
|
IDWriteTextFormat *format;
|
|
HRESULT hr;
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 0.0, NULL, FALSE, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 1.0, NULL, FALSE, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, 1.0, NULL, FALSE, &layout);
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
/* create with text format */
|
|
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
|
|
DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
EXPECT_REF(format, 1);
|
|
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
EXPECT_REF(format, 1);
|
|
EXPECT_REF(layout, 1);
|
|
|
|
IDWriteTextLayout_AddRef(layout);
|
|
EXPECT_REF(format, 1);
|
|
EXPECT_REF(layout, 2);
|
|
IDWriteTextLayout_Release(layout);
|
|
IDWriteTextLayout_Release(layout);
|
|
|
|
/* zero length string is okay */
|
|
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 0, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
IDWriteTextLayout_Release(layout);
|
|
|
|
IDWriteTextFormat_Release(format);
|
|
}
|
|
|
|
START_TEST(layout)
|
|
{
|
|
HRESULT hr;
|
|
|
|
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
if (hr != S_OK)
|
|
{
|
|
win_skip("failed to create factory\n");
|
|
return;
|
|
}
|
|
|
|
test_CreateTextLayout();
|
|
test_CreateGdiCompatibleTextLayout();
|
|
|
|
IDWriteFactory_Release(factory);
|
|
}
|