Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / addsub.c
1 /** Add, sub tests.
2
3     type: signed char, int, long
4     storage: static, 
5     attr: volatile
6 */
7 #include <testfwk.h>
8
9 void 
10 testAdd(void)
11 {
12   {storage} {attr} {type} left, right, result;
13
14   left = 5;
15   right = 26;
16
17   result = left+right;
18   ASSERT(result == 31);
19   
20   left = 39;
21   right = -120;
22   
23   result = left+right;
24   ASSERT(result == (39-120));
25
26   left = -39;
27   right = 80;
28   
29   result = left+right;
30   ASSERT(result == (-39+80));
31
32   left = -39;
33   right = -70;
34   
35   result = left+right;
36   ASSERT(result == (-39-70));
37
38   result += 0xab00;
39   ASSERT(result == ({type})(0xab00-39-70));
40 }
41
42 void 
43 testSub(void)
44 {
45   {storage} {attr} {type} left, right, result;
46
47   left = 5;
48   right = 26;
49
50   result = left-right;
51   ASSERT(result == (5-26));
52   
53   left = 39;
54   right = -76;
55   
56   result = left-right;
57   ASSERT(result == (39+76));
58
59   left = -12;
60   right = 56;
61   
62   result = left-right;
63   ASSERT(result == (-12-56));
64   
65   left = -39;
66   right = -20;
67   
68   result = left-right;
69   ASSERT(result == (-39+20));
70
71   result = left-(signed)0x1200;
72   ASSERT(result == ({type})(-39-(signed)0x1200));
73 }