[gxml] TwDocument and GDocument Namespace Unit Test fixes
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] TwDocument and GDocument Namespace Unit Test fixes
- Date: Wed, 10 Feb 2016 20:51:07 +0000 (UTC)
commit 141cf4d83e6493b0113a2ec635ae54382de6a561
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Feb 10 14:49:56 2016 -0600
TwDocument and GDocument Namespace Unit Test fixes
gxml/TwElement.vala | 1 +
test/GDocumentTest.vala | 2 ++
test/TwDocumentTest.vala | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/gxml/TwElement.vala b/gxml/TwElement.vala
index 6ed24b7..e391140 100644
--- a/gxml/TwElement.vala
+++ b/gxml/TwElement.vala
@@ -45,6 +45,7 @@ public class GXml.TwElement : GXml.TwNode, GXml.Element
// GXml.Element
public void set_attr (string name, string value)
{
+ if (":" in name) return;
var att = new TwAttribute (document, name, value);
attrs.set (name, att);
}
diff --git a/test/GDocumentTest.vala b/test/GDocumentTest.vala
index 1a50b91..e7e3671 100644
--- a/test/GDocumentTest.vala
+++ b/test/GDocumentTest.vala
@@ -314,6 +314,8 @@ class GDocumentTest : GXmlTest {
var pt = c.attrs.get ("prop");
assert (pt != null);
var pt2 = (c as Element).get_ns_attr ("prop", doc.root.namespaces[0].uri);
+ Test.message ("ROOT: "+doc.root.to_string ());
+ assert (doc.root.to_string () == "<root
xmlns:gxml=\"http://www.gnome.org/GXml\"><child xmlns:gxml2=\"http://www.gnome.org/GXml2\"
gxml:prop=\"Ten\"/></root>");
} catch (GLib.Error e) {
GLib.message ("ERROR: "+ e.message);
assert_not_reached ();
diff --git a/test/TwDocumentTest.vala b/test/TwDocumentTest.vala
index f9722ea..4628198 100644
--- a/test/TwDocumentTest.vala
+++ b/test/TwDocumentTest.vala
@@ -383,5 +383,44 @@ class TwDocumentTest : GXmlTest {
assert ("<root/>" in str);
assert ("<root/>" in doc.to_string ());
});
+ Test.add_func ("/gxml/tw-document/namespace", () => {
+ try {
+ var doc = new TwDocument ();
+ doc.children.add (doc.create_element ("root"));
+ doc.set_namespace ("http://www.gnome.org/GXml","gxml");
+ Test.message ("ROOT: "+doc.to_string ());
+ assert (doc.root != null);
+ assert (doc.namespaces != null);
+ assert (doc.namespaces.size == 1);
+ assert (doc.namespaces[0].prefix == "gxml");
+ assert (doc.namespaces[0].uri == "http://www.gnome.org/GXml");
+ doc.root.children.add (doc.create_element ("child"));
+ assert (doc.root.children != null);
+ assert (doc.root.children.size == 1);
+ var c = doc.root.children[0];
+ c.set_namespace ("http://www.gnome.org/GXml2","gxml2");
+ assert (c.namespaces != null);
+ assert (c.namespaces.size == 1);
+ assert (c.namespaces[0].prefix == "gxml2");
+ assert (c.namespaces[0].uri == "http://www.gnome.org/GXml2");
+ (c as Element).set_attr ("gxml:prop","val");
+ var p = (c as Element).get_attr ("gxml:prop");
+ assert (p == null);
+ Test.message ("ROOT: "+doc.to_string ());
+ string[] str = doc.to_string ().split("\n");
+ assert (str[1] == "<root
xmlns:gxml=\"http://www.gnome.org/GXml\"><gxml2:child xmlns:gxml2=\"http://www.gnome.org/GXml2\"/></root>");
+ (c as Element).set_ns_attr (doc.namespaces[0], "prop", "Ten");
+ Test.message ("ROOT: "+doc.root.to_string ());
+ assert (c.attrs.size == 1);
+ var pt = c.attrs.get ("prop");
+ assert (pt != null);
+ var pt2 = (c as Element).get_ns_attr ("prop", doc.namespaces[0].uri);
+ str = doc.to_string ().split("\n");
+ assert (str[1] == "<root
xmlns:gxml=\"http://www.gnome.org/GXml\"><gxml2:child xmlns:gxml2=\"http://www.gnome.org/GXml2\"
gxml:prop=\"Ten\"/></root>");
+ } catch (GLib.Error e) {
+ GLib.message ("ERROR: "+ e.message);
+ assert_not_reached ();
+ }
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]