From 1f3d18d49ff481981b712e980396965091feb98e Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Mon, 13 May 2019 22:42:21 -0400 Subject: [PATCH] refactor move TestAddSHA256 from lib/cgo/tests/check_cipher.hash.c to lib/cgo/tests/check_cipher.hash.common.c ref #34 --- lib/cgo/tests/check_cipher.hash.c | 25 ------------ lib/cgo/tests/check_cipher.hash.common.c | 50 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 lib/cgo/tests/check_cipher.hash.common.c diff --git a/lib/cgo/tests/check_cipher.hash.c b/lib/cgo/tests/check_cipher.hash.c index 9fad756de..e58e80811 100644 --- a/lib/cgo/tests/check_cipher.hash.c +++ b/lib/cgo/tests/check_cipher.hash.c @@ -250,31 +250,6 @@ START_TEST(TestDoubleSHA256) } END_TEST -START_TEST(TestAddSHA256) -{ - - unsigned char bbuff[130]; - GoSlice b = {bbuff, 0, 130}; - randBytes(&b, 128); - cipher__SHA256 h; - SKY_cipher_SumSHA256(b, &h); - - unsigned char cbuff[130]; - GoSlice c = {cbuff, 0, 130}; - randBytes(&c, 64); - cipher__SHA256 i; - SKY_cipher_SumSHA256(c, &i); - - cipher__SHA256 add; - cipher__SHA256 tmp; - - SKY_cipher_AddSHA256(&h, &i, &add); - ck_assert(!isU8Eq(add, tmp, 32)); - ck_assert(!isU8Eq(add, h, 32)); - ck_assert(!isU8Eq(add, i, 32)); -} -END_TEST - START_TEST(TestXorSHA256) { diff --git a/lib/cgo/tests/check_cipher.hash.common.c b/lib/cgo/tests/check_cipher.hash.common.c new file mode 100644 index 000000000..077bac3ac --- /dev/null +++ b/lib/cgo/tests/check_cipher.hash.common.c @@ -0,0 +1,50 @@ +#include +#include + +#include +#include "libskycoin.h" +#include "skyerrors.h" +#include "skyassert.h" +#include "skystring.h" +#include "skytest.h" + +// TestSuite(cipher_hash, .init = setup, .fini = teardown); + +START_TEST(TestAddSHA256) +{ + + unsigned char bbuff[130]; + GoSlice b = {bbuff, 0, 130}; + randBytes(&b, 128); + cipher__SHA256 h; + SKY_cipher_SumSHA256(b, &h); + + unsigned char cbuff[130]; + GoSlice c = {cbuff, 0, 130}; + randBytes(&c, 64); + cipher__SHA256 i; + SKY_cipher_SumSHA256(c, &i); + + cipher__SHA256 add; + cipher__SHA256 tmp; + + SKY_cipher_AddSHA256(&h, &i, &add); + ck_assert(!isU8Eq(add, tmp, 32)); + ck_assert(!isU8Eq(add, h, 32)); + ck_assert(!isU8Eq(add, i, 32)); +} +END_TEST + +// define test suite and cases +Suite *common_check_cipher_hash(void) +{ + Suite *s = suite_create("Load common check_cipher.hash"); + TCase *tc; + + tc = tcase_create("check_cipher.hash"); + tcase_add_test(tc, TestAddSHA256); + suite_add_tcase(s, tc); + tcase_set_timeout(tc, 150); + + return s; +}