Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / satcounteroverflow.c.in
blobb22887c302a6259ada676aa8cbcbff5d6063caca
1 /** user-implemented saturating counters using unsigned integer wraparound
3 type: unsigned char, unsigned int, unsigned long
4 */
6 #include <testfwk.h>
8 {type} cnt;
10 void satinc(void)
12 cnt++;
13 if (!cnt)
14 cnt--;
17 void satdec(void)
19 cnt--;
20 if (cnt == ({type})-1)
21 cnt++;
24 void testSat(void)
26 cnt = 0;
27 satinc ();
28 ASSERT (cnt == 1);
29 satdec ();
30 satdec ();
31 ASSERT (cnt == 0);
33 cnt = -2;
34 satinc ();
35 ASSERT (cnt == ({type})-1);
36 satinc ();
37 ASSERT (cnt == ({type})-1);