Skip to content

Commit

Permalink
tests REFACTOR use macros for all replies
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 28, 2024
1 parent eb7f265 commit dbc9821
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 5 additions & 2 deletions tests/np2_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct np2_test {
} \
assert_null(state->op);

#define ASSERT_OK_REPLY(state) \
ASSERT_OK_REPLY_PARAM(state->nc_sess, 3000, state)

#define ASSERT_DATA_REPLY_PARAM(nc_sess, timeout_ms, state) \
do { \
state->msgtype = nc_recv_reply(nc_sess, state->rpc, state->msgid, timeout_ms, &state->envp, &state->op); \
Expand All @@ -102,8 +105,8 @@ struct np2_test {
} \
assert_int_equal(LY_SUCCESS, lyd_print_mem(&state->str, state->op, LYD_XML, 0));

#define ASSERT_OK_REPLY(state) \
ASSERT_OK_REPLY_PARAM(state->nc_sess, 3000, state)
#define ASSERT_DATA_REPLY(state) \
ASSERT_DATA_REPLY_PARAM(state->nc_sess, 3000, state)

#define ASSERT_OK_REPLY_SESS2(state) \
state->msgtype = nc_recv_reply(state->nc_sess2, state->rpc, state->msgid, 3000, &state->envp, &state->op); \
Expand Down
11 changes: 2 additions & 9 deletions tests/test_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ test_lock_changes(void **state)
NC_RPC_EDIT_ERROPT_ROLLBACK, "<first xmlns=\"ed1\">TestFirst</first>", NC_PARAMTYPE_CONST);
st->msgtype = nc_send_rpc(st->nc_sess2, st->rpc, 1000, &st->msgid);
assert_int_equal(NC_MSG_RPC, st->msgtype);
st->msgtype = nc_recv_reply(st->nc_sess2, st->rpc, st->msgid, 2000, &st->envp, &st->op);
assert_int_equal(st->msgtype, NC_MSG_REPLY);
assert_null(st->op);
assert_string_equal(LYD_NAME(lyd_child(st->envp)), "rpc-error");
ASSERT_ERROR_REPLY_SESS2(st);
FREE_TEST_VARS(st);
}

Expand Down Expand Up @@ -285,11 +282,7 @@ test_get(void **state)
st->rpc = nc_rpc_get(NULL, NC_WD_ALL, NC_PARAMTYPE_CONST);
st->msgtype = nc_send_rpc(st->nc_sess, st->rpc, 1000, &st->msgid);
assert_int_equal(NC_MSG_RPC, st->msgtype);
st->msgtype = nc_recv_reply(st->nc_sess, st->rpc, st->msgid, 2000, &st->envp, &st->op);
assert_int_equal(st->msgtype, NC_MSG_REPLY);
assert_non_null(st->op);
assert_non_null(st->envp);

ASSERT_DATA_REPLY(st);
FREE_TEST_VARS(st);
}

Expand Down

0 comments on commit dbc9821

Please sign in to comment.