[gxml] test/: remove usage of deprecated GXmlDomError
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] test/: remove usage of deprecated GXmlDomError
- Date: Fri, 23 Aug 2013 20:58:31 +0000 (UTC)
commit eeb40e95b34693408a6f37eec05d5eb414f99402
Author: Richard Schwarting <aquarichy gmail com>
Date: Tue Aug 6 15:56:55 2013 +0200
test/: remove usage of deprecated GXmlDomError
test/AttrTest.vala | 292 ++++++++------------
test/CharacterDataTest.vala | 125 +++------
test/DocumentTest.vala | 247 ++++++-----------
test/ElementTest.vala | 616 ++++++++++++++++++-----------------------
test/GXmlTest.vala | 17 +-
test/NodeTest.vala | 652 +++++++++++++++++++------------------------
test/SerializableTest.vala | 13 +-
test/SerializationTest.vala | 3 -
test/TextTest.vala | 76 +++---
9 files changed, 846 insertions(+), 1195 deletions(-)
---
diff --git a/test/AttrTest.vala b/test/AttrTest.vala
index 10eb880..bba12cd 100644
--- a/test/AttrTest.vala
+++ b/test/AttrTest.vala
@@ -1,215 +1,151 @@
/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
using GXml;
+/* TODO: add tests for g_warnings being set; apparently you can trap g_criticals and test error messages
with gtester */
class AttrTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/element/namespace_uri", () => {
- try {
- Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
- GXml.Node root = doc.document_element;
- Element node = (Element)root.child_nodes.item (0);
-
- Attr core = node.get_attribute_node ("core");
- Attr shell = node.get_attribute_node ("shell");
- Attr price = node.get_attribute_node ("price");
-
- assert (core.namespace_uri == "http://mom.co.uk/wands");
- assert (shell.namespace_uri == "http://mom.co.uk/wands");
- assert (price.namespace_uri == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
+ GXml.Node root = doc.document_element;
+ Element node = (Element)root.child_nodes.item (0);
+
+ Attr core = node.get_attribute_node ("core");
+ Attr shell = node.get_attribute_node ("shell");
+ Attr price = node.get_attribute_node ("price");
+
+ assert (core.namespace_uri == "http://mom.co.uk/wands");
+ assert (shell.namespace_uri == "http://mom.co.uk/wands");
+ assert (price.namespace_uri == null);
});
Test.add_func ("/gxml/element/prefix", () => {
- try {
- Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
- GXml.Node root = doc.document_element;
- Element node = (Element)root.child_nodes.item (0);
-
- Attr core = node.get_attribute_node ("core");
- Attr shell = node.get_attribute_node ("shell");
- Attr price = node.get_attribute_node ("price");
-
- assert (core.prefix == "wands");
- assert (shell.prefix == "wands");
- assert (price.prefix == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
+ GXml.Node root = doc.document_element;
+ Element node = (Element)root.child_nodes.item (0);
+
+ Attr core = node.get_attribute_node ("core");
+ Attr shell = node.get_attribute_node ("shell");
+ Attr price = node.get_attribute_node ("price");
+
+ assert (core.prefix == "wands");
+ assert (shell.prefix == "wands");
+ assert (price.prefix == null);
});
Test.add_func ("/gxml/element/local_name", () => {
- try {
- Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
- GXml.Node root = doc.document_element;
- Element node = (Element)root.child_nodes.item (0);
-
- Attr core = node.get_attribute_node ("core");
- Attr shell = node.get_attribute_node ("shell");
- Attr price = node.get_attribute_node ("price");
-
- assert (core.local_name == "core");
- assert (shell.local_name == "shell");
- assert (price.local_name == "price");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Wands
xmlns:wands=\"http://mom.co.uk/wands\"><Wand price=\"43.56\" wands:core=\"dragon heart cord\"
wands:shell=\"oak\"/></Wands>");
+ GXml.Node root = doc.document_element;
+ Element node = (Element)root.child_nodes.item (0);
+
+ Attr core = node.get_attribute_node ("core");
+ Attr shell = node.get_attribute_node ("shell");
+ Attr price = node.get_attribute_node ("price");
+
+ assert (core.local_name == "core");
+ assert (shell.local_name == "shell");
+ assert (price.local_name == "price");
});
Test.add_func ("/gxml/attribute/node_name", () => {
- try {
- Document doc = get_doc ();
- Attr attr = get_attr ("broomSeries", "Nimbus", doc);
-
- assert (attr.node_name == "broomSeries");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = get_attr ("broomSeries", "Nimbus", doc);
+
+ assert (attr.node_name == "broomSeries");
});
Test.add_func ("/gxml/attribute/node_value", () => {
- try {
- Document doc = get_doc ();
- Attr attr = doc.create_attribute ("bank");
-
- assert (attr.node_value == "");
- attr.node_value = "Gringots";
- assert (attr.node_value == "Gringots");
- attr.node_value = "Wizardlies";
- assert (attr.node_value == "Wizardlies");
- /* make sure changing .value changes .node_value */
- attr.value = "Gringots";
- assert (attr.node_value == "Gringots");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = doc.create_attribute ("bank");
+
+ assert (attr.node_value == "");
+ attr.node_value = "Gringots";
+ assert (attr.node_value == "Gringots");
+ attr.node_value = "Wizardlies";
+ assert (attr.node_value == "Wizardlies");
+ /* make sure changing .value changes .node_value */
+ attr.value = "Gringots";
+ assert (attr.node_value == "Gringots");
});
Test.add_func ("/gxml/attribute/name", () => {
- try {
- Document doc = get_doc ();
- Attr attr = get_attr ("broomSeries", "Nimbus", doc);
-
- assert (attr.name == "broomSeries");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = get_attr ("broomSeries", "Nimbus", doc);
+
+ assert (attr.name == "broomSeries");
});
Test.add_func ("/gxml/attribute/node_value", () => {
- try {
- Document doc = get_doc ();
- Attr attr = doc.create_attribute ("bank");
-
- assert (attr.value == "");
- attr.value = "Gringots";
- assert (attr.value == "Gringots");
- attr.value = "Wizardlies";
- assert (attr.value == "Wizardlies");
- /* make sure changing .node_value changes .value */
- attr.node_value = "Gringots";
- assert (attr.value == "Gringots");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = doc.create_attribute ("bank");
+
+ assert (attr.value == "");
+ attr.value = "Gringots";
+ assert (attr.value == "Gringots");
+ attr.value = "Wizardlies";
+ assert (attr.value == "Wizardlies");
+ /* make sure changing .node_value changes .value */
+ attr.node_value = "Gringots";
+ assert (attr.value == "Gringots");
});
Test.add_func ("/gxml/attribute/specified", () => {
// TODO: involves supporting DTDs, which come later
});
Test.add_func ("/gxml/attribute/parent_node", () => {
- try {
- Document doc = get_doc ();
- Element elem = get_elem ("creature", doc);
- Attr attr = get_attr ("breed", "Dragons", doc);
-
- assert (attr.parent_node == null);
- elem.set_attribute_node (attr);
- assert (attr.parent_node == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Element elem = get_elem ("creature", doc);
+ Attr attr = get_attr ("breed", "Dragons", doc);
+
+ assert (attr.parent_node == null);
+ elem.set_attribute_node (attr);
+ assert (attr.parent_node == null);
});
Test.add_func ("/gxml/attribute/previous_sibling", () => {
- try {
- Document doc = get_doc ();
- Element elem = get_elem ("creature", doc);
- Attr attr1 = get_attr ("breed", "Dragons", doc);
- Attr attr2 = get_attr ("size", "large", doc);
-
- elem.set_attribute_node (attr1);
- elem.set_attribute_node (attr2);
-
- assert (attr1.previous_sibling == null);
- assert (attr2.previous_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Element elem = get_elem ("creature", doc);
+ Attr attr1 = get_attr ("breed", "Dragons", doc);
+ Attr attr2 = get_attr ("size", "large", doc);
+
+ elem.set_attribute_node (attr1);
+ elem.set_attribute_node (attr2);
+
+ assert (attr1.previous_sibling == null);
+ assert (attr2.previous_sibling == null);
});
Test.add_func ("/gxml/attribute/next_sibling", () => {
- try {
- Document doc = get_doc ();
- Element elem = get_elem ("creature", doc);
- Attr attr1 = get_attr ("breed", "Dragons", doc);
- Attr attr2 = get_attr ("size", "large", doc);
-
- elem.set_attribute_node (attr1);
- elem.set_attribute_node (attr2);
-
- assert (attr1.next_sibling == null);
- assert (attr2.next_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Element elem = get_elem ("creature", doc);
+ Attr attr1 = get_attr ("breed", "Dragons", doc);
+ Attr attr2 = get_attr ("size", "large", doc);
+
+ elem.set_attribute_node (attr1);
+ elem.set_attribute_node (attr2);
+
+ assert (attr1.next_sibling == null);
+ assert (attr2.next_sibling == null);
});
Test.add_func ("/gxml/attribute/insert_before", () => {
- try {
- Document doc = get_doc ();
- Attr attr = get_attr ("pie", "Dumbleberry", doc);
- Text txt = doc.create_text_node ("Whipped ");
-
- assert (attr.value == "Dumbleberry");
- attr.insert_before (txt, attr.child_nodes.first ());
- assert (attr.value == "Whipped Dumbleberry");
- // the Text nodes should be merged
- assert (attr.child_nodes.length == 1);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = get_attr ("pie", "Dumbleberry", doc);
+ Text txt = doc.create_text_node ("Whipped ");
+
+ assert (attr.value == "Dumbleberry");
+ attr.insert_before (txt, attr.child_nodes.first ());
+ assert (attr.value == "Whipped Dumbleberry");
+ // the Text nodes should be merged
+ assert (attr.child_nodes.length == 1);
});
Test.add_func ("/gxml/attribute/replace_child", () => {
- try {
- Document doc = get_doc ();
- Attr attr = get_attr ("WinningHouse", "Slytherin", doc);
- Text txt = doc.create_text_node ("Gryffindor");
-
- assert (attr.value == "Slytherin");
- attr.replace_child (txt, attr.child_nodes.item (0));
- assert (attr.value == "Gryffindor");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = get_attr ("WinningHouse", "Slytherin", doc);
+ Text txt = doc.create_text_node ("Gryffindor");
+
+ assert (attr.value == "Slytherin");
+ attr.replace_child (txt, attr.child_nodes.item (0));
+ assert (attr.value == "Gryffindor");
});
Test.add_func ("/gxml/attribute/remove_child", () => {
- try {
- Document doc = get_doc ();
- Attr attr = get_attr ("parchment", "MauraudersMap", doc);
-
- assert (attr.value == "MauraudersMap");
- // mischief managed
- attr.remove_child (attr.child_nodes.last ());
- assert (attr.value == "");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ Attr attr = get_attr ("parchment", "MauraudersMap", doc);
+
+ assert (attr.value == "MauraudersMap");
+ // mischief managed
+ attr.remove_child (attr.child_nodes.last ());
+ assert (attr.value == "");
});
}
}
diff --git a/test/CharacterDataTest.vala b/test/CharacterDataTest.vala
index 4aeb073..899d740 100644
--- a/test/CharacterDataTest.vala
+++ b/test/CharacterDataTest.vala
@@ -4,108 +4,73 @@ using GXml;
class CharacterDataTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/characterdata/data", () => {
- try {
- string str = "It does not do to dwell on dreams and forget to live,
remember that.";
- Document doc;
- Text txt = get_text_new_doc (str, out doc);
+ string str = "It does not do to dwell on dreams and forget to live, remember
that.";
+ Document doc;
+ Text txt = get_text_new_doc (str, out doc);
- assert (txt.data == str);
- assert (txt.data == txt.node_value);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (txt.data == str);
+ assert (txt.data == txt.node_value);
});
Test.add_func ("/gxml/characterdata/length", () => {
- try {
- string str = "After all, to the well-organized mind, death is but the
next great adventure.";
- Document doc;
- Text txt = get_text_new_doc (str, out doc);
+ string str = "After all, to the well-organized mind, death is but the next
great adventure.";
+ Document doc;
+ Text txt = get_text_new_doc (str, out doc);
- assert (txt.length == str.length);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (txt.length == str.length);
});
Test.add_func ("/gxml/characterdata/substring_data", () => {
- try {
- Document doc;
- Text txt = get_text_new_doc ("The trouble is, humans do have a knack
of choosing precisely those things that are worst for them.", out doc);
- string str = txt.substring_data (4, 7);
+ Document doc;
+ Text txt = get_text_new_doc ("The trouble is, humans do have a knack of
choosing precisely those things that are worst for them.", out doc);
+ string str = txt.substring_data (4, 7);
- assert (str == "trouble");
+ assert (str == "trouble");
- // TODO: test bounds
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: test bounds
});
Test.add_func ("/gxml/characterdata/append_data", () => {
- try {
- string str_start = "Never trust anything that can think for itself";
- string str_whole = "Never trust anything that can think for itself if
you can't see where it keeps its brain.";
- Document doc;
- Text txt = get_text_new_doc ("Never trust anything that can think for
itself", out doc);
+ string str_start = "Never trust anything that can think for itself";
+ string str_whole = "Never trust anything that can think for itself if you
can't see where it keeps its brain.";
+ Document doc;
+ Text txt = get_text_new_doc ("Never trust anything that can think for
itself", out doc);
- assert (txt.data == str_start);
- txt.append_data (" if you can't see where it keeps its brain.");
- assert (txt.data == str_whole);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (txt.data == str_start);
+ txt.append_data (" if you can't see where it keeps its brain.");
+ assert (txt.data == str_whole);
});
Test.add_func ("/gxml/characterdata/insert_data", () => {
- try {
- Document doc;
- Text txt = get_text_new_doc ("It is our choices that show what we
are, far more than our abilities.", out doc);
- txt.insert_data (35, " truly");
- assert (txt.data == "It is our choices that show what we truly are,
far more than our abilities.");
+ Document doc;
+ Text txt = get_text_new_doc ("It is our choices that show what we are, far
more than our abilities.", out doc);
+ txt.insert_data (35, " truly");
+ assert (txt.data == "It is our choices that show what we truly are, far more
than our abilities.");
- txt.insert_data (0, "Yes. ");
- assert (txt.data == "Yes. It is our choices that show what we truly
are, far more than our abilities.");
+ txt.insert_data (0, "Yes. ");
+ assert (txt.data == "Yes. It is our choices that show what we truly are, far
more than our abilities.");
- txt.insert_data (txt.data.length, " Indeed.");
- assert (txt.data == "Yes. It is our choices that show what we truly
are, far more than our abilities. Indeed.");
+ txt.insert_data (txt.data.length, " Indeed.");
+ assert (txt.data == "Yes. It is our choices that show what we truly are, far
more than our abilities. Indeed.");
- // should fail
- txt.insert_data (txt.data.length + 1, " Perhaps.");
- assert (txt.data == "Yes. It is our choices that show what we truly
are, far more than our abilities. Indeed.");
+ // should fail
+ txt.insert_data (txt.data.length + 1, " Perhaps.");
+ assert (txt.data == "Yes. It is our choices that show what we truly are, far
more than our abilities. Indeed.");
- // should fail
- txt.insert_data (-1, " No.");
- assert (txt.data == "Yes. It is our choices that show what we truly
are, far more than our abilities. Indeed.");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // should fail
+ txt.insert_data (-1, " No.");
+ assert (txt.data == "Yes. It is our choices that show what we truly are, far
more than our abilities. Indeed.");
});
Test.add_func ("/gxml/characterdata/delete_data", () => {
- try {
- Document doc;
- Text txt = get_text_new_doc ("Happiness can be found, even in the
darkest of times, if one only remembers to turn on the light.", out doc);
- txt.delete_data (14, 65);
- assert (txt.data == "Happiness can turn on the light.");
- // TODO: test bounds
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Text txt = get_text_new_doc ("Happiness can be found, even in the darkest of
times, if one only remembers to turn on the light.", out doc);
+ txt.delete_data (14, 65);
+ assert (txt.data == "Happiness can turn on the light.");
+ // TODO: test bounds
});
Test.add_func ("/gxml/characterdata/replace_data", () => {
- try {
- // TODO: test bounds
+ // TODO: test bounds
- Document doc;
- Text txt = get_text_new_doc ("In dreams, we enter a world that's
entirely our own.", out doc);
- txt.replace_data (3, 6, "the refrigerator");
- assert (txt.data == "In the refrigerator, we enter a world that's
entirely our own.");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Text txt = get_text_new_doc ("In dreams, we enter a world that's entirely our
own.", out doc);
+ txt.replace_data (3, 6, "the refrigerator");
+ assert (txt.data == "In the refrigerator, we enter a world that's entirely
our own.");
});
}
}
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index c19f9e4..30cc373 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -16,43 +16,28 @@ class DocumentTest : GXmlTest {
*/
});
Test.add_func ("/gxml/document/implementation", () => {
- try {
- Document doc = get_doc ();
+ Document doc = get_doc ();
- Implementation impl = doc.implementation;
+ Implementation impl = doc.implementation;
- assert (impl.has_feature ("xml") == true);
- assert (impl.has_feature ("xml", "1.0") == true);
- assert (impl.has_feature ("xml", "2.0") == false);
- assert (impl.has_feature ("html") == false);
- assert (impl.has_feature ("nonsense") == false);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (impl.has_feature ("xml") == true);
+ assert (impl.has_feature ("xml", "1.0") == true);
+ assert (impl.has_feature ("xml", "2.0") == false);
+ assert (impl.has_feature ("html") == false);
+ assert (impl.has_feature ("nonsense") == false);
});
Test.add_func ("/gxml/document/document_element", () => {
- try {
- Document doc = get_doc ();
- Element root = doc.document_element;
+ Document doc = get_doc ();
+ Element root = doc.document_element;
- assert (root.node_name == "Sentences");
- assert (root.has_child_nodes ());
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (root.node_name == "Sentences");
+ assert (root.has_child_nodes ());
});
Test.add_func ("/gxml/document/construct_from_path", () => {
- try {
- Document doc = get_doc ();
+ Document doc = get_doc ();
- check_contents (doc);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ check_contents (doc);
});
Test.add_func ("/gxml/document/construct_from_stream", () => {
try {
@@ -69,19 +54,14 @@ class DocumentTest : GXmlTest {
}
});
Test.add_func ("/gxml/document/construct_from_string", () => {
- try {
- string xml = "<Fruits><Apple></Apple><Orange></Orange></Fruits>";
- Document doc = new Document.from_string (xml);
-
- GXml.Node root = doc.document_element;
- assert (root.node_name == "Fruits");
- assert (root.has_child_nodes () == true);
- assert (root.first_child.node_name == "Apple");
- assert (root.last_child.node_name == "Orange");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ string xml = "<Fruits><Apple></Apple><Orange></Orange></Fruits>";
+ Document doc = new Document.from_string (xml);
+
+ GXml.Node root = doc.document_element;
+ assert (root.node_name == "Fruits");
+ assert (root.has_child_nodes () == true);
+ assert (root.first_child.node_name == "Apple");
+ assert (root.last_child.node_name == "Orange");
});
Test.add_func ("/gxml/document/save", () => {
try {
@@ -131,36 +111,35 @@ class DocumentTest : GXmlTest {
// assert (elem == null); // TODO: decide what we want returned on
DomExceptions
});
Test.add_func ("/gxml/document/create_document_fragment", () => {
- try {
- Document doc = get_doc ();
- DocumentFragment fragment = doc.create_document_fragment ();
-
- // TODO: can we set XML in the content, and actually have that
translate into real libxml2 underlying nodes?
- Element percy = doc.create_element ("Author");
- Element percy_name = doc.create_element ("Name");
- Element percy_email = doc.create_element ("Email");
- percy_name.content = "Percy";
- percy_email.content = "pweasley hogwarts co uk";
- percy.append_child (percy_name);
- percy.append_child (percy_email);
- fragment.append_child (percy);
-
- Element ginny = doc.create_element ("Author");
- Element ginny_name = doc.create_element ("Name");
- Element ginny_email = doc.create_element ("Email");
- ginny_name.content = "Ginny";
- ginny_email.content = "weasleyg hogwarts co uk";
- ginny.append_child (ginny_name);
- ginny.append_child (ginny_email);
- fragment.append_child (ginny);
-
- NodeList authors_list = doc.get_elements_by_tag_name ("Authors");
- assert (authors_list.length == 1);
- Element authors = (Element)authors_list.item (0);
- assert (authors.get_elements_by_tag_name ("Author").length == 2);
- assert (fragment.child_nodes.length == 2);
-
- assert (doc.to_string () == "<?xml version=\"1.0\"?>
+ Document doc = get_doc ();
+ DocumentFragment fragment = doc.create_document_fragment ();
+
+ // TODO: can we set XML in the content, and actually have that translate into
real libxml2 underlying nodes?
+ Element percy = doc.create_element ("Author");
+ Element percy_name = doc.create_element ("Name");
+ Element percy_email = doc.create_element ("Email");
+ percy_name.content = "Percy";
+ percy_email.content = "pweasley hogwarts co uk";
+ percy.append_child (percy_name);
+ percy.append_child (percy_email);
+ fragment.append_child (percy);
+
+ Element ginny = doc.create_element ("Author");
+ Element ginny_name = doc.create_element ("Name");
+ Element ginny_email = doc.create_element ("Email");
+ ginny_name.content = "Ginny";
+ ginny_email.content = "weasleyg hogwarts co uk";
+ ginny.append_child (ginny_name);
+ ginny.append_child (ginny_email);
+ fragment.append_child (ginny);
+
+ NodeList authors_list = doc.get_elements_by_tag_name ("Authors");
+ assert (authors_list.length == 1);
+ Element authors = (Element)authors_list.item (0);
+ assert (authors.get_elements_by_tag_name ("Author").length == 2);
+ assert (fragment.child_nodes.length == 2);
+
+ assert (doc.to_string () == "<?xml version=\"1.0\"?>
<Sentences>
<Sentence lang=\"en\">I like the colour blue.</Sentence>
<Sentence lang=\"de\">Ich liebe die Tür.</Sentence>
@@ -177,10 +156,10 @@ class DocumentTest : GXmlTest {
</Sentences>
");
- authors.append_child (fragment);
- assert (authors.get_elements_by_tag_name ("Author").length == 4);
+ authors.append_child (fragment);
+ assert (authors.get_elements_by_tag_name ("Author").length == 4);
- string expected = "<?xml version=\"1.0\"?>
+ string expected = "<?xml version=\"1.0\"?>
<Sentences>
<Sentence lang=\"en\">I like the colour blue.</Sentence>
<Sentence lang=\"de\">Ich liebe die Tür.</Sentence>
@@ -196,106 +175,66 @@ class DocumentTest : GXmlTest {
<Author><Name>Percy</Name><Email>pweasley hogwarts co
uk</Email></Author><Author><Name>Ginny</Name><Email>weasleyg hogwarts co uk</Email></Author></Authors>
</Sentences>
";
- // TODO: want to find a way to flattern the string, strip whitespace
- assert (doc.to_string () == expected);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: want to find a way to flattern the string, strip whitespace
+ assert (doc.to_string () == expected);
});
Test.add_func ("/gxml/document/create_text_node", () => {
- try {
- Document doc = get_doc ();
- Text text = doc.create_text_node ("Star of my dreams");
+ Document doc = get_doc ();
+ Text text = doc.create_text_node ("Star of my dreams");
- assert (text.node_name == "#text");
- assert (text.node_value == "Star of my dreams");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (text.node_name == "#text");
+ assert (text.node_value == "Star of my dreams");
});
Test.add_func ("/gxml/document/create_comment", () => {
- try {
- Document doc = get_doc ();
- Comment comment = doc.create_comment ("Ever since the day we
promised.");
+ Document doc = get_doc ();
+ Comment comment = doc.create_comment ("Ever since the day we promised.");
- assert (comment.node_name == "#comment");
- assert (comment.node_value == "Ever since the day we promised.");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (comment.node_name == "#comment");
+ assert (comment.node_value == "Ever since the day we promised.");
});
Test.add_func ("/gxml/document/create_cdata_section", () => {
- try {
- Document doc = get_doc ();
- CDATASection cdata = doc.create_cdata_section ("put in real cdata");
+ Document doc = get_doc ();
+ CDATASection cdata = doc.create_cdata_section ("put in real cdata");
- assert (cdata.node_name == "#cdata-section");
- assert (cdata.node_value == "put in real cdata");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (cdata.node_name == "#cdata-section");
+ assert (cdata.node_value == "put in real cdata");
});
Test.add_func ("/gxml/document/create_processing_instruction", () => {
- try {
- Document doc = get_doc ();
- ProcessingInstruction instruction = doc.create_processing_instruction
("target", "data");
+ Document doc = get_doc ();
+ ProcessingInstruction instruction = doc.create_processing_instruction
("target", "data");
- assert (instruction.node_name == "target");
- assert (instruction.target == "target");
- assert (instruction.data == "data");
- assert (instruction.node_value == "data");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (instruction.node_name == "target");
+ assert (instruction.target == "target");
+ assert (instruction.data == "data");
+ assert (instruction.node_value == "data");
});
Test.add_func ("/gxml/document/create_attribute", () => {
- try {
- Document doc = get_doc ();
- Attr attr = doc.create_attribute ("attrname");
+ Document doc = get_doc ();
+ Attr attr = doc.create_attribute ("attrname");
- assert (attr.name == "attrname");
- assert (attr.node_name == "attrname");
- assert (attr.node_value == "");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (attr.name == "attrname");
+ assert (attr.node_name == "attrname");
+ assert (attr.node_value == "");
});
Test.add_func ("/gxml/document/create_entity_reference", () => {
- try {
- Document doc = get_doc ();
- EntityReference entity = doc.create_entity_reference ("entref");
+ Document doc = get_doc ();
+ EntityReference entity = doc.create_entity_reference ("entref");
- assert (entity.node_name == "entref");
- // TODO: think of at least one other smoke test
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (entity.node_name == "entref");
+ // TODO: think of at least one other smoke test
});
Test.add_func ("/gxml/document/get_elements_by_tag_name", () => {
- try {
- Document doc = get_doc ();
- NodeList elems = doc.get_elements_by_tag_name ("Email");
+ Document doc = get_doc ();
+ NodeList elems = doc.get_elements_by_tag_name ("Email");
- assert (elems.length == 2);
- assert (((Element)elems.item (0)).content == "fweasley hogwarts co
uk");
- /* more thorough test exists in Element, since right now
- Document uses that one */
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (elems.length == 2);
+ assert (((Element)elems.item (0)).content == "fweasley hogwarts co uk");
+ /* more thorough test exists in Element, since right now
+ Document uses that one */
});
Test.add_func ("/gxml/document/to_string", () => {
- try {
- Document doc = get_doc ();
- assert (doc.to_string () == "<?xml version=\"1.0\"?>
+ Document doc = get_doc ();
+ assert (doc.to_string () == "<?xml version=\"1.0\"?>
<Sentences>
<Sentence lang=\"en\">I like the colour blue.</Sentence>
<Sentence lang=\"de\">Ich liebe die Tür.</Sentence>
@@ -311,11 +250,7 @@ class DocumentTest : GXmlTest {
</Authors>
</Sentences>
");
- // TODO: want to test with format on and off
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: want to test with format on and off
});
}
diff --git a/test/ElementTest.vala b/test/ElementTest.vala
index ea0aeaf..588090d 100644
--- a/test/ElementTest.vala
+++ b/test/ElementTest.vala
@@ -14,160 +14,124 @@ using GXml;
class ElementTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/element/namespace_support_manual", () => {
- try {
- // TODO: wanted to use TestElement but CAN'T because Vala won't let
me access the internal constructor of Element?
- Xml.Doc *xmldoc;
- Xml.Node *xmlroot;
- Xml.Node *xmlnode;
- Xml.Ns *ns_magic;
- Xml.Ns *ns_course;
- xmldoc = new Xml.Doc ();
-
- xmlroot = xmldoc->new_node (null, "Potions");
- ns_course = xmlroot->new_ns ("http://hogwarts.co.uk/courses",
"course");
- xmldoc->set_root_element (xmlroot);
-
- xmlnode = xmldoc->new_node (null, "Potion");
- ns_magic = xmlnode->new_ns ("http://hogwarts.co.uk/magic", "magic");
- xmlnode->new_ns_prop (ns_course, "commonName", "Florax");
- xmlroot->add_child (xmlnode);
-
- Document doc = new Document.from_libxml2 (xmldoc);
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- assert (node.namespace_uri == null);
- assert (node.prefix == null);
- xmlnode->set_ns (ns_magic);
- assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
- assert (node.prefix == "magic");
- assert (node.local_name == "Potion");
- assert (node.node_name == "Potion");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: wanted to use TestElement but CAN'T because Vala won't let me access
the internal constructor of Element?
+ Xml.Doc *xmldoc;
+ Xml.Node *xmlroot;
+ Xml.Node *xmlnode;
+ Xml.Ns *ns_magic;
+ Xml.Ns *ns_course;
+ xmldoc = new Xml.Doc ();
+
+ xmlroot = xmldoc->new_node (null, "Potions");
+ ns_course = xmlroot->new_ns ("http://hogwarts.co.uk/courses", "course");
+ xmldoc->set_root_element (xmlroot);
+
+ xmlnode = xmldoc->new_node (null, "Potion");
+ ns_magic = xmlnode->new_ns ("http://hogwarts.co.uk/magic", "magic");
+ xmlnode->new_ns_prop (ns_course, "commonName", "Florax");
+ xmlroot->add_child (xmlnode);
+
+ Document doc = new Document.from_libxml2 (xmldoc);
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ assert (node.namespace_uri == null);
+ assert (node.prefix == null);
+ xmlnode->set_ns (ns_magic);
+ assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
+ assert (node.prefix == "magic");
+ assert (node.local_name == "Potion");
+ assert (node.node_name == "Potion");
});
Test.add_func ("/gxml/element/namespace_uri", () => {
- try {
- // TODO: wanted to use TestElement but CAN'T because Vala won't let
me access the internal constructor of Element?
- Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: wanted to use TestElement but CAN'T because Vala won't let me access
the internal constructor of Element?
+ Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
});
Test.add_func ("/gxml/element/testing", () => {
- try {
- // TODO: wanted to use TestElement but CAN'T because Vala won't let
me access the internal constructor of Element?
- Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"><products:Ingredient /></magic:Potion></Potions>");
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- // root.dbg_inspect ();
- // node.dbg_inspect ();
- // node.child_nodes.item (0).dbg_inspect ();
-
- assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
-
- // TODO: remove below
- // message ("going to show attributes on node %s", node.node_name);
- // foreach (Attr attr in node.attributes.get_values ()) {
- // message ("attrkey: %s, value: %s", attr.node_name,
attr.node_value);
- // }
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: wanted to use TestElement but CAN'T because Vala won't let me access
the internal constructor of Element?
+ Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"><products:Ingredient /></magic:Potion></Potions>");
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ // root.dbg_inspect ();
+ // node.dbg_inspect ();
+ // node.child_nodes.item (0).dbg_inspect ();
+
+ assert (node.namespace_uri == "http://hogwarts.co.uk/magic");
+
+ // TODO: remove below
+ // message ("going to show attributes on node %s", node.node_name);
+ // foreach (Attr attr in node.attributes.get_values ()) {
+ // message ("attrkey: %s, value: %s", attr.node_name, attr.node_value);
+ // }
});
Test.add_func ("/gxml/element/prefix", () => {
- try {
- Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- assert (node.prefix == "magic");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ assert (node.prefix == "magic");
});
Test.add_func ("/gxml/element/local_name", () => {
- try {
- Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- assert (node.local_name == "Potion");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ assert (node.local_name == "Potion");
});
Test.add_func ("/gxml/element/namespace_definitions", () => {
- try {
- Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
- GXml.Node root = doc.document_element;
- GXml.Node node = root.child_nodes.item (0);
-
- NodeList namespaces = node.namespace_definitions;
-
- assert (namespaces.length == 2);
-
- assert (namespaces.item (0).prefix == "xmlns");
- assert (namespaces.item (0).node_name == "magic");
- assert (namespaces.item (0).node_value ==
"http://hogwarts.co.uk/magic");
- assert (namespaces.item (1).prefix == "xmlns");
- assert (namespaces.item (1).node_name == "products");
- assert (namespaces.item (1).node_value ==
"http://diagonalley.co.uk/products");
- assert (node.local_name == "Potion");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = new Document.from_string ("<Potions><magic:Potion
xmlns:magic=\"http://hogwarts.co.uk/magic\"
xmlns:products=\"http://diagonalley.co.uk/products\"/></Potions>");
+ GXml.Node root = doc.document_element;
+ GXml.Node node = root.child_nodes.item (0);
+
+ NodeList namespaces = node.namespace_definitions;
+
+ assert (namespaces.length == 2);
+
+ assert (namespaces.item (0).prefix == "xmlns");
+ assert (namespaces.item (0).node_name == "magic");
+ assert (namespaces.item (0).node_value == "http://hogwarts.co.uk/magic");
+ assert (namespaces.item (1).prefix == "xmlns");
+ assert (namespaces.item (1).node_name == "products");
+ assert (namespaces.item (1).node_value ==
"http://diagonalley.co.uk/products");
+ assert (node.local_name == "Potion");
});
Test.add_func ("/gxml/element/attributes", () => {
- try {
- HashTable<string,Attr> attributes;
+ HashTable<string,Attr> attributes;
- Document doc;
- Element elem;
+ Document doc;
+ Element elem;
- doc = get_doc ();
+ doc = get_doc ();
- elem = doc.create_element ("alphanumeric");
+ elem = doc.create_element ("alphanumeric");
- attributes = elem.attributes;
- assert (attributes != null);
- assert (attributes.size () == 0);
+ attributes = elem.attributes;
+ assert (attributes != null);
+ assert (attributes.size () == 0);
- elem.set_attribute ("alley", "Diagon");
- elem.set_attribute ("train", "Hogwarts Express");
+ elem.set_attribute ("alley", "Diagon");
+ elem.set_attribute ("train", "Hogwarts Express");
- assert (attributes == elem.attributes);
- assert (attributes.size () == 2);
- assert (attributes.lookup ("alley").value == "Diagon");
- assert (attributes.lookup ("train").value == "Hogwarts Express");
+ assert (attributes == elem.attributes);
+ assert (attributes.size () == 2);
+ assert (attributes.lookup ("alley").value == "Diagon");
+ assert (attributes.lookup ("train").value == "Hogwarts Express");
- Attr attr = doc.create_attribute ("owl");
- attr.value = "Hedwig";
+ Attr attr = doc.create_attribute ("owl");
+ attr.value = "Hedwig";
- attributes.insert ("owl", attr);
+ attributes.insert ("owl", attr);
- assert (attributes.size () == 3);
- assert (elem.get_attribute ("owl") == "Hedwig");
+ assert (attributes.size () == 3);
+ assert (elem.get_attribute ("owl") == "Hedwig");
- attributes.remove ("alley");
- assert (elem.get_attribute ("alley") == "");
-
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ attributes.remove ("alley");
+ assert (elem.get_attribute ("alley") == "");
});
/* by accessing .attributes, the element is marked as
* dirty, because it can't be sure whether we're
@@ -178,152 +142,117 @@ class ElementTest : GXmlTest {
HashTable<string,GXml.Attr> attrs;
string str;
- try {
- Document doc = new Document.from_string ("<?xml version='1.0'
encoding='UTF-8'?><entry><link rel='http://schemas.google.com/contacts/2008/rel#photo'/></entry>");
- GXml.Node root = doc.document_element;
- foreach (GXml.Node child in root.child_nodes) {
- attrs = child.attributes;
- }
-
- str = doc.to_string ();
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
+ Document doc = new Document.from_string ("<?xml version='1.0'
encoding='UTF-8'?><entry><link rel='http://schemas.google.com/contacts/2008/rel#photo'/></entry>");
+ GXml.Node root = doc.document_element;
+ foreach (GXml.Node child in root.child_nodes) {
+ attrs = child.attributes;
}
+
+ str = doc.to_string ();
});
Test.add_func ("/gxml/element/get_set_attribute", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("student", out doc);
-
- assert ("" == elem.get_attribute ("name"));
-
- elem.set_attribute ("name", "Malfoy");
- assert ("Malfoy" == elem.get_attribute ("name"));
- elem.set_attribute ("name", "Lovegood");
- assert ("Lovegood" == elem.get_attribute ("name"));
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("student", out doc);
+
+ assert ("" == elem.get_attribute ("name"));
+
+ elem.set_attribute ("name", "Malfoy");
+ assert ("Malfoy" == elem.get_attribute ("name"));
+ elem.set_attribute ("name", "Lovegood");
+ assert ("Lovegood" == elem.get_attribute ("name"));
});
Test.add_func ("/gxml/element/remove_attribute", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("tagname", out doc);
-
- elem.set_attribute ("name", "Malfoy");
- assert ("Malfoy" == elem.get_attribute ("name"));
- assert ("Malfoy" == elem.get_attribute_node ("name").value);
- elem.remove_attribute ("name");
- assert ("" == elem.get_attribute ("name"));
- assert (null == elem.get_attribute_node ("name"));
-
- // Consider testing default attributes (see Attr and specified)
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("tagname", out doc);
+
+ elem.set_attribute ("name", "Malfoy");
+ assert ("Malfoy" == elem.get_attribute ("name"));
+ assert ("Malfoy" == elem.get_attribute_node ("name").value);
+ elem.remove_attribute ("name");
+ assert ("" == elem.get_attribute ("name"));
+ assert (null == elem.get_attribute_node ("name"));
+
+ // Consider testing default attributes (see Attr and specified)
});
Test.add_func ("/gxml/element/get_attribute_node", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("tagname", out doc);
-
- assert (elem.get_attribute_node ("name") == null);
- elem.set_attribute ("name", "Severus");
- assert (elem.get_attribute_node ("name").value == "Severus");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("tagname", out doc);
+
+ assert (elem.get_attribute_node ("name") == null);
+ elem.set_attribute ("name", "Severus");
+ assert (elem.get_attribute_node ("name").value == "Severus");
});
Test.add_func ("/gxml/element/set_attribute_node", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("tagname", out doc);
- Attr attr1 = elem.owner_document.create_attribute ("name");
- Attr attr2 = elem.owner_document.create_attribute ("name");
-
- attr1.value = "Snape";
- attr2.value = "Moody";
-
- /* We test to make sure that the current value in the node after
being set is correct,
- and that the old node gets correctly returned when replaced. */
- assert (elem.get_attribute_node ("name") == null);
- assert (elem.set_attribute_node (attr1) == null);
- assert (elem.get_attribute_node ("name").value == "Snape");
- assert (elem.set_attribute_node (attr2).value == "Snape");
- assert (elem.get_attribute_node ("name").value == "Moody");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("tagname", out doc);
+ Attr attr1 = elem.owner_document.create_attribute ("name");
+ Attr attr2 = elem.owner_document.create_attribute ("name");
+
+ attr1.value = "Snape";
+ attr2.value = "Moody";
+
+ /* We test to make sure that the current value in the node after being set is
correct,
+ and that the old node gets correctly returned when replaced. */
+ assert (elem.get_attribute_node ("name") == null);
+ assert (elem.set_attribute_node (attr1) == null);
+ assert (elem.get_attribute_node ("name").value == "Snape");
+ assert (elem.set_attribute_node (attr2).value == "Snape");
+ assert (elem.get_attribute_node ("name").value == "Moody");
});
Test.add_func ("/gxml/element/remove_attribute_node", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("tagname", out doc);
- Attr attr;
-
- attr = elem.owner_document.create_attribute ("name");
- attr.value = "Luna";
-
- /* Test to make sure the current value ends up empty/reset after
removal
- and that removal returns the removed node. */
- elem.set_attribute_node (attr);
- assert (elem.get_attribute_node ("name").value == "Luna");
- assert (elem.remove_attribute_node (attr) == attr);
- assert (elem.get_attribute_node ("name") == null);
- assert (elem.get_attribute ("name") == "");
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("tagname", out doc);
+ Attr attr;
+
+ attr = elem.owner_document.create_attribute ("name");
+ attr.value = "Luna";
+
+ /* Test to make sure the current value ends up empty/reset after removal
+ and that removal returns the removed node. */
+ elem.set_attribute_node (attr);
+ assert (elem.get_attribute_node ("name").value == "Luna");
+ assert (elem.remove_attribute_node (attr) == attr);
+ assert (elem.get_attribute_node ("name") == null);
+ assert (elem.get_attribute ("name") == "");
});
Test.add_func ("/gxml/element/get_elements_by_tag_name", () => {
- try {
- Document doc;
- GXml.Node root;
- Element elem;
- NodeList emails;
- Element email;
- Text text;
-
- doc = get_doc ();
-
- root = doc.document_element; // child_nodes.nth_data (0);
- assert (root.node_name == "Sentences");
-
- elem = (Element)root;
- emails = elem.get_elements_by_tag_name ("Email");
- assert (emails.length == 2);
-
- email = (Element)emails.nth_data (0);
- assert (email.tag_name == "Email");
- assert (email.child_nodes.length == 1);
-
- text = (Text)email.child_nodes.nth_data (0);
- assert (text.node_name == "#text");
- assert (text.node_value == "fweasley hogwarts co uk");
-
- email = (Element)emails.nth_data (1);
- assert (email.tag_name == "Email");
- assert (email.child_nodes.length == 1);
-
- text = (Text)email.child_nodes.nth_data (0);
- assert (text.node_name == "#text");
- assert (text.node_value == "gweasley hogwarts co uk");
-
- // TODO: need to test that preorder traversal order is correct
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ GXml.Node root;
+ Element elem;
+ NodeList emails;
+ Element email;
+ Text text;
+
+ doc = get_doc ();
+
+ root = doc.document_element; // child_nodes.nth_data (0);
+ assert (root.node_name == "Sentences");
+
+ elem = (Element)root;
+ emails = elem.get_elements_by_tag_name ("Email");
+ assert (emails.length == 2);
+
+ email = (Element)emails.nth_data (0);
+ assert (email.tag_name == "Email");
+ assert (email.child_nodes.length == 1);
+
+ text = (Text)email.child_nodes.nth_data (0);
+ assert (text.node_name == "#text");
+ assert (text.node_value == "fweasley hogwarts co uk");
+
+ email = (Element)emails.nth_data (1);
+ assert (email.tag_name == "Email");
+ assert (email.child_nodes.length == 1);
+
+ text = (Text)email.child_nodes.nth_data (0);
+ assert (text.node_name == "#text");
+ assert (text.node_value == "gweasley hogwarts co uk");
+
+ // TODO: need to test that preorder traversal order is correct
});
Test.add_func ("/gxml/element/get_elements_by_tag_name.live", () => {
/* Need to test the following cases:
@@ -340,12 +269,11 @@ class ElementTest : GXmlTest {
remove a tree with 2, list has 5
readd the tree, list has 7
*/
- try {
- Document doc;
- string xml;
+ Document doc;
+ string xml;
- xml =
-"<A>
+ xml =
+ "<A>
<t />
<Bs>
<t />
@@ -359,115 +287,101 @@ class ElementTest : GXmlTest {
</Bs>
<Cs><C><t /></C></Cs>
</A>";
- doc = new Document.from_string (xml);
+ doc = new Document.from_string (xml);
- GXml.Node a = doc.document_element;
- GXml.Node bs = a.child_nodes.item (3);
- GXml.Node b3 = bs.child_nodes.item (7);
- GXml.Node t1, t2;
+ GXml.Node a = doc.document_element;
+ GXml.Node bs = a.child_nodes.item (3);
+ GXml.Node b3 = bs.child_nodes.item (7);
+ GXml.Node t1, t2;
- NodeList ts = ((Element)bs).get_elements_by_tag_name ("t");
- assert (ts.length == 5);
+ NodeList ts = ((Element)bs).get_elements_by_tag_name ("t");
+ assert (ts.length == 5);
- // Test adding direct child
- bs.append_child (t1 = doc.create_element ("t"));
- assert (ts.length == 6);
+ // Test adding direct child
+ bs.append_child (t1 = doc.create_element ("t"));
+ assert (ts.length == 6);
- // Test adding descendant
- b3.append_child (doc.create_element ("t"));
- assert (ts.length == 7);
+ // Test adding descendant
+ b3.append_child (doc.create_element ("t"));
+ assert (ts.length == 7);
- // Test situation where we add a node tree
- GXml.Node b4;
- GXml.Node d, d2;
+ // Test situation where we add a node tree
+ GXml.Node b4;
+ GXml.Node d, d2;
- b4 = doc.create_element ("B");
- b4.append_child (doc.create_element ("t"));
- d = doc.create_element ("D");
- d.append_child (t2 = doc.create_element ("t"));
- b4.append_child (d);
+ b4 = doc.create_element ("B");
+ b4.append_child (doc.create_element ("t"));
+ d = doc.create_element ("D");
+ d.append_child (t2 = doc.create_element ("t"));
+ b4.append_child (d);
- bs.append_child (b4);
+ bs.append_child (b4);
- assert (ts.length == 9);
+ assert (ts.length == 9);
- // Test situation where we use insert_before
- d2 = doc.create_element ("D");
- d2.append_child (doc.create_element ("t"));
- b4.insert_before (d2, d);
+ // Test situation where we use insert_before
+ d2 = doc.create_element ("D");
+ d2.append_child (doc.create_element ("t"));
+ b4.insert_before (d2, d);
- assert (ts.length == 10);
+ assert (ts.length == 10);
- // Test situation where we add a document fragment
- DocumentFragment frag;
+ // Test situation where we add a document fragment
+ DocumentFragment frag;
- frag = doc.create_document_fragment ();
- frag.append_child (doc.create_element ("t"));
- d = doc.create_element ("D");
- d.append_child (doc.create_element ("t"));
- frag.append_child (d);
- d2 = doc.create_element ("D");
- d2.append_child (doc.create_element ("t"));
- frag.insert_before (d2, d);
+ frag = doc.create_document_fragment ();
+ frag.append_child (doc.create_element ("t"));
+ d = doc.create_element ("D");
+ d.append_child (doc.create_element ("t"));
+ frag.append_child (d);
+ d2 = doc.create_element ("D");
+ d2.append_child (doc.create_element ("t"));
+ frag.insert_before (d2, d);
- b4.append_child (frag);
- assert (ts.length == 13);
+ b4.append_child (frag);
+ assert (ts.length == 13);
- // Test removing single child
- t1.parent_node.remove_child (t1);
- assert (ts.length == 12);
+ // Test removing single child
+ t1.parent_node.remove_child (t1);
+ assert (ts.length == 12);
- // Test removing deeper descendant
- t2.parent_node.remove_child (t2);
- assert (ts.length == 11);
+ // Test removing deeper descendant
+ t2.parent_node.remove_child (t2);
+ assert (ts.length == 11);
- // Test removing subtree
- b4 = b4.parent_node.remove_child (b4);
+ // Test removing subtree
+ b4 = b4.parent_node.remove_child (b4);
- assert (ts.length == 6);
+ assert (ts.length == 6);
- // Test restoring subtree
- bs.append_child (b4);
- assert (ts.length == 11);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // Test restoring subtree
+ bs.append_child (b4);
+ assert (ts.length == 11);
});
Test.add_func ("/gxml/element/normalize", () => {
- try {
- Document doc;
- Element elem = get_elem_new_doc ("tagname", out doc);
- elem.normalize ();
-
- // STUB
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Element elem = get_elem_new_doc ("tagname", out doc);
+ elem.normalize ();
+
+ // STUB
});
Test.add_func ("/gxml/element/to_string", () => {
- try {
- Document doc, doc2;
- Element elem = get_elem_new_doc ("country", out doc);
- elem.append_child (elem.owner_document.create_text_node ("New
Zealand"));
- assert (elem.to_string () == "<country>New Zealand</country>");
-
- // during stringification, we don't want to confuse XML <> with text
<>
- Element elem2 = get_elem_new_doc ("messy", out doc2);
- elem2.append_child (elem.owner_document.create_text_node
("<<>>"));
- string expected = "<messy>&lt;<>&gt;</messy>";
- if (elem2.to_string () != expected) {
- Test.message ("Expected [%s] found [%s]",
- expected, elem2.to_string ());
- assert_not_reached ();
- }
-
- // TODO: want to test with format on and off
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
+ Document doc, doc2;
+ Element elem = get_elem_new_doc ("country", out doc);
+ elem.append_child (elem.owner_document.create_text_node ("New Zealand"));
+ assert (elem.to_string () == "<country>New Zealand</country>");
+
+ // during stringification, we don't want to confuse XML <> with text <>
+ Element elem2 = get_elem_new_doc ("messy", out doc2);
+ elem2.append_child (elem.owner_document.create_text_node ("<<>>"));
+ string expected = "<messy>&lt;<>&gt;</messy>";
+ if (elem2.to_string () != expected) {
+ Test.message ("Expected [%s] found [%s]",
+ expected, elem2.to_string ());
assert_not_reached ();
}
+
+ // TODO: want to test with format on and off
});
}
}
\ No newline at end of file
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 817ed2d..e52aca4 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -42,12 +42,9 @@ class GXmlTest {
return 0;
}
- internal static Document get_doc () throws DomError {
+ internal static Document get_doc () {
Document doc = null;
- try {
- doc = new Document.from_path (get_test_dir () + "/test.xml");
- } catch (DomError e) {
- }
+ doc = new Document.from_path (get_test_dir () + "/test.xml");
return doc;
}
@@ -59,26 +56,26 @@ class GXmlTest {
}
}
- // internal static Attr get_attr_new_doc (string name, string value) throws DomError {
+ // internal static Attr get_attr_new_doc (string name, string value) {
// return get_attr (name, value, get_doc ());
// }
- internal static Attr get_attr (string name, string value, Document doc) throws DomError {
+ internal static Attr get_attr (string name, string value, Document doc) {
Attr attr = doc.create_attribute (name);
attr.value = value;
return attr;
}
- internal static Element get_elem_new_doc (string name, out Document doc) throws DomError {
+ internal static Element get_elem_new_doc (string name, out Document doc) {
return get_elem (name, doc = get_doc ());
}
- internal static Element get_elem (string name, Document doc) throws DomError {
+ internal static Element get_elem (string name, Document doc) {
Element elem = doc.create_element (name);
return elem;
}
- internal static Text get_text_new_doc (string data, out Document doc) throws DomError {
+ internal static Text get_text_new_doc (string data, out Document doc) {
return get_text (data, doc = get_doc ());
}
diff --git a/test/NodeTest.vala b/test/NodeTest.vala
index 6b21fca..2b1ad59 100644
--- a/test/NodeTest.vala
+++ b/test/NodeTest.vala
@@ -12,444 +12,364 @@ class NodeTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/domnode/node_name_get", () => {
- try {
- // TODO: should Nodes never have a null name?
- Document doc = get_doc ();
- GXml.Node node;
+ // TODO: should Nodes never have a null name?
+ Document doc = get_doc ();
+ GXml.Node node;
- node = get_elem ("elemname", doc);
- assert (node.node_name == "elemname");
+ node = get_elem ("elemname", doc);
+ assert (node.node_name == "elemname");
- node = doc.create_attribute ("attrname");
- assert (node.node_name == "attrname");
+ node = doc.create_attribute ("attrname");
+ assert (node.node_name == "attrname");
- node = doc.create_text_node ("some text");
- assert (node.node_name == "#text");
+ node = doc.create_text_node ("some text");
+ assert (node.node_name == "#text");
- node = doc.create_cdata_section ("cdata");
- assert (node.node_name == "#cdata-section");
+ node = doc.create_cdata_section ("cdata");
+ assert (node.node_name == "#cdata-section");
- node = doc.create_entity_reference ("refname");
- assert (node.node_name == "refname");
+ node = doc.create_entity_reference ("refname");
+ assert (node.node_name == "refname");
- // node = doc.create_entity ();
- // assert (node.node_name == ...); // entity name
+ // node = doc.create_entity ();
+ // assert (node.node_name == ...); // entity name
- node = doc.create_processing_instruction ("target", "data");
- assert (node.node_name == "target");
+ node = doc.create_processing_instruction ("target", "data");
+ assert (node.node_name == "target");
- node = doc.create_comment ("some comment");
- assert (node.node_name == "#comment");
+ node = doc.create_comment ("some comment");
+ assert (node.node_name == "#comment");
- assert (doc.node_name == "#document");
+ assert (doc.node_name == "#document");
- // node = doc.create_document_type ("");
- // assert (node.node_name == ...); // document-type name
+ // node = doc.create_document_type ("");
+ // assert (node.node_name == ...); // document-type name
- // node = doc.create_document_fragment ("");
- // assert (node.node_name == "#document-fragment");
+ // node = doc.create_document_fragment ("");
+ // assert (node.node_name == "#document-fragment");
- // node = doc.create_notation ("some notation");
- // assert (node.node_name == ...); // notation name
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // node = doc.create_notation ("some notation");
+ // assert (node.node_name == ...); // notation name
});
Test.add_func ("/gxml/domnode/node_type_get", () => {
- try {
- // TODO: implement commented-out types
+ // TODO: implement commented-out types
- Document doc = get_doc ();
- GXml.Node node;
+ Document doc = get_doc ();
+ GXml.Node node;
- node = get_elem ("a", doc);
- assert (node.node_type == NodeType.ELEMENT);
+ node = get_elem ("a", doc);
+ assert (node.node_type == NodeType.ELEMENT);
- node = doc.create_attribute ("name");
- assert (node.node_type == NodeType.ATTRIBUTE);
+ node = doc.create_attribute ("name");
+ assert (node.node_type == NodeType.ATTRIBUTE);
- node = doc.create_text_node ("some text");
- assert (node.node_type == NodeType.TEXT);
+ node = doc.create_text_node ("some text");
+ assert (node.node_type == NodeType.TEXT);
- node = doc.create_cdata_section ("cdata");
- assert (node.node_type == NodeType.CDATA_SECTION);
+ node = doc.create_cdata_section ("cdata");
+ assert (node.node_type == NodeType.CDATA_SECTION);
- node = doc.create_entity_reference ("refname");
- assert (node.node_type == NodeType.ENTITY_REFERENCE);
+ node = doc.create_entity_reference ("refname");
+ assert (node.node_type == NodeType.ENTITY_REFERENCE);
- // node = doc.create_entity ();
- // assert (node.node_type == NodeType.ENTITY);
+ // node = doc.create_entity ();
+ // assert (node.node_type == NodeType.ENTITY);
- node = doc.create_processing_instruction ("target", "data");
- assert (node.node_type == NodeType.PROCESSING_INSTRUCTION);
+ node = doc.create_processing_instruction ("target", "data");
+ assert (node.node_type == NodeType.PROCESSING_INSTRUCTION);
- node = doc.create_comment ("some comment");
- assert (node.node_type == NodeType.COMMENT);
+ node = doc.create_comment ("some comment");
+ assert (node.node_type == NodeType.COMMENT);
- assert (doc.node_type == NodeType.DOCUMENT);
+ assert (doc.node_type == NodeType.DOCUMENT);
- // node = doc.create_document_type ("");
- // assert (node.node_type == NodeType.DOCUMENT_TYPE);
+ // node = doc.create_document_type ("");
+ // assert (node.node_type == NodeType.DOCUMENT_TYPE);
- // node = doc.create_document_fragment ("");
- // assert (node.node_type == NodeType.DOCUMENT_FRAGMENT);
+ // node = doc.create_document_fragment ("");
+ // assert (node.node_type == NodeType.DOCUMENT_FRAGMENT);
- // node = doc.create_notation ("some notation");
- // assert (node.node_type == NodeType.NOTATION);
+ // node = doc.create_notation ("some notation");
+ // assert (node.node_type == NodeType.NOTATION);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
});
Test.add_func ("/gxml/domnode/node_value_get", () => {
- try {
- /* See: http://www.w3.org/TR/DOM-Level-1/level-one-core.html */
+ /* See: http://www.w3.org/TR/DOM-Level-1/level-one-core.html */
- Document doc = get_doc ();
+ Document doc = get_doc ();
- GXml.Node node;
+ GXml.Node node;
- node = doc.create_element ("elem");
- assert (node.node_value == null);
+ node = doc.create_element ("elem");
+ assert (node.node_value == null);
- node = doc.create_attribute ("name");
- ((Attr)node).value = "Harry Potter";
- assert (node.node_value == "Harry Potter");
+ node = doc.create_attribute ("name");
+ ((Attr)node).value = "Harry Potter";
+ assert (node.node_value == "Harry Potter");
- node = doc.create_text_node ("text content");
- assert (node.node_value == "text content");
+ node = doc.create_text_node ("text content");
+ assert (node.node_value == "text content");
- node = doc.create_cdata_section ("cdata content");
- assert (node.node_value == "cdata content");
+ node = doc.create_cdata_section ("cdata content");
+ assert (node.node_value == "cdata content");
- node = doc.create_entity_reference ("refname");
- assert (node.node_value == null);
+ node = doc.create_entity_reference ("refname");
+ assert (node.node_value == null);
- // TODO: entity
+ // TODO: entity
- node = doc.create_processing_instruction ("target", "proc inst data");
- assert (node.node_value == "proc inst data");
+ node = doc.create_processing_instruction ("target", "proc inst data");
+ assert (node.node_value == "proc inst data");
- node = doc.create_comment ("some comment");
- assert (node.node_value == "some comment");
+ node = doc.create_comment ("some comment");
+ assert (node.node_value == "some comment");
- assert (doc.node_value == null);
+ assert (doc.node_value == null);
- /* TODO: Document Type, Document Fragment, Notation */
- // assert (attr.node_value == "harry");
- /* TODO: figure out a solution.
- Attr's node_value doesn't get used when elem is thought of
- as a Node.
- GXml.Node wants to get it from Node's Xml.Node* node,
- while Attr wants to get it from Attr's Xml.Attr* node. :( */
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ /* TODO: Document Type, Document Fragment, Notation */
+ // assert (attr.node_value == "harry");
+ /* TODO: figure out a solution.
+ Attr's node_value doesn't get used when elem is thought of
+ as a Node.
+ GXml.Node wants to get it from Node's Xml.Node* node,
+ while Attr wants to get it from Attr's Xml.Attr* node. :( */
});
Test.add_func ("/gxml/domnode/parent_node", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("James", doc);
- GXml.Node child = get_elem ("Harry", doc);
-
- assert (child.parent_node == null);
- parent.append_child (child);
- assert (child.parent_node == parent);
-
- GXml.Node attr = doc.create_attribute ("a");
- assert (attr.parent_node == null);
- assert (doc.parent_node == null);
- // assert (document fragment's parent_node == null); // TODO
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("James", doc);
+ GXml.Node child = get_elem ("Harry", doc);
+
+ assert (child.parent_node == null);
+ parent.append_child (child);
+ assert (child.parent_node == parent);
+
+ GXml.Node attr = doc.create_attribute ("a");
+ assert (attr.parent_node == null);
+ assert (doc.parent_node == null);
+ // assert (document fragment's parent_node == null); // TODO
});
Test.add_func ("/gxml/domnode/child_nodes", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
- assert (parent.child_nodes.length == 3);
- assert (parent.child_nodes.nth_data (0) == child_0);
- assert (parent.child_nodes.nth_data (2) == child_2);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+ assert (parent.child_nodes.length == 3);
+ assert (parent.child_nodes.nth_data (0) == child_0);
+ assert (parent.child_nodes.nth_data (2) == child_2);
});
Test.add_func ("/gxml/domnode/first_child", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
-
- assert (parent.first_child == child_0);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+
+ assert (parent.first_child == child_0);
});
Test.add_func ("/gxml/domnode/last_child", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
-
- assert (parent.last_child == child_2);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+
+ assert (parent.last_child == child_2);
});
Test.add_func ("/gxml/domnode/previous_sibling", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
-
- assert (child_0.previous_sibling == null);
- assert (child_1.previous_sibling == child_0);
- assert (child_2.previous_sibling == child_1);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+
+ assert (child_0.previous_sibling == null);
+ assert (child_1.previous_sibling == child_0);
+ assert (child_2.previous_sibling == child_1);
});
Test.add_func ("/gxml/domnode/next_sibling", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
-
- assert (child_0.next_sibling == child_1);
- assert (child_1.next_sibling == child_2);
- assert (child_2.next_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+
+ assert (child_0.next_sibling == child_1);
+ assert (child_1.next_sibling == child_2);
+ assert (child_2.next_sibling == null);
});
Test.add_func ("/gxml/domnode/attributes", () => {
- try {
- Document doc = get_doc ();
- GXml.Node elem = get_elem ("Hogwarts", doc);
- GXml.Node attr = get_attr ("Potter", "Lily", doc);
-
- assert (elem.attributes != null);
- assert (attr.attributes == null);
-
- // TODO: test more
- // TODO: test compatibility between live changes and stuff
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node elem = get_elem ("Hogwarts", doc);
+ GXml.Node attr = get_attr ("Potter", "Lily", doc);
+
+ assert (elem.attributes != null);
+ assert (attr.attributes == null);
+
+ // TODO: test more
+ // TODO: test compatibility between live changes and stuff
});
Test.add_func ("/gxml/domnode/owner_document", () => {
- try {
- Document doc2 = get_doc ();
- Document doc1 = get_doc ();
- GXml.Node elem = get_elem ("Malfoy", doc1);
-
- assert (elem.owner_document == doc1);
- assert (elem.owner_document != doc2);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc2 = get_doc ();
+ Document doc1 = get_doc ();
+ GXml.Node elem = get_elem ("Malfoy", doc1);
+
+ assert (elem.owner_document == doc1);
+ assert (elem.owner_document != doc2);
});
Test.add_func ("/gxml/domnode/insert_before", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_2);
- parent.insert_before (child_0, child_2);
- parent.insert_before (child_1, child_2);
-
- assert (parent.first_child == child_0);
- assert (parent.last_child == child_2);
- assert (parent.child_nodes.length == 3);
- assert (parent.child_nodes.nth_data (0) == child_0);
- assert (parent.child_nodes.nth_data (1) == child_1);
- assert (parent.child_nodes.nth_data (2) == child_2);
- assert (child_0.previous_sibling == null);
- assert (child_1.previous_sibling == child_0);
- assert (child_2.previous_sibling == child_1);
- assert (child_0.next_sibling == child_1);
- assert (child_1.next_sibling == child_2);
- assert (child_2.next_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_2);
+ parent.insert_before (child_0, child_2);
+ parent.insert_before (child_1, child_2);
+
+ assert (parent.first_child == child_0);
+ assert (parent.last_child == child_2);
+ assert (parent.child_nodes.length == 3);
+ assert (parent.child_nodes.nth_data (0) == child_0);
+ assert (parent.child_nodes.nth_data (1) == child_1);
+ assert (parent.child_nodes.nth_data (2) == child_2);
+ assert (child_0.previous_sibling == null);
+ assert (child_1.previous_sibling == child_0);
+ assert (child_2.previous_sibling == child_1);
+ assert (child_0.next_sibling == child_1);
+ assert (child_1.next_sibling == child_2);
+ assert (child_2.next_sibling == null);
});
Test.add_func ("/gxml/domnode/replace_child", () => {
- try {
- // TODO: for this one, and others that include a ref_child, we want
to test passing an irrelevant ref child and a null ref child
-
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_2);
-
- parent.replace_child (child_1, child_2);
-
- assert (parent.first_child == child_0);
- assert (parent.last_child == child_1);
- assert (parent.child_nodes.length == 2);
- assert (parent.child_nodes.nth_data (0) == child_0);
- assert (parent.child_nodes.nth_data (1) == child_1);
- assert (child_0.previous_sibling == null);
- assert (child_1.previous_sibling == child_0);
- assert (child_0.next_sibling == child_1);
- assert (child_1.next_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ // TODO: for this one, and others that include a ref_child, we want to test
passing an irrelevant ref child and a null ref child
+
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_2);
+
+ parent.replace_child (child_1, child_2);
+
+ assert (parent.first_child == child_0);
+ assert (parent.last_child == child_1);
+ assert (parent.child_nodes.length == 2);
+ assert (parent.child_nodes.nth_data (0) == child_0);
+ assert (parent.child_nodes.nth_data (1) == child_1);
+ assert (child_0.previous_sibling == null);
+ assert (child_1.previous_sibling == child_0);
+ assert (child_0.next_sibling == child_1);
+ assert (child_1.next_sibling == null);
});
Test.add_func ("/gxml/domnode/remove_child", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_2);
- parent.append_child (child_1);
-
- parent.remove_child (child_2);
-
- assert (child_2.previous_sibling == null);
- assert (child_2.next_sibling == null);
-
- assert (parent.first_child == child_0);
- assert (parent.last_child == child_1);
- assert (parent.child_nodes.length == 2);
- assert (parent.child_nodes.nth_data (0) == child_0);
- assert (parent.child_nodes.nth_data (1) == child_1);
- assert (child_0.previous_sibling == null);
- assert (child_1.previous_sibling == child_0);
- assert (child_0.next_sibling == child_1);
- assert (child_1.next_sibling == null);
-
- parent.remove_child (child_0);
-
- assert (parent.first_child == child_1);
- assert (parent.last_child == child_1);
- assert (parent.child_nodes.length == 1);
- assert (parent.child_nodes.nth_data (0) == child_1);
- assert (child_1.previous_sibling == null);
- assert (child_1.next_sibling == null);
-
- parent.remove_child (child_1);
-
- assert (parent.first_child == null);
- assert (parent.last_child == null);
- assert (parent.child_nodes.length == 0);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_2);
+ parent.append_child (child_1);
+
+ parent.remove_child (child_2);
+
+ assert (child_2.previous_sibling == null);
+ assert (child_2.next_sibling == null);
+
+ assert (parent.first_child == child_0);
+ assert (parent.last_child == child_1);
+ assert (parent.child_nodes.length == 2);
+ assert (parent.child_nodes.nth_data (0) == child_0);
+ assert (parent.child_nodes.nth_data (1) == child_1);
+ assert (child_0.previous_sibling == null);
+ assert (child_1.previous_sibling == child_0);
+ assert (child_0.next_sibling == child_1);
+ assert (child_1.next_sibling == null);
+
+ parent.remove_child (child_0);
+
+ assert (parent.first_child == child_1);
+ assert (parent.last_child == child_1);
+ assert (parent.child_nodes.length == 1);
+ assert (parent.child_nodes.nth_data (0) == child_1);
+ assert (child_1.previous_sibling == null);
+ assert (child_1.next_sibling == null);
+
+ parent.remove_child (child_1);
+
+ assert (parent.first_child == null);
+ assert (parent.last_child == null);
+ assert (parent.child_nodes.length == 0);
});
Test.add_func ("/gxml/domnode/append_child", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
- GXml.Node child_1 = get_elem ("Ron", doc);
- GXml.Node child_2 = get_elem ("Ginnie", doc);
-
- assert (parent.child_nodes.length == 0);
- parent.append_child (child_0);
- parent.append_child (child_1);
- parent.append_child (child_2);
-
- assert (parent.first_child == child_0);
- assert (parent.last_child == child_2);
- assert (parent.child_nodes.length == 3);
- assert (parent.child_nodes.nth_data (0) == child_0);
- assert (parent.child_nodes.nth_data (1) == child_1);
- assert (parent.child_nodes.nth_data (2) == child_2);
- assert (child_0.previous_sibling == null);
- assert (child_1.previous_sibling == child_0);
- assert (child_2.previous_sibling == child_1);
- assert (child_0.next_sibling == child_1);
- assert (child_1.next_sibling == child_2);
- assert (child_2.next_sibling == null);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
+ GXml.Node child_1 = get_elem ("Ron", doc);
+ GXml.Node child_2 = get_elem ("Ginnie", doc);
+
+ assert (parent.child_nodes.length == 0);
+ parent.append_child (child_0);
+ parent.append_child (child_1);
+ parent.append_child (child_2);
+
+ assert (parent.first_child == child_0);
+ assert (parent.last_child == child_2);
+ assert (parent.child_nodes.length == 3);
+ assert (parent.child_nodes.nth_data (0) == child_0);
+ assert (parent.child_nodes.nth_data (1) == child_1);
+ assert (parent.child_nodes.nth_data (2) == child_2);
+ assert (child_0.previous_sibling == null);
+ assert (child_1.previous_sibling == child_0);
+ assert (child_2.previous_sibling == child_1);
+ assert (child_0.next_sibling == child_1);
+ assert (child_1.next_sibling == child_2);
+ assert (child_2.next_sibling == null);
});
Test.add_func ("/gxml/domnode/has_child_nodes", () => {
- try {
- Document doc = get_doc ();
- GXml.Node parent = get_elem ("Molly", doc);
- GXml.Node child_0 = get_elem ("Percy", doc);
+ Document doc = get_doc ();
+ GXml.Node parent = get_elem ("Molly", doc);
+ GXml.Node child_0 = get_elem ("Percy", doc);
- assert (parent.has_child_nodes () == false);
+ assert (parent.has_child_nodes () == false);
- parent.append_child (child_0);
+ parent.append_child (child_0);
- assert (parent.has_child_nodes () == true);
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ assert (parent.has_child_nodes () == true);
});
Test.add_func ("/gxml/domnode/clone_nodes", () => {
// STUB
diff --git a/test/SerializableTest.vala b/test/SerializableTest.vala
index f8174a6..e572c44 100644
--- a/test/SerializableTest.vala
+++ b/test/SerializableTest.vala
@@ -108,15 +108,10 @@ public class SerializableCapsicum : GLib.Object, GXml.Serializable {
switch (property_name) {
case "ratings":
GXml.DocumentFragment frag = doc.create_document_fragment ();
- try {
- foreach (int rating_int in ratings) {
- rating = doc.create_element ("rating");
- rating.content = "%d".printf (rating_int);
- frag.append_child (rating);
- }
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
+ foreach (int rating_int in ratings) {
+ rating = doc.create_element ("rating");
+ rating.content = "%d".printf (rating_int);
+ frag.append_child (rating);
}
return frag;
case "height":
diff --git a/test/SerializationTest.vala b/test/SerializationTest.vala
index 6d15a71..e7e66e9 100644
--- a/test/SerializationTest.vala
+++ b/test/SerializationTest.vala
@@ -603,9 +603,6 @@ class SerializationTest : GXmlTest {
} catch (GXml.SerializationError e) {
Test.message ("%s", e.message);
assert_not_reached ();
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
}
});
Test.add_func ("/gxml/serialization/simple_fields", () => {
diff --git a/test/TextTest.vala b/test/TextTest.vala
index bfd82dd..c16fdab 100644
--- a/test/TextTest.vala
+++ b/test/TextTest.vala
@@ -6,48 +6,40 @@ class TextTest : GXmlTest {
/* NOTE: GXml.Node name and node value behaviour tested by NodeTest */
Test.add_func ("/gxml/text/split_text", () => {
- try {
- Document doc;
- Text txt1 = get_text_new_doc ("Constant vigilance!", out doc);
- Text txt2 = txt1.split_text (5);
-
- assert (txt1.node_value == "Const");
- assert (txt2.node_value == "ant vigilance!");
-
- /* TODO: libxml2 doesn't allow txt siblings, so for now
- splitting text creates an unattached second Text
- node. It might still be useful if you wanted to insert
- an element in between, like with HTML markup? */
- /*
- assert (txt1.parent_node == txt2.parent_node);
- assert (txt1.next_sibling == txt2);
- assert (txt1 == txt2.previous_sibling);
- */
-
- txt2 = txt1.split_text (0);
- assert (txt1.node_value == "");
- assert (txt2.node_value == "Const");
-
- txt1 = txt2.split_text (5);
- assert (txt1.node_value == "");
- assert (txt2.node_value == "Const");
-
- txt1 = txt2.split_text (-2);
- test_error (DomException.INDEX_SIZE);
- assert (txt1.node_value == ""); // TODO: decide if we want to return
null instead
- assert (txt2.node_value == "Const");
-
- txt1 = txt2.split_text (10);
- test_error (DomException.INDEX_SIZE);
- assert (txt1.node_value == ""); // TODO: decide if we want to return
null instead
- assert (txt2.node_value == "Const");
-
-
-
- } catch (GXml.DomError e) {
- Test.message ("%s", e.message);
- assert_not_reached ();
- }
+ Document doc;
+ Text txt1 = get_text_new_doc ("Constant vigilance!", out doc);
+ Text txt2 = txt1.split_text (5);
+
+ assert (txt1.node_value == "Const");
+ assert (txt2.node_value == "ant vigilance!");
+
+ /* TODO: libxml2 doesn't allow txt siblings, so for now
+ splitting text creates an unattached second Text
+ node. It might still be useful if you wanted to insert
+ an element in between, like with HTML markup? */
+ /*
+ assert (txt1.parent_node == txt2.parent_node);
+ assert (txt1.next_sibling == txt2);
+ assert (txt1 == txt2.previous_sibling);
+ */
+
+ txt2 = txt1.split_text (0);
+ assert (txt1.node_value == "");
+ assert (txt2.node_value == "Const");
+
+ txt1 = txt2.split_text (5);
+ assert (txt1.node_value == "");
+ assert (txt2.node_value == "Const");
+
+ txt1 = txt2.split_text (-2);
+ test_error (DomException.INDEX_SIZE);
+ assert (txt1.node_value == ""); // TODO: decide if we want to return null
instead
+ assert (txt2.node_value == "Const");
+
+ txt1 = txt2.split_text (10);
+ test_error (DomException.INDEX_SIZE);
+ assert (txt1.node_value == ""); // TODO: decide if we want to return null
instead
+ assert (txt2.node_value == "Const");
});
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]