libamxs  0.6.0
Data Model Synchronization C API
test_amxs_sync_start.c File Reference
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <setjmp.h>
#include <cmocka.h>
#include <amxc/amxc_variant.h>
#include <amxc/amxc_htable.h>
#include <amxc/amxc_lqueue.h>
#include <amxp/amxp_signal.h>
#include <amxp/amxp_slot.h>
#include <amxd/amxd_dm.h>
#include <amxo/amxo.h>
#include <amxs/amxs.h>
#include <amxc/amxc_macros.h>
#include "test_amxs_sync_start.h"
#include "dummy_be.h"

Go to the source code of this file.

Functions

int test_amxs_sync_setup (UNUSED void **state)
 
int test_amxs_sync_teardown (UNUSED void **state)
 
void test_amxs_sync_start_args (UNUSED void **state)
 
void test_amxs_sync_stop_args (UNUSED void **state)
 
void test_amxs_sync_start_param (UNUSED void **state)
 
void test_amxs_sync_start_object (UNUSED void **state)
 
void test_amxs_sync_start_template_object (UNUSED void **state)
 
void test_amxs_sync_start_multiple_objects (UNUSED void **state)
 
void test_amxs_sync_start_instance_object_search_path (UNUSED void **state)
 
void test_amxs_sync_start_copied (UNUSED void **state)
 
void test_amxs_sync_start_copied_change_paths (UNUSED void **state)
 

Variables

static amxb_bus_ctx_t * bus_ctx = NULL
 

Function Documentation

◆ test_amxs_sync_setup()

int test_amxs_sync_setup ( UNUSED void **  state)

Definition at line 83 of file test_amxs_sync_start.c.

83  {
84  assert_int_equal(test_register_dummy_be(), 0);
85  assert_int_equal(amxb_connect(&bus_ctx, "dummy:/tmp/dummy.sock"), 0);
86  assert_int_equal(test_load_dummy_remote("a.odl"), 0);
87  assert_int_equal(test_load_dummy_remote("b.odl"), 0);
88 
89  return 0;
90 }
int test_load_dummy_remote(const char *odl)
Definition: dummy_be.c:254
int test_register_dummy_be(void)
Definition: dummy_be.c:244
static amxb_bus_ctx_t * bus_ctx

◆ test_amxs_sync_start_args()

void test_amxs_sync_start_args ( UNUSED void **  state)

Definition at line 100 of file test_amxs_sync_start.c.

100  {
101  amxs_sync_ctx_t* ctx = NULL;
102 
103  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
104  assert_int_not_equal(amxs_sync_ctx_start_sync(NULL), 0);
105  assert_int_not_equal(amxs_sync_ctx_start_sync(ctx), 0);
106  amxs_sync_ctx_delete(&ctx);
107 }
#define AMXS_SYNC_DEFAULT
Default synchronization attributes.
Definition: amxs_types.h:190
amxs_status_t amxs_sync_ctx_new(amxs_sync_ctx_t **ctx, const char *object_a, const char *object_b, int attributes)
Synchronization context constructor function.
amxs_status_t amxs_sync_ctx_start_sync(amxs_sync_ctx_t *ctx)
Starts the object synchronization.
void amxs_sync_ctx_delete(amxs_sync_ctx_t **ctx)
Synchronization context destructor function.
Definition: amxs_types.h:161

◆ test_amxs_sync_start_copied()

void test_amxs_sync_start_copied ( UNUSED void **  state)

Definition at line 282 of file test_amxs_sync_start.c.

