Skip to content

Commit ba3802e

Browse files
author
Petr Hanzlik
committed
utests type UPDATE replace internal funstions with API
1 parent 96b050a commit ba3802e

18 files changed

Lines changed: 67 additions & 51 deletions

tests/utests/types/binary.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test_plugin_store(void **state)
5151
struct ly_err_item *err = NULL;
5252
struct lys_module *mod;
5353
struct lyd_value value = {0};
54-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]));
54+
struct lyplg_type *type = NULL;
5555
struct lysc_type *lysc_type, *lysc_type2;
5656
LY_ERR ly_ret;
5757
const char *schema;
@@ -61,6 +61,7 @@ test_plugin_store(void **state)
6161
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
6262
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
6363
lysc_type2 = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
64+
type = lysc_get_type_plugin(lysc_type2->plugin_ref);
6465

6566
/* check proper type */
6667
assert_string_equal("ly2 binary", type->id);
@@ -250,13 +251,14 @@ test_plugin_print(void **state)
250251
struct lyd_value value = {0};
251252
struct lys_module *mod;
252253
struct lysc_type *lysc_type;
253-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]));
254+
struct lyplg_type *type = NULL;
254255
struct ly_err_item *err = NULL;
255256

256257
/* create schema. Prepare common used variables */
257258
schema = MODULE_CREATE_YANG("a", "leaf l {type binary;}");
258259
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
259260
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
261+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
260262

261263
/* Testing empty value. */
262264
val = "";
@@ -273,13 +275,14 @@ test_plugin_duplicate(void **state)
273275
struct lyd_value value = {0}, dup;
274276
struct lys_module *mod;
275277
struct lysc_type *lysc_type;
276-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]));
278+
struct lyplg_type *type = NULL;
277279
struct ly_err_item *err = NULL;
278280

279281
/* create schema. Prepare common used variables */
280282
schema = MODULE_CREATE_YANG("a", "leaf l {type binary;}");
281283
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
282284
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
285+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
283286

284287
/* Testing empty value. */
285288
val = "";
@@ -298,14 +301,15 @@ test_plugin_sort(void **state)
298301
const char *schema;
299302
struct lys_module *mod;
300303
struct lyd_value val1 = {0}, val2 = {0};
301-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BINARY]));
304+
struct lyplg_type *type = NULL;
302305
struct lysc_type *lysc_type;
303306
struct ly_err_item *err = NULL;
304307

305308
/* create schema. Prepare common used variables */
306309
schema = MODULE_CREATE_YANG("a", "leaf-list ll {type binary;}");
307310
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
308311
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data)->type;
312+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
309313

310314
/* v1 < v2, v2 > v1, v1 == v1 */
311315
v1 = "YWhveQ=="; /* ahoy */

tests/utests/types/bits.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
/* LOCAL INCLUDE HEADERS */
2323
#include "libyang.h"
24-
#include "path.h"
2524

2625
#define MODULE_CREATE_YIN(MOD_NAME, NODES) \
2726
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
@@ -800,7 +799,7 @@ test_plugin_store(void **state)
800799
struct ly_err_item *err = NULL;
801800
struct lys_module *mod;
802801
struct lyd_value value = {0};
803-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]));
802+
struct lyplg_type *type = NULL;
804803
struct lysc_type *lysc_type;
805804
LY_ERR ly_ret;
806805
char *alloc;
@@ -811,6 +810,7 @@ test_plugin_store(void **state)
811810
" bit two; bit three;}}");
812811
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
813812
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
813+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
814814

815815
/* check proper type */
816816
assert_string_equal("ly2 bits", type->id);
@@ -884,7 +884,7 @@ test_plugin_compare(void **state)
884884
struct ly_err_item *err = NULL;
885885
struct lys_module *mod;
886886
struct lyd_value values[10];
887-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]));
887+
struct lyplg_type *type = NULL;
888888
struct lysc_type *lysc_type;
889889
LY_ERR ly_ret;
890890
const char *schema;
@@ -904,6 +904,7 @@ test_plugin_compare(void **state)
904904
"leaf p4 {type string;}");
905905
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
906906
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
907+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
907908

908909
/* CREATE VALUES */
909910
for (unsigned int it = 0; it < sizeof(val_init) / sizeof(val_init[0]); it++) {
@@ -946,14 +947,15 @@ test_plugin_sort(void **state)
946947
{
947948
const char *schema;
948949
struct lys_module *mod;
949-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]));
950+
struct lyplg_type *type = NULL;
950951
struct lysc_type *lysc_type;
951952
struct ly_err_item *err = NULL;
952953
struct lyd_value val1 = {0}, val2 = {0};
953954

954955
schema = MODULE_CREATE_YANG("T0", "leaf-list ll { type bits { bit zero; bit one; bit two; bit three;}}");
955956
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
956957
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
958+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
957959

