blob: 722d0bf1e71ef2780805135c1b414a0b58186034 [file] [log] [blame]
Michal Vaskoba9f3582023-02-22 10:26:32 +01001/**
2 * @file test_client.c
3 * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
4 * @brief client test
5 *
6 * Copyright (c) 2018 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#define _GNU_SOURCE
16
Michal Vaskob83a3fa2021-05-26 09:53:42 +020017#include <errno.h>
18#include <setjmp.h>
David Sedlák2057be12018-09-30 21:48:55 +020019#include <stdio.h>
20#include <stdlib.h>
David Sedlák2057be12018-09-30 21:48:55 +020021#include <sys/socket.h>
Michal Vaskob83a3fa2021-05-26 09:53:42 +020022#include <sys/types.h>
David Sedlák2057be12018-09-30 21:48:55 +020023
24#include <cmocka.h>
25#include <libyang/libyang.h>
David Sedlák2057be12018-09-30 21:48:55 +020026#include <log.h>
Michal Vaskob83a3fa2021-05-26 09:53:42 +020027#include <session_client.h>
David Sedlák2057be12018-09-30 21:48:55 +020028#include "tests/config.h"
29
30static int
31setup_f(void **state)
32{
33 (void)state;
34
35 nc_verbosity(NC_VERB_VERBOSE);
36
37 return 0;
38}
39
40static int
41teardown_f(void **state)
42{
43 (void)state;
44
45 return 0;
46}
47
48static void
49test_nc_client_setting_schema_searchpath(void **state)
50{
51 (void)state;
52 const char *path;
53 int ret;
54
55 /* initiate client */
56 nc_client_init();
57
58 path = nc_client_get_schema_searchpath();
59 assert_null(path);
60
61 ret = nc_client_set_schema_searchpath("path");
62 assert_int_equal(ret, 0);
63 path = nc_client_get_schema_searchpath();
64 assert_string_equal(path, "path");
65
66 ret = nc_client_set_schema_searchpath("path1");
67 assert_int_equal(ret, 0);
68 path = nc_client_get_schema_searchpath();
69 assert_string_equal(path, "path1");
70}
71
Michal Vasko77367452021-02-16 16:32:18 +010072LY_ERR
73test_clb(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
Michal Vasko77367452021-02-16 16:32:18 +010088LY_ERR
89test_clb1(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data,
90 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 +020091{
92 (void)mod_name;
93 (void)mod_rev;
94 (void)submod_name;
95 (void)sub_rev;
96 (void)user_data;
97 (void)format;
Michal Vasko77367452021-02-16 16:32:18 +010098 (void)model_data;
David Sedlák2057be12018-09-30 21:48:55 +020099 (void)free_module_data;
100
Michal Vasko77367452021-02-16 16:32:18 +0100101 return LY_SUCCESS;
David Sedlák2057be12018-09-30 21:48:55 +0200102}
103
104static void
105test_nc_client_setting_schema_callback(void **state)
106{
107 (void)state;
108 ly_module_imp_clb ret_f;
109 char *data_ret;
110 int ret;
111
112 ret_f = nc_client_get_schema_callback((void **)&data_ret);
113 assert_null(ret_f);
114 assert_null(data_ret);
115
116 ret = nc_client_set_schema_callback(test_clb, "DATA");
117 assert_int_equal(ret, 0);
118 ret_f = nc_client_get_schema_callback((void **)&data_ret);
119 assert_ptr_equal(test_clb, ret_f);
120 assert_string_equal("DATA", data_ret);
121
122 ret = nc_client_set_schema_callback(test_clb1, "DATA1");
123 assert_int_equal(ret, 0);
124 ret_f = nc_client_get_schema_callback((void **)&data_ret);
125 assert_ptr_equal(test_clb1, ret_f);
126 assert_string_equal("DATA1", data_ret);
127
128 /* destroy client */
129 nc_client_destroy();
130}
131
132int
133main(void)
134{
135 const struct CMUnitTest tests[] = {
136 cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_searchpath, setup_f, teardown_f),
137 cmocka_unit_test_setup_teardown(test_nc_client_setting_schema_callback, setup_f, teardown_f),
138 };
139
140 return cmocka_run_group_tests(tests, NULL, NULL);
141}