Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include <setjmp.h> |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 5 | #include <string.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 6 | #include <sys/socket.h> |
| 7 | #include <sys/types.h> |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 8 | |
| 9 | #include <cmocka.h> |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 10 | #include <config.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 11 | #include <libyang/libyang.h> |
| 12 | #include <log.h> |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 13 | #include <messages_p.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 14 | #include <session_client.h> |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 15 | #include "tests/config.h" |
| 16 | |
| 17 | static int |
| 18 | setup_f(void **state) |
| 19 | { |
| 20 | (void)state; |
| 21 | |
| 22 | nc_verbosity(NC_VERB_VERBOSE); |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | static int |
| 28 | teardown_f(void **state) |
| 29 | { |
| 30 | (void)state; |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
David Sedlák | 2f2f2e3 | 2018-10-08 21:49:32 +0200 | [diff] [blame] | 35 | static void |
| 36 | test_nc_rpc_act_generic_xml(void **state) |
| 37 | { |
| 38 | (void)state; |
| 39 | struct nc_rpc *rpc = NULL; |
| 40 | struct nc_rpc_act_generic *generic_rpc = NULL; |
| 41 | |
| 42 | /* create generic rpc with NC_PARAMTYPE_CONST */ |
| 43 | rpc = nc_rpc_act_generic_xml("xml", NC_PARAMTYPE_CONST); |
| 44 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC); |
| 45 | generic_rpc = (struct nc_rpc_act_generic *)rpc; |
| 46 | assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC); |
| 47 | assert_int_equal(generic_rpc->has_data, 0); |
| 48 | assert_string_equal(generic_rpc->content.xml_str, "xml"); |
| 49 | nc_rpc_free(rpc); |
| 50 | |
| 51 | /* create generic rpc with NC_PARAMTYPE_FREE */ |
| 52 | char *str = strdup("str"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 53 | |
David Sedlák | 2f2f2e3 | 2018-10-08 21:49:32 +0200 | [diff] [blame] | 54 | rpc = nc_rpc_act_generic_xml(str, NC_PARAMTYPE_FREE); |
| 55 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC); |
| 56 | generic_rpc = (struct nc_rpc_act_generic *)rpc; |
| 57 | assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC); |
| 58 | assert_int_equal(generic_rpc->has_data, 0); |
| 59 | assert_string_equal(generic_rpc->content.xml_str, str); |
| 60 | nc_rpc_free(rpc); |
| 61 | |
| 62 | /* create generic rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 63 | rpc = nc_rpc_act_generic_xml("xml", NC_PARAMTYPE_DUP_AND_FREE); |
| 64 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC); |
| 65 | generic_rpc = (struct nc_rpc_act_generic *)rpc; |
| 66 | assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC); |
| 67 | assert_int_equal(generic_rpc->has_data, 0); |
| 68 | assert_string_equal(generic_rpc->content.xml_str, "xml"); |
| 69 | nc_rpc_free(rpc); |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | test_nc_rpc_act_generic(void **state) |
| 74 | { |
| 75 | (void)state; |
| 76 | struct nc_rpc *rpc = NULL; |
| 77 | struct nc_rpc_act_generic *generic_rpc = NULL; |
| 78 | struct lyd_node node; |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 79 | |
David Sedlák | 2f2f2e3 | 2018-10-08 21:49:32 +0200 | [diff] [blame] | 80 | node.next = NULL; |
| 81 | node.prev = &node; |
| 82 | |
| 83 | rpc = nc_rpc_act_generic(&node, NC_PARAMTYPE_CONST); |
| 84 | assert_non_null(rpc); |
| 85 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC); |
| 86 | generic_rpc = (struct nc_rpc_act_generic *)rpc; |
| 87 | assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC); |
| 88 | assert_int_equal(generic_rpc->has_data, 1); |
| 89 | assert_ptr_equal(generic_rpc->content.data, &node); |
| 90 | nc_rpc_free(rpc); |
| 91 | } |
| 92 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 93 | /* function to check if values of getconfig rpc are set correctly */ |
| 94 | void |
| 95 | check_getconfig(struct nc_rpc *rpc, enum NC_DATASTORE_TYPE source, char *filter, NC_WD_MODE wd_mode) |
| 96 | { |
| 97 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GETCONFIG); |
| 98 | struct nc_rpc_getconfig *getconfig_rpc = (struct nc_rpc_getconfig *)rpc; |
| 99 | |
| 100 | assert_int_equal(getconfig_rpc->type, NC_RPC_GETCONFIG); |
| 101 | assert_int_equal(getconfig_rpc->source, source); |
| 102 | assert_string_equal(getconfig_rpc->filter, filter); |
| 103 | assert_int_equal(getconfig_rpc->wd_mode, wd_mode); |
| 104 | } |
| 105 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 106 | static void |
| 107 | test_nc_rpc_getconfig(void **state) |
| 108 | { |
| 109 | (void)state; |
| 110 | struct nc_rpc *rpc = NULL; |
| 111 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 112 | /* create getconfig rpc with NC_PARAMTYPE_CONST */ |
| 113 | rpc = nc_rpc_getconfig(NC_DATASTORE_CANDIDATE, "filter-string", NC_WD_UNKNOWN, NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 114 | assert_non_null(rpc); |
Michal Vasko | 79142c2 | 2020-07-29 15:26:51 +0200 | [diff] [blame] | 115 | check_getconfig(rpc, NC_DATASTORE_CANDIDATE, "filter-string", NC_WD_UNKNOWN); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 116 | nc_rpc_free(rpc); |
| 117 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 118 | /* create getconfig rpc with NC_PARAMTYPE_FREE */ |
| 119 | char *filter = strdup("string"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 120 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 121 | rpc = nc_rpc_getconfig(NC_DATASTORE_CONFIG, filter, NC_WD_EXPLICIT, NC_PARAMTYPE_FREE); |
| 122 | assert_non_null(rpc); |
| 123 | check_getconfig(rpc, NC_DATASTORE_CONFIG, filter, NC_WD_EXPLICIT); |
| 124 | nc_rpc_free(rpc); |
| 125 | |
| 126 | /* create getconfig rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 127 | rpc = nc_rpc_getconfig(NC_DATASTORE_RUNNING, "filter", NC_WD_ALL, NC_PARAMTYPE_DUP_AND_FREE); |
| 128 | assert_non_null(rpc); |
| 129 | check_getconfig(rpc, NC_DATASTORE_RUNNING, "filter", NC_WD_ALL); |
| 130 | nc_rpc_free(rpc); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 131 | } |
| 132 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 133 | /* function to check if values of edit rpc are set correctly */ |
| 134 | void |
| 135 | check_edit(struct nc_rpc *rpc, NC_DATASTORE target, NC_RPC_EDIT_DFLTOP default_op, NC_RPC_EDIT_TESTOPT test_opt, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 136 | NC_RPC_EDIT_ERROPT error_opt, const char *edit_content) |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 137 | { |
| 138 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_EDIT); |
| 139 | struct nc_rpc_edit *edit_rpc = (struct nc_rpc_edit *)rpc; |
| 140 | |
| 141 | assert_int_equal(edit_rpc->type, NC_RPC_EDIT); |
| 142 | assert_int_equal(edit_rpc->target, target); |
| 143 | assert_int_equal(edit_rpc->default_op, default_op); |
| 144 | assert_int_equal(edit_rpc->test_opt, test_opt); |
| 145 | assert_int_equal(edit_rpc->error_opt, error_opt); |
| 146 | assert_string_equal(edit_rpc->edit_cont, edit_content); |
| 147 | } |
| 148 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 149 | static void |
| 150 | test_nc_rpc_edit(void **state) |
| 151 | { |
| 152 | (void)state; |
| 153 | struct nc_rpc *rpc = NULL; |
| 154 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 155 | /* create edit rpc with NC_PARAMTYPE_CONST */ |
| 156 | rpc = nc_rpc_edit(NC_DATASTORE_RUNNING, NC_RPC_EDIT_DFLTOP_REPLACE, NC_RPC_EDIT_TESTOPT_TESTSET, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 157 | NC_RPC_EDIT_ERROPT_STOP, "url", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 158 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 159 | check_edit(rpc, NC_DATASTORE_RUNNING, NC_RPC_EDIT_DFLTOP_REPLACE, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 160 | NC_RPC_EDIT_TESTOPT_TESTSET, NC_RPC_EDIT_ERROPT_STOP, "url"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 161 | nc_rpc_free(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 162 | |
| 163 | /* create edit rpc with NC_PARAMTYPE_FREE */ |
| 164 | char *str = strdup("string"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 165 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 166 | rpc = nc_rpc_edit(NC_DATASTORE_CANDIDATE, NC_RPC_EDIT_DFLTOP_MERGE, NC_RPC_EDIT_TESTOPT_SET, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 167 | NC_RPC_EDIT_ERROPT_ROLLBACK, str, NC_PARAMTYPE_FREE); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 168 | assert_non_null(rpc); |
| 169 | check_edit(rpc, NC_DATASTORE_CANDIDATE, NC_RPC_EDIT_DFLTOP_MERGE, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 170 | NC_RPC_EDIT_TESTOPT_SET, NC_RPC_EDIT_ERROPT_ROLLBACK, str); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 171 | nc_rpc_free(rpc); |
| 172 | |
| 173 | /* create edit rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 174 | rpc = nc_rpc_edit(NC_DATASTORE_CONFIG, NC_RPC_EDIT_DFLTOP_NONE, NC_RPC_EDIT_TESTOPT_TEST, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 175 | NC_RPC_EDIT_ERROPT_CONTINUE, "url1", NC_PARAMTYPE_DUP_AND_FREE); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 176 | assert_non_null(rpc); |
| 177 | check_edit(rpc, NC_DATASTORE_CONFIG, NC_RPC_EDIT_DFLTOP_NONE, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 178 | NC_RPC_EDIT_TESTOPT_TEST, NC_RPC_EDIT_ERROPT_CONTINUE, "url1"); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 179 | nc_rpc_free(rpc); |
| 180 | } |
| 181 | |
| 182 | /* function to check if values of copy rpc are set correctly */ |
| 183 | void |
| 184 | check_copy(struct nc_rpc *rpc, NC_DATASTORE target, const char *url_trg, NC_DATASTORE source, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 185 | const char *url_or_config_src, NC_WD_MODE wd_mode) |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 186 | { |
| 187 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_COPY); |
| 188 | struct nc_rpc_copy *copy_rpc = (struct nc_rpc_copy *)rpc; |
| 189 | |
| 190 | assert_int_equal(copy_rpc->type, NC_RPC_COPY); |
| 191 | assert_int_equal(copy_rpc->target, target); |
| 192 | assert_string_equal(copy_rpc->url_trg, url_trg); |
| 193 | assert_int_equal(copy_rpc->source, source); |
| 194 | assert_string_equal(copy_rpc->url_config_src, url_or_config_src); |
| 195 | assert_int_equal(copy_rpc->wd_mode, wd_mode); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static void |
| 199 | test_nc_rpc_copy(void **state) |
| 200 | { |
| 201 | (void)state; |
| 202 | struct nc_rpc *rpc = NULL; |
| 203 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 204 | /* create copy rpc with NC_PARAMTYPE_CONST */ |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 205 | rpc = nc_rpc_copy(NC_DATASTORE_RUNNING, "target-url", NC_DATASTORE_RUNNING, "src-url", |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 206 | NC_WD_ALL, NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 207 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 208 | check_copy(rpc, NC_DATASTORE_RUNNING, "target-url", NC_DATASTORE_RUNNING, "src-url", NC_WD_ALL); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 209 | nc_rpc_free(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 210 | |
| 211 | /* create copy rpc with NC_PARAMTYPE_FREE */ |
| 212 | char *target = strdup("target"); |
| 213 | char *src = strdup("src"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 214 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 215 | rpc = nc_rpc_copy(NC_DATASTORE_STARTUP, target, NC_DATASTORE_RUNNING, src, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 216 | NC_WD_ALL_TAG, NC_PARAMTYPE_FREE); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 217 | assert_non_null(rpc); |
| 218 | check_copy(rpc, NC_DATASTORE_STARTUP, target, NC_DATASTORE_RUNNING, src, NC_WD_ALL_TAG); |
| 219 | nc_rpc_free(rpc); |
| 220 | |
| 221 | /* create copy rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 222 | rpc = nc_rpc_copy(NC_DATASTORE_STARTUP, "url", NC_DATASTORE_CANDIDATE, "url", |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 223 | NC_WD_TRIM, NC_PARAMTYPE_DUP_AND_FREE); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 224 | assert_non_null(rpc); |
| 225 | check_copy(rpc, NC_DATASTORE_STARTUP, "url", NC_DATASTORE_CANDIDATE, "url", NC_WD_TRIM); |
| 226 | nc_rpc_free(rpc); |
| 227 | } |
| 228 | |
| 229 | /* function to check if values of delete rpc are set correctly */ |
| 230 | void |
| 231 | check_delete(struct nc_rpc *rpc, NC_DATASTORE target, const char *url) |
| 232 | { |
| 233 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_DELETE); |
| 234 | struct nc_rpc_delete *delete_rpc = (struct nc_rpc_delete *)rpc; |
| 235 | |
| 236 | assert_int_equal(delete_rpc->type, NC_RPC_DELETE); |
| 237 | assert_int_equal(delete_rpc->target, target); |
| 238 | assert_string_equal(delete_rpc->url, url); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void |
| 242 | test_nc_rpc_delete(void **state) |
| 243 | { |
| 244 | (void)state; |
| 245 | struct nc_rpc *rpc = NULL; |
| 246 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 247 | /* create delete rpc with NC_PARAMTYPE_CONST */ |
| 248 | rpc = nc_rpc_delete(NC_DATASTORE_RUNNING, "target-url", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 249 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 250 | check_delete(rpc, NC_DATASTORE_RUNNING, "target-url"); |
| 251 | nc_rpc_free(rpc); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 252 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 253 | /* create delete rpc with NC_PARAMTYPE_FREE */ |
| 254 | char *url = strdup("url"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 255 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 256 | rpc = nc_rpc_delete(NC_DATASTORE_CANDIDATE, url, NC_PARAMTYPE_FREE); |
| 257 | assert_non_null(rpc); |
| 258 | check_delete(rpc, NC_DATASTORE_CANDIDATE, url); |
| 259 | nc_rpc_free(rpc); |
| 260 | |
| 261 | /* create delete rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 262 | rpc = nc_rpc_delete(NC_DATASTORE_CONFIG, "target", NC_PARAMTYPE_DUP_AND_FREE); |
| 263 | assert_non_null(rpc); |
| 264 | check_delete(rpc, NC_DATASTORE_CONFIG, "target"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 265 | nc_rpc_free(rpc); |
| 266 | } |
| 267 | |
| 268 | static void |
| 269 | test_nc_rpc_lock(void **state) |
| 270 | { |
| 271 | (void)state; |
| 272 | struct nc_rpc *rpc = NULL; |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 273 | struct nc_rpc_lock *lock_rpc = NULL; |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 274 | |
| 275 | rpc = nc_rpc_lock(NC_DATASTORE_RUNNING); |
| 276 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 277 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_LOCK); |
| 278 | |
| 279 | lock_rpc = (struct nc_rpc_lock *)rpc; |
| 280 | assert_int_equal(lock_rpc->type, NC_RPC_LOCK); |
| 281 | assert_int_equal(lock_rpc->target, NC_DATASTORE_RUNNING); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 282 | |
| 283 | nc_rpc_free(rpc); |
| 284 | } |
| 285 | |
| 286 | static void |
| 287 | test_nc_rpc_unlock(void **state) |
| 288 | { |
| 289 | (void)state; |
| 290 | struct nc_rpc *rpc = NULL; |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 291 | struct nc_rpc_lock *unlock_rpc = NULL; |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 292 | |
| 293 | rpc = nc_rpc_unlock(NC_DATASTORE_RUNNING); |
| 294 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 295 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_UNLOCK); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 296 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 297 | unlock_rpc = (struct nc_rpc_lock *)rpc; |
| 298 | assert_int_equal(unlock_rpc->type, NC_RPC_UNLOCK); |
| 299 | assert_int_equal(unlock_rpc->target, NC_DATASTORE_RUNNING); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 300 | nc_rpc_free(rpc); |
| 301 | } |
| 302 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 303 | /* function to check if values of get rpc are set correctly */ |
| 304 | void |
| 305 | check_get_rpc(struct nc_rpc *rpc, const char *filter, NC_WD_MODE wd_mode) |
| 306 | { |
| 307 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GET); |
| 308 | struct nc_rpc_get *get_rpc = (struct nc_rpc_get *)rpc; |
| 309 | |
| 310 | assert_int_equal(get_rpc->type, NC_RPC_GET); |
| 311 | assert_string_equal(get_rpc->filter, filter); |
| 312 | assert_int_equal(get_rpc->wd_mode, wd_mode); |
| 313 | } |
| 314 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 315 | static void |
| 316 | test_nc_rpc_get(void **state) |
| 317 | { |
| 318 | (void)state; |
| 319 | struct nc_rpc *rpc = NULL; |
| 320 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 321 | /* create get rpc with NC_PARAMTYPE_CONST */ |
| 322 | rpc = nc_rpc_get("filter", NC_WD_ALL, NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 323 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 324 | check_get_rpc(rpc, "filter", NC_WD_ALL); |
| 325 | nc_rpc_free(rpc); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 326 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 327 | /* create get rpc with NC_PARAMTYPE_FREE */ |
| 328 | char *str = strdup("string"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 329 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 330 | rpc = nc_rpc_get(str, NC_WD_EXPLICIT, NC_PARAMTYPE_FREE); |
| 331 | assert_non_null(rpc); |
| 332 | check_get_rpc(rpc, str, NC_WD_EXPLICIT); |
| 333 | nc_rpc_free(rpc); |
| 334 | |
| 335 | /* create get rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 336 | rpc = nc_rpc_get("filter-string", NC_WD_UNKNOWN, NC_PARAMTYPE_DUP_AND_FREE); |
| 337 | assert_non_null(rpc); |
| 338 | check_get_rpc(rpc, "filter-string", NC_WD_UNKNOWN); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 339 | nc_rpc_free(rpc); |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | test_nc_rpc_kill(void **state) |
| 344 | { |
| 345 | (void)state; |
| 346 | struct nc_rpc *rpc = NULL; |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 347 | struct nc_rpc_kill *kill_rpc = NULL; |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 348 | |
| 349 | rpc = nc_rpc_kill(10); |
| 350 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 351 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_KILL); |
| 352 | |
| 353 | kill_rpc = (struct nc_rpc_kill *)rpc; |
| 354 | assert_int_equal(kill_rpc->type, NC_RPC_KILL); |
| 355 | assert_int_equal(kill_rpc->sid, 10); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 356 | |
| 357 | nc_rpc_free(rpc); |
| 358 | } |
| 359 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 360 | /* function to check if values of commit rpc are set correctly */ |
| 361 | void |
| 362 | check_commit_rpc(struct nc_rpc *rpc, int confirmed, uint32_t confirm_timeout, const char *persist, const char *persist_id) |
| 363 | { |
| 364 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_COMMIT); |
| 365 | struct nc_rpc_commit *commit_rpc = (struct nc_rpc_commit *)rpc; |
| 366 | |
| 367 | assert_int_equal(commit_rpc->type, NC_RPC_COMMIT); |
| 368 | assert_int_equal(commit_rpc->confirmed, confirmed); |
| 369 | assert_int_equal(commit_rpc->confirm_timeout, confirm_timeout); |
| 370 | assert_string_equal(commit_rpc->persist, persist); |
| 371 | assert_string_equal(commit_rpc->persist_id, persist_id); |
| 372 | } |
| 373 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 374 | static void |
| 375 | test_nc_rpc_commit(void **state) |
| 376 | { |
| 377 | (void)state; |
| 378 | struct nc_rpc *rpc = NULL; |
| 379 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 380 | /* create commit rpc with NC_PARAMTYPE_CONST*/ |
| 381 | rpc = nc_rpc_commit(1, 100, "persist", "persist-id", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 382 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 383 | check_commit_rpc(rpc, 1, 100, "persist", "persist-id"); |
| 384 | nc_rpc_free(rpc); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 385 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 386 | /* create commit rpc with NC_PARAMTYPE_FREE*/ |
| 387 | char *str1 = strdup("str1"); |
| 388 | char *str2 = strdup("str2"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 389 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 390 | rpc = nc_rpc_commit(2, 5, str1, str2, NC_PARAMTYPE_FREE); |
| 391 | assert_non_null(rpc); |
| 392 | check_commit_rpc(rpc, 2, 5, str1, str2); |
| 393 | nc_rpc_free(rpc); |
| 394 | |
| 395 | /* create commit rpc with NC_PARAMTYPE_DUP_AND_FREE*/ |
| 396 | rpc = nc_rpc_commit(10, 200, "persistent", "persistent-id", NC_PARAMTYPE_DUP_AND_FREE); |
| 397 | assert_non_null(rpc); |
| 398 | check_commit_rpc(rpc, 10, 200, "persistent", "persistent-id"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 399 | nc_rpc_free(rpc); |
| 400 | } |
| 401 | |
| 402 | static void |
| 403 | test_nc_rpc_discard(void **state) |
| 404 | { |
| 405 | (void)state; |
| 406 | struct nc_rpc *rpc = NULL; |
| 407 | |
| 408 | rpc = nc_rpc_discard(); |
| 409 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 410 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_DISCARD); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 411 | |
| 412 | nc_rpc_free(rpc); |
| 413 | } |
| 414 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 415 | /* function to check if values of cancel rpc are set correctly */ |
| 416 | void |
| 417 | check_cancel_rpc(struct nc_rpc *rpc, const char *persist_id) |
| 418 | { |
| 419 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_CANCEL); |
| 420 | struct nc_rpc_cancel *cancel_rpc = (struct nc_rpc_cancel *)rpc; |
| 421 | |
| 422 | assert_int_equal(cancel_rpc->type, NC_RPC_CANCEL); |
| 423 | assert_string_equal(cancel_rpc->persist_id, persist_id); |
| 424 | } |
| 425 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 426 | static void |
| 427 | test_nc_rpc_cancel(void **state) |
| 428 | { |
| 429 | (void)state; |
| 430 | struct nc_rpc *rpc = NULL; |
| 431 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 432 | /* create cancel rpc with NC_PARAMTYPE_CONST*/ |
| 433 | rpc = nc_rpc_cancel("persist-id", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 434 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 435 | check_cancel_rpc(rpc, "persist-id"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 436 | nc_rpc_free(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 437 | |
| 438 | /* create cancel rpc with NC_PARAMTYPE_FREE*/ |
| 439 | char *str = strdup("string"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 440 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 441 | rpc = nc_rpc_cancel(str, NC_PARAMTYPE_FREE); |
| 442 | assert_non_null(rpc); |
| 443 | check_cancel_rpc(rpc, str); |
| 444 | nc_rpc_free(rpc); |
| 445 | |
| 446 | /* create cancel rpc with NC_PARAMTYPE_DUP_AND_FREE*/ |
| 447 | rpc = nc_rpc_cancel("id", NC_PARAMTYPE_DUP_AND_FREE); |
| 448 | assert_non_null(rpc); |
| 449 | check_cancel_rpc(rpc, "id"); |
| 450 | nc_rpc_free(rpc); |
| 451 | } |
| 452 | |
| 453 | /* function to check if values of validate rpc are set correctly */ |
| 454 | void |
| 455 | check_validate_rpc(struct nc_rpc *rpc, NC_DATASTORE source, const char *url_or_config) |
| 456 | { |
| 457 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_VALIDATE); |
| 458 | struct nc_rpc_validate *validate_rpc = (struct nc_rpc_validate *)rpc; |
| 459 | |
| 460 | assert_int_equal(validate_rpc->type, NC_RPC_VALIDATE); |
| 461 | assert_int_equal(validate_rpc->source, source); |
| 462 | assert_string_equal(validate_rpc->url_config_src, url_or_config); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static void |
| 466 | test_nc_rpc_validate(void **state) |
| 467 | { |
| 468 | (void)state; |
| 469 | struct nc_rpc *rpc = NULL; |
| 470 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 471 | /* create validate rpc with NC_PARAMTYPE_CONST */ |
| 472 | rpc = nc_rpc_validate(NC_DATASTORE_RUNNING, "url", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 473 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 474 | check_validate_rpc(rpc, NC_DATASTORE_RUNNING, "url"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 475 | nc_rpc_free(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 476 | |
| 477 | /* create validate rpc with NC_PARAMTYPE_FREE */ |
| 478 | char *str = strdup("string"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 479 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 480 | rpc = nc_rpc_validate(NC_DATASTORE_CANDIDATE, str, NC_PARAMTYPE_FREE); |
| 481 | assert_non_null(rpc); |
| 482 | check_validate_rpc(rpc, NC_DATASTORE_CANDIDATE, str); |
| 483 | nc_rpc_free(rpc); |
| 484 | |
| 485 | /* create validate rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 486 | rpc = nc_rpc_validate(NC_DATASTORE_CONFIG, "url1", NC_PARAMTYPE_DUP_AND_FREE); |
| 487 | assert_non_null(rpc); |
| 488 | check_validate_rpc(rpc, NC_DATASTORE_CONFIG, "url1"); |
| 489 | nc_rpc_free(rpc); |
| 490 | } |
| 491 | |
| 492 | /* function to check if values of getschema rpc are set correctly */ |
| 493 | void |
| 494 | check_getschema_rpc(struct nc_rpc *rpc, const char *identifier, const char *version, const char *format) |
| 495 | { |
| 496 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GETSCHEMA); |
| 497 | struct nc_rpc_getschema *getchema_rpc = (struct nc_rpc_getschema *)rpc; |
| 498 | |
| 499 | assert_int_equal(getchema_rpc->type, NC_RPC_GETSCHEMA); |
| 500 | assert_string_equal(getchema_rpc->identifier, identifier); |
| 501 | assert_string_equal(getchema_rpc->version, version); |
| 502 | assert_string_equal(getchema_rpc->format, format); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static void |
| 506 | test_nc_rpc_getschema(void **state) |
| 507 | { |
| 508 | (void)state; |
| 509 | struct nc_rpc *rpc = NULL; |
| 510 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 511 | /* create getchema with NC_PARAMTYPE_CONST*/ |
| 512 | rpc = nc_rpc_getschema("id", "version", "format", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 513 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 514 | check_getschema_rpc(rpc, "id", "version", "format"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 515 | nc_rpc_free(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 516 | |
| 517 | /* create getchema with NC_PARAMTYPE_FREE*/ |
| 518 | char *str1 = strdup("str1"); |
| 519 | char *str2 = strdup("str2"); |
| 520 | char *str3 = strdup("str3"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 521 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 522 | rpc = nc_rpc_getschema(str1, str2, str3, NC_PARAMTYPE_FREE); |
| 523 | assert_non_null(rpc); |
| 524 | check_getschema_rpc(rpc, str1, str2, str3); |
| 525 | nc_rpc_free(rpc); |
| 526 | |
| 527 | /* create getchema with NC_PARAMTYPE_DUP_AND_FREE*/ |
| 528 | rpc = nc_rpc_getschema("id1", "version1", "format1", NC_PARAMTYPE_DUP_AND_FREE); |
| 529 | assert_non_null(rpc); |
| 530 | check_getschema_rpc(rpc, "id1", "version1", "format1"); |
| 531 | nc_rpc_free(rpc); |
| 532 | } |
| 533 | |
| 534 | /* function to check if values of subscribe rpc are set correctly */ |
| 535 | void |
| 536 | check_subscribe_rpc(struct nc_rpc *rpc, const char *stream_name, const char *filter, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 537 | const char *start_time, const char *stop_time) |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 538 | { |
| 539 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_SUBSCRIBE); |
| 540 | struct nc_rpc_subscribe *subscribe_rpc = (struct nc_rpc_subscribe *)rpc; |
| 541 | |
| 542 | assert_int_equal(subscribe_rpc->type, NC_RPC_SUBSCRIBE); |
| 543 | assert_string_equal(subscribe_rpc->stream, stream_name); |
| 544 | assert_string_equal(subscribe_rpc->filter, filter); |
| 545 | assert_string_equal(subscribe_rpc->start, start_time); |
| 546 | assert_string_equal(subscribe_rpc->stop, stop_time); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static void |
| 550 | test_nc_rpc_subscribe(void **state) |
| 551 | { |
| 552 | (void)state; |
| 553 | struct nc_rpc *rpc = NULL; |
| 554 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 555 | /* create subscribe rpc with NC_PARAMTYPE_CONST*/ |
| 556 | rpc = nc_rpc_subscribe("stream-name", "filter", "start-time", "stop-time", NC_PARAMTYPE_CONST); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 557 | assert_non_null(rpc); |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 558 | check_subscribe_rpc(rpc, "stream-name", "filter", "start-time", "stop-time"); |
| 559 | nc_rpc_free(rpc); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 560 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 561 | /* create subscribe rpc with NC_PARAMTYPE_FREE*/ |
| 562 | char *str1 = strdup("str1"); |
| 563 | char *str2 = strdup("str2"); |
| 564 | char *str3 = strdup("str3"); |
| 565 | char *str4 = strdup("str4"); |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 566 | |
David Sedlák | 3983ed0 | 2018-10-07 23:17:19 +0200 | [diff] [blame] | 567 | rpc = nc_rpc_subscribe(str1, str2, str3, str4, NC_PARAMTYPE_FREE); |
| 568 | assert_non_null(rpc); |
| 569 | check_subscribe_rpc(rpc, str1, str2, str3, str4); |
| 570 | nc_rpc_free(rpc); |
| 571 | |
| 572 | /* create subscribe rpc with NC_PARAMTYPE_DUP_AND_FREE*/ |
| 573 | rpc = nc_rpc_subscribe("name", "filter-str", "start", "stop", NC_PARAMTYPE_DUP_AND_FREE); |
| 574 | assert_non_null(rpc); |
| 575 | check_subscribe_rpc(rpc, "name", "filter-str", "start", "stop"); |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 576 | nc_rpc_free(rpc); |
| 577 | } |
| 578 | |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 579 | /* function to check if values of getdata rpc are set correctly */ |
| 580 | void |
| 581 | check_getdata(struct nc_rpc *rpc, char *datastore, const char *filter, const char *config_filter, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 582 | char **origin_filter, int origin_filter_count, int negated_origin_filter, uint16_t max_depth, |
| 583 | int with_origin, NC_WD_MODE wd_mode) |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 584 | { |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 585 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GETDATA); |
| 586 | struct nc_rpc_getdata *rpc_getdata = (struct nc_rpc_getdata *)rpc; |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 587 | |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 588 | assert_int_equal(rpc_getdata->type, NC_RPC_GETDATA); |
| 589 | assert_string_equal(rpc_getdata->datastore, datastore); |
| 590 | assert_string_equal(rpc_getdata->filter, filter); |
| 591 | assert_string_equal(rpc_getdata->config_filter, config_filter); |
| 592 | assert_string_equal(*rpc_getdata->origin_filter, *origin_filter); |
| 593 | assert_int_equal(rpc_getdata->origin_filter_count, origin_filter_count); |
| 594 | assert_int_equal(rpc_getdata->negated_origin_filter, negated_origin_filter); |
| 595 | assert_int_equal(rpc_getdata->max_depth, max_depth); |
| 596 | assert_int_equal(rpc_getdata->with_origin, with_origin); |
| 597 | assert_int_equal(rpc_getdata->wd_mode, wd_mode); |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void |
| 601 | test_nc_rpc_getdata(void **state) |
| 602 | { |
| 603 | (void)state; |
| 604 | struct nc_rpc *rpc = NULL; |
| 605 | |
| 606 | /* create getdata rpc with NC_PARAMTYPE_CONST */ |
| 607 | char *origin_filters = "origin_filter"; |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 608 | |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 609 | rpc = nc_rpc_getdata("candidate", "filter", "true", &origin_filters, 1, 1, 3, 1, NC_WD_UNKNOWN, NC_PARAMTYPE_CONST); |
| 610 | assert_non_null(rpc); |
| 611 | check_getdata(rpc, "candidate", "filter", "true", &origin_filters, 1, 1, 3, 1, NC_WD_UNKNOWN); |
| 612 | nc_rpc_free(rpc); |
| 613 | |
| 614 | /* create getdata rpc with NC_PARAMTYPE_FREE */ |
| 615 | char *datastore = strdup("running"); |
| 616 | char *filter = strdup("filter"); |
| 617 | char *config_filter = strdup("true"); |
| 618 | char buf[20] = {0}; |
| 619 | char **origin_filter; |
| 620 | int origin_filter_count = 2; |
| 621 | |
| 622 | origin_filter = calloc(origin_filter_count, sizeof *origin_filter); |
| 623 | assert_non_null(origin_filter); |
| 624 | for (int i = 0; i < origin_filter_count; i++) { |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 625 | snprintf(buf, sizeof(buf) - 1, "origin_filter%d", i + 1); |
| 626 | origin_filter[i] = strdup(buf); |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | rpc = nc_rpc_getdata(datastore, filter, config_filter, origin_filter, origin_filter_count, 2, 3, 1, NC_WD_EXPLICIT, NC_PARAMTYPE_FREE); |
| 630 | assert_non_null(rpc); |
| 631 | check_getdata(rpc, datastore, filter, config_filter, origin_filter, origin_filter_count, 2, 3, 1, NC_WD_EXPLICIT); |
| 632 | nc_rpc_free(rpc); |
| 633 | |
| 634 | /* create getdata rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 635 | char *origin_filter1 = "origin_filter1"; |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 636 | |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 637 | rpc = nc_rpc_getdata("startup", "filter1", "false", &origin_filter1, 1, 0, 3, 1, NC_WD_ALL, NC_PARAMTYPE_DUP_AND_FREE); |
| 638 | assert_non_null(rpc); |
| 639 | check_getdata(rpc, "startup", "filter1", "false", &origin_filter1, 1, 0, 3, 1, NC_WD_ALL); |
| 640 | nc_rpc_free(rpc); |
| 641 | } |
| 642 | |
| 643 | /* function to check if values of editdata rpc are set correctly */ |
| 644 | void |
| 645 | check_editdata(struct nc_rpc *rpc, char *datastore, NC_RPC_EDIT_DFLTOP default_op, const char *edit_content) |
| 646 | { |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 647 | assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_EDITDATA); |
| 648 | struct nc_rpc_editdata *rpc_editdata = (struct nc_rpc_editdata *)rpc; |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 649 | |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 650 | assert_int_equal(rpc_editdata->type, NC_RPC_EDITDATA); |
| 651 | assert_string_equal(rpc_editdata->datastore, datastore); |
| 652 | assert_int_equal(rpc_editdata->default_op, default_op); |
| 653 | assert_string_equal(rpc_editdata->edit_cont, edit_content); |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void |
| 657 | test_nc_rpc_editdata(void **state) |
| 658 | { |
| 659 | (void)state; |
| 660 | struct nc_rpc *rpc = NULL; |
| 661 | |
| 662 | /* create editdata rpc with NC_PARAMTYPE_CONST */ |
| 663 | rpc = nc_rpc_editdata("candidate", NC_RPC_EDIT_DFLTOP_UNKNOWN, "edit", NC_PARAMTYPE_CONST); |
| 664 | assert_non_null(rpc); |
| 665 | check_editdata(rpc, "candidate", NC_RPC_EDIT_DFLTOP_UNKNOWN, "edit"); |
| 666 | nc_rpc_free(rpc); |
| 667 | |
| 668 | /* create editdata rpc with NC_PARAMTYPE_FREE */ |
| 669 | char *datastore = strdup("running"); |
| 670 | char *edit_cont = strdup("edit_data"); |
| 671 | |
| 672 | rpc = nc_rpc_editdata(datastore, NC_RPC_EDIT_DFLTOP_MERGE, edit_cont, NC_PARAMTYPE_FREE); |
| 673 | assert_non_null(rpc); |
| 674 | check_editdata(rpc, datastore, NC_RPC_EDIT_DFLTOP_MERGE, edit_cont); |
| 675 | nc_rpc_free(rpc); |
| 676 | |
| 677 | /* create editdata rpc with NC_PARAMTYPE_DUP_AND_FREE */ |
| 678 | rpc = nc_rpc_editdata("startup", NC_RPC_EDIT_DFLTOP_REPLACE, "edit_cont", NC_PARAMTYPE_DUP_AND_FREE); |
| 679 | assert_non_null(rpc); |
| 680 | check_editdata(rpc, "startup", NC_RPC_EDIT_DFLTOP_REPLACE, "edit_cont"); |
| 681 | nc_rpc_free(rpc); |
| 682 | } |
| 683 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 684 | int |
| 685 | main(void) |
| 686 | { |
| 687 | const struct CMUnitTest tests[] = { |
David Sedlák | 2f2f2e3 | 2018-10-08 21:49:32 +0200 | [diff] [blame] | 688 | cmocka_unit_test_setup_teardown(test_nc_rpc_act_generic_xml, setup_f, teardown_f), |
| 689 | cmocka_unit_test_setup_teardown(test_nc_rpc_act_generic, setup_f, teardown_f), |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 690 | cmocka_unit_test_setup_teardown(test_nc_rpc_getconfig, setup_f, teardown_f), |
| 691 | cmocka_unit_test_setup_teardown(test_nc_rpc_edit, setup_f, teardown_f), |
| 692 | cmocka_unit_test_setup_teardown(test_nc_rpc_copy, setup_f, teardown_f), |
| 693 | cmocka_unit_test_setup_teardown(test_nc_rpc_delete, setup_f, teardown_f), |
| 694 | cmocka_unit_test_setup_teardown(test_nc_rpc_lock, setup_f, teardown_f), |
| 695 | cmocka_unit_test_setup_teardown(test_nc_rpc_unlock, setup_f, teardown_f), |
| 696 | cmocka_unit_test_setup_teardown(test_nc_rpc_get, setup_f, teardown_f), |
| 697 | cmocka_unit_test_setup_teardown(test_nc_rpc_kill, setup_f, teardown_f), |
| 698 | cmocka_unit_test_setup_teardown(test_nc_rpc_commit, setup_f, teardown_f), |
| 699 | cmocka_unit_test_setup_teardown(test_nc_rpc_discard, setup_f, teardown_f), |
| 700 | cmocka_unit_test_setup_teardown(test_nc_rpc_cancel, setup_f, teardown_f), |
| 701 | cmocka_unit_test_setup_teardown(test_nc_rpc_validate, setup_f, teardown_f), |
| 702 | cmocka_unit_test_setup_teardown(test_nc_rpc_getschema, setup_f, teardown_f), |
| 703 | cmocka_unit_test_setup_teardown(test_nc_rpc_subscribe, setup_f, teardown_f), |
Fred Gan | ec58484 | 2021-01-13 15:16:22 +0800 | [diff] [blame] | 704 | cmocka_unit_test_setup_teardown(test_nc_rpc_getdata, setup_f, teardown_f), |
| 705 | cmocka_unit_test_setup_teardown(test_nc_rpc_editdata, setup_f, teardown_f), |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 706 | }; |
| 707 | |
| 708 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 709 | } |