114Ensure (xmlutils, parse_entity_oval_timestamp)
116 gchar *generator_name;
117 entity_t generator, timestamp, entity;
120 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
122 "xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/"
123 "oval-definitions-5 oval-definitions-schema.xsd "
124 "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux "
125 "linux-definitions-schema.xsd "
126 "http://oval.mitre.org/XMLSchema/oval-definitions-5#windows "
127 "windows-definitions-schema.xsd "
128 "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent "
129 "independent-definitions-schema.xsd "
130 "http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd "
131 "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix "
132 "unix-definitions-schema.xsd\" "
133 "xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" "
134 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
135 "xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" "
136 "xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">"
138 " <oval:product_name>The OVAL Repository</oval:product_name>"
139 " <oval:schema_version>5.10</oval:schema_version>"
140 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>"
142 "</oval_definitions>";
144 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
146 assert_that (
entity_name (entity), is_equal_to_string (
"oval_definitions"));
147 generator_name = g_strdup (
"generator");
149 g_free (generator_name);
150 assert_that (generator, is_not_null);
152 assert_that (timestamp, is_not_null);
154 is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
161Ensure (xmlutils, next_entities_handles_multiple_children)
167 xml =
"<top><a>1</a><b></b><c>3</c></top>";
169 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
171 assert_that (
entity_name (entity), is_equal_to_string (
"top"));
176 assert_that (child, is_not_null);
177 assert_that (
entity_name (child), is_equal_to_string (
"a"));
178 assert_that (
entity_text (child), is_equal_to_string (
"1"));
182 assert_that (child, is_not_null);
183 assert_that (
entity_name (child), is_equal_to_string (
"b"));
184 assert_that (
entity_text (child), is_equal_to_string (
""));
188 assert_that (child, is_not_null);
189 assert_that (
entity_name (child), is_equal_to_string (
"c"));
190 assert_that (
entity_text (child), is_equal_to_string (
"3"));
261Ensure (xmlutils, parse_element_handles_namespace)
267 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><n:b ba1='test' "
268 "n2:ba2='test2'>1</n:b></a>";
270 assert_that (
parse_element (xml, &element), is_equal_to (0));
272 assert_that (
element_name (element), is_equal_to_string (
"a"));
275 assert_that (
element_name (b), is_equal_to_string (
"n:b"));
278 assert_that (text, is_equal_to_string (
"1"));
282 assert_that (attr, is_equal_to_string (
"test2"));
288Ensure (xmlutils, parse_element_oval_timestamp)
290 gchar *generator_name, *text;
294 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
296 "xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/"
297 "oval-definitions-5 oval-definitions-schema.xsd "
298 "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux "
299 "linux-definitions-schema.xsd "
300 "http://oval.mitre.org/XMLSchema/oval-definitions-5#windows "
301 "windows-definitions-schema.xsd "
302 "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent "
303 "independent-definitions-schema.xsd "
304 "http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd "
305 "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix "
306 "unix-definitions-schema.xsd\" "
307 "xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" "
308 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
309 "xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" "
310 "xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">"
312 " <oval:product_name>The OVAL Repository</oval:product_name>"
313 " <oval:schema_version>5.10</oval:schema_version>"
314 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>"
316 "</oval_definitions>";
318 assert_that (
parse_element (xml, &element), is_equal_to (0));
320 assert_that (
element_name (element), is_equal_to_string (
"oval_definitions"));
321 generator_name = g_strdup (
"generator");
323 g_free (generator_name);
324 assert_that (generator, is_not_null);
326 assert_that (timestamp, is_not_null);
329 assert_that (text, is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
335Ensure (xmlutils, parse_element_item_metadata)
343 "a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">"
344 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle "
345 "Books (aka com.kindle.books.for99) for android 6.0</title>"
348 "href=\"https://play.google.com/store/apps/"
349 "details?id=com.kindle.books.for99\">Product information</reference>"
351 "href=\"https://docs.google.com/spreadsheets/d/"
352 "1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/"
353 "edit?pli=1#gid=1053404143\">Government Advisory</reference>"
355 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" "
356 "modification-date=\"2014-11-10T17:01:25.103Z\"/>"
360 assert_that (
parse_element (xml, &element), is_equal_to (0));
362 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
364 assert_that (item, is_not_null);
366 assert_that (meta, is_not_null);
367 assert_that (
element_name (meta), is_equal_to_string (
"meta:item-metadata"));
372Ensure (xmlutils, parse_element_item_metadata_with_namespace)
377 xml =
"<cpe-list xmlns=\"http://cpe.mitre.org/dictionary/2.0\" "
378 "xmlns:ns6=\"http://scap.nist.gov/schema/scap-core/0.1\" "
379 "xmlns:config=\"http://scap.nist.gov/schema/configuration/0.1\" "
380 "xmlns:meta=\"http://scap.nist.gov/schema/cpe-dictionary-metadata/"
381 "0.2\" xmlns:cpe-23=\"http://scap.nist.gov/schema/cpe-extension/2.3\" "
382 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
383 "xmlns:scap-core=\"http://scap.nist.gov/schema/scap-core/0.3\" "
384 "xsi:schemaLocation=\"http://cpe.mitre.org/dictionary/2.0 "
385 "https://scap.nist.gov/schema/cpe/2.2/cpe-dictionary_2.2.xsd "
386 "http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 "
387 "https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd "
388 "http://scap.nist.gov/schema/scap-core/0.3 "
389 "https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd "
390 "http://scap.nist.gov/schema/configuration/0.1 "
391 "https://scap.nist.gov/schema/nvd/configuration_0.1.xsd "
392 "http://scap.nist.gov/schema/scap-core/0.1 "
393 "https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd\">"
396 "a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">"
397 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle "
398 "Books (aka com.kindle.books.for99) for android 6.0</title>"
401 "href=\"https://play.google.com/store/apps/"
402 "details?id=com.kindle.books.for99\">Product information</reference>"
404 "href=\"https://docs.google.com/spreadsheets/d/"
405 "1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/"
406 "edit?pli=1#gid=1053404143\">Government Advisory</reference>"
408 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" "
409 "modification-date=\"2014-11-10T17:01:25.103Z\"/>"
413 assert_that (
parse_element (xml, &element), is_equal_to (0));
415 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
417 assert_that (item, is_not_null);
419 assert_that (meta, is_not_null);
421 assert_that (
element_name (meta), is_equal_to_string (
"item-metadata"));
510Ensure (xmlutils, element_next_handles_multiple_children)
516 xml =
"<top><a>1</a><b>2</b><c>3</c></top>";
518 assert_that (
parse_element (xml, &element), is_equal_to (0));
520 assert_that (
element_name (element), is_equal_to_string (
"top"));
523 assert_that (child, is_not_null);
524 assert_that (
element_name (child), is_equal_to_string (
"a"));
526 assert_that (text, is_equal_to_string (
"1"));
530 assert_that (child, is_not_null);
531 assert_that (
element_name (child), is_equal_to_string (
"b"));
533 assert_that (text, is_equal_to_string (
"2"));
537 assert_that (child, is_not_null);
538 assert_that (
element_name (child), is_equal_to_string (
"c"));
540 assert_that (text, is_equal_to_string (
"3"));
581Ensure (xmlutils, depth1_returns_top_level_children_in_order)
584 const char *xml =
"<root>"
591 assert_that (path, is_not_null);
601 assert_that (err, is_null);
602 assert_that (e, is_not_null);
603 assert_that (
element_name (e), is_equal_to_string (
"a"));
605 assert_that (text, is_equal_to_string (
"A"));
610 assert_that (err, is_null);
611 assert_that (e, is_not_null);
612 assert_that (
element_name (e), is_equal_to_string (
"b"));
614 assert_that (text, is_equal_to_string (
"B"));
619 assert_that (err, is_null);
620 assert_that (e, is_not_null);
621 assert_that (
element_name (e), is_equal_to_string (
"c"));
623 assert_that (d, is_not_null);
625 assert_that (text, is_equal_to_string (
"D"));
630 assert_that (e, is_null);
631 assert_that (err, is_null);
638Ensure (xmlutils, depth2_returns_grandchildren)
641 const char *xml =
"<root>"
643 " <c><d id='1'>D</d><d id='2'>E</d></c>"
647 assert_that (path, is_not_null);
659 assert_that (err, is_null);
660 assert_that (e, is_not_null);
661 assert_that (
element_name (e), is_equal_to_string (
"d"));
663 assert_that (attr, is_equal_to_string (
"1"));
668 assert_that (err, is_null);
669 assert_that (e, is_not_null);
670 assert_that (
element_name (e), is_equal_to_string (
"d"));
672 assert_that (attr, is_equal_to_string (
"2"));
677 assert_that (e, is_null);
678 assert_that (err, is_null);
725 suite = create_test_suite ();
727 add_test_with_context (suite, xmlutils, parse_entity_parses_simple_xml);
728 add_test_with_context (suite, xmlutils,
729 parse_entity_parses_xml_with_attributes);
730 add_test_with_context (suite, xmlutils, parse_entity_handles_declaration);
731 add_test_with_context (suite, xmlutils, parse_entity_handles_namespace);
732 add_test_with_context (suite, xmlutils, parse_entity_oval_timestamp);
734 add_test_with_context (suite, xmlutils,
735 next_entities_handles_multiple_children);
737 add_test_with_context (suite, xmlutils, parse_element_parses_simple_xml);
738 add_test_with_context (suite, xmlutils,
739 parse_element_parses_xml_with_attributes);
740 add_test_with_context (suite, xmlutils, parse_element_handles_declaration);
741 add_test_with_context (suite, xmlutils, parse_element_handles_namespace);
742 add_test_with_context (suite, xmlutils, parse_element_oval_timestamp);
743 add_test_with_context (suite, xmlutils, parse_element_item_metadata);
744 add_test_with_context (suite, xmlutils,
745 parse_element_item_metadata_with_namespace);
746 add_test_with_context (suite, xmlutils, parse_element_item_handles_cdata);
747 add_test_with_context (suite, xmlutils, parse_element_free_using_child);
749 add_test_with_context (suite, xmlutils, print_element_to_string_prints);
751 add_test_with_context (suite, xmlutils,
752 element_next_handles_multiple_children);
754 add_test_with_context (suite, xmlutils,
755 depth1_returns_top_level_children_in_order);
757 add_test_with_context (suite, xmlutils, depth2_returns_grandchildren);
759 add_test_with_context (suite, xmlutils, rewind_resets_state);
762 ret = run_single_test (suite, argv[1], create_text_reporter ());
764 ret = run_test_suite (suite, create_text_reporter ());
766 destroy_test_suite (suite);