Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestSumSHA256 from lib/cgo/tests/check_cipher.hash.c to lib/cgo/tests/check_cipher.hash.common.c
ref #34
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent ffcec79 commit b0ae131
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
28 changes: 0 additions & 28 deletions lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

// TestSuite(cipher_hash, .init = setup, .fini = teardown);

void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256)
{
SKY_cipher_SumSHA256(bytes, sha256);
}

START_TEST(TestRipemd160Set)
{
cipher__Ripemd160 h;
Expand Down Expand Up @@ -105,26 +100,6 @@ START_TEST(TestSHA256Hex)
}
END_TEST

START_TEST(TestSumSHA256)
{
unsigned char bbuff[257], cbuff[257];
GoSlice b = {bbuff, 0, 257};
cipher__SHA256 h1;
randBytes(&b, 256);
SKY_cipher_SumSHA256(b, &h1);
cipher__SHA256 tmp;
ck_assert(!isU8Eq(h1, tmp, 32));
GoSlice c = {cbuff, 0, 257};
randBytes(&c, 256);
cipher__SHA256 h2;
SKY_cipher_SumSHA256(c, &h2);
ck_assert(!isU8Eq(h1, tmp, 32));
cipher__SHA256 tmp_h2;
freshSumSHA256(c, &tmp_h2);
ck_assert(isU8Eq(h2, tmp_h2, 32));
}
END_TEST

START_TEST(TestSHA256FromHex)
{
unsigned int error;
Expand Down Expand Up @@ -277,12 +252,9 @@ Suite* cipher_hash(void)

tc = tcase_create("cipher.hash");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestHashRipemd160);
tcase_add_test(tc, TestRipemd160Set);
tcase_add_test(tc, TestSHA256Set);
tcase_add_test(tc, TestSHA256Hex);
tcase_add_test(tc, TestSHA256KnownValue);
tcase_add_test(tc, TestSumSHA256);
tcase_add_test(tc, TestSHA256FromHex);
tcase_add_test(tc, TestDoubleSHA256);
tcase_add_test(tc, TestXorSHA256);
Expand Down
26 changes: 26 additions & 0 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ void freshSumRipemd160(GoSlice bytes, cipher__Ripemd160* rp160)
SKY_cipher_HashRipemd160(bytes, rp160);
}

void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256)
{
SKY_cipher_SumSHA256(bytes, sha256);
}

START_TEST(TestAddSHA256)
{

Expand Down Expand Up @@ -108,6 +113,26 @@ START_TEST(TestSHA256KnownValue)
}
END_TEST

START_TEST(TestSumSHA256)
{
unsigned char bbuff[257], cbuff[257];
GoSlice b = {bbuff, 0, 257};
cipher__SHA256 h1;
randBytes(&b, 256);
SKY_cipher_SumSHA256(b, &h1);
cipher__SHA256 tmp;
ck_assert(!isU8Eq(h1, tmp, 32));
GoSlice c = {cbuff, 0, 257};
randBytes(&c, 256);
cipher__SHA256 h2;
SKY_cipher_SumSHA256(c, &h2);
ck_assert(!isU8Eq(h1, tmp, 32));
cipher__SHA256 tmp_h2;
freshSumSHA256(c, &tmp_h2);
ck_assert(isU8Eq(h2, tmp_h2, 32));
}
END_TEST

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

Expand Down

0 comments on commit b0ae131

Please sign in to comment.