asmb: asmb verhaelt sich nun exakt wie asmb_ref
[uebersetzerbau-ss10.git] / asmb / asmbtest.c
index ed928c5fb8750a6d2ab97adb73c66bd66c2f3b82..bea72ba703a03c8ba70ee44607bc426bf08f929f 100644 (file)
@@ -15,10 +15,38 @@ unsigned char *asmb_ref(unsigned char *s)
        return s;
 }
 
-#define NUM_TESTCASES 13
+static char ascii(char s) {
+       if(s < 0x20) return '.';
+       if(s > 0x7E) return '.';
+       return s;
+}
+
+static void hexdump(void *d, int len) {
+       unsigned char *data;
+       int i, off;
+       data = (unsigned char*)d;
+       for (off=0; off<len; off += 16) {
+               printf("\t%08x  ",off);
+               for(i=0; i<16; i++)
+                       if((i+off)>=len) printf("   ");
+                       else printf("%02x ",data[off+i]);
+
+               printf(" ");
+               for(i=0; i<16; i++)
+                       if((i+off)>=len) printf(" ");
+                       else printf("%c",ascii(data[off+i]));
+               printf("\n");
+       }
+}
+
+#define NUM_TESTCASES 17
 int main()
 {
-       char *input[NUM_TESTCASES]={"asdfABCDEFGHKL54", 
+       char *input[NUM_TESTCASES]={
+               "AAaaB\0BBUUUUZZZZ",
+               "AAaaBBB\0",
+               "AaA\0ABBB",
+               "A\0ABCDEF",
                "foofuuMUHkk", 
                "AbC", 
                "BLA|MUHMKUH|KA", 
@@ -29,10 +57,15 @@ int main()
                "AbC\0AAAAAAAAAAAA", 
                "BLA|MUHMKUH|KAA\0", 
                "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", 
-               "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" ,
-               "ASas\0ASas"
+               "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf",
+               "ASas\0ASas",
+               "asdfABCDEFGHKL54",
        };
-       int len[NUM_TESTCASES] = {16,
+       int len[NUM_TESTCASES] = {
+               16,
+               8,
+               8,
+               8,
                11,
                3,
                14,
@@ -44,12 +77,13 @@ int main()
                16,
                32,
                48,
-               9
+               9,
+               16
        };
        char *output_our, *output_ref;
        char *input_our,  *input_ref;
+       int right=0, wrong=0, neither=0, i;
 
-       int i,j;
        for(i = 0; i < NUM_TESTCASES; i++) {
                input_our = (char *) malloc (len[i]);
                input_ref = (char *) malloc (len[i]);
@@ -61,31 +95,34 @@ int main()
                output_ref = (char *) asmb_ref((unsigned char *) input_ref);
 
                if(memcmp(output_our,output_ref, len[i]) != 0) {
-                       if(strncmp(output_our, output_ref, len[i]) == 0)
+                       if(strncmp(output_our, output_ref, len[i]) == 0) {
+                               neither++;
                                printf("Testfall%02i nach Nullbyte ungleich\n", i);
-                       else
-                               printf("Testfall%02i falsch!\n", i);
-
-                       printf("Input(\"%s\"):\n\t", input[i]);
-                       for(j = 0; j <= len[i]; j++) {
-                               printf("%02X ", input[i][j]);
                        }
-                       printf("\nerwartet:\n\t");
-                       for(j = 0; j <= len[i]; j++) {
-                               printf("%02X ", output_ref[j]);
-                       }
-                       printf("\ntatsaechliches Ergebnis:\n\t");
-                       for(j = 0; j <= len[i]; j++) {
-                               printf("%02X ", output_our[j]);
+                       else {
+                               wrong++;
+                               printf("Testfall%02i falsch!\n", i);
                        }
+
+                       printf("Input(\"%s\"):\n", input[i]);
+                       hexdump(input[i], len[i]);
+
+                       printf("\nerwartet:\n");
+                       hexdump(output_ref, len[i]);
+
+                       printf("\ntatsaechliches Ergebnis:\n");
+                       hexdump(output_our, len[i]);
                        printf("\n");
                }
                else {
+                       right++;
                        printf("Testfall%02i korrekt\n", i);
                }
                free(input_our);
                free(input_ref);
        }
+       printf("========\n%2i Testfaelle sind korrekt\n%2i Testfaelle sind nach dem Nullbyte ungleich\n"
+                       "%2i Testfaelle sind falsch\n", right, neither, wrong);
        return 0;
 }