blob: 2f2ef95453203e8273e3e02da026c1cfbc0a5e5b [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
56const char *test_clb(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev,
57 void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data, void *user_data))
58{
59 (void)mod_name;
60 (void)mod_rev;
61 (void)submod_name;
62 (void)sub_rev;
63 (void)user_data;
64 (void)format;
65 (void)free_module_data;
66
67 return 0;
68}
69
70const char *test_clb1(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev,
71 void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data, void *user_data))
72{
73 (void)mod_name;
74 (void)mod_rev;
75 (void)submod_name;
76 (void)sub_rev;
77 (void)user_data;
78 (void)format;
79 (void)free_module_data;
80
81 return 0;
82}
83
84static void
85test_nc_client_setting_schema_callback(void **state)
86{
87 (void)state;
88 ly_module_imp_clb ret_f;
89 char *data_ret;
90 int ret;
91
92 ret_f = nc_client_get_schema_callback((void **)&data_ret);
93 assert_null(ret_f);
94 assert_null(data_ret);
95
96 ret = nc_client_set_schema_callback(test_clb, "DATA");
97 assert_int_equal(ret, 0);
98 ret_f = nc_client_get_schema_callback((void **)&data_ret);
99 assert_ptr_equal(test_clb, ret_f);
100 assert_string_equal("DATA", data_ret);
101
102 ret = nc_client_set_schema_callback(test_clb1, "DATA1");
103 assert_int_equal(ret, 0);
104 ret_f = nc_client_get_schema_callback((void **)&data_ret);
105 assert_ptr_equal(test_clb1, ret_f);
106 assert_string_equal("DATA1", data_ret);
107
108 /* destroy client */
109 nc_client_destroy();
110}
111
112int
113main(void)
114{
115 const struct CMUnitTest tests[] = {
116 cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_searchpath, setup_f, teardown_f),
117 cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_callback, setup_f, teardown_f),
118 };
119
120 return cmocka_run_group_tests(tests, NULL, NULL);
121}