282  {
283  amxs_sync_ctx_t* ctx = NULL;
284  amxs_sync_ctx_t* copy_ctx = NULL;
285  amxs_sync_object_t* object = NULL;
286 
287  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
288  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
289  assert_int_equal(amxs_sync_object_new(&object, "A_template.", "B_template.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
290  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
291  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
292  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
293  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
294  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
295 
296  assert_int_equal(amxs_sync_ctx_copy(&copy_ctx, ctx, NULL), 0);
297 
298  assert_int_equal(amxs_sync_ctx_start_sync(copy_ctx), 0);
299  assert_true(amxs_sync_ctx_is_started(copy_ctx));
300  amxs_sync_ctx_stop_sync(copy_ctx);
301  assert_false(amxs_sync_ctx_is_started(copy_ctx));
302 
303  amxs_sync_ctx_delete(&ctx);
304  amxs_sync_ctx_delete(&copy_ctx);
305 }
amxs_status_t amxs_sync_object_new(amxs_sync_object_t **object, const char *object_a, const char *object_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Synchronization object constructor function.
amxs_status_t amxs_sync_object_add_new_param(amxs_sync_object_t *object, const char *param_a, const char *param_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Creates and adds a synchronization parameter to a synchronization object.
amxs_status_t amxs_sync_ctx_copy(amxs_sync_ctx_t **dest, amxs_sync_ctx_t *src, void *priv)
Copies an existing synchronization context to a new synchronization context.
amxs_status_t amxs_sync_ctx_add_new_param(amxs_sync_ctx_t *ctx, const char *param_a, const char *param_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Creates and adds a synchronization parameter to a synchronization context.
static bool amxs_sync_ctx_is_started(const amxs_sync_ctx_t *const ctx)
Checks is the synchronization context is running.
amxs_status_t amxs_sync_ctx_add_object(amxs_sync_ctx_t *ctx, amxs_sync_object_t *object)
Adds a synchronization object to a synchronization context.
void amxs_sync_ctx_stop_sync(amxs_sync_ctx_t *ctx)
Stops the object synchronization.

◆ test_amxs_sync_start_copied_change_paths()

void test_amxs_sync_start_copied_change_paths ( UNUSED void **  state)

Definition at line 307 of file test_amxs_sync_start.c.

307  {
308  amxs_sync_ctx_t* ctx = NULL;
309  amxs_sync_ctx_t* copy_ctx = NULL;
310 
311  assert_int_equal(amxs_sync_ctx_new(&ctx,
312  "A.A_template.{i}.",
313  "B.B_template.{i}.",
315  0);
316  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
317 
318  assert_int_equal(amxs_sync_ctx_copy(&copy_ctx, ctx, NULL), 0);
319  assert_int_equal(amxs_sync_ctx_set_paths(copy_ctx,
320  "A.A_template.[param_A == 1337].",
321  "B.B_template.[param_B == 42]."), 0);
322 
323  assert_int_equal(amxs_sync_ctx_start_sync(copy_ctx), 0);
324  assert_true(amxs_sync_ctx_is_started(copy_ctx));
325  amxs_sync_ctx_stop_sync(copy_ctx);
326  assert_false(amxs_sync_ctx_is_started(copy_ctx));
327 
328  amxs_sync_ctx_delete(&ctx);
329  amxs_sync_ctx_delete(&copy_ctx);
330 }
amxs_status_t amxs_sync_ctx_set_paths(amxs_sync_ctx_t *const ctx, const char *object_a, const char *object_b)
Updates the object paths of the synchronization context.

◆ test_amxs_sync_start_instance_object_search_path()

void test_amxs_sync_start_instance_object_search_path ( UNUSED void **  state)

Definition at line 254 of file test_amxs_sync_start.c.

254  {
255  amxs_sync_ctx_t* ctx = NULL;
256 
257  assert_int_equal(amxs_sync_ctx_new(&ctx,
258  "A.A_template.[param_A == 1337].",
259  "B.B_template.[param_B == 42].",
261  0);
262  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
263  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
264  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
265  assert_string_equal(ctx->a, "A.A_template.1.");
266  assert_string_equal(ctx->b, "B.B_template.1.");
268  amxs_sync_ctx_delete(&ctx);
269 
270  assert_int_equal(amxs_sync_ctx_new(&ctx,
271  "A.A_template.[nonexistent == 1337].",
272  "B.B_template.[param_B == 42].",
274  0);
275  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
277  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 0);
279  amxs_sync_ctx_delete(&ctx);
280 }
@ amxs_status_object_not_found
Definition: amxs_types.h:93
char * a
Definition: amxs_types.h:163
amxc_llist_t subscriptions
Definition: amxs_types.h:173
char * b
Definition: amxs_types.h:164

◆ test_amxs_sync_start_multiple_objects()

void test_amxs_sync_start_multiple_objects ( UNUSED void **  state)

Definition at line 236 of file test_amxs_sync_start.c.

236  {
237  amxs_sync_ctx_t* ctx = NULL;
238  amxs_sync_object_t* object = NULL;
239 
240  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
241  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
242  assert_int_equal(amxs_sync_object_new(&object, "A_template.", "B_template.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
243  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
244  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
245  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
246  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
247  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
248  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
249  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 10);
251  amxs_sync_ctx_delete(&ctx);
252 }

◆ test_amxs_sync_start_object()

void test_amxs_sync_start_object ( UNUSED void **  state)

Definition at line 154 of file test_amxs_sync_start.c.

154  {
155  amxs_sync_ctx_t* ctx = NULL;
156  amxs_sync_object_t* object = NULL;
157 
158  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
159  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
160  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
161  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
162  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
163  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 4);
165  amxs_sync_ctx_delete(&ctx);
166 
167  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
168  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
169  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_ONLY_A_TO_B, NULL, NULL, NULL), 0);
170  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
171  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
172  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 3);
174  amxs_sync_ctx_delete(&ctx);
175 
176  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
177  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
178  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_INIT_B, NULL, NULL, NULL), 0);
179  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
180  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
181  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 3);
183  amxs_sync_ctx_delete(&ctx);
184 
185  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
186  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_ONLY_A_TO_B, NULL, NULL, NULL), 0);
187  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
188  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
189  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
190  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
192  amxs_sync_ctx_delete(&ctx);
193 
194  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
195  assert_int_equal(amxs_sync_object_new(&object, "object_A.", "object_B.", AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_INIT_B, NULL, NULL, NULL), 0);
196  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
197  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
198  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
199  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
201  amxs_sync_ctx_delete(&ctx);
202 }
#define AMXS_SYNC_INIT_B
Take the initial values from object B.
Definition: amxs_types.h:205
#define AMXS_SYNC_ONLY_B_TO_A
Only synchronize from object B to object A.
Definition: amxs_types.h:195
#define AMXS_SYNC_ONLY_A_TO_B
Only synchronize from object A to object B.
Definition: amxs_types.h:200

