[gxml] Added GomDocument.read_from_file()
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added GomDocument.read_from_file()
- Date: Tue, 13 Dec 2016 02:54:06 +0000 (UTC)
commit bed78f0faac609628beaa2fc6ea0fa7118aab5e9
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Dec 12 17:43:46 2016 -0600
Added GomDocument.read_from_file()
This is required to provide equivalent functionality to
Serializable, may a read_from_string() could be useful too
gxml/GomDocument.vala | 7 +++++++
test/GomDocumentTest.vala | 22 ++++++++++++++++++++++
test/TElementTest.vala | 2 +-
3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 979a188..e0b242e 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -102,6 +102,13 @@ public class GXml.GomDocument : GomNode,
var parser = new XParser (this);
parser.write_stream (stream, null);
}
+ /**
+ * Read file contents and parse it to document.
+ */
+ public void read_from_file (GLib.File file) throws GLib.Error {
+ var parser = new XParser (this);
+ parser.read_file (file, null);
+ }
public DomElement create_element (string local_name) throws GLib.Error {
return new GomElement.initialize (this, local_name);
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index 6ed027d..100091b 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -93,6 +93,28 @@ class GomDocumentTest : GXmlTest {
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/gom-document/read-gfile/local", () => {
+ try {
+ var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/tw-test-file.xml");
+ if (f.query_exists ()) f.delete ();
+ var s = new GLib.StringBuilder ();
+ s.append ("""<document_element />""");
+ var d = new GomDocument.from_string (s.str);
+ var parser = new XParser (d);
+ Test.message ("Saving to file: "+f.get_uri ()+parser.write_string ());
+ d.write_file (f);
+ assert (f.query_exists ());
+ var d2 = new GomDocument ();
+ assert (d2 != null);
+ d2.read_from_file (f);
+ assert (d2.document_element != null);
+ assert (d2.document_element.node_name == "document_element");
+ f.delete ();
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
Test.add_func ("/gxml/gom-document/gfile/remote/read", () => {
try {
var rf = GLib.File.new_for_uri
("https://git.gnome.org/browse/gxml/plain/gxml.doap");
diff --git a/test/TElementTest.vala b/test/TElementTest.vala
index ef5d790..26dac2f 100644
--- a/test/TElementTest.vala
+++ b/test/TElementTest.vala
@@ -54,9 +54,9 @@ class TElementTest : GXmlTest {
assert (c.content == "");
c.content = "";
assert (c.content == "");
- assert (c.children_nodes.size == 1);
c.content = "HELLO CONTENT";
assert (c.children_nodes.size == 1);
+ assert (c.children_nodes.size == 1);
assert (c.content == "HELLO CONTENT");
} catch { assert_not_reached (); }
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]