[svn-commits] dvossel: trunk r250235 - /trunk/tests/test_utils.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 2 17:38:32 CST 2010


Author: dvossel
Date: Tue Mar  2 17:38:29 2010
New Revision: 250235

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=250235
Log:
base64 unit test

Modified:
    trunk/tests/test_utils.c

Modified: trunk/tests/test_utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_utils.c?view=diff&rev=250235&r1=250234&r2=250235
==============================================================================
--- trunk/tests/test_utils.c (original)
+++ trunk/tests/test_utils.c Tue Mar  2 17:38:29 2010
@@ -185,11 +185,64 @@
 	return res;
 }
 
+AST_TEST_DEFINE(base64_test)
+{
+	static const struct {
+		const char *input;
+		const char *decoded;
+	} tests[] = {
+		{ "giraffe",
+			"Z2lyYWZmZQ==" },
+		{ "platypus",
+			"cGxhdHlwdXM=" },
+		{ "ParastratiosphecomyiaStratiosphecomyioides",
+			"UGFyYXN0cmF0aW9zcGhlY29teWlhU3RyYXRpb3NwaGVjb215aW9pZGVz" },
+	};
+	int i;
+	enum ast_test_result_state res = AST_TEST_PASS;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "base64_test";
+		info->category = "main/utils/";
+		info->summary = "base64 test";
+		info->description = "This test exercises the base64 conversions.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+
+	for (i = 0; i < ARRAY_LEN(tests); i++) {
+		char tmp[64];
+		ast_base64encode(tmp, (unsigned char *)tests[i].input, strlen(tests[i].input), sizeof(tmp));
+		if (strcasecmp(tmp, tests[i].decoded)) {
+			ast_test_status_update(test,
+					"input: '%s'  base64 output: '%s'  expected base64 output: '%s'\n",
+					tests[i].input, tmp, tests[i].decoded);
+			res = AST_TEST_FAIL;
+		}
+
+		memset(tmp, 0, sizeof(tmp));
+		ast_base64decode((unsigned char *) tmp, tests[i].decoded, (sizeof(tmp) - 1));
+		if (strcasecmp(tmp, tests[i].input)) {
+			ast_test_status_update(test,
+					"base64 input: '%s'  output: '%s'  expected output: '%s'\n",
+					tests[i].decoded, tmp, tests[i].input);
+			res = AST_TEST_FAIL;
+		}
+	}
+
+	return res;
+}
+
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(uri_encode_decode_test);
 	AST_TEST_UNREGISTER(md5_test);
 	AST_TEST_UNREGISTER(sha1_test);
+	AST_TEST_UNREGISTER(base64_test);
 	return 0;
 }
 
@@ -198,6 +251,7 @@
 	AST_TEST_REGISTER(uri_encode_decode_test);
 	AST_TEST_REGISTER(md5_test);
 	AST_TEST_REGISTER(sha1_test);
+	AST_TEST_REGISTER(base64_test);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the svn-commits mailing list