From 6a3505cc0e0a632cdf9fb10c0b38b8f0a435a13d Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 17 Jan 2016 05:58:08 +0100
Subject: combase/tests: Add tests for WindowsTrimString{Start,End}.

---
 dlls/combase/tests/string.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/dlls/combase/tests/string.c b/dlls/combase/tests/string.c
index db6c8f5..ac6c587 100644
--- a/dlls/combase/tests/string.c
+++ b/dlls/combase/tests/string.c
@@ -42,6 +42,8 @@ static HRESULT (WINAPI *pWindowsPromoteStringBuffer)(HSTRING_BUFFER, HSTRING *);
 static HRESULT (WINAPI *pWindowsStringHasEmbeddedNull)(HSTRING, BOOL *);
 static HRESULT (WINAPI *pWindowsSubstring)(HSTRING, UINT32, HSTRING *);
 static HRESULT (WINAPI *pWindowsSubstringWithSpecifiedLength)(HSTRING, UINT32, UINT32, HSTRING *);
+static HRESULT (WINAPI *pWindowsTrimStringEnd)(HSTRING, HSTRING, HSTRING *);
+static HRESULT (WINAPI *pWindowsTrimStringStart)(HSTRING, HSTRING, HSTRING *);
 
 #define SET(x) p##x = (void*)GetProcAddress(hmod, #x)
 
@@ -68,6 +70,8 @@ static BOOL init_functions(void)
     SET(WindowsStringHasEmbeddedNull);
     SET(WindowsSubstring);
     SET(WindowsSubstringWithSpecifiedLength);
+    SET(WindowsTrimStringEnd);
+    SET(WindowsTrimStringStart);
     return TRUE;
 }
 
@@ -456,6 +460,78 @@ static void test_compare(void)
     ok(res == 0, "Expected 0, got %d\n", res);
 }
 
+static void test_trim(void)
+{
+    HSTRING str1, str2, trimmed;
+    HSTRING_HEADER header1, header2;
+
+    /* Test trimming of string buffers */
+    ok(pWindowsCreateString(input_string, 6, &str1) == S_OK, "Failed to create string\n");
+    ok(pWindowsCreateString(input_string1, 3, &str2) == S_OK, "Failed to create string\n");
+
+    ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    check_string(trimmed, input_string2, 3, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+    ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    ok(trimmed == str1, "Trimmed string created new string\n");
+    check_string(trimmed, input_string, 6, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
+    ok(pWindowsCreateString(input_string2, 3, &str2) == S_OK, "Failed to create string\n");
+
+    ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    ok(trimmed == str1, "Trimmed string created new string\n");
+    check_string(trimmed, input_string, 6, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+    ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    check_string(trimmed, input_string1, 3, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
+    ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
+
+    /* Test trimming of string references */
+    ok(pWindowsCreateStringReference(input_string, 6, &header1, &str1) == S_OK, "Failed to create string ref\n");
+    ok(pWindowsCreateStringReference(input_string1, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
+
+    ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    check_string(trimmed, input_string2, 3, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+    ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    ok(trimmed != str1, "Trimmed string ref didn't create new string\n");
+    check_string(trimmed, input_string, 6, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
+    ok(pWindowsCreateStringReference(input_string2, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
+
+    ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    ok(trimmed != str1, "Trimmed string ref didn't create new string\n");
+    check_string(trimmed, input_string, 6, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+    ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
+    check_string(trimmed, input_string1, 3, FALSE);
+    ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
+
+    ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
+    ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string ref\n");
+
+    /* Test handling of a NULL string */
+    ok(pWindowsCreateString(input_string, 6, &str1) == S_OK, "Failed to create string\n");
+    ok(pWindowsTrimStringStart(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringStart(NULL, str1, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringStart(NULL, NULL, &trimmed) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringStart(NULL, str1, &trimmed) == S_OK, "Failed to trim empty string\n");
+    ok(trimmed == NULL, "Trimming created new string\n");
+    ok(pWindowsTrimStringEnd(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringEnd(NULL, str1, NULL) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringEnd(NULL, NULL, &trimmed) == E_INVALIDARG, "Incorrect error handling\n");
+    ok(pWindowsTrimStringEnd(NULL, str1, &trimmed) == S_OK, "Failed to trim empty string\n");
+    ok(trimmed == NULL, "Trimming created new string\n");
+    ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
+}
+
 START_TEST(string)
 {
     if (!init_functions())
@@ -467,4 +543,5 @@ START_TEST(string)
     test_substring();
     test_concat();
     test_compare();
+    test_trim();
 }
-- 
2.6.4

