Commit 4199d35
Fix XML parser error (bug: 0000058)
Changed files (5)
modifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/TestBirdFont.valamodifiedlibbirdfont/TestCases.valamodifiedlibbirdxml/Tag.valamodifiedlibbirdxml/Xml.vala
Diff
@@ -483,6 +483,8 @@ public class BirdFont { DefaultCharacterSet.get_characters_for_prefered_language (); HeadTable.init ();+ + TestBirdFont.run_tests (); } public static void set_bundle_path (string path) {@@ -50,7 +50,6 @@ class TestBirdFont : GLib.Object { test_cases = tests.get_test_functions (); current_case = test_cases.first (); test_cases_to_run = "All"; - from_command_line (); } @@ -62,6 +61,12 @@ class TestBirdFont : GLib.Object { slow_test = s; } + public static void run_tests () { + TestBirdFont t = get_singleton (); + state = RUNNING; + t.run_all_tests (); + } + public static TestBirdFont get_singleton () { if (singleton == null) { singleton = new TestBirdFont (); @@ -105,7 +110,7 @@ class TestBirdFont : GLib.Object { if (st == "All" || st == "") { return; } else { - stderr.printf (@"Run only test case \"$st\" \n"); + stderr.printf (@"Run test case \"$st\" \n"); } test_cases_to_run = st; @@ -210,7 +215,7 @@ class TestBirdFont : GLib.Object { has_failed = false; has_skipped = false; - + if (test_cases_to_run != "All" && test_cases_to_run != test.name) { has_skipped = true; } else { @@ -12,6 +12,8 @@ Lesser General Public License for more details. */ +using Bird;+ namespace BirdFont { /** All the things we want to test listed is here. */@@ -47,6 +49,7 @@ class TestCases { add (test_double_quadratic, "Double quadratic"); add (test_raster_path, "Raster path"); add (test_file_path, "File path");+ add (test_xml, "XML"); add_bechmark (benchmark_stroke, "Stroke"); }@@ -1284,6 +1287,45 @@ class TestCases { warning (@"Wrong folder, $folder"); } }+ + static void test_xml () {+ Tag root;+ XmlParser parser;++ parser = new XmlParser ("""<g><g><g></g><g><g></g></g></g></g>"""); ++ root = parser.get_root_tag ();+ print_tags (root);++ if (parser.validate ()) {+ root = parser.get_root_tag ();+ print_tags (root);+ } else {+ warning ("Invalid XML code.");+ }++ }++ static void print_tags (Tag tag) {+ print (tag.get_name ());+ print ("\n");+ print_attributes (tag);+ print (tag.get_content ());++ foreach (Tag t in tag) {+ print_tags (t);+ }+ }++ static void print_attributes (Tag tag) {+ Attributes attributes = tag.get_attributes ();+ foreach (Attribute attribute in attributes) {+ print ("\t");+ print (attribute.get_name ());+ print ("\n");+ }+ }+ } }@@ -253,8 +253,8 @@ public class Tag { int index = start; int slash_index = start; int previous_index;- unichar c;- int start_count = 0;+ unichar c, slash;+ int start_count = 1; if (name.length == 0) { error = true;@@ -265,14 +265,15 @@ public class Tag { while (true) { previous_index = index; if (!data.get_next_char (ref index, out c)) {+ warn (@"Unexpected end of file"); break; } if (c == '<') { slash_index = index;- data.get_next_char (ref slash_index, out c);- if (c == '/' && is_tag (name, slash_index)) {- if (start_count == 0) {+ data.get_next_char (ref slash_index, out slash);+ if (slash == '/' && is_tag (name, slash_index)) {+ if (start_count == 1) { return previous_index; } else { start_count--;@@ -281,7 +282,7 @@ public class Tag { } } } else if (is_tag (name, index)) {- start_count++; + start_count++; } } }@@ -306,7 +307,6 @@ public class Tag { } } - if (data.get_next_char (ref data_index, out c_data)) { return c_data == '>' || c_data == ' ' || c_data == '\t' || c_data == '\n' || c_data == '\r' || c_data == '/';@@ -60,7 +60,7 @@ internal const int WARNINGS = 1; * void print_attributes (Tag tag) { * Attributes attributes = tag.get_attributes (); * foreach (Attribute attribute in attributes) {- * print (attribute.get_name ()");+ * print (attribute.get_name ()); * print ("\n"); * } * }