mariadb/unittest/mysys/base64-t.c
unknown 0c9a3e597d Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
Fixed compiler warnings, errors and link errors
Fixed new bug on Solaris with gethrtime()
Added --debug-check option to all mysql clients to print errors and memory leaks
Added --debug-info to all clients. This now works as --debug-check but also prints memory and cpu usage


BUILD/compile-solaris-sparc-debug:
  Remove old cpu options
client/client_priv.h:
  Added OPT_DBUG_CHECK
client/mysql.cc:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysql_upgrade.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqladmin.cc:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqlbinlog.cc:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqlcheck.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqldump.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqlimport.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqlshow.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqlslap.c:
  --debug-info now prints memory usage 
  Added --debug-check
client/mysqltest.c:
  --debug-info now prints memory usage 
  Added --debug-check
include/my_sys.h:
  Added extra option to TERMINATE to not print statistics
libmysql/libmysql.c:
  Fixed compiler warning
mysql-test/mysql-test-run.pl:
  --debug-info -> --debug-check to not print memory usage
mysys/my_getsystime.c:
  Moved fast time calculation to my_micro_time_and_time()
  Fixed bug in previous push related to HAVE_GETHRTIME
mysys/my_init.c:
  Print not freed memory in my_end() if MY_CHECK_ERROR is given
mysys/my_static.c:
  Cleanup
mysys/safemalloc.c:
  Added extra option to TERMINATE to not print statistics
sql/item_xmlfunc.cc:
  Fixed compiler warning
sql/sql_test.cc:
  Fixed TERMINATE() call
unittest/mysys/base64-t.c:
  Fixed link error
unittest/mysys/bitmap-t.c:
  Fixed link error
unittest/mysys/my_atomic-t.c:
  Fixed link error
2007-08-01 22:59:05 +03:00

94 lines
2.6 KiB
C

/* 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; version 2 of the License.
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 <my_global.h>
#include <my_sys.h>
#include <base64.h>
#include <tap.h>
#include <string.h>
#define BASE64_LOOP_COUNT 500
#define BASE64_ROWS 4 /* Number of ok(..) */
int
main(void)
{
int i, cmp;
size_t j, k, l, dst_len, needed_length;
MY_INIT("base64-t");
plan(BASE64_LOOP_COUNT * BASE64_ROWS);
for (i= 0; i < BASE64_LOOP_COUNT; 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, NULL);
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();
}