Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
moce TestHashRipemd160 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 66fd014 commit 1e8eedf
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -10,40 +10,11 @@

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

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(TestHashRipemd160)
{
cipher__Ripemd160 tmp;
cipher__Ripemd160 r;
cipher__Ripemd160 r2;
unsigned char buff[257];
GoSlice slice = {buff, 0, 257};

randBytes(&slice, 128);
SKY_cipher_HashRipemd160(slice, &tmp);
randBytes(&slice, 160);
SKY_cipher_HashRipemd160(slice, &r);
ck_assert(!isU8Eq(tmp, r, sizeof(cipher__Ripemd160)));

unsigned char buff1[257];
GoSlice b = {buff1, 0, 257};
randBytes(&b, 256);
SKY_cipher_HashRipemd160(b, &r2);
ck_assert(!isU8Eq(tmp, r2, sizeof(cipher__Ripemd160)));
freshSumRipemd160(b, &tmp);
ck_assert(isU8Eq(tmp, r2, sizeof(cipher__Ripemd160)));
}
END_TEST

START_TEST(TestRipemd160Set)
{
cipher__Ripemd160 h;
Expand Down
30 changes: 30 additions & 0 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

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

void freshSumRipemd160(GoSlice bytes, cipher__Ripemd160* rp160)
{
SKY_cipher_HashRipemd160(bytes, rp160);
}

START_TEST(TestAddSHA256)
{

Expand All @@ -35,6 +40,30 @@ START_TEST(TestAddSHA256)
}
END_TEST

START_TEST(TestHashRipemd160)
{
cipher__Ripemd160 tmp;
cipher__Ripemd160 r;
cipher__Ripemd160 r2;
unsigned char buff[257];
GoSlice slice = {buff, 0, 257};

randBytes(&slice, 128);
SKY_cipher_HashRipemd160(slice, &tmp);
randBytes(&slice, 160);
SKY_cipher_HashRipemd160(slice, &r);
ck_assert(!isU8Eq(tmp, r, sizeof(cipher__Ripemd160)));

unsigned char buff1[257];
GoSlice b = {buff1, 0, 257};
randBytes(&b, 256);
SKY_cipher_HashRipemd160(b, &r2);
ck_assert(!isU8Eq(tmp, r2, sizeof(cipher__Ripemd160)));
freshSumRipemd160(b, &tmp);
ck_assert(isU8Eq(tmp, r2, sizeof(cipher__Ripemd160)));
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_hash(void)
{
Expand All @@ -43,6 +72,7 @@ Suite *common_check_cipher_hash(void)

tc = tcase_create("check_cipher.hash");
tcase_add_test(tc, TestAddSHA256);
tcase_add_test(tc, TestHashRipemd160);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit 1e8eedf

Please sign in to comment.