Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / addsub.c.in
blob1d07d1499add5ad24a4d2149cfa26c7397a7b0d6
1 /** Add, sub tests.
3 type: signed char, int, long
4 storage: static,
5 attr: volatile
6 */
7 #include <testfwk.h>
9 {type} add_func({type} i)
11 return(i + (5ul << 16));
14 void
15 testAdd(void)
17 {storage} {attr} {type} left, right, result;
19 left = 5;
20 right = 26;
22 result = left+right;
23 ASSERT(result == 31);
25 left = 39;
26 right = -120;
28 result = left+right;
29 ASSERT(result == (39-120));
31 left = -39;
32 right = 80;
34 result = left+right;
35 ASSERT(result == (-39+80));
37 left = -39;
38 right = -70;
40 result = left+right;
41 ASSERT(result == (-39-70));
43 result += 0xab00;
44 ASSERT(result == ({type})(0xab00-39-70));
46 left = 0x5500;
47 right = 0x0a00;
49 result = left + right;
50 ASSERT(result == ({type})(0x5500 + 0x0a00));
52 left = 0x550000ul;
54 result = left + 0x0a0000ul;
55 ASSERT(result == ({type})(0x550000ul + 0x0a0000ul));
57 ASSERT(add_func(0) == ({type})(5ul << 16));
60 void
61 testSub(void)
63 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
64 {storage} {attr} {type} left, right, result;
66 left = 5;
67 right = 26;
69 result = left-right;
70 ASSERT(result == (5-26));
72 left = 39;
73 right = -76;
75 result = left-right;
76 ASSERT(result == (39+76));
78 left = -12;
79 right = 56;
81 result = left-right;
82 ASSERT(result == (-12-56));
84 left = -39;
85 right = -20;
87 result = left-right;
88 ASSERT(result == (-39+20));
90 result = left-(signed)0x1200;
91 ASSERT(result == ({type})(-39-(signed)0x1200));
92 #endif