Add tests for each library's cryb_foo_version() function.

This may seem stupid, but I've found bugs in the past which would have been caught by unit tests which I didn't write because they seemed stupid.
This commit is contained in:
Dag-Erling Smørgrav 2016-09-17 16:14:00 +02:00
parent e78c0f811b
commit a36c6ba31c
9 changed files with 388 additions and 4 deletions

8
t/.gitignore vendored
View file

@ -10,9 +10,14 @@
/*.trs /*.trs
/t_adler /t_adler
/t_aes /t_aes
/t_cipher
/t_core
/t_ctype /t_ctype
/t_digest
/t_enc
/t_endian /t_endian
/t_fletcher /t_fletcher
/t_hash
/t_hmac_sha1 /t_hmac_sha1
/t_hmac_sha1_openssl /t_hmac_sha1_openssl
/t_hmac_sha224 /t_hmac_sha224
@ -23,13 +28,12 @@
/t_hmac_sha384_openssl /t_hmac_sha384_openssl
/t_hmac_sha512 /t_hmac_sha512
/t_hmac_sha512_openssl /t_hmac_sha512_openssl
/t_mac
/t_md2 /t_md2
/t_md2_rsaref
/t_md4 /t_md4
/t_md4_openssl /t_md4_openssl
/t_md5 /t_md5
/t_md5_openssl /t_md5_openssl
/t_md5_rsaref
/t_memset_s /t_memset_s
/t_mpi /t_mpi
/t_murmur3_32 /t_murmur3_32

View file

@ -35,6 +35,8 @@ TESTS =
# libcryb-cipher # libcryb-cipher
if CRYB_CIPHER if CRYB_CIPHER
TESTS += t_cipher
t_cipher_LDADD = $(libt) $(libcipher)
TESTS += t_aes t_rc4 TESTS += t_aes t_rc4
t_aes_LDADD = $(libt) $(libcipher) t_aes_LDADD = $(libt) $(libcipher)
t_rc4_LDADD = $(libt) $(libcipher) t_rc4_LDADD = $(libt) $(libcipher)
@ -42,21 +44,25 @@ endif CRYB_CIPHER
# libcryb-core # libcryb-core
if CRYB_CORE if CRYB_CORE
TESTS += t_core
t_core_LDADD = $(libt) $(libcore)
TESTS += t_ctype t_endian t_memset_s t_strlcat t_strlcmp t_strlcpy TESTS += t_ctype t_endian t_memset_s t_strlcat t_strlcmp t_strlcpy
TESTS += t_string t_wstring
EXTRA_DIST += t__string.c
t_ctype_LDADD = $(libt) $(libcore) t_ctype_LDADD = $(libt) $(libcore)
t_endian_LDADD = $(libt) $(libcore) t_endian_LDADD = $(libt) $(libcore)
t_memset_s_LDADD = $(libt) $(libcore) t_memset_s_LDADD = $(libt) $(libcore)
t_strlcat_LDADD = $(libt) $(libcore) t_strlcat_LDADD = $(libt) $(libcore)
t_strlcmp_LDADD = $(libt) $(libcore) t_strlcmp_LDADD = $(libt) $(libcore)
t_strlcpy_LDADD = $(libt) $(libcore) t_strlcpy_LDADD = $(libt) $(libcore)
TESTS += t_string t_wstring
EXTRA_DIST += t__string.c
t_string_LDADD = $(libt) $(libcore) t_string_LDADD = $(libt) $(libcore)
t_wstring_LDADD = $(libt) $(libcore) t_wstring_LDADD = $(libt) $(libcore)
endif CRYB_CORE endif CRYB_CORE
# libcryb-enc # libcryb-enc
if CRYB_ENC if CRYB_ENC
TESTS += t_enc
t_enc_LDADD = $(libt) $(libenc)
TESTS += t_rfc3986 t_rfc4648 TESTS += t_rfc3986 t_rfc4648
t_rfc3986_LDADD = $(libt) $(libenc) t_rfc3986_LDADD = $(libt) $(libenc)
t_rfc4648_LDADD = $(libt) $(libenc) t_rfc4648_LDADD = $(libt) $(libenc)
@ -64,6 +70,8 @@ endif CRYB_ENC
# libcryb-digest # libcryb-digest
if CRYB_DIGEST if CRYB_DIGEST
TESTS += t_digest
t_digest_LDADD = $(libt) $(libdigest)
TESTS += t_md2 t_md4 t_md5 TESTS += t_md2 t_md4 t_md5
t_md2_LDADD = $(libt) $(libdigest) $(RT_LIBS) t_md2_LDADD = $(libt) $(libdigest) $(RT_LIBS)
t_md4_LDADD = $(libt) $(libdigest) $(RT_LIBS) t_md4_LDADD = $(libt) $(libdigest) $(RT_LIBS)
@ -114,6 +122,8 @@ endif CRYB_DIGEST
# libcryb-hash # libcryb-hash
if CRYB_HASH if CRYB_HASH
TESTS += t_hash
t_hash_LDADD = $(libt) $(libhash)
TESTS += t_adler t_fletcher t_murmur3_32 t_pearson TESTS += t_adler t_fletcher t_murmur3_32 t_pearson
t_adler_LDADD = $(libt) $(libhash) t_adler_LDADD = $(libt) $(libhash)
t_fletcher_LDADD = $(libt) $(libhash) t_fletcher_LDADD = $(libt) $(libhash)
@ -123,6 +133,8 @@ endif CRYB_HASH
# libcryb-mac # libcryb-mac
if CRYB_MAC if CRYB_MAC
TESTS += t_mac
t_mac_LDADD = $(libt) $(libmac)
TESTS += t_hmac_sha1 t_hmac_sha224 t_hmac_sha256 t_hmac_sha384 t_hmac_sha512 TESTS += t_hmac_sha1 t_hmac_sha224 t_hmac_sha256 t_hmac_sha384 t_hmac_sha512
t_hmac_sha1_LDADD = $(libt) $(libmac) t_hmac_sha1_LDADD = $(libt) $(libmac)
t_hmac_sha224_LDADD = $(libt) $(libmac) t_hmac_sha224_LDADD = $(libt) $(libmac)

60
t/t_cipher.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/cipher.h>
#include <cryb/test.h>
static int
t_cipher_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_cipher_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_cipher_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

60
t/t_core.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/core.h>
#include <cryb/test.h>
static int
t_core_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_core_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_core_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

60
t/t_digest.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/digest.h>
#include <cryb/test.h>
static int
t_digest_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_digest_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_digest_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

60
t/t_enc.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/enc.h>
#include <cryb/test.h>
static int
t_enc_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_enc_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_enc_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

60
t/t_hash.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/hash.h>
#include <cryb/test.h>
static int
t_hash_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_hash_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_hash_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

60
t/t_mac.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "cryb/impl.h"
#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>
#include <cryb/mac.h>
#include <cryb/test.h>
static int
t_mac_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_mac_version()));
}
static int
t_prepare(int argc, char *argv[])
{
(void)argc;
(void)argv;
t_add_test(t_mac_version, NULL, "version");
return (0);
}
int
main(int argc, char *argv[])
{
t_main(t_prepare, NULL, argc, argv);
}

View file

@ -41,6 +41,13 @@
#include <cryb/test.h> #include <cryb/test.h>
static int
t_mpi_version(char **desc CRYB_UNUSED, void *arg CRYB_UNUSED)
{
return (t_compare_str(PACKAGE_VERSION, cryb_mpi_version()));
}
/*************************************************************************** /***************************************************************************
* Useful constants * Useful constants
@ -1563,6 +1570,7 @@ t_prepare(int argc, char *argv[])
(void)argc; (void)argc;
(void)argv; (void)argv;
t_add_test(t_mpi_version, NULL, "version");
/* initialize constants used in multiple test cases */ /* initialize constants used in multiple test cases */
assert(sizeof small_e == sizeof small_v); assert(sizeof small_e == sizeof small_v);