2016-11-03 16:15:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-03-07 00:03:04 +00:00
|
|
|
#include "crypto/test_aes.h"
|
2016-11-07 20:11:58 +00:00
|
|
|
#include "crypto/test_rsa.h"
|
|
|
|
#include "crypto/test_base58.h"
|
2016-12-01 18:05:14 +00:00
|
|
|
#include "crypto/test_base32.h"
|
2017-02-02 19:10:12 +00:00
|
|
|
#include "crypto/test_key.h"
|
2017-02-06 22:11:22 +00:00
|
|
|
#include "crypto/test_ephemeral.h"
|
2017-03-09 05:12:04 +00:00
|
|
|
#include "crypto/test_mac.h"
|
2017-02-02 19:10:12 +00:00
|
|
|
#include "test_secio.h"
|
2016-11-14 01:55:11 +00:00
|
|
|
#include "test_mbedtls.h"
|
2017-02-02 19:10:12 +00:00
|
|
|
#include "test_multistream.h"
|
2017-02-13 18:26:41 +00:00
|
|
|
#include "test_conn.h"
|
2017-02-20 12:08:53 +00:00
|
|
|
#include "test_record.h"
|
2017-02-20 23:53:20 +00:00
|
|
|
#include "test_peer.h"
|
2016-11-07 20:11:58 +00:00
|
|
|
|
2017-01-23 17:07:48 +00:00
|
|
|
const char* names[] = {
|
|
|
|
"test_public_der_to_private_der",
|
|
|
|
"test_mbedtls_varint_128_binary",
|
|
|
|
"test_mbedtls_varint_128_string",
|
|
|
|
"test_crypto_rsa_private_key_der",
|
2017-02-06 22:11:22 +00:00
|
|
|
"test_crypto_rsa_signing",
|
2017-01-23 17:07:48 +00:00
|
|
|
"test_crypto_rsa_public_key_to_peer_id",
|
|
|
|
"test_crypto_x509_der_to_private2",
|
|
|
|
"test_crypto_x509_der_to_private",
|
2017-03-09 05:12:04 +00:00
|
|
|
"test_crypto_hashing_sha256",
|
2017-01-23 17:07:48 +00:00
|
|
|
//"test_multihash_encode",
|
|
|
|
//"test_multihash_decode",
|
|
|
|
//"test_multihash_base58_encode_decode",
|
|
|
|
//"test_multihash_base58_decode",
|
|
|
|
//"test_multihash_size",
|
|
|
|
"test_base58_encode_decode",
|
|
|
|
"test_base58_size",
|
|
|
|
"test_base58_max_size",
|
|
|
|
"test_base58_peer_address",
|
|
|
|
//"test_mbedtls_pk_write_key_der",
|
|
|
|
//"test_crypto_rsa_sign",
|
2017-02-02 19:10:12 +00:00
|
|
|
"test_crypto_encoding_base32_encode",
|
|
|
|
"test_protobuf_private_key",
|
2017-02-23 16:15:48 +00:00
|
|
|
"test_secio_handshake",
|
2017-03-07 00:03:04 +00:00
|
|
|
"test_secio_encrypt_decrypt",
|
|
|
|
"test_secio_exchange_protobuf_encode",
|
2017-02-02 23:27:57 +00:00
|
|
|
"test_multistream_connect",
|
2017-02-06 22:11:22 +00:00
|
|
|
"test_multistream_get_list",
|
2017-02-13 18:26:41 +00:00
|
|
|
"test_ephemeral_key_generate",
|
2017-03-07 00:03:04 +00:00
|
|
|
"test_ephemeral_key_sign",
|
2017-02-13 22:41:31 +00:00
|
|
|
"test_dialer_new",
|
2017-02-20 12:08:53 +00:00
|
|
|
"test_dialer_dial",
|
2017-03-02 21:14:52 +00:00
|
|
|
"test_dialer_dial_multistream",
|
2017-02-20 12:08:53 +00:00
|
|
|
"test_record_protobuf",
|
2017-02-20 13:19:22 +00:00
|
|
|
"test_record_make_put_record",
|
2017-02-20 14:31:59 +00:00
|
|
|
"test_record_peer_protobuf",
|
2017-02-20 23:53:20 +00:00
|
|
|
"test_record_message_protobuf",
|
|
|
|
"test_peer",
|
2017-03-07 00:03:04 +00:00
|
|
|
"test_peerstore",
|
|
|
|
"test_aes"
|
2017-01-23 17:07:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int (*funcs[])(void) = {
|
|
|
|
test_public_der_to_private_der,
|
|
|
|
test_mbedtls_varint_128_binary,
|
|
|
|
test_mbedtls_varint_128_string,
|
|
|
|
test_crypto_rsa_private_key_der,
|
2017-02-06 22:11:22 +00:00
|
|
|
test_crypto_rsa_signing,
|
2017-01-23 17:07:48 +00:00
|
|
|
test_crypto_rsa_public_key_to_peer_id,
|
|
|
|
test_crypto_x509_der_to_private2,
|
|
|
|
test_crypto_x509_der_to_private,
|
2017-03-09 05:12:04 +00:00
|
|
|
test_crypto_hashing_sha256,
|
2017-01-23 17:07:48 +00:00
|
|
|
//test_multihash_encode,
|
|
|
|
//test_multihash_decode,
|
|
|
|
//test_multihash_base58_encode_decode,
|
|
|
|
//test_multihash_base58_decode,
|
|
|
|
//test_multihash_size,
|
|
|
|
test_base58_encode_decode,
|
|
|
|
test_base58_size,
|
|
|
|
test_base58_max_size,
|
|
|
|
test_base58_peer_address,
|
|
|
|
//test_mbedtls_pk_write_key_der,
|
|
|
|
//test_crypto_rsa_sign,
|
2017-02-02 19:10:12 +00:00
|
|
|
test_crypto_encoding_base32_encode,
|
|
|
|
test_protobuf_private_key,
|
2017-02-23 16:15:48 +00:00
|
|
|
test_secio_handshake,
|
2017-03-07 00:03:04 +00:00
|
|
|
test_secio_encrypt_decrypt,
|
|
|
|
test_secio_exchange_protobuf_encode,
|
2017-02-02 23:27:57 +00:00
|
|
|
test_multistream_connect,
|
2017-02-06 22:11:22 +00:00
|
|
|
test_multistream_get_list,
|
|
|
|
test_ephemeral_key_generate,
|
2017-03-07 00:03:04 +00:00
|
|
|
test_ephemeral_key_sign,
|
2017-02-13 22:41:31 +00:00
|
|
|
test_dialer_new,
|
2017-02-20 12:08:53 +00:00
|
|
|
test_dialer_dial,
|
2017-03-02 21:14:52 +00:00
|
|
|
test_dialer_dial_multistream,
|
2017-02-20 12:08:53 +00:00
|
|
|
test_record_protobuf,
|
2017-02-20 13:19:22 +00:00
|
|
|
test_record_make_put_record,
|
2017-02-20 14:31:59 +00:00
|
|
|
test_record_peer_protobuf,
|
2017-02-20 23:53:20 +00:00
|
|
|
test_record_message_protobuf,
|
|
|
|
test_peer,
|
2017-03-07 00:03:04 +00:00
|
|
|
test_peerstore,
|
|
|
|
test_aes
|
2017-01-23 17:07:48 +00:00
|
|
|
};
|
|
|
|
|
2016-11-03 14:18:32 +00:00
|
|
|
int testit(const char* name, int (*func)(void)) {
|
|
|
|
printf("Testing %s...\n", name);
|
|
|
|
int retVal = func();
|
|
|
|
if (retVal)
|
|
|
|
printf("%s success!\n", name);
|
|
|
|
else
|
|
|
|
printf("** Uh oh! %s failed.**\n", name);
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2017-01-23 17:07:48 +00:00
|
|
|
int counter = 0;
|
|
|
|
int tests_ran = 0;
|
|
|
|
char* test_wanted;
|
|
|
|
int only_one = 0;
|
|
|
|
if(argc > 1) {
|
|
|
|
only_one = 1;
|
|
|
|
if (argv[1][0] == '\'') { // some shells put quotes around arguments
|
|
|
|
argv[1][strlen(argv[1])-1] = 0;
|
|
|
|
test_wanted = &(argv[1][1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
test_wanted = argv[1];
|
|
|
|
}
|
|
|
|
int array_length = sizeof(funcs) / sizeof(funcs[0]);
|
|
|
|
int array2_length = sizeof(names) / sizeof(names[0]);
|
|
|
|
if (array_length != array2_length) {
|
|
|
|
printf("Test arrays are not of the same length. Funcs: %d, Names: %d\n", array_length, array2_length);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < array_length; i++) {
|
|
|
|
if (only_one) {
|
|
|
|
const char* currName = names[i];
|
|
|
|
if (strcmp(currName, test_wanted) == 0) {
|
|
|
|
tests_ran++;
|
|
|
|
counter += testit(names[i], funcs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!only_one) {
|
|
|
|
tests_ran++;
|
|
|
|
counter += testit(names[i], funcs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tests_ran == 0)
|
|
|
|
printf("***** No tests found *****\n");
|
|
|
|
else {
|
2017-02-02 19:10:12 +00:00
|
|
|
if (tests_ran - counter > 0) {
|
|
|
|
printf("***** There were %d failed test(s) (%d successful) *****\n", tests_ran - counter, counter);
|
2017-01-23 17:07:48 +00:00
|
|
|
} else {
|
|
|
|
printf("All %d tests passed\n", tests_ran);
|
|
|
|
}
|
|
|
|
}
|
2016-11-03 14:18:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|