[gxml] GomDocument: new write_string()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] GomDocument: new write_string()
- Date: Fri, 5 May 2017 16:44:53 +0000 (UTC)
commit 76123366c970d072fdd4617588f7e9037885798d
Author: Daniel Espinosa <esodan gmail com>
Date: Fri May 5 11:43:46 2017 -0500
GomDocument: new write_string()
gxml/GomDocument.vala | 7 +++++++
test/GomDocumentTest.vala | 17 +++++++++++++++++
test/GomElementTest.vala | 7 ++++++-
3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 963a108..c45e345 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -128,6 +128,13 @@ public class GXml.GomDocument : GomNode,
return parser.create_stream (null);
}
/**
+ * Serialize {@link GomDocument} to a string.
+ */
+ public string write_string () throws GLib.Error {
+ var parser = new XParser (this);
+ return parser.write_string ();
+ }
+ /**
* Reads a file contents and parse it to document.
*/
public void read_from_file (GLib.File file) throws GLib.Error {
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index b5d05e8..22ad703 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -526,5 +526,22 @@ class GomDocumentTest : GXmlTest {
var doc = new GomDocument ();
assert (doc.parent_node == null);
});
+ Test.add_func ("/gxml/gom-document/write/string", () => {
+ try {
+ var d = new GomDocument ();
+ var n = d.create_element ("Node") as GomElement;
+ d.append_child (n);
+ n.set_attribute ("name","value");
+ var n2 = d.create_element ("Node2") as GomElement;
+ n.append_child (n2);
+ message (d.write_string ());
+ string str = d.write_string ();
+ assert ("<Node" in str);
+ assert ("<Node name=\"value\"><Node2/></Node>" in str);
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
}
}
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index 687f6b2..8a40607 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -226,9 +226,14 @@ class GomElementTest : GXmlTest {
var n = new GomElement ();
n.initialize ("Node");
n.set_attribute ("name","value");
+ var n2 = n.owner_document.create_element ("Node2") as GomElement;
+ n.append_child (n2);
string str = n.write_string ();
assert ("<Node" in str);
- assert ("<Node name=\"value\"/>" in str);
+ assert ("<Node name=\"value\"><Node2/></Node>" in str);
+ str = n2.write_string ();
+ assert ("<Node2/>" in str);
+ assert (!("<Node name=\"value\"><Node2/></Node>" in str));
} 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]