blob: b22887c302a6259ada676aa8cbcbff5d6063caca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
/** user-implemented saturating counters using unsigned integer wraparound
type: unsigned char, unsigned int, unsigned long
*/
#include <testfwk.h>
{type} cnt;
void satinc(void)
{
cnt++;
if (!cnt)
cnt--;
}
void satdec(void)
{
cnt--;
if (cnt == ({type})-1)
cnt++;
}
void testSat(void)
{
cnt = 0;
satinc ();
ASSERT (cnt == 1);
satdec ();
satdec ();
ASSERT (cnt == 0);
cnt = -2;
satinc ();
ASSERT (cnt == ({type})-1);
satinc ();
ASSERT (cnt == ({type})-1);
}
|