-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move TestNewPubKey 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
9038eeb
commit 6dc0acc
Showing
5 changed files
with
71 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <check.h> | ||
#include "libskycoin.h" | ||
#include "skyerrors.h" | ||
#include "skyassert.h" | ||
#include "skystring.h" | ||
#include "skytest.h" | ||
|
||
START_TEST(TestNewPubKey) | ||
{ | ||
unsigned char buff[101]; | ||
GoSlice slice; | ||
cipher__PubKey pk, pk2; | ||
cipher__SecKey sk; | ||
|
||
slice.data = buff; | ||
slice.cap = 101; | ||
|
||
randBytes(&slice, 31); | ||
slice.len = 31; | ||
unsigned int errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode == SKY_ErrInvalidLengthPubKey, "31 random bytes"); | ||
|
||
randBytes(&slice, 32); | ||
errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode == SKY_ErrInvalidLengthPubKey, "32 random bytes"); | ||
|
||
randBytes(&slice, 34); | ||
errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode == SKY_ErrInvalidLengthPubKey, "34 random bytes"); | ||
|
||
slice.len = 0; | ||
errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode == SKY_ErrInvalidLengthPubKey, "0 random bytes"); | ||
|
||
randBytes(&slice, 100); | ||
errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode == SKY_ErrInvalidLengthPubKey, "100 random bytes"); | ||
|
||
randBytes(&slice, 33); | ||
errorcode = SKY_cipher_NewPubKey(slice, &pk); | ||
ck_assert_msg(errorcode != SKY_OK, "33 random bytes"); | ||
|
||
SKY_cipher_GenerateKeyPair(&pk, &sk); | ||
GoSlice buffer = {pk, sizeof(pk), sizeof(pk)}; | ||
errorcode = SKY_cipher_NewPubKey(buffer, &pk2); | ||
ck_assert_msg(errorcode == SKY_OK); | ||
|
||
ck_assert(isPubKeyEq(&pk, &pk2)); | ||
} | ||
END_TEST | ||
|
||
// define test suite and cases | ||
Suite *common_check_cipher_crypto(void) | ||
{ | ||
Suite *s = suite_create("Load common check_cipher.crypto"); | ||
TCase *tc; | ||
|
||
tc = tcase_create("check_cipher.crypto"); | ||
tcase_add_test(tc, TestNewPubKey); | ||
suite_add_tcase(s, tc); | ||
tcase_set_timeout(tc, 150); | ||
|
||
return s; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters