libamxb  4.8.2
Bus Agnostic C API
test_amxb_local.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #include <stdlib.h>
56 #include <stdio.h>
57 #include <dlfcn.h>
58 #include <stdarg.h>
59 #include <stddef.h>
60 #include <setjmp.h>
61 #include <cmocka.h>
62 #include <sys/types.h>
63 #include <signal.h>
64 
65 #include <amxc/amxc.h>
66 #include <amxp/amxp.h>
67 
68 #include <amxd/amxd_dm.h>
69 #include <amxo/amxo.h>
70 
71 #include <amxb/amxb.h>
72 #include <amxb/amxb_register.h>
73 
74 #include "dummy_be.h"
75 #include "test_amxb_local.h"
76 
77 #include <amxc/amxc_macros.h>
78 static amxb_bus_ctx_t* bus_ctx = NULL;
79 static amxd_dm_t dm;
80 static amxo_parser_t parser;
81 
82 static void event_handler(const char* const sig_name,
83  const amxc_var_t* const data,
84  void* const priv) {
85  int* event_count = (int*) priv;
86  printf("Event received = %s\n", sig_name);
87  fflush(stdout);
88  amxc_var_dump(data, STDOUT_FILENO);
89  (*event_count)++;
90 }
91 
92 
93 static void handle_events(void) {
94  printf("Handling events ");
95  while(amxp_signal_read() == 0) {
96  printf(".");
97  }
98  printf("\n");
99 }
100 
102  amxb_request_t* req,
103  int status,
104  UNUSED void* priv) {
105  if(status == 0) {
106  amxc_var_dump(req->result, STDOUT_FILENO);
107  }
108 }
109 
110 static void test_request_done(UNUSED const amxb_bus_ctx_t* bus_ctx,
111  amxb_request_t* req,
112  int status,
113  UNUSED void* priv) {
114  if(status == 0) {
115  amxc_var_dump(req->result, STDOUT_FILENO);
116  }
117 
118  amxb_close_request(&req);
119 }
120 
121 int test_amxb_local_setup(UNUSED void** state) {
122  amxd_object_t* root_obj = NULL;
123 
125 
126  assert_int_equal(amxb_connect(&bus_ctx, "dummy:/tmp/dummy.sock"), 0);
127 
128  assert_int_equal(amxd_dm_init(&dm), amxd_status_ok);
129  assert_int_equal(amxo_parser_init(&parser), 0);
130 
131  root_obj = amxd_dm_get_root(&dm);
132  assert_non_null(root_obj);
133 
134  assert_int_equal(amxo_parser_parse_file(&parser, "./test.odl", root_obj), 0);
135 
136  handle_events();
137 
138  assert_int_equal(amxb_register(bus_ctx, &dm), 0);
139 
140  return 0;
141 }
142 
143 int test_amxb_local_teardown(UNUSED void** state) {
145  amxb_free(&bus_ctx);
146 
148 
149  amxo_parser_clean(&parser);
150  amxd_dm_clean(&dm);
151 
153 
154  return 0;
155 }
156 
157 void test_amxb_call(UNUSED void** state) {
158  amxc_var_t values;
159  amxc_var_t* results = NULL;
160  amxc_var_init(&values);
161 
162  assert_int_equal(amxb_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, NULL, 1), 0);
163 
164  assert_int_equal(amxb_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, &values, 1), 0);
165  amxc_var_dump(&values, STDOUT_FILENO);
166  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
167  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
168  assert_int_equal(amxc_htable_size(&results->data.vm), 1);
169 
170  assert_int_not_equal(amxb_call(bus_ctx, "Device.Link.Interface.1", "_get", NULL, NULL, 1), 0);
171 
172  amxc_var_clean(&values);
173 }
174 
175 void test_amxb_async_call(UNUSED void** state) {
176  amxb_request_t* request = NULL;
177 
178  request = amxb_async_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, test_request_done_keep, NULL);
179  assert_non_null(request);
180  assert_int_equal(amxb_wait_for_request(request, 10), 0);
181  amxc_var_dump(request->result, STDOUT_FILENO);
182  amxb_close_request(&request);
183  assert_null(request);
184 
185  request = amxb_async_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, test_request_done_keep, NULL);
186  assert_non_null(request);
187  amxb_close_request(&request);
188  handle_events();
189 
190  request = amxb_async_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, test_request_done, NULL);
191  assert_non_null(request);
192  handle_events();
193 
194  request = amxb_async_call(bus_ctx, "Device.Ethernet.Interface.1", "_get", NULL, test_request_done, NULL);
195  assert_non_null(request);
196  assert_int_equal(amxb_wait_for_request(request, 10), 0);
197 }
198 
199 void test_amxb_get(UNUSED void** state) {
200  amxc_var_t values;
201  amxc_var_t* results = NULL;
202  amxc_var_init(&values);
203 
204  assert_int_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.1.Status", 0, &values, 1), 0);
205  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
206  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
207  amxc_var_dump(&values, STDOUT_FILENO);
208  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
209  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
210  assert_int_equal(amxc_htable_size(&results->data.vm), 1);
211 
212  assert_int_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.*.Status", 0, &values, 1), 0);
213  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
214  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
215  amxc_var_dump(&values, STDOUT_FILENO);
216  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
217  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
218  assert_int_equal(amxc_htable_size(&results->data.vm), 4);
219 
220  assert_int_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.[Enable == true].Status", 0, &values, 1), 0);
221  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
222  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
223  amxc_var_dump(&values, STDOUT_FILENO);
224  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
225  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
226  assert_int_equal(amxc_htable_size(&results->data.vm), 2);
227 
228  assert_int_not_equal(amxb_get(bus_ctx, "Device.Ethernet.Link.[Enable == true].Status", 0, &values, 1), 0);
229 
230  assert_int_equal(amxb_get(bus_ctx, "Device.Alias", 0, &values, 1), 0);
231  amxc_var_dump(&values, STDOUT_FILENO);
232  assert_int_equal(amxb_get(bus_ctx, "Device.Port", 0, &values, 1), 0);
233  amxc_var_dump(&values, STDOUT_FILENO);
234 
235  amxc_var_clean(&values);
236 }
237 
238 void test_amxb_get_multiple(UNUSED void** state) {
239  amxc_var_t values;
240  amxc_var_init(&values);
241 
242  amxc_var_t paths;
243  amxc_var_init(&paths);
244  amxc_var_set_type(&paths, AMXC_VAR_ID_LIST);
245  amxc_var_add(cstring_t, &paths, "Device.Ethernet.Interface.1.Status");
246  amxc_var_add(cstring_t, &paths, "Device.Ethernet.Interface.20.");
247  amxc_var_add(cstring_t, &paths, "Device.time.");
248 
249  assert_int_equal(amxb_get_multiple(bus_ctx, &paths, 0, &values, 5), 0);
250  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_HTABLE);
251  assert_int_equal(amxc_var_type_of(GETP_ARG(&values, "'Device.Ethernet.Interface.1.Status'.result")), AMXC_VAR_ID_LIST);
252  assert_int_equal(GETP_UINT32(&values, "'Device.Ethernet.Interface.1.Status'.status"), 0);
253  assert_string_equal(GETP_CHAR(&values, "'Device.Ethernet.Interface.1.Status'.result.0.'Device.Ethernet.Interface.1.'.Status"), "Up");
254 
255  amxc_var_dump(&values, STDOUT_FILENO);
256  assert_int_equal(amxc_var_type_of(GETP_ARG(&values, "'Device.Ethernet.Interface.20.'.result")), AMXC_VAR_ID_LIST);
257  assert_int_equal(GETP_UINT32(&values, "'Device.Ethernet.Interface.20.'.status"), 2);
258 
259  assert_int_equal(amxc_var_type_of(GETP_ARG(&values, "'Device.time.'.result")), AMXC_VAR_ID_LIST);
260  assert_int_equal(amxc_var_type_of(GETP_ARG(&values, "'Device.time.")), AMXC_VAR_ID_HTABLE);
261  assert_int_equal(GETP_UINT32(&values, "'Device.time.'.status"), 2);
262 
263  amxc_var_dump(&values, STDOUT_FILENO);
264  amxc_var_clean(&values);
265  amxc_var_clean(&paths);
266 }
267 
268 void test_amxb_get_instances(UNUSED void** state) {
269  amxc_var_t values;
270  amxc_var_t* results = NULL;
271  amxc_var_init(&values);
272 
273  assert_int_equal(amxb_get_instances(bus_ctx, "Device.Ethernet.Interface.", 0, &values, 1), 0);
274  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
275  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
276  amxc_var_dump(&values, STDOUT_FILENO);
277  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
278  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
279  assert_int_equal(amxc_htable_size(&results->data.vm), 4);
280 
281  amxc_var_clean(&values);
282 }
283 
284 void test_amxb_get_reference(UNUSED void** state) {
285  amxc_var_t values;
286  amxc_var_t* results = NULL;
287  amxc_var_init(&values);
288 
289  assert_int_equal(amxb_get(bus_ctx, "Device.Reference+.", 0, &values, 1), 0);
290  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
291  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
292  amxc_var_dump(&values, STDOUT_FILENO);
293  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
294  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
295  assert_int_equal(amxc_htable_size(&results->data.vm), 1);
296 
297  assert_int_equal(amxb_get(bus_ctx, "Device.Refs#2+.", 0, &values, 1), 0);
298  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
299  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
300  amxc_var_dump(&values, STDOUT_FILENO);
301  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
302  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
303  assert_int_equal(amxc_htable_size(&results->data.vm), 1);
304 
305  assert_int_not_equal(amxb_get(bus_ctx, "Device.Refs#85+.", 0, &values, 1), 0);
306  assert_int_not_equal(amxb_get(bus_ctx, "Device.Refs#0+.", 0, &values, 1), 0);
307 
308  amxc_var_clean(&values);
309 }
310 
311 void test_amxb_get_key_path_reference(UNUSED void** state) {
312  amxc_var_t values;
313  amxc_var_t* results = NULL;
314  amxc_var_init(&values);
315 
316  assert_int_equal(amxb_get(bus_ctx, "Device.TestObject.[Enabled == false].Reference+.", 0, &values, 1), 0);
317  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
318  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
319  amxc_var_dump(&values, STDOUT_FILENO);
320  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
321  assert_int_equal(amxc_var_type_of(results), AMXC_VAR_ID_HTABLE);
322  assert_int_equal(amxc_htable_size(&results->data.vm), 1);
323 
324  assert_int_not_equal(amxb_get(bus_ctx, "Device.TestObject.[Enabled == true].Reference+.", 0, &values, 1), 0);
325 
326  amxc_var_clean(&values);
327 }
328 
329 void test_amxb_set(UNUSED void** state) {
330  amxc_var_t values;
331  amxc_var_t ret;
332  amxc_var_t* results = NULL;
333  amxc_var_init(&ret);
334  amxc_var_init(&values);
335 
336  amxc_var_set_type(&values, AMXC_VAR_ID_HTABLE);
337  amxc_var_add_key(bool, &values, "Enable", false);
338  amxc_var_add_key(cstring_t, &values, "Status", "Dormant");
339  assert_int_equal(amxb_set(bus_ctx, "Device.Ethernet.Interface.1", &values, &ret, 1), 0);
340  amxc_var_dump(&ret, STDOUT_FILENO);
341  assert_int_equal(amxc_var_type_of(&ret), AMXC_VAR_ID_LIST);
342  assert_int_equal(amxc_var_type_of(GETI_ARG(&ret, 0)), AMXC_VAR_ID_HTABLE);
343  results = GETP_ARG(&ret, "0.'Device.Ethernet.Interface.1.'");
344  assert_non_null(results);
345  assert_non_null(GET_ARG(results, "Enable"));
346  assert_non_null(GET_ARG(results, "Status"));
347 
348  assert_int_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.1.", 0, &values, 1), 0);
349  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
350  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
351  amxc_var_dump(&values, STDOUT_FILENO);
352  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
353  assert_non_null(results);
354  results = amxc_var_get_key(results, "Device.Ethernet.Interface.1.", AMXC_VAR_FLAG_DEFAULT);
355  assert_non_null(results);
356  results = amxc_var_get_key(results, "Status", AMXC_VAR_FLAG_DEFAULT);
357  assert_non_null(results);
358  assert_string_equal(amxc_var_constcast(cstring_t, results), "Dormant");
359 
360  assert_int_not_equal(amxb_set(bus_ctx, "Device.Link.Interface.1", &values, &ret, 1), 0);
361 
362  amxc_var_clean(&ret);
363  amxc_var_clean(&values);
364 }
365 
366 void test_amxb_add(UNUSED void** state) {
367  amxc_var_t values;
368  amxc_var_t ret;
369  amxc_var_t* results = NULL;
370  amxc_var_init(&ret);
371  amxc_var_init(&values);
372 
373  amxc_var_set_type(&values, AMXC_VAR_ID_HTABLE);
374  amxc_var_add_key(bool, &values, "Enable", false);
375  amxc_var_add_key(cstring_t, &values, "Status", "Unknown");
376 
377  assert_int_equal(amxb_add(bus_ctx, "Device.Ethernet.Interface", 0, NULL, &values, &ret, 1), 0);
378  assert_int_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.5.", 0, &values, 1), 0);
379  assert_int_equal(amxc_var_type_of(&values), AMXC_VAR_ID_LIST);
380  assert_int_equal(amxc_llist_size(&values.data.vl), 1);
381  amxc_var_dump(&values, STDOUT_FILENO);
382  results = amxc_var_get_index(&values, 0, AMXC_VAR_FLAG_DEFAULT);
383  results = amxc_var_get_key(results, "Device.Ethernet.Interface.5.", AMXC_VAR_FLAG_DEFAULT);
384  results = amxc_var_get_key(results, "Status", AMXC_VAR_FLAG_DEFAULT);
385  assert_string_equal(amxc_var_constcast(cstring_t, results), "Unknown");
386 
387  assert_int_not_equal(amxb_add(bus_ctx, "Device.Ethernet.Link", 0, NULL, NULL, NULL, 1), 0);
388 
389  amxc_var_clean(&ret);
390  amxc_var_clean(&values);
391 }
392 
393 void test_amxb_del(UNUSED void** state) {
394  amxc_var_t values;
395  amxc_var_t ret;
396  amxc_var_init(&ret);
397  amxc_var_init(&values);
398 
399  assert_int_equal(amxb_del(bus_ctx, "Device.Ethernet.Interface", 5, NULL, &ret, 1), 0);
400  assert_int_not_equal(amxb_get(bus_ctx, "Device.Ethernet.Interface.5.", 0, &values, 1), 0);
401 
402  assert_int_not_equal(amxb_del(bus_ctx, "Device.Ethernet.Interface", 5, NULL, &ret, 1), 0);
403 
404  amxc_var_clean(&ret);
405  amxc_var_clean(&values);
406 }
407 
408 void test_search_path_expr_func(UNUSED void** state) {
409  amxp_expr_t expr;
410  const char* expression1 = "'Device.Ethernet.Interface.3.Stats.' in search_path('Device.Ethernet.Interface.*.Stats.')";
411  const char* expression2 = "'Device.Ethernet.Interface.3.Stats.' in search_path('Device.Ethernet.Interface.3.Stats.')";
412  const char* expression3 = "'Device.Ethernet.Interface.3.Stats.' in search_path('Device.Ethernet.Interface.[Enable == 1].Stats.')";
413 
414  amxp_expr_init(&expr, expression1);
415  assert_true(amxp_expr_evaluate(&expr, NULL, NULL, NULL));
416  amxp_expr_clean(&expr);
417 
418  amxp_expr_init(&expr, expression2);
419  assert_true(amxp_expr_evaluate(&expr, NULL, NULL, NULL));
420  amxp_expr_clean(&expr);
421 
422  amxp_expr_init(&expr, expression3);
423  assert_false(amxp_expr_evaluate(&expr, NULL, NULL, NULL));
424  amxp_expr_clean(&expr);
425 }
426 
427 void test_amxb_subscribe(UNUSED void** state) {
428  int event_count = 0;
429  handle_events();
430 
431  event_count = 0;
432  assert_int_equal(amxb_subscribe(bus_ctx, "Device.Ethernet.Interface", NULL, event_handler, &event_count), 0);
433 
434  assert_int_equal(amxb_add(bus_ctx, "Device.Ethernet.Interface", 0, NULL, NULL, NULL, 1), 0);
435 
436  handle_events();
437  assert_int_not_equal(event_count, 0);
438 }
439 
440 void test_amxb_subscribe_non_existing(UNUSED void** state) {
441  int event_count = 0;
442  handle_events();
443 
444  event_count = 0;
445  assert_int_not_equal(amxb_subscribe(bus_ctx, "Device.Ethernet.Link.", NULL, event_handler, &event_count), 0);
446 
447  handle_events();
448  assert_int_equal(event_count, 0);
449 }
450 
451 void test_amxb_subscribe_twice(UNUSED void** state) {
452  int event_count = 0;
453  handle_events();
454 
455  event_count = 0;
456  assert_int_equal(amxb_subscribe(bus_ctx, "Device.Ethernet.Interface", NULL, event_handler, &event_count), 0);
457  assert_int_equal(amxb_subscribe(bus_ctx, "Device.Ethernet.Interface", NULL, event_handler, &event_count), 0);
458 
459  assert_int_equal(amxb_add(bus_ctx, "Device.Ethernet.Interface", 0, NULL, NULL, NULL, 1), 0);
460 
461  handle_events();
462  assert_int_not_equal(event_count, 0);
463 }
464 
465 void test_amxb_subscribe_instance(UNUSED void** state) {
466  int event_count = 0;
467  handle_events();
468 
469  event_count = 0;
470  assert_int_equal(amxb_subscribe(bus_ctx, "Device.Ethernet.Interface.1.", NULL, event_handler, &event_count), 0);
471 
472  handle_events();
473 }
474 
475 void test_amxb_publish(UNUSED void** state) {
476  assert_int_equal(amxb_publish(bus_ctx, "Device.Ethernet.Interface.1.", "test", NULL), 0);
477  assert_int_not_equal(amxb_publish(NULL, "Device.Ethernet.Interface.1.", "test", NULL), 0);
478  assert_int_not_equal(amxb_publish(bus_ctx, NULL, "test", NULL), 0);
479  assert_int_not_equal(amxb_publish(bus_ctx, "Device.Ethernet.Interface.1.", NULL, NULL), 0);
480  assert_int_not_equal(amxb_publish(bus_ctx, "", "test", NULL), 0);
481  assert_int_not_equal(amxb_publish(bus_ctx, "Device.Ethernet.", "", NULL), 0);
482  assert_int_not_equal(amxb_publish(bus_ctx, "Device.Ethernet.Link.1.", "test", NULL), 0);
483 }
484 
486  UNUSED const amxc_var_t* const data,
487  UNUSED void* priv) {
488  assert_non_null(bus_ctx);
489  if(data != NULL) {
490  assert_int_equal(amxc_var_type_of(data), AMXC_VAR_ID_LIST);
491  }
492 }
493 
494 void test_amxb_list(UNUSED void** state) {
495  assert_int_equal(amxb_list(bus_ctx, "Device.Ethernet.Interface.1.", 0, test_amxb_list_cb, NULL), 0);
496  assert_int_equal(amxb_list(bus_ctx, "Device.Ethernet.Interface.",
499  test_amxb_list_cb, NULL), 0);
500  assert_int_equal(amxb_list(bus_ctx, "Device.Ethernet.Interface.1.",
504  test_amxb_list_cb, NULL), 0);
505  assert_int_equal(amxb_list(bus_ctx, "Device.Ethernet.Interface.",
509  test_amxb_list_cb, NULL), 0);
510  assert_int_not_equal(amxb_list(NULL, "Device.Ethernet.Interface.1.", 0, test_amxb_list_cb, NULL), 0);
511  assert_int_not_equal(amxb_list(bus_ctx, NULL, 0, test_amxb_list_cb, NULL), 0);
512 }
Ambiorix bus agnostic API header file.
#define AMXB_FLAG_NAMED
#define AMXB_FLAG_INSTANCES
#define AMXB_FLAG_FUNCTIONS
#define AMXB_FLAG_PARAMETERS
#define AMXB_FLAG_OBJECTS
Ambiorix Bus Agnostic Data Model registration.
int test_unregister_dummy_be(void)
Definition: dummy_be.c:187
int test_register_dummy_be(void)
Definition: dummy_be.c:183
void amxb_be_remove_all(void)
Removes and unloads all backends.
int amxb_connect(amxb_bus_ctx_t **ctx, const char *uri)
Create a bus connection.
void amxb_free(amxb_bus_ctx_t **ctx)
Frees allocated memory.
int amxb_disconnect(amxb_bus_ctx_t *ctx)
Disconnects a bus connection.
int amxb_publish(amxb_bus_ctx_t *const ctx, const char *object, const char *name, amxc_var_t *data)
Publish an event for a specific object.
int amxb_subscribe(amxb_bus_ctx_t *const ctx, const char *object, const char *expression, amxp_slot_fn_t slot_cb, void *priv)
Subscribes for events of a object tree.
int amxb_wait_for_request(amxb_request_t *req, int timeout)
Waits for an asynchronous remote function invoke to finish.
int amxb_close_request(amxb_request_t **req)
Closes a previously create remote function called context.
int amxb_del(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t index, const char *name, amxc_var_t *ret, int timeout)
Deletes one or more instances of a multi-instance object.
int amxb_set(amxb_bus_ctx_t *const bus_ctx, const char *object, amxc_var_t *values, amxc_var_t *ret, int timeout)
Sets parameter values of one single object or of multiple instance objects.
amxb_request_t * amxb_async_call(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *method, amxc_var_t *args, amxb_be_done_cb_fn_t done_fn, void *priv)
Invokes a data model function.
int amxb_call(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *method, amxc_var_t *args, amxc_var_t *ret, int timeout)
Invokes a data model function.
int amxb_get_multiple(amxb_bus_ctx_t *const bus_ctx, amxc_var_t *req_paths, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more (root) objects or multiple parameters.
int amxb_get(amxb_bus_ctx_t *const bus_ctx, const char *object, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more objects or a single parameter.
int amxb_get_instances(amxb_bus_ctx_t *const bus_ctx, const char *search_path, int32_t depth, amxc_var_t *ret, int timeout)
Fetches the instances and the unique keys of a multi-instance object.
int amxb_add(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t index, const char *name, amxc_var_t *values, amxc_var_t *ret, int timeout)
Adds an instance to a multi-instance object.
int amxb_list(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
List the service elements/nodes of an object.
int amxb_register(amxb_bus_ctx_t *const ctx, amxd_dm_t *const dm)
Registers a data model to a certain bus context (connection).
A request structure.
Definition: amxb_types.h:138
amxc_var_t * result
Definition: amxb_types.h:140
void test_amxb_set(UNUSED void **state)
void test_amxb_get_instances(UNUSED void **state)
void test_amxb_del(UNUSED void **state)
void test_amxb_list(UNUSED void **state)
static amxd_dm_t dm
void test_amxb_add(UNUSED void **state)
int test_amxb_local_setup(UNUSED void **state)
static amxo_parser_t parser
void test_amxb_subscribe_instance(UNUSED void **state)
void test_amxb_get_multiple(UNUSED void **state)
static void test_request_done_keep(UNUSED const amxb_bus_ctx_t *bus_ctx, amxb_request_t *req, int status, UNUSED void *priv)
void test_search_path_expr_func(UNUSED void **state)
void test_amxb_publish(UNUSED void **state)
void test_amxb_async_call(UNUSED void **state)
static amxb_bus_ctx_t * bus_ctx
void test_amxb_subscribe(UNUSED void **state)
void test_amxb_call(UNUSED void **state)
void test_amxb_get_key_path_reference(UNUSED void **state)
int test_amxb_local_teardown(UNUSED void **state)
static void test_request_done(UNUSED const amxb_bus_ctx_t *bus_ctx, amxb_request_t *req, int status, UNUSED void *priv)
void test_amxb_get(UNUSED void **state)
void test_amxb_subscribe_non_existing(UNUSED void **state)
void test_amxb_subscribe_twice(UNUSED void **state)
static void event_handler(const char *const sig_name, const amxc_var_t *const data, void *const priv)
static void handle_events(void)
void test_amxb_get_reference(UNUSED void **state)
static void test_amxb_list_cb(const amxb_bus_ctx_t *bus_ctx, UNUSED const amxc_var_t *const data, UNUSED void *priv)