[gxml] Fixed GDocument.libxml_to_string(). Added unit tests
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Fixed GDocument.libxml_to_string(). Added unit tests
- Date: Mon, 8 Feb 2016 15:22:57 +0000 (UTC)
commit 4f1b8e807158c10eaa4f51585a320c4ef134fba3
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Feb 8 09:21:29 2016 -0600
Fixed GDocument.libxml_to_string(). Added unit tests
gxml/GXmlDocument.vala | 2 +-
test/GDocumentTest.vala | 39 ++++++++++++++++++---------------------
2 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/gxml/GXmlDocument.vala b/gxml/GXmlDocument.vala
index d8c8930..5a82d5f 100644
--- a/gxml/GXmlDocument.vala
+++ b/gxml/GXmlDocument.vala
@@ -168,7 +168,7 @@ public class GXml.GDocument : GXml.GNode, GXml.Document
public string libxml_to_string () {
string buffer;
doc->dump_memory (out buffer);
- return buffer;
+ return buffer.dup ();
}
public virtual bool save (GLib.Cancellable? cancellable = null)
throws GLib.Error
diff --git a/test/GDocumentTest.vala b/test/GDocumentTest.vala
index 4f734c0..b004b46 100644
--- a/test/GDocumentTest.vala
+++ b/test/GDocumentTest.vala
@@ -236,27 +236,24 @@ class GDocumentTest : GXmlTest {
assert (attr.value == "attrvalue");
//
//Test.message ("DOC libxml2:"+doc.libxml_to_string ());
- });/*
+ });
Test.add_func ("/gxml/gdocument/to_string", () => {
- GDocument doc = new GDocument.from_string ("<root />");
- 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>
- <Authors>
- <Author>
- <Name>Fred</Name>
- <Email>fweasley hogwarts co uk</Email>
- </Author>
- <Author>
- <Name>George</Name>
- <Email>gweasley hogwarts co uk</Email>
- </Author>
- </Authors>
-</Sentences>
-");
- // TODO: want to test with format on and off
-
- });*/
+ GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
+<Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die
Tür.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co
uk</Email></Author></Authors></Sentences>");
+ string s1 = doc.to_string ();
+ string[] cs1 = s1.split ("\n");
+ Test.message (s1);
+ assert (cs1[0] == "<?xml version=\"1.0\"?>");
+ assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour
blue.</Sentence><Sentence lang=\"de\">Ich liebe die
Tür.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co
uk</Email></Author></Authors></Sentences>");
+ });
+ Test.add_func ("/gxml/gdocument/libxml_to_string", () => {
+ GDocument doc = new GDocument.from_string ("<?xml version=\"1.0\"?>
+<Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die
Tür.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co
uk</Email></Author></Authors></Sentences>");
+ string s1 = doc.libxml_to_string ();
+ string[] cs1 = s1.split ("\n");
+ Test.message (s1);
+ assert (cs1[0] == "<?xml version=\"1.0\"?>");
+ assert (cs1[1] == "<Sentences><Sentence lang=\"en\">I like the colour
blue.</Sentence><Sentence lang=\"de\">Ich liebe die
Tür.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co
uk</Email></Author></Authors></Sentences>");
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]