OSDN Git Service

Enable to track git://github.com/monaka/binutils.git
[pf3gnuchains/pf3gnuchains3x.git] / winsup / mingw / mingwex / testwmem.c
1 #include <memory.h>
2 #include <wchar.h>
3 #include <stdio.h>
4
5 wchar_t fmt1[] =   L"         1         2         3         4         5";
6 wchar_t fmt2[] =   L"12345678901234567890123456789012345678901234567890";
7
8 void test_wmemchr( void )
9 {
10    wchar_t* dest;
11    wint_t result;
12    wint_t ch = L'r';
13    wchar_t str[] =   L"lazy";
14    wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";
15
16    wprintf( L"Wmemchr\n" );
17    wprintf( L"String to be searched:\n\t\t%s\n", string1 );
18    wprintf( L"\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );
19
20    wprintf( L"Search char:\t%c\n", ch );
21    dest = wmemchr( string1, ch, sizeof( string1 ) );
22    result = dest - string1 + 1;
23    if( dest != NULL )
24       wprintf( L"Result:\t\t%c found at position %d\n\n", ch, result );
25    else
26       wprintf( L"Result:\t\t%c not found\n\n" );
27 return;
28 }
29 void test_wmemset( void )
30 {/*                               1         2 
31                         0123456789012345678901234567890 */
32    wchar_t buffer[] = L"This is a test of the wmemset function";
33    wprintf( L"Before: %s\n", buffer );
34    wmemset( buffer+22, L'*', 7 );
35    wprintf( L"After:  %s\n\n", buffer );
36 return;
37 }
38
39 void test_wmemmove( void )
40 {
41     wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";
42     wchar_t string2[60] = L"The quick brown fox jumps over the lazy dog";
43
44     wprintf( L"Wmemcpy without overlap\n" );
45     wprintf( L"Source:\t\t%s\n", string1 + 40 );
46     wprintf( L"Destination:\t%s\n", string1 + 16 );
47     wmemcpy( string1 + 16, string1 + 40, 3 );
48     wprintf( L"Result:\t\t%s\n", string1 );
49     wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
50     wmemcpy( string1 + 16, string2 + 40, 3 );
51
52    wprintf( L"Wmemmove with overlap\n" );
53    wprintf( L"Source:\t\t%s\n", string2 + 4 );
54    wprintf( L"Destination:\t%s\n", string2 + 10 );
55    wmemmove( string2 + 10, string2 + 4, 40 );
56    wprintf( L"Result:\t\t%s\n", string2 );
57    wprintf( L"Length:\t\t%d characters\n\n", wcslen( string2 ) );
58
59    wprintf( L"Wmemcpy with overlap\n" );
60    wprintf( L"Source:\t\t%s\n", string1 + 4 );
61    wprintf( L"Destination:\t%s\n", string1 + 10 );
62    wmemcpy( string1 + 10, string1 + 4, 40 );
63    wprintf( L"Result:\t\t%s\n", string1 );
64    wprintf( L"Length:\t\t%d characters\n\n", wcslen( string1 ) );
65 }
66
67
68 void test_wmemcmp( void )
69 {
70    wchar_t first[]  = L"12345678901234567890";
71    wchar_t second[] = L"12345678901234567891";
72    wint_t result;
73    wprintf(L"Wmemcmp\n"); 
74    wprintf( L"Compare '%.19s' to '%.19s':\n", first, second );
75    result = wmemcmp( first, second, 19 );
76    if( result < 0 )
77       wprintf( L"First is less than second.\n" );
78    else if( result == 0 )
79       wprintf( L"First is equal to second.\n" );
80    else if( result > 0 )
81       wprintf( L"First is greater than second.\n" );
82    wprintf( L"\nCompare '%.20s' to '%.20s':\n", first, second );
83    result = wmemcmp( first, second, 20 );
84    if( result < 0 )
85       wprintf( L"First is less than second.\n\n" );
86    else if( result == 0 )
87       wprintf( L"First is equal to second.\n\n" );
88    else if( result > 0 )
89       wprintf( L"First is greater than second.\n\n" );
90 }
91
92
93
94 int main(){
95 test_wmemset();
96 test_wmemmove();
97 test_wmemchr();
98 test_wmemcmp();
99 return 0;
100 }
101
102
103
104