]> git.sur5r.net Git - cc65/blob - test/val/add4.c
added tests as prepared by oliver
[cc65] / test / val / add4.c
1 /*
2   !!DESCRIPTION!!
3   !!ORIGIN!!      SDCC regression tests
4   !!LICENCE!!     GPL, read COPYING.GPL
5 */
6
7 #include <stdio.h>
8 #include <limits.h>
9
10 unsigned char success = 0;
11 unsigned char failures = 0;
12 unsigned char dummy = 0;
13
14 #ifdef SUPPORT_BIT_TYPES
15 bit bit0 = 0;
16 #endif
17 int int0 = 0;
18 int int1 = 0;
19 char char0 = 0;
20 char char1 = 0;
21 long long0 = 0;
22 long long1 = 0;
23 unsigned long ulong0 = 0;
24 unsigned long ulong1 = 0;
25 #define NULL 0
26 char *cP0=NULL;
27 char *cP1=NULL;
28 int *iP0=NULL;
29 int *iP1=NULL;
30
31 void
32 done ()
33 {
34   dummy++;
35 }
36
37 /* pointer to char arithmetic */
38
39 void pc_add(void)
40 {
41   if(*cP1)
42     failures++;
43
44   *cP1 += 1;
45   if(*cP1 != 1)
46     failures++;
47
48   if(char0 != 1)
49     failures++;
50
51   char0++;
52
53   if(*cP1 != 2)
54     failures++;
55
56   char1 = char0 + *cP1;
57
58   if(char1 != 4)
59     failures++;
60 }
61
62 /* pointer to integer arithmetic */
63 void pi_add(void)
64 {
65   if(*iP0)
66     failures++;
67
68   *iP0 += 1;
69
70   if(*iP0 != 1)
71     failures++;
72
73   if(int0 != 1)
74     failures++;
75
76   int1 = int0 + *iP0;
77   if(int1 != 2)
78     failures++;
79 }
80
81 int main(void)
82 {
83   cP1 = &char0;
84   pc_add();
85
86   iP0 = &int0;
87   pi_add();
88
89   success = failures;
90   done();
91   printf("failures: %d\n",failures);
92
93   return failures;
94 }