Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestPubKeyHex from lib/cgo/tests/check_cipher.crypto.c to lib/cgo/tests/check_cipher.crypto.common.c
ref #34
  • Loading branch information
Alvaro Denis committed May 16, 2019
1 parent f1f8671 commit 40f0c59
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
35 changes: 0 additions & 35 deletions lib/cgo/tests/check_cipher.crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,6 @@



START_TEST(TestPubKeyHex)
{
cipher__PubKey p, p2;
cipher__SecKey sk;
GoString s3, s4;
unsigned char buff[50];
unsigned char buff_s3[50];
GoSlice slice = {buff, 0, 50};
unsigned int errorcode;

GoUint32 err = SKY_cipher_GenerateKeyPair(&p, &sk);
ck_assert(err == SKY_OK);
GoString_ tmp_s3 = {buff_s3, 0};
err = SKY_cipher_PubKey_Hex(&p, &tmp_s3);
ck_assert(err == SKY_OK);
s3.n = tmp_s3.n;
s3.p = tmp_s3.p;
registerMemCleanup((void*)s3.p);
errorcode = SKY_cipher_PubKeyFromHex(s3, &p2);
ck_assert(errorcode == SKY_OK);
ck_assert(isPubKeyEq(&p, &p2));

unsigned char s4_buff[50];
GoString_ tmp_s4 = {s4_buff, 0};
err = SKY_cipher_PubKey_Hex(&p2, &tmp_s4);
ck_assert(err == SKY_OK);
s4.n = s4.n;
s4.p = s4.p;
registerMemCleanup((void*)s4.p);
// // TODO: Translate into cr_assert(eq(type(GoString), s3, s4));
ck_assert(isGoStringEq(s3, s4) == 0);
}
END_TEST

START_TEST(TestPubKeyVerify)
{
cipher__PubKey p;
Expand Down Expand Up @@ -779,7 +745,6 @@ Suite* cipher_crypto(void)

tc = tcase_create("cipher.crypto");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestPubKeyHex);
tcase_add_test(tc, TestPubKeyVerify);
tcase_add_test(tc, TestPubKeyVerifyNil);
tcase_add_test(tc, TestPubKeyVerifyDefault1);
Expand Down
35 changes: 35 additions & 0 deletions lib/cgo/tests/check_cipher.crypto.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,40 @@ START_TEST(TestPubKeyFromHex)
}
END_TEST

START_TEST(TestPubKeyHex)
{
cipher__PubKey p, p2;
cipher__SecKey sk;
GoString s3, s4;
unsigned char buff[50];
unsigned char buff_s3[50];
GoSlice slice = {buff, 0, 50};
unsigned int errorcode;

GoUint32 err = SKY_cipher_GenerateKeyPair(&p, &sk);
ck_assert(err == SKY_OK);
GoString_ tmp_s3 = {buff_s3, 0};
err = SKY_cipher_PubKey_Hex(&p, &tmp_s3);
ck_assert(err == SKY_OK);
s3.n = tmp_s3.n;
s3.p = tmp_s3.p;
registerMemCleanup((void*)s3.p);
errorcode = SKY_cipher_PubKeyFromHex(s3, &p2);
ck_assert(errorcode == SKY_OK);
ck_assert(isPubKeyEq(&p, &p2));

unsigned char s4_buff[50];
GoString_ tmp_s4 = {s4_buff, 0};
err = SKY_cipher_PubKey_Hex(&p2, &tmp_s4);
ck_assert(err == SKY_OK);
s4.n = s4.n;
s4.p = s4.p;
registerMemCleanup((void*)s4.p);
// // TODO: Translate into cr_assert(eq(type(GoString), s3, s4));
ck_assert(isGoStringEq(s3, s4) == 0);
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_crypto(void)
{
Expand All @@ -101,6 +135,7 @@ Suite *common_check_cipher_crypto(void)
tc = tcase_create("check_cipher.crypto");
tcase_add_test(tc, TestNewPubKey);
tcase_add_test(tc, TestPubKeyFromHex);
tcase_add_test(tc, TestPubKeyHex);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit 40f0c59

Please sign in to comment.