David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <setjmp.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <errno.h> |
| 7 | |
| 8 | #include <cmocka.h> |
| 9 | #include <libyang/libyang.h> |
| 10 | #include <session_client.h> |
| 11 | #include <log.h> |
| 12 | #include "tests/config.h" |
| 13 | |
| 14 | static int |
| 15 | setup_f(void **state) |
| 16 | { |
| 17 | (void)state; |
| 18 | |
| 19 | nc_verbosity(NC_VERB_VERBOSE); |
| 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int |
| 25 | teardown_f(void **state) |
| 26 | { |
| 27 | (void)state; |
| 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static void |
| 33 | test_nc_client_setting_schema_searchpath(void **state) |
| 34 | { |
| 35 | (void)state; |
| 36 | const char *path; |
| 37 | int ret; |
| 38 | |
| 39 | /* initiate client */ |
| 40 | nc_client_init(); |
| 41 | |
| 42 | path = nc_client_get_schema_searchpath(); |
| 43 | assert_null(path); |
| 44 | |
| 45 | ret = nc_client_set_schema_searchpath("path"); |
| 46 | assert_int_equal(ret, 0); |
| 47 | path = nc_client_get_schema_searchpath(); |
| 48 | assert_string_equal(path, "path"); |
| 49 | |
| 50 | ret = nc_client_set_schema_searchpath("path1"); |
| 51 | assert_int_equal(ret, 0); |
| 52 | path = nc_client_get_schema_searchpath(); |
| 53 | assert_string_equal(path, "path1"); |
| 54 | } |
| 55 | |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 56 | LY_ERR |
| 57 | test_clb(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data, |
| 58 | LYS_INFORMAT *format, const char **model_data, void (**free_module_data)(void *model_data, void *user_data)) |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 59 | { |
| 60 | (void)mod_name; |
| 61 | (void)mod_rev; |
| 62 | (void)submod_name; |
| 63 | (void)sub_rev; |
| 64 | (void)user_data; |
| 65 | (void)format; |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 66 | (void)model_data; |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 67 | (void)free_module_data; |
| 68 | |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 69 | return LY_SUCCESS; |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 72 | LY_ERR |
| 73 | test_clb1(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data, |
| 74 | LYS_INFORMAT *format, const char **model_data, void (**free_module_data)(void *model_data, void *user_data)) |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 75 | { |
| 76 | (void)mod_name; |
| 77 | (void)mod_rev; |
| 78 | (void)submod_name; |
| 79 | (void)sub_rev; |
| 80 | (void)user_data; |
| 81 | (void)format; |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 82 | (void)model_data; |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 83 | (void)free_module_data; |
| 84 | |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 85 | return LY_SUCCESS; |
David Sedlák | 2057be1 | 2018-09-30 21:48:55 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void |
| 89 | test_nc_client_setting_schema_callback(void **state) |
| 90 | { |
| 91 | (void)state; |
| 92 | ly_module_imp_clb ret_f; |
| 93 | char *data_ret; |
| 94 | int ret; |
| 95 | |
| 96 | ret_f = nc_client_get_schema_callback((void **)&data_ret); |
| 97 | assert_null(ret_f); |
| 98 | assert_null(data_ret); |
| 99 | |
| 100 | ret = nc_client_set_schema_callback(test_clb, "DATA"); |
| 101 | assert_int_equal(ret, 0); |
| 102 | ret_f = nc_client_get_schema_callback((void **)&data_ret); |
| 103 | assert_ptr_equal(test_clb, ret_f); |
| 104 | assert_string_equal("DATA", data_ret); |
| 105 | |
| 106 | ret = nc_client_set_schema_callback(test_clb1, "DATA1"); |
| 107 | assert_int_equal(ret, 0); |
| 108 | ret_f = nc_client_get_schema_callback((void **)&data_ret); |
| 109 | assert_ptr_equal(test_clb1, ret_f); |
| 110 | assert_string_equal("DATA1", data_ret); |
| 111 | |
| 112 | /* destroy client */ |
| 113 | nc_client_destroy(); |
| 114 | } |
| 115 | |
| 116 | int |
| 117 | main(void) |
| 118 | { |
| 119 | const struct CMUnitTest tests[] = { |
| 120 | cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_searchpath, setup_f, teardown_f), |
| 121 | cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_callback, setup_f, teardown_f), |
| 122 | }; |
| 123 | |
| 124 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 125 | } |