[PATCH 4/4] api-ms-win-core-winrt-string-l1-1-0: Add tests.

Martin Storsjo martin at martin.st
Sun Dec 7 07:26:43 CST 2014


---
 configure.ac                                       |   1 +
 .../tests/Makefile.in                              |   4 +
 .../tests/win_string.c                             | 159 +++++++++++++++++++++
 3 files changed, 164 insertions(+)
 create mode 100644 dlls/api-ms-win-core-winrt-string-l1-1-0/tests/Makefile.in
 create mode 100644 dlls/api-ms-win-core-winrt-string-l1-1-0/tests/win_string.c

diff --git a/configure.ac b/configure.ac
index 9953bdf..a0f8cee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2714,6 +2714,7 @@ WINE_CONFIG_DLL(api-ms-win-core-winrt-error-l1-1-0)
 WINE_CONFIG_DLL(api-ms-win-core-winrt-error-l1-1-1)
 WINE_CONFIG_DLL(api-ms-win-core-winrt-l1-1-0)
 WINE_CONFIG_DLL(api-ms-win-core-winrt-string-l1-1-0)
+WINE_CONFIG_TEST(dlls/api-ms-win-core-winrt-string-l1-1-0/tests)
 WINE_CONFIG_DLL(api-ms-win-core-xstate-l2-1-0)
 WINE_CONFIG_DLL(api-ms-win-downlevel-advapi32-l1-1-0)
 WINE_CONFIG_DLL(api-ms-win-downlevel-advapi32-l2-1-0)
diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/Makefile.in b/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/Makefile.in
new file mode 100644
index 0000000..271f818
--- /dev/null
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/Makefile.in
@@ -0,0 +1,4 @@
+TESTDLL   = api-ms-win-core-winrt-string-l1-1-0.dll
+
+C_SRCS = \
+	win_string.c
diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/win_string.c b/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/win_string.c
new file mode 100644
index 0000000..7e983a1
--- /dev/null
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/tests/win_string.c
@@ -0,0 +1,159 @@
+/*
+ * Unit tests for Windows String functions
+ *
+ * Copyright (c) 2014 Martin Storsjo
+ *
+ * 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
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winstring.h"
+
+#include "wine/test.h"
+
+#define SETNOFAIL(x) p##x = (void*)GetProcAddress(hmod, #x)
+#define SET(x) SETNOFAIL(x); ok(p##x != NULL, "Export '%s' not found\n", #x)
+
+static HRESULT (WINAPI *pWindowsCreateString)(LPCWSTR, UINT32, HSTRING *);
+static HRESULT (WINAPI *pWindowsDuplicateString)(HSTRING, HSTRING *);
+static HRESULT (WINAPI *pWindowsCreateStringReference)(LPCWSTR, UINT32, HSTRING_HEADER *, HSTRING *);
+static HRESULT (WINAPI *pWindowsDeleteString)(HSTRING);
+static HRESULT (WINAPI *pWindowsPreallocateStringBuffer)(UINT32, WCHAR **, HSTRING_BUFFER *);
+static HRESULT (WINAPI *pWindowsDeleteStringBuffer)(HSTRING_BUFFER);
+static HRESULT (WINAPI *pWindowsPromoteStringBuffer)(HSTRING_BUFFER, HSTRING *);
+static UINT32  (WINAPI *pWindowsGetStringLen)(HSTRING);
+static LPCWSTR (WINAPI *pWindowsGetStringRawBuffer)(HSTRING, UINT32 *);
+static HRESULT (WINAPI *pWindowsStringHasEmbeddedNull)(HSTRING, BOOL *);
+static BOOL    (WINAPI *pWindowsIsStringEmpty)(HSTRING);
+
+static void check_string(HSTRING str, UINT32 length, BOOL has_null)
+{
+    BOOL out_null;
+    BOOL empty = length == 0;
+    UINT32 out_length;
+    LPCWSTR ptr;
+
+    ok(pWindowsIsStringEmpty(str) == empty, "WindowsIsStringEmpty failed\n");
+    ok(pWindowsStringHasEmbeddedNull(str, &out_null) == S_OK, "pWindowsStringHasEmbeddedNull failed\n");
+    ok(out_null == has_null, "WindowsStringHasEmbeddedNull failed\n");
+    ok(pWindowsGetStringLen(str) == length, "WindowsGetStringLen failed\n");
+    ptr = pWindowsGetStringRawBuffer(str, &out_length);
+    // WindowsGetStringRawBuffer should return a non-null, null terminated empty string
+    // even if str is NULL.
+    ok(ptr != NULL, "WindowsGetStringRawBuffer returned null\n");
+    ok(out_length == length, "WindowsGetStringRawBuffer returned incorrect length\n");
+    ptr = pWindowsGetStringRawBuffer(str, NULL);
+    ok(ptr != NULL, "WindowsGetStringRawBuffer returned null\n");
+    ok(ptr[length] == '\0', "WindowsGetStringRawBuffer doesn't return a null terminated buffer\n");
+}
+
+static void test_win_string(void)
+{
+    HMODULE hmod;
+    HSTRING str, str2;
+    HSTRING_HEADER header;
+    HSTRING_BUFFER buf;
+    WCHAR *ptr;
+    static const WCHAR input_string[] = { 'a', 'b', 'c', 'd', 'e', 'f', '\0' };
+    static const WCHAR input_embed_null[] = { 'a', '\0', 'c', '\0', 'e', 'f', '\0' };
+
+    hmod = LoadLibraryA("api-ms-win-core-winrt-string-l1-1-0.dll");
+    SET(WindowsCreateString);
+    SET(WindowsDuplicateString);
+    SET(WindowsCreateStringReference);
+    SET(WindowsDeleteString);
+    SET(WindowsPreallocateStringBuffer);
+    SET(WindowsDeleteStringBuffer);
+    SET(WindowsPromoteStringBuffer);
+    SET(WindowsGetStringLen);
+    SET(WindowsGetStringRawBuffer);
+    SET(WindowsStringHasEmbeddedNull);
+    SET(WindowsIsStringEmpty);
+
+    ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
+    check_string(str, 6, FALSE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+    ok(pWindowsCreateString(input_string, 6, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsCreateString(NULL, 6, &str) == E_POINTER, "Incorrect error handling\n");
+
+    ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
+    check_string(str, 6, FALSE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
+    // Strings to CreateStringReference must be null terminated with the correct length. According to MSDN this should be E_INVALIDARG, but it returns 0x80000017 in practice.
+    ok(FAILED(pWindowsCreateStringReference(input_string, 5, &header, &str)), "Incorrect error handling\n");
+    ok(pWindowsCreateStringReference(input_string, 6, NULL, &str) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsCreateStringReference(input_string, 6, &header, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsCreateStringReference(NULL, 6, &header, &str) == E_POINTER, "Incorrect error handling\n");
+
+    check_string(NULL, 0, FALSE);
+
+    ok(pWindowsCreateString(input_embed_null, 6, &str) == S_OK, "Failed to create string\n");
+    check_string(str, 6, TRUE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsCreateStringReference(input_embed_null, 6, &header, &str) == S_OK, "Failed to create string ref\n");
+    check_string(str, 6, TRUE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
+
+    ok(pWindowsCreateString(input_string, 0, &str) == S_OK, "Failed to create string\n");
+    check_string(str, 0, FALSE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+
+    // Test creating a string without a null-termination at the specified length
+    ok(pWindowsCreateString(input_string, 3, &str) == S_OK, "Failed to create string\n");
+    check_string(str, 3, FALSE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
+    ok(pWindowsDuplicateString(str, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsDuplicateString(str, &str2) == S_OK, "Failed to duplicate string\n");
+    ok(str == str2, "Duplicated string created new string\n");
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
+    ok(pWindowsDuplicateString(str, &str2) == S_OK, "Failed to duplicate string\n");
+    ok(str != str2, "Duplicated string ref didn't create new string\n");
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
+
+    ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
+    ok(pWindowsDeleteStringBuffer(buf) == S_OK, "Failed to delete string buffer\n");
+
+    ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
+    ok(ptr[6] == '\0', "Preallocated string buffer didn't have null termination\n");
+    memcpy(ptr, input_string, 6 * sizeof(*input_string));
+    ok(pWindowsPromoteStringBuffer(buf, NULL) == E_POINTER, "Incorrect error handling\n");
+    ok(pWindowsPromoteStringBuffer(buf, &str) == S_OK, "Failed to promote string buffer\n");
+    check_string(str, 6, FALSE);
+    ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsPreallocateStringBuffer(6, NULL, &buf) == E_POINTER, "Incorrect error handling\n");
+    ok(pWindowsPreallocateStringBuffer(6, &ptr, NULL) == E_POINTER, "Incorrect error handling\n");
+
+    ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
+    ptr[6] = 'a'; // Overwrite the buffer's null termination, promotion should fail
+    ok(pWindowsPromoteStringBuffer(buf, &str) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsDeleteStringBuffer(buf) == S_OK, "Failed to delete string buffer\n");
+}
+
+START_TEST(win_string)
+{
+    test_win_string();
+}
-- 
1.8.1.2




More information about the wine-patches mailing list