From 9b0f49264e423ecb49fa4fc45959556b021a2e4c Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sun, 7 Oct 2012 18:43:15 -0400 Subject: [PATCH] dwrite: Implement GetString(). --- dlls/dwrite/main.c | 17 +++++++++++++++-- dlls/dwrite/tests/font.c | 37 ++++++++++++++++++++++++++++++++++--- include/winerror.h | 2 ++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c index 4ddc74bf45a..67ba83c4dbb 100644 --- a/dlls/dwrite/main.c +++ b/dlls/dwrite/main.c @@ -286,8 +286,21 @@ static HRESULT WINAPI localizedstrings_GetStringLength(IDWriteLocalizedStrings * static HRESULT WINAPI localizedstrings_GetString(IDWriteLocalizedStrings *iface, UINT32 index, WCHAR *buffer, UINT32 size) { struct localizedstrings *This = impl_from_IDWriteLocalizedStrings(iface); - FIXME("(%p)->(%u %p %u): stub\n", This, index, buffer, size); - return E_NOTIMPL; + + TRACE("(%p)->(%u %p %u)\n", This, index, buffer, size); + + if (index >= This->count) { + if (buffer) *buffer = 0; + return E_FAIL; + } + + if (size < strlenW(This->data[index].string)+1) { + if (buffer) *buffer = 0; + return E_NOT_SUFFICIENT_BUFFER; + } + + strcpyW(buffer, This->data[index].string); + return S_OK; } static const IDWriteLocalizedStringsVtbl localizedstringsvtbl = { diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index b22453cb475..81e17fdb49d 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -320,6 +320,7 @@ static void test_GetFamilyNames(void) IDWriteGdiInterop *interop; IDWriteFont *font; LOGFONTW logfont; + WCHAR buffer[100]; HRESULT hr; UINT32 len; @@ -357,15 +358,45 @@ if (0) /* crashes on native */ if (0) /* crashes on native */ hr = IDWriteLocalizedStrings_GetStringLength(names, 0, NULL); + len = 100; + hr = IDWriteLocalizedStrings_GetStringLength(names, 10, &len); + ok(hr == E_FAIL, "got 0x%08x\n", hr); + ok(len == (UINT32)-1, "got %u\n", len); + len = 0; hr = IDWriteLocalizedStrings_GetStringLength(names, 0, &len); ok(hr == S_OK, "got 0x%08x\n", hr); ok(len > 0, "got %u\n", len); - len = 100; - hr = IDWriteLocalizedStrings_GetStringLength(names, 10, &len); + /* GetString */ + hr = IDWriteLocalizedStrings_GetString(names, 0, NULL, 0); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr); + + hr = IDWriteLocalizedStrings_GetString(names, 10, NULL, 0); ok(hr == E_FAIL, "got 0x%08x\n", hr); - ok(len == (UINT32)-1, "got %u\n", len); + +if (0) + hr = IDWriteLocalizedStrings_GetString(names, 0, NULL, 100); + + buffer[0] = 1; + hr = IDWriteLocalizedStrings_GetString(names, 10, buffer, 100); + ok(hr == E_FAIL, "got 0x%08x\n", hr); + ok(buffer[0] == 0, "got %x\n", buffer[0]); + + buffer[0] = 1; + hr = IDWriteLocalizedStrings_GetString(names, 0, buffer, len-1); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr); + ok(buffer[0] == 0, "got %x\n", buffer[0]); + + buffer[0] = 1; + hr = IDWriteLocalizedStrings_GetString(names, 0, buffer, len); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got 0x%08x\n", hr); + ok(buffer[0] == 0, "got %x\n", buffer[0]); + + buffer[0] = 0; + hr = IDWriteLocalizedStrings_GetString(names, 0, buffer, len+1); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(buffer[0] != 0, "got %x\n", buffer[0]); IDWriteLocalizedStrings_Release(names); diff --git a/include/winerror.h b/include/winerror.h index 0b9a59ea31a..b6281f82345 100644 --- a/include/winerror.h +++ b/include/winerror.h @@ -1939,6 +1939,8 @@ static inline HRESULT HRESULT_FROM_WIN32(unsigned int x) /* the codes 4000-40ff are reserved for OLE */ #undef NOERROR /* arpa/nameser_compat.h defines this */ +#define E_NOT_SUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) + #ifdef RC_INVOKED #define _HRESULT_TYPEDEF_(x) (x) #else