File: base64.c

package info (click to toggle)
tarantool 1.5.2.20.g5f5d924-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,568 kB
  • ctags: 18,697
  • sloc: ansic: 109,092; sh: 21,312; cpp: 20,633; xml: 9,666; asm: 2,488; python: 2,195; java: 1,759; perl: 1,002; makefile: 679
file content (40 lines) | stat: -rw-r--r-- 977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <third_party/base64.h>
#include "unit.h"
#include <string.h>


static void
base64_test(const char *str)
{
	header();

	int len = strlen(str);
	int base64_buflen = base64_bufsize(len);
	char *base64_buf = malloc(base64_buflen);
	char *strbuf = malloc(len + 1);

	int res = base64_encode(str, len, base64_buf, base64_buflen);

	fail_unless(strlen(base64_buf) == res);

	base64_decode(base64_buf, strlen(base64_buf), strbuf, len + 1);

	fail_unless(strcmp(str, strbuf) == 0);

	free(base64_buf);
	free(strbuf);

	footer();
}

int main(int argc, char *argv[])
{
	base64_test("");
	base64_test("a");
	base64_test("Something that doesn't fit into a single line, "
	            "something that doesn't fit into a single line, "
	            "something that doesn't fit into a single line, "
	            "something that doesn't fit into a single line, "
	            "something that doesn't fit into a single line. ");
	base64_test("\001\002\003\004\005\006\253\254\255");
}