b8932f7594b879b7c70814dc62b5def01817e37d
[uebersetzerbau-ss10.git] / asmb / asmbtest.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 13
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                 "ASas\0ASas"
33         };
34         int len[NUM_TESTCASES] = {16,
35                 11,
36                 3,
37                 14,
38                 61,
39                 17,
40                 16,
41                 16,
42                 16,
43                 16,
44                 32,
45                 48,
46                 9
47         };
48         char *output_our, *output_ref;
49         char *input_our,  *input_ref;
50
51         int i,j;
52         for(i = 0; i < NUM_TESTCASES; i++) {
53                 input_our = strndup(input[i], len[i]);
54                 input_ref = strndup(input[i], len[i]);
55
56                 output_our = (char *) asmb((unsigned char *) input_our);
57                 output_ref = (char *) asmb_ref((unsigned char *) input_ref);
58                 if(memcmp(output_our,output_ref, len[i]) != 0) {
59                         printf("Testfall%02i falsch!\n Input(\"%s\"):\n\t", i, input[i]);
60                         for(j = 0; j <= len[i]; j++) {
61                                 printf("%02X ", input[i][j]);
62                         }
63                         printf("\nerwartet:\n\t");
64                         for(j = 0; j <= len[i]; j++) {
65                                 printf("%02X ", output_ref[j]);
66                         }
67                         printf("\ntatsaechliches Ergebnis:\n\t");
68                         for(j = 0; j <= len[i]; j++) {
69                                 printf("%02X ", output_our[j]);
70                         }
71                         printf("\n");
72                 }
73                 else {
74                         printf("Testfall%02i korrekt\n", i);
75                 }
76                 free(input_our);
77                 free(input_ref);
78         }
79         return 0;
80 }
81