958960
/* 1000 < 1001 */
959961
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, "three", strlen("three") * 8,
@@ -983,7 +985,7 @@ test_plugin_print(void **state)
983985
struct ly_err_item *err = NULL;
984986
struct lys_module *mod;
985987
struct lyd_value values[10];
986-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]));
988+
struct lyplg_type *type = NULL;
987989
struct lysc_type *lysc_type;
988990
LY_ERR ly_ret;
989991
const char *schema;
@@ -996,6 +998,7 @@ test_plugin_print(void **state)
996998
" bit two; bit three;}}");
997999
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
9981000
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1001+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
9991002

10001003
/* CREATE VALUES */
10011004
for (unsigned int it = 0; it < sizeof(val_init) / sizeof(val_init[0]); it++) {
@@ -1025,7 +1028,7 @@ test_plugin_dup(void **state)
10251028
struct ly_err_item *err = NULL;
10261029
struct lys_module *mod;
10271030
struct lyd_value values[10];
1028-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_BITS]));
1031+
struct lyplg_type *type = NULL;
10291032
struct lysc_type *lysc_type;
10301033
const char *schema;
10311034
LY_ERR ly_ret;
@@ -1038,6 +1041,7 @@ test_plugin_dup(void **state)
10381041
" bit two; bit three;}}");
10391042
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
10401043
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1044+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
10411045

10421046
/* CREATE VALUES */
10431047
for (unsigned int it = 0; it < sizeof(val_init) / sizeof(val_init[0]); it++) {

tests/utests/types/enumeration.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@ test_plugin_sort(void **state)
9494
const char *schema;
9595
struct lys_module *mod;
9696
struct lyd_value val1 = {0}, val2 = {0};
97-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_ENUM]));
97+
struct lyplg_type *type = NULL;
9898
struct lysc_type *lysc_type;
9999
struct ly_err_item *err = NULL;
100100

101101
schema = MODULE_CREATE_YANG("sort", "leaf l1 {type enumeration {enum white; enum yellow; enum black;}}");
102102
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
103103
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
104+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
104105

105106
v1 = "white";
106107
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,

tests/utests/types/inet_types.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ test_plugin_sort(void **state)
197197
const char *schema;
198198
struct lys_module *mod;
199199
struct lyd_value val1 = {0}, val2 = {0};
200-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION]));
200+
struct lyplg_type *type = NULL;
201201
struct lysc_type *lysc_type;
202202
struct ly_err_item *err = NULL;
203203

@@ -212,6 +212,7 @@ test_plugin_sort(void **state)
212212

213213
/* ipv4-address */
214214
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
215+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
215216

216217
v1 = "192.168.0.1";
217218
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
@@ -239,7 +240,7 @@ test_plugin_sort(void **state)
239240

240241
/* ipv6-address */
241242
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next)->type;
242-
type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]));
243+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
243244

244245
v1 = "2008:15:0:0:0:0:feAC:1";
245246
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
@@ -267,7 +268,7 @@ test_plugin_sort(void **state)
267268

268269
/* ipv4-address-no-zone */
269270
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next)->type;
270-
type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_UNION]));
271+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
271272
v1 = "127.0.0.1";
272273
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
273274
0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err));
@@ -282,7 +283,7 @@ test_plugin_sort(void **state)
282283

283284
/* ipv6-address-no-zone */
284285
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next->next)->type;
285-
type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_STRING]));
286+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
286287
v1 = "A:B:c:D:e:f:1:1";
287288
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
288289
0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err));
@@ -297,6 +298,7 @@ test_plugin_sort(void **state)
297298

298299
/* ipv4-prefix */
299300
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next->next->next)->type;
301+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
300302
v1 = "0.1.58.4/32";
301303
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
302304
0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err));
@@ -311,10 +313,11 @@ test_plugin_sort(void **state)
311313

312314
/* ipv6-prefix */
313315
lysc_type = ((struct lysc_node_leaflist *)mod->compiled->data->next->next->next->next->next)->type;
314-
v1 = "::C:D:E:f:a/96";
316+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
317+
v1 = "::C:D:E:f:a/112";
315318
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,
316319
0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err));
317-
v2 = "::C:D:E:f:a/112";
320+
v2 = "::C:D:E:f:a/96";
318321
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v2, strlen(v2) * 8,
319322
0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val2, NULL, &err));
320323
assert_true(0 < type->sort(UTEST_LYCTX, &val1, &val2));

tests/utests/types/instanceid.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818

1919
/* LOCAL INCLUDE HEADERS */
2020
#include "libyang.h"
21-
#include "path.h"
21+
22+
enum ly_path_pred_type {
23+
LY_PATH_PREDTYPE_POSITION, /**< position predicate - [2] */
24+
LY_PATH_PREDTYPE_LIST, /**< keys predicate - [key1='val1'][key2='val2']... */
25+
LY_PATH_PREDTYPE_LEAFLIST, /**< leaflist value predicate - [.='value'] */
26+
LY_PATH_PREDTYPE_LIST_VAR /**< keys predicate with variable instead of value - [key1=$USER]... */
27+
};
2228

2329
#define MODULE_CREATE_YANG(MOD_NAME, NODES) \
2430
"module " MOD_NAME " {\n" \

