libamxd  6.4.1
Data Model Manager
test_amxd_path.c File Reference
#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.

Functions

void test_can_create_delete_path (UNUSED void **state)
 
void test_can_split_path (UNUSED void **state)
 
void test_can_split_search_path_wildcard (UNUSED void **state)
 
void test_can_split_search_path_expression (UNUSED void **state)
 
void test_is_search_path (UNUSED void **state)
 
void test_is_object_path (UNUSED void **state)
 
void test_can_split_empty_path (UNUSED void **state)
 
void test_is_supported_path (UNUSED void **state)
 
void test_can_clean_supported_path (UNUSED void **state)
 
void test_build_supported_path_from_search_path (UNUSED void **state)
 
void test_is_invalid_path (UNUSED void **state)
 
void test_get_fixed_part (UNUSED void **state)
 
void test_get_first (UNUSED void **state)
 
void test_get_depth (UNUSED void **state)
 
void test_is_instance_path (UNUSED void **state)
 
void test_remove_last_can_update_path_type (UNUSED void **state)
 
void test_can_append_path (UNUSED void **state)
 
void test_can_prepend_path (UNUSED void **state)
 
void test_can_get_last_from_path (UNUSED void **state)
 
void test_can_parse_reference_path (UNUSED void **state)
 
void test_can_get_index_of_reference (UNUSED void **state)
 
void test_can_get_full_parameter_path (UNUSED void **state)
 
void test_cannot_get_invalid_parameter_path (UNUSED void **state)
 

Function Documentation

◆ 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.

