2017-02-20 20:58:19 +00:00
|
|
|
#include <stdio.h>
|
2016-11-06 01:57:36 +00:00
|
|
|
|
2017-02-20 20:58:19 +00:00
|
|
|
#include "test_multiaddr.h"
|
2016-11-08 12:57:13 +00:00
|
|
|
|
2017-02-20 20:58:19 +00:00
|
|
|
const char* names[] = {
|
|
|
|
"test_new_from_string",
|
2017-02-20 22:45:48 +00:00
|
|
|
"test_full",
|
|
|
|
"test_hex_to_var",
|
2017-03-09 23:20:56 +00:00
|
|
|
"test_int_to_hex",
|
2017-04-03 16:54:15 +00:00
|
|
|
"test_multiaddr_utils",
|
2017-04-04 03:01:46 +00:00
|
|
|
"test_multiaddr_peer_id",
|
2017-04-17 16:56:36 +00:00
|
|
|
"test_multiaddr_get_peer_id",
|
2017-07-13 23:29:02 +00:00
|
|
|
"test_multiaddr_bytes",
|
|
|
|
"test_new_like_libp2p"
|
2017-02-20 20:58:19 +00:00
|
|
|
};
|
2017-02-13 18:25:43 +00:00
|
|
|
|
2017-02-20 20:58:19 +00:00
|
|
|
int (*funcs[])(void) = {
|
|
|
|
test_new_from_string,
|
2017-02-20 22:45:48 +00:00
|
|
|
test_full,
|
|
|
|
test_hex_to_var,
|
2017-03-09 23:20:56 +00:00
|
|
|
test_int_to_hex,
|
2017-04-03 16:54:15 +00:00
|
|
|
test_multiaddr_utils,
|
2017-04-04 03:01:46 +00:00
|
|
|
test_multiaddr_peer_id,
|
2017-04-17 16:56:36 +00:00
|
|
|
test_multiaddr_get_peer_id,
|
2017-07-13 23:29:02 +00:00
|
|
|
test_multiaddr_bytes,
|
|
|
|
test_new_like_libp2p
|
2017-02-20 20:58:19 +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;
|
2016-11-08 12:57:13 +00:00
|
|
|
}
|
2017-02-20 20:58:19 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
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 {
|
|
|
|
if (tests_ran - counter > 0) {
|
|
|
|
printf("***** There were %d failed test(s) (%d successful) *****\n", tests_ran - counter, counter);
|
|
|
|
} else {
|
|
|
|
printf("All %d tests passed\n", tests_ran);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|