e979897cac565692723206cb961cafd4380b3fbc
[uebersetzerbau-ss10.git] / asmb / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 extern unsigned char *asmb(unsigned char *a);
6
7 unsigned char *asmb_ref(unsigned char *s)
8 {
9         unsigned long i;
10         for (i=0; s[i]; 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 #define NUM_TESTCASES 12
19 int main()
20 {
21         char *input[NUM_TESTCASES]={"asdfABCDEFGHKL54", 
22                 "foofuuMUHkk", 
23                 "AbC", 
24                 "BLA|MUHMKUH|KA", 
25                 "ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH", 
26                 "asdfABCDEFGHKL544", 
27                 "asdfA\0BCDEFGHKL5", 
28                 "foofuuMUHkk\0AAAA", 
29                 "AbC\0AAAAAAAAAAAA", 
30                 "BLA|MUHMKUH|KAA\0", 
31                 "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", 
32                 "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" 
33         };
34         int len[NUM_TESTCASES] = {16,
35                 11,
36                 3,
37                 14,
38                 60,
39                 17,
40                 16,
41                 16,
42                 16,
43                 16,
44                 32,
45                 48
46         };
47         char *output_our, *output_ref;
48         char *input_our,  *input_ref;
49
50         int i,j;
51         for(i = 0; i < NUM_TESTCASES; i++) {
52                 input_our = strndup(input[i], len[i]);
53                 input_ref = strndup(input[i], len[i]);
54
55                 output_our = (char *) asmb((unsigned char*) input_our);
56                 output_ref = (char *) asmb_ref((unsigned char*) input_ref);
57                 if(memcmp(output_our,output_ref, len[i]) != 0) {
58                         printf("Testfall falsch!\nInput:\n\t");
59                         for(j = 0; j <= len[i]; j++) {
60                                 printf("%02X ", input[i][j]);
61                         }
62                         printf("\nerwartet:\n\t");
63                         for(j = 0; j <= len[i]; j++) {
64                                 printf("%02X ", output_ref[j]);
65                         }
66                         printf("\ntatsaechliches Ergebnis:\n\t");
67                         for(j = 0; j <= len[i]; j++) {
68                                 printf("%02X ", output_our[j]);
69                         }
70                         printf("\n");
71                 }
72                 else {
73                         printf("Testfall korrekt\n");
74                 }
75                 free(input_our);
76                 free(input_ref);
77         }
78         return 0;
79 }
80