about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJoe DF <joedf@live.ca>2015-06-12 01:28:32 -0400
committerJoe DF <joedf@live.ca>2015-06-12 01:28:32 -0400
commit3fb8ce591c046465a0dab56ada3bbea98e66c7ef (patch)
treec0c468b111c61d81625fbc43da87b30e6124bcc7
parent71f83ced19dee4f28b604ae60c6cf21f2f603feb (diff)
downloadbase64-3fb8ce591c046465a0dab56ada3bbea98e66c7ef.tar.gz
Updated test.c and b64_decodef() works
-rw-r--r--base64.h9
-rw-r--r--test.c51
2 files changed, 44 insertions, 16 deletions
diff --git a/base64.h b/base64.h
index d7a1072..22b00fb 100644
--- a/base64.h
+++ b/base64.h
@@ -2,7 +2,7 @@
 	base64.c - by Joe DF (joedf@ahkscript.org)
 	Released under the MIT License
 	
-	Revision: 2015-06-12 00:02:32
+	Revision: 2015-06-12 01:26:51
 	
 	Thank you for inspiration:
 	http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode
@@ -36,4 +36,9 @@ unsigned int b64_decode(const unsigned char* in, unsigned int in_len, unsigned i
 // file-version b64_encode
 // Input : filenames
 // returns size of output
-unsigned int b64_encodef(char *InFile, char *OutFile);
\ No newline at end of file
+unsigned int b64_encodef(char *InFile, char *OutFile);
+
+// file-version b64_decode
+// Input : filenames
+// returns size of output
+unsigned int b64_decodef(char *InFile, char *OutFile);
\ No newline at end of file
diff --git a/test.c b/test.c
index 757beaa..6eee388 100644
--- a/test.c
+++ b/test.c
@@ -21,14 +21,21 @@
 
 #define NELEMS(x)  (sizeof(x) / sizeof(x[0]))
 
-#define STATUS(x)  ((x>0)?"[PASS]":"[FAIL]")
+//#define STATUS(x)  ((x>0)?"[PASS]":"[FAIL]")
+#define STATUS(x)  score(x)
+#define PERCENT(a,b)  ((float)((float)a/(float)b)*100)
 
 int test_b64_encode();
 int test_b64_decode();
 int test_b64_encodef();
 int test_b64_decodef();
 int hexputs(const int* data, int len);
+int hexprint(const int* data, int len);
 int compare(int *a, int *b, int l);
+char *score(int x);
+
+int testScore = 0;
+int testTotal = 0;
 
 int main() {
 	
@@ -45,7 +52,7 @@ int main() {
 	printf("%s\n",STATUS(test_b64_encodef()));
 	puts("\nTesting test_b64_decodef() ...\n");
 	printf("%s\n",STATUS(test_b64_decodef()));
-	puts("\n[END]");
+	printf("\n[END] Test score: %g%% (%d/%d)\n",PERCENT(testScore,testTotal),testScore,testTotal);
 
 	return 0;
 }
@@ -146,7 +153,7 @@ int test_b64_encodef() {
 	fclose(pFile);
 	
 	j = b64_encodef("B64_TEST01A.tmp","B64_TEST01B.tmp");
-	//remove("B64_TEST01A.tmp");
+	remove("B64_TEST01A.tmp");
 	
 	if (!j)
 		return 0;
@@ -158,7 +165,7 @@ int test_b64_encodef() {
 	char *out = malloc(j+1);
 	fgets(out,j+1,pFile);
 	fclose(pFile);
-	//remove("B64_TEST01B.tmp");
+	remove("B64_TEST01B.tmp");
 	printf("Comparing \"%s\" to \"%s\" : ",STRING_B,out);
 	if (strcmp(STRING_B,out)==0)
 		return 1;
@@ -179,7 +186,7 @@ int test_b64_decodef() {
 	fclose(pFile);
 	
 	j = b64_decodef("B64_TEST02A.tmp","B64_TEST02B.tmp");
-	//remove("B64_TEST02A.tmp");
+	remove("B64_TEST02A.tmp");
 	
 	if (!j)
 		return 0;
@@ -188,26 +195,36 @@ int test_b64_decodef() {
 	if (pFile==NULL)
 		return 0;
 	
-	char *out = malloc(j+1);
-	fgets(out,j+1,pFile);
+	int c, l=0, out[j+1];
+	while(c!=EOF) {
+		c=fgetc(pFile);
+		if (c==EOF)
+		break;
+		out[l++] = c;
+	}
 	fclose(pFile);
-	//remove("B64_TEST02B.tmp");
-	printf("Comparing \"%s\" with : ",HEXSTR_B); hexputs((int*)out,j);
-
+	remove("B64_TEST02B.tmp");
+	printf("Comparing \"%s\" to \"",HEXSTR_B); hexprint(out,j); printf("\" : ");
 	int r_b[] = HEXNUM_B;
-
-	if (compare((int*)HEXSTR_B,(int*)out,NELEMS(r_b)))
+	if (compare(r_b,out,j))
 		return 1;
 	
 	return 0;
 }
 
 int hexputs(const int* data, int len) {
+	hexprint(data,len);
+	printf("\n");
+	return 0;
+}
+
+int hexprint(const int* data, int len) {
 	int i;
 	for (i=0;i<len;i++) {
-		printf("0x%X ",data[i]);
+		printf("0x%X",data[i]);
+		if (i<len-1)
+			printf(" ");
 	}
-	printf("\n");
 	return 0;
 }
 
@@ -218,4 +235,10 @@ int compare(int *a, int *b, int l) {
 			return 0;
 	}
 	return 1;
+}
+
+char *score(int x) {
+	testScore+=(!!x)*1;
+	testTotal+=1;
+	return ((x>0)?"[PASS]":"[FAIL]");
 }
\ No newline at end of file