Moved mciavi32 to the top-level dlls directory.
[wine] / dlls / msvcrt / tests / string.c
1 /*
2  * Unit test suite for string functions.
3  *
4  * Copyright 2004 Uwe Bonnes
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include <string.h>
24 #include <stdlib.h>
25
26 static void* (*pmemcpy)(void *, const void *, size_t n);
27 static int* (*pmemcmp)(void *, const void *, size_t n);
28
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)
31
32 static void test_swab( void ) {
33     char original[]  = "BADCFEHGJILKNMPORQTSVUXWZY@#";
34     char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#";
35     char expected2[] = "ABCDEFGHIJKLMNOPQRSTUVWX$";
36     char expected3[] = "$";
37     
38     char from[30];
39     char to[30];
40     
41     int testsize;
42     
43     /* Test 1 - normal even case */                               
44     memset(to,'$', sizeof(to));
45     memset(from,'@', sizeof(from));
46     testsize = 26;
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);
50
51     /* Test 2 - uneven case  */                               
52     memset(to,'$', sizeof(to));
53     memset(from,'@', sizeof(from));
54     testsize = 25;
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);
58
59     /* Test 3 - from = to */                               
60     memset(to,'$', sizeof(to));
61     memset(from,'@', sizeof(from));
62     testsize = 26;
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);
66
67     /* Test 4 - 1 bytes */                               
68     memset(to,'$', sizeof(to));
69     memset(from,'@', sizeof(from));
70     testsize = 1;
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);
74 }
75
76
77 START_TEST(string)
78 {
79     void *mem;
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");
86
87     /* MSVCRT memcpy behaves like memmove for overlapping moves,
88        MFC42 CString::Insert seems to rely on that behaviour */
89     mem = malloc(100);
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);
95
96     /* Test _swab function */
97     test_swab();
98 }