◆ test_amxs_sync_start_param()

void test_amxs_sync_start_param ( UNUSED void **  state)

Definition at line 119 of file test_amxs_sync_start.c.

119  {
120  amxs_sync_ctx_t* ctx = NULL;
121 
122  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
123  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
124  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
125  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
127  amxs_sync_ctx_delete(&ctx);
128 
129  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT | AMXS_SYNC_INIT_B), 0);
130  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
131  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
132  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
134  amxs_sync_ctx_delete(&ctx);
135 
136  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", NULL, AMXS_SYNC_ONLY_A_TO_B), 0);
137  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
138  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
139  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 1);
141  amxs_sync_ctx_delete(&ctx);
142 
143  assert_int_equal(amxs_sync_ctx_new(&ctx, NULL, "B.", AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_INIT_B), 0);
144  assert_int_equal(amxs_sync_ctx_add_new_param(ctx, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
145  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
146  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 1);
148  amxs_sync_ctx_delete(&ctx);
149 
150  assert_int_equal(amxs_sync_ctx_new(&ctx, NULL, NULL, AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_INIT_B), 3);
151  assert_null(ctx);
152 }

◆ test_amxs_sync_start_template_object()

void test_amxs_sync_start_template_object ( UNUSED void **  state)

Definition at line 204 of file test_amxs_sync_start.c.

204  {
205  amxs_sync_ctx_t* ctx = NULL;
206  amxs_sync_object_t* object = NULL;
207 
208  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
209  assert_int_equal(amxs_sync_object_new(&object, "A_template.", "B_template.", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
210  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
211  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
212  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
213  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 4);
215  amxs_sync_ctx_delete(&ctx);
216 
217  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
218  assert_int_equal(amxs_sync_object_new(&object, "A_template.", "B_template.", AMXS_SYNC_ONLY_A_TO_B, NULL, NULL, NULL), 0);
219  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
220  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
221  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
222  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
224  amxs_sync_ctx_delete(&ctx);
225 
226  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
227  assert_int_equal(amxs_sync_object_new(&object, "A_template.", "B_template.", AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_INIT_B, NULL, NULL, NULL), 0);
228  assert_int_equal(amxs_sync_object_add_new_param(object, "param_A", "param_B", AMXS_SYNC_DEFAULT, NULL, NULL, NULL), 0);
229  assert_int_equal(amxs_sync_ctx_add_object(ctx, object), 0);
230  assert_int_equal(amxs_sync_ctx_start_sync(ctx), 0);
231  assert_int_equal(amxc_llist_size(&ctx->subscriptions), 2);
233  amxs_sync_ctx_delete(&ctx);
234 }

◆ test_amxs_sync_stop_args()

void test_amxs_sync_stop_args ( UNUSED void **  state)

Definition at line 109 of file test_amxs_sync_start.c.

109  {
110  amxs_sync_ctx_t* ctx = NULL;
111 
112  assert_int_equal(amxs_sync_ctx_new(&ctx, "A.", "B.", AMXS_SYNC_DEFAULT), 0);
116  amxs_sync_ctx_delete(&ctx);
117 }

◆ test_amxs_sync_teardown()

int test_amxs_sync_teardown ( UNUSED void **  state)

Definition at line 92 of file test_amxs_sync_start.c.

92  {
93  amxb_disconnect(bus_ctx);
94  amxb_free(&bus_ctx);
95  assert_int_equal(test_unregister_dummy_be(), 0);
96 
97  return 0;
98 }
int test_unregister_dummy_be(void)
Definition: dummy_be.c:249

Variable Documentation

◆ bus_ctx

amxb_bus_ctx_t* bus_ctx = NULL
static

Definition at line 81 of file test_amxs_sync_start.c.