c-ipfs/test/testit.c

123 lines
3 KiB
C
Raw Normal View History

2016-12-05 11:13:20 +00:00
#include "cid/test_cid.h"
#include "cmd/ipfs/test_init.h"
#include "flatfs/test_flatfs.h"
2016-12-05 15:50:17 +00:00
#include "merkledag/test_merkledag.h"
2016-12-05 11:13:20 +00:00
#include "node/test_node.h"
#include "repo/test_repo_bootstrap_peers.h"
#include "repo/test_repo_config.h"
#include "repo/test_repo_fsrepo.h"
#include "repo/test_repo_identity.h"
#include "storage/test_ds_helper.h"
#include "storage/test_datastore.h"
#include "storage/test_blocks.h"
2016-12-04 20:13:57 +00:00
2016-12-05 11:13:20 +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 == 0;
}
const char* names[] = {
"test_cid_new_free",
"test_cid_cast_multihash",
"test_cid_cast_non_multihash",
"test_cid_protobuf_encode_decode",
2016-12-05 11:13:20 +00:00
"test_repo_config_new",
"test_repo_config_init",
"test_repo_config_write",
"test_repo_config_identity_new",
"test_repo_config_identity_private_key",
"test_get_init_command",
"test_repo_fsrepo_open_config",
"test_flatfs_get_directory",
"test_flatfs_get_filename",
"test_flatfs_get_full_filename",
"test_ds_key_from_binary",
"test_blocks_new",
"test_repo_bootstrap_peers_init",
"test_ipfs_datastore_put",
2016-12-05 15:50:17 +00:00
"test_node",
"test_node_link_encode_decode",
"test_node_encode_decode",
"test_merkledag_add_data",
2016-12-12 11:27:06 +00:00
"test_merkledag_get_data",
"test_merkledag_add_node_with_links"
2016-12-05 11:13:20 +00:00
};
int (*funcs[])(void) = {
test_cid_new_free,
test_cid_cast_multihash,
test_cid_cast_non_multihash,
test_cid_protobuf_encode_decode,
2016-12-05 11:13:20 +00:00
test_repo_config_new,
test_repo_config_init,
test_repo_config_write,
test_repo_config_identity_new,
test_repo_config_identity_private_key,
test_get_init_command,
test_repo_fsrepo_open_config,
test_flatfs_get_directory,
test_flatfs_get_filename,
test_flatfs_get_full_filename,
test_ds_key_from_binary,
test_blocks_new,
test_repo_bootstrap_peers_init,
test_ipfs_datastore_put,
2016-12-05 15:50:17 +00:00
test_node,
test_node_link_encode_decode,
test_node_encode_decode,
test_merkledag_add_data,
2016-12-12 11:27:06 +00:00
test_merkledag_get_data,
test_merkledag_add_node_with_links
2016-12-05 11:13:20 +00:00
};
/**
* run 1 test or run all
*/
int main(int argc, char** argv) {
int counter = 0;
2016-12-05 18:11:22 +00:00
int tests_ran = 0;
2016-12-05 11:13:20 +00:00
char* test_wanted;
int only_one = 0;
if(argc > 1) {
only_one = 1;
2016-12-05 18:11:22 +00:00
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];
2016-12-05 11:13:20 +00:00
}
2016-12-05 18:11:22 +00:00
int array_length = sizeof(funcs) / sizeof(funcs[0]);
for (int i = 0; i < array_length; i++) {
if (only_one) {
char* currName = names[i];
if (strcmp(currName, test_wanted) == 0) {
tests_ran++;
counter += testit(names[i], funcs[i]);
}
2016-12-05 18:11:22 +00:00
}
2016-12-05 11:13:20 +00:00
else
2016-12-05 18:11:22 +00:00
if (!only_one) {
tests_ran++;
2016-12-05 11:13:20 +00:00
counter += testit(names[i], funcs[i]);
2016-12-05 18:11:22 +00:00
}
2016-12-05 11:13:20 +00:00
}
2016-12-05 18:11:22 +00:00
if (tests_ran == 0)
printf("***** No tests found *****\n");
else {
if (counter > 0) {
printf("***** There were %d failed test(s) *****\n", counter);
} else {
printf("All %d tests passed\n", tests_ran);
}
2016-12-05 11:13:20 +00:00
}
return 1;
}