diff options
author | Katharina Fey <kookie@spacekookie.de> | 2016-08-28 14:06:22 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2019-06-04 20:21:03 +0200 |
commit | 75481c8cb77067cda4c9fb6499d72764f7e84a24 (patch) | |
tree | 40aba2846c55b001417a22389a1d9b5eea4547c7 | |
parent | bcf48a0e4bd5bbf97c22cf9f7c9494b54d1f22ff (diff) |
Fixing some errors and finishing more refactoring
Diffstat (limited to '')
-rw-r--r-- | lib/dyn_utils.c | 18 | ||||
-rw-r--r-- | test/main.c | 89 |
2 files changed, 53 insertions, 54 deletions
diff --git a/lib/dyn_utils.c b/lib/dyn_utils.c index 055623b..c6e5ac0 100644 --- a/lib/dyn_utils.c +++ b/lib/dyn_utils.c @@ -82,11 +82,11 @@ dt_err dtree_encode_json(dtree *data, char *json_data) /* Iterate through all it's children */ int i; for(i = 0; i < data->used; i++) { - dtree *child = data->payload.recursive[i]; + dtree *child = data->payload.list[i]; if(child->type == PAIR) { - dtree *key = child->payload.recursive[0]; - dtree *val = child->payload.recursive[1]; + dtree *key = child->payload.list[0]; + dtree *val = child->payload.list[1]; char kkey[1024]; parse_key_value(key, kkey, mode);; @@ -186,7 +186,7 @@ dt_err dtree_decode_json(dtree *(*data), const char *jd) { if(in_str) { } else { - if(curr_key[0] != NULL) { + if(curr_key[0] != '\0') { dtree *key, *val; dtree *rec_entry; @@ -358,14 +358,14 @@ const char *parse_value_list(dtree *value, char *buffer, char *global, short mod { if(value->used > 0) { - dt_uni_t test = value->payload.recursive[0]->type; + dt_uni_t test = value->payload.list[0]->type; if(test == LITERAL || test == NUMERIC) { fflush(stdout); int j; for(j = 0; j < value->used; j++) { - dtree *child = value->payload.recursive[j]; + dtree *child = value->payload.list[j]; char vall[1024]; parse_value_list(child, vall, global, mode, depth + 1, (i == value->used - 1) ? TRUE : FALSE); @@ -381,11 +381,11 @@ const char *parse_value_list(dtree *value, char *buffer, char *global, short mod int j; for(j = 0; j < value->used; j++) { - dtree *child = value->payload.recursive[j]; + dtree *child = value->payload.list[j]; if(child->type == PAIR) { - dtree *key = child->payload.recursive[0]; - dtree *val = child->payload.recursive[1]; + dtree *key = child->payload.list[0]; + dtree *val = child->payload.list[1]; char kkey[1024]; diff --git a/test/main.c b/test/main.c index 240de6c..e551d4f 100644 --- a/test/main.c +++ b/test/main.c @@ -1,6 +1,8 @@ #include <stdio.h> + #include <dtree/dtree.h> +#include <dtree/eztree.h> /** * A small test that creates a tree, splits the nodes @@ -26,37 +28,34 @@ int main(void) dt_err err; printf("=== libdyntree test suite ===\n"); - /* Search inside trees */ - TEST(search_for_payload()) - - /* Split and merge trees */ - TEST(split_and_merge()) - - /* Test shortcut functions */ - TEST(test_shortcut_functions()) - - /* Try to encode a structure into json */ - char json[512]; // Provide a buffer that is big enough - TEST(json_encode(json)) - - printf("\n\nJson string: %s\n", json); - - dtree *data; - dtree_decode_json(&data, json); - - /* Copy structures */ - - dtree *key, *val; - dtree *root = dtree_allocpair_new(&key, &val); - - dtree_addliteral(key, "Core Data"); - dtree_addliteral(val, "dtree is cool!"); - - dtree *root_copy; - dtree_copy(root, &root_copy); - - printf("Copy complete?\n"); - +// /* Search inside trees */ +// TEST(search_for_payload()) +// +// /* Split and merge trees */ +// TEST(split_and_merge()) +// +// /* Test shortcut functions */ +// TEST(test_shortcut_functions()) +// +// /* Try to encode a structure into json */ +// char json[512]; // Provide a buffer that is big enough +// TEST(json_encode(json)) +// +// printf("\n\nJson string: %s\n", json); +// +// dtree *data; +// dtree_decode_json(&data, json); +// dtree_free(data); + + dtree *root, *child, *key, *val; + dtree_malloc(&root); + dtree_addlist(root, &child); + dtree_addpair(child, &key, &val); + dtree_addliteral(key, "server"); + dtree_addliteral(val, "github.com"); + + dtree *copy; + dtree_copy_deep(root, ©); end: exit: @@ -135,7 +134,7 @@ dt_err search_for_payload() err = dtree_search_payload(root, &found, (void*) string, LITERAL); if(err) goto exit; - err = dtree_search_payload(root, &found, (void*) 1337, NUMERAL); + err = dtree_search_payload(root, &found, (void*) 1337, NUMERIC); if(err) goto exit; exit: @@ -221,19 +220,19 @@ dt_err test_shortcut_functions() dtree *root = dtree_allocpair_new(&key, &val); dtree_addliteral(key, "Address"); -// dtree_addliteral(val, "Berlin 10555", REAL_STRLEN("Berlin 10555")); - - dtree *list_root; - dtree **list = dtree_alloc_listlist(&list_root, 4); // Allocate 4 nodes - - int i; - for(i = 0; i < 4; i++){ - char message[32]; - sprintf(message, "Message no.%d", i); - dtree_addliteral(list[i], message); - } - - dtree_merge_trees(val, list_root); + dtree_addliteral(val, "Berlin 10555"); + +// dtree *list_root; +// dtree **list = dtree_alloc_listlist(&list_root, 4); // Allocate 4 nodes +// +// int i; +// for(i = 0; i < 4; i++){ +// char message[32]; +// sprintf(message, "Message no.%d", i); +// dtree_addliteral(list[i], message); +// } +// +// dtree_merge_trees(val, list_root); dtree_free(root); return SUCCESS; // We think |