plugins types FEATURE sort callback in leafref
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 25575eb..4b8b1b9 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -1059,6 +1059,12 @@
const struct lyd_value *val2);
/**
+ * @brief Implementation of ::lyplg_type_sort_clb for the built-in leafref type.
+ */
+LIBYANG_API_DECL int lyplg_type_sort_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1,
+ const struct lyd_value *val2);
+
+/**
* @brief Implementation of ::lyplg_type_print_clb for the built-in leafref type.
*/
LIBYANG_API_DECL const void *lyplg_type_print_leafref(const struct ly_ctx *ctx, const struct lyd_value *value,
diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c
index 8350da8..fee2ef9 100644
--- a/src/plugins_types/leafref.c
+++ b/src/plugins_types/leafref.c
@@ -106,6 +106,12 @@
return val1->realtype->plugin->compare(ctx, val1, val2);
}
+LIBYANG_API_DEF int
+lyplg_type_sort_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
+{
+ return val1->realtype->plugin->sort(ctx, val1, val2);
+}
+
LIBYANG_API_DEF const void *
lyplg_type_print_leafref(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
void *prefix_data, ly_bool *dynamic, size_t *value_len)
@@ -142,7 +148,7 @@
.plugin.store = lyplg_type_store_leafref,
.plugin.validate = lyplg_type_validate_leafref,
.plugin.compare = lyplg_type_compare_leafref,
- .plugin.sort = NULL,
+ .plugin.sort = lyplg_type_sort_leafref,
.plugin.print = lyplg_type_print_leafref,
.plugin.duplicate = lyplg_type_dup_leafref,
.plugin.free = lyplg_type_free_leafref,
diff --git a/tests/utests/types/leafref.c b/tests/utests/types/leafref.c
index 5d510b9..1941e48 100644
--- a/tests/utests/types/leafref.c
+++ b/tests/utests/types/leafref.c
@@ -210,6 +210,43 @@
}
static void
+test_plugin_sort(void **state)
+{
+ const char *v1, *v2;
+ const char *schema;
+ struct lys_module *mod;
+ struct lyd_value val1 = {0}, val2 = {0};
+ struct lyplg_type *type = lyplg_type_plugin_find("", NULL, ly_data_type2str[LY_TYPE_LEAFREF]);
+ struct lysc_type *lysc_type;
+ struct ly_err_item *err = NULL;
+
+ schema = MODULE_CREATE_YANG("simple",
+ "leaf l1 {"
+ " type leafref {"
+ " require-instance false;"
+ " path \"../target\";"
+ " }"
+ "}"
+ "leaf target {"
+ " type string;"
+ "}");
+ UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
+ lysc_type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
+
+ v1 = "str1";
+ assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1),
+ 0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val1, NULL, &err));
+ v2 = "str2";
+ assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v2, strlen(v2),
+ 0, LY_VALUE_JSON, NULL, LYD_VALHINT_STRING, NULL, &val2, NULL, &err));
+ assert_int_equal(-1, type->sort(UTEST_LYCTX, &val1, &val2));
+ assert_int_equal(0, type->sort(UTEST_LYCTX, &val1, &val1));
+ assert_int_equal(1, type->sort(UTEST_LYCTX, &val2, &val1));
+ type->free(UTEST_LYCTX, &val1);
+ type->free(UTEST_LYCTX, &val2);
+}
+
+static void
test_data_xpath_json(void **state)
{
const char *schema, *data;
@@ -280,6 +317,7 @@
UTEST(test_data_xml),
UTEST(test_data_json),
UTEST(test_plugin_lyb),
+ UTEST(test_plugin_sort),
UTEST(test_data_xpath_json),
UTEST(test_xpath_invalid_schema)
};