libamxd  6.4.1
Data Model Manager
test_amxd_action_object_describe.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 <stdarg.h>
57 #include <stddef.h>
58 #include <setjmp.h>
59 #include <fcntl.h>
60 #include <unistd.h>
61 #include <signal.h>
62 #include <cmocka.h>
63 
64 #include <amxc/amxc.h>
65 #include <amxp/amxp_signal.h>
66 #include <amxp/amxp_slot.h>
67 
68 #include <amxd/amxd_common.h>
69 #include <amxd/amxd_dm.h>
70 #include <amxd/amxd_object.h>
71 #include <amxd/amxd_parameter.h>
72 #include <amxd/amxd_function.h>
73 #include <amxd/amxd_action.h>
74 #include <amxd/amxd_object_event.h>
75 
77 
78 #include <amxc/amxc_macros.h>
79 static amxd_dm_t dm;
80 
82  amxd_object_t* object = NULL;
83  amxd_object_t* template = NULL;
84  amxd_param_t* param = NULL;
85  amxc_var_t* data = NULL;
86  amxc_var_t* sub_data = NULL;
87 
88  amxc_var_new(&data);
89  amxc_var_set_type(data, AMXC_VAR_ID_HTABLE);
90  amxc_var_add_key(cstring_t, data, "Text", "Hello World");
91  amxc_var_add_key(uint32_t, data, "Number", 100);
92  sub_data = amxc_var_add_key(amxc_htable_t, data, "Sub", NULL);
93  amxc_var_add_key(cstring_t, sub_data, "Text", "Hello Universe");
94  amxc_var_add_key(bool, sub_data, "Boolean", true);
95 
96  assert_int_equal(amxd_dm_init(&dm), 0);
97 
98  assert_int_equal(amxd_object_new(&template, amxd_object_template, "parent"), 0);
99  assert_int_equal(amxd_dm_add_root_object(&dm, template), 0);
100  assert_int_equal(amxd_object_new(&object, amxd_object_singleton, "child"), 0);
101  assert_int_equal(amxd_object_add_object(template, object), 0);
102 
103  assert_int_equal(amxd_param_new(&param, "templ_param", AMXC_VAR_ID_CSTRING), 0);
105  assert_int_equal(amxd_object_add_param(template, param), 0);
106  assert_int_equal(amxd_param_new(&param, "inst_param", AMXC_VAR_ID_BOOL), 0);
107  assert_int_equal(amxd_object_add_param(template, param), 0);
108  assert_int_equal(amxd_param_new(&param, "param", AMXC_VAR_ID_UINT32), 0);
111  assert_int_equal(amxd_object_add_param(template, param), 0);
112  assert_int_equal(amxd_object_add_event(template, "MyEvent1!"), 0);
113  assert_int_equal(amxd_object_add_event_ext(template, "MyEvent2!", data), 0);
114 
115  assert_int_equal(amxd_param_new(&param, "child_param", AMXC_VAR_ID_CSTRING), 0);
117  assert_int_equal(amxd_object_add_param(object, param), 0);
118  assert_int_equal(amxd_param_new(&param, "child_param2", AMXC_VAR_ID_BOOL), 0);
119  assert_int_equal(amxd_object_add_param(object, param), 0);
120  assert_int_equal(amxd_param_new(&param, "child_param3", AMXC_VAR_ID_UINT64), 0);
121  assert_int_equal(amxd_object_add_param(object, param), 0);
122 
123  assert_int_equal(amxd_object_new(&object, amxd_object_singleton, "PChild"), 0);
124  assert_int_equal(amxd_object_set_attr(object, amxd_oattr_protected, true), 0);
125  assert_int_equal(amxd_object_add_object(template, object), 0);
126 
127  return template;
128 }
129 
130 void test_amxd_object_describe(UNUSED void** state) {
131  amxd_object_t* template = NULL;
132  amxd_object_t* instance = NULL;
133  amxc_var_t retval;
134  amxc_var_t args;
135 
136  amxc_var_init(&retval);
137  amxc_var_init(&args);
138 
139  template = test_build_dm();
140  assert_int_equal(amxd_object_new_instance(&instance, template, NULL, 0, NULL), 0);
141  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
142  amxc_var_add_key(uint32_t, &args, "access", amxd_dm_access_public);
143  assert_int_equal(amxd_action_object_describe(template, NULL, action_object_describe, &args, &retval, NULL), 0);
144  assert_int_equal(amxc_var_type_of(&retval), AMXC_VAR_ID_HTABLE);
145  amxc_var_dump(&retval, STDOUT_FILENO);
146 
147  assert_ptr_not_equal(amxc_var_get_path(&retval, "name", AMXC_VAR_FLAG_DEFAULT), NULL);
148  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
149  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
150  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
151  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
152  assert_ptr_not_equal(amxc_var_get_path(&retval, "type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
153  assert_ptr_not_equal(amxc_var_get_path(&retval, "type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
154  assert_ptr_not_equal(amxc_var_get_path(&retval, "path", AMXC_VAR_FLAG_DEFAULT), NULL);
155  assert_ptr_not_equal(amxc_var_get_path(&retval, "object", AMXC_VAR_FLAG_DEFAULT), NULL);
156  assert_ptr_equal(amxc_var_get_path(&retval, "index", AMXC_VAR_FLAG_DEFAULT), NULL);
157  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param", AMXC_VAR_FLAG_DEFAULT), NULL);
158  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
159  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
160  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
161  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
162  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
163  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
164  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
165  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
166  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
167  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
168  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
169  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.templ_param", AMXC_VAR_FLAG_DEFAULT), NULL);
170  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
171  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
172  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
173  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
174  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
175  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
176  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
177  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
178  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
179  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
180  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
181  assert_ptr_not_equal(amxc_var_get_path(&retval, "events.'MyEvent1!'", AMXC_VAR_FLAG_DEFAULT), NULL);
182  assert_ptr_not_equal(amxc_var_get_path(&retval, "events.'MyEvent2!'", AMXC_VAR_FLAG_DEFAULT), NULL);
183  assert_ptr_equal(amxc_var_get_path(&retval, "objects", AMXC_VAR_FLAG_DEFAULT), NULL);
184 
185  amxc_var_clean(&retval);
186  assert_int_equal(amxd_action_object_describe(instance, NULL, action_object_describe, NULL, &retval, NULL), 0);
187  assert_int_equal(amxc_var_type_of(&retval), AMXC_VAR_ID_HTABLE);
188  amxc_var_dump(&retval, STDOUT_FILENO);
189 
190  assert_ptr_not_equal(amxc_var_get_path(&retval, "name", AMXC_VAR_FLAG_DEFAULT), NULL);
191  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
192  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
193  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
194  assert_ptr_not_equal(amxc_var_get_path(&retval, "attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
195  assert_ptr_not_equal(amxc_var_get_path(&retval, "type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
196  assert_ptr_not_equal(amxc_var_get_path(&retval, "type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
197  assert_ptr_not_equal(amxc_var_get_path(&retval, "path", AMXC_VAR_FLAG_DEFAULT), NULL);
198  assert_ptr_not_equal(amxc_var_get_path(&retval, "object", AMXC_VAR_FLAG_DEFAULT), NULL);
199  assert_ptr_not_equal(amxc_var_get_path(&retval, "index", AMXC_VAR_FLAG_DEFAULT), NULL);
200  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param", AMXC_VAR_FLAG_DEFAULT), NULL);
201  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
202  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
203  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
204  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
205  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
206  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
207  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
208  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
209  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
210  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
211  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
212  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.inst_param", AMXC_VAR_FLAG_DEFAULT), NULL);
213  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
214  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
215  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
216  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
217  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
218  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
219  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
220  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
221  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
222  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
223  assert_ptr_not_equal(amxc_var_get_path(&retval, "parameters.param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
224  assert_ptr_not_equal(amxc_var_get_path(&retval, "events.'MyEvent1!'", AMXC_VAR_FLAG_DEFAULT), NULL);
225  assert_ptr_not_equal(amxc_var_get_path(&retval, "events.'MyEvent2!'", AMXC_VAR_FLAG_DEFAULT), NULL);
226  assert_ptr_not_equal(amxc_var_get_path(&retval, "objects'", AMXC_VAR_FLAG_DEFAULT), NULL);
227  assert_ptr_not_equal(amxc_var_get_path(&retval, "objects.0", AMXC_VAR_FLAG_DEFAULT), NULL);
228 
229  assert_int_not_equal(amxd_action_object_describe(NULL, NULL, action_object_describe, NULL, &retval, NULL), 0);
230  assert_int_not_equal(amxd_action_object_describe(template, NULL, action_object_describe, NULL, NULL, NULL), 0);
231  assert_int_not_equal(amxd_action_object_describe(template, NULL, action_object_read, NULL, &retval, NULL), 0);
232 
233  amxc_var_clean(&retval);
234  assert_int_equal(amxd_object_describe(template, &retval, AMXD_OBJECT_ALL, amxd_dm_access_protected), 0);
235  assert_int_equal(amxc_var_type_of(&retval), AMXC_VAR_ID_HTABLE);
236 
237  assert_int_not_equal(amxd_object_describe(NULL, &retval, AMXD_OBJECT_ALL, amxd_dm_access_protected), 0);
238  assert_int_not_equal(amxd_object_describe(template, NULL, AMXD_OBJECT_ALL, amxd_dm_access_protected), 0);
239 
240  amxc_var_clean(&retval);
241  amxc_var_clean(&args);
242  amxd_dm_clean(&dm);
243 }
244 
245 void test_amxd_object_describe_params(UNUSED void** state) {
246  amxd_object_t* template = NULL;
247  amxd_object_t* instance = NULL;
248  amxc_var_t retval;
249 
250  amxc_var_init(&retval);
251 
252  template = test_build_dm();
253  assert_int_equal(amxd_object_new_instance(&instance, template, NULL, 0, NULL), 0);
254 
255  assert_int_equal(amxd_object_describe_params(template, &retval, amxd_dm_access_protected), 0);
256  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param", AMXC_VAR_FLAG_DEFAULT), NULL);
257  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
258  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
259  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
260  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
261  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
262  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
263  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
264  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
265  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
266  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
267  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
268  assert_ptr_not_equal(amxc_var_get_path(&retval, "templ_param", AMXC_VAR_FLAG_DEFAULT), NULL);
269  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
270  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
271  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
272  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
273  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
274  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
275  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
276  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
277  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
278  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
279  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
280 
281  assert_int_equal(amxd_object_describe_params(instance, &retval, amxd_dm_access_protected), 0);
282  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param", AMXC_VAR_FLAG_DEFAULT), NULL);
283  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
284  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
285  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
286  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
287  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
288  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
289  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
290  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
291  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
292  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
293  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
294  assert_ptr_not_equal(amxc_var_get_path(&retval, "inst_param", AMXC_VAR_FLAG_DEFAULT), NULL);
295  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
296  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
297  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
298  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
299  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.read-only", AMXC_VAR_FLAG_DEFAULT), NULL);
300  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.volatile", AMXC_VAR_FLAG_DEFAULT), NULL);
301  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.attributes.persistent", AMXC_VAR_FLAG_DEFAULT), NULL);
302  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.name", AMXC_VAR_FLAG_DEFAULT), NULL);
303  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.value", AMXC_VAR_FLAG_DEFAULT), NULL);
304  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
305  assert_ptr_not_equal(amxc_var_get_path(&retval, "param.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
306 
307  assert_int_not_equal(amxd_object_describe_params(NULL, &retval, amxd_dm_access_protected), 0);
308  assert_int_not_equal(amxd_object_describe_params(instance, NULL, amxd_dm_access_protected), 0);
309 
310  amxc_var_clean(&retval);
311  amxd_dm_clean(&dm);
312 }
313 
314 void test_amxd_object_describe_functions(UNUSED void** state) {
315  amxd_object_t* template = NULL;
316  amxd_object_t* instance = NULL;
317  amxc_var_t retval;
318  amxc_var_t args;
319 
320  amxc_var_init(&retval);
321  amxc_var_init(&args);
322 
323  template = test_build_dm();
324  assert_int_equal(amxd_object_new_instance(&instance, template, NULL, 0, NULL), 0);
325  assert_int_equal(amxd_object_new_instance(&instance, template, NULL, 0, NULL), 0);
326  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
327  amxc_var_add_key(uint32_t, &args, "access", amxd_dm_access_protected);
328 
329  assert_int_equal(amxd_object_describe_functions(template, &retval, amxd_dm_access_protected), 0);
330 
331  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get", AMXC_VAR_FLAG_DEFAULT), NULL);
332  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
333  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
334  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
335  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
336  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.name", AMXC_VAR_FLAG_DEFAULT), NULL);
337  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
338  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
339  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments", AMXC_VAR_FLAG_DEFAULT), NULL);
340  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0", AMXC_VAR_FLAG_DEFAULT), NULL);
341  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
342  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.attributes.out", AMXC_VAR_FLAG_DEFAULT), NULL);
343  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.attributes.in", AMXC_VAR_FLAG_DEFAULT), NULL);
344  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.attributes.mandatory", AMXC_VAR_FLAG_DEFAULT), NULL);
345  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.attributes.strict", AMXC_VAR_FLAG_DEFAULT), NULL);
346  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.name", AMXC_VAR_FLAG_DEFAULT), NULL);
347  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
348  assert_ptr_not_equal(amxc_var_get_path(&retval, "_get.arguments.0.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
349 
350  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set", AMXC_VAR_FLAG_DEFAULT), NULL);
351  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
352  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.attributes.private", AMXC_VAR_FLAG_DEFAULT), NULL);
353  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.attributes.instance", AMXC_VAR_FLAG_DEFAULT), NULL);
354  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.attributes.template", AMXC_VAR_FLAG_DEFAULT), NULL);
355  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.name", AMXC_VAR_FLAG_DEFAULT), NULL);
356  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
357  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
358  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments", AMXC_VAR_FLAG_DEFAULT), NULL);
359  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0", AMXC_VAR_FLAG_DEFAULT), NULL);
360  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.attributes", AMXC_VAR_FLAG_DEFAULT), NULL);
361  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.attributes.out", AMXC_VAR_FLAG_DEFAULT), NULL);
362  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.attributes.in", AMXC_VAR_FLAG_DEFAULT), NULL);
363  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.attributes.mandatory", AMXC_VAR_FLAG_DEFAULT), NULL);
364  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.attributes.strict", AMXC_VAR_FLAG_DEFAULT), NULL);
365  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.name", AMXC_VAR_FLAG_DEFAULT), NULL);
366  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.type_id", AMXC_VAR_FLAG_DEFAULT), NULL);
367  assert_ptr_not_equal(amxc_var_get_path(&retval, "_set.arguments.0.type_name", AMXC_VAR_FLAG_DEFAULT), NULL);
368 
369  assert_int_not_equal(amxd_object_describe_functions(NULL, &retval, amxd_dm_access_protected), 0);
370  assert_int_not_equal(amxd_object_describe_functions(instance, NULL, amxd_dm_access_protected), 0);
371 
372  amxc_var_clean(&args);
373  amxc_var_clean(&retval);
374  amxd_dm_clean(&dm);
375 }
376 
377 void test_amxd_object_describe_events(UNUSED void** state) {
378  amxd_object_t* template = NULL;
379  amxd_object_t* instance = NULL;
380  amxc_var_t retval;
381 
382  amxc_var_init(&retval);
383 
384  template = test_build_dm();
385  assert_int_equal(amxd_object_new_instance(&instance, template, NULL, 0, NULL), 0);
386 
387  assert_int_equal(amxd_object_describe_events(template, &retval, amxd_dm_access_protected), 0);
388  amxc_var_dump(&retval, STDOUT_FILENO);
389  assert_ptr_not_equal(amxc_var_get_path(&retval, "MyEvent1!", AMXC_VAR_FLAG_DEFAULT), NULL);
390  assert_ptr_equal(amxc_var_get_path(&retval, "'MyEvent1!'.0", AMXC_VAR_FLAG_DEFAULT), NULL);
391  assert_ptr_not_equal(amxc_var_get_path(&retval, "MyEvent2!", AMXC_VAR_FLAG_DEFAULT), NULL);
392  assert_ptr_not_equal(amxc_var_get_path(&retval, "'MyEvent2!'.0", AMXC_VAR_FLAG_DEFAULT), NULL);
393  assert_ptr_not_equal(amxc_var_get_path(&retval, "'MyEvent2!'.1", AMXC_VAR_FLAG_DEFAULT), NULL);
394  assert_ptr_not_equal(amxc_var_get_path(&retval, "'MyEvent2!'.2", AMXC_VAR_FLAG_DEFAULT), NULL);
395  assert_ptr_not_equal(amxc_var_get_path(&retval, "'MyEvent2!'.3", AMXC_VAR_FLAG_DEFAULT), NULL);
396  assert_ptr_equal(amxc_var_get_path(&retval, "'MyEvent2!'.4", AMXC_VAR_FLAG_DEFAULT), NULL);
397 
398  assert_int_equal(amxd_object_describe_events(instance, &retval, amxd_dm_access_protected), 0);
399  assert_ptr_not_equal(amxc_var_get_path(&retval, "MyEvent1!", AMXC_VAR_FLAG_DEFAULT), NULL);
400  assert_ptr_not_equal(amxc_var_get_path(&retval, "MyEvent2!", AMXC_VAR_FLAG_DEFAULT), NULL);
401 
402  assert_int_not_equal(amxd_object_describe_events(NULL, &retval, amxd_dm_access_protected), 0);
403  assert_int_not_equal(amxd_object_describe_events(instance, NULL, amxd_dm_access_protected), 0);
404 
405  amxc_var_clean(&retval);
406  amxd_dm_clean(&dm);
407 }
Ambiorix Data Model Default actions header file.
Ambiorix Data Model API header file.
Ambiorix Data Model RPC methods API header file.
Ambiorix Data Model API header file.
amxd_status_t amxd_object_describe(amxd_object_t *const object, amxc_var_t *const value, uint32_t flags, amxd_dm_access_t access)
Ambiorix Data Model API header file.
amxd_status_t amxd_object_describe_events(amxd_object_t *const object, amxc_var_t *const value, amxd_dm_access_t access)
amxd_status_t amxd_object_describe_params(amxd_object_t *const object, amxc_var_t *const value, amxd_dm_access_t access)
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)
@ amxd_pattr_template
Definition: amxd_types.h:355
@ amxd_pattr_private
Definition: amxd_types.h:357
@ amxd_pattr_instance
Definition: amxd_types.h:356
@ action_object_describe
Definition: amxd_types.h:121
@ action_object_read
Definition: amxd_types.h:117
#define AMXD_OBJECT_ALL
List and describe flag.
Definition: amxd_object.h:328
@ amxd_oattr_protected
Definition: amxd_types.h:210
@ amxd_dm_access_protected
Definition: amxd_types.h:139
@ amxd_dm_access_public
Definition: amxd_types.h:136
@ amxd_object_template
Definition: amxd_types.h:183
@ amxd_object_singleton
Definition: amxd_types.h:181
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.
Definition: amxd_dm.c:418
amxd_status_t amxd_dm_init(amxd_dm_t *dm)
Initializes a data model structure.
Definition: amxd_dm.c:334
void amxd_dm_clean(amxd_dm_t *dm)
Cleans a data model structure.
Definition: amxd_dm.c:365
amxd_status_t amxd_action_object_describe(amxd_object_t *object, amxd_param_t *param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval, void *priv)
Default object describe action implementation.
amxd_status_t amxd_object_add_event_ext(amxd_object_t *const object, const char *event_name, amxc_var_t *event_data)
Adds an event definition to the object.
amxd_status_t amxd_object_add_event(amxd_object_t *const object, const char *event_name)
Adds an event definition to the 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.
Definition: amxd_object.c:207
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_describe_functions(amxd_object_t *const object, amxc_var_t *const value, amxd_dm_access_t access)
Fetches the full object RPC method definitions in a variant.
amxd_status_t amxd_object_set_attr(amxd_object_t *const object, const amxd_oattr_id_t attr, const bool enable)
Sets or unsets an object attribute.
Definition: amxd_object.c:269
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.
Definition: amxd_object.c:185
static amxd_dm_t dm
void test_amxd_object_describe_params(UNUSED void **state)
void test_amxd_object_describe_functions(UNUSED void **state)
void test_amxd_object_describe_events(UNUSED void **state)
void test_amxd_object_describe(UNUSED void **state)
static amxd_object_t * test_build_dm(void)