asmb: pernors infforum thread bla
[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         char *input[NUM_TESTCASES]={"asdfABCDEFGHKL54", 
21                 "foofuuMUHkk", 
22                 "AbC", 
23                 "BLA|MUHMKUH|KA", 
24                 "ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH", 
25                 "asdfABCDEFGHKL544", 
26                 "asdfA\0BCDEFGHKL5", 
27                 "foofuuMUHkk\0AAAA", 
28                 "AbC\0AAAAAAAAAAAA", 
29                 "BLA|MUHMKUH|KAA\0", 
30                 "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", 
31                 "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" 
32         };
33         int len[NUM_TESTCASES] = {16,
34                 11,
35                 3,
36                 14,
37                 60,
38                 17,
39                 16,
40                 16,
41                 16,
42                 16,
43                 32,
44                 48
45         };
46         char *output_our, *output_ref;
47         char *input_our,  *input_ref;
48
49         int i,j;
50         for(i = 0; i < NUM_TESTCASES; i++) {
51                 input_our = strndup(input[i], len[i]);
52                 input_ref = strndup(input[i], len[i]);
53
54                 output_our = asmb(input_our);
55                 output_ref = asmb_ref(input_ref);
56                 if(memcmp(output_our,output_ref, len[i]) != 0) {
57                         printf("Testfall falsch! \n Input: \n");
58                         for(j = 0; j <= len[i]; j++) {
59                                 printf("%02X ",input[j]);
60                         }
61                         printf("\nerwartet: \n");
62                         for(j = 0; j <= len[i]; j++) {
63                                 printf("%02X ",output_ref[j]);
64                         }
65                         printf("\ntatsaechliches Ergebnis: \n");
66                         for(j = 0; j <= len[i]; j++) {
67                                 printf("%02X ",output_our[j]);
68                         }
69                         printf("\n");
70                 }
71                 else {
72                         printf("Testfall korrekt\n");
73                 }
74                 free(input_our);
75                 free(input_ref);
76         }
77         return 0;
78 }
79
80