tests/utests/types/int16.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
/* LOCAL INCLUDE HEADERS */
2323
#include "libyang.h"
24-
#include "path.h"
25-
#include "plugins_internal.h"
2624

2725
#define MODULE_CREATE_YANG(MOD_NAME, NODES) \
2826
"module " MOD_NAME " {\n" \

tests/utests/types/int32.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
/* LOCAL INCLUDE HEADERS */
2323
#include "libyang.h"
24-
#include "path.h"
25-
#include "plugins_internal.h"
2624

2725
#define MODULE_CREATE_YANG(MOD_NAME, NODES) \
2826
"module " MOD_NAME " {\n" \

tests/utests/types/int64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
/* LOCAL INCLUDE HEADERS */
2323
#include "libyang.h"
24-
#include "path.h"
25-
#include "plugins_internal.h"
2624

2725
#define MODULE_CREATE_YANG(MOD_NAME, NODES) \
2826
"module " MOD_NAME " {\n" \

tests/utests/types/int8.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
/* LOCAL INCLUDE HEADERS */
2323
#include "libyang.h"
24-
#include "path.h"
25-
#include "plugins_internal.h"
2624

2725
#define LYD_TREE_CREATE(INPUT, MODEL) \
2826
CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)
@@ -1399,7 +1397,7 @@ test_plugin_store(void **state)
13991397
struct ly_err_item *err = NULL;
14001398
struct lys_module *mod;
14011399
struct lyd_value value = {0};
1402-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]));
1400+
struct lyplg_type *type = NULL;
14031401
struct lysc_type *lysc_type;
14041402
LY_ERR ly_ret;
14051403
char *alloc;
@@ -1410,6 +1408,7 @@ test_plugin_store(void **state)
14101408
schema = MODULE_CREATE_YANG("defs", "leaf port {type int8 {range \"-50 .. 50\";}}");
14111409
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
14121410
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1411+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
14131412

14141413
/* check proper type */
14151414
assert_string_equal("ly2 integers", type->id);
@@ -1546,7 +1545,7 @@ test_plugin_compare(void **state)
15461545
struct ly_err_item *err = NULL;
15471546
struct lys_module *mod;
15481547
struct lyd_value values[10];
1549-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]));
1548+
struct lyplg_type *type = NULL;
15501549
struct lysc_type *lysc_type;
15511550
LY_ERR ly_ret;
15521551
const char *schema;
@@ -1565,6 +1564,7 @@ test_plugin_compare(void **state)
15651564
"leaf p4 {type uint8;}");
15661565
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
15671566
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1567+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
15681568

15691569
/* CREATE VALUES */
15701570
for (unsigned int it = 0; it < sizeof(val_init) / sizeof(val_init[0]); it++) {
@@ -1631,7 +1631,7 @@ test_plugin_print(void **state)
16311631
struct ly_err_item *err = NULL;
16321632
struct lys_module *mod;
16331633
struct lyd_value values[10];
1634-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]));
1634+
struct lyplg_type *type = NULL;
16351635
struct lysc_type *lysc_type;
16361636
LY_ERR ly_ret;
16371637
const char *schema;
@@ -1642,6 +1642,7 @@ test_plugin_print(void **state)
16421642
schema = MODULE_CREATE_YANG("defs", "leaf port {type int8;}");
16431643
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
16441644
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1645+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
16451646

16461647
/* CREATE VALUES */
16471648
for (unsigned int it = 0; it < sizeof(val_init) / sizeof(val_init[0]); it++) {
@@ -1671,7 +1672,7 @@ test_plugin_dup(void **state)
16711672
struct ly_err_item *err = NULL;
16721673
struct lys_module *mod;
16731674
struct lyd_value values[10];
1674-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_INT8]));
1675+
struct lyplg_type *type = NULL;
16751676
struct lysc_type *lysc_type[2];
16761677
const char *schema;
16771678
LY_ERR ly_ret;
@@ -1682,6 +1683,7 @@ test_plugin_dup(void **state)
16821683
schema = MODULE_CREATE_YANG("T0", "leaf port {type int8;}");
16831684
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
16841685
lysc_type[0] = ((struct lysc_node_leaf *)mod->compiled->data)->type;
1686+
type = lysc_get_type_plugin(lysc_type[0]->plugin_ref);
16851687

16861688
schema = MODULE_CREATE_YANG("T1",
16871689
"typedef my_int_type {"

tests/utests/types/leafref.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ test_plugin_sort(void **state)
216216
const char *schema;
217217
struct lys_module *mod;
218218
struct lyd_value val1 = {0}, val2 = {0};
219-
struct lyplg_type *type = lysc_get_type_plugin(lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[LY_TYPE_LEAFREF]));
219+
struct lyplg_type *type = NULL;
220220
struct lysc_type *lysc_type;
221221
struct ly_err_item *err = NULL;
222222

@@ -232,6 +232,7 @@ test_plugin_sort(void **state)
232232
"}");
233233
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
234234
lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
235+
type = lysc_get_type_plugin(lysc_type->plugin_ref);
235236

236237
v1 = "str1";
237238
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,

0 commit comments

Comments
 (0)