storage.dll16: Fix get_nth_next_small_blocknr.
[wine.git] / dlls / combase / tests / string.c
blob7a705da2973954a6cbd370bf1e2129f4e74b4881
1 /*
2 * Unit tests for Windows String functions
4 * Copyright (c) 2014 Martin Storsjo
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winstring.h"
28 #include "wine/test.h"
30 static HRESULT (WINAPI *pWindowsCompareStringOrdinal)(HSTRING, HSTRING, INT32 *);
31 static HRESULT (WINAPI *pWindowsConcatString)(HSTRING, HSTRING, HSTRING *);
32 static HRESULT (WINAPI *pWindowsCreateString)(LPCWSTR, UINT32, HSTRING *);
33 static HRESULT (WINAPI *pWindowsCreateStringReference)(LPCWSTR, UINT32, HSTRING_HEADER *, HSTRING *);
34 static HRESULT (WINAPI *pWindowsDeleteString)(HSTRING);
35 static HRESULT (WINAPI *pWindowsDeleteStringBuffer)(HSTRING_BUFFER);
36 static HRESULT (WINAPI *pWindowsDuplicateString)(HSTRING, HSTRING *);
37 static UINT32 (WINAPI *pWindowsGetStringLen)(HSTRING);
38 static LPCWSTR (WINAPI *pWindowsGetStringRawBuffer)(HSTRING, UINT32 *);
39 static BOOL (WINAPI *pWindowsIsStringEmpty)(HSTRING);
40 static HRESULT (WINAPI *pWindowsPreallocateStringBuffer)(UINT32, WCHAR **, HSTRING_BUFFER *);
41 static HRESULT (WINAPI *pWindowsPromoteStringBuffer)(HSTRING_BUFFER, HSTRING *);
42 static HRESULT (WINAPI *pWindowsStringHasEmbeddedNull)(HSTRING, BOOL *);
43 static HRESULT (WINAPI *pWindowsSubstring)(HSTRING, UINT32, HSTRING *);
44 static HRESULT (WINAPI *pWindowsSubstringWithSpecifiedLength)(HSTRING, UINT32, UINT32, HSTRING *);
45 static HRESULT (WINAPI *pWindowsTrimStringEnd)(HSTRING, HSTRING, HSTRING *);
46 static HRESULT (WINAPI *pWindowsTrimStringStart)(HSTRING, HSTRING, HSTRING *);
48 #define SET(x) p##x = (void*)GetProcAddress(hmod, #x)
50 static BOOL init_functions(void)
52 HMODULE hmod = LoadLibraryA("combase.dll");
53 if (!hmod)
55 win_skip("Failed to load combase.dll, skipping tests\n");
56 return FALSE;
58 SET(WindowsCompareStringOrdinal);
59 SET(WindowsConcatString);
60 SET(WindowsCreateString);
61 SET(WindowsCreateStringReference);
62 SET(WindowsDeleteString);
63 SET(WindowsDeleteStringBuffer);
64 SET(WindowsDuplicateString);
65 SET(WindowsGetStringLen);
66 SET(WindowsGetStringRawBuffer);
67 SET(WindowsIsStringEmpty);
68 SET(WindowsPreallocateStringBuffer);
69 SET(WindowsPromoteStringBuffer);
70 SET(WindowsStringHasEmbeddedNull);
71 SET(WindowsSubstring);
72 SET(WindowsSubstringWithSpecifiedLength);
73 SET(WindowsTrimStringEnd);
74 SET(WindowsTrimStringStart);
75 return TRUE;
78 #undef SET
81 #define check_string(str, content, length, has_null) _check_string(__LINE__, str, content, length, has_null)
82 static void _check_string(int line, HSTRING str, LPCWSTR content, UINT32 length, BOOL has_null)
84 BOOL out_null;
85 BOOL empty = length == 0;
86 UINT32 out_length;
87 LPCWSTR ptr;
89 ok_(__FILE__, line)(pWindowsIsStringEmpty(str) == empty, "WindowsIsStringEmpty failed\n");
90 ok_(__FILE__, line)(pWindowsStringHasEmbeddedNull(str, &out_null) == S_OK, "pWindowsStringHasEmbeddedNull failed\n");
91 ok_(__FILE__, line)(out_null == has_null, "WindowsStringHasEmbeddedNull failed\n");
92 ok_(__FILE__, line)(pWindowsGetStringLen(str) == length, "WindowsGetStringLen failed\n");
93 ptr = pWindowsGetStringRawBuffer(str, &out_length);
94 /* WindowsGetStringRawBuffer should return a non-null, null terminated empty string
95 * even if str is NULL. */
96 ok_(__FILE__, line)(ptr != NULL, "WindowsGetStringRawBuffer returned null\n");
97 ok_(__FILE__, line)(out_length == length, "WindowsGetStringRawBuffer returned incorrect length\n");
98 ptr = pWindowsGetStringRawBuffer(str, NULL);
99 ok_(__FILE__, line)(ptr != NULL, "WindowsGetStringRawBuffer returned null\n");
100 ok_(__FILE__, line)(ptr[length] == '\0', "WindowsGetStringRawBuffer doesn't return a null terminated buffer\n");
101 ok_(__FILE__, line)(memcmp(ptr, content, sizeof(*content) * length) == 0, "Incorrect string content\n");
104 static const WCHAR input_string[] = { 'a', 'b', 'c', 'd', 'e', 'f', '\0', '\0' };
105 static const WCHAR input_string1[] = { 'a', 'b', 'c', '\0' };
106 static const WCHAR input_string2[] = { 'd', 'e', 'f', '\0' };
107 static const WCHAR input_empty_string[] = { '\0' };
108 static const WCHAR input_embed_null[] = { 'a', '\0', 'c', '\0', 'e', 'f', '\0' };
109 static const WCHAR output_substring[] = { 'c', 'd', 'e', 'f', '\0' };
111 static void test_create_delete(void)
113 HSTRING str;
114 HSTRING_HEADER header;
116 /* Test normal creation of a string */
117 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
118 check_string(str, input_string, 6, FALSE);
119 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
120 /* Test error handling in WindowsCreateString */
121 ok(pWindowsCreateString(input_string, 6, NULL) == E_INVALIDARG, "Incorrect error handling\n");
122 ok(pWindowsCreateString(NULL, 6, &str) == E_POINTER, "Incorrect error handling\n");
124 /* Test handling of a NULL string */
125 ok(pWindowsDeleteString(NULL) == S_OK, "Failed to delete null string\n");
127 /* Test creation of a string reference */
128 ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
129 check_string(str, input_string, 6, FALSE);
130 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
132 /* Test error handling in WindowsCreateStringReference */
133 /* Strings to CreateStringReference must be null terminated with the correct
134 * length. According to MSDN this should be E_INVALIDARG, but it returns
135 * 0x80000017 in practice. */
136 ok(FAILED(pWindowsCreateStringReference(input_string, 5, &header, &str)), "Incorrect error handling\n");
137 /* If the input string is non-null, it must be null-terminated even if the
138 * length is zero. */
139 ok(FAILED(pWindowsCreateStringReference(input_string, 0, &header, &str)), "Incorrect error handling\n");
140 ok(pWindowsCreateStringReference(input_string, 6, NULL, &str) == E_INVALIDARG, "Incorrect error handling\n");
141 ok(pWindowsCreateStringReference(input_string, 6, &header, NULL) == E_INVALIDARG, "Incorrect error handling\n");
142 ok(pWindowsCreateStringReference(NULL, 6, &header, &str) == E_POINTER, "Incorrect error handling\n");
144 /* Test creating a string without a null-termination at the specified length */
145 ok(pWindowsCreateString(input_string, 3, &str) == S_OK, "Failed to create string\n");
146 check_string(str, input_string, 3, FALSE);
147 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
149 /* Test an empty string */
150 ok(pWindowsCreateString(input_empty_string, 0, &str) == S_OK, "Failed to create string\n");
151 ok(str == NULL, "Empty string not a null string\n");
152 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
154 ok(pWindowsCreateString(input_string, 0, &str) == S_OK, "Failed to create string\n");
155 ok(str == NULL, "Empty string not a null string\n");
156 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
158 ok(pWindowsCreateStringReference(input_empty_string, 0, &header, &str) == S_OK, "Failed to create string\n");
159 ok(str == NULL, "Empty string not a null string\n");
160 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
162 ok(pWindowsCreateString(NULL, 0, &str) == S_OK, "Failed to create string\n");
163 ok(str == NULL, "Empty string not a null string\n");
164 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
166 ok(pWindowsCreateStringReference(NULL, 0, &header, &str) == S_OK, "Failed to create string\n");
167 ok(str == NULL, "Empty string not a null string\n");
168 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
171 static void test_duplicate(void)
173 HSTRING str, str2;
174 HSTRING_HEADER header;
175 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
176 ok(pWindowsDuplicateString(str, NULL) == E_INVALIDARG, "Incorrect error handling\n");
177 ok(pWindowsDuplicateString(str, &str2) == S_OK, "Failed to duplicate string\n");
178 ok(str == str2, "Duplicated string created new string\n");
179 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
180 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
182 ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
183 ok(pWindowsDuplicateString(str, &str2) == S_OK, "Failed to duplicate string\n");
184 ok(str != str2, "Duplicated string ref didn't create new string\n");
185 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
186 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
188 ok(pWindowsDuplicateString(NULL, &str2) == S_OK, "Failed to duplicate NULL string\n");
189 ok(str2 == NULL, "Duplicated string created new string\n");
190 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
193 static void test_access(void)
195 HSTRING str;
196 HSTRING_HEADER header;
198 /* Test handling of a NULL string */
199 check_string(NULL, NULL, 0, FALSE);
201 /* Test strings with embedded null chars */
202 ok(pWindowsCreateString(input_embed_null, 6, &str) == S_OK, "Failed to create string\n");
203 check_string(str, input_embed_null, 6, TRUE);
204 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
206 ok(pWindowsCreateStringReference(input_embed_null, 6, &header, &str) == S_OK, "Failed to create string ref\n");
207 check_string(str, input_embed_null, 6, TRUE);
208 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
210 /* Test normal creation of a string with trailing null */
211 ok(pWindowsCreateString(input_string, 7, &str) == S_OK, "Failed to create string\n");
212 check_string(str, input_string, 7, TRUE);
213 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
215 ok(pWindowsCreateStringReference(input_string, 7, &header, &str) == S_OK, "Failed to create string ref\n");
216 check_string(str, input_string, 7, TRUE);
217 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
220 static void test_string_buffer(void)
222 /* Initialize ptr to NULL to make sure it actually is set in the first
223 * test below. */
224 HSTRING_BUFFER buf = NULL;
225 WCHAR *ptr = NULL;
226 HSTRING str;
228 /* Test creation of an empty buffer */
229 ok(pWindowsPreallocateStringBuffer(0, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
230 ok(buf == NULL, "Empty string buffer isn't a null string\n");
231 ok(ptr != NULL, "Empty string didn't return a buffer pointer\n");
232 ok(pWindowsPromoteStringBuffer(buf, &str) == S_OK, "Failed to promote string buffer\n");
233 ok(str == NULL, "Empty string isn't a null string\n");
234 check_string(str, input_empty_string, 0, FALSE);
235 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
237 ok(pWindowsDeleteStringBuffer(NULL) == S_OK, "Failed to delete null string buffer\n");
239 /* Test creation and deletion of string buffers */
240 ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
241 ok(pWindowsDeleteStringBuffer(buf) == S_OK, "Failed to delete string buffer\n");
243 /* Test creation and promotion of string buffers */
244 ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
245 ok(ptr[6] == '\0', "Preallocated string buffer didn't have null termination\n");
246 memcpy(ptr, input_string, 6 * sizeof(*input_string));
247 ok(pWindowsPromoteStringBuffer(buf, NULL) == E_POINTER, "Incorrect error handling\n");
248 ok(pWindowsPromoteStringBuffer(buf, &str) == S_OK, "Failed to promote string buffer\n");
249 check_string(str, input_string, 6, FALSE);
250 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
252 /* Test error handling in preallocation */
253 ok(pWindowsPreallocateStringBuffer(6, NULL, &buf) == E_POINTER, "Incorrect error handling\n");
254 ok(pWindowsPreallocateStringBuffer(6, &ptr, NULL) == E_POINTER, "Incorrect error handling\n");
256 ok(pWindowsPreallocateStringBuffer(6, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
257 ptr[6] = 'a'; /* Overwrite the buffer's null termination, promotion should fail */
258 ok(pWindowsPromoteStringBuffer(buf, &str) == E_INVALIDARG, "Incorrect error handling\n");
259 ok(pWindowsDeleteStringBuffer(buf) == S_OK, "Failed to delete string buffer\n");
261 /* Test strings with trailing null chars */
262 ok(pWindowsPreallocateStringBuffer(7, &ptr, &buf) == S_OK, "Failed to preallocate string buffer\n");
263 memcpy(ptr, input_string, 7 * sizeof(*input_string));
264 ok(pWindowsPromoteStringBuffer(buf, &str) == S_OK, "Failed to promote string buffer\n");
265 check_string(str, input_string, 7, TRUE);
266 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
269 static void test_substring(void)
271 HSTRING str, substr;
272 HSTRING_HEADER header;
274 /* Test substring of string buffers */
275 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
276 ok(pWindowsSubstring(str, 2, &substr) == S_OK, "Failed to create substring\n");
277 check_string(substr, output_substring, 4, FALSE);
278 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
279 ok(pWindowsSubstringWithSpecifiedLength(str, 2, 3, &substr) == S_OK, "Failed to create substring\n");
280 check_string(substr, output_substring, 3, FALSE);
281 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
282 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
284 /* Test duplication of string using substring */
285 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
286 ok(pWindowsSubstring(str, 0, &substr) == S_OK, "Failed to create substring\n");
287 ok(str != substr, "Duplicated string didn't create new string\n");
288 check_string(substr, input_string, 6, FALSE);
289 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
290 ok(pWindowsSubstringWithSpecifiedLength(str, 0, 6, &substr) == S_OK, "Failed to create substring\n");
291 ok(str != substr, "Duplicated string didn't create new string\n");
292 check_string(substr, input_string, 6, FALSE);
293 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
294 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
296 /* Test substring of string reference */
297 ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
298 ok(pWindowsSubstring(str, 2, &substr) == S_OK, "Failed to create substring of string ref\n");
299 check_string(substr, output_substring, 4, FALSE);
300 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
301 ok(pWindowsSubstringWithSpecifiedLength(str, 2, 3, &substr) == S_OK, "Failed to create substring of string ref\n");
302 check_string(substr, output_substring, 3, FALSE);
303 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
304 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
306 /* Test duplication of string reference using substring */
307 ok(pWindowsCreateStringReference(input_string, 6, &header, &str) == S_OK, "Failed to create string ref\n");
308 ok(pWindowsSubstring(str, 0, &substr) == S_OK, "Failed to create substring of string ref\n");
309 ok(str != substr, "Duplicated string ref didn't create new string\n");
310 check_string(substr, input_string, 6, FALSE);
311 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
312 ok(pWindowsSubstringWithSpecifiedLength(str, 0, 6, &substr) == S_OK, "Failed to create substring of string ref\n");
313 ok(str != substr, "Duplicated string ref didn't create new string\n");
314 check_string(substr, input_string, 6, FALSE);
315 ok(pWindowsDeleteString(substr) == S_OK, "Failed to delete string\n");
316 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string ref\n");
318 /* Test get substring of empty string */
319 ok(pWindowsSubstring(NULL, 0, &substr) == S_OK, "Failed to duplicate NULL string\n");
320 ok(substr == NULL, "Substring created new string\n");
321 ok(pWindowsSubstringWithSpecifiedLength(NULL, 0, 0, &substr) == S_OK, "Failed to duplicate NULL string\n");
322 ok(substr == NULL, "Substring created new string\n");
324 /* Test get empty substring of string */
325 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
326 ok(pWindowsSubstring(str, 6, &substr) == S_OK, "Failed to create substring\n");
327 ok(substr == NULL, "Substring created new string\n");
328 ok(pWindowsSubstringWithSpecifiedLength(str, 6, 0, &substr) == S_OK, "Failed to create substring\n");
329 ok(substr == NULL, "Substring created new string\n");
330 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
332 /* Test handling of using too high start index or length */
333 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
334 ok(pWindowsSubstring(str, 7, &substr) == E_BOUNDS, "Incorrect error handling\n");
335 ok(pWindowsSubstringWithSpecifiedLength(str, 7, 0, &substr) == E_BOUNDS, "Incorrect error handling\n");
336 ok(pWindowsSubstringWithSpecifiedLength(str, 6, 1, &substr) == E_BOUNDS, "Incorrect error handling\n");
337 ok(pWindowsSubstringWithSpecifiedLength(str, 7, ~0U, &substr) == E_BOUNDS, "Incorrect error handling\n");
338 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
340 /* Test handling of a NULL string */
341 ok(pWindowsCreateString(input_string, 6, &str) == S_OK, "Failed to create string\n");
342 ok(pWindowsSubstring(str, 7, NULL) == E_INVALIDARG, "Incorrect error handling\n");
343 ok(pWindowsSubstringWithSpecifiedLength(str, 7, 0, NULL) == E_INVALIDARG, "Incorrect error handling\n");
344 ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
347 static void test_concat(void)
349 HSTRING str1, str2, concat;
350 HSTRING_HEADER header1, header2;
352 /* Test concatenation of string buffers */
353 ok(pWindowsCreateString(input_string1, 3, &str1) == S_OK, "Failed to create string\n");
354 ok(pWindowsCreateString(input_string2, 3, &str2) == S_OK, "Failed to create string\n");
356 ok(pWindowsConcatString(str1, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
357 ok(pWindowsConcatString(str1, NULL, &concat) == S_OK, "Failed to concatenate string\n");
358 ok(str1 == concat, "Concatenate created new string\n");
359 check_string(concat, input_string1, 3, FALSE);
360 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
362 ok(pWindowsConcatString(NULL, str2, NULL) == E_INVALIDARG, "Incorrect error handling\n");
363 ok(pWindowsConcatString(NULL, str2, &concat) == S_OK, "Failed to concatenate string\n");
364 ok(str2 == concat, "Concatenate created new string\n");
365 check_string(concat, input_string2, 3, FALSE);
366 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
368 ok(pWindowsConcatString(str1, str2, NULL) == E_INVALIDARG, "Incorrect error handling\n");
369 ok(pWindowsConcatString(str1, str2, &concat) == S_OK, "Failed to concatenate string\n");
370 check_string(concat, input_string, 6, FALSE);
371 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
373 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
374 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
376 /* Test concatenation of string references */
377 ok(pWindowsCreateStringReference(input_string1, 3, &header1, &str1) == S_OK, "Failed to create string ref\n");
378 ok(pWindowsCreateStringReference(input_string2, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
380 ok(pWindowsConcatString(str1, NULL, &concat) == S_OK, "Failed to concatenate string\n");
381 ok(str1 != concat, "Concatenate string ref didn't create new string\n");
382 check_string(concat, input_string1, 3, FALSE);
383 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
385 ok(pWindowsConcatString(NULL, str2, &concat) == S_OK, "Failed to concatenate string\n");
386 ok(str2 != concat, "Concatenate string ref didn't create new string\n");
387 check_string(concat, input_string2, 3, FALSE);
388 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
390 ok(pWindowsConcatString(str1, str2, &concat) == S_OK, "Failed to concatenate string\n");
391 check_string(concat, input_string, 6, FALSE);
392 ok(pWindowsDeleteString(concat) == S_OK, "Failed to delete string\n");
394 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
395 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string ref\n");
397 /* Test concatenation of two empty strings */
398 ok(pWindowsConcatString(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
399 ok(pWindowsConcatString(NULL, NULL, &concat) == S_OK, "Failed to concatenate string\n");
400 ok(concat == NULL, "Concatenate created new string\n");
403 static void test_compare(void)
405 HSTRING str1, str2;
406 HSTRING_HEADER header1, header2;
407 INT32 res;
409 /* Test comparison of string buffers */
410 ok(pWindowsCreateString(input_string1, 3, &str1) == S_OK, "Failed to create string\n");
411 ok(pWindowsCreateString(input_string2, 3, &str2) == S_OK, "Failed to create string\n");
413 ok(pWindowsCompareStringOrdinal(str1, str1, &res) == S_OK, "Failed to compare string\n");
414 ok(res == 0, "Expected 0, got %d\n", res);
415 ok(pWindowsCompareStringOrdinal(str1, str2, &res) == S_OK, "Failed to compare string\n");
416 ok(res == -1, "Expected -1, got %d\n", res);
417 ok(pWindowsCompareStringOrdinal(str2, str1, &res) == S_OK, "Failed to compare string\n");
418 ok(res == 1, "Expected 1, got %d\n", res);
419 ok(pWindowsCompareStringOrdinal(str2, str2, &res) == S_OK, "Failed to compare string\n");
420 ok(res == 0, "Expected 0, got %d\n", res);
421 ok(pWindowsCompareStringOrdinal(str1, NULL, &res) == S_OK, "Failed to compare string\n");
422 ok(res == 1, "Expected 1, got %d\n", res);
423 ok(pWindowsCompareStringOrdinal(NULL, str1, &res) == S_OK, "Failed to compare string\n");
424 ok(res == -1, "Expected -1, got %d\n", res);
425 ok(pWindowsCompareStringOrdinal(str2, NULL, &res) == S_OK, "Failed to compare string\n");
426 ok(res == 1, "Expected 1, got %d\n", res);
427 ok(pWindowsCompareStringOrdinal(NULL, str2, &res) == S_OK, "Failed to compare string\n");
428 ok(res == -1, "Expected -1, got %d\n", res);
430 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
431 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
433 /* Test comparison of string references */
434 ok(pWindowsCreateStringReference(input_string1, 3, &header1, &str1) == S_OK, "Failed to create string ref\n");
435 ok(pWindowsCreateStringReference(input_string2, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
437 ok(pWindowsCompareStringOrdinal(str1, str1, &res) == S_OK, "Failed to compare string\n");
438 ok(res == 0, "Expected 0, got %d\n", res);
439 ok(pWindowsCompareStringOrdinal(str1, str2, &res) == S_OK, "Failed to compare string\n");
440 ok(res == -1, "Expected -1, got %d\n", res);
441 ok(pWindowsCompareStringOrdinal(str2, str1, &res) == S_OK, "Failed to compare string\n");
442 ok(res == 1, "Expected 1, got %d\n", res);
443 ok(pWindowsCompareStringOrdinal(str2, str2, &res) == S_OK, "Failed to compare string\n");
444 ok(res == 0, "Expected 0, got %d\n", res);
445 ok(pWindowsCompareStringOrdinal(str1, NULL, &res) == S_OK, "Failed to compare string\n");
446 ok(res == 1, "Expected 1, got %d\n", res);
447 ok(pWindowsCompareStringOrdinal(NULL, str1, &res) == S_OK, "Failed to compare string\n");
448 ok(res == -1, "Expected -1, got %d\n", res);
449 ok(pWindowsCompareStringOrdinal(str2, NULL, &res) == S_OK, "Failed to compare string\n");
450 ok(res == 1, "Expected 1, got %d\n", res);
451 ok(pWindowsCompareStringOrdinal(NULL, str2, &res) == S_OK, "Failed to compare string\n");
452 ok(res == -1, "Expected -1, got %d\n", res);
454 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
455 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string ref\n");
457 /* Test comparison of two empty strings */
458 ok(pWindowsCompareStringOrdinal(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
459 ok(pWindowsCompareStringOrdinal(NULL, NULL, &res) == S_OK, "Failed to compare NULL string\n");
460 ok(res == 0, "Expected 0, got %d\n", res);
463 static void test_trim(void)
465 HSTRING str1, str2, trimmed;
466 HSTRING_HEADER header1, header2;
468 /* Test trimming of string buffers */
469 ok(pWindowsCreateString(input_string, 6, &str1) == S_OK, "Failed to create string\n");
470 ok(pWindowsCreateString(input_string1, 3, &str2) == S_OK, "Failed to create string\n");
472 ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
473 check_string(trimmed, input_string2, 3, FALSE);
474 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
475 ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
476 ok(trimmed == str1, "Trimmed string created new string\n");
477 check_string(trimmed, input_string, 6, FALSE);
478 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
480 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
481 ok(pWindowsCreateString(input_string2, 3, &str2) == S_OK, "Failed to create string\n");
483 ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
484 ok(trimmed == str1, "Trimmed string created new string\n");
485 check_string(trimmed, input_string, 6, FALSE);
486 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
487 ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
488 check_string(trimmed, input_string1, 3, FALSE);
489 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
491 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string\n");
492 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
494 /* Test trimming of string references */
495 ok(pWindowsCreateStringReference(input_string, 6, &header1, &str1) == S_OK, "Failed to create string ref\n");
496 ok(pWindowsCreateStringReference(input_string1, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
498 ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
499 check_string(trimmed, input_string2, 3, FALSE);
500 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
501 ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
502 ok(trimmed != str1, "Trimmed string ref didn't create new string\n");
503 check_string(trimmed, input_string, 6, FALSE);
504 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
506 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
507 ok(pWindowsCreateStringReference(input_string2, 3, &header2, &str2) == S_OK, "Failed to create string ref\n");
509 ok(pWindowsTrimStringStart(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
510 ok(trimmed != str1, "Trimmed string ref didn't create new string\n");
511 check_string(trimmed, input_string, 6, FALSE);
512 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
513 ok(pWindowsTrimStringEnd(str1, str2, &trimmed) == S_OK, "Failed to trim string\n");
514 check_string(trimmed, input_string1, 3, FALSE);
515 ok(pWindowsDeleteString(trimmed) == S_OK, "Failed to delete string\n");
517 ok(pWindowsDeleteString(str2) == S_OK, "Failed to delete string ref\n");
518 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string ref\n");
520 /* Test handling of NULL strings */
521 ok(pWindowsCreateString(input_string, 6, &str1) == S_OK, "Failed to create string\n");
522 ok(pWindowsTrimStringStart(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
523 ok(pWindowsTrimStringStart(NULL, str1, NULL) == E_INVALIDARG, "Incorrect error handling\n");
524 ok(pWindowsTrimStringStart(NULL, NULL, &trimmed) == E_INVALIDARG, "Incorrect error handling\n");
525 ok(pWindowsTrimStringStart(NULL, str1, &trimmed) == S_OK, "Failed to trim empty string\n");
526 ok(trimmed == NULL, "Trimming created new string\n");
527 ok(pWindowsTrimStringEnd(NULL, NULL, NULL) == E_INVALIDARG, "Incorrect error handling\n");
528 ok(pWindowsTrimStringEnd(NULL, str1, NULL) == E_INVALIDARG, "Incorrect error handling\n");
529 ok(pWindowsTrimStringEnd(NULL, NULL, &trimmed) == E_INVALIDARG, "Incorrect error handling\n");
530 ok(pWindowsTrimStringEnd(NULL, str1, &trimmed) == S_OK, "Failed to trim empty string\n");
531 ok(trimmed == NULL, "Trimming created new string\n");
532 ok(pWindowsDeleteString(str1) == S_OK, "Failed to delete string\n");
535 START_TEST(string)
537 if (!init_functions())
538 return;
539 test_create_delete();
540 test_duplicate();
541 test_access();
542 test_string_buffer();
543 test_substring();
544 test_concat();
545 test_compare();
546 test_trim();