printers CHANGE rewrite printers mechanism
Instead of specifying output type (memory, stream, file descriptor, ...)
with each printer function call, use printer handler mechanism. The
handler is first created with specifying the output type with necessary
parameters. Then, the handler can be used in the single print function
without the need to specify the specific output type parameters. There
are also a helper functions to update/change the output type parameter
without a need to recreate the printer handler.
This change is necessary due to the increasing complexity of the
printer functions. We want to add another parameters/specific functions,
for example to print a separate node, but together with the specific
output type parameters, the function parameters list would be quite
complex.
diff --git a/tests/utests/schema/test_printer_yang.c b/tests/utests/schema/test_printer_yang.c
index 1f3f749..93e3aeb 100644
--- a/tests/utests/schema/test_printer_yang.c
+++ b/tests/utests/schema/test_printer_yang.c
@@ -131,16 +131,19 @@
" \"some reference\";\n"
"}\n";
char *printed;
+ struct lyp_out *out;
+ size_t size = 0;
+ assert_non_null(out = lyp_new_memory(&printed, 0));
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
- assert_int_equal(strlen(orig), lys_print_mem(&printed, mod, LYS_OUT_YANG, 0, 0));
+ assert_int_equal(strlen(orig), size = lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_string_equal(printed, orig);
- free(printed);
- assert_int_equal(strlen(compiled), lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+ lyp_out_reset(out);
+ assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
assert_string_equal(printed, compiled);
- free(printed);
+ lyp_out_reset(out);
orig = "module b {\n"
" yang-version 1.1;\n"
@@ -184,12 +187,12 @@
" }\n"
"}\n";
assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
- assert_int_equal(strlen(orig), lys_print_mem(&printed, mod, LYS_OUT_YANG, 0, 0));
+ assert_int_equal(strlen(orig), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_string_equal(printed, orig);
- free(printed);
- assert_int_equal(strlen(compiled), lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+ lyp_out_reset(out);
+ assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
assert_string_equal(printed, compiled);
- free(printed);
+ lyp_out_reset(out);
orig = compiled ="module c {\n"
" yang-version 1.1;\n"
@@ -209,14 +212,15 @@
" }\n"
"}\n";
assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
- assert_int_equal(strlen(orig), lys_print_mem(&printed, mod, LYS_OUT_YANG, 0, 0));
+ assert_int_equal(strlen(orig), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_string_equal(printed, orig);
- free(printed);
- assert_int_equal(strlen(compiled), lys_print_mem(&printed, mod, LYS_OUT_YANG, 0, 0));
+ lyp_out_reset(out);
+ assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_string_equal(printed, compiled);
- free(printed);
+ /* missing free(printed); which is done in the following lyp_free() */
*state = NULL;
+ lyp_free(out, NULL, 1);
ly_ctx_destroy(ctx, NULL);
}
diff --git a/tests/utests/schema/test_printer_yin.c b/tests/utests/schema/test_printer_yin.c
index 2ffa611..5656795 100644
--- a/tests/utests/schema/test_printer_yin.c
+++ b/tests/utests/schema/test_printer_yin.c
@@ -578,20 +578,27 @@
" </rpc>\n"
"</module>\n";
- char * printed;
+ char *printed;
+ struct lyp_out *out;
+
+ assert_non_null(out = lyp_new_memory(&printed, 0));
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
- assert_int_equal(strlen(ori_res), lys_print_mem(&printed, mod, LYS_OUT_YIN, 0, 0));
+ assert_int_equal(strlen(ori_res), lys_print(out, mod, LYS_OUT_YIN, 0, 0));
assert_string_equal(printed, ori_res);
- free(printed);
+
/*
+ lyp_memory_clean(out);
assert_int_equal(strlen(compiled), lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0, 0));
assert_string_equal(printed, compiled);
- free(printed);
*/
+ /* note that the printed is freed here, so it must not be freed via lyp_free()! */
+ free(printed);
+
*state = NULL;
+ lyp_free(out, NULL, 0);
ly_ctx_destroy(ctx, NULL);
}