struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-string-opt-5.c
blob5004714801c58c9cf43d934150e24a93d824572b
1 /*
2 string-opt-5.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 /* Copyright (C) 2000 Free Software Foundation.
13 Ensure builtin strlen, strcmp, strchr, strrchr and strncpy
14 perform correctly.
16 Written by Jakub Jelinek, 11/7/2000. */
18 #include <string.h>
20 int x = 6;
21 int y = 1;
22 const char *bar = "hi world";
23 char buf [24];
25 void
26 testTortureExecute (void)
28 #if !defined(__SDCC_pic16) && !defined(__SDCC_pdk14) // Lack of memory
29 const char *const foo = "hello world";
30 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
31 char dst [64];
32 #endif
34 if (strlen (bar) != 8)
35 ASSERT (0);
36 if (strlen (bar + (++x & 2)) != 6)
37 ASSERT (0);
38 if (x != 7)
39 ASSERT (0);;
40 if (strlen (foo + (x++, 6)) != 5)
41 ASSERT (0);
42 if (x != 8)
43 ASSERT (0);
44 if (strlen (foo + (++x & 1)) != 10)
45 ASSERT (0);
46 if (x != 9)
47 ASSERT (0);
48 if (strcmp (foo + (x -= 6), "lo world"))
49 ASSERT (0);
50 if (x != 3)
51 ASSERT (0);
52 if (strcmp (foo, bar) >= 0)
53 ASSERT (0);
54 if (strcmp (foo, bar + (x++ & 1)) >= 0)
55 ASSERT (0);
56 if (x != 4)
57 ASSERT (0);
58 if (strchr (foo + (x++ & 7), 'l') != foo + 9)
59 ASSERT (0);
60 if (x != 5)
61 ASSERT (0);
62 if (strchr (bar, 'o') != bar + 4)
63 ASSERT (0);
64 if (strchr (bar, '\0') != bar + 8)
65 ASSERT (0);
66 if (strrchr (bar, 'x'))
67 ASSERT (0);
68 if (strrchr (bar, 'o') != bar + 4)
69 ASSERT (0);
70 if (strcmp (foo + (x++ & 1), "ello world" + (--y & 1)))
71 ASSERT (0);
72 if (x != 6 || y != 0)
73 ASSERT (0);
74 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
75 dst[5] = ' ';
76 dst[6] = '\0';
77 x = 5;
78 y = 1;
79 if (strncpy (dst + 1, foo + (x++ & 3), 4) != dst + 1
80 || x != 6
81 || strcmp (dst + 1, "ello "))
82 ASSERT (0);
83 memset (dst, ' ', sizeof dst);
84 if (strncpy (dst + (++x & 1), (y++ & 3) + "foo", 10) != dst + 1
85 || x != 7
86 || y != 2
87 || memcmp (dst, " oo\0\0\0\0\0\0\0\0 ", 12))
88 ASSERT (0);
89 memset (dst, ' ', sizeof dst);
90 if (strncpy (dst, "hello", 8) != dst || memcmp (dst, "hello\0\0\0 ", 9))
91 ASSERT (0);
92 x = '!';
93 memset (buf, ' ', sizeof buf);
94 if (memset (buf, x++, ++y) != buf
95 || x != '!' + 1
96 || y != 3
97 || memcmp (buf, "!!!", 3))
98 ASSERT (0);
99 if (memset (buf + y++, '-', 8) != buf + 3
100 || y != 4
101 || memcmp (buf, "!!!--------", 11))
102 ASSERT (0);
103 x = 10;
104 if (memset (buf + ++x, 0, y++) != buf + 11
105 || x != 11
106 || y != 5
107 || memcmp (buf + 8, "---\0\0\0", 7))
108 ASSERT (0);
110 if (memset (buf + (x += 4), 0, 6) != buf + 15
111 || x != 15
112 || memcmp (buf + 10, "-\0\0\0\0\0\0\0\0\0", 11))
113 ASSERT (0);
115 return;
116 #endif
117 #endif