push 4d5485f9b89f417d46b39b93e8d940437007f325
[wine/hacks.git] / dlls / msvcrt / tests / string.c
blob7b434f79998515a9a4b9d546869d9ccb2f1b4ac0
1 /*
2 * Unit test suite for string functions.
4 * Copyright 2004 Uwe Bonnes
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 "wine/test.h"
22 #include "winbase.h"
23 #include <string.h>
24 #include <mbstring.h>
25 #include <stdlib.h>
26 #include <mbctype.h>
28 static void* (*pmemcpy)(void *, const void *, size_t n);
29 static int* (*pmemcmp)(void *, const void *, size_t n);
31 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
32 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
34 static void test_swab( void ) {
35 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
36 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
37 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
38 char expected3[] = "$";
40 char from[30];
41 char to[30];
43 int testsize;
45 /* Test 1 - normal even case */
46 memset(to,'$', sizeof(to));
47 memset(from,'@', sizeof(from));
48 testsize = 26;
49 memcpy(from, original, testsize);
50 _swab( from, to, testsize );
51 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
53 /* Test 2 - uneven case */
54 memset(to,'$', sizeof(to));
55 memset(from,'@', sizeof(from));
56 testsize = 25;
57 memcpy(from, original, testsize);
58 _swab( from, to, testsize );
59 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
61 /* Test 3 - from = to */
62 memset(to,'$', sizeof(to));
63 memset(from,'@', sizeof(from));
64 testsize = 26;
65 memcpy(to, original, testsize);
66 _swab( to, to, testsize );
67 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
69 /* Test 4 - 1 bytes */
70 memset(to,'$', sizeof(to));
71 memset(from,'@', sizeof(from));
72 testsize = 1;
73 memcpy(from, original, testsize);
74 _swab( from, to, testsize );
75 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
78 static void test_ismbblead(void)
80 unsigned int s = '\354';
82 _setmbcp(936);
83 todo_wine ok(_ismbblead(s), "got result %d\n", _ismbblead(s));
84 _setmbcp(1252);
87 static void test_mbsspn( void)
89 unsigned char str1[]="cabernet";
90 unsigned char str2[]="shiraz";
91 unsigned char set[]="abc";
92 unsigned char empty[]="";
93 int ret;
94 ret=_mbsspn( str1, set);
95 ok( ret==3, "_mbsspn returns %d should be 3\n", ret);
96 ret=_mbsspn( str2, set);
97 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
98 ret=_mbsspn( str1, empty);
99 ok( ret==0, "_mbsspn returns %d should be 0\n", ret);
102 static void test_mbsspnp( void)
104 unsigned char str1[]="cabernet";
105 unsigned char str2[]="shiraz";
106 unsigned char set[]="abc";
107 unsigned char empty[]="";
108 unsigned char full[]="abcenrt";
109 unsigned char* ret;
110 ret=_mbsspnp( str1, set);
111 ok( ret[0]=='e', "_mbsspnp returns %c should be e\n", ret[0]);
112 ret=_mbsspnp( str2, set);
113 ok( ret[0]=='s', "_mbsspnp returns %c should be s\n", ret[0]);
114 ret=_mbsspnp( str1, empty);
115 ok( ret[0]=='c', "_mbsspnp returns %c should be c\n", ret[0]);
116 ret=_mbsspnp( str1, full);
117 ok( ret==NULL, "_mbsspnp returns %p should be NULL\n", ret);
120 static void test_strdup(void)
122 char *str;
123 str = _strdup( 0 );
124 ok( str == 0, "strdup returns %s should be 0\n", str);
125 free( str );
128 START_TEST(string)
130 void *mem;
131 static const char xilstring[]="c:/xilinx";
132 int nLen;
133 HMODULE hMsvcrt;
135 hMsvcrt = GetModuleHandleA("msvcrt.dll");
136 if (!hMsvcrt)
137 hMsvcrt = GetModuleHandleA("msvcrtd.dll");
138 ok(hMsvcrt != 0, "GetModuleHandleA failed\n");
139 SET(pmemcpy,"memcpy");
140 SET(pmemcmp,"memcmp");
142 /* MSVCRT memcpy behaves like memmove for overlapping moves,
143 MFC42 CString::Insert seems to rely on that behaviour */
144 mem = malloc(100);
145 ok(mem != NULL, "memory not allocated for size 0\n");
146 strcpy((char*)mem,xilstring);
147 nLen=strlen(xilstring);
148 pmemcpy((char*)mem+5, mem,nLen+1);
149 ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0,
150 "Got result %s\n",(char*)mem+5);
152 /* Test _swab function */
153 test_swab();
155 /* Test ismbblead*/
156 test_ismbblead();
157 /* test _mbsspn */
158 test_mbsspn();
159 test_mbsspnp();
160 /* test _strdup */
161 test_strdup();