3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 wchar_t fmt1[] = L" 1 2 3 4 5";
29 wchar_t fmt2[] = L"12345678901234567890123456789012345678901234567890";
31 void test_wmemchr( void )
36 wchar_t str[] = L"lazy";
37 wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";
39 wprintf( L"Wmemchr\n" );
40 wprintf( L"String to be searched:\n\t\t%s\n", string1 );
41 wprintf( L"\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
43 wprintf( L"Search char:\t%c\n", ch );
44 dest = wmemchr( string1, ch, sizeof( string1 ) );
45 result = dest - string1 + 1;
47 wprintf( L"Result:\t\t%c found at position %d\n\n", ch, result );
49 wprintf( L"Result:\t\t%c not found\n\n" );
52 void test_wmemset( void )
54 0123456789012345678901234567890 */
55 wchar_t buffer[] = L"This is a test of the wmemset function";
56 wprintf( L"Before: %s\n", buffer );
57 wmemset( buffer+22, L'*', 7 );
58 wprintf( L"After: %s\n\n", buffer );
62 void test_wmemmove( void )
64 wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";
65 wchar_t string2[60] = L"The quick brown fox jumps over the lazy dog";
67 wprintf( L"Wmemcpy without overlap\n" );
68 wprintf( L"Source:\t\t%s\n", string1 + 40 );
69 wprintf( L"Destination:\t%s\n", string1 + 16 );
70 wmemcpy( string1 + 16, string1 + 40, 3 );
71 wprintf( L"Result:\t\t%s\n", string1 );
72 wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
73 wmemcpy( string1 + 16, string2 + 40, 3 );
75 wprintf( L"Wmemmove with overlap\n" );
76 wprintf( L"Source:\t\t%s\n", string2 + 4 );
77 wprintf( L"Destination:\t%s\n", string2 + 10 );
78 wmemmove( string2 + 10, string2 + 4, 40 );
79 wprintf( L"Result:\t\t%s\n", string2 );
80 wprintf( L"Length:\t\t%d characters\n\n", wcslen( string2 ) );
82 wprintf( L"Wmemcpy with overlap\n" );
83 wprintf( L"Source:\t\t%s\n", string1 + 4 );
84 wprintf( L"Destination:\t%s\n", string1 + 10 );
85 wmemcpy( string1 + 10, string1 + 4, 40 );
86 wprintf( L"Result:\t\t%s\n", string1 );
87 wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
91 void test_wmemcmp( void )
93 wchar_t first[] = L"12345678901234567890";
94 wchar_t second[] = L"12345678901234567891";
96 wprintf(L"Wmemcmp\n");
97 wprintf( L"Compare '%.19s' to '%.19s':\n", first, second );
98 result = wmemcmp( first, second, 19 );
100 wprintf( L"First is less than second.\n" );
101 else if( result == 0 )
102 wprintf( L"First is equal to second.\n" );
103 else if( result > 0 )
104 wprintf( L"First is greater than second.\n" );
105 wprintf( L"\nCompare '%.20s' to '%.20s':\n", first, second );
106 result = wmemcmp( first, second, 20 );
108 wprintf( L"First is less than second.\n\n" );
109 else if( result == 0 )
110 wprintf( L"First is equal to second.\n\n" );
111 else if( result > 0 )
112 wprintf( L"First is greater than second.\n\n" );