implemented sml_tree_path
This commit is contained in:
parent
cf690f09ff
commit
8bdbd61981
4 changed files with 103 additions and 13 deletions
|
@ -34,7 +34,7 @@ extern "C" {
|
|||
#define SML_PROC_PAR_VALUE_TAG_TIME 0x04
|
||||
|
||||
|
||||
// what a messy tupel
|
||||
// what a messy tupel ...
|
||||
typedef struct {
|
||||
octet_string *server_id;
|
||||
sml_time *sec_index;
|
||||
|
@ -96,8 +96,8 @@ typedef struct s_tree{
|
|||
} sml_tree;
|
||||
|
||||
typedef struct {
|
||||
octet_string **path_entries;
|
||||
int path_entries_len;
|
||||
int path_entries_len;
|
||||
octet_string **path_entries;
|
||||
} sml_tree_path;
|
||||
|
||||
// SML_TREE
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include <sml/sml_value.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
// SML_TREE_PATH
|
||||
|
||||
sml_tree_path *sml_tree_path_init() {
|
||||
sml_tree_path *tree_path = (sml_tree_path *) malloc(sizeof(sml_tree_path));
|
||||
memset(tree_path, 0, sizeof(sml_tree_path));
|
||||
|
@ -28,14 +31,38 @@ sml_tree_path *sml_tree_path_init() {
|
|||
}
|
||||
|
||||
sml_tree_path *sml_tree_path_parse(sml_buffer *buf) {
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
sml_tree_path *tree_path = sml_tree_path_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
octet_string *s;
|
||||
int elems;
|
||||
for (elems = sml_buf_get_next_length(buf); elems > 0; elems--) {
|
||||
s = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
if (s) {
|
||||
sml_tree_path_add_path_entry(tree_path, s);
|
||||
}
|
||||
}
|
||||
|
||||
return tree_path;
|
||||
|
||||
error:
|
||||
printf("error\n");
|
||||
buf->error = 1;
|
||||
sml_tree_path_free(tree_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry) {
|
||||
tree_path->path_entries_len++;
|
||||
tree_path->path_entries = (octet_string **) realloc(tree_path->path_entries, sizeof(octet_string *) * tree_path->path_entries_len);
|
||||
tree_path->path_entries = (octet_string **) realloc(tree_path->path_entries,
|
||||
sizeof(octet_string *) * tree_path->path_entries_len);
|
||||
tree_path->path_entries[tree_path->path_entries_len - 1] = entry;
|
||||
|
||||
}
|
||||
|
||||
void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) {
|
||||
|
@ -49,10 +76,21 @@ void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf) {
|
|||
}
|
||||
|
||||
void sml_tree_path_free(sml_tree_path *tree_path){
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
int i;
|
||||
if (tree_path) {
|
||||
if (tree_path->path_entries && tree_path->path_entries_len > 0) {
|
||||
for (i = 0; i < tree_path->path_entries_len; i++) {
|
||||
sml_octet_string_free(tree_path->path_entries[i]);
|
||||
}
|
||||
free(tree_path->path_entries);
|
||||
}
|
||||
free(tree_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SML_TREE
|
||||
|
||||
sml_tree *sml_tree_init(octet_string *parameter_name) {
|
||||
sml_tree *tree = (sml_tree *) malloc(sizeof(sml_tree));
|
||||
memset(tree, 0, sizeof(sml_tree));
|
||||
|
@ -78,6 +116,9 @@ void sml_tree_write(sml_tree *tree, sml_buffer *buf) {
|
|||
sml_buf_optional_write(buf);
|
||||
}
|
||||
|
||||
|
||||
// SML_PROC_PAR_VALUE
|
||||
|
||||
sml_proc_par_value *sml_proc_par_value_init() {
|
||||
sml_proc_par_value *value = (sml_proc_par_value *) malloc(sizeof(sml_proc_par_value));
|
||||
memset(value, 0, sizeof(sml_proc_par_value));
|
||||
|
@ -181,6 +222,9 @@ void sml_proc_par_value_free(sml_proc_par_value *ppv){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// SML_TUPEL_ENTRY
|
||||
|
||||
sml_tupel_entry *sml_tupel_entry_init() {
|
||||
sml_tupel_entry *tupel = (sml_tupel_entry *) malloc(sizeof(sml_tupel_entry));
|
||||
memset(tupel, 0, sizeof(sml_tupel_entry));
|
||||
|
@ -315,13 +359,10 @@ void sml_tupel_entry_free(sml_tupel_entry *tupel) {
|
|||
free(tupel);
|
||||
}
|
||||
}
|
||||
/*
|
||||
octet_string *obj_name;
|
||||
sml_unit *unit;
|
||||
i8 *scaler;
|
||||
sml_value *value;
|
||||
octet_string *value_signature;
|
||||
*/
|
||||
|
||||
|
||||
// SML_PERIOD_ENTRY
|
||||
|
||||
sml_period_entry *sml_period_entry_init() {
|
||||
sml_period_entry *period = (sml_period_entry *) malloc(sizeof(sml_period_entry));
|
||||
memset(period, 0, sizeof(sml_period_entry));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "../unity/unity_fixture.h"
|
||||
#include "test_helper.h"
|
||||
#include <sml/sml_tree.h>
|
||||
#include <sml/sml_octet_string.h>
|
||||
|
||||
TEST_GROUP(sml_tree);
|
||||
|
||||
|
@ -42,6 +43,53 @@ TEST_GROUP_RUNNER(sml_tree) {
|
|||
}
|
||||
|
||||
|
||||
TEST_GROUP(sml_tree_path);
|
||||
|
||||
TEST_SETUP(sml_tree_path) {
|
||||
buf = sml_buffer_init(512);
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(sml_tree_path) {
|
||||
sml_buffer_free(buf);
|
||||
}
|
||||
|
||||
TEST(sml_tree_path, init) {
|
||||
sml_tree_path *t = sml_tree_path_init();
|
||||
TEST_ASSERT_NOT_NULL(t);
|
||||
}
|
||||
|
||||
TEST(sml_tree_path, add_entry) {
|
||||
sml_tree_path *t = sml_tree_path_init();
|
||||
TEST_ASSERT_NOT_NULL(t);
|
||||
TEST_ASSERT_EQUAL(0, t->path_entries_len);
|
||||
sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"tree", 4));
|
||||
TEST_ASSERT_EQUAL(1, t->path_entries_len);
|
||||
}
|
||||
|
||||
TEST(sml_tree_path, parse) {
|
||||
hex2binary("720648616C6C6F0264", sml_buf_get_current_buf(buf));
|
||||
sml_tree_path *t = sml_tree_path_parse(buf);
|
||||
TEST_ASSERT_NOT_NULL(t);
|
||||
TEST_ASSERT_EQUAL(2, t->path_entries_len);
|
||||
TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[0], "48616C6C6F"));
|
||||
TEST_ASSERT_EQUAL(0, sml_octet_string_cmp_with_hex(t->path_entries[1], "64"));
|
||||
}
|
||||
|
||||
TEST(sml_tree_path, write) {
|
||||
sml_tree_path *t = sml_tree_path_init();
|
||||
sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5));
|
||||
sml_tree_path_add_path_entry(t, sml_octet_string_init((unsigned char *)"Hallo", 5));
|
||||
sml_tree_path_write(t, buf);
|
||||
expected_buf(buf, "720648616C6C6F0648616C6C6F", 13);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(sml_tree_path) {
|
||||
RUN_TEST_CASE(sml_tree_path, init);
|
||||
RUN_TEST_CASE(sml_tree_path, add_entry);
|
||||
RUN_TEST_CASE(sml_tree_path, parse);
|
||||
RUN_TEST_CASE(sml_tree_path, write);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_GROUP(sml_proc_par_value);
|
||||
|
|
|
@ -28,6 +28,7 @@ static void runAllTests() {
|
|||
RUN_TEST_GROUP(sml_list);
|
||||
RUN_TEST_GROUP(sml_time);
|
||||
RUN_TEST_GROUP(sml_tree);
|
||||
RUN_TEST_GROUP(sml_tree_path);
|
||||
RUN_TEST_GROUP(sml_proc_par_value);
|
||||
RUN_TEST_GROUP(sml_open_request);
|
||||
RUN_TEST_GROUP(sml_message);
|
||||
|
|
Loading…
Add table
Reference in a new issue