Start adding tests

This commit is contained in:
Frank Denis 2013-01-20 14:03:05 -08:00
parent 688aad67ef
commit c04d4816fb
4 changed files with 39 additions and 3 deletions

View File

@ -6,4 +6,5 @@ EXTRA_DIST = \
autogen.sh
SUBDIRS = \
src
src \
test

View File

@ -201,6 +201,7 @@ AC_CONFIG_FILES([Makefile
src/Makefile
src/libsodium/Makefile
src/libsodium/include/Makefile
src/libsodium/include/sodium/version.h])
src/libsodium/include/sodium/version.h
test/Makefile
])
AC_OUTPUT

18
test/Makefile.am Normal file
View File

@ -0,0 +1,18 @@
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/src/libsodium/include
TESTS_TARGETS = \
test-randombytes
check_PROGRAMS = $(TESTS_TARGETS)
TESTS = $(TESTS_TARGETS)
TESTS_LDADD = $(top_srcdir)/src/libsodium/libsodium.la
test_randombytes_SOURCES = test-randombytes.c
test_randombytes_LDADD = $(TESTS_LDADD)
verify: check

16
test/test-randombytes.c Normal file
View File

@ -0,0 +1,16 @@
#include "sodium/randombytes.h"
unsigned char x[65536];
unsigned long long freq[256];
int main(void)
{
unsigned long long i;
randombytes(x,sizeof x);
for (i = 0;i < 256;++i) freq[i] = 0;
for (i = 0;i < sizeof x;++i) ++freq[255 & (int) x[i]];
for (i = 0;i < 256;++i) if (!freq[i]) return 111;
return 0;
}