summaryrefslogtreecommitdiff
path: root/unittest/mysys/base64-t.c
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2006-06-01 12:25:47 +0200
committerunknown <serg@serg.mylan>2006-06-01 12:25:47 +0200
commit740077bdc58a20faf66fab159f56626b8acf3662 (patch)
tree445a123eb59c53a13ae718cbc126d350bc89610f /unittest/mysys/base64-t.c
parent5c27329565ef1dc72e6ca127af0a7ca000862970 (diff)
downloadmariadb-git-740077bdc58a20faf66fab159f56626b8acf3662.tar.gz
unittest:
rename *.t* to *-t* to be automake-friendly simplify Makefiles test_atomic.c: move to unittest, add GPL comment, fix warnings, convert to tap framework. configure: remove custom tests for available types, use AC_CHECK_TYPE instead x86-gcc.h: fix gcc -ansi errors while maintaining readability ignore: added *-t unittest/mysys/base64-t.c: Rename: unittest/mysys/base64.t.c -> unittest/mysys/base64-t.c unittest/mysys/bitmap-t.c: Rename: unittest/mysys/bitmap.t.c -> unittest/mysys/bitmap-t.c unittest/mytap/t/basic-t.c: Rename: unittest/mytap/t/basic.t.c -> unittest/mytap/t/basic-t.c unittest/examples/no_plan-t.c: Rename: unittest/examples/no_plan.t.c -> unittest/examples/no_plan-t.c unittest/examples/simple-t.c: Rename: unittest/examples/simple.t.c -> unittest/examples/simple-t.c unittest/examples/skip-t.c: Rename: unittest/examples/skip.t.c -> unittest/examples/skip-t.c unittest/examples/skip_all-t.c: Rename: unittest/examples/skip_all.t.c -> unittest/examples/skip_all-t.c unittest/examples/todo-t.c: Rename: unittest/examples/todo.t.c -> unittest/examples/todo-t.c BitKeeper/etc/ignore: added *-t config/ac-macros/misc.m4: remove custom AC_TRY_RUN tests for available types, use AC_CHECK_TYPE instead configure.in: remove custom tests for available types, use AC_CHECK_TYPE instead include/atomic/x86-gcc.h: fix gcc -ansi errors while maintaining readability include/my_global.h: remove custom tests for available types, use AC_CHECK_TYPE instead include/my_sys.h: add missing declaration mysys/Makefile.am: move test_atomic to unittest unittest/Makefile.am: simplifications, correct permissions in chmod unittest/README.txt: rename *.t* to *-t* to be automake-friendly unittest/examples/Makefile.am: rename *.t* to *-t* to be automake-friendly simplify Makefile unittest/mysys/Makefile.am: rename *.t* to *-t* to be automake-friendly simplify Makefile unittest/mysys/my_atomic-t.c: move mysys/test_atomic.c to unittest, add GPL comment, fix warnings, convert to tap framework. unittest/mytap/t/Makefile.am: rename *.t* to *-t* to be automake-friendly simplify Makefile unittest/unit.pl: rename *.t* to *-t* to be automake-friendly
Diffstat (limited to 'unittest/mysys/base64-t.c')
-rw-r--r--unittest/mysys/base64-t.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/unittest/mysys/base64-t.c b/unittest/mysys/base64-t.c
new file mode 100644
index 00000000000..1b4f2eb2356
--- /dev/null
+++ b/unittest/mysys/base64-t.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA */
+
+#include <base64.h>
+#include <tap.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main(void)
+{
+ int i, cmp;
+ size_t j, k, l, dst_len, needed_length;
+
+ for (i= 0; i < 500; i++)
+ {
+ /* Create source data */
+ const size_t src_len= rand() % 1000 + 1;
+
+ char * src= (char *) malloc(src_len);
+ char * s= src;
+ char * str;
+ char * dst;
+
+ for (j= 0; j<src_len; j++)
+ {
+ char c= rand();
+ *s++= c;
+ }
+
+ /* Encode */
+ needed_length= base64_needed_encoded_length(src_len);
+ str= (char *) malloc(needed_length);
+ for (k= 0; k < needed_length; k++)
+ str[k]= 0xff; /* Fill memory to check correct NUL termination */
+ ok(base64_encode(src, src_len, str) == 0,
+ "base64_encode: size %d", i);
+ ok(needed_length == strlen(str) + 1,
+ "base64_needed_encoded_length: size %d", i);
+
+ /* Decode */
+ dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
+ dst_len= base64_decode(str, strlen(str), dst);
+ ok(dst_len == src_len, "Comparing lengths");
+
+ cmp= memcmp(src, dst, src_len);
+ ok(cmp == 0, "Comparing encode-decode result");
+ if (cmp != 0)
+ {
+ char buf[80];
+ diag(" --------- src --------- --------- dst ---------");
+ for (k= 0; k<src_len; k+=8)
+ {
+ sprintf(buf, "%.4x ", (uint) k);
+ for (l=0; l<8 && k+l<src_len; l++)
+ {
+ unsigned char c= src[k+l];
+ sprintf(buf, "%.2x ", (unsigned)c);
+ }
+
+ sprintf(buf, " ");
+
+ for (l=0; l<8 && k+l<dst_len; l++)
+ {
+ unsigned char c= dst[k+l];
+ sprintf(buf, "%.2x ", (unsigned)c);
+ }
+ diag(buf);
+ }
+ diag("src length: %.8x, dst length: %.8x\n",
+ (uint) src_len, (uint) dst_len);
+ }
+ }
+ return exit_status();
+}