Fixed bugs #2728224, #2728218
[fw/sdcc] / support / regression / tests / memory.c
1 /** memory function test
2 */
3 #include <testfwk.h>
4
5 #include <string.h>
6
7 unsigned char destination[4];
8 const unsigned char source[4] = {0, 1, 2, 3};
9
10 void testmemory(void)
11 {
12   /* Test memset() */
13   destination[3] = 23;
14   memset(destination, 42, 3);
15   ASSERT(destination[0] == 42);
16   ASSERT(destination[2] == 42);
17   ASSERT(destination[3] == 23);
18
19   /* Test memcpy() */
20   memcpy(destination + 1, source + 1, 2);
21   ASSERT(destination[0] == 42);
22   ASSERT(destination[2] == source[2]);
23   ASSERT(destination[3] == 23);
24
25   /* Test memcmp() */
26   memcpy(destination, source, 4);
27   ASSERT(memcmp(destination, source, 4) == 0);
28
29   /* Test memmove() */
30   memcpy(destination, source, 4);
31   memmove(destination, destination + 1, 3);
32   ASSERT(destination[0] == source[1]);
33   ASSERT(destination[2] == source[3]);
34   ASSERT(destination[3] == source[3]);
35   memcpy(destination, source, 4);
36   memmove(destination + 1, destination, 3);
37   ASSERT(destination[0] == source[0]);
38   ASSERT(destination[1] == source[0]);
39   ASSERT(destination[3] == source[2]);
40
41   /* Test memchr() */
42   /* memchr() is not yet supported by sdcc.
43   ASSERT(NULL == memchr(destination, 5, 4));
44   ASSERT(destination == memchr(destination, 0, 4));
45   ASSERT(destination + 3 == memchr(destination, 3, 4));*/
46
47   ASSERT(strlen("test") == 4);
48   ASSERT(strlen("t") == 1);
49   ASSERT(strlen("") == 0);
50 }
51