forked from agorise/c-ipfs
Fixed tests
This commit is contained in:
parent
8d0aa3372d
commit
b9b90014a6
4 changed files with 137 additions and 83 deletions
|
@ -29,6 +29,7 @@
|
|||
<listOptionValue builtIn="false" value=""${workspace_loc:/c-multihash/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/c-multiaddr}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lmdb}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/c-ipfs/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.581176638" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#ifndef __TEST_INIT_H__
|
||||
#define __TEST_INIT_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ipfs/cmd/ipfs/init.h"
|
||||
#include "ipfs/commands/argument.h"
|
||||
#include "ipfs/commands/request.h"
|
||||
|
|
42
test/node/test_node.h
Normal file
42
test/node/test_node.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "ipfs/node/node.h"
|
||||
|
||||
int test_node() {
|
||||
//Variables of link:
|
||||
char * name = "Alex";
|
||||
unsigned char * ahash = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";
|
||||
struct Link * mylink;
|
||||
mylink = Create_Link(name,ahash);
|
||||
printf("===================================\n" \
|
||||
"Node Link:\n" \
|
||||
" -Name: %s\n" \
|
||||
" -Size: %lu\n" \
|
||||
"\n Cid Details:\n\n" \
|
||||
" -Version: %d\n" \
|
||||
" -Codec: %c\n" \
|
||||
" -Hash: %s\n" \
|
||||
" -Hash Length: %lu\n" \
|
||||
"====================================\n" \
|
||||
, mylink->name, mylink->size, mylink->Lcid->version,mylink->Lcid->codec,mylink->Lcid->hash,mylink->Lcid->hash_length);
|
||||
//Link Two for testing purposes
|
||||
char * name2 = "Simo";
|
||||
unsigned char * ahash2 = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnSimo";
|
||||
struct Link * mylink2;
|
||||
mylink2 = Create_Link(name2,ahash2);
|
||||
//Nodes
|
||||
struct Node * Mynode;
|
||||
Mynode = N_Create_From_Link(mylink);
|
||||
mylink->name = "HAHA";//Testing for valid node creation
|
||||
printf("Node Link[0] Name: %s\nHash: %s\n",Mynode->links[0]->name, Mynode->links[0]->Lcid->hash);
|
||||
Mynode = N_Add_Link(&Mynode, mylink2, sizeof(mylink2));
|
||||
mylink2->name = "HAHA";//Testing for valid node creation
|
||||
printf("Node Link[1] Name: %s\nHash: %s\n",Mynode->links[1]->name,Mynode->links[1]->Lcid->hash);
|
||||
struct Link * ResultLink = Node_Get_Link(Mynode, "Simo");
|
||||
printf("\nResultLink: \nName: %s\nHash: %s\n", ResultLink->name, ResultLink->Lcid->hash);
|
||||
Node_Remove_Link("Simo", Mynode);
|
||||
printf("Outlinkamt: %d\n", Mynode->link_ammount);
|
||||
Free_Link(mylink);
|
||||
Free_Link(mylink2);
|
||||
Free_Link(ResultLink);
|
||||
Node_Delete(Mynode);
|
||||
return 0;
|
||||
}
|
175
test/testit.c
175
test/testit.c
|
@ -1,84 +1,93 @@
|
|||
#include "storage/test_ds_helper.h" #include "storage/test_ds_helper.h"
|
||||
#include "storage/test_datastore.h" #include "storage/test_datastore.h"
|
||||
#include "storage/test_blocks.h" #include "storage/test_blocks.h"
|
||||
+#include "ipfs/node/node.h"
|
||||
#include "cid/test_cid.h"
|
||||
#include "cmd/ipfs/test_init.h"
|
||||
#include "flatfs/test_flatfs.h"
|
||||
#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"
|
||||
|
||||
-int testit(const char* name, int (*func)(void)) { +int main(int argc, char** argv)
|
||||
- printf("Testing %s...\n", name); +{
|
||||
- int retVal = func(); + printf("XETH TESTS\n");
|
||||
- if (retVal) + //Variables of link:
|
||||
- printf("%s success!\n", name); + char * name = "Alex";
|
||||
- else + char * ahash = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";
|
||||
- printf("** Uh oh! %s failed.**\n", name); + struct Link * mylink;
|
||||
- return retVal == 0; + mylink = Create_Link(name,ahash);
|
||||
-} + printf("===================================\n" \
|
||||
- + "Node Link:\n" \
|
||||
-const char* names[] = { + " -Name: %s\n" \
|
||||
- "test_cid_new_free", + " -Size: %lu\n" \
|
||||
- "test_cid_cast_multihash", + "\n Cid Details:\n\n" \
|
||||
- "test_cid_cast_non_multihash", + " -Version: %d\n" \
|
||||
- //"test_init_new_installation", + " -Codec: %c\n" \
|
||||
- "test_repo_config_new", + " -Hash: %s\n" \
|
||||
- "test_repo_config_init", + " -Hash Length: %lu\n" \
|
||||
- "test_repo_config_write", + "====================================\n" \
|
||||
- "test_repo_config_identity_new", + , mylink->name, mylink->size, mylink->Lcid->version,mylink->Lcid->codec,mylink->Lcid->hash,mylink->Lcid->hash_length);
|
||||
- "test_repo_config_identity_private_key", + //Link Two for testing purposes
|
||||
- "test_get_init_command", + char * name2 = "Simo";
|
||||
- "test_repo_fsrepo_open_config", + char * ahash2 = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnSimo";
|
||||
- "test_flatfs_get_directory", + struct Link * mylink2;
|
||||
- "test_flatfs_get_filename", + mylink2 = Create_Link(name2,ahash2);
|
||||
- "test_flatfs_get_full_filename", + //Nodes
|
||||
- "test_ds_key_from_binary", + struct Node * Mynode;
|
||||
- "test_blocks_new", + Mynode = N_Create_From_Link(mylink,sizeof(mylink));
|
||||
- "test_repo_bootstrap_peers_init", + mylink->name = "HAHA";//Testing for valid node creation
|
||||
- "test_ipfs_datastore_put" + printf("Node Link[0] Name: %s\nHash: %s\n",Mynode->links[0]->name, Mynode->links[0]->Lcid->hash);
|
||||
-}; + Mynode = N_Add_Link(&Mynode, mylink2, sizeof(mylink2));
|
||||
- + mylink2->name = "HAHA";//Testing for valid node creation
|
||||
-int (*funcs[])(void) = { + printf("Node Link[1] Name: %s\nHash: %s\n",Mynode->links[1]->name,Mynode->links[1]->Lcid->hash);
|
||||
- test_cid_new_free, + struct Link * ResultLink = Node_Get_Link("Simo", Mynode);
|
||||
- test_cid_cast_multihash, + printf("\nResultLink: \nName: %s\nHash: %s\n", ResultLink->name, ResultLink->Lcid->hash);
|
||||
- test_cid_cast_non_multihash, + Node_Remove_Link("Simo", Mynode);
|
||||
- //test_init_new_installation, + printf("Outlinkamt: %d\n", Mynode->link_ammount);
|
||||
- test_repo_config_new, + Free_Link(mylink);
|
||||
- test_repo_config_init, + Free_Link(mylink2);
|
||||
- test_repo_config_write, + Free_Link(ResultLink);
|
||||
- test_repo_config_identity_new, + Node_Delete(Mynode);
|
||||
- test_repo_config_identity_private_key, + return 0;
|
||||
- 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
|
||||
-};
|
||||
-
|
||||
-/**
|
||||
- * run 1 test or run all
|
||||
- */
|
||||
-int main(int argc, char** argv) {
|
||||
- int counter = 0;
|
||||
- char* test_wanted;
|
||||
- int only_one = 0;
|
||||
- if(argc > 1) {
|
||||
- only_one = 1;
|
||||
- test_wanted = argv[1];
|
||||
- }
|
||||
- for (int i = 0; i < sizeof(funcs) / sizeof(funcs[0]); i++) {
|
||||
- if (only_one && strcmp(names[i], test_wanted) == 0)
|
||||
- counter += testit(names[i], funcs[i]);
|
||||
- else
|
||||
- if (!only_one)
|
||||
- counter += testit(names[i], funcs[i]);
|
||||
-
|
||||
- }
|
||||
-
|
||||
- if (counter > 0) {
|
||||
- printf("***** There were %d failed test(s) *****\n", counter);
|
||||
- } else {
|
||||
- printf("All tests passed\n");
|
||||
- }
|
||||
- return 1;
|
||||
}
|
||||
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_init_new_installation",
|
||||
"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",
|
||||
"test_node"
|
||||
};
|
||||
|
||||
int (*funcs[])(void) = {
|
||||
test_cid_new_free,
|
||||
test_cid_cast_multihash,
|
||||
test_cid_cast_non_multihash,
|
||||
//test_init_new_installation,
|
||||
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,
|
||||
test_node
|
||||
};
|
||||
|
||||
/**
|
||||
* run 1 test or run all
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
int counter = 0;
|
||||
char* test_wanted;
|
||||
int only_one = 0;
|
||||
if(argc > 1) {
|
||||
only_one = 1;
|
||||
test_wanted = argv[1];
|
||||
}
|
||||
for (int i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
|
||||
if (only_one && strcmp(names[i], test_wanted) == 0)
|
||||
counter += testit(names[i], funcs[i]);
|
||||
else
|
||||
if (!only_one)
|
||||
counter += testit(names[i], funcs[i]);
|
||||
|
||||
}
|
||||
|
||||
if (counter > 0) {
|
||||
printf("***** There were %d failed test(s) *****\n", counter);
|
||||
} else {
|
||||
printf("All tests passed\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue