Split isc_crc64 API test into separate unit test and convert it to cmocka

This commit is contained in:
Ondřej Surý
2018-10-11 18:20:17 +02:00
parent 7fc78e7cad
commit 13888c93a4
4 changed files with 120 additions and 71 deletions

View File

@@ -24,7 +24,6 @@
#include <isc/hex.h>
#include <isc/region.h>
#include <isc/crc64.h>
#include <isc/util.h>
#include <isc/print.h>
#include <isc/string.h>
@@ -40,71 +39,6 @@ typedef struct hash_testcase {
int repeats;
} hash_testcase_t;
/* CRC64 Test */
ATF_TC(isc_crc64);
ATF_TC_HEAD(isc_crc64, tc) {
atf_tc_set_md_var(tc, "descr", "64-bit cyclic redundancy check");
}
ATF_TC_BODY(isc_crc64, tc) {
uint64_t crc;
int i;
UNUSED(tc);
hash_testcase_t testcases[] = {
{
TEST_INPUT(""),
"0000000000000000", 1
},
{
TEST_INPUT("a"),
"CE73F427ACC0A99A", 1
},
{
TEST_INPUT("abc"),
"048B813AF9F49702", 1
},
{
TEST_INPUT("message digest"),
"5273F9EA7A357BF4", 1
},
{
TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
"59F079F9218BAAA1", 1
},
{
TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
"nopqrstuvwxyz0123456789"),
"A36DA8F71E78B6FB", 1
},
{
TEST_INPUT("123456789012345678901234567890123456789"
"01234567890123456789012345678901234567890"),
"81E5EB73C8E7874A", 1
},
{ NULL, 0, NULL, 1 }
};
hash_testcase_t *testcase = testcases;
while (testcase->input != NULL && testcase->result != NULL) {
char str[19];
isc_crc64_init(&crc);
for(i = 0; i < testcase->repeats; i++) {
isc_crc64_update(&crc,
(const uint8_t *) testcase->input,
testcase->input_len);
}
isc_crc64_final(&crc);
snprintf(str, sizeof(str),
"0x%016" PRIX64, crc);
ATF_CHECK_STREQ(str, testcase->result);
testcase++;
}
}
ATF_TC(isc_hash_function);
ATF_TC_HEAD(isc_hash_function, tc) {
atf_tc_set_md_var(tc, "descr", "Hash function test");
@@ -227,14 +161,12 @@ ATF_TC_BODY(isc_hash_initializer, tc) {
*/
ATF_TP_ADD_TCS(tp) {
/*
* Tests of hash functions, including isc_hash and the
* various cryptographic hashes.
* Tests of isc_hash functions.
*/
ATF_TP_ADD_TC(tp, isc_hash_function);
ATF_TP_ADD_TC(tp, isc_hash_function_reverse);
ATF_TP_ADD_TC(tp, isc_hash_initializer);
ATF_TP_ADD_TC(tp, isc_crc64);
return (atf_no_error());
}