safeclib testsuite
This commit is contained in:
parent
7686a2ec56
commit
ecd6ba66b8
3 changed files with 118 additions and 0 deletions
28
tests/15safeclib.tests
Normal file
28
tests/15safeclib.tests
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
TESTING "Safe clib and tools" ./test-safeclib
|
||||
|
||||
TEST "Allocating 0 bytes" allocation0 <<END
|
||||
return: 134
|
||||
END
|
||||
|
||||
TEST "Allocating some memory" allocation1024 <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "Allocation error" allocationtoobig <<END
|
||||
return: 134
|
||||
END
|
||||
|
||||
|
||||
TEST "string equal check" streq <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
TEST "temporary buffers" tmpbuf <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -36,6 +36,11 @@ test_llist_SOURCES = $(tests_srcdir)/library/test-llist.c
|
|||
test_llist_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/
|
||||
test_llist_LDADD = liblumi.a -lnobugmt -lpthread -ldl -lm
|
||||
|
||||
check_PROGRAMS += test-safeclib
|
||||
test_safeclib_SOURCES = $(tests_srcdir)/library/test-safeclib.c
|
||||
test_safeclib_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/
|
||||
test_safeclib_LDADD = $(builddir)/liblumi.a -lnobugmt -lpthread -ldl -lm
|
||||
|
||||
check_PROGRAMS += test-uuid
|
||||
test_uuid_SOURCES = $(tests_srcdir)/library/test-uuid.c
|
||||
test_uuid_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/
|
||||
|
|
|
|||
85
tests/library/test-safeclib.c
Normal file
85
tests/library/test-safeclib.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#include "lib/safeclib.h"
|
||||
#include "tests/test.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
TESTS_BEGIN
|
||||
|
||||
TEST ("allocation0")
|
||||
{
|
||||
lumiera_malloc (0);
|
||||
NOTREACHED;
|
||||
}
|
||||
|
||||
TEST ("allocation1024")
|
||||
{
|
||||
void* data[1024];
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
data[i] = lumiera_malloc (1024);
|
||||
ENSURE (data);
|
||||
}
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
free (data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST ("allocationtoobig")
|
||||
{
|
||||
struct rlimit rl;
|
||||
rl.rlim_cur = 100*1024*1024;
|
||||
rl.rlim_max = 100*1024*1024;
|
||||
setrlimit (RLIMIT_AS, &rl);
|
||||
lumiera_malloc (200*1024*1024);
|
||||
NOTREACHED;
|
||||
}
|
||||
|
||||
TEST ("streq")
|
||||
{
|
||||
if (!lumiera_streq ("foo", "foo"))
|
||||
LUMIERA_DIE (TEST);
|
||||
if (!lumiera_streq (NULL, NULL))
|
||||
LUMIERA_DIE (TEST);
|
||||
if (!!lumiera_streq (NULL, "foo"))
|
||||
LUMIERA_DIE (TEST);
|
||||
if (!!lumiera_streq ("foo", NULL))
|
||||
LUMIERA_DIE (TEST);
|
||||
if (!!lumiera_streq ("foo", "bar"))
|
||||
LUMIERA_DIE (TEST);
|
||||
}
|
||||
|
||||
TEST ("tmpbuf")
|
||||
{
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
char* buf = lumiera_tmpbuf_provide (1024);
|
||||
|
||||
for (int j = 0; j < 1024; ++j)
|
||||
{
|
||||
buf[j] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TESTS_END
|
||||
Loading…
Reference in a new issue