288  {
289  amxd_path_t path;
290  char* sup_path = NULL;
291 
292  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.*.AssociatedDevice."), 0);
293  amxc_var_dump(&path.parts, STDOUT_FILENO);
294  sup_path = amxd_path_build_supported_path(&path);
295  assert_string_equal(sup_path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.");
296  free(sup_path);
297 
298  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[param == value].AssociatedDevice.*.");
299  sup_path = amxd_path_build_supported_path(&path);
300  assert_string_equal(sup_path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
301  free(sup_path);
302 
303  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[param == value].AssociatedDevice.*.");
304  sup_path = amxd_path_build_supported_path(&path);
305  assert_string_equal(sup_path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
306  free(sup_path);
307 
308  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.1.AssociatedDevice.*.");
309  amxc_var_dump(&path.parts, STDOUT_FILENO);
310  sup_path = amxd_path_build_supported_path(&path);
311  assert_string_equal(sup_path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
312  free(sup_path);
313 
314  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.1.AssociatedDevice.2.");
315  amxc_var_dump(&path.parts, STDOUT_FILENO);
316  sup_path = amxd_path_build_supported_path(&path);
317  assert_string_equal(sup_path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
318  free(sup_path);
319 
320  printf("Path = Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*\n");
321  amxd_path_setf(&path, false, "Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*.");
322  fflush(stdout);
323  amxc_var_dump(&path.parts, STDOUT_FILENO);
324  sup_path = amxd_path_build_supported_path(&path);
325  printf("Supported path = %s\n", sup_path);
326  fflush(stdout);
327  assert_string_equal(sup_path, "Phonebook.Contact.{i}.PhoneNumber.{i}.");
328  free(sup_path);
329 
330  amxd_path_clean(&path);
331 }
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
Definition: amxd_path.c:328
char * amxd_path_build_supported_path(amxd_path_t *path)
Creates the supported path representation of the given path.
Definition: amxd_path.c:699
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351
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.
amxc_var_t parts
Definition: amxd_types.h:409

◆ test_can_append_path()

void test_can_append_path ( UNUSED void **  state)

Definition at line 519 of file test_amxd_path.c.

519  {
520  amxd_path_t path;
521 
522  amxd_path_init(&path, NULL);
523 
524  assert_int_equal(amxd_path_append(NULL, "foo", false), amxd_status_unknown_error);
525  assert_int_equal(amxd_path_append(&path, NULL, false), amxd_status_unknown_error);
526  assert_int_equal(amxd_path_append(&path, "", false), amxd_status_unknown_error);
527 
528  assert_int_equal(amxd_path_append(&path, "First.", false), amxd_status_ok);
529  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "First.");
530  assert_int_equal(path.type, amxd_path_object);
531 
532  assert_int_equal(amxd_path_append(&path, "Second.", false), amxd_status_ok);
533  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "First.Second.");
534  assert_int_equal(path.type, amxd_path_object);
535 
536  assert_int_equal(amxd_path_append(&path, "Third", true), amxd_status_ok);
537  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "First.Second.Third.");
538  assert_int_equal(path.type, amxd_path_object);
539 
540  assert_int_equal(amxd_path_append(&path, "*", true), amxd_status_ok);
541  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "First.Second.Third.*.");
542  assert_int_equal(path.type, amxd_path_search);
543 
544  amxd_path_clean(&path);
545 }
@ amxd_path_search
Definition: amxd_types.h:401
@ amxd_path_object
Definition: amxd_types.h:400
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
Definition: amxd_object.h:214
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.
Definition: amxd_path.c:441
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
Definition: amxd_path.c:470
amxd_path_type_t type
Definition: amxd_types.h:410

◆ test_can_clean_supported_path()

void test_can_clean_supported_path ( UNUSED void **  state)

Definition at line 255 of file test_amxd_path.c.

255  {
256  amxd_path_t path;
257  char* clean_path = NULL;
258 
259  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice."), 0);
260  amxc_var_dump(&path.parts, STDOUT_FILENO);
261  clean_path = amxd_path_get_supported_path(&path);
262  assert_string_equal(clean_path, "Device.WiFi.AccessPoint.AssociatedDevice.");
263  free(clean_path);
264 
265  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.");
266  clean_path = amxd_path_get_supported_path(&path);
267  assert_string_equal(clean_path, "Device.WiFi.AccessPoint.AssociatedDevice.");
268  free(clean_path);
269 
270  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.MAC");
271  clean_path = amxd_path_get_supported_path(&path);
272  assert_string_equal(clean_path, "Device.WiFi.AccessPoint.AssociatedDevice.");
273  free(clean_path);
274  amxd_path_clean(&path);
275 
276  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.1.AssociatedDevice.2.MAC");
277  clean_path = amxd_path_get_supported_path(&path);
278  assert_string_equal(clean_path, "Device.WiFi.AccessPoint.AssociatedDevice.");
279  free(clean_path);
280  amxd_path_clean(&path);
281 
282  clean_path = amxd_path_get_supported_path(&path);
283  assert_null(clean_path);
284 
285  amxd_path_clean(&path);
286 }
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.
Definition: amxd_path.c:611

◆ test_can_create_delete_path()

void test_can_create_delete_path ( UNUSED void **  state)

Definition at line 76 of file test_amxd_path.c.

76  {
77  amxd_path_t* path = NULL;
78 
79  int index = 0;
80  const char* verify[] = {
81  "Device.", "Interface.", "1.", "Stats."
82  };
83 
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);
87 
88  amxc_var_for_each(var, (&path->parts)) {
89  const char* txt = amxc_var_constcast(cstring_t, var);
90  printf("%s\n", txt);
91  assert_string_equal(txt, verify[index]);
92  index++;
93  }
94 
95  assert_string_equal(amxd_path_get(path, AMXD_OBJECT_TERMINATE), "Device.Interface.1.Stats.");
96 
97  amxd_path_delete(&path);
98  assert_null(path);
99 }
void amxd_path_delete(amxd_path_t **path)
Frees an allocated amxd_path_t structure.
Definition: amxd_path.c:378
amxd_status_t amxd_path_new(amxd_path_t **path, const char *object_path)
Allocates and initializes an amxd_path_t structure.
Definition: amxd_path.c:365

◆ 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.

654  {
655  amxd_path_t path;
656  const char* param_path = "Greeter.State";
657  char* result = NULL;
658 
659  amxd_path_init(&path, param_path);
660 
661  result = amxd_path_get_param_path(&path);
662  assert_string_equal(result, param_path);
663 
664  free(result);
665  amxd_path_clean(&path);
666 }
char * amxd_path_get_param_path(amxd_path_t *path)
Get the full parameter path from the provided amxd_path_t struct.
Definition: amxd_path.c:787

◆ 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.

632  {
633  amxd_path_t path;
634  char* ref_part = NULL;
635 
636  amxd_path_init(&path, "Device.WiFi.SSID.1.LowerLayers#3+.Name");
637 
638  amxc_var_for_each(var, (&path.parts)) {
639  const char* txt = amxc_var_constcast(cstring_t, var);
640  printf("%s\n", txt);
641  }
642 
643  assert_int_equal(amxd_path_get_type(&path), amxd_path_reference);
644  ref_part = amxd_path_get_reference_part(&path, false);
645  assert_string_equal(ref_part, "Device.WiFi.SSID.1.LowerLayers");
646  assert_int_equal(amxd_path_get_reference_index(&path), 3);
647  assert_string_equal(amxd_path_get_param(&path), "Name");
648  free(ref_part);
649 
650  amxd_path_clean(&path);
651 
652 }
@ amxd_path_reference
Definition: amxd_types.h:403
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
Definition: amxd_path.c:497
char * amxd_path_get_reference_part(amxd_path_t *path, bool remove)
Returns the reference path.
Definition: amxd_path.c:640
static amxd_path_type_t amxd_path_get_type(amxd_path_t *path)
Returns the path type.
Definition: amxd_path.h:507
uint32_t amxd_path_get_reference_index(amxd_path_t *path)
Returns the reference path index.
Definition: amxd_path.c:689

◆ 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.

576  {
577  amxd_path_t path;
578  char* last = NULL;
579 
580  amxd_path_init(&path, "DHCPv4.Server.Pool.*.");
581 
582  last = amxd_path_get_last(&path, false);
583  assert_non_null(last);
584  assert_string_equal(last, "*.");
585  free(last);
586 
587  last = amxd_path_get_last(&path, true);
588  assert_non_null(last);
589  assert_string_equal(last, "*.");
590  free(last);
591 
592  last = amxd_path_get_last(&path, false);
593  assert_non_null(last);
594  assert_string_equal(last, "Pool.");
595  free(last);
596 
597  amxd_path_clean(&path);
598 }
char * amxd_path_get_last(amxd_path_t *path, bool remove)
Gets the last part of the path.
Definition: amxd_path.c:531

◆ test_can_parse_reference_path()

void test_can_parse_reference_path ( UNUSED void **  state)

Definition at line 600 of file test_amxd_path.c.

600  {
601  amxd_path_t path;
602  char* ref_part = NULL;
603 
604  amxd_path_init(&path, "Device.NAT.PortMapping.1.Interface+.Name");
605 
606  amxc_var_for_each(var, (&path.parts)) {
607  const char* txt = amxc_var_constcast(cstring_t, var);
608  printf("%s\n", txt);
609  }
610 
611  assert_int_equal(amxd_path_get_type(&path), amxd_path_reference);
612  ref_part = amxd_path_get_reference_part(&path, false);
613  assert_string_equal(ref_part, "Device.NAT.PortMapping.1.Interface");
614  assert_int_equal(amxd_path_get_reference_index(&path), 1);
615  assert_string_equal(amxd_path_get_param(&path), "Name");
616  free(ref_part);
617 
618  ref_part = amxd_path_get_fixed_part(&path, false);
619  assert_string_equal(ref_part, "Device.NAT.PortMapping.1.Interface");
620  free(ref_part);
621 
622  amxd_path_clean(&path);
623 
624  amxd_path_init(&path, "Device.NAT.PortMapping.1.Interface#1+.Name");
625  assert_int_equal(amxd_path_get_type(&path), amxd_path_reference);
626  ref_part = amxd_path_get_reference_part(&path, true);
627 
628  free(ref_part);
629  amxd_path_clean(&path);
630 }
char * amxd_path_get_fixed_part(amxd_path_t *path, bool remove)
Gets the fixed part of the path.
Definition: amxd_path.c:576

◆ test_can_prepend_path()

void test_can_prepend_path ( UNUSED void **  state)

Definition at line 547 of file test_amxd_path.c.

