Skip to content

Commit 9e70a23

Browse files
committed
tests: check return values of the C functions
The old version with no error checking was a kinda nice test to see what happens when errors are not checked :), but hey, let's check them. Change-Id: I9613aedcb8e6af444a3f400480ea23ba4d912b55
1 parent b31f348 commit 9e70a23

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

tests/unsafe.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ using node_deleter_t = decltype([](auto node) constexpr {
2727
TEST_CASE("Unsafe methods")
2828
{
2929
ly_ctx* ctx;
30-
ly_ctx_new(ly_yang_module_dir(), 0, &ctx);
30+
REQUIRE(ly_ctx_new(ly_yang_module_dir(), 0, &ctx) == LY_SUCCESS);
3131
// When wrapping raw lyd_nodes, the context struct however is not managed and needs to be released manually (for
3232
// example with a unique_ptr), like below.
3333
auto ctx_deleter = std::unique_ptr<ly_ctx, ctx_deleter_t>(ctx);
34-
lys_parse_mem(ctx, example_schema.c_str(), LYS_IN_YANG, nullptr);
34+
REQUIRE(lys_parse_mem(ctx, example_schema.c_str(), LYS_IN_YANG, nullptr) == LY_SUCCESS);
3535
auto data = R"({ "example-schema:leafInt32": 32 })";
3636

3737
DOCTEST_SUBCASE("createUnmanagedContext")
@@ -52,7 +52,7 @@ TEST_CASE("Unsafe methods")
5252
DOCTEST_SUBCASE("wrapRawNode")
5353
{
5454
lyd_node* node;
55-
lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &node);
55+
REQUIRE(lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &node) == LY_SUCCESS);
5656

5757
// The wrapped node does take ownership of the lyd_node* and deletes it on destruction of the class.
5858
auto wrapped = libyang::wrapRawNode(node);
@@ -81,7 +81,7 @@ TEST_CASE("Unsafe methods")
8181
DOCTEST_SUBCASE("wrapUnmanagedRawNode")
8282
{
8383
lyd_node* node;
84-
lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &node);
84+
REQUIRE(lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &node) == LY_SUCCESS);
8585
// With wrapConstRawNode, the node needs to be released manually.
8686
auto node_deleter = std::unique_ptr<lyd_node, node_deleter_t>(node);
8787

@@ -105,7 +105,7 @@ TEST_CASE("Unsafe methods")
105105
DOCTEST_SUBCASE("Inserting an UNMANAGED node into an unmanaged node")
106106
{
107107
lyd_node* anotherNode;
108-
lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode);
108+
REQUIRE(lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode) == LY_SUCCESS);
109109
auto anotherNodeWrapped = libyang::wrapUnmanagedRawNode(const_cast<const lyd_node*>(anotherNode));
110110
wrapped.insertSibling(anotherNodeWrapped);
111111
// Both are still unmanaged, both are accessible.
@@ -131,7 +131,7 @@ TEST_CASE("Unsafe methods")
131131
DOCTEST_SUBCASE("Inserting a MANAGED node into an unmanaged node")
132132
{
133133
lyd_node* anotherNode;
134-
lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode);
134+
REQUIRE(lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode) == LY_SUCCESS);
135135
auto anotherNodeWrapped = libyang::wrapRawNode(anotherNode);
136136
wrapped.insertSibling(anotherNodeWrapped);
137137
// BOTH are now unmanaged, both are accessible.
@@ -159,7 +159,7 @@ TEST_CASE("Unsafe methods")
159159
DOCTEST_SUBCASE("Inserting a UNMANAGED node into a managed node")
160160
{
161161
lyd_node* anotherNode;
162-
lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode);
162+
REQUIRE(lyd_new_path(nullptr, ctx, "/example-schema:leafInt8", "0", LYD_VALIDATE_PRESENT, &anotherNode) == LY_SUCCESS);
163163
auto anotherNodeWrapped = libyang::wrapRawNode(anotherNode);
164164
anotherNodeWrapped.insertSibling(wrapped);
165165
// BOTH are now managed by C++, both are accessible.
@@ -172,7 +172,7 @@ TEST_CASE("Unsafe methods")
172172
DOCTEST_SUBCASE("Query identity from unmanaged node")
173173
{
174174
lyd_node* node;
175-
lyd_new_path(nullptr, ctx, "/example-schema:leafFoodTypedef", "example-schema:pizza", LYD_VALIDATE_PRESENT, &node);
175+
REQUIRE(lyd_new_path(nullptr, ctx, "/example-schema:leafFoodTypedef", "example-schema:pizza", LYD_VALIDATE_PRESENT, &node) == LY_SUCCESS);
176176
auto wrappedNode = libyang::wrapUnmanagedRawNode(const_cast<const lyd_node*>(node));
177177

178178
REQUIRE(wrappedNode.path() == "/example-schema:leafFoodTypedef");

0 commit comments

Comments
 (0)