[gxml] API change to sync TDocument with other implementations
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] API change to sync TDocument with other implementations
- Date: Tue, 15 Mar 2016 19:56:14 +0000 (UTC)
commit f464d3cd8e96365881b6b50b8e051373b6b91cd6
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Mar 15 13:48:20 2016 -0600
API change to sync TDocument with other implementations
gxml/TDocument.vala | 9 ++++++-
test/TDocumentTest.vala | 22 ++++++++++----------
test/gxml-performance.vala | 46 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 62 insertions(+), 15 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 93a8ef5..c5c657d 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -37,14 +37,19 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
_name = "#document";
}
public TDocument () {}
- public TDocument.for_path (string path) {
+ public TDocument.from_path (string path) {
this.file = GLib.File.new_for_path (path);
if (!file.query_exists ()) return;
try { read_doc (this, file, null); } catch {}
}
- public TDocument.for_file (GLib.File file) {
+
+ public TDocument.for_uri (string uri) {
+ this.from_file (File.new_for_uri (uri));
+ }
+
+ public TDocument.from_file (GLib.File file) {
if (!file.query_exists ()) return;
try { read_doc (this, file, null); } catch {}
this.file = file;
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index 5223cf5..45024da 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -51,7 +51,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
if (f.query_exists ()) f.delete ();
- var d = new TDocument.for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+ var d = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
var e = d.create_element ("root");
d.children.add (e);
assert (d.children.size == 1);
@@ -70,7 +70,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
if (f.query_exists ()) f.delete ();
- var d = new TDocument.for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+ var d = new TDocument.from_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
var e = d.create_element ("root");
d.children.add (e);
assert (d.children.size == 1);
@@ -98,7 +98,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
if (f.query_exists ()) f.delete ();
- var d = new TDocument.for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+ var d = new TDocument.from_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
var e = d.create_element ("root");
d.children.add (e);
assert (d.children.size == 1);
@@ -135,7 +135,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
if (f.query_exists ()) f.delete ();
- var d = new TDocument.for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+ var d = new TDocument.from_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
var e = d.create_element ("root");
d.children.add (e);
assert (d.children.size == 1);
@@ -170,7 +170,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
if (f.query_exists ()) f.delete ();
- var d = new TDocument.for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
+ var d = new TDocument.from_path
(GXmlTestConfig.TEST_SAVE_DIR+"/t-test.xml");
var e = d.create_element ("root");
d.children.add (e);
assert (d.children.size == 1);
@@ -218,7 +218,7 @@ class TDocumentTest : GXmlTest {
#if DEBUG
GLib.message (@"Creating Document...");
#endif
- var d = new TDocument.for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+ var d = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
var e = d.create_element ("bookstore");
d.children.add (e);
assert (d.children.size == 1);
@@ -281,7 +281,7 @@ class TDocumentTest : GXmlTest {
#if DEBUG
GLib.message (@"Creating Document...");
#endif
- var d = new TDocument.for_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
+ var d = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/t-large.xml");
var e = d.create_element ("bookstore");
d.children.add (e);
assert (d.children.size == 1);
@@ -498,7 +498,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
assert (f.query_exists ());
- var d = new TDocument.for_file (f);
+ var d = new TDocument.from_file (f);
//GLib.message ("Doc:"+d.to_string ());
assert (d.root != null);
assert (d.root.name == "Sentences");
@@ -541,7 +541,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
assert (f.query_exists ());
- var d = new TDocument.for_file (f);
+ var d = new TDocument.from_file (f);
assert (d.children[0] is GXml.Comment);
assert (d.children[0].value == " Top Level Comment ");
var a = d.root.children[2];
@@ -557,7 +557,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
assert (f.query_exists ());
- var d = new TDocument.for_file (f);
+ var d = new TDocument.from_file (f);
TDocument.read_doc (d, f, null);
assert (d.children[1] is GXml.ProcessingInstruction);
assert ((d.children[1] as GXml.ProcessingInstruction).target == "target");
@@ -581,7 +581,7 @@ class TDocumentTest : GXmlTest {
try {
var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
assert (f.query_exists ());
- var d = new TDocument.for_file (f);
+ var d = new TDocument.from_file (f);
TDocument.read_doc (d, f, null);
assert (d.root.children.size == 6);
var p = (d.root.children[5]);
diff --git a/test/gxml-performance.vala b/test/gxml-performance.vala
index 0f85a5e..885e622 100644
--- a/test/gxml-performance.vala
+++ b/test/gxml-performance.vala
@@ -413,7 +413,7 @@ public class Performance
try {
double time;
Test.timer_start ();
- var d = new TDocument.for_path (GXmlTest.get_test_dir () + "/test-large.xml");
+ var d = new TDocument.from_path (GXmlTest.get_test_dir () + "/test-large.xml");
time = Test.timer_elapsed ();
Test.minimized_result (time, "TDocument open document from path: %g seconds", time);
Test.message ("Starting Deserializing...");
@@ -934,7 +934,7 @@ public class Performance
d.save_as (f);
time = Test.timer_elapsed ();
Test.minimized_result (time, "Created document: %g seconds", time);
- Test.message ("Starting deserializing document: Disable collection deserialization...");
+ Test.message ("Starting deserializing document: Enable collection deserialization...");
Test.timer_start ();
var gd = new GDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/post-des-test-file.xml");
time = Test.timer_elapsed ();
@@ -958,6 +958,48 @@ public class Performance
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/performance/tdocument/arraylist/post-deserialization/enable",
+ () => {
+ try {
+ var f = GLib.File.new_for_path
(GXmlTestConfig.TEST_SAVE_DIR+"/post-des-test-file.xml");
+ if (f.query_exists ()) f.delete ();
+ double time;
+ Test.message ("Starting generating document...");
+ Test.timer_start ();
+ var d = new TDocument ();
+ var ce = new CElement ();
+ for (int i = 0; i < 30000; i++) {
+ var e = new AElement ();
+ ce.elements.add (e);
+ }
+ ce.serialize (d);
+ d.save_as (f);
+ time = Test.timer_elapsed ();
+ Test.minimized_result (time, "Created document: %g seconds", time);
+ Test.message ("Starting deserializing document: Enable collection deserialization...");
+ Test.timer_start ();
+ var gd = new TDocument.from_path (GXmlTestConfig.TEST_SAVE_DIR+"/post-des-test-file.xml");
+ time = Test.timer_elapsed ();
+ Test.minimized_result (time, "Opening doc: %g seconds", time);
+ Test.message ("Start deseralization of TDocument");
+ Test.timer_start ();
+ var cep = new CElement ();
+ cep.elements.enable_deserialize = true;
+ cep.deserialize (gd);
+ time = Test.timer_elapsed ();
+ Test.minimized_result (time, "Enable Deserialize Collection. Deserialized from doc: %g seconds",
time);
+ Test.message ("Calling deserialize_children()...");
+ Test.timer_start ();
+ cep.elements.deserialize_children ();
+ assert (!cep.elements.deserialize_children ());
+ time = Test.timer_elapsed ();
+ Test.minimized_result (time, "Enable Deserialize Collection. Deserialized from NODE: %g seconds",
time);
+ if (f.query_exists ()) f.delete ();
+ } catch (GLib.Error e) {
+ GLib.message ("ERROR: "+e.message);
+ assert_not_reached ();
+ }
+ });
#endif
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]