547  {
548  amxd_path_t path;
549 
550  amxd_path_init(&path, NULL);
551 
552  assert_int_equal(amxd_path_prepend(NULL, "foo"), amxd_status_unknown_error);
553  assert_int_equal(amxd_path_prepend(&path, NULL), amxd_status_unknown_error);
554  assert_int_equal(amxd_path_prepend(&path, ""), amxd_status_unknown_error);
555 
556  assert_int_equal(amxd_path_append(&path, "*", true), amxd_status_ok);
557  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "*.");
558  assert_int_equal(path.type, amxd_path_search);
559 
560  assert_int_equal(amxd_path_prepend(&path, "Third."), amxd_status_ok);
561  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "Third.*.");
562  assert_int_equal(path.type, amxd_path_search);
563 
564  assert_int_equal(amxd_path_prepend(&path, "Second."), amxd_status_ok);
565  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "Second.Third.*.");
566  assert_int_equal(path.type, amxd_path_search);
567 
568 
569  assert_int_equal(amxd_path_prepend(&path, "First."), amxd_status_ok);
570  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "First.Second.Third.*.");
571  assert_int_equal(path.type, amxd_path_search);
572 
573  amxd_path_clean(&path);
574 }
amxd_status_t amxd_path_prepend(amxd_path_t *path, const char *extension)
Prepends an object name/index to the path.
Definition: amxd_path.c:456

◆ test_can_split_empty_path()

void test_can_split_empty_path ( UNUSED void **  state)

Definition at line 221 of file test_amxd_path.c.

221  {
222  amxd_path_t path;
223 
224  assert_int_equal(amxd_path_init(&path, ""), 0);
225  assert_true(amxc_llist_is_empty(&path.parts.data.vl));
226  amxd_path_clean(&path);
227 
228  amxd_path_init(&path, NULL);
229  assert_true(amxc_llist_is_empty(&path.parts.data.vl));
230  amxd_path_clean(&path);
231 }

◆ test_can_split_path()

void test_can_split_path ( UNUSED void **  state)

Definition at line 101 of file test_amxd_path.c.

101  {
102  amxd_path_t path;
103 
104  int index = 0;
105  const char* verify[] = {
106  "Device.", "Interface.", "1.", "Stats."
107  };
108 
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);
111 
112  amxc_var_for_each(var, (&path.parts)) {
113  const char* txt = amxc_var_constcast(cstring_t, var);
114  printf("%s\n", txt);
115  assert_string_equal(txt, verify[index]);
116  index++;
117  }
118 
119  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "Device.Interface.1.Stats.");
120  assert_string_equal(amxd_path_get(&path, 0), "Device.Interface.1.Stats");
121  amxd_path_clean(&path);
122 
123  assert_int_not_equal(amxd_path_init(&path, "Device.Interface.'Test#1+'.Stats."), 0);
124 
125  amxd_path_clean(&path);
126 }

◆ 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.

152  {
153  amxd_path_t path;
154 
155  int index = 0;
156  const char* verify[] = {
157  "Device.", "Interface.", "[Enable==true]", ".", "Stats."
158  };
159 
160  assert_int_equal(amxd_path_init(&path, "Device.Interface.[Enable==true].Stats.PacketsReceived"), 0);
161 
162  amxc_var_for_each(var, (&path.parts)) {
163  const char* txt = amxc_var_constcast(cstring_t, var);
164  printf("%s\n", txt);
165  assert_string_equal(txt, verify[index]);
166  index++;
167  }
168 
169  assert_int_equal(amxc_llist_size(&path.parts.data.vl), 5);
170  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "Device.Interface.[Enable==true].Stats.");
171  assert_string_equal(amxd_path_get(&path, 0), "Device.Interface.[Enable==true].Stats");
172  assert_string_equal(amxd_path_get_param(&path), "PacketsReceived");
173 
174  amxd_path_clean(&path);
175 }

◆ 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.

128  {
129  amxd_path_t path;
130 
131  int index = 0;
132  const char* verify[] = {
133  "Device.", "Interface.", "*", ".", "Stats."
134  };
135 
136  assert_int_equal(amxd_path_init(&path, "Device.Interface.*.Stats."), 0);
137 
138  amxc_var_for_each(var, (&path.parts)) {
139  const char* txt = amxc_var_constcast(cstring_t, var);
140  printf("%s\n", txt);
141  assert_string_equal(txt, verify[index]);
142  index++;
143  }
144 
145  assert_int_equal(amxc_llist_size(&path.parts.data.vl), 5);
146  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "Device.Interface.*.Stats.");
147  assert_string_equal(amxd_path_get(&path, 0), "Device.Interface.*.Stats");
148 
149  amxd_path_clean(&path);
150 }

