65 #include <amxc/amxc.h>
66 #include <amxp/amxp_signal.h>
67 #include <amxp/amxp_slot.h>
74 #include <amxc/amxc_macros.h>
308 const char* names[] = {
310 "another_normal_alias",
315 "textbefore[brackets]",
318 "injectionattack\" || \"a\" == \"b",
319 "injectionattack\" || \"a\" == \"b' || 'a' == 'b",
320 "diversion_brackets",
321 "[diversion_brackets]",
327 assert_int_equal(
amxd_param_new(¶m,
"Alias", AMXC_VAR_ID_CSTRING), 0);
334 for(
size_t i = 0; i <
sizeof(names) /
sizeof(names)[0]; i++) {
337 const char* name = names[i];
345 assert_non_null(instance);
346 printf(
"Instance name = %s\n", name);
352 assert_non_null(retrieved_instance);
353 assert_ptr_equal(retrieved_instance, instance);
356 for(
size_t i = 0; i <
sizeof(names) /
sizeof(names)[0]; i++) {
358 const char* name = names[i];
360 printf(
"Instance name = %s\n", name);
366 assert_non_null(retrieved_instance);
370 for(
size_t i = 0; i <
sizeof(names) /
sizeof(names)[0]; i++) {
372 const char* name = names[i];
374 printf(
"Instance name = %s\n", name);
379 retrieved_instance =
amxd_dm_findf(&
dm,
"MyRoot.MyTemplate.[%s].", name);
380 if(retrieved_instance == NULL) {
381 retrieved_instance =
amxd_dm_findf(&
dm,
"MyRoot.MyTemplate.[Alias == '%s'].", name);
383 if(retrieved_instance == NULL) {
384 retrieved_instance =
amxd_dm_findf(&
dm,
"MyRoot.MyTemplate.[Alias == \"%s\"].", name);
387 assert_non_null(retrieved_instance);
510 amxc_llist_init(&paths);
523 assert_string_equal(path,
"parent");
527 assert_string_equal(path,
"parent.child");
531 assert_string_equal(path,
"child");
539 assert_string_equal(path,
"parent.child.sub-child");
543 assert_string_equal(path,
"parent.child.{i}");
547 assert_string_equal(path,
"parent.child.{i}.");
551 assert_string_equal(path,
"parent.child.{i}.");
555 assert_string_equal(path,
"parent.child.sub-child.");
559 assert_string_equal(path,
"parent.child.[sub-child]");
562 assert_string_equal(path,
"parent.child.[1]");
566 assert_string_equal(path,
"parent.child.sub-child");
569 assert_string_equal(path,
"parent.child.1");
573 assert_string_equal(path,
"parent\\.child\\.sub-child");
576 assert_string_equal(path,
"parent\\.child\\.1");
580 assert_string_equal(path,
"parent\\.child\\.\\[sub-child\\]");
583 assert_string_equal(path,
"parent\\.child\\.\\[1\\]");
587 assert_ptr_equal(path, NULL);
591 assert_ptr_not_equal(instance_child2, NULL);
592 assert_ptr_not_equal(instance_child2, child2);
595 assert_string_equal(path,
"parent.child.[sub-child].sub-child");
599 assert_non_null(child2);
604 assert_non_null(child1);
606 assert_non_null(child2);
610 amxc_llist_clean(&paths, amxc_string_list_it_free);
621 "parent.child_2.child_2_1",
622 "parent.child_2.child_2_2",
623 "parent.child_2.[instance_1]",
624 "parent.child_2.[instance_1].child_2_1",
625 "parent.child_2.[instance_1].child_2_2",
626 "parent.child_2.[instance_2]",
627 "parent.child_2.[instance_2].child_2_1",
628 "parent.child_2.[instance_2].child_2_2",
632 UNUSED int32_t depth,
635 assert_ptr_equal(priv, NULL);
649 "parent.child_2.[instance_2]",
656 UNUSED int32_t depth,
659 assert_ptr_equal(priv, NULL);
682 printf(
"Current parent = %s\n", parent->
name);
689 printf(
"Current parent = %s\n", parent->
name);
711 "parent.child_2.instance_1",
712 "parent.child_2.instance_1.child_2_1",
713 "parent.child_2.instance_1.child_2_2",
714 "parent.child_2.instance_2",
715 "parent.child_2.instance_2.child_2_1",
716 "parent.child_2.instance_2.child_2_2",
720 UNUSED int32_t depth,
722 assert_ptr_equal(priv, NULL);
738 UNUSED int32_t depth,
740 assert_ptr_equal(priv, NULL);
745 UNUSED int32_t depth,
748 assert_ptr_equal(priv, NULL);
771 printf(
"Current parent = %s\n", parent->
name);
778 printf(
"Current parent = %s\n", parent->
name);
801 UNUSED int32_t depth,
804 assert_ptr_equal(priv, NULL);
818 "parent.child_2.[2]",
823 UNUSED int32_t depth,
826 assert_ptr_equal(priv, NULL);
849 printf(
"Current parent = %s\n", parent->
name);
856 printf(
"Current parent = %s\n", parent->
name);
Ambiorix Data Model API header file.
amxd_object_t * amxd_dm_findf(amxd_dm_t *const dm, const char *abs_path,...) __attribute__((format(printf
Ambiorix Data Model API header file.
amxd_status_t amxd_param_new(amxd_param_t **param, const char *name, const uint32_t type)
amxd_status_t amxd_param_set_attr(amxd_param_t *param, const amxd_pattr_id_t attr, const bool enable)
enum _amxd_status amxd_status_t
@ amxd_status_invalid_name
#define AMXD_OBJECT_SUPPORTED
Path format flag - adds {i} as placeholder for an instance object.
#define AMXD_OBJECT_INDEXED
Name and path format flag - use index for instance objects.
#define AMXD_OBJECT_REGEXP
Path format flag - create path that can be used as regular expression.
#define AMXD_OBJECT_NAMED
Name and path format flag - default behavior, use name for instance objects.
#define AMXD_OBJECT_EXTENDED
Path format flag - set name or index of instrance objects between '[' and ']'.
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
amxd_object_t * amxd_dm_get_root(amxd_dm_t *const dm)
Fetches the root object of the data model.
amxd_status_t amxd_dm_add_root_object(amxd_dm_t *const dm, amxd_object_t *const object)
Adds an object to the root of the data model.
amxd_status_t amxd_dm_init(amxd_dm_t *dm)
Initializes a data model structure.
void amxd_dm_clean(amxd_dm_t *dm)
Cleans a data model structure.
amxd_object_t amxd_status_t amxd_status_t char * amxd_object_get_path(const amxd_object_t *object, const uint32_t flags)
Get the full path of the object.
bool amxd_object_is_child_of(const amxd_object_t *const child, const amxd_object_t *const parent)
Checks if the child object is in the hierarchical tree of the parent object.
amxd_object_t * amxd_object_get_parent(const amxd_object_t *const object)
Get the parent object.
amxd_object_t * amxd_object_get_child(const amxd_object_t *object, const char *name)
Get a child of the object.
amxd_object_t * amxd_object_get_root(const amxd_object_t *const object)
Get the data model root.
char * amxd_object_get_rel_path(const amxd_object_t *child, const amxd_object_t *parent, const uint32_t flags)
Get the relative path of the object.
void amxd_object_hierarchy_walk(amxd_object_t *const object, const amxd_direction_t direction, amxd_object_filter_fn_t filter, amxd_object_cb_fn_t cb, int32_t depth, void *priv)
Iterates over all objects in the data model tree.
amxd_object_t * amxd_object_findf(amxd_object_t *object, const char *rel_path,...) __attribute__((format(printf
Find an object in the data model tree, starting from an object.
amxd_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
amxd_object_t amxd_status_t amxd_object_resolve_pathf(amxd_object_t *object, amxc_llist_t *paths, const char *rel_path,...) __attribute__((format(printf
Resolves a search path into a list of matching object paths.
amxd_object_t * amxd_object_get(const amxd_object_t *object, const char *name)
Get an instance or child of an object.
amxd_status_t amxd_object_add_object(amxd_object_t *const parent, amxd_object_t *const child)
Adds an object in the data model tree.
amxd_object_t * amxd_object_get_instance(const amxd_object_t *object, const char *name, uint32_t index)
Get an instance of the template object.
amxd_status_t amxd_object_add_param(amxd_object_t *const object, amxd_param_t *const param)
Adds a parameter definition to an object.
amxd_status_t amxd_object_new_instance(amxd_object_t **object, amxd_object_t *templ, const char *name, uint32_t index, amxc_var_t *values)
Data model object constructor function.
amxd_status_t amxd_object_new(amxd_object_t **object, const amxd_object_type_t type, const char *name)
Data model object constructor function.
void amxd_object_delete(amxd_object_t **object)
Invokes the destroy handler(s) of the object.
const char * amxd_object_get_name(const amxd_object_t *const object, const uint32_t flags)
Get the name of the object (or index as a string for instance objects)
static amxd_status_t status
void test_amxd_object_walk_depth(UNUSED void **state)
void test_amxd_object_get_dm(UNUSED void **state)
static void check_path_up(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
void test_amxd_object_add_object_invalid_args(UNUSED void **state)
void test_amxd_object_add_object(UNUSED void **state)
static bool no_root_objects(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
static char * expected_paths_down_depth[]
static void check_path_down_filtered(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
void test_amxd_object_walk_filtered(UNUSED void **state)
static char * expected_paths_up_depth[]
static void check_path_down_depth(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
void test_amxd_object_findf(UNUSED void **state)
static char * expected_paths_up[]
void test_amxd_object_get(UNUSED void **state)
void test_amxd_object_walk(UNUSED void **state)
static bool no_tempate_child_objects(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
static char * expected_paths_down_filtered[]
static void check_path_up_depth(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
static void check_path_down(amxd_object_t *const object, UNUSED int32_t depth, void *priv)
void test_amxd_object_find(UNUSED void **state)
void test_amxd_object_get_path(UNUSED void **state)
void test_amxd_object_is_child_of(UNUSED void **state)
void test_amxd_object_walk_invalid_args(UNUSED void **state)
void test_amxd_object_get_root(UNUSED void **state)
void test_amxd_object_get_parent(UNUSED void **state)
void test_amxd_object_get_child(UNUSED void **state)
void test_amxd_object_get_instance_difficult_alias_name(UNUSED void **state)
void test_amxd_object_get_instance(UNUSED void **state)
static char * expected_paths_down[]