5 extern unsigned char *asmb(unsigned char *a);
7 unsigned char *asmb_ref(unsigned char *s)
10 for (i=0; s[i]; i++) {
12 c += (c>='A' && c<='Z') ? 'a'-'A' : 0;
18 static char ascii(char s) {
19 if(s < 0x20) return '.';
20 if(s > 0x7E) return '.';
24 static void hexdump(void *d, int len) {
27 data = (unsigned char*)d;
28 for (off=0; off<len; off += 16) {
29 printf("\t%08x ",off);
31 if((i+off)>=len) printf(" ");
32 else printf("%02x ",data[off+i]);
36 if((i+off)>=len) printf(" ");
37 else printf("%c",ascii(data[off+i]));
42 #define NUM_TESTCASES 18
45 char *input[NUM_TESTCASES]={
53 "ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH",
59 "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC",
60 "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf",
65 int len[NUM_TESTCASES] = {
85 char *output_our, *output_ref;
86 char *input_our, *input_ref;
87 int right=0, wrong=0, neither=0, i;
89 for(i = 0; i < NUM_TESTCASES; i++) {
90 input_our = (char *) malloc (len[i]);
91 input_ref = (char *) malloc (len[i]);
93 (void) memcpy(input_our, input[i], len[i]+1);
94 (void) memcpy(input_ref, input[i], len[i]+1);
96 output_our = (char *) asmb((unsigned char *) input_our);
97 output_ref = (char *) asmb_ref((unsigned char *) input_ref);
99 if(memcmp(output_our,output_ref, len[i]) != 0) {
100 if(strncmp(output_our, output_ref, len[i]) == 0) {
102 printf("Testfall%02i nach Nullbyte ungleich\n", i);
106 printf("Testfall%02i falsch!\n", i);
109 printf("Input(\"%s\"):\n", input[i]);
110 hexdump(input[i], len[i]);
112 printf("\nerwartet:\n");
113 hexdump(output_ref, len[i]);
115 printf("\ntatsaechliches Ergebnis:\n");
116 hexdump(output_our, len[i]);
121 printf("Testfall%02i korrekt\n", i);
126 printf("========\n%2i Testfaelle sind korrekt\n%2i Testfaelle sind nach dem Nullbyte ungleich\n"
127 "%2i Testfaelle sind falsch\n", right, neither, wrong);