Add tests for sodium_*() functions.

This commit is contained in:
Frank Denis 2013-04-25 22:37:15 -07:00
parent 5eb4d489ea
commit 4c31bb5ef1
8 changed files with 75 additions and 0 deletions

3
.gitignore vendored
View File

@ -80,6 +80,9 @@ test/default/secretbox2
test/default/secretbox7
test/default/secretbox8
test/default/shorthash
test/default/sodium_core
test/default/sodium_utils
test/default/sodium_version
test/default/stream
test/default/stream2
test/default/stream3

View File

@ -32,6 +32,9 @@ EXTRA_DIST = \
secretbox7.exp \
secretbox8.exp \
shorthash.exp \
sodium_core.exp \
sodium_utils.exp \
sodium_version.exp \
stream.exp \
stream2.exp \
stream3.exp \
@ -76,6 +79,9 @@ TESTS_TARGETS = \
secretbox7 \
secretbox8 \
shorthash \
sodium_core \
sodium_utils \
sodium_version \
stream \
stream2 \
stream3 \
@ -181,6 +187,15 @@ secretbox8_LDADD = $(TESTS_LDADD)
shorthash_SOURCE = cmptest.h shorthash.c
shorthash_LDADD = $(TESTS_LDADD)
sodium_core_SOURCE = cmptest.h sodium_core.c
sodium_core_LDADD = $(TESTS_LDADD)
sodium_utils_SOURCE = cmptest.h sodium_utils.c
sodium_utils_LDADD = $(TESTS_LDADD)
sodium_version_SOURCE = cmptest.h sodium_version.c
sodium_version_LDADD = $(TESTS_LDADD)
stream_SOURCE = cmptest.h stream.c
stream_LDADD = $(TESTS_LDADD)

View File

@ -0,0 +1,11 @@
#include <stdio.h>
#define TEST_NAME "sodium_core"
#include "cmptest.h"
int main(void)
{
printf ("%d\n", sodium_init());
return 0;
}

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <string.h>
#define TEST_NAME "sodium_utils"
#include "cmptest.h"
int main(void)
{
char buf1[1000];
char buf2[1000];
randombytes(buf1, sizeof buf1);
memcpy(buf2, buf1, sizeof buf2);
printf ("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
sodium_memzero(buf1, 0U);
printf ("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
sodium_memzero(buf1, sizeof buf1 / 2);
printf ("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
printf ("%d\n", sodium_memcmp(buf1, buf2, 0U));
sodium_memzero(buf2, sizeof buf2 / 2);
printf ("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
return 0;
}

View File

@ -0,0 +1,5 @@
0
0
255
0
0

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#define TEST_NAME "sodium_version"
#include "cmptest.h"
int main(void)
{
printf ("%d\n", sodium_version_string() != NULL);
printf ("%d\n", sodium_library_version_major() > 0);
printf ("%d\n", sodium_library_version_minor() > 0);
return 0;
}

View File

@ -0,0 +1,3 @@
1
1
1