◆ 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.

668  {
669  amxd_path_t path;
670  const char* object_path = "Greeter.";
671 
672  amxd_path_init(&path, NULL);
673 
674  assert_null(amxd_path_get_param_path(NULL));
675  assert_null(amxd_path_get_param_path(&path));
676 
677  amxd_path_setf(&path, false, "%s", object_path);
678  assert_null(amxd_path_get_param_path(&path));
679 
680  amxd_path_clean(&path);
681 
682  amxd_path_init(&path, "NetModel.Intf.['Device.Bridging.Bridge.1.' in InterfacePath]");
683  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "NetModel.Intf.['Device.Bridging.Bridge.1.' in InterfacePath].");
684 
685  amxd_path_clean(&path);
686 }

◆ test_get_depth()

void test_get_depth ( UNUSED void **  state)

Definition at line 440 of file test_amxd_path.c.

440  {
441  amxd_path_t path;
442 
443  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
444  assert_int_equal(amxd_path_get_depth(&path), 5);
445 
446  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.");
447  assert_int_equal(amxd_path_get_depth(&path), 5);
448 
449  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.");
450  assert_int_equal(amxd_path_get_depth(&path), 5);
451 
452  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[Stats.BytesRceived > 100].");
453  assert_int_equal(amxd_path_get_depth(&path), 4);
454 
455  assert_int_equal(amxd_path_get_depth(NULL), 0);
456 
457  amxd_path_clean(&path);
458 }
uint32_t amxd_path_get_depth(const amxd_path_t *const path)
Calculates the depth of the path.
Definition: amxd_path.c:733

◆ test_get_first()

void test_get_first ( UNUSED void **  state)

Definition at line 416 of file test_amxd_path.c.

416  {
417  amxd_path_t path;
418  char* part = NULL;
419 
420  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
421  part = amxd_path_get_first(&path, false);
422  assert_string_equal(part, "Device.");
423  free(part);
424 
425  part = amxd_path_get_first(&path, true);
426  assert_string_equal(part, "Device.");
427  free(part);
428 
429  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "WiFi.AccessPoint.2.AssociatedDevice.");
430 
431  part = amxd_path_get_first(&path, true);
432  assert_string_equal(part, "WiFi.");
433  free(part);
434 
435  assert_null(amxd_path_get_first(NULL, true));
436 
437  amxd_path_clean(&path);
438 }
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
Definition: amxd_path.c:501

◆ test_get_fixed_part()

void test_get_fixed_part ( UNUSED void **  state)

Definition at line 394 of file test_amxd_path.c.

