@@ -49,7 +49,7 @@ TEST(test_ly_ctx_new)
4949 ASSERT_EQ (2 , list.size ());
5050 } catch ( const std::exception& e ) {
5151 mt::printFailed (e.what (), stdout);
52- return ;
52+ throw ;
5353 }
5454}
5555
@@ -79,7 +79,7 @@ TEST(test_ly_ctx_get_searchdirs)
7979 ASSERT_EQ (yang_folder, list.at (0 ));
8080 } catch ( const std::exception& e ) {
8181 mt::printFailed (e.what (), stdout);
82- return ;
82+ throw ;
8383 }
8484}
8585
@@ -107,7 +107,7 @@ TEST(test_ly_ctx_set_searchdir)
107107 ASSERT_EQ (new_yang_folder, list.at (0 ));
108108 } catch ( const std::exception& e ) {
109109 mt::printFailed (e.what (), stdout);
110- return ;
110+ throw ;
111111 }
112112}
113113
@@ -140,7 +140,7 @@ TEST(test_ly_ctx_info)
140140 ASSERT_EQ (LYD_VAL_OK, info->validity ());
141141 } catch ( const std::exception& e ) {
142142 mt::printFailed (e.what (), stdout);
143- return ;
143+ throw ;
144144 }
145145}
146146
@@ -198,7 +198,7 @@ TEST(test_ly_ctx_load_get_module)
198198 ASSERT_STREQ (revision, module ->rev ()->date ());
199199 } catch ( const std::exception& e ) {
200200 mt::printFailed (e.what (), stdout);
201- return ;
201+ throw ;
202202 }
203203}
204204
@@ -228,7 +228,7 @@ TEST(test_ly_ctx_get_module_older)
228228 ASSERT_STREQ (revision_older, module_older->rev ()->date ());
229229 } catch ( const std::exception& e ) {
230230 mt::printFailed (e.what (), stdout);
231- return ;
231+ throw ;
232232 }
233233}
234234
@@ -251,7 +251,7 @@ TEST(test_ly_ctx_get_module_by_ns)
251251 ASSERT_STREQ (module_name, module ->name ());
252252 } catch ( const std::exception& e ) {
253253 mt::printFailed (e.what (), stdout);
254- return ;
254+ throw ;
255255 }
256256}
257257
@@ -278,7 +278,7 @@ TEST(test_ly_ctx_clean)
278278 ASSERT_NULL (module );
279279 } catch ( const std::exception& e ) {
280280 mt::printFailed (e.what (), stdout);
281- return ;
281+ throw ;
282282 }
283283}
284284
@@ -303,7 +303,7 @@ TEST(test_ly_ctx_parse_module_path)
303303 ASSERT_STREQ (module_name2, module ->name ());
304304 } catch ( const std::exception& e ) {
305305 mt::printFailed (e.what (), stdout);
306- return ;
306+ throw ;
307307 }
308308}
309309
@@ -340,7 +340,7 @@ TEST(test_ly_ctx_get_submodule)
340340 ASSERT_STREQ (sub_name, submodule->name ());
341341 } catch ( const std::exception& e ) {
342342 mt::printFailed (e.what (), stdout);
343- return ;
343+ throw ;
344344 }
345345}
346346
@@ -365,7 +365,7 @@ TEST(test_ly_ctx_get_submodule2)
365365 ASSERT_STREQ (sub_name, submodule->name ());
366366 } catch ( const std::exception& e ) {
367367 mt::printFailed (e.what (), stdout);
368- return ;
368+ throw ;
369369 }
370370}
371371
@@ -391,7 +391,7 @@ TEST(test_ly_ctx_find_path)
391391 std::make_shared<libyang::Set>();
392392 } catch ( const std::exception& e ) {
393393 mt::printFailed (e.what (), stdout);
394- return ;
394+ throw ;
395395 }
396396}
397397
@@ -431,7 +431,142 @@ TEST(test_ly_set)
431431 ASSERT_EQ (0 , set->number ());
432432 } catch ( const std::exception& e ) {
433433 mt::printFailed (e.what (), stdout);
434- return ;
434+ throw ;
435+ }
436+ }
437+
438+ TEST (test_ly_ctx_new_ylpath)
439+ {
440+ const char *yang_folder = TESTS_DIR " /api/files" ;
441+ const char *path = TESTS_DIR " /api/files/ylpath.xml" ;
442+
443+ try {
444+ auto ctx = std::make_shared<libyang::Context>(yang_folder, path, LYD_XML, 0 );
445+ ASSERT_FALSE (nullptr == ctx);
446+ auto list = std::make_shared<std::vector<std::string>>(ctx->get_searchdirs ());
447+ ASSERT_FALSE (nullptr == list);
448+ ASSERT_EQ (1 , list->size ());
449+
450+ } catch ( const std::exception& e ) {
451+ mt::printFailed (e.what (), stdout);
452+ throw ;
453+ }
454+ }
455+
456+ TEST (test_ly_ctx_new_ylmem)
457+ {
458+ const char *yang_folder = TESTS_DIR " /api/files" ;
459+
460+ try {
461+ auto ctx = std::make_shared<libyang::Context>(yang_folder);
462+ ASSERT_FALSE (nullptr == ctx);
463+ auto info = ctx->info ();
464+ ASSERT_FALSE (nullptr == info);
465+ ASSERT_EQ (LYD_VAL_OK, info->validity ());
466+
467+ auto mem = info->print_mem (LYD_XML, 0 );
468+ auto new_ctx = std::make_shared<libyang::Context>(yang_folder, LYD_XML, mem.data (), 0 );
469+ ASSERT_FALSE (nullptr == new_ctx);
470+ auto list = std::make_shared<std::vector<std::string>>(new_ctx->get_searchdirs ());
471+ ASSERT_FALSE (nullptr == list);
472+ ASSERT_EQ (1 , list->size ());
473+ } catch ( const std::exception& e ) {
474+ mt::printFailed (e.what (), stdout);
475+ throw ;
476+ }
477+ }
478+
479+ TEST (test_ly_ctx_get_module_iter)
480+ {
481+ const char *yang_folder = TESTS_DIR " /api/files" ;
482+ const char *module_name = " a" ;
483+
484+ try {
485+ auto ctx = std::make_shared<libyang::Context>(yang_folder);
486+ ASSERT_NOTNULL (ctx);
487+
488+ auto module = ctx->load_module (module_name);
489+ ASSERT_NOTNULL (module );
490+ ASSERT_STREQ (module_name, module ->name ());
491+ auto list = std::make_shared<std::vector<libyang::S_Module>>(ctx->get_module_iter ());
492+ ASSERT_NOTNULL (list);
493+ ASSERT_EQ (7 , list->size ());
494+ } catch ( const std::exception& e ) {
495+ mt::printFailed (e.what (), stdout);
496+ throw ;
497+ }
498+ }
499+
500+ TEST (test_ly_ctx_get_disabled_module_iter)
501+ {
502+ const char *yang_folder = TESTS_DIR " /api/files" ;
503+ const char *module_name = " x" ;
504+
505+ try {
506+ auto ctx = std::make_shared<libyang::Context>(yang_folder);
507+ ASSERT_NOTNULL (ctx);
508+
509+ auto module = ctx->load_module (module_name);
510+ ASSERT_NOTNULL (module );
511+ ASSERT_STREQ (module_name, module ->name ());
512+ // FIXME no way to disable module from here
513+
514+ auto list = std::make_shared<std::vector<libyang::S_Module>>(ctx->get_disabled_module_iter ());
515+ ASSERT_NOTNULL (list);
516+ ASSERT_EQ (0 , list->size ());
517+ } catch ( const std::exception& e ) {
518+ mt::printFailed (e.what (), stdout);
519+ throw ;
520+ }
521+ }
522+
523+ TEST (test_ly_ctx_data_instantiables)
524+ {
525+ const char *yang_folder = TESTS_DIR " /api/files" ;
526+ const char *module_name = " b" ;
527+
528+ try {
529+ auto ctx = std::make_shared<libyang::Context>(yang_folder);
530+ ASSERT_NOTNULL (ctx);
531+
532+ auto module = ctx->load_module (module_name);
533+ ASSERT_NOTNULL (module );
534+ ASSERT_STREQ (module_name, module ->name ());
535+
536+ auto list = std::make_shared<std::vector<libyang::S_Schema_Node>>(ctx->data_instantiables (0 ));
537+ ASSERT_NOTNULL (list);
538+ ASSERT_EQ (5 , list->size ());
539+ } catch ( const std::exception& e ) {
540+ mt::printFailed (e.what (), stdout);
541+ throw ;
542+ }
543+ }
544+
545+ TEST (test_ly_ctx_get_node)
546+ {
547+ const char *yang_folder = TESTS_DIR " /api/files" ;
548+ const char *module_name = " b" ;
549+
550+ try {
551+ auto ctx = std::make_shared<libyang::Context>(yang_folder);
552+ ASSERT_NOTNULL (ctx);
553+
554+ auto module = ctx->load_module (module_name);
555+ ASSERT_NOTNULL (module );
556+ ASSERT_STREQ (module_name, module ->name ());
557+
558+ auto list = std::make_shared<std::vector<libyang::S_Schema_Node>>(ctx->data_instantiables (0 ));
559+ ASSERT_NOTNULL (list);
560+ ASSERT_EQ (5 , list->size ());
561+
562+ auto schema = list->back ();
563+ ASSERT_NOTNULL (schema);
564+ auto node = ctx->get_node (schema, " /b:x/b:bubba" , 0 );
565+ ASSERT_NOTNULL (node);
566+
567+ } catch ( const std::exception& e ) {
568+ mt::printFailed (e.what (), stdout);
569+ throw ;
435570 }
436571}
437572
0 commit comments