mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-11-21 16:46:54 -08:00
182 lines
8.0 KiB
Diff
182 lines
8.0 KiB
Diff
|
From 397611b845973e2418118ffcb4aee305b671d533 Mon Sep 17 00:00:00 2001
|
||
|
From: Thomas Pointhuber <thomas.pointhuber@gmx.at>
|
||
|
Date: Mon, 16 Mar 2015 09:45:21 +0100
|
||
|
Subject: combase: implement WindowsSubstring (try 2)
|
||
|
|
||
|
---
|
||
|
.../api-ms-win-core-winrt-string-l1-1-0.spec | 2 +-
|
||
|
dlls/combase/combase.spec | 2 +-
|
||
|
dlls/combase/string.c | 19 +++++++
|
||
|
dlls/combase/tests/string.c | 60 ++++++++++++++++++++++
|
||
|
include/winerror.h | 1 +
|
||
|
5 files changed, 82 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git a/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec b/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
|
||
|
index 2361a1d..825980d 100644
|
||
|
--- a/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
|
||
|
+++ b/dlls/api-ms-win-core-winrt-string-l1-1-0/api-ms-win-core-winrt-string-l1-1-0.spec
|
||
|
@@ -21,7 +21,7 @@
|
||
|
@ stdcall WindowsPromoteStringBuffer(ptr ptr) combase.WindowsPromoteStringBuffer
|
||
|
@ stub WindowsReplaceString
|
||
|
@ stdcall WindowsStringHasEmbeddedNull(ptr ptr) combase.WindowsStringHasEmbeddedNull
|
||
|
-@ stub WindowsSubstring
|
||
|
+@ stdcall WindowsSubstring(ptr long ptr) combase.WindowsSubstring
|
||
|
@ stub WindowsSubstringWithSpecifiedLength
|
||
|
@ stub WindowsTrimStringEnd
|
||
|
@ stub WindowsTrimStringStart
|
||
|
diff --git a/dlls/combase/combase.spec b/dlls/combase/combase.spec
|
||
|
index ac095ce..48c3a7e 100644
|
||
|
--- a/dlls/combase/combase.spec
|
||
|
+++ b/dlls/combase/combase.spec
|
||
|
@@ -302,7 +302,7 @@
|
||
|
@ stdcall WindowsPromoteStringBuffer(ptr ptr)
|
||
|
@ stub WindowsReplaceString
|
||
|
@ stdcall WindowsStringHasEmbeddedNull(ptr ptr)
|
||
|
-@ stub WindowsSubstring
|
||
|
+@ stdcall WindowsSubstring(ptr long ptr)
|
||
|
@ stub WindowsSubstringWithSpecifiedLength
|
||
|
@ stub WindowsTrimStringEnd
|
||
|
@ stub WindowsTrimStringStart
|
||
|
diff --git a/dlls/combase/string.c b/dlls/combase/string.c
|
||
|
index 7054af6..33e5100 100644
|
||
|
--- a/dlls/combase/string.c
|
||
|
+++ b/dlls/combase/string.c
|
||
|
@@ -255,6 +255,25 @@ HRESULT WINAPI WindowsStringHasEmbeddedNull(HSTRING str, BOOL *out)
|
||
|
}
|
||
|
|
||
|
/***********************************************************************
|
||
|
+ * WindowsSubstring (combase.@)
|
||
|
+ */
|
||
|
+HRESULT WINAPI WindowsSubstring(HSTRING str, UINT32 start, HSTRING *out)
|
||
|
+{
|
||
|
+ struct hstring_private *priv = impl_from_HSTRING(str);
|
||
|
+ UINT32 len = WindowsGetStringLen(str);
|
||
|
+ if (out == NULL)
|
||
|
+ return E_INVALIDARG;
|
||
|
+ if (start > len)
|
||
|
+ return E_BOUNDS;
|
||
|
+ if (start == len)
|
||
|
+ {
|
||
|
+ *out = NULL;
|
||
|
+ return S_OK;
|
||
|
+ }
|
||
|
+ return WindowsCreateString(&priv->buffer[start], len - start, out);
|
||
|
+}
|
||
|
+
|
||
|
+/***********************************************************************
|
||
|
* WindowsIsStringEmpty (combase.@)
|
||
|
*/
|
||
|
BOOL WINAPI WindowsIsStringEmpty(HSTRING str)
|
||
|
diff --git a/dlls/combase/tests/string.c b/dlls/combase/tests/string.c
|
||
|
index 72eaa84..c46d04e 100644
|
||
|
--- a/dlls/combase/tests/string.c
|
||
|
+++ b/dlls/combase/tests/string.c
|
||
|
@@ -38,6 +38,7 @@ static BOOL (WINAPI *pWindowsIsStringEmpty)(HSTRING);
|
||
|
static HRESULT (WINAPI *pWindowsPreallocateStringBuffer)(UINT32, WCHAR **, HSTRING_BUFFER *);
|
||
|
static HRESULT (WINAPI *pWindowsPromoteStringBuffer)(HSTRING_BUFFER, HSTRING *);
|
||
|
static HRESULT (WINAPI *pWindowsStringHasEmbeddedNull)(HSTRING, BOOL *);
|
||
|
+static HRESULT (WINAPI *pWindowsSubstring)(HSTRING, UINT32, HSTRING *);
|
||
|
|
||
|
#define SET(x) p##x = (void*)GetProcAddress(hmod, #x)
|
||
|
|
||
|
@@ -60,6 +61,7 @@ static BOOL init_functions(void)
|
||
|
SET(WindowsPreallocateStringBuffer);
|
||
|
SET(WindowsPromoteStringBuffer);
|
||
|
SET(WindowsStringHasEmbeddedNull);
|
||
|
+ SET(WindowsSubstring);
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
@@ -92,6 +94,7 @@ static void _check_string(int line, HSTRING str, LPCWSTR content, UINT32 length,
|
||
|
static const WCHAR input_string[] = { 'a', 'b', 'c', 'd', 'e', 'f', '\0', '\0' };
|
||
|
static const WCHAR input_empty_string[] = { '\0' };
|
||
|
static const WCHAR input_embed_null[] = { 'a', '\0', 'c', '\0', 'e', 'f', '\0' };
|
||
|
+static const WCHAR output_substring[] = { 'c', 'd', 'e', 'f', '\0' };
|
||
|
|
||
|
static void test_create_delete(void)
|
||
|
{
|
||
|
@@ -236,6 +239,62 @@ static void test_string_buffer(void)
|
||
|
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
}
|
||
|
|
||
|
+static void test_substring(void)
|
||
|
+{
|
||
|
+ HSTRING str, substr;
|
||
|
+ HSTRING_HEADER header;
|
||
|
+
|
||
|
+ /* Test substring of string buffers */
|
||
|
+ ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
|
||
|
+ ok(pWindowsSubstring(str, 2, &substr) == S_OK, "Failed to create substring!\n");
|
||
|
+ check_string(substr, output_substring, 4, FALSE);
|
||
|
+ ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+
|
||
|
+ /* Test duplication of string using substring */
|
||
|
+ ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
|
||
|
+ ok(pWindowsSubstring(str, 0, &substr) == S_OK, "Failed to create substring!\n");
|
||
|
+ ok(str != substr, "Duplicated string didn't create new string\n");
|
||
|
+ check_string(substr, input_string, 6, FALSE);
|
||
|
+ ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+
|
||
|
+ /* Test substring of string reference */
|
||
|
+ ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
|
||
|
+ ok(pWindowsSubstring(str, 2, &substr) == S_OK, "Failed to create substring of string ref!\n");
|
||
|
+ check_string(substr, output_substring, 4, FALSE);
|
||
|
+ ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
|
||
|
+
|
||
|
+ /* Test duplication of string reference using substring */
|
||
|
+ ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
|
||
|
+ ok(pWindowsSubstring(str, 0, &substr) == S_OK, "Failed to create substring of string ref!\n");
|
||
|
+ ok(str != substr, "Duplicated string ref didn't create new string\n");
|
||
|
+ check_string(substr, input_string, 6, FALSE);
|
||
|
+ ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+
|
||
|
+ /* Test get Substring of empty string */
|
||
|
+ ok(pWindowsSubstring(NULL, 0, &substr) == S_OK, "Failed to duplicate NULL string\n");
|
||
|
+ ok(substr == NULL, "Substring created new string\n");
|
||
|
+
|
||
|
+ /* Test get empty Substring of string */
|
||
|
+ ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
|
||
|
+ ok(pWindowsSubstring(str, 6, &substr) == S_OK, "Failed to create substring!\n");
|
||
|
+ ok(substr == NULL, "Substring created new string\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+
|
||
|
+ /* Test handling of using to high startIndex */
|
||
|
+ ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
|
||
|
+ ok(pWindowsSubstring(str, 7, &substr) == E_BOUNDS, "Incorrect error handling\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+
|
||
|
+ /* Test handling of a NULL string */
|
||
|
+ ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
|
||
|
+ ok(pWindowsSubstring(str, 7, NULL) == E_INVALIDARG, "Incorrect error handling\n");
|
||
|
+ ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
|
||
|
+}
|
||
|
+
|
||
|
START_TEST(string)
|
||
|
{
|
||
|
if (!init_functions())
|
||
|
@@ -244,4 +303,5 @@ START_TEST(string)
|
||
|
test_duplicate();
|
||
|
test_access();
|
||
|
test_string_buffer();
|
||
|
+ test_substring();
|
||
|
}
|
||
|
diff --git a/include/winerror.h b/include/winerror.h
|
||
|
index 2958cbd..9b9fb72 100644
|
||
|
--- a/include/winerror.h
|
||
|
+++ b/include/winerror.h
|
||
|
@@ -2090,6 +2090,7 @@ static inline HRESULT HRESULT_FROM_WIN32(unsigned int x)
|
||
|
#define S_FALSE _HRESULT_TYPEDEF_(1)
|
||
|
|
||
|
#define E_PENDING _HRESULT_TYPEDEF_(0x8000000A)
|
||
|
+#define E_BOUNDS _HRESULT_TYPEDEF_(0x8000000B)
|
||
|
|
||
|
|
||
|
#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001)
|
||
|
--
|
||
|
2.3.2
|
||
|
|