-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathtest_hello.c
More file actions
104 lines (85 loc) · 2.43 KB
/
test_hello.c
File metadata and controls
104 lines (85 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @file test_hello.c
* @author Vincent Jardin
* @brief test NETCONF hello capability advertisement
*
* @copyright
* Copyright (c) 2026 Free Mobile, Vincent Jardin.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*/
#define _GNU_SOURCE
#include <setjmp.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <cmocka.h>
#include <libyang/libyang.h>
#include <nc_client.h>
#include "np2_test.h"
#include "np2_test_config.h"
static int
local_setup(void **state)
{
char test_name[256];
const char *modules[] = {
NP_TEST_MODULE_DIR "/edit1.yang", /* YANG 1.0 */
NP_TEST_MODULE_DIR "/notif2.yang", /* YANG 1.1 */
NULL
};
int rc;
np2_glob_test_setup_test_name(test_name);
rc = np2_glob_test_setup_env(test_name);
assert_int_equal(rc, 0);
rc = np2_glob_test_setup_server(state, test_name, modules, NULL, 0);
assert_int_equal(rc, 0);
return 0;
}
static int
local_teardown(void **state)
{
const char *modules[] = {"edit1", "notif2", NULL};
if (*state) {
return np2_glob_test_teardown(state, modules);
}
return 0;
}
static void
test_yang10_in_hello(void **state)
{
struct np2_test *st = *state;
const char *cpblt;
/* YANG 1.0 modules must be advertised in hello capabilities (RFC 6241) */
cpblt = nc_session_cpblt(st->nc_sess, "urn:ed1?module=edit1");
assert_non_null(cpblt);
}
static void
test_yang11_not_in_hello(void **state)
{
struct np2_test *st = *state;
const char *cpblt;
/* YANG 1.1 modules must NOT be in hello capabilities per RFC 7950 section 1.1:
* "A server advertises support for YANG 1.1 modules by using ietf-yang-library
* instead of listing them as capabilities in the <hello> message."
* Clients should discover YANG 1.1 modules via ietf-yang-library. */
cpblt = nc_session_cpblt(st->nc_sess, "urn:n2?module=notif2");
assert_null(cpblt);
}
int
main(int argc, char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_yang10_in_hello),
cmocka_unit_test(test_yang11_not_in_hello),
};
if (argc > 1) {
parse_arg(argc, argv);
}
return cmocka_run_group_tests(tests, local_setup, local_teardown);
}