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"
26 static void* (*pmemcpy)(void *, const void *, size_t n);
27 static int* (*pmemcmp)(void *, const void *, size_t n);
29 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
30 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
32 static void test_swab( void ) {
33 char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#";
34 char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
35 char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
36 char expected3[] = "$";
43 /* Test 1 - normal even case */
44 memset(to,'$', sizeof(to));
45 memset(from,'@', sizeof(from));
47 memcpy(from, original, testsize);
48 _swab( from, to, testsize );
49 ok(memcmp(to,expected1,testsize) == 0, "Testing even size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
51 /* Test 2 - uneven case */
52 memset(to,'$', sizeof(to));
53 memset(from,'@', sizeof(from));
55 memcpy(from, original, testsize);
56 _swab( from, to, testsize );
57 ok(memcmp(to,expected2,testsize) == 0, "Testing odd size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
59 /* Test 3 - from = to */
60 memset(to,'$', sizeof(to));
61 memset(from,'@', sizeof(from));
63 memcpy(to, original, testsize);
64 _swab( to, to, testsize );
65 ok(memcmp(to,expected1,testsize) == 0, "Testing overlapped size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
67 /* Test 4 - 1 bytes */
68 memset(to,'$', sizeof(to));
69 memset(from,'@', sizeof(from));
71 memcpy(from, original, testsize);
72 _swab( from, to, testsize );
73 ok(memcmp(to,expected3,testsize) == 0, "Testing small size %d returned '%*.*s'\n", testsize, testsize, testsize, to);
80 static const char xilstring[]="c:/xilinx";
81 int nLen=strlen(xilstring);
82 HMODULE hMsvcrt = LoadLibraryA("msvcrt.dll");
83 ok(hMsvcrt != 0, "LoadLibraryA failed\n");
84 SET(pmemcpy,"memcpy");
85 SET(pmemcmp,"memcmp");
87 /* MSVCRT memcpy behaves like memmove for overlapping moves,
88 MFC42 CString::Insert seems to rely on that behaviour */
90 ok(mem != NULL, "memory not allocated for size 0\n");
91 strcpy((char*)mem,xilstring);
92 pmemcpy((char*)mem+5, mem,nLen+1);
93 ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0,
94 "Got result %s\n",(char*)mem+5);
96 /* Test _swab function */