Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestSHA256Set 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 e3bef74 commit 00a0099
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
31 changes: 0 additions & 31 deletions lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,6 @@ START_TEST(TestRipemd160Set)
}
END_TEST

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

randBytes(&slice, 33);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 100);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 31);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 0);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 32);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_OK);
ck_assert(isU8Eq(h, slice.data, 32));
}
END_TEST

START_TEST(TestSHA256FromHex)
{
unsigned int error;
Expand Down Expand Up @@ -225,7 +195,6 @@ Suite* cipher_hash(void)
tc = tcase_create("cipher.hash");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestRipemd160Set);
tcase_add_test(tc, TestSHA256Set);
tcase_add_test(tc, TestSHA256FromHex);
tcase_add_test(tc, TestDoubleSHA256);
tcase_add_test(tc, TestXorSHA256);
Expand Down
31 changes: 31 additions & 0 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,44 @@ START_TEST(TestSHA256Hex)
}
END_TEST

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

randBytes(&slice, 33);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 100);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 31);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 0);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthSHA256);

randBytes(&slice, 32);
error = SKY_cipher_SHA256_Set(&h, slice);
ck_assert(error == SKY_OK);
ck_assert(isU8Eq(h, slice.data, 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, TestSHA256Set);
tcase_add_test(tc, TestAddSHA256);
tcase_add_test(tc, TestHashRipemd160);
tcase_add_test(tc, TestSHA256KnownValue);
Expand Down

0 comments on commit 00a0099

Please sign in to comment.