2 * Text layout/format tests
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 static IDWriteFactory *factory;
30 static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
31 static const WCHAR enusW[] = {'e','n','-','u','s',0};
33 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
34 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
36 ULONG rc = IUnknown_AddRef(obj);
37 IUnknown_Release(obj);
38 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
41 static void test_CreateTextLayout(void)
43 static const WCHAR strW[] = {'s','t','r','i','n','g',0};
44 IDWriteTextLayout *layout;
47 hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, &layout);
48 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
50 hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 0.0, &layout);
51 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
53 hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1.0, 0.0, &layout);
54 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
56 hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 1.0, &layout);
57 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
59 hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, &layout);
60 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
63 static void test_CreateGdiCompatibleTextLayout(void)
65 static const WCHAR strW[] = {'s','t','r','i','n','g',0};
66 IDWriteTextLayout *layout;
67 IDWriteTextFormat *format;
70 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
71 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
73 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
74 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
76 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 0.0, NULL, FALSE, &layout);
77 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
79 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 1.0, NULL, FALSE, &layout);
80 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
82 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, 1.0, NULL, FALSE, &layout);
83 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
85 /* create with text format */
86 hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
87 DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
88 ok(hr == S_OK, "got 0x%08x\n", hr);
89 EXPECT_REF(format, 1);
91 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
92 ok(hr == S_OK, "got 0x%08x\n", hr);
93 EXPECT_REF(format, 1);
94 EXPECT_REF(layout, 1);
96 IDWriteTextLayout_AddRef(layout);
97 EXPECT_REF(format, 1);
98 EXPECT_REF(layout, 2);
99 IDWriteTextLayout_Release(layout);
100 IDWriteTextLayout_Release(layout);
102 /* zero length string is okay */
103 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 0, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
104 ok(hr == S_OK, "got 0x%08x\n", hr);
105 IDWriteTextLayout_Release(layout);
107 IDWriteTextFormat_Release(format);
110 static void test_CreateTextFormat(void)
112 IDWriteFontCollection *collection, *syscoll;
113 IDWriteTextFormat *format;
116 hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
117 DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
118 ok(hr == S_OK, "got 0x%08x\n", hr);
120 if (0) /* crashes on native */
121 hr = IDWriteTextFormat_GetFontCollection(format, NULL);
124 hr = IDWriteTextFormat_GetFontCollection(format, &collection);
125 ok(hr == S_OK, "got 0x%08x\n", hr);
126 ok(collection != NULL, "got %p\n", collection);
128 hr = IDWriteFactory_GetSystemFontCollection(factory, &syscoll, FALSE);
129 ok(hr == S_OK, "got 0x%08x\n", hr);
130 ok(collection == syscoll, "got %p, was %p\n", syscoll, collection);
131 IDWriteFontCollection_Release(syscoll);
132 IDWriteFontCollection_Release(collection);
134 IDWriteTextFormat_Release(format);
137 static void test_GetLocaleName(void)
139 static const WCHAR strW[] = {'s','t','r','i','n','g',0};
140 static const WCHAR ruW[] = {'r','u',0};
141 IDWriteTextLayout *layout;
142 IDWriteTextFormat *format;
147 hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
148 DWRITE_FONT_STRETCH_NORMAL, 10.0, ruW, &format);
149 ok(hr == S_OK, "got 0x%08x\n", hr);
151 hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 0, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
152 ok(hr == S_OK, "got 0x%08x\n", hr);
153 len = IDWriteTextLayout_GetLocaleNameLength(layout);
154 ok(len == 2, "got %u\n", len);
155 len = IDWriteTextFormat_GetLocaleNameLength(format);
156 ok(len == 2, "got %u\n", len);
157 hr = IDWriteTextLayout_GetLocaleName(layout, buff, len);
158 ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr);
159 hr = IDWriteTextLayout_GetLocaleName(layout, buff, len+1);
160 ok(hr == S_OK, "got 0x%08x\n", hr);
161 ok(!lstrcmpW(buff, ruW), "got %s\n", wine_dbgstr_w(buff));
162 hr = IDWriteTextFormat_GetLocaleName(format, buff, len);
163 ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr);
164 hr = IDWriteTextFormat_GetLocaleName(format, buff, len+1);
165 ok(hr == S_OK, "got 0x%08x\n", hr);
166 ok(!lstrcmpW(buff, ruW), "got %s\n", wine_dbgstr_w(buff));
168 IDWriteTextLayout_Release(layout);
169 IDWriteTextFormat_Release(format);
176 hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_ISOLATED, &IID_IDWriteFactory, (IUnknown**)&factory);
177 ok(hr == S_OK, "got 0x%08x\n", hr);
180 win_skip("failed to create factory\n");
184 test_CreateTextLayout();
185 test_CreateGdiCompatibleTextLayout();
186 test_CreateTextFormat();
187 test_GetLocaleName();
189 IDWriteFactory_Release(factory);