#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <cmocka.h>
#include <stdio.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_dm.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_path.h>
#include "test_amxd_path.h"
#include <amxc/amxc_macros.h>
Go to the source code of this file.
◆ test_build_supported_path_from_search_path()
void test_build_supported_path_from_search_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 288 of file test_amxd_path.c.
290 char* sup_path = NULL;
292 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.*.AssociatedDevice."), 0);
293 amxc_var_dump(&path.
parts, STDOUT_FILENO);
295 assert_string_equal(sup_path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.");
298 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[param == value].AssociatedDevice.*.");
300 assert_string_equal(sup_path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
303 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[param == value].AssociatedDevice.*.");
305 assert_string_equal(sup_path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
308 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.1.AssociatedDevice.*.");
309 amxc_var_dump(&path.
parts, STDOUT_FILENO);
311 assert_string_equal(sup_path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
314 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.1.AssociatedDevice.2.");
315 amxc_var_dump(&path.
parts, STDOUT_FILENO);
317 assert_string_equal(sup_path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
320 printf(
"Path = Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*\n");
321 amxd_path_setf(&path,
false,
"Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*.");
323 amxc_var_dump(&path.
parts, STDOUT_FILENO);
325 printf(
"Supported path = %s\n", sup_path);
327 assert_string_equal(sup_path,
"Phonebook.Contact.{i}.PhoneNumber.{i}.");
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
char * amxd_path_build_supported_path(amxd_path_t *path)
Creates the supported path representation of the given path.
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
amxd_status_t amxd_path_setf(amxd_path_t *path, bool add_dot, const char *obj_path,...) __attribute__((format(printf
Sets or replaces the path contained in the amxd_path_t structure.
◆ test_can_append_path()
void test_can_append_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 519 of file test_amxd_path.c.
@ amxd_status_unknown_error
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
amxd_status_t amxd_status_t amxd_path_append(amxd_path_t *path, const char *extension, bool add_dot)
Appends a parameter name or object name/index to the path.
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
◆ test_can_clean_supported_path()
void test_can_clean_supported_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 255 of file test_amxd_path.c.
257 char* clean_path = NULL;
259 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice."), 0);
260 amxc_var_dump(&path.
parts, STDOUT_FILENO);
262 assert_string_equal(clean_path,
"Device.WiFi.AccessPoint.AssociatedDevice.");
265 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
267 assert_string_equal(clean_path,
"Device.WiFi.AccessPoint.AssociatedDevice.");
270 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.MAC");
272 assert_string_equal(clean_path,
"Device.WiFi.AccessPoint.AssociatedDevice.");
276 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.1.AssociatedDevice.2.MAC");
278 assert_string_equal(clean_path,
"Device.WiFi.AccessPoint.AssociatedDevice.");
283 assert_null(clean_path);
char * amxd_path_get_supported_path(amxd_path_t *path)
Translates the path into a path that can be used to fetch the object definition.
◆ test_can_create_delete_path()
void test_can_create_delete_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 76 of file test_amxd_path.c.
80 const char* verify[] = {
81 "Device.",
"Interface.",
"1.",
"Stats."
84 assert_int_equal(
amxd_path_new(&path,
"Device.Interface.1.Stats."), 0);
85 assert_non_null(path);
86 assert_int_equal(amxc_llist_size(&path->
parts.data.vl), 4);
88 amxc_var_for_each(var, (&path->
parts)) {
89 const char* txt = amxc_var_constcast(cstring_t, var);
91 assert_string_equal(txt, verify[index]);
void amxd_path_delete(amxd_path_t **path)
Frees an allocated amxd_path_t structure.
amxd_status_t amxd_path_new(amxd_path_t **path, const char *object_path)
Allocates and initializes an amxd_path_t structure.
◆ test_can_get_full_parameter_path()
void test_can_get_full_parameter_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 654 of file test_amxd_path.c.
656 const char* param_path =
"Greeter.State";
662 assert_string_equal(result, param_path);
char * amxd_path_get_param_path(amxd_path_t *path)
Get the full parameter path from the provided amxd_path_t struct.
◆ test_can_get_index_of_reference()
void test_can_get_index_of_reference |
( |
UNUSED void ** |
state | ) |
|
Definition at line 632 of file test_amxd_path.c.
634 char* ref_part = NULL;
638 amxc_var_for_each(var, (&path.
parts)) {
639 const char* txt = amxc_var_constcast(cstring_t, var);
645 assert_string_equal(ref_part,
"Device.WiFi.SSID.1.LowerLayers");
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
char * amxd_path_get_reference_part(amxd_path_t *path, bool remove)
Returns the reference path.
static amxd_path_type_t amxd_path_get_type(amxd_path_t *path)
Returns the path type.
uint32_t amxd_path_get_reference_index(amxd_path_t *path)
Returns the reference path index.
◆ test_can_get_last_from_path()
void test_can_get_last_from_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 576 of file test_amxd_path.c.
583 assert_non_null(last);
584 assert_string_equal(last,
"*.");
588 assert_non_null(last);
589 assert_string_equal(last,
"*.");
593 assert_non_null(last);
594 assert_string_equal(last,
"Pool.");
char * amxd_path_get_last(amxd_path_t *path, bool remove)
Gets the last part of the path.
◆ test_can_parse_reference_path()
void test_can_parse_reference_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 600 of file test_amxd_path.c.
602 char* ref_part = NULL;
604 amxd_path_init(&path,
"Device.NAT.PortMapping.1.Interface+.Name");
606 amxc_var_for_each(var, (&path.
parts)) {
607 const char* txt = amxc_var_constcast(cstring_t, var);
613 assert_string_equal(ref_part,
"Device.NAT.PortMapping.1.Interface");
619 assert_string_equal(ref_part,
"Device.NAT.PortMapping.1.Interface");
624 amxd_path_init(&path,
"Device.NAT.PortMapping.1.Interface#1+.Name");
char * amxd_path_get_fixed_part(amxd_path_t *path, bool remove)
Gets the fixed part of the path.
◆ test_can_prepend_path()
void test_can_prepend_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 547 of file test_amxd_path.c.
amxd_status_t amxd_path_prepend(amxd_path_t *path, const char *extension)
Prepends an object name/index to the path.
◆ test_can_split_empty_path()
void test_can_split_empty_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 221 of file test_amxd_path.c.
225 assert_true(amxc_llist_is_empty(&path.
parts.data.vl));
229 assert_true(amxc_llist_is_empty(&path.
parts.data.vl));
◆ test_can_split_path()
void test_can_split_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 101 of file test_amxd_path.c.
105 const char* verify[] = {
106 "Device.",
"Interface.",
"1.",
"Stats."
109 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.1.Stats."), 0);
110 assert_int_equal(amxc_llist_size(&path.
parts.data.vl), 4);
112 amxc_var_for_each(var, (&path.
parts)) {
113 const char* txt = amxc_var_constcast(cstring_t, var);
115 assert_string_equal(txt, verify[index]);
120 assert_string_equal(
amxd_path_get(&path, 0),
"Device.Interface.1.Stats");
123 assert_int_not_equal(
amxd_path_init(&path,
"Device.Interface.'Test#1+'.Stats."), 0);
◆ test_can_split_search_path_expression()
void test_can_split_search_path_expression |
( |
UNUSED void ** |
state | ) |
|
Definition at line 152 of file test_amxd_path.c.
156 const char* verify[] = {
157 "Device.",
"Interface.",
"[Enable==true]",
".",
"Stats."
160 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.[Enable==true].Stats.PacketsReceived"), 0);
162 amxc_var_for_each(var, (&path.
parts)) {
163 const char* txt = amxc_var_constcast(cstring_t, var);
165 assert_string_equal(txt, verify[index]);
169 assert_int_equal(amxc_llist_size(&path.
parts.data.vl), 5);
171 assert_string_equal(
amxd_path_get(&path, 0),
"Device.Interface.[Enable==true].Stats");
◆ test_can_split_search_path_wildcard()
void test_can_split_search_path_wildcard |
( |
UNUSED void ** |
state | ) |
|
Definition at line 128 of file test_amxd_path.c.
132 const char* verify[] = {
133 "Device.",
"Interface.",
"*",
".",
"Stats."
136 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.*.Stats."), 0);
138 amxc_var_for_each(var, (&path.
parts)) {
139 const char* txt = amxc_var_constcast(cstring_t, var);
141 assert_string_equal(txt, verify[index]);
145 assert_int_equal(amxc_llist_size(&path.
parts.data.vl), 5);
147 assert_string_equal(
amxd_path_get(&path, 0),
"Device.Interface.*.Stats");
◆ test_cannot_get_invalid_parameter_path()
void test_cannot_get_invalid_parameter_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 668 of file test_amxd_path.c.
670 const char* object_path =
"Greeter.";
682 amxd_path_init(&path,
"NetModel.Intf.['Device.Bridging.Bridge.1.' in InterfacePath]");
◆ test_get_depth()
void test_get_depth |
( |
UNUSED void ** |
state | ) |
|
Definition at line 440 of file test_amxd_path.c.
443 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
446 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.");
449 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.");
452 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[Stats.BytesRceived > 100].");
uint32_t amxd_path_get_depth(const amxd_path_t *const path)
Calculates the depth of the path.
◆ test_get_first()
void test_get_first |
( |
UNUSED void ** |
state | ) |
|
Definition at line 416 of file test_amxd_path.c.
420 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
422 assert_string_equal(part,
"Device.");
426 assert_string_equal(part,
"Device.");
432 assert_string_equal(part,
"WiFi.");
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
◆ test_get_fixed_part()
void test_get_fixed_part |
( |
UNUSED void ** |
state | ) |
|
Definition at line 394 of file test_amxd_path.c.
396 const char* p = NULL;
399 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice."), 0);
401 assert_string_equal(fixed,
"Device.WiFi.AccessPoint.");
405 assert_string_equal(p,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.");
408 assert_string_equal(fixed,
"Device.WiFi.AccessPoint.");
411 assert_string_equal(p,
"{i}.AssociatedDevice.");
◆ test_is_instance_path()
void test_is_instance_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 460 of file test_amxd_path.c.
463 assert_int_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
466 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.");
469 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.");
472 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.*.");
475 amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.[Stats.BytesRceived > 100].");
490 amxd_path_setf(&path,
false,
"Phonebook.Contact.[FirstName == 'ward'].");
bool amxd_path_is_instance_path(const amxd_path_t *const path)
Checks if the path is in the instantiated data model.
◆ test_is_invalid_path()
void test_is_invalid_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 333 of file test_amxd_path.c.
336 assert_int_not_equal(
amxd_path_init(&path,
"Device.WiFi.AccessPoint.{some_id}.AssociatedDevice."), 0);
342 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.{i}."), 0);
348 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.{i}"), 0);
354 assert_int_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.*."), 0);
360 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.*.AssociatedDevice.[Name = \"test\"]"), 0);
366 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.\"AccessPoint.{i}.AssociatedDevice\".*."), 0);
372 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.\"{i}\".AssociatedDevice.{i}."), 0);
378 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.{\"i\"}.AssociatedDevice."), 0);
384 assert_int_not_equal(
amxd_path_setf(&path,
false,
"Phonebook.Contact.*"), 0);
static bool amxd_path_is_object_path(amxd_path_t *path)
Checks if the path is an object path.
static bool amxd_path_is_supported_path(amxd_path_t *path)
Checks if the path is in the supported data model.
static bool amxd_path_is_valid(amxd_path_t *path)
Checks if the path is valid path.
static bool amxd_path_is_search_path(amxd_path_t *path)
Checks if the path is a search path.
◆ test_is_object_path()
void test_is_object_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 205 of file test_amxd_path.c.
209 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.1.Stats.PacketsReceived"), 0);
215 assert_string_equal(fixed,
"Device.Interface.1.Stats.");
◆ test_is_search_path()
void test_is_search_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 177 of file test_amxd_path.c.
181 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.[Enable==true].Stats.PacketsReceived"), 0);
186 assert_string_equal(fixed,
"Device.Interface.");
189 amxd_path_setf(&path,
false,
"Device.Interface.1.Stats.PacketsReceived");
193 amxd_path_setf(&path,
false,
"Device.Interface.[Name == \"Eth0\"].Stats.PacketsReceived");
197 amxd_path_setf(&path,
false,
"Device.Interface.[Name == \"{alpha.1}\"].Stats.PacketsReceived");
◆ test_is_supported_path()
void test_is_supported_path |
( |
UNUSED void ** |
state | ) |
|
Definition at line 233 of file test_amxd_path.c.
237 assert_int_equal(
amxd_path_init(&path,
"Device.Interface.{i}.Stats.PacketsReceived"), 0);
242 assert_string_equal(fixed,
"Device.Interface.");
246 assert_int_equal(
amxd_path_setf(&path,
false,
"Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}"), 0);
◆ test_remove_last_can_update_path_type()
void test_remove_last_can_update_path_type |
( |
UNUSED void ** |
state | ) |
|
Definition at line 501 of file test_amxd_path.c.
504 const char* initial_path =
"DHCPv4.Client.[Enable == true].";
511 assert_string_equal(last,
"[Enable == true].");