File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ if(BUILD_TESTING)
118118 endfunction ()
119119
120120 libyang_cpp_test (context )
121+ target_link_libraries (test_context PkgConfig::LIBYANG )
121122 libyang_cpp_test (data_node )
122123 target_link_libraries (test_data_node PkgConfig::LIBYANG )
123124 libyang_cpp_test (schema_node )
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class LIBYANG_CPP_EXPORT Error : public std::runtime_error {
3535class LIBYANG_CPP_EXPORT ParsedInfoUnavailable : public Error {
3636public:
3737 explicit ParsedInfoUnavailable ();
38+ explicit ParsedInfoUnavailable (const std::string& what);
3839};
3940
4041/* *
Original file line number Diff line number Diff line change @@ -155,6 +155,9 @@ void Module::setImplemented(const AllFeatures)
155155 */
156156std::vector<Feature> Module::features () const
157157{
158+ if (!m_module->parsed ) {
159+ throw ParsedInfoUnavailable{" Module::features: lys_module::parsed is not available" };
160+ }
158161 std::vector<Feature> res;
159162 for (const auto & feature : std::span (m_module->parsed ->features , LY_ARRAY_COUNT (m_module->parsed ->features ))) {
160163 res.emplace_back (Feature{&feature, m_ctx});
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ ParsedInfoUnavailable::ParsedInfoUnavailable()
2222{
2323}
2424
25+ ParsedInfoUnavailable::ParsedInfoUnavailable (const std::string& what)
26+ : Error(what)
27+ {
28+ }
29+
2530ErrorCode ErrorWithCode::code () const
2631{
2732 return m_errCode;
Original file line number Diff line number Diff line change 1010#include < fstream>
1111#include < libyang-cpp/Context.hpp>
1212#include < libyang-cpp/Utils.hpp>
13+ #include < libyang/context.h>
1314#include " example_schema.hpp"
1415#include " pretty_printers.hpp"
1516#include " test_vars.hpp"
@@ -333,6 +334,17 @@ TEST_CASE("context")
333334 REQUIRE (enabledFeatures == expectedEnabledFeatures);
334335 }
335336
337+ DOCTEST_SUBCASE (" printed context" )
338+ {
339+ ctx->setSearchDir (TESTS_DIR / " yang" );
340+ auto mod = ctx->loadModule (" mod1" , std::nullopt , {" *" });
341+ REQUIRE (mod.features ().size () == 3 );
342+ ly_ctx_free_parsed (retrieveContext (*ctx));
343+ REQUIRE_THROWS_WITH_AS (mod.features (),
344+ " Module::features: lys_module::parsed is not available" ,
345+ libyang::ParsedInfoUnavailable);
346+ }
347+
336348 DOCTEST_SUBCASE (" Module::setImplemented" )
337349 {
338350 ctx->setSearchDir (TESTS_DIR / " yang" );
You can’t perform that action at this time.
0 commit comments