Fixes for missing prototypes warnings.
[wine/multimedia.git] / dlls / msvcrt / tests / string.c
blob7fda59e12d7611fc57f35393a483bb125494be09
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 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 START_TEST(string)
104 void *mem;
105 static const char xilstring[]="c:/xilinx";
106 int nLen=strlen(xilstring);
107 HMODULE hMsvcrt = LoadLibraryA("msvcrt.dll");
108 ok(hMsvcrt != 0, "LoadLibraryA failed\n");
109 SET(pmemcpy,"memcpy");
110 SET(pmemcmp,"memcmp");
112 /* MSVCRT memcpy behaves like memmove for overlapping moves,
113 MFC42 CString::Insert seems to rely on that behaviour */
114 mem = malloc(100);
115 ok(mem != NULL, "memory not allocated for size 0\n");
116 strcpy((char*)mem,xilstring);
117 pmemcpy((char*)mem+5, mem,nLen+1);
118 ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0,
119 "Got result %s\n",(char*)mem+5);
121 /* Test _swab function */
122 test_swab();
124 /* Test ismbblead*/
125 test_ismbblead();
126 /* test _mbsspn */
127 test_mbsspn();