]> git.sur5r.net Git - cc65/blob - test/val/cq9.c
added tests as prepared by oliver
[cc65] / test / val / cq9.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 9: Statements
3   !!ORIGIN!!      LCC 4.1 Testsuite
4   !!LICENCE!!     own, freely distributeable for non-profit. read CPYRIGHT.LCC
5 */
6
7 struct defs {
8      int cbits;          /* No. of bits per char           */
9      int ibits;          /*                 int            */
10      int sbits;          /*                 short          */
11      int lbits;          /*                 long           */
12      int ubits;          /*                 unsigned       */
13      int fbits;          /*                 float          */
14      int dbits;          /*                 double         */
15      #ifndef NO_FLOATS
16         float fprec;        /* Smallest number that can be    */
17         float dprec;        /* significantly added to 1.      */
18      #endif
19      int flgs;           /* Print return codes, by section */
20      int flgm;           /* Announce machine dependencies  */
21      int flgd;           /* give explicit diagnostics      */
22      int flgl;           /* Report local return codes.     */
23      int rrc;            /* recent return code             */
24      int crc;            /* Cumulative return code         */
25      char rfs[8];        /* Return from section            */
26 };
27
28      int lbits;          /*                 long           */
29      int ubits;          /*                 unsigned       */
30      int fbits;          /*                 float          */
31      int dbits;          /*                 double         */
32      #ifndef NO_FLOATS
33         float fprec;        /* Smallest number that can be    */
34         float dprec;        /* significantly added to 1.      */
35      #endif
36      int flgs;           /* Print return codes, by section */
37      int flgm;           /* Announce machine dependencies  */
38      int flgd;           /* give explicit diagnostics      */
39      int flgl;           /* Report local return codes.     */
40      int rrc;            /* recent return code             */
41      int crc;            /* Cumulative return code         */
42      char rfs[8];        /* Return from section            */
43
44 #ifndef NO_OLD_FUNC_DECL
45 s9(pd0)          /*  9  Statements  */
46 struct defs *pd0;
47 {
48 #else
49 int s9(struct defs *pd0){
50 #endif
51    static char s9er[] = "s9,er%d\n";
52    static char qs9[8] = "s9     ";
53    int rc;
54    char *ps, *pt;
55    int lrc, i;
56
57    ps = qs9;
58    pt = pd0->rfs;
59    rc = 0;
60    while (*pt++ = *ps++);
61
62         /* One would think that the section on statements would
63         provide the most variety in the entire sequence of tests.
64         As it turns out, most of the material in this section has
65         already been checked in the process of checking out
66         everything else, and the section at this point is somewhat
67         anticlimactic. For this reason, we restrict ourselves
68         to testing two features not already covered.
69
70         Compound statements are delimited by braces. They have the
71         nice property that identifiers of the auto and register
72         variety are pushed and popped. It is currently legal to
73         transfer into a block, but we wont...
74                                                                 */
75
76    lrc = 0;
77    for(i=0; i<2; i++){
78      int j;
79      register int k;
80      j = k = 2;
81        {
82        int j;
83        register int k;
84        j = k = 3;
85        if((j != 3) || (k != 3)) lrc = 1;
86        }
87      if((j != 2) || (k != 2)) lrc = 1;
88    }
89
90    if(lrc != 0){
91      if(pd0->flgd != 0) printf(s9er,1);
92      rc = rc+1;
93    }
94
95         /* Goto statements go to labeled statements, we hope.   */
96
97    goto nobarf;
98      if(pd0->flgd != 0) printf(s9er,2);
99      rc = rc+2;
100    nobarf:;
101
102    return rc;
103 }
104
105 /*********************************************************************************************
106  the main loop that launches the sections
107 *********************************************************************************************/
108
109 #ifndef NO_TYPELESS_STRUCT_PTR
110         int section(int j,struct* pd0){
111 #else
112         int section(int j,void* pd0){
113 #endif
114         switch(j){
115                 case 0: return s9(pd0);
116         }
117 }
118
119 #define cq_sections 1
120
121 /*
122         C REFERENCE MANUAL (main)
123 */
124
125 #ifndef NO_OLD_FUNC_DECL
126 main(n,args)
127 int n;
128 char **args;
129 {
130 #else
131 int main(int n,char **args) {
132 #endif
133
134 int j;
135 static struct defs d0, *pd0;
136
137    d0.flgs = 1;          /* These flags dictate            */
138    d0.flgm = 1;          /*     the verbosity of           */
139    d0.flgd = 1;          /*         the program.           */
140    d0.flgl = 1;
141
142    pd0 = &d0;
143
144    for (j=0; j<cq_sections; j++) {
145      d0.rrc=section(j,pd0);
146      d0.crc=d0.crc+d0.rrc;
147      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
148    }
149
150    if(d0.crc == 0) printf("\nNo errors detected.\n");
151    else printf("\nFailed.\n");
152
153    return d0.crc;
154 }