asma: ... offizielle testfaelle rennen jetzt auch durch
[uebersetzerbau-ss10.git] / asma / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 extern unsigned char *asma(unsigned char *s);
6
7 unsigned char *asma_ref(unsigned char *s)
8 {
9         int i;
10         for (i=0; i<16; i++) {
11                 unsigned char c = s[i];
12                 c += (c >= 'A' && c <= 'Z') ? 'a'-'A' : 0;
13                 s[i] = c;
14         }
15         return s;
16 }
17
18 int main(int argc, char **argv) {
19         char *input1[]={"asdfABCDEFGHKL54", "foofuuMUHkk", "AbC", "BLA|MUHMKUH|KA"};
20         char *output1;
21         char *output2;
22         char *input2;
23         char *input3;
24         int i, j;
25         int off[] = {2,0,0,0};
26
27         for(i = 0; i < 4; i++) {
28                 input2 = strdup(input1[i]);
29                 input3 = strdup(input1[i]);
30                 output1 = (char *)asma_ref((unsigned char *)(input2 + off[i]));
31                 output2 = (char *)asma((unsigned char *)(input3 + off[i]));
32
33                 output1[16]='\0';
34                 output2[16]='\0';
35
36                 printf("\n");
37                 if(memcmp(output1,output2, 16)) {
38                         j = 0;
39                         printf("Testfall falsch; Input war: \"%s\"\n", input1[i]);
40                         printf("erwartet:\n\t\"%s\"\ntatsaechliches Ergebnis:\n\t\"%s\"\n", output1, output2);
41 #if 0
42                         printf("0x");
43                         for(j = 0; j < 16; j++)
44                                 printf("%02X", output2[j]);
45                         printf("\n");
46 #endif
47                 } else {
48                         printf("Testfall \"%s\" passt.\n", output1);
49                 }
50
51                 free(input2);
52                 free(input3);
53         }
54
55         return 0;
56 }
57