4
4
* Written by Václav Kubernát <kubernat@cesnet.cz>
5
5
*
6
6
* SPDX-License-Identifier: BSD-3-Clause
7
- */
7
+ */
8
8
9
9
#include < doctest/doctest.h>
10
10
#include < libyang-cpp/Context.hpp>
11
11
#include < libyang-cpp/Utils.hpp>
12
12
#include < libyang/libyang.h>
13
+ #include < libyang/tree_data.h>
13
14
#include " example_schema.hpp"
14
15
#include " test_vars.hpp"
15
16
#include " utils/filesystem_path.hpp"
@@ -40,7 +41,6 @@ TEST_CASE("Unsafe methods")
40
41
ctx_deleter.release ();
41
42
42
43
auto wrapped = libyang::createUnmanagedContext (ctx, ly_ctx_destroy);
43
-
44
44
}
45
45
46
46
DOCTEST_SUBCASE (" No custom deleter" )
@@ -111,6 +111,20 @@ TEST_CASE("Unsafe methods")
111
111
// Both are still unmanaged, both are accessible.
112
112
REQUIRE (wrapped.path () == " /example-schema:leafInt32" );
113
113
REQUIRE (anotherNodeWrapped.path () == " /example-schema:leafInt8" );
114
+
115
+ DOCTEST_SUBCASE (" no explicit unlink" ) { }
116
+
117
+ DOCTEST_SUBCASE (" unlink an unmanaged node from an unmanaged node" )
118
+ {
119
+ REQUIRE (wrapped.findPath (" /example-schema:leafInt8" ));
120
+ REQUIRE (anotherNodeWrapped.findPath (" /example-schema:leafInt32" ));
121
+
122
+ // After unlink they are not reachable from each other
123
+ anotherNodeWrapped.unlink ();
124
+ REQUIRE (!wrapped.findPath (" /example-schema:leafInt8" ));
125
+ REQUIRE (!anotherNodeWrapped.findPath (" /example-schema:leafInt32" ));
126
+ lyd_free_all (anotherNode);
127
+ }
114
128
}
115
129
116
130
// You have a C++ managed node and you want to insert that into an unmanaged node.
@@ -123,6 +137,22 @@ TEST_CASE("Unsafe methods")
123
137
// BOTH are now unmanaged, both are accessible.
124
138
REQUIRE (wrapped.path () == " /example-schema:leafInt32" );
125
139
REQUIRE (anotherNodeWrapped.path () == " /example-schema:leafInt8" );
140
+
141
+ DOCTEST_SUBCASE (" no explicit unlink" ) { }
142
+
143
+ DOCTEST_SUBCASE (" unlink a managed node from an unmanaged node" )
144
+ {
145
+ REQUIRE (wrapped.findPath (" /example-schema:leafInt8" ));
146
+ REQUIRE (anotherNodeWrapped.findPath (" /example-schema:leafInt32" ));
147
+
148
+ // After unlink they are not reachable from each other
149
+ anotherNodeWrapped.unlink ();
150
+ REQUIRE (!wrapped.findPath (" /example-schema:leafInt8" ));
151
+ REQUIRE (!anotherNodeWrapped.findPath (" /example-schema:leafInt32" ));
152
+
153
+ // this is still unmanaged and we need to delete it
154
+ lyd_free_all (anotherNode);
155
+ }
126
156
}
127
157
128
158
// You have a C++ managed node and you want to insert an unmanaged node into it.
0 commit comments