Imported Upstream version 2.9.0
[debian/cc1111] / 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 memmove() */
26   memcpy(destination, source, 4);
27   memmove(destination, destination + 1, 3);
28   ASSERT(destination[0] == source[1]);
29   ASSERT(destination[2] == source[3]);
30   ASSERT(destination[3] == source[3]);
31   memcpy(destination, source, 4);
32   memmove(destination + 1, destination, 3);
33   ASSERT(destination[0] == source[0]);
34   ASSERT(destination[1] == source[0]);
35   ASSERT(destination[3] == source[2]);
36
37   /* Test memchr() */
38   /* memchr() is not yet supported by sdcc.
39   ASSERT(NULL == memchr(destination, 5, 4));
40   ASSERT(destination == memchr(destination, 0, 4));
41   ASSERT(destination + 3 == memchr(destination, 3, 4));*/
42
43   ASSERT(strlen("test") == 4);
44   ASSERT(strlen("t") == 1);
45   ASSERT(strlen("") == 0);
46 }
47