394  {
395  amxd_path_t path;
396  const char* p = NULL;
397  char* fixed = NULL;
398 
399  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.{i}.AssociatedDevice."), 0);
400  fixed = amxd_path_get_fixed_part(&path, false);
401  assert_string_equal(fixed, "Device.WiFi.AccessPoint.");
402  free(fixed);
403 
405  assert_string_equal(p, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.");
406 
407  fixed = amxd_path_get_fixed_part(&path, true);
408  assert_string_equal(fixed, "Device.WiFi.AccessPoint.");
409  free(fixed);
411  assert_string_equal(p, "{i}.AssociatedDevice.");
412 
413  amxd_path_clean(&path);
414 }

◆ test_is_instance_path()

void test_is_instance_path ( UNUSED void **  state)

Definition at line 460 of file test_amxd_path.c.

460  {
461  amxd_path_t path;
462 
463  assert_int_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.2.AssociatedDevice."), 0);
464  assert_false(amxd_path_is_instance_path(&path));
465 
466  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.");
467  assert_false(amxd_path_is_instance_path(&path));
468 
469  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.");
470  assert_false(amxd_path_is_instance_path(&path));
471 
472  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[Enabled == true].AssociatedDevice.*.");
473  assert_true(amxd_path_is_instance_path(&path));
474 
475  amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.[Stats.BytesRceived > 100].");
476  assert_true(amxd_path_is_instance_path(&path));
477 
478  amxd_path_setf(&path, false, "Phonebook.Contact. ");
479  assert_false(amxd_path_is_instance_path(&path));
480 
481  amxd_path_setf(&path, false, "Phonebook.Contact.*.");
482  assert_true(amxd_path_is_instance_path(&path));
483 
484  amxd_path_setf(&path, false, "Phonebook.Contact.1.");
485  assert_true(amxd_path_is_instance_path(&path));
486 
487  amxd_path_setf(&path, false, "Phonebook.Contact.1");
488  assert_false(amxd_path_is_instance_path(&path));
489 
490  amxd_path_setf(&path, false, "Phonebook.Contact.[FirstName == 'ward'].");
491  assert_true(amxd_path_is_instance_path(&path));
492 
493  amxd_path_setf(&path, false, "Phonebook.Contact.1.FirstName");
494  assert_true(amxd_path_is_instance_path(&path));
495 
496  assert_false(amxd_path_is_instance_path(NULL));
497 
498  amxd_path_clean(&path);
499 }
bool amxd_path_is_instance_path(const amxd_path_t *const path)
Checks if the path is in the instantiated data model.
Definition: amxd_path.c:753

◆ test_is_invalid_path()

void test_is_invalid_path ( UNUSED void **  state)

Definition at line 333 of file test_amxd_path.c.

333  {
334  amxd_path_t path;
335 
336  assert_int_not_equal(amxd_path_init(&path, "Device.WiFi.AccessPoint.{some_id}.AssociatedDevice."), 0);
337  assert_false(amxd_path_is_search_path(&path));
338  assert_false(amxd_path_is_supported_path(&path));
339  assert_false(amxd_path_is_object_path(&path));
340  assert_false(amxd_path_is_valid(&path));
341 
342  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.{i}."), 0);
343  assert_false(amxd_path_is_search_path(&path));
344  assert_false(amxd_path_is_supported_path(&path));
345  assert_false(amxd_path_is_object_path(&path));
346  assert_false(amxd_path_is_valid(&path));
347 
348  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.{i}"), 0);
349  assert_false(amxd_path_is_search_path(&path));
350  assert_false(amxd_path_is_supported_path(&path));
351  assert_false(amxd_path_is_object_path(&path));
352  assert_false(amxd_path_is_valid(&path));
353 
354  assert_int_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.*."), 0);
355  assert_true(amxd_path_is_search_path(&path));
356  assert_false(amxd_path_is_supported_path(&path));
357  assert_false(amxd_path_is_object_path(&path));
358  assert_true(amxd_path_is_valid(&path));
359 
360  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.*.AssociatedDevice.[Name = \"test\"]"), 0);
361  assert_false(amxd_path_is_search_path(&path));
362  assert_false(amxd_path_is_supported_path(&path));
363  assert_false(amxd_path_is_object_path(&path));
364  assert_false(amxd_path_is_valid(&path));
365 
366  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.\"AccessPoint.{i}.AssociatedDevice\".*."), 0);
367  assert_false(amxd_path_is_search_path(&path));
368  assert_false(amxd_path_is_supported_path(&path));
369  assert_false(amxd_path_is_object_path(&path));
370  assert_false(amxd_path_is_valid(&path));
371 
372  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.\"{i}\".AssociatedDevice.{i}."), 0);
373  assert_false(amxd_path_is_search_path(&path));
374  assert_false(amxd_path_is_supported_path(&path));
375  assert_false(amxd_path_is_object_path(&path));
376  assert_false(amxd_path_is_valid(&path));
377 
378  assert_int_not_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.{\"i\"}.AssociatedDevice."), 0);
379  assert_false(amxd_path_is_search_path(&path));
380  assert_false(amxd_path_is_supported_path(&path));
381  assert_false(amxd_path_is_object_path(&path));
382  assert_false(amxd_path_is_valid(&path));
383 
384  assert_int_not_equal(amxd_path_setf(&path, false, "Phonebook.Contact.*"), 0);
385  assert_false(amxd_path_is_search_path(&path));
386  assert_false(amxd_path_is_supported_path(&path));
387  assert_false(amxd_path_is_object_path(&path));
388  assert_false(amxd_path_is_valid(&path));
389 
390 
391  amxd_path_clean(&path);
392 }
static bool amxd_path_is_object_path(amxd_path_t *path)
Checks if the path is an object path.
Definition: amxd_path.h:579
static bool amxd_path_is_supported_path(amxd_path_t *path)
Checks if the path is in the supported data model.
Definition: amxd_path.h:562
static bool amxd_path_is_valid(amxd_path_t *path)
Checks if the path is valid path.
Definition: amxd_path.h:526
static bool amxd_path_is_search_path(amxd_path_t *path)
Checks if the path is a search path.
Definition: amxd_path.h:544

