Commits

carl douglas  committed c1bf7a0

refactor test program

  • Participants
  • Parent commits 444cc0d

Comments (0)

Files changed (1)

 #ifdef BASE64_TEST
 int main (int argc, char *argv[]) {
 
-   char *tst[] = {
-    "TWFu",
-    "cGxlYXN1cmUu",
-    "bGVhc3VyZS4=",
-    "ZWFzdXJlLg==",
-    "YXN1cmUu",
-    "c3VyZS4="
-  };
-   char *exp[] = {
-    "Man",
-    "pleasure.",
-    "leasure.",
-    "easure.",
-    "asure.",
-    "sure."
+   struct { char *enc; char *dec; } test[] = {
+     {"TWFu",         "Man"},
+     {"cGxlYXN1cmUu", "pleasure."},
+     {"bGVhc3VyZS4=", "leasure."},
+     {"ZWFzdXJlLg==", "easure."},
+     {"YXN1cmUu",     "asure."},
+     {"c3VyZS4=",     "sure."},
+     {NULL, NULL}
   };
   int i;
-  for (i = 0; i < 6; i++) {
+  int passed = 0;
+
+  for (i = 0; test[i].enc != NULL; i++) {
     char res[64];
-    base64_decode(tst[i], res);
-    printf("'%s' = '%s' : %s\n",
-        tst[i], res, strcmp(res, exp[i]) == 0 ? "PASS" : "FAIL");
+    int cmp;
+    base64_decode(test[i].enc, res);
+    cmp = strcmp(res, test[i].dec);
+    printf("'%s'\t=\t'%s'\t: %s\n",
+        test[i].enc, res, cmp == 0 ? "PASS" : "FAIL");
+    passed += (cmp == 0 ? 1 : 0);
   }
 
-  return 0;
+  return passed == i ? 0 : 1;
 }
 #endif