@@ -159,6 +159,61 @@ test_anydata(void **state)
159159 lyd_free_all (tree );
160160}
161161
162+ static void
163+ test_anydata_strict_validation (void * * state )
164+ {
165+ const char * data_without_schema ;
166+ const char * data_invalid ;
167+ const char * data_valid ;
168+ char * str ;
169+ struct lyd_node * tree ;
170+
171+ // no shcema defiend for "urn:tests:no:schema" in the parsing context
172+ data_without_schema = "<any xmlns=\"urn:tests:a\">\n"
173+ " <x:element1 xmlns:x=\"urn:tests:no:schema\">\n"
174+ " <x:element2>default-val</x:element2>\n"
175+ " </x:element1>\n"
176+ "</any>\n" ;
177+
178+ PARSER_CHECK_ERROR (data_without_schema , LYD_PARSE_ANYDATA_STRICT , LYD_VALIDATE_PRESENT , tree , LY_EVALID ,
179+ "No module with namespace \"urn:tests:no:schema\" in the context." , "/a:any" , 3 );
180+
181+ // anydata value are based on "module a" defined in the setup function and loaded into the parsing context.
182+ // However, the value passed in the anydata subtree is not defined in "module a".
183+ data_invalid = "<any xmlns=\"urn:tests:a\">\n"
184+ " <element1>default-val</element1>\n"
185+ "</any>\n" ;
186+
187+ PARSER_CHECK_ERROR (data_invalid , LYD_PARSE_ANYDATA_STRICT , LYD_VALIDATE_PRESENT , tree , LY_EVALID ,
188+ "Node \"element1\" not found in the \"a\" module." , "/a:any" , 2 );
189+
190+ // anydata value are based on "module a" defined in the setup function and loaded into the parsing context
191+ data_valid = "<any xmlns=\"urn:tests:a\">\n"
192+ " <foo>default-val</foo>\n"
193+ "</any>\n" ;
194+
195+ CHECK_PARSE_LYD (data_valid , LYD_PARSE_ANYDATA_STRICT , LYD_VALIDATE_PRESENT , tree );
196+ assert_non_null (tree );
197+ tree = tree -> next ;
198+ CHECK_LYSC_NODE (tree -> schema , NULL , 0 , LYS_CONFIG_R | LYS_STATUS_CURR | LYS_SET_CONFIG , 1 , "any" ,
199+ 1 , LYS_ANYDATA , 0 , 0 , NULL , 0 );
200+
201+ const char * data_expected =
202+ "<any xmlns=\"urn:tests:a\">\n"
203+ " <foo>default-val</foo>\n"
204+ "</any>\n" ;
205+
206+ CHECK_LYD_STRING (tree , LYD_PRINT_SIBLINGS , data_expected );
207+
208+ assert_int_equal (LY_SUCCESS , lyd_any_value_str (tree , & str ));
209+ lyd_free_all (tree );
210+
211+ assert_int_equal (LY_SUCCESS , lyd_new_path2 (NULL , UTEST_LYCTX , "/a:any" , str , strlen (str ), LYD_ANYDATA_XML , 0 , & tree , NULL ));
212+ free (str );
213+ CHECK_LYD_STRING (tree , LYD_PRINT_SIBLINGS , data_expected );
214+ lyd_free_all (tree );
215+ }
216+
162217static void
163218test_anyxml (void * * state )
164219{
@@ -1042,6 +1097,7 @@ main(void)
10421097 const struct CMUnitTest tests [] = {
10431098 UTEST (test_leaf , setup ),
10441099 UTEST (test_anydata , setup ),
1100+ UTEST (test_anydata_strict_validation , setup ),
10451101 UTEST (test_anyxml , setup ),
10461102 UTEST (test_list , setup ),
10471103 UTEST (test_container , setup ),
0 commit comments