◆ test_is_object_path()

void test_is_object_path ( UNUSED void **  state)

Definition at line 205 of file test_amxd_path.c.

205  {
206  amxd_path_t path;
207  char* fixed = NULL;
208 
209  assert_int_equal(amxd_path_init(&path, "Device.Interface.1.Stats.PacketsReceived"), 0);
210  assert_false(amxd_path_is_search_path(&path));
211  assert_false(amxd_path_is_supported_path(&path));
212  assert_true(amxd_path_is_object_path(&path));
213 
214  fixed = amxd_path_get_fixed_part(&path, false);
215  assert_string_equal(fixed, "Device.Interface.1.Stats.");
216  free(fixed);
217 
218  amxd_path_clean(&path);
219 }

◆ test_is_search_path()

void test_is_search_path ( UNUSED void **  state)

Definition at line 177 of file test_amxd_path.c.

177  {
178  amxd_path_t path;
179  char* fixed = NULL;
180 
181  assert_int_equal(amxd_path_init(&path, "Device.Interface.[Enable==true].Stats.PacketsReceived"), 0);
182  assert_true(amxd_path_is_search_path(&path));
183  assert_false(amxd_path_is_supported_path(&path));
184 
185  fixed = amxd_path_get_fixed_part(&path, false);
186  assert_string_equal(fixed, "Device.Interface.");
187  free(fixed);
188 
189  amxd_path_setf(&path, false, "Device.Interface.1.Stats.PacketsReceived");
190  assert_false(amxd_path_is_search_path(&path));
191  assert_false(amxd_path_is_supported_path(&path));
192 
193  amxd_path_setf(&path, false, "Device.Interface.[Name == \"Eth0\"].Stats.PacketsReceived");
194  assert_true(amxd_path_is_search_path(&path));
195  assert_false(amxd_path_is_supported_path(&path));
196 
197  amxd_path_setf(&path, false, "Device.Interface.[Name == \"{alpha.1}\"].Stats.PacketsReceived");
198  assert_true(amxd_path_is_search_path(&path));
199  assert_false(amxd_path_is_supported_path(&path));
200  assert_true(amxd_path_is_valid(&path));
201 
202  amxd_path_clean(&path);
203 }

◆ test_is_supported_path()

void test_is_supported_path ( UNUSED void **  state)

Definition at line 233 of file test_amxd_path.c.

233  {
234  amxd_path_t path;
235  char* fixed = NULL;
236 
237  assert_int_equal(amxd_path_init(&path, "Device.Interface.{i}.Stats.PacketsReceived"), 0);
238  assert_false(amxd_path_is_search_path(&path));
239  assert_true(amxd_path_is_supported_path(&path));
240 
241  fixed = amxd_path_get_fixed_part(&path, false);
242  assert_string_equal(fixed, "Device.Interface.");
243 
244  free(fixed);
245 
246  assert_int_equal(amxd_path_setf(&path, false, "Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}"), 0);
247  assert_false(amxd_path_is_search_path(&path));
248  assert_true(amxd_path_is_supported_path(&path));
249  assert_false(amxd_path_is_object_path(&path));
250  assert_true(amxd_path_is_valid(&path));
251 
252  amxd_path_clean(&path);
253 }

◆ 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.

501  {
502  amxd_path_t path;
503  char* last = NULL;
504  const char* initial_path = "DHCPv4.Client.[Enable == true].";
505 
506  amxd_path_init(&path, initial_path);
507  assert_true(amxd_path_is_search_path(&path));
508  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), initial_path);
509 
510  last = amxd_path_get_last(&path, true);
511  assert_string_equal(last, "[Enable == true].");
512  assert_string_equal(amxd_path_get(&path, AMXD_OBJECT_TERMINATE), "DHCPv4.Client.");
513  free(last);
514  assert_false(amxd_path_is_search_path(&path));
515 
516  amxd_path_clean(&path);
517 }