3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
8 char rcs_id[] = "$Id$" ;
16 /* This program can be used to test C-compilers */
17 /* It is supposed the first test program (= "test1") */
18 /* is used to test the basic arithmetic */
20 /* The following are global counters */
22 int t, /* the value indicates the number of the test procedure */
23 ect, /* error counter */
24 tct; /* count the number of test procedures called */
26 /************************************************************************/
28 /* The following is tested: */
29 /* FOR STATEMENTS in test1 */
30 /* WHILE STATEMENTS in test2 */
31 /* WHILE and FOR STATEMENTS in test3 */
32 /* DO STATEMENTS in test4 */
33 /* SWITCH STATEMENTS in test5
\e */
35 /************************************************************************/
39 char *pp1 = "End of test program, ";
40 char *pp2 = " test(s) completed, ";
41 char *pp3 = " errors detected\n";
43 char *pp5 = " in test";
47 /* converts integer "p" to ascii string "ptr" */
79 for (i=0, j=strlen(s)-1; i<j; i++, j--)
88 /* returns the length of string str */
103 char chtct[10],chect[10];
105 ect = 0; /* No errors, so far so good */
106 test1(); /* testing FOR STATEMENTS */
107 test2(); /* testing WHILE STATEMENTS */
108 test3(); /* testing combined FOR and WHILE statements */
109 test4(); /* testing DO statements */
110 test5(); /* testing SWITCH statements */
111 test6(); /* testing GOTO statements */
114 write(1,pp1,strlen(pp1));
116 write(1,chtct,strlen(chtct));
117 write(1,pp2,strlen(pp2));
119 write(1,chect,strlen(chect));
120 write(1,pp3,strlen(pp3));
126 e(n) /* prints an error message */
129 char cht[10],chn[10];
130 ect++; /* total number of errors increased by 1 */
131 write(1,pp4,strlen(pp4));
133 write(1,chn,strlen(chn));
134 write(1,pp5,strlen(pp5));
136 write(1,cht,strlen(cht));
137 write(1,pp6,strlen(pp6));
143 test1() /* Testing the for statement */
145 int i, j; /* variables, used as contolling integers in the */
148 t = 1; /* This is test 1 */
154 return; /* If the break doesn't work, let's hope the */
214 for (i=i; i<(i+0); i++)
215 for (i=i+0; i<(i-0); i++)
216 for (i=i-0; i<i; i++)
235 for (i++, i++, i++, i++; ; )
241 for (i=j=i=j=i=j=i; i && j && i; --i, --j)
246 for (i=32700; i<32767; i++)
252 for (i=32000; i<=32767; i++)
258 for (i=32767; i>32700; i--)
262 for (i= -32768; i<-32700; i++)
270 test2() /* Testing the while statement */
316 while ( (i==j) && (i!=j) )
347 test3() /* Combined FOR and WHILE statements */
365 test4() /* Do statement */
401 test5() /* SWITCH statement */
411 case 0: if (i != 0) e(1);
413 case 1: if (i != 1) e(2);
415 case 2: if (i != 2) e(3);
417 case 3: if (i != 3) e(4);
419 case 4: if (i != 4) e(5);
429 for (i=j= -18; i<10; i++, j++)
447 case -4: if (i != -4) e(9);
476 test6() /* goto statement */
499 llab8: if ( k != 4 ) e(5);
505 lab0: if ( k!= 0 ) e(1);
507 lab1: if ( k!= 1 ) e(2);
509 lab2: if ( k!= 2 ) e(3);
511 lab3: if ( k!= 3 ) e(4);
517 test7() /* Combinations of FOR, WHILE, DO and SWITCH statements */
523 for ( i=j=k=0; i<6; i++, j++, k++ )
551 case 0: if ( i+j+k != 0 ) e(7);
554 default: if ( i+j+k != k ) e(9);
557 default: if ( j > 6 ) e(10);
569 for ( i=j= -3; i<0; i++,j++)
575 case -3: if ( j != i ) e(13);
576 case -2: if ( j != i ) e(14);
577 case -1: for ( k=i; k < 2*j-j; k++)
600 int a1[1], a2[2][2], a3[3][3][3];
605 for ( i=0; i<2; i++ )
606 for ( j=0; j<2; j++ )
607 a2[i][j] = (i*j) ^ (i+j);
608 if ( a2[0][0] != 0 ) e(1);
609 if ( a2[0][1] != 1 ) e(2);
610 if ( a2[1][0] != a2[0][1] ) e(3);
614 a3[i][j][k] = i | j | k;
615 if ( a3[0][0][0] != 0 ) e(4);
616 if ( a3[0][1][2] != a3[2][0][1] ) e(5);
617 if ( a3[2][1][1] != (2 | 1 | 1) ) e(6);
620 for ( ; p1 == p2 ; p1++ )
627 if ( *p1 != *p2 ) e(8);