Commit 3f9e35d3 authored by unknown's avatar unknown

WL#3206 (Adding unit tests):

Moving mytap library into unittest/
Adding 'test' target to make and run unit tests.
Minor fixes.


unittest/mytap/Doxyfile:
  mvdir
unittest/mytap/t/basic.t.c:
  mvdir
unittest/mytap/tap.c:
  mvdir
unittest/mytap/tap.h:
  mvdir
Makefile.am:
  Correcting after moving mytap/
configure.in:
  Correcting after moving mytap/
unittest/Makefile.am:
  Adding 'test' target to build and execute unit tests.
unittest/examples/Makefile.am:
  Correcting after moving mytap/
unittest/mysys/Makefile.am:
  Correcting after moving mytap/
unittest/mysys/bitmap.t.c:
  Adding copyright notice.
unittest/mytap/Makefile.am:
  Correcting after moving mytap/
unittest/mytap/t/Makefile.am:
  Correcting after moving mytap/
unittest/mysys/base64.t.c:
  New BitKeeper file ``unittest/mysys/base64.t.c''
parent b0d2b658
......@@ -29,7 +29,7 @@ SUBDIRS = . include @docs_dirs@ @zlib_dir@ @yassl_dir@ \
@mysql_se_plugins@ \
netware @libmysqld_dirs@ \
@bench_dirs@ support-files @tools_dirs@ \
plugin mytap unittest
plugin unittest
DIST_SUBDIRS = . include @docs_dirs@ zlib \
@readline_topdir@ sql-common \
......@@ -39,7 +39,7 @@ DIST_SUBDIRS = . include @docs_dirs@ zlib \
@man_dirs@ tests SSL\
BUILD netware os2 @libmysqld_dirs@\
@bench_dirs@ support-files server-tools tools \
plugin mytap unittest
plugin unittest
# Run these targets before any others, also make part of clean target,
# to make sure we create new links after a clean.
......
......@@ -2599,7 +2599,8 @@ AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS)
# Output results
AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
mytap/Makefile mytap/t/Makefile unittest/Makefile dnl
unittest/Makefile dnl
unittest/mytap/Makefile unittest/mytap/t/Makefile dnl
unittest/mysys/Makefile unittest/examples/Makefile dnl
strings/Makefile regex/Makefile storage/Makefile storage/heap/Makefile dnl
storage/myisam/Makefile storage/myisammrg/Makefile dnl
......
SUBDIRS = mysys examples
SUBDIRS = mytap . mysys examples
.PHONY: mytap mysys examples test
noinst_SCRIPTS = unit
test: mytap mysys examples
./unit run $^
mytap:
cd mytap && $(MAKE)
mysys:
cd mysys && $(MAKE)
examples:
cd examples && $(MAKE)
unit: unit.pl
cp $< $@
chmod +x $@
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include
AM_CPPFLAGS += -I$(top_builddir)/mytap
AM_CPPFLAGS += -I$(top_builddir)/unittest/mytap
AM_LDFLAGS = -L$(top_builddir)/mytap
AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
AM_CFLAGS = -Wall -ansi -pedantic
AM_CFLAGS = -W -Wall -ansi -pedantic
LDADD = -lmytap
......
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include
AM_CPPFLAGS += -I$(top_builddir)/mytap
AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include
AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_builddir)/unittest/mytap
AM_CFLAGS = -Wall -ansi -pedantic
AM_LDFLAGS = -L$(top_builddir)/unittest/mytap -L$(top_builddir)/mysys
AM_LDFLAGS += -L$(top_builddir)/strings -L$(top_builddir)/dbug
AM_LDFLAGS = -L$(top_builddir)/mytap -L$(top_builddir)/mysys
AM_LDFLAGS += -L$(top_builddir)/strings
LDADD = -lmytap -lmysys -lmystrings -ldbug
LDADD = -lmytap -lmysys -lmystrings
noinst_PROGRAMS = bitmap.t
noinst_PROGRAMS = bitmap.t base64.t
bitmap_t_SOURCES = bitmap.t.c
base64_t_SOURCES = base64.t.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; 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;
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");
int cmp= memcmp(src, dst, src_len);
ok(cmp == 0, "Comparing encode-decode result");
if (cmp != 0)
{
diag(" --------- src --------- --------- dst ---------");
char buf[80];
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();
}
/* Copyright (C) 2006 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
This test was copied from the unit test inside the
mysys/my_bitmap.c file and adapted by Mats Kindahl to use the mytap
library.
*/
#include <tap.h>
#include <my_global.h>
#include "my_bitmap.h"
#include <string.h>
#include <my_bitmap.h>
static void bitmap_print(MY_BITMAP *map)
{
......
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
AM_CPPFLAGS += -I$(top_builddir)/mytap
noinst_LIBRARIES = libmytap.a
noinst_HEADERS = tap.h
......
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include -I$(top_builddir)/mytap
AM_CPPFLAGS = -I$(srcdir) -I$(top_builddir)/include
AM_CPPFLAGS += -I$(srcdir)/..
AM_LDFLAGS = -L$(srcdir)/..
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment