Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestSHA256Hex from lib/cgo/tests/check_cipher.hash.c to lib/cgo/tests/check_cipher.hash.common.c
ref skycoin#34
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent b0ae131 commit e3bef74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 0 additions & 29 deletions lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,6 @@ START_TEST(TestSHA256Set)
}
END_TEST

START_TEST(TestSHA256Hex)
{
cipher__SHA256 h;
unsigned char buff[101];
GoSlice slice = {buff, 0, 101};
int error;

memset(&h, 0, sizeof(h));
randBytes(&slice, 32);
SKY_cipher_SHA256_Set(&h, slice);
GoString_ s;

SKY_cipher_SHA256_Hex(&h, &s);
registerMemCleanup((void*)s.p);

cipher__SHA256 h2;
GoString tmpS = {s.p, s.n};
error = SKY_cipher_SHA256FromHex(tmpS, &h2);
ck_assert(error == SKY_OK);
ck_assert(isU8Eq(h, h2, 32));

GoString_ s2;
SKY_cipher_SHA256_Hex(&h2, &s2);
registerMemCleanup((void*)s2.p);
ck_assert_str_eq(s.p, s2.p);
}
END_TEST

START_TEST(TestSHA256FromHex)
{
unsigned int error;
Expand Down Expand Up @@ -254,7 +226,6 @@ Suite* cipher_hash(void)
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestRipemd160Set);
tcase_add_test(tc, TestSHA256Set);
tcase_add_test(tc, TestSHA256Hex);
tcase_add_test(tc, TestSHA256FromHex);
tcase_add_test(tc, TestDoubleSHA256);
tcase_add_test(tc, TestXorSHA256);
Expand Down
29 changes: 29 additions & 0 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ START_TEST(TestSumSHA256)
}
END_TEST

START_TEST(TestSHA256Hex)
{
cipher__SHA256 h;
unsigned char buff[101];
GoSlice slice = {buff, 0, 101};
int error;

memset(&h, 0, sizeof(h));
randBytes(&slice, 32);
SKY_cipher_SHA256_Set(&h, slice);
GoString_ s;

SKY_cipher_SHA256_Hex(&h, &s);
registerMemCleanup((void*)s.p);

cipher__SHA256 h2;
GoString tmpS = {s.p, s.n};
error = SKY_cipher_SHA256FromHex(tmpS, &h2);
ck_assert(error == SKY_OK);
ck_assert(isU8Eq(h, h2, 32));

GoString_ s2;
SKY_cipher_SHA256_Hex(&h2, &s2);
registerMemCleanup((void*)s2.p);
ck_assert_str_eq(s.p, s2.p);
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_hash(void)
{
Expand All @@ -144,6 +172,7 @@ Suite *common_check_cipher_hash(void)
tcase_add_test(tc, TestHashRipemd160);
tcase_add_test(tc, TestSHA256KnownValue);
tcase_add_test(tc, TestSumSHA256);
tcase_add_test(tc, TestSHA256Hex);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit e3bef74

Please sign in to comment.