blob: 1be8fa56288a3ca1aace7d2ea6efb8dc19883b77 [file] [log] [blame]
David Sedlák2057be12018-09-30 21:48:55 +02001#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
14static int
15setup_f(void **state)
16{
17 (void)state;
18
19 nc_verbosity(NC_VERB_VERBOSE);
20
21 return 0;
22}
23
24static int
25teardown_f(void **state)
26{
27 (void)state;
28
29 return 0;
30}
31
32static void
33test_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 Vasko77367452021-02-16 16:32:18 +010056LY_ERR
57test_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ák2057be12018-09-30 21:48:55 +020059{
60 (void)mod_name;
61 (void)mod_rev;
62 (void)submod_name;
63 (void)sub_rev;
64 (void)user_data;
65 (void)format;
Michal Vasko77367452021-02-16 16:32:18 +010066 (void)model_data;
David Sedlák2057be12018-09-30 21:48:55 +020067 (void)free_module_data;
68
Michal Vasko77367452021-02-16 16:32:18 +010069 return LY_SUCCESS;
David Sedlák2057be12018-09-30 21:48:55 +020070}
71
Michal Vasko77367452021-02-16 16:32:18 +010072LY_ERR
73test_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ák2057be12018-09-30 21:48:55 +020075{
76 (void)mod_name;
77 (void)mod_rev;
78 (void)submod_name;
79 (void)sub_rev;
80 (void)user_data;
81 (void)format;
Michal Vasko77367452021-02-16 16:32:18 +010082 (void)model_data;
David Sedlák2057be12018-09-30 21:48:55 +020083 (void)free_module_data;
84
Michal Vasko77367452021-02-16 16:32:18 +010085 return LY_SUCCESS;
David Sedlák2057be12018-09-30 21:48:55 +020086}
87
88static void
89test_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